1 /*
2  * Copyright (C) 2014, Taowei Luo (uaedante@gmail.com)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library.  If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "internal.h"
22 
23 /* This file may be used in three place. That is vbox_tmpl.c,
24  * vbox_common.c and vbox_driver.c. The vboxUniformedAPI and some
25  * types used for vboxUniformedAPI is defined here.
26  *
27  * The vbox_tmpl.c is the only place where the driver knows the inside
28  * architecture of those vbox structs(vboxObj, vboxSession,
29  * pFuncs, and vboxCallback). The file should be included
30  * after the correct vbox_CAPI_v*.h, then we can use the vbox structs
31  * in vboxGlobalData. The vbox_tmpl.c should implement functions
32  * defined in vboxUniformedAPI.
33  *
34  * In vbox_driver.c, it is used to define the struct vboxUniformedAPI.
35  * The vbox_driver.c collects vboxUniformedAPI for all versions.
36  * Then vboxRegister calls the vboxRegisterUniformedAPI to register.
37  * Note: In vbox_driver.c, the vbox structs in vboxGlobalData is
38  * defined by vbox_CAPI_v4_0.h.
39  *
40  * The vbox_common.c, it is used to generate common codes for all vbox
41  * versions. Because the same member variable's offset in a vbox struct
42  * may change between different vbox versions. The vbox_common.c
43  * shouldn't directly use struct's member variables defined in
44  * vbox_CAPI_v*.h. To make things safety, we include the
45  * vbox_common.h in vbox_common.c. In this case, we treat structs
46  * defined by vbox as a void*. The common codes don't concern about
47  * the inside of this structs(actually, we can't, in the common level).
48  * With the help of vboxUniformed API, we call VirtualBox's API and
49  * implement the vbox driver in a high level.
50  *
51  * In conclusion:
52  *  * In vbox_tmpl.c, this file is included after vbox_CAPI_v*.h
53  *  * In vbox_driver.c, this file is included after vbox_XPCOMCGlue.h
54  *  * In vbox_common.c, this file is included after vbox_common.h
55  *
56  */
57 
58 /* Extracted define from vbox_tmpl.c */
59 
60 struct _vboxIID {
61     /* IID is represented by a UTF-16 encoded UUID in string form. */
62     PRUnichar *value;
63 
64     /* owner indicates if we own the value and need to free it. */
65     bool owner;
66 };
67 
68 typedef struct _vboxIID vboxIID;
69 
70 typedef union {
71     nsresult uResultCode;
72     PRInt32 resultCode;
73 } resultCodeUnion;
74 
75 
76 struct _vboxDriver {
77     virObjectLockable parent;
78 
79     virCaps *caps;
80     virDomainXMLOption *xmlopt;
81     virObjectEventState *domainEventState;
82 
83     /* vbox API initialization members */
84     PCVBOXXPCOM pFuncs;
85     IVirtualBox *vboxObj;
86     ISession *vboxSession;
87 #ifdef VBOX_API_VERSION
88     IVirtualBoxClient *vboxClient;
89 #endif
90 
91     unsigned long version;
92 
93     /* reference counting of vbox connections */
94     int volatile connectionCount;
95 };
96 
97 typedef struct _vboxDriver vboxDriver;
98 
99 /* vboxUniformedAPI gives vbox_common.c a uniformed layer to see
100  * vbox API.
101  */
102 
103 /* Functions for pFuncs */
104 typedef struct {
105     int (*Initialize)(struct _vboxDriver *driver);
106     void (*Uninitialize)(struct _vboxDriver *driver);
107     void (*ComUnallocMem)(PCVBOXXPCOM pFuncs, void *pv);
108     void (*Utf16Free)(PCVBOXXPCOM pFuncs, PRUnichar *pwszString);
109     void (*Utf8Free)(PCVBOXXPCOM pFuncs, char *pszString);
110     int (*Utf16ToUtf8)(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString);
111     int (*Utf8ToUtf16)(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString);
112 } vboxUniformedPFN;
113 
114 /* Functions for vboxIID */
115 typedef struct {
116     void (*vboxIIDInitialize)(vboxIID *iid);
117     void (*vboxIIDUnalloc)(struct _vboxDriver *driver, vboxIID *iid);
118     void (*vboxIIDToUUID)(struct _vboxDriver *driver, vboxIID *iid, unsigned char *uuid);
119     void (*vboxIIDFromUUID)(struct _vboxDriver *driver, vboxIID *iid, const unsigned char *uuid);
120     bool (*vboxIIDIsEqual)(struct _vboxDriver *driver, vboxIID *iid1, vboxIID *iid2);
121     void (*vboxIIDFromArrayItem)(struct _vboxDriver *driver, vboxIID *iid, vboxArray *array, int idx);
122     void (*vboxIIDToUtf8)(struct _vboxDriver *driver, vboxIID *iid, char **utf8);
123     void (*DEBUGIID)(struct _vboxDriver *driver, const char *msg, vboxIID *iid);
124 } vboxUniformedIID;
125 
126 /* Functions for vboxArray */
127 typedef struct {
128     nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter);
129     nsresult (*vboxArrayGetWithIIDArg)(vboxArray *array, void *self, void *getter, vboxIID *iid);
130     void (*vboxArrayRelease)(vboxArray *array);
131     void (*vboxArrayUnalloc)(vboxArray *array);
132     /* Generate function pointers for vboxArrayGet */
133     void* (*handleGetMachines)(IVirtualBox *vboxObj);
134     void* (*handleGetHardDisks)(IVirtualBox *vboxObj);
135     void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon);
136     void* (*handleMachineGetStorageControllers)(IMachine *machine);
137     void* (*handleMachineGetMediumAttachments)(IMachine *machine);
138     void* (*handleMachineGetSharedFolders)(IMachine *machine);
139     void* (*handleSnapshotGetChildren)(ISnapshot *snapshot);
140     void* (*handleMediumGetChildren)(IMedium *medium);
141     void* (*handleMediumGetSnapshotIds)(IMedium *medium);
142     void* (*handleMediumGetMachineIds)(IMedium *medium);
143     void* (*handleHostGetNetworkInterfaces)(IHost *host);
144 } vboxUniformedArray;
145 
146 /* Functions for nsISupports */
147 typedef struct {
148     nsresult (*Release)(nsISupports *nsi);
149     nsresult (*AddRef)(nsISupports *nsi);
150 } vboxUniformednsISupports;
151 
152 /* Functions for IVirtualBox */
153 typedef struct {
154     nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
155     nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIID *iid, IMachine **machine);
156     nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine);
157     nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
158     nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host);
159     nsresult (*CreateMachine)(struct _vboxDriver *driver, virDomainDef *def, IMachine **machine, char *uuidstr);
160     nsresult (*CreateHardDisk)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
161     nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
162     nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType,
163                              PRUint32 accessMode, IMedium **medium);
164     nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
165     nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIID *iid, IMedium **medium);
166     nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
167     nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
168     nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server);
169 } vboxUniformedIVirtualBox;
170 
171 /* Functions for IMachine */
172 typedef struct {
173     nsresult (*AddStorageController)(IMachine *machine, PRUnichar *name,
174         PRUint32 connectionType, IStorageController **controller);
175     nsresult (*GetStorageControllerByName)(IMachine *machine, PRUnichar *name,
176                                            IStorageController **storageController);
177     nsresult (*AttachDevice)(IMachine *machine, PRUnichar *name,
178                              PRInt32 controllerPort, PRInt32 device,
179                              PRUint32 type, IMedium *medium);
180     nsresult (*CreateSharedFolder)(IMachine *machine, PRUnichar *name,
181                                    PRUnichar *hostPath, PRBool writable,
182                                    PRBool automount);
183     nsresult (*RemoveSharedFolder)(IMachine *machine, PRUnichar *name);
184     nsresult (*LaunchVMProcess)(struct _vboxDriver *driver, IMachine *machine,
185                                 vboxIID *iid,
186                                 PRUnichar *sessionType, PRUnichar *env,
187                                 IProgress **progress);
188     nsresult (*Unregister)(IMachine *machine, PRUint32 cleanupMode,
189                            PRUint32 *aMediaSize, IMedium ***aMedia);
190     nsresult (*FindSnapshot)(IMachine *machine, vboxIID *iid, ISnapshot **snapshot);
191     nsresult (*DetachDevice)(IMachine *machine, PRUnichar *name,
192                              PRInt32 controllerPort, PRInt32 device);
193     nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible);
194     nsresult (*GetState)(IMachine *machine, PRUint32 *state);
195     nsresult (*GetName)(IMachine *machine, PRUnichar **name);
196     nsresult (*GetId)(IMachine *machine, vboxIID *iid);
197     nsresult (*GetBIOSSettings)(IMachine *machine, IBIOSSettings **bios);
198     nsresult (*GetAudioAdapter)(IMachine *machine, IAudioAdapter **audioAdapter);
199     nsresult (*GetNetworkAdapter)(IMachine *machine, PRUint32 slot, INetworkAdapter **adapter);
200     nsresult (*GetChipsetType)(IMachine *machine, PRUint32 *chipsetType);
201     nsresult (*GetSerialPort)(IMachine *machine, PRUint32 slot, ISerialPort **port);
202     nsresult (*GetParallelPort)(IMachine *machine, PRUint32 slot, IParallelPort **port);
203     nsresult (*GetVRDEServer)(IMachine *machine, IVRDEServer **VRDEServer);
204     nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon);
205     nsresult (*GetCurrentSnapshot)(IMachine *machine, ISnapshot **currentSnapshot);
206     nsresult (*GetSettingsFilePath)(IMachine *machine, PRUnichar **settingsFilePath);
207     nsresult (*GetCPUCount)(IMachine *machine, PRUint32 *CPUCount);
208     nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount);
209     nsresult (*GetMemorySize)(IMachine *machine, PRUint32 *memorySize);
210     nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize);
211     nsresult (*GetCPUProperty)(IMachine *machine, PRUint32 property, PRBool *value);
212     nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value);
213     nsresult (*GetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 *device);
214     nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device);
215     nsresult (*GetVRAMSize)(IMachine *machine, PRUint32 *VRAMSize);
216     nsresult (*SetVRAMSize)(IMachine *machine, PRUint32 VRAMSize);
217     nsresult (*GetMonitorCount)(IMachine *machine, PRUint32 *monitorCount);
218     nsresult (*SetMonitorCount)(IMachine *machine, PRUint32 monitorCount);
219     nsresult (*GetAccelerate3DEnabled)(IMachine *machine, PRBool *accelerate3DEnabled);
220     nsresult (*SetAccelerate3DEnabled)(IMachine *machine, PRBool accelerate3DEnabled);
221     nsresult (*GetAccelerate2DVideoEnabled)(IMachine *machine, PRBool *accelerate2DVideoEnabled);
222     nsresult (*SetAccelerate2DVideoEnabled)(IMachine *machine, PRBool accelerate2DVideoEnabled);
223     nsresult (*GetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar **value);
224     nsresult (*SetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar *value);
225     nsresult (*GetSnapshotCount)(IMachine *machine, PRUint32 *snapshotCount);
226     nsresult (*SaveSettings)(IMachine *machine);
227 } vboxUniformedIMachine;
228 
229 /* Functions for ISession */
230 typedef struct {
231     nsresult (*Open)(struct _vboxDriver *driver, vboxIID *iid, IMachine *machine);
232     nsresult (*OpenExisting)(struct _vboxDriver *driver, vboxIID *iid, IMachine *machine);
233     nsresult (*GetConsole)(ISession *session, IConsole **console);
234     nsresult (*GetMachine)(ISession *session, IMachine **machine);
235     nsresult (*Close)(ISession *session);
236 } vboxUniformedISession;
237 
238 /* Functions for IConsole */
239 typedef struct {
240     nsresult (*SaveState)(IConsole *console, IProgress **progress);
241     nsresult (*Pause)(IConsole *console);
242     nsresult (*Resume)(IConsole *console);
243     nsresult (*PowerButton)(IConsole *console);
244     nsresult (*PowerDown)(IConsole *console);
245     nsresult (*Reset)(IConsole *console);
246     nsresult (*TakeSnapshot)(IConsole *console, PRUnichar *name,
247                              PRUnichar *description, IProgress **progress);
248     nsresult (*DeleteSnapshot)(IConsole *console, vboxIID *iid, IProgress **progress);
249     nsresult (*GetDisplay)(IConsole *console, IDisplay **display);
250     nsresult (*GetKeyboard)(IConsole *console, IKeyboard **keyboard);
251 } vboxUniformedIConsole;
252 
253 /* Functions for IProgress */
254 typedef struct {
255     nsresult (*WaitForCompletion)(IProgress *progress, PRInt32 timeout);
256     nsresult (*GetResultCode)(IProgress *progress, resultCodeUnion *resultCode);
257     nsresult (*GetCompleted)(IProgress *progress, PRBool *completed);
258 } vboxUniformedIProgress;
259 
260 /* Functions for ISystemProperties */
261 typedef struct {
262     nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
263     nsresult (*GetMaxBootPosition)(ISystemProperties *systemProperties, PRUint32 *maxBootPosition);
264     nsresult (*GetMaxNetworkAdapters)(ISystemProperties *systemProperties, PRUint32 chipset,
265                                       PRUint32 *maxNetworkAdapters);
266     nsresult (*GetSerialPortCount)(ISystemProperties *systemProperties, PRUint32 *SerialPortCount);
267     nsresult (*GetParallelPortCount)(ISystemProperties *systemProperties, PRUint32 *ParallelPortCount);
268     nsresult (*GetMaxPortCountForStorageBus)(ISystemProperties *systemProperties, PRUint32 bus,
269                                              PRUint32 *maxPortCount);
270     nsresult (*GetMaxDevicesPerPortForStorageBus)(ISystemProperties *systemProperties,
271                                                   PRUint32 bus, PRUint32 *maxDevicesPerPort);
272     nsresult (*GetMaxGuestRAM)(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM);
273 } vboxUniformedISystemProperties;
274 
275 /* Functions for IBIOSSettings */
276 typedef struct {
277     nsresult (*GetACPIEnabled)(IBIOSSettings *bios, PRBool *ACPIEnabled);
278     nsresult (*SetACPIEnabled)(IBIOSSettings *bios, PRBool ACPIEnabled);
279     nsresult (*GetIOAPICEnabled)(IBIOSSettings *bios, PRBool *IOAPICEnabled);
280     nsresult (*SetIOAPICEnabled)(IBIOSSettings *bios, PRBool IOAPICEnabled);
281 } vboxUniformedIBIOSSettings;
282 
283 /* Functions for IAudioAdapter */
284 typedef struct {
285     nsresult (*GetEnabled)(IAudioAdapter *audioAdapter, PRBool *enabled);
286     nsresult (*SetEnabled)(IAudioAdapter *audioAdapter, PRBool enabled);
287     nsresult (*GetAudioController)(IAudioAdapter *audioAdapter, PRUint32 *audioController);
288     nsresult (*SetAudioController)(IAudioAdapter *audioAdapter, PRUint32 audioController);
289 } vboxUniformedIAudioAdapter;
290 
291 /* Functions for INetworkAdapter */
292 typedef struct {
293     nsresult (*GetAttachmentType)(INetworkAdapter *adapter, PRUint32 *attachmentType);
294     nsresult (*GetEnabled)(INetworkAdapter *adapter, PRBool *enabled);
295     nsresult (*SetEnabled)(INetworkAdapter *adapter, PRBool enabled);
296     nsresult (*GetAdapterType)(INetworkAdapter *adapter, PRUint32 *adapterType);
297     nsresult (*SetAdapterType)(INetworkAdapter *adapter, PRUint32 adapterType);
298     nsresult (*GetBridgedInterface)(INetworkAdapter *adapter, PRUnichar **bridgedInterface);
299     nsresult (*SetBridgedInterface)(INetworkAdapter *adapter, PRUnichar *bridgedInterface);
300     nsresult (*GetInternalNetwork)(INetworkAdapter *adapter, PRUnichar **internalNetwork);
301     nsresult (*SetInternalNetwork)(INetworkAdapter *adapter, PRUnichar *internalNetwork);
302     nsresult (*GetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface);
303     nsresult (*SetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface);
304     nsresult (*GetMACAddress)(INetworkAdapter *adapter, PRUnichar **MACAddress);
305     nsresult (*SetMACAddress)(INetworkAdapter *adapter, PRUnichar *MACAddress);
306     nsresult (*AttachToBridgedInterface)(INetworkAdapter *adapter);
307     nsresult (*AttachToInternalNetwork)(INetworkAdapter *adapter);
308     nsresult (*AttachToHostOnlyInterface)(INetworkAdapter *adapter);
309     nsresult (*AttachToNAT)(INetworkAdapter *adapter);
310 } vboxUniformedINetworkAdapter;
311 
312 /* Functions for ISerialPort */
313 typedef struct {
314     nsresult (*GetEnabled)(ISerialPort *port, PRBool *enabled);
315     nsresult (*SetEnabled)(ISerialPort *port, PRBool enabled);
316     nsresult (*GetPath)(ISerialPort *port, PRUnichar **path);
317     nsresult (*SetPath)(ISerialPort *port, PRUnichar *path);
318     nsresult (*GetIRQ)(ISerialPort *port, PRUint32 *IRQ);
319     nsresult (*SetIRQ)(ISerialPort *port, PRUint32 IRQ);
320     nsresult (*GetIOBase)(ISerialPort *port, PRUint32 *IOBase);
321     nsresult (*SetIOBase)(ISerialPort *port, PRUint32 IOBase);
322     nsresult (*GetHostMode)(ISerialPort *port, PRUint32 *hostMode);
323     nsresult (*SetHostMode)(ISerialPort *port, PRUint32 hostMode);
324 } vboxUniformedISerialPort;
325 
326 /* Functions for IParallelPort */
327 typedef struct {
328     nsresult (*GetEnabled)(IParallelPort *port, PRBool *enabled);
329     nsresult (*SetEnabled)(IParallelPort *port, PRBool enabled);
330     nsresult (*GetPath)(IParallelPort *port, PRUnichar **path);
331     nsresult (*SetPath)(IParallelPort *port, PRUnichar *path);
332     nsresult (*GetIRQ)(IParallelPort *port, PRUint32 *IRQ);
333     nsresult (*SetIRQ)(IParallelPort *port, PRUint32 IRQ);
334     nsresult (*GetIOBase)(IParallelPort *port, PRUint32 *IOBase);
335     nsresult (*SetIOBase)(IParallelPort *port, PRUint32 IOBase);
336 } vboxUniformedIParallelPort;
337 
338 /* Functions for IVRDEServer */
339 typedef struct {
340     nsresult (*GetEnabled)(IVRDEServer *VRDEServer, PRBool *enabled);
341     nsresult (*SetEnabled)(IVRDEServer *VRDEServer, PRBool enabled);
342     nsresult (*GetPorts)(struct _vboxDriver *driver, IVRDEServer *VRDEServer,
343                          IMachine *machine, virDomainGraphicsDef *graphics);
344     nsresult (*SetPorts)(struct _vboxDriver *driver, IVRDEServer *VRDEServer,
345                          virDomainGraphicsDef *graphics);
346     nsresult (*GetReuseSingleConnection)(IVRDEServer *VRDEServer, PRBool *enabled);
347     nsresult (*SetReuseSingleConnection)(IVRDEServer *VRDEServer, PRBool enabled);
348     nsresult (*GetAllowMultiConnection)(IVRDEServer *VRDEServer, PRBool *enabled);
349     nsresult (*SetAllowMultiConnection)(IVRDEServer *VRDEServer, PRBool enabled);
350     nsresult (*GetNetAddress)(struct _vboxDriver *driver, IVRDEServer *VRDEServer,
351                               PRUnichar **netAddress);
352     nsresult (*SetNetAddress)(struct _vboxDriver *driver, IVRDEServer *VRDEServer,
353                               PRUnichar *netAddress);
354 } vboxUniformedIVRDEServer;
355 
356 /* Common Functions for IUSBController and IUSBDeviceFilters */
357 typedef struct {
358     nsresult (*Enable)(IUSBCommon *USBCommon);
359     nsresult (*GetEnabled)(IUSBCommon *USBCommon, PRBool *enabled);
360     nsresult (*CreateDeviceFilter)(IUSBCommon *USBCommon, PRUnichar *name,
361                                    IUSBDeviceFilter **filter);
362     nsresult (*InsertDeviceFilter)(IUSBCommon *USBCommon, PRUint32 position,
363                                    IUSBDeviceFilter *filter);
364 } vboxUniformedIUSBCommon;
365 
366 typedef struct {
367     nsresult (*GetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **productId);
368     nsresult (*SetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *productId);
369     nsresult (*GetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool *active);
370     nsresult (*SetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool active);
371     nsresult (*GetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **vendorId);
372     nsresult (*SetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *vendorId);
373 } vboxUniformedIUSBDeviceFilter;
374 
375 /* Functions for IMedium */
376 typedef struct {
377     nsresult (*GetId)(IMedium *medium, vboxIID *iid);
378     nsresult (*GetLocation)(IMedium *medium, PRUnichar **location);
379     nsresult (*GetState)(IMedium *medium, PRUint32 *state);
380     nsresult (*GetName)(IMedium *medium, PRUnichar **name);
381     nsresult (*GetSize)(IMedium *medium, PRUint64 *uSize);
382     nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly);
383     nsresult (*GetParent)(IMedium *medium, IMedium **parent);
384     nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize,
385                             IMedium ***children);
386     nsresult (*GetFormat)(IMedium *medium, PRUnichar **format);
387     nsresult (*DeleteStorage)(IMedium *medium, IProgress **progress);
388     nsresult (*Release)(IMedium *medium);
389     nsresult (*Close)(IMedium *medium);
390     nsresult (*SetType)(IMedium *medium, PRUint32 type);
391     nsresult (*CreateDiffStorage)(IMedium *medium, IMedium *target,
392                                   PRUint32 variantSize, PRUint32 *variant,
393                                   IProgress **progress);
394     nsresult (*CreateBaseStorage)(IMedium *medium, PRUint64 logicalSize,
395                                   PRUint32 variant, IProgress **progress);
396     nsresult (*GetLogicalSize)(IMedium *medium, PRUint64 *uLogicalSize);
397 } vboxUniformedIMedium;
398 
399 /* Functions for IMediumAttachment */
400 typedef struct {
401     nsresult (*GetMedium)(IMediumAttachment *mediumAttachment, IMedium **medium);
402     nsresult (*GetController)(IMediumAttachment *mediumAttachment, PRUnichar **controller);
403     nsresult (*GetType)(IMediumAttachment *mediumAttachment, PRUint32 *type);
404     nsresult (*GetPort)(IMediumAttachment *mediumAttachment, PRInt32 *port);
405     nsresult (*GetDevice)(IMediumAttachment *mediumAttachment, PRInt32 *device);
406 } vboxUniformedIMediumAttachment;
407 
408 
409 /* Functions for IStorageController */
410 typedef struct {
411     nsresult (*GetBus)(IStorageController *storageController, PRUint32 *bus);
412     nsresult (*SetControllerType)(IStorageController *storageController, PRUint32 controllerType);
413     nsresult (*GetControllerType)(IStorageController *storageController, PRUint32 *controllerType);
414 } vboxUniformedIStorageController;
415 
416 /* Functions for ISharedFolder */
417 typedef struct {
418     nsresult (*GetHostPath)(ISharedFolder *sharedFolder, PRUnichar **hostPath);
419     nsresult (*GetName)(ISharedFolder *sharedFolder, PRUnichar **name);
420     nsresult (*GetWritable)(ISharedFolder *sharedFolder, PRBool *writable);
421 } vboxUniformedISharedFolder;
422 
423 /* Functions for ISnapshot */
424 typedef struct {
425     nsresult (*GetName)(ISnapshot *snapshot, PRUnichar **name);
426     nsresult (*GetId)(ISnapshot *snapshot, vboxIID *iid);
427     nsresult (*GetMachine)(ISnapshot *snapshot, IMachine **machine);
428     nsresult (*GetDescription)(ISnapshot *snapshot, PRUnichar **description);
429     nsresult (*GetTimeStamp)(ISnapshot *snapshot, PRInt64 *timeStamp);
430     nsresult (*GetParent)(ISnapshot *snapshot, ISnapshot **parent);
431     nsresult (*GetOnline)(ISnapshot *snapshot, PRBool *online);
432 } vboxUniformedISnapshot;
433 
434 /* Functions for IDisplay */
435 typedef struct {
436     nsresult (*GetScreenResolution)(IDisplay *display,
437                                     PRUint32 screenId,
438                                     PRUint32 *width,
439                                     PRUint32 *height,
440                                     PRUint32 *bitsPerPixel,
441                                     PRInt32 *xOrigin,
442                                     PRInt32 *yOrigin);
443     nsresult (*TakeScreenShotPNGToArray)(IDisplay *display,
444                                          PRUint32 screenId,
445                                          PRUint32 width,
446                                          PRUint32 height,
447                                          PRUint32 *screenDataSize,
448                                          PRUint8** screenData);
449 } vboxUniformedIDisplay;
450 
451 /* Functions for IHost */
452 typedef struct {
453     nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIID *iid,
454                                              IHostNetworkInterface **networkInterface);
455     nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name,
456                                                IHostNetworkInterface **networkInterface);
457     nsresult (*CreateHostOnlyNetworkInterface)(struct _vboxDriver *driver,
458                                                IHost *host, char *name,
459                                                IHostNetworkInterface **networkInterface);
460     nsresult (*RemoveHostOnlyNetworkInterface)(IHost *host, vboxIID *iid,
461                                                IProgress **progress);
462 } vboxUniformedIHost;
463 
464 /* Functions for IHostNetworkInterface */
465 typedef struct {
466     nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
467     nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
468     nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name);
469     nsresult (*GetId)(IHostNetworkInterface *hni, vboxIID *iid);
470     nsresult (*GetHardwareAddress)(IHostNetworkInterface *hni, PRUnichar **hardwareAddress);
471     nsresult (*GetIPAddress)(IHostNetworkInterface *hni, PRUnichar **IPAddress);
472     nsresult (*GetNetworkMask)(IHostNetworkInterface *hni, PRUnichar **networkMask);
473     nsresult (*EnableStaticIPConfig)(IHostNetworkInterface *hni, PRUnichar *IPAddress,
474                                      PRUnichar *networkMask);
475     nsresult (*EnableDynamicIPConfig)(IHostNetworkInterface *hni);
476     nsresult (*DHCPRediscover)(IHostNetworkInterface *hni);
477 } vboxUniformedIHNInterface;
478 
479 /* Functions for IDHCPServer */
480 typedef struct {
481     nsresult (*GetIPAddress)(IDHCPServer *dhcpServer, PRUnichar **IPAddress);
482     nsresult (*GetNetworkMask)(IDHCPServer *dhcpServer, PRUnichar **networkMask);
483     nsresult (*GetLowerIP)(IDHCPServer *dhcpServer, PRUnichar **lowerIP);
484     nsresult (*GetUpperIP)(IDHCPServer *dhcpServer, PRUnichar **upperIP);
485     nsresult (*SetEnabled)(IDHCPServer *dhcpServer, PRBool enabled);
486     nsresult (*SetConfiguration)(IDHCPServer *dhcpServer, PRUnichar *IPAddress,
487                                  PRUnichar *networkMask, PRUnichar *FromIPAddress,
488                                  PRUnichar *ToIPAddress);
489     nsresult (*Start)(IDHCPServer *dhcpServer, PRUnichar *networkName,
490                       PRUnichar *trunkName, PRUnichar *trunkType);
491     nsresult (*Stop)(IDHCPServer *dhcpServer);
492 } vboxUniformedIDHCPServer;
493 
494 typedef struct {
495     nsresult (*PutScancode)(IKeyboard *keyboard, PRInt32 scancode);
496     nsresult (*PutScancodes)(IKeyboard *keyboard, PRUint32 scancodesSize,
497                              PRInt32 *scanCodes, PRUint32 *codesStored);
498 } vboxUniformedIKeyboard;
499 
500 typedef struct {
501     bool (*Online)(PRUint32 state);
502     bool (*Inactive)(PRUint32 state);
503     bool (*NotStart)(PRUint32 state);
504     bool (*Running)(PRUint32 state);
505     bool (*Paused)(PRUint32 state);
506     bool (*PoweredOff)(PRUint32 state);
507 } uniformedMachineStateChecker;
508 
509 typedef struct {
510     /* vbox API version */
511     uint32_t APIVersion;
512     uint32_t XPCOMCVersion;
513     /* vbox APIs */
514     nsresult (*unregisterMachine)(struct _vboxDriver *driver, vboxIID *iid, IMachine **machine);
515     void (*deleteConfig)(IMachine *machine);
516     void (*vboxAttachDrivesOld)(virDomainDef *def, struct _vboxDriver *driver, IMachine *machine);
517     virDomainState (*vboxConvertState)(PRUint32 state);
518     int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
519     vboxUniformedPFN UPFN;
520     vboxUniformedIID UIID;
521     vboxUniformedArray UArray;
522     vboxUniformednsISupports nsUISupports;
523     vboxUniformedIVirtualBox UIVirtualBox;
524     vboxUniformedIMachine UIMachine;
525     vboxUniformedISession UISession;
526     vboxUniformedIConsole UIConsole;
527     vboxUniformedIProgress UIProgress;
528     vboxUniformedISystemProperties UISystemProperties;
529     vboxUniformedIBIOSSettings UIBIOSSettings;
530     vboxUniformedIAudioAdapter UIAudioAdapter;
531     vboxUniformedINetworkAdapter UINetworkAdapter;
532     vboxUniformedISerialPort UISerialPort;
533     vboxUniformedIParallelPort UIParallelPort;
534     vboxUniformedIVRDEServer UIVRDEServer;
535     vboxUniformedIUSBCommon UIUSBCommon;
536     vboxUniformedIUSBDeviceFilter UIUSBDeviceFilter;
537     vboxUniformedIMedium UIMedium;
538     vboxUniformedIMediumAttachment UIMediumAttachment;
539     vboxUniformedIStorageController UIStorageController;
540     vboxUniformedISharedFolder UISharedFolder;
541     vboxUniformedISnapshot UISnapshot;
542     vboxUniformedIDisplay UIDisplay;
543     vboxUniformedIHost UIHost;
544     vboxUniformedIHNInterface UIHNInterface;
545     vboxUniformedIDHCPServer UIDHCPServer;
546     vboxUniformedIKeyboard UIKeyboard;
547     uniformedMachineStateChecker machineStateChecker;
548     /* vbox API features */
549     bool chipsetType;
550     bool vboxSnapshotRedefine;
551 } vboxUniformedAPI;
552 
553 virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
554                                     const unsigned char *uuid);
555 
556 /* Version specified functions for installing uniformed API */
557 void vbox52InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
558 void vbox60InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
559 void vbox61InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
560