vbox_uniformed_api.h 28.0 KB
Newer Older
T
Taowei 已提交
1
/*
T
Taowei Luo 已提交
2
 * Copyright (C) 2014, Taowei Luo (uaedante@gmail.com)
T
Taowei 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

19
#pragma once
T
Taowei 已提交
20

21
#include "internal.h"
T
Taowei 已提交
22 23 24 25 26 27 28

/* This file may be used in three place. That is vbox_tmpl.c,
 * vbox_common.c and vbox_driver.c. The vboxUniformedAPI and some
 * types used for vboxUniformedAPI is defined here.
 *
 * The vbox_tmpl.c is the only place where the driver knows the inside
 * architecture of those vbox structs(vboxObj, vboxSession,
29
 * pFuncs, and vboxCallback). The file should be included
T
Taowei 已提交
30 31 32 33 34 35 36 37
 * after the currect vbox_CAPI_v*.h, then we can use the vbox structs
 * in vboxGlobalData. The vbox_tmpl.c should implement functions
 * defined in vboxUniformedAPI.
 *
 * In vbox_driver.c, it is used to define the struct vboxUniformedAPI.
 * The vbox_driver.c collects vboxUniformedAPI for all versions.
 * Then vboxRegister calls the vboxRegisterUniformedAPI to register.
 * Note: In vbox_driver.c, the vbox structs in vboxGlobalData is
38
 * defined by vbox_CAPI_v4_0.h.
T
Taowei 已提交
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
T
Taowei 已提交
42
 * may change between different vbox versions. The vbox_common.c
43
 * shouldn't directly use struct's member variables defined in
T
Taowei 已提交
44 45 46 47 48 49 50 51 52
 * vbox_CAPI_v*.h. To make things safety, we include the
 * vbox_common.h in vbox_common.c. In this case, we treat structs
 * defined by vbox as a void*. The common codes don't concern about
 * the inside of this structs(actually, we can't, in the common level).
 * With the help of vboxUniformed API, we call VirtualBox's API and
 * implement the vbox driver in a high level.
 *
 * In conclusion:
 *  * 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
T
Taowei 已提交
54 55 56 57
 *  * In vbox_common.c, this file is included after vbox_common.h
 *
 */

T
Taowei 已提交
58 59
/* Extracted define from vbox_tmpl.c */

60
struct _vboxIID {
T
Taowei 已提交
61 62 63 64 65 66 67
    /* IID is represented by a UTF-16 encoded UUID in string form. */
    PRUnichar *value;

    /* owner indicates if we own the value and need to free it. */
    bool owner;
};

68
typedef struct _vboxIID vboxIID;
T
Taowei 已提交
69 70 71 72 73 74

typedef union {
    nsresult uResultCode;
    PRInt32 resultCode;
} resultCodeUnion;

T
Taowei 已提交
75

76 77 78 79 80 81 82 83 84 85 86
struct _vboxDriver {
    virObjectLockable parent;

    virCapsPtr caps;
    virDomainXMLOptionPtr xmlopt;
    virObjectEventStatePtr domainEventState;

    /* vbox API initialization members */
    PCVBOXXPCOM pFuncs;
    IVirtualBox *vboxObj;
    ISession *vboxSession;
87
#ifdef VBOX_API_VERSION
88
    IVirtualBoxClient *vboxClient;
89
#endif
90 91 92 93 94 95 96 97 98 99

    unsigned long version;

    /* reference counting of vbox connections */
    int volatile connectionCount;
};

typedef struct _vboxDriver vboxDriver;
typedef struct _vboxDriver *vboxDriverPtr;

T
Taowei 已提交
100 101 102 103 104 105
/* vboxUniformedAPI gives vbox_common.c a uniformed layer to see
 * vbox API.
 */

/* Functions for pFuncs */
typedef struct {
106 107
    int (*Initialize)(vboxDriverPtr driver);
    void (*Uninitialize)(vboxDriverPtr driver);
T
Taowei 已提交
108 109 110 111 112 113 114
    void (*ComUnallocMem)(PCVBOXXPCOM pFuncs, void *pv);
    void (*Utf16Free)(PCVBOXXPCOM pFuncs, PRUnichar *pwszString);
    void (*Utf8Free)(PCVBOXXPCOM pFuncs, char *pszString);
    int (*Utf16ToUtf8)(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString);
    int (*Utf8ToUtf16)(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString);
} vboxUniformedPFN;

T
Taowei 已提交
115 116
/* Functions for vboxIID */
typedef struct {
117 118 119 120 121 122 123 124
    void (*vboxIIDInitialize)(vboxIID *iid);
    void (*vboxIIDUnalloc)(vboxDriverPtr driver, vboxIID *iid);
    void (*vboxIIDToUUID)(vboxDriverPtr driver, vboxIID *iid, unsigned char *uuid);
    void (*vboxIIDFromUUID)(vboxDriverPtr driver, vboxIID *iid, const unsigned char *uuid);
    bool (*vboxIIDIsEqual)(vboxDriverPtr driver, vboxIID *iid1, vboxIID *iid2);
    void (*vboxIIDFromArrayItem)(vboxDriverPtr driver, vboxIID *iid, vboxArray *array, int idx);
    void (*vboxIIDToUtf8)(vboxDriverPtr driver, vboxIID *iid, char **utf8);
    void (*DEBUGIID)(vboxDriverPtr driver, const char *msg, vboxIID *iid);
T
Taowei 已提交
125 126
} vboxUniformedIID;

T
Taowei 已提交
127 128 129
/* Functions for vboxArray */
typedef struct {
    nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter);
130
    nsresult (*vboxArrayGetWithIIDArg)(vboxArray *array, void *self, void *getter, vboxIID *iid);
T
Taowei 已提交
131
    void (*vboxArrayRelease)(vboxArray *array);
T
Taowei Luo 已提交
132
    void (*vboxArrayUnalloc)(vboxArray *array);
T
Taowei 已提交
133 134
    /* Generate function pointers for vboxArrayGet */
    void* (*handleGetMachines)(IVirtualBox *vboxObj);
135
    void* (*handleGetHardDisks)(IVirtualBox *vboxObj);
T
Taowei 已提交
136
    void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon);
137
    void* (*handleMachineGetStorageControllers)(IMachine *machine);
T
Taowei 已提交
138 139
    void* (*handleMachineGetMediumAttachments)(IMachine *machine);
    void* (*handleMachineGetSharedFolders)(IMachine *machine);
140 141 142
    void* (*handleSnapshotGetChildren)(ISnapshot *snapshot);
    void* (*handleMediumGetChildren)(IMedium *medium);
    void* (*handleMediumGetSnapshotIds)(IMedium *medium);
T
Taowei Luo 已提交
143
    void* (*handleMediumGetMachineIds)(IMedium *medium);
T
Taowei 已提交
144
    void* (*handleHostGetNetworkInterfaces)(IHost *host);
T
Taowei 已提交
145 146
} vboxUniformedArray;

T
Taowei 已提交
147 148 149
/* Functions for nsISupports */
typedef struct {
    nsresult (*Release)(nsISupports *nsi);
150
    nsresult (*AddRef)(nsISupports *nsi);
T
Taowei 已提交
151 152
} vboxUniformednsISupports;

T
Taowei 已提交
153 154 155
/* Functions for IVirtualBox */
typedef struct {
    nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
156
    nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIID *iid, IMachine **machine);
157
    nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine);
T
Taowei 已提交
158
    nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
T
Taowei 已提交
159
    nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host);
160
    nsresult (*CreateMachine)(vboxDriverPtr driver, virDomainDefPtr def, IMachine **machine, char *uuidstr);
161
    nsresult (*CreateHardDisk)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
T
Taowei 已提交
162
    nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
163
    nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType,
164
                             PRUint32 accessMode, IMedium **medium);
T
Taowei 已提交
165
    nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
166
    nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIID *iid, IMedium **medium);
T
Taowei 已提交
167 168
    nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
    nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
T
Taowei 已提交
169
    nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server);
T
Taowei 已提交
170 171
} vboxUniformedIVirtualBox;

T
Taowei 已提交
172 173
/* Functions for IMachine */
typedef struct {
T
Taowei 已提交
174 175
    nsresult (*AddStorageController)(IMachine *machine, PRUnichar *name,
        PRUint32 connectionType, IStorageController **controller);
T
Taowei 已提交
176 177
    nsresult (*GetStorageControllerByName)(IMachine *machine, PRUnichar *name,
                                           IStorageController **storageController);
T
Taowei 已提交
178 179 180 181 182 183
    nsresult (*AttachDevice)(IMachine *machine, PRUnichar *name,
                             PRInt32 controllerPort, PRInt32 device,
                             PRUint32 type, IMedium *medium);
    nsresult (*CreateSharedFolder)(IMachine *machine, PRUnichar *name,
                                   PRUnichar *hostPath, PRBool writable,
                                   PRBool automount);
T
Taowei 已提交
184
    nsresult (*RemoveSharedFolder)(IMachine *machine, PRUnichar *name);
185
    nsresult (*LaunchVMProcess)(vboxDriverPtr driver, IMachine *machine,
186
                                vboxIID *iid,
T
Taowei 已提交
187 188
                                PRUnichar *sessionType, PRUnichar *env,
                                IProgress **progress);
189 190
    nsresult (*Unregister)(IMachine *machine, PRUint32 cleanupMode,
                           PRUint32 *aMediaSize, IMedium ***aMedia);
191
    nsresult (*FindSnapshot)(IMachine *machine, vboxIID *iid, ISnapshot **snapshot);
T
Taowei Luo 已提交
192 193
    nsresult (*DetachDevice)(IMachine *machine, PRUnichar *name,
                             PRInt32 controllerPort, PRInt32 device);
T
Taowei 已提交
194 195
    nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible);
    nsresult (*GetState)(IMachine *machine, PRUint32 *state);
T
Taowei 已提交
196
    nsresult (*GetName)(IMachine *machine, PRUnichar **name);
197
    nsresult (*GetId)(IMachine *machine, vboxIID *iid);
T
Taowei 已提交
198 199 200 201 202 203
    nsresult (*GetBIOSSettings)(IMachine *machine, IBIOSSettings **bios);
    nsresult (*GetAudioAdapter)(IMachine *machine, IAudioAdapter **audioAdapter);
    nsresult (*GetNetworkAdapter)(IMachine *machine, PRUint32 slot, INetworkAdapter **adapter);
    nsresult (*GetChipsetType)(IMachine *machine, PRUint32 *chipsetType);
    nsresult (*GetSerialPort)(IMachine *machine, PRUint32 slot, ISerialPort **port);
    nsresult (*GetParallelPort)(IMachine *machine, PRUint32 slot, IParallelPort **port);
204
    nsresult (*GetVRDEServer)(IMachine *machine, IVRDEServer **VRDEServer);
T
Taowei 已提交
205
    nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon);
206 207
    nsresult (*GetCurrentSnapshot)(IMachine *machine, ISnapshot **currentSnapshot);
    nsresult (*GetSettingsFilePath)(IMachine *machine, PRUnichar **settingsFilePath);
T
Taowei 已提交
208
    nsresult (*GetCPUCount)(IMachine *machine, PRUint32 *CPUCount);
T
Taowei 已提交
209
    nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount);
T
Taowei 已提交
210
    nsresult (*GetMemorySize)(IMachine *machine, PRUint32 *memorySize);
T
Taowei 已提交
211
    nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize);
T
Taowei 已提交
212
    nsresult (*GetCPUProperty)(IMachine *machine, PRUint32 property, PRBool *value);
T
Taowei 已提交
213
    nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value);
T
Taowei 已提交
214
    nsresult (*GetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 *device);
T
Taowei 已提交
215
    nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device);
T
Taowei 已提交
216
    nsresult (*GetVRAMSize)(IMachine *machine, PRUint32 *VRAMSize);
T
Taowei 已提交
217
    nsresult (*SetVRAMSize)(IMachine *machine, PRUint32 VRAMSize);
T
Taowei 已提交
218
    nsresult (*GetMonitorCount)(IMachine *machine, PRUint32 *monitorCount);
T
Taowei 已提交
219
    nsresult (*SetMonitorCount)(IMachine *machine, PRUint32 monitorCount);
T
Taowei 已提交
220
    nsresult (*GetAccelerate3DEnabled)(IMachine *machine, PRBool *accelerate3DEnabled);
T
Taowei 已提交
221
    nsresult (*SetAccelerate3DEnabled)(IMachine *machine, PRBool accelerate3DEnabled);
T
Taowei 已提交
222
    nsresult (*GetAccelerate2DVideoEnabled)(IMachine *machine, PRBool *accelerate2DVideoEnabled);
T
Taowei 已提交
223
    nsresult (*SetAccelerate2DVideoEnabled)(IMachine *machine, PRBool accelerate2DVideoEnabled);
T
Taowei 已提交
224
    nsresult (*GetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar **value);
T
Taowei 已提交
225
    nsresult (*SetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar *value);
226
    nsresult (*GetSnapshotCount)(IMachine *machine, PRUint32 *snapshotCount);
T
Taowei 已提交
227
    nsresult (*SaveSettings)(IMachine *machine);
T
Taowei 已提交
228 229
} vboxUniformedIMachine;

T
Taowei 已提交
230 231
/* Functions for ISession */
typedef struct {
232 233
    nsresult (*Open)(vboxDriverPtr driver, vboxIID *iid, IMachine *machine);
    nsresult (*OpenExisting)(vboxDriverPtr driver, vboxIID *iid, IMachine *machine);
T
Taowei 已提交
234
    nsresult (*GetConsole)(ISession *session, IConsole **console);
T
Taowei 已提交
235
    nsresult (*GetMachine)(ISession *session, IMachine **machine);
T
Taowei 已提交
236 237 238 239 240 241
    nsresult (*Close)(ISession *session);
} vboxUniformedISession;

/* Functions for IConsole */
typedef struct {
    nsresult (*SaveState)(IConsole *console, IProgress **progress);
T
Taowei 已提交
242
    nsresult (*Pause)(IConsole *console);
T
Taowei 已提交
243
    nsresult (*Resume)(IConsole *console);
T
Taowei 已提交
244
    nsresult (*PowerButton)(IConsole *console);
T
Taowei 已提交
245
    nsresult (*PowerDown)(IConsole *console);
T
Taowei 已提交
246
    nsresult (*Reset)(IConsole *console);
247 248
    nsresult (*TakeSnapshot)(IConsole *console, PRUnichar *name,
                             PRUnichar *description, IProgress **progress);
249
    nsresult (*DeleteSnapshot)(IConsole *console, vboxIID *iid, IProgress **progress);
T
Taowei 已提交
250
    nsresult (*GetDisplay)(IConsole *console, IDisplay **display);
251
    nsresult (*GetKeyboard)(IConsole *console, IKeyboard **keyboard);
T
Taowei 已提交
252 253 254 255 256 257
} vboxUniformedIConsole;

/* Functions for IProgress */
typedef struct {
    nsresult (*WaitForCompletion)(IProgress *progress, PRInt32 timeout);
    nsresult (*GetResultCode)(IProgress *progress, resultCodeUnion *resultCode);
T
Taowei 已提交
258
    nsresult (*GetCompleted)(IProgress *progress, PRBool *completed);
T
Taowei 已提交
259 260
} vboxUniformedIProgress;

T
Taowei 已提交
261 262 263
/* Functions for ISystemProperties */
typedef struct {
    nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
T
Taowei 已提交
264 265 266 267 268 269 270 271 272
    nsresult (*GetMaxBootPosition)(ISystemProperties *systemProperties, PRUint32 *maxBootPosition);
    nsresult (*GetMaxNetworkAdapters)(ISystemProperties *systemProperties, PRUint32 chipset,
                                      PRUint32 *maxNetworkAdapters);
    nsresult (*GetSerialPortCount)(ISystemProperties *systemProperties, PRUint32 *SerialPortCount);
    nsresult (*GetParallelPortCount)(ISystemProperties *systemProperties, PRUint32 *ParallelPortCount);
    nsresult (*GetMaxPortCountForStorageBus)(ISystemProperties *systemProperties, PRUint32 bus,
                                             PRUint32 *maxPortCount);
    nsresult (*GetMaxDevicesPerPortForStorageBus)(ISystemProperties *systemProperties,
                                                  PRUint32 bus, PRUint32 *maxDevicesPerPort);
T
Taowei 已提交
273
    nsresult (*GetMaxGuestRAM)(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM);
T
Taowei 已提交
274 275
} vboxUniformedISystemProperties;

T
Taowei 已提交
276 277
/* Functions for IBIOSSettings */
typedef struct {
T
Taowei 已提交
278
    nsresult (*GetACPIEnabled)(IBIOSSettings *bios, PRBool *ACPIEnabled);
T
Taowei 已提交
279
    nsresult (*SetACPIEnabled)(IBIOSSettings *bios, PRBool ACPIEnabled);
T
Taowei 已提交
280
    nsresult (*GetIOAPICEnabled)(IBIOSSettings *bios, PRBool *IOAPICEnabled);
T
Taowei 已提交
281 282 283 284 285
    nsresult (*SetIOAPICEnabled)(IBIOSSettings *bios, PRBool IOAPICEnabled);
} vboxUniformedIBIOSSettings;

/* Functions for IAudioAdapter */
typedef struct {
T
Taowei 已提交
286
    nsresult (*GetEnabled)(IAudioAdapter *audioAdapter, PRBool *enabled);
T
Taowei 已提交
287
    nsresult (*SetEnabled)(IAudioAdapter *audioAdapter, PRBool enabled);
T
Taowei 已提交
288
    nsresult (*GetAudioController)(IAudioAdapter *audioAdapter, PRUint32 *audioController);
T
Taowei 已提交
289 290 291 292 293
    nsresult (*SetAudioController)(IAudioAdapter *audioAdapter, PRUint32 audioController);
} vboxUniformedIAudioAdapter;

/* Functions for INetworkAdapter */
typedef struct {
T
Taowei 已提交
294 295
    nsresult (*GetAttachmentType)(INetworkAdapter *adapter, PRUint32 *attachmentType);
    nsresult (*GetEnabled)(INetworkAdapter *adapter, PRBool *enabled);
T
Taowei 已提交
296
    nsresult (*SetEnabled)(INetworkAdapter *adapter, PRBool enabled);
T
Taowei 已提交
297
    nsresult (*GetAdapterType)(INetworkAdapter *adapter, PRUint32 *adapterType);
T
Taowei 已提交
298
    nsresult (*SetAdapterType)(INetworkAdapter *adapter, PRUint32 adapterType);
T
Taowei 已提交
299
    nsresult (*GetBridgedInterface)(INetworkAdapter *adapter, PRUnichar **bridgedInterface);
T
Taowei 已提交
300
    nsresult (*SetBridgedInterface)(INetworkAdapter *adapter, PRUnichar *bridgedInterface);
T
Taowei 已提交
301
    nsresult (*GetInternalNetwork)(INetworkAdapter *adapter, PRUnichar **internalNetwork);
T
Taowei 已提交
302
    nsresult (*SetInternalNetwork)(INetworkAdapter *adapter, PRUnichar *internalNetwork);
T
Taowei 已提交
303
    nsresult (*GetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface);
T
Taowei 已提交
304
    nsresult (*SetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface);
T
Taowei 已提交
305
    nsresult (*GetMACAddress)(INetworkAdapter *adapter, PRUnichar **MACAddress);
T
Taowei 已提交
306 307 308 309 310 311 312 313 314
    nsresult (*SetMACAddress)(INetworkAdapter *adapter, PRUnichar *MACAddress);
    nsresult (*AttachToBridgedInterface)(INetworkAdapter *adapter);
    nsresult (*AttachToInternalNetwork)(INetworkAdapter *adapter);
    nsresult (*AttachToHostOnlyInterface)(INetworkAdapter *adapter);
    nsresult (*AttachToNAT)(INetworkAdapter *adapter);
} vboxUniformedINetworkAdapter;

/* Functions for ISerialPort */
typedef struct {
T
Taowei 已提交
315
    nsresult (*GetEnabled)(ISerialPort *port, PRBool *enabled);
T
Taowei 已提交
316
    nsresult (*SetEnabled)(ISerialPort *port, PRBool enabled);
T
Taowei 已提交
317
    nsresult (*GetPath)(ISerialPort *port, PRUnichar **path);
T
Taowei 已提交
318
    nsresult (*SetPath)(ISerialPort *port, PRUnichar *path);
T
Taowei 已提交
319
    nsresult (*GetIRQ)(ISerialPort *port, PRUint32 *IRQ);
T
Taowei 已提交
320
    nsresult (*SetIRQ)(ISerialPort *port, PRUint32 IRQ);
T
Taowei 已提交
321
    nsresult (*GetIOBase)(ISerialPort *port, PRUint32 *IOBase);
T
Taowei 已提交
322
    nsresult (*SetIOBase)(ISerialPort *port, PRUint32 IOBase);
T
Taowei 已提交
323
    nsresult (*GetHostMode)(ISerialPort *port, PRUint32 *hostMode);
T
Taowei 已提交
324 325 326 327 328
    nsresult (*SetHostMode)(ISerialPort *port, PRUint32 hostMode);
} vboxUniformedISerialPort;

/* Functions for IParallelPort */
typedef struct {
T
Taowei 已提交
329
    nsresult (*GetEnabled)(IParallelPort *port, PRBool *enabled);
T
Taowei 已提交
330
    nsresult (*SetEnabled)(IParallelPort *port, PRBool enabled);
T
Taowei 已提交
331
    nsresult (*GetPath)(IParallelPort *port, PRUnichar **path);
T
Taowei 已提交
332
    nsresult (*SetPath)(IParallelPort *port, PRUnichar *path);
T
Taowei 已提交
333
    nsresult (*GetIRQ)(IParallelPort *port, PRUint32 *IRQ);
T
Taowei 已提交
334
    nsresult (*SetIRQ)(IParallelPort *port, PRUint32 IRQ);
T
Taowei 已提交
335
    nsresult (*GetIOBase)(IParallelPort *port, PRUint32 *IOBase);
T
Taowei 已提交
336 337 338
    nsresult (*SetIOBase)(IParallelPort *port, PRUint32 IOBase);
} vboxUniformedIParallelPort;

339
/* Functions for IVRDEServer */
T
Taowei 已提交
340
typedef struct {
341 342 343
    nsresult (*GetEnabled)(IVRDEServer *VRDEServer, PRBool *enabled);
    nsresult (*SetEnabled)(IVRDEServer *VRDEServer, PRBool enabled);
    nsresult (*GetPorts)(vboxDriverPtr driver, IVRDEServer *VRDEServer,
344
                         IMachine *machine, virDomainGraphicsDefPtr graphics);
345
    nsresult (*SetPorts)(vboxDriverPtr driver, IVRDEServer *VRDEServer,
T
Taowei 已提交
346
                         virDomainGraphicsDefPtr graphics);
347 348 349 350 351
    nsresult (*GetReuseSingleConnection)(IVRDEServer *VRDEServer, PRBool *enabled);
    nsresult (*SetReuseSingleConnection)(IVRDEServer *VRDEServer, PRBool enabled);
    nsresult (*GetAllowMultiConnection)(IVRDEServer *VRDEServer, PRBool *enabled);
    nsresult (*SetAllowMultiConnection)(IVRDEServer *VRDEServer, PRBool enabled);
    nsresult (*GetNetAddress)(vboxDriverPtr driver, IVRDEServer *VRDEServer,
T
Taowei 已提交
352
                              PRUnichar **netAddress);
353
    nsresult (*SetNetAddress)(vboxDriverPtr driver, IVRDEServer *VRDEServer,
T
Taowei 已提交
354
                              PRUnichar *netAddress);
355
} vboxUniformedIVRDEServer;
T
Taowei 已提交
356 357 358 359

/* Common Functions for IUSBController and IUSBDeviceFilters */
typedef struct {
    nsresult (*Enable)(IUSBCommon *USBCommon);
T
Taowei 已提交
360
    nsresult (*GetEnabled)(IUSBCommon *USBCommon, PRBool *enabled);
T
Taowei 已提交
361 362 363 364 365 366 367
    nsresult (*CreateDeviceFilter)(IUSBCommon *USBCommon, PRUnichar *name,
                                   IUSBDeviceFilter **filter);
    nsresult (*InsertDeviceFilter)(IUSBCommon *USBCommon, PRUint32 position,
                                   IUSBDeviceFilter *filter);
} vboxUniformedIUSBCommon;

typedef struct {
T
Taowei 已提交
368
    nsresult (*GetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **productId);
T
Taowei 已提交
369
    nsresult (*SetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *productId);
T
Taowei 已提交
370
    nsresult (*GetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool *active);
T
Taowei 已提交
371
    nsresult (*SetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool active);
T
Taowei 已提交
372
    nsresult (*GetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **vendorId);
T
Taowei 已提交
373 374 375 376 377
    nsresult (*SetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *vendorId);
} vboxUniformedIUSBDeviceFilter;

/* Functions for IMedium */
typedef struct {
378
    nsresult (*GetId)(IMedium *medium, vboxIID *iid);
T
Taowei 已提交
379
    nsresult (*GetLocation)(IMedium *medium, PRUnichar **location);
380
    nsresult (*GetState)(IMedium *medium, PRUint32 *state);
381
    nsresult (*GetName)(IMedium *medium, PRUnichar **name);
T
Taowei Luo 已提交
382
    nsresult (*GetSize)(IMedium *medium, PRUint64 *uSize);
T
Taowei 已提交
383
    nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly);
384
    nsresult (*GetParent)(IMedium *medium, IMedium **parent);
385 386
    nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize,
                            IMedium ***children);
387 388
    nsresult (*GetFormat)(IMedium *medium, PRUnichar **format);
    nsresult (*DeleteStorage)(IMedium *medium, IProgress **progress);
T
Taowei 已提交
389
    nsresult (*Release)(IMedium *medium);
390
    nsresult (*Close)(IMedium *medium);
T
Taowei 已提交
391
    nsresult (*SetType)(IMedium *medium, PRUint32 type);
392 393 394 395 396 397
    nsresult (*CreateDiffStorage)(IMedium *medium, IMedium *target,
                                  PRUint32 variantSize, PRUint32 *variant,
                                  IProgress **progress);
    nsresult (*CreateBaseStorage)(IMedium *medium, PRUint64 logicalSize,
                                  PRUint32 variant, IProgress **progress);
    nsresult (*GetLogicalSize)(IMedium *medium, PRUint64 *uLogicalSize);
T
Taowei 已提交
398 399
} vboxUniformedIMedium;

T
Taowei 已提交
400 401
/* Functions for IMediumAttachment */
typedef struct {
402
    nsresult (*GetMedium)(IMediumAttachment *mediumAttachment, IMedium **medium);
T
Taowei 已提交
403 404 405 406 407 408 409 410 411 412
    nsresult (*GetController)(IMediumAttachment *mediumAttachment, PRUnichar **controller);
    nsresult (*GetType)(IMediumAttachment *mediumAttachment, PRUint32 *type);
    nsresult (*GetPort)(IMediumAttachment *mediumAttachment, PRInt32 *port);
    nsresult (*GetDevice)(IMediumAttachment *mediumAttachment, PRInt32 *device);
} vboxUniformedIMediumAttachment;


/* Functions for IStorageController */
typedef struct {
    nsresult (*GetBus)(IStorageController *storageController, PRUint32 *bus);
413 414
    nsresult (*SetControllerType)(IStorageController *storageController, PRUint32 controllerType);
    nsresult (*GetControllerType)(IStorageController *storageController, PRUint32 *controllerType);
T
Taowei 已提交
415 416 417 418 419 420 421 422 423
} vboxUniformedIStorageController;

/* Functions for ISharedFolder */
typedef struct {
    nsresult (*GetHostPath)(ISharedFolder *sharedFolder, PRUnichar **hostPath);
    nsresult (*GetName)(ISharedFolder *sharedFolder, PRUnichar **name);
    nsresult (*GetWritable)(ISharedFolder *sharedFolder, PRBool *writable);
} vboxUniformedISharedFolder;

424 425 426
/* Functions for ISnapshot */
typedef struct {
    nsresult (*GetName)(ISnapshot *snapshot, PRUnichar **name);
427
    nsresult (*GetId)(ISnapshot *snapshot, vboxIID *iid);
428 429 430 431 432 433 434
    nsresult (*GetMachine)(ISnapshot *snapshot, IMachine **machine);
    nsresult (*GetDescription)(ISnapshot *snapshot, PRUnichar **description);
    nsresult (*GetTimeStamp)(ISnapshot *snapshot, PRInt64 *timeStamp);
    nsresult (*GetParent)(ISnapshot *snapshot, ISnapshot **parent);
    nsresult (*GetOnline)(ISnapshot *snapshot, PRBool *online);
} vboxUniformedISnapshot;

T
Taowei 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
/* Functions for IDisplay */
typedef struct {
    nsresult (*GetScreenResolution)(IDisplay *display,
                                    PRUint32 screenId,
                                    PRUint32 *width,
                                    PRUint32 *height,
                                    PRUint32 *bitsPerPixel,
                                    PRInt32 *xOrigin,
                                    PRInt32 *yOrigin);
    nsresult (*TakeScreenShotPNGToArray)(IDisplay *display,
                                         PRUint32 screenId,
                                         PRUint32 width,
                                         PRUint32 height,
                                         PRUint32 *screenDataSize,
                                         PRUint8** screenData);
} vboxUniformedIDisplay;

T
Taowei 已提交
452 453
/* Functions for IHost */
typedef struct {
454
    nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIID *iid,
T
Taowei 已提交
455
                                             IHostNetworkInterface **networkInterface);
T
Taowei 已提交
456 457
    nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name,
                                               IHostNetworkInterface **networkInterface);
458
    nsresult (*CreateHostOnlyNetworkInterface)(vboxDriverPtr driver,
T
Taowei 已提交
459 460
                                               IHost *host, char *name,
                                               IHostNetworkInterface **networkInterface);
461
    nsresult (*RemoveHostOnlyNetworkInterface)(IHost *host, vboxIID *iid,
T
Taowei 已提交
462
                                               IProgress **progress);
T
Taowei 已提交
463 464
} vboxUniformedIHost;

T
Taowei 已提交
465 466 467 468
/* Functions for IHostNetworkInterface */
typedef struct {
    nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
    nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
T
Taowei 已提交
469
    nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name);
470
    nsresult (*GetId)(IHostNetworkInterface *hni, vboxIID *iid);
T
Taowei 已提交
471 472 473
    nsresult (*GetHardwareAddress)(IHostNetworkInterface *hni, PRUnichar **hardwareAddress);
    nsresult (*GetIPAddress)(IHostNetworkInterface *hni, PRUnichar **IPAddress);
    nsresult (*GetNetworkMask)(IHostNetworkInterface *hni, PRUnichar **networkMask);
T
Taowei 已提交
474 475 476 477
    nsresult (*EnableStaticIPConfig)(IHostNetworkInterface *hni, PRUnichar *IPAddress,
                                     PRUnichar *networkMask);
    nsresult (*EnableDynamicIPConfig)(IHostNetworkInterface *hni);
    nsresult (*DHCPRediscover)(IHostNetworkInterface *hni);
T
Taowei 已提交
478 479
} vboxUniformedIHNInterface;

T
Taowei 已提交
480 481
/* Functions for IDHCPServer */
typedef struct {
T
Taowei 已提交
482 483 484 485
    nsresult (*GetIPAddress)(IDHCPServer *dhcpServer, PRUnichar **IPAddress);
    nsresult (*GetNetworkMask)(IDHCPServer *dhcpServer, PRUnichar **networkMask);
    nsresult (*GetLowerIP)(IDHCPServer *dhcpServer, PRUnichar **lowerIP);
    nsresult (*GetUpperIP)(IDHCPServer *dhcpServer, PRUnichar **upperIP);
T
Taowei 已提交
486 487 488 489 490 491
    nsresult (*SetEnabled)(IDHCPServer *dhcpServer, PRBool enabled);
    nsresult (*SetConfiguration)(IDHCPServer *dhcpServer, PRUnichar *IPAddress,
                                 PRUnichar *networkMask, PRUnichar *FromIPAddress,
                                 PRUnichar *ToIPAddress);
    nsresult (*Start)(IDHCPServer *dhcpServer, PRUnichar *networkName,
                      PRUnichar *trunkName, PRUnichar *trunkType);
T
Taowei 已提交
492
    nsresult (*Stop)(IDHCPServer *dhcpServer);
T
Taowei 已提交
493 494
} vboxUniformedIDHCPServer;

495 496 497 498 499 500
typedef struct {
    nsresult (*PutScancode)(IKeyboard *keyboard, PRInt32 scancode);
    nsresult (*PutScancodes)(IKeyboard *keyboard, PRUint32 scancodesSize,
                             PRInt32 *scanCodes, PRUint32 *codesStored);
} vboxUniformedIKeyboard;

T
Taowei 已提交
501 502
typedef struct {
    bool (*Online)(PRUint32 state);
503
    bool (*Inactive)(PRUint32 state);
T
Taowei 已提交
504
    bool (*NotStart)(PRUint32 state);
T
Taowei 已提交
505
    bool (*Running)(PRUint32 state);
T
Taowei 已提交
506
    bool (*Paused)(PRUint32 state);
T
Taowei 已提交
507
    bool (*PoweredOff)(PRUint32 state);
T
Taowei 已提交
508 509
} uniformedMachineStateChecker;

T
Taowei 已提交
510 511 512 513 514
typedef struct {
    /* vbox API version */
    uint32_t APIVersion;
    uint32_t XPCOMCVersion;
    /* vbox APIs */
515
    nsresult (*unregisterMachine)(vboxDriverPtr driver, vboxIID *iid, IMachine **machine);
T
Taowei 已提交
516
    void (*deleteConfig)(IMachine *machine);
517
    void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxDriverPtr driver, IMachine *machine);
T
Taowei 已提交
518
    virDomainState (*vboxConvertState)(PRUint32 state);
519
    int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
T
Taowei 已提交
520
    vboxUniformedPFN UPFN;
T
Taowei 已提交
521
    vboxUniformedIID UIID;
T
Taowei 已提交
522
    vboxUniformedArray UArray;
T
Taowei 已提交
523
    vboxUniformednsISupports nsUISupports;
T
Taowei 已提交
524
    vboxUniformedIVirtualBox UIVirtualBox;
T
Taowei 已提交
525
    vboxUniformedIMachine UIMachine;
T
Taowei 已提交
526 527 528
    vboxUniformedISession UISession;
    vboxUniformedIConsole UIConsole;
    vboxUniformedIProgress UIProgress;
T
Taowei 已提交
529
    vboxUniformedISystemProperties UISystemProperties;
T
Taowei 已提交
530 531 532 533 534
    vboxUniformedIBIOSSettings UIBIOSSettings;
    vboxUniformedIAudioAdapter UIAudioAdapter;
    vboxUniformedINetworkAdapter UINetworkAdapter;
    vboxUniformedISerialPort UISerialPort;
    vboxUniformedIParallelPort UIParallelPort;
535
    vboxUniformedIVRDEServer UIVRDEServer;
T
Taowei 已提交
536 537 538
    vboxUniformedIUSBCommon UIUSBCommon;
    vboxUniformedIUSBDeviceFilter UIUSBDeviceFilter;
    vboxUniformedIMedium UIMedium;
T
Taowei 已提交
539 540 541
    vboxUniformedIMediumAttachment UIMediumAttachment;
    vboxUniformedIStorageController UIStorageController;
    vboxUniformedISharedFolder UISharedFolder;
542
    vboxUniformedISnapshot UISnapshot;
T
Taowei 已提交
543
    vboxUniformedIDisplay UIDisplay;
T
Taowei 已提交
544
    vboxUniformedIHost UIHost;
T
Taowei 已提交
545
    vboxUniformedIHNInterface UIHNInterface;
T
Taowei 已提交
546
    vboxUniformedIDHCPServer UIDHCPServer;
547
    vboxUniformedIKeyboard UIKeyboard;
T
Taowei 已提交
548
    uniformedMachineStateChecker machineStateChecker;
T
Taowei 已提交
549
    /* vbox API features */
T
Taowei 已提交
550
    bool chipsetType;
551
    bool vboxSnapshotRedefine;
T
Taowei 已提交
552 553
} vboxUniformedAPI;

T
Taowei 已提交
554 555
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
                                    const unsigned char *uuid);
T
Taowei 已提交
556 557

/* Version specified functions for installing uniformed API */
D
Dawid Zamirski 已提交
558
void vbox52InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
559
void vbox60InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);