vbox_uniformed_api.h 30.2 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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
 *
 * 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/>.
 */

#ifndef VBOX_UNIFORMED_API_H
# define VBOX_UNIFORMED_API_H

# include "internal.h"

/* 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,
 * pFuncs, vboxCallback and vboxQueue). The file should be included
 * 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
 * defined by vbox_CAPI_v2.2.h.
 *
 * The vbox_common.c, it is used to generate common codes for all vbox
 * versions. Bacause the same member varible's offset in a vbox struct
 * may change between different vbox versions. The vbox_common.c
 * shouldn't directly use struct's member varibles defined in
 * 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
 *  * In vbox_driver.c, this file is included after vbox_glue.h
 *  * In vbox_common.c, this file is included after vbox_common.h
 *
 */

T
Taowei 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/* Extracted define from vbox_tmpl.c */

# ifdef WIN32
struct _vboxIID_v2_x_WIN32 {
    /* IID is represented by a GUID value. */
    GUID value;
};
# endif /* !WIN32 */

struct _vboxIID_v2_x {
    /* IID is represented by a pointer to a nsID. */
    nsID *value;

    /* backing is used in cases where we need to create or copy an IID.
     * We cannot allocate memory that can be freed by ComUnallocMem.
     * Therefore, we use this stack allocated nsID instead. */
    nsID backing;
};

struct _vboxIID_v3_x {
    /* 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;
};

typedef union {
# ifdef WIN32
    struct _vboxIID_v2_x_WIN32 vboxIID_v2_x_WIN32;
# endif /* !WIN32 */
    struct _vboxIID_v2_x vboxIID_v2_x;
    struct _vboxIID_v3_x vboxIID_v3_x;
} vboxIIDUnion;

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

99 100
struct _vboxCallback {
    struct IVirtualBoxCallback_vtbl *vtbl;
T
Taowei 已提交
101
    virConnectPtr conn;
102 103
    int vboxCallBackRefCount;
};
T
Taowei 已提交
104

105 106
typedef struct _vboxCallback vboxCallback;
typedef struct _vboxCallback *vboxCallbackPtr;
T
Taowei 已提交
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
struct _vboxDriver {
    virObjectLockable parent;

    virCapsPtr caps;
    virDomainXMLOptionPtr xmlopt;
    virObjectEventStatePtr domainEventState;

    /* vbox API initialization members */
    PCVBOXXPCOM pFuncs;
    IVirtualBox *vboxObj;
    ISession *vboxSession;
# if VBOX_API_VERSION == 4002020 || VBOX_API_VERSION >= 4003004
    IVirtualBoxClient *vboxClient;
# endif

    int fdWatch;
124
    vboxCallbackPtr vboxCallback;
125 126 127 128 129 130 131 132 133 134 135 136 137 138
# if VBOX_API_VERSION > 2002000 && VBOX_API_VERSION < 4000000
    nsIEventQueue *vboxQueue;
# else
    void *vboxQueue;
# endif
    unsigned long version;

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

typedef struct _vboxDriver vboxDriver;
typedef struct _vboxDriver *vboxDriverPtr;

T
Taowei 已提交
139 140 141 142 143 144
/* vboxUniformedAPI gives vbox_common.c a uniformed layer to see
 * vbox API.
 */

/* Functions for pFuncs */
typedef struct {
145 146
    int (*Initialize)(vboxDriverPtr driver);
    void (*Uninitialize)(vboxDriverPtr driver);
T
Taowei 已提交
147 148 149 150 151 152 153
    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 已提交
154 155 156
/* Functions for vboxIID */
typedef struct {
    void (*vboxIIDInitialize)(vboxIIDUnion *iidu);
157 158 159 160 161 162 163
    void (*vboxIIDUnalloc)(vboxDriverPtr driver, vboxIIDUnion *iidu);
    void (*vboxIIDToUUID)(vboxDriverPtr driver, vboxIIDUnion *iidu, unsigned char *uuid);
    void (*vboxIIDFromUUID)(vboxDriverPtr driver, vboxIIDUnion *iidu, const unsigned char *uuid);
    bool (*vboxIIDIsEqual)(vboxDriverPtr driver, vboxIIDUnion *iidu1, vboxIIDUnion *iidu2);
    void (*vboxIIDFromArrayItem)(vboxDriverPtr driver, vboxIIDUnion *iidu, vboxArray *array, int idx);
    void (*vboxIIDToUtf8)(vboxDriverPtr driver, vboxIIDUnion *iidu, char **utf8);
    void (*DEBUGIID)(vboxDriverPtr driver, const char *msg, vboxIIDUnion *iidu);
T
Taowei 已提交
164 165
} vboxUniformedIID;

T
Taowei 已提交
166 167 168
/* Functions for vboxArray */
typedef struct {
    nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter);
169
    nsresult (*vboxArrayGetWithIIDArg)(vboxArray *array, void *self, void *getter, vboxIIDUnion *iidu);
T
Taowei 已提交
170
    void (*vboxArrayRelease)(vboxArray *array);
T
Taowei Luo 已提交
171
    void (*vboxArrayUnalloc)(vboxArray *array);
T
Taowei 已提交
172 173
    /* Generate function pointers for vboxArrayGet */
    void* (*handleGetMachines)(IVirtualBox *vboxObj);
174
    void* (*handleGetHardDisks)(IVirtualBox *vboxObj);
T
Taowei 已提交
175 176 177
    void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon);
    void* (*handleMachineGetMediumAttachments)(IMachine *machine);
    void* (*handleMachineGetSharedFolders)(IMachine *machine);
178 179 180
    void* (*handleSnapshotGetChildren)(ISnapshot *snapshot);
    void* (*handleMediumGetChildren)(IMedium *medium);
    void* (*handleMediumGetSnapshotIds)(IMedium *medium);
T
Taowei Luo 已提交
181
    void* (*handleMediumGetMachineIds)(IMedium *medium);
T
Taowei 已提交
182
    void* (*handleHostGetNetworkInterfaces)(IHost *host);
T
Taowei 已提交
183 184
} vboxUniformedArray;

T
Taowei 已提交
185 186 187
/* Functions for nsISupports */
typedef struct {
    nsresult (*Release)(nsISupports *nsi);
188
    nsresult (*AddRef)(nsISupports *nsi);
T
Taowei 已提交
189 190
} vboxUniformednsISupports;

T
Taowei 已提交
191 192 193
/* Functions for IVirtualBox */
typedef struct {
    nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
T
Taowei 已提交
194
    nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine);
195
    nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine);
T
Taowei 已提交
196
    nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
T
Taowei 已提交
197
    nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host);
198
    nsresult (*CreateMachine)(vboxDriverPtr driver, virDomainDefPtr def, IMachine **machine, char *uuidstr);
199
    nsresult (*CreateHardDisk)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
T
Taowei 已提交
200
    nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
201
    nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType,
202
                             PRUint32 accessMode, IMedium **medium);
T
Taowei 已提交
203
    nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
204
    nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMedium **medium);
T
Taowei 已提交
205 206
    nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
    nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
T
Taowei 已提交
207
    nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server);
T
Taowei 已提交
208 209
} vboxUniformedIVirtualBox;

T
Taowei 已提交
210 211
/* Functions for IMachine */
typedef struct {
T
Taowei 已提交
212 213
    nsresult (*AddStorageController)(IMachine *machine, PRUnichar *name,
        PRUint32 connectionType, IStorageController **controller);
T
Taowei 已提交
214 215
    nsresult (*GetStorageControllerByName)(IMachine *machine, PRUnichar *name,
                                           IStorageController **storageController);
T
Taowei 已提交
216 217 218 219 220 221
    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 已提交
222
    nsresult (*RemoveSharedFolder)(IMachine *machine, PRUnichar *name);
223
    nsresult (*LaunchVMProcess)(vboxDriverPtr driver, IMachine *machine,
T
Taowei 已提交
224 225 226
                                vboxIIDUnion *iidu,
                                PRUnichar *sessionType, PRUnichar *env,
                                IProgress **progress);
227 228
    nsresult (*Unregister)(IMachine *machine, PRUint32 cleanupMode,
                           PRUint32 *aMediaSize, IMedium ***aMedia);
229
    nsresult (*FindSnapshot)(IMachine *machine, vboxIIDUnion *iidu, ISnapshot **snapshot);
T
Taowei Luo 已提交
230 231
    nsresult (*DetachDevice)(IMachine *machine, PRUnichar *name,
                             PRInt32 controllerPort, PRInt32 device);
T
Taowei 已提交
232 233
    nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible);
    nsresult (*GetState)(IMachine *machine, PRUint32 *state);
T
Taowei 已提交
234 235
    nsresult (*GetName)(IMachine *machine, PRUnichar **name);
    nsresult (*GetId)(IMachine *machine, vboxIIDUnion *iidu);
T
Taowei 已提交
236 237 238 239 240 241 242 243
    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);
    nsresult (*GetVRDxServer)(IMachine *machine, IVRDxServer **VRDxServer);
    nsresult (*GetUSBCommon)(IMachine *machine, IUSBCommon **USBCommon);
244 245
    nsresult (*GetCurrentSnapshot)(IMachine *machine, ISnapshot **currentSnapshot);
    nsresult (*GetSettingsFilePath)(IMachine *machine, PRUnichar **settingsFilePath);
T
Taowei 已提交
246
    nsresult (*GetCPUCount)(IMachine *machine, PRUint32 *CPUCount);
T
Taowei 已提交
247
    nsresult (*SetCPUCount)(IMachine *machine, PRUint32 CPUCount);
T
Taowei 已提交
248
    nsresult (*GetMemorySize)(IMachine *machine, PRUint32 *memorySize);
T
Taowei 已提交
249
    nsresult (*SetMemorySize)(IMachine *machine, PRUint32 memorySize);
T
Taowei 已提交
250
    nsresult (*GetCPUProperty)(IMachine *machine, PRUint32 property, PRBool *value);
T
Taowei 已提交
251
    nsresult (*SetCPUProperty)(IMachine *machine, PRUint32 property, PRBool value);
T
Taowei 已提交
252
    nsresult (*GetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 *device);
T
Taowei 已提交
253
    nsresult (*SetBootOrder)(IMachine *machine, PRUint32 position, PRUint32 device);
T
Taowei 已提交
254
    nsresult (*GetVRAMSize)(IMachine *machine, PRUint32 *VRAMSize);
T
Taowei 已提交
255
    nsresult (*SetVRAMSize)(IMachine *machine, PRUint32 VRAMSize);
T
Taowei 已提交
256
    nsresult (*GetMonitorCount)(IMachine *machine, PRUint32 *monitorCount);
T
Taowei 已提交
257
    nsresult (*SetMonitorCount)(IMachine *machine, PRUint32 monitorCount);
T
Taowei 已提交
258
    nsresult (*GetAccelerate3DEnabled)(IMachine *machine, PRBool *accelerate3DEnabled);
T
Taowei 已提交
259
    nsresult (*SetAccelerate3DEnabled)(IMachine *machine, PRBool accelerate3DEnabled);
T
Taowei 已提交
260
    nsresult (*GetAccelerate2DVideoEnabled)(IMachine *machine, PRBool *accelerate2DVideoEnabled);
T
Taowei 已提交
261
    nsresult (*SetAccelerate2DVideoEnabled)(IMachine *machine, PRBool accelerate2DVideoEnabled);
T
Taowei 已提交
262
    nsresult (*GetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar **value);
T
Taowei 已提交
263
    nsresult (*SetExtraData)(IMachine *machine, PRUnichar *key, PRUnichar *value);
264
    nsresult (*GetSnapshotCount)(IMachine *machine, PRUint32 *snapshotCount);
T
Taowei 已提交
265
    nsresult (*SaveSettings)(IMachine *machine);
T
Taowei 已提交
266 267
} vboxUniformedIMachine;

T
Taowei 已提交
268 269
/* Functions for ISession */
typedef struct {
270 271
    nsresult (*Open)(vboxDriverPtr driver, vboxIIDUnion *iidu, IMachine *machine);
    nsresult (*OpenExisting)(vboxDriverPtr driver, vboxIIDUnion *iidu, IMachine *machine);
T
Taowei 已提交
272
    nsresult (*GetConsole)(ISession *session, IConsole **console);
T
Taowei 已提交
273
    nsresult (*GetMachine)(ISession *session, IMachine **machine);
T
Taowei 已提交
274 275 276 277 278 279
    nsresult (*Close)(ISession *session);
} vboxUniformedISession;

/* Functions for IConsole */
typedef struct {
    nsresult (*SaveState)(IConsole *console, IProgress **progress);
T
Taowei 已提交
280
    nsresult (*Pause)(IConsole *console);
T
Taowei 已提交
281
    nsresult (*Resume)(IConsole *console);
T
Taowei 已提交
282
    nsresult (*PowerButton)(IConsole *console);
T
Taowei 已提交
283
    nsresult (*PowerDown)(IConsole *console);
T
Taowei 已提交
284
    nsresult (*Reset)(IConsole *console);
285 286
    nsresult (*TakeSnapshot)(IConsole *console, PRUnichar *name,
                             PRUnichar *description, IProgress **progress);
T
Taowei 已提交
287
    nsresult (*DeleteSnapshot)(IConsole *console, vboxIIDUnion *iidu, IProgress **progress);
T
Taowei 已提交
288
    nsresult (*GetDisplay)(IConsole *console, IDisplay **display);
289
    nsresult (*GetKeyboard)(IConsole *console, IKeyboard **keyboard);
T
Taowei 已提交
290 291 292 293 294 295
} vboxUniformedIConsole;

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

T
Taowei 已提交
299 300 301
/* Functions for ISystemProperties */
typedef struct {
    nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
T
Taowei 已提交
302 303 304 305 306 307 308 309 310
    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 已提交
311
    nsresult (*GetMaxGuestRAM)(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM);
T
Taowei 已提交
312 313
} vboxUniformedISystemProperties;

T
Taowei 已提交
314 315
/* Functions for IBIOSSettings */
typedef struct {
T
Taowei 已提交
316
    nsresult (*GetACPIEnabled)(IBIOSSettings *bios, PRBool *ACPIEnabled);
T
Taowei 已提交
317
    nsresult (*SetACPIEnabled)(IBIOSSettings *bios, PRBool ACPIEnabled);
T
Taowei 已提交
318
    nsresult (*GetIOAPICEnabled)(IBIOSSettings *bios, PRBool *IOAPICEnabled);
T
Taowei 已提交
319 320 321 322 323
    nsresult (*SetIOAPICEnabled)(IBIOSSettings *bios, PRBool IOAPICEnabled);
} vboxUniformedIBIOSSettings;

/* Functions for IAudioAdapter */
typedef struct {
T
Taowei 已提交
324
    nsresult (*GetEnabled)(IAudioAdapter *audioAdapter, PRBool *enabled);
T
Taowei 已提交
325
    nsresult (*SetEnabled)(IAudioAdapter *audioAdapter, PRBool enabled);
T
Taowei 已提交
326
    nsresult (*GetAudioController)(IAudioAdapter *audioAdapter, PRUint32 *audioController);
T
Taowei 已提交
327 328 329 330 331
    nsresult (*SetAudioController)(IAudioAdapter *audioAdapter, PRUint32 audioController);
} vboxUniformedIAudioAdapter;

/* Functions for INetworkAdapter */
typedef struct {
T
Taowei 已提交
332 333
    nsresult (*GetAttachmentType)(INetworkAdapter *adapter, PRUint32 *attachmentType);
    nsresult (*GetEnabled)(INetworkAdapter *adapter, PRBool *enabled);
T
Taowei 已提交
334
    nsresult (*SetEnabled)(INetworkAdapter *adapter, PRBool enabled);
T
Taowei 已提交
335
    nsresult (*GetAdapterType)(INetworkAdapter *adapter, PRUint32 *adapterType);
T
Taowei 已提交
336
    nsresult (*SetAdapterType)(INetworkAdapter *adapter, PRUint32 adapterType);
T
Taowei 已提交
337
    nsresult (*GetBridgedInterface)(INetworkAdapter *adapter, PRUnichar **bridgedInterface);
T
Taowei 已提交
338
    nsresult (*SetBridgedInterface)(INetworkAdapter *adapter, PRUnichar *bridgedInterface);
T
Taowei 已提交
339
    nsresult (*GetInternalNetwork)(INetworkAdapter *adapter, PRUnichar **internalNetwork);
T
Taowei 已提交
340
    nsresult (*SetInternalNetwork)(INetworkAdapter *adapter, PRUnichar *internalNetwork);
T
Taowei 已提交
341
    nsresult (*GetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface);
T
Taowei 已提交
342
    nsresult (*SetHostOnlyInterface)(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface);
T
Taowei 已提交
343
    nsresult (*GetMACAddress)(INetworkAdapter *adapter, PRUnichar **MACAddress);
T
Taowei 已提交
344 345 346 347 348 349 350 351 352
    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 已提交
353
    nsresult (*GetEnabled)(ISerialPort *port, PRBool *enabled);
T
Taowei 已提交
354
    nsresult (*SetEnabled)(ISerialPort *port, PRBool enabled);
T
Taowei 已提交
355
    nsresult (*GetPath)(ISerialPort *port, PRUnichar **path);
T
Taowei 已提交
356
    nsresult (*SetPath)(ISerialPort *port, PRUnichar *path);
T
Taowei 已提交
357
    nsresult (*GetIRQ)(ISerialPort *port, PRUint32 *IRQ);
T
Taowei 已提交
358
    nsresult (*SetIRQ)(ISerialPort *port, PRUint32 IRQ);
T
Taowei 已提交
359
    nsresult (*GetIOBase)(ISerialPort *port, PRUint32 *IOBase);
T
Taowei 已提交
360
    nsresult (*SetIOBase)(ISerialPort *port, PRUint32 IOBase);
T
Taowei 已提交
361
    nsresult (*GetHostMode)(ISerialPort *port, PRUint32 *hostMode);
T
Taowei 已提交
362 363 364 365 366
    nsresult (*SetHostMode)(ISerialPort *port, PRUint32 hostMode);
} vboxUniformedISerialPort;

/* Functions for IParallelPort */
typedef struct {
T
Taowei 已提交
367
    nsresult (*GetEnabled)(IParallelPort *port, PRBool *enabled);
T
Taowei 已提交
368
    nsresult (*SetEnabled)(IParallelPort *port, PRBool enabled);
T
Taowei 已提交
369
    nsresult (*GetPath)(IParallelPort *port, PRUnichar **path);
T
Taowei 已提交
370
    nsresult (*SetPath)(IParallelPort *port, PRUnichar *path);
T
Taowei 已提交
371
    nsresult (*GetIRQ)(IParallelPort *port, PRUint32 *IRQ);
T
Taowei 已提交
372
    nsresult (*SetIRQ)(IParallelPort *port, PRUint32 IRQ);
T
Taowei 已提交
373
    nsresult (*GetIOBase)(IParallelPort *port, PRUint32 *IOBase);
T
Taowei 已提交
374 375 376 377 378
    nsresult (*SetIOBase)(IParallelPort *port, PRUint32 IOBase);
} vboxUniformedIParallelPort;

/* Functions for IVRDPServer and IVRDEServer */
typedef struct {
T
Taowei 已提交
379
    nsresult (*GetEnabled)(IVRDxServer *VRDxServer, PRBool *enabled);
T
Taowei 已提交
380
    nsresult (*SetEnabled)(IVRDxServer *VRDxServer, PRBool enabled);
381
    nsresult (*GetPorts)(vboxDriverPtr driver, IVRDxServer *VRDxServer,
T
Taowei 已提交
382
                         virDomainGraphicsDefPtr graphics);
383
    nsresult (*SetPorts)(vboxDriverPtr driver, IVRDxServer *VRDxServer,
T
Taowei 已提交
384
                         virDomainGraphicsDefPtr graphics);
T
Taowei 已提交
385
    nsresult (*GetReuseSingleConnection)(IVRDxServer *VRDxServer, PRBool *enabled);
T
Taowei 已提交
386
    nsresult (*SetReuseSingleConnection)(IVRDxServer *VRDxServer, PRBool enabled);
T
Taowei 已提交
387
    nsresult (*GetAllowMultiConnection)(IVRDxServer *VRDxServer, PRBool *enabled);
T
Taowei 已提交
388
    nsresult (*SetAllowMultiConnection)(IVRDxServer *VRDxServer, PRBool enabled);
389
    nsresult (*GetNetAddress)(vboxDriverPtr driver, IVRDxServer *VRDxServer,
T
Taowei 已提交
390
                              PRUnichar **netAddress);
391
    nsresult (*SetNetAddress)(vboxDriverPtr driver, IVRDxServer *VRDxServer,
T
Taowei 已提交
392 393 394 395 396 397
                              PRUnichar *netAddress);
} vboxUniformedIVRDxServer;

/* Common Functions for IUSBController and IUSBDeviceFilters */
typedef struct {
    nsresult (*Enable)(IUSBCommon *USBCommon);
T
Taowei 已提交
398
    nsresult (*GetEnabled)(IUSBCommon *USBCommon, PRBool *enabled);
T
Taowei 已提交
399 400 401 402 403 404 405
    nsresult (*CreateDeviceFilter)(IUSBCommon *USBCommon, PRUnichar *name,
                                   IUSBDeviceFilter **filter);
    nsresult (*InsertDeviceFilter)(IUSBCommon *USBCommon, PRUint32 position,
                                   IUSBDeviceFilter *filter);
} vboxUniformedIUSBCommon;

typedef struct {
T
Taowei 已提交
406
    nsresult (*GetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **productId);
T
Taowei 已提交
407
    nsresult (*SetProductId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *productId);
T
Taowei 已提交
408
    nsresult (*GetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool *active);
T
Taowei 已提交
409
    nsresult (*SetActive)(IUSBDeviceFilter *USBDeviceFilter, PRBool active);
T
Taowei 已提交
410
    nsresult (*GetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **vendorId);
T
Taowei 已提交
411 412 413 414 415 416
    nsresult (*SetVendorId)(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *vendorId);
} vboxUniformedIUSBDeviceFilter;

/* Functions for IMedium */
typedef struct {
    nsresult (*GetId)(IMedium *medium, vboxIIDUnion *iidu);
T
Taowei 已提交
417
    nsresult (*GetLocation)(IMedium *medium, PRUnichar **location);
418
    nsresult (*GetState)(IMedium *medium, PRUint32 *state);
419
    nsresult (*GetName)(IMedium *medium, PRUnichar **name);
T
Taowei Luo 已提交
420
    nsresult (*GetSize)(IMedium *medium, PRUint64 *uSize);
T
Taowei 已提交
421
    nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly);
422
    nsresult (*GetParent)(IMedium *medium, IMedium **parent);
423 424
    nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize,
                            IMedium ***children);
425 426
    nsresult (*GetFormat)(IMedium *medium, PRUnichar **format);
    nsresult (*DeleteStorage)(IMedium *medium, IProgress **progress);
T
Taowei 已提交
427
    nsresult (*Release)(IMedium *medium);
428
    nsresult (*Close)(IMedium *medium);
T
Taowei 已提交
429
    nsresult (*SetType)(IMedium *medium, PRUint32 type);
430 431 432 433 434 435
    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 已提交
436 437
} vboxUniformedIMedium;

T
Taowei 已提交
438 439
/* Functions for IMediumAttachment */
typedef struct {
440
    nsresult (*GetMedium)(IMediumAttachment *mediumAttachment, IMedium **medium);
T
Taowei 已提交
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    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);
} 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;

460 461 462 463 464 465 466 467 468 469 470
/* Functions for ISnapshot */
typedef struct {
    nsresult (*GetName)(ISnapshot *snapshot, PRUnichar **name);
    nsresult (*GetId)(ISnapshot *snapshot, vboxIIDUnion *iidu);
    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 已提交
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
/* 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 已提交
488 489 490 491
/* Functions for IHost */
typedef struct {
    nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIIDUnion *iidu,
                                             IHostNetworkInterface **networkInterface);
T
Taowei 已提交
492 493
    nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name,
                                               IHostNetworkInterface **networkInterface);
494
    nsresult (*CreateHostOnlyNetworkInterface)(vboxDriverPtr driver,
T
Taowei 已提交
495 496
                                               IHost *host, char *name,
                                               IHostNetworkInterface **networkInterface);
T
Taowei 已提交
497 498
    nsresult (*RemoveHostOnlyNetworkInterface)(IHost *host, vboxIIDUnion *iidu,
                                               IProgress **progress);
T
Taowei 已提交
499 500
} vboxUniformedIHost;

T
Taowei 已提交
501 502 503 504
/* Functions for IHostNetworkInterface */
typedef struct {
    nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
    nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
T
Taowei 已提交
505
    nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name);
T
Taowei 已提交
506
    nsresult (*GetId)(IHostNetworkInterface *hni, vboxIIDUnion *iidu);
T
Taowei 已提交
507 508 509
    nsresult (*GetHardwareAddress)(IHostNetworkInterface *hni, PRUnichar **hardwareAddress);
    nsresult (*GetIPAddress)(IHostNetworkInterface *hni, PRUnichar **IPAddress);
    nsresult (*GetNetworkMask)(IHostNetworkInterface *hni, PRUnichar **networkMask);
T
Taowei 已提交
510 511 512 513
    nsresult (*EnableStaticIPConfig)(IHostNetworkInterface *hni, PRUnichar *IPAddress,
                                     PRUnichar *networkMask);
    nsresult (*EnableDynamicIPConfig)(IHostNetworkInterface *hni);
    nsresult (*DHCPRediscover)(IHostNetworkInterface *hni);
T
Taowei 已提交
514 515
} vboxUniformedIHNInterface;

T
Taowei 已提交
516 517
/* Functions for IDHCPServer */
typedef struct {
T
Taowei 已提交
518 519 520 521
    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 已提交
522 523 524 525 526 527
    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 已提交
528
    nsresult (*Stop)(IDHCPServer *dhcpServer);
T
Taowei 已提交
529 530
} vboxUniformedIDHCPServer;

531 532 533 534 535 536
typedef struct {
    nsresult (*PutScancode)(IKeyboard *keyboard, PRInt32 scancode);
    nsresult (*PutScancodes)(IKeyboard *keyboard, PRUint32 scancodesSize,
                             PRInt32 *scanCodes, PRUint32 *codesStored);
} vboxUniformedIKeyboard;

T
Taowei 已提交
537 538
typedef struct {
    bool (*Online)(PRUint32 state);
539
    bool (*Inactive)(PRUint32 state);
T
Taowei 已提交
540
    bool (*NotStart)(PRUint32 state);
T
Taowei 已提交
541
    bool (*Running)(PRUint32 state);
T
Taowei 已提交
542
    bool (*Paused)(PRUint32 state);
T
Taowei 已提交
543
    bool (*PoweredOff)(PRUint32 state);
T
Taowei 已提交
544 545
} uniformedMachineStateChecker;

T
Taowei 已提交
546 547 548 549 550
typedef struct {
    /* vbox API version */
    uint32_t APIVersion;
    uint32_t XPCOMCVersion;
    /* vbox APIs */
551
    int (*initializeDomainEvent)(vboxDriverPtr driver);
552 553
    void (*detachDevices)(vboxDriverPtr driver, IMachine *machine, PRUnichar *hddcnameUtf16);
    nsresult (*unregisterMachine)(vboxDriverPtr driver, vboxIIDUnion *iidu, IMachine **machine);
T
Taowei 已提交
554
    void (*deleteConfig)(IMachine *machine);
555
    void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxDriverPtr driver, IMachine *machine);
T
Taowei 已提交
556
    virDomainState (*vboxConvertState)(PRUint32 state);
557 558 559
    void (*dumpIDEHDDsOld)(virDomainDefPtr def, vboxDriverPtr driver, IMachine *machine);
    void (*dumpDVD)(virDomainDefPtr def, vboxDriverPtr driver, IMachine *machine);
    int (*attachDVD)(vboxDriverPtr driver, IMachine *machine, const char *src);
T
Taowei 已提交
560
    int (*detachDVD)(IMachine *machine);
561 562
    void (*dumpFloppy)(virDomainDefPtr def, vboxDriverPtr driver, IMachine *machine);
    int (*attachFloppy)(vboxDriverPtr driver, IMachine *machine, const char *src);
T
Taowei 已提交
563
    int (*detachFloppy)(IMachine *machine);
564
    int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
565
    void (*registerDomainEvent)(virHypervisorDriverPtr driver);
T
Taowei 已提交
566
    vboxUniformedPFN UPFN;
T
Taowei 已提交
567
    vboxUniformedIID UIID;
T
Taowei 已提交
568
    vboxUniformedArray UArray;
T
Taowei 已提交
569
    vboxUniformednsISupports nsUISupports;
T
Taowei 已提交
570
    vboxUniformedIVirtualBox UIVirtualBox;
T
Taowei 已提交
571
    vboxUniformedIMachine UIMachine;
T
Taowei 已提交
572 573 574
    vboxUniformedISession UISession;
    vboxUniformedIConsole UIConsole;
    vboxUniformedIProgress UIProgress;
T
Taowei 已提交
575
    vboxUniformedISystemProperties UISystemProperties;
T
Taowei 已提交
576 577 578 579 580 581 582 583 584
    vboxUniformedIBIOSSettings UIBIOSSettings;
    vboxUniformedIAudioAdapter UIAudioAdapter;
    vboxUniformedINetworkAdapter UINetworkAdapter;
    vboxUniformedISerialPort UISerialPort;
    vboxUniformedIParallelPort UIParallelPort;
    vboxUniformedIVRDxServer UIVRDxServer;
    vboxUniformedIUSBCommon UIUSBCommon;
    vboxUniformedIUSBDeviceFilter UIUSBDeviceFilter;
    vboxUniformedIMedium UIMedium;
T
Taowei 已提交
585 586 587
    vboxUniformedIMediumAttachment UIMediumAttachment;
    vboxUniformedIStorageController UIStorageController;
    vboxUniformedISharedFolder UISharedFolder;
588
    vboxUniformedISnapshot UISnapshot;
T
Taowei 已提交
589
    vboxUniformedIDisplay UIDisplay;
T
Taowei 已提交
590
    vboxUniformedIHost UIHost;
T
Taowei 已提交
591
    vboxUniformedIHNInterface UIHNInterface;
T
Taowei 已提交
592
    vboxUniformedIDHCPServer UIDHCPServer;
593
    vboxUniformedIKeyboard UIKeyboard;
T
Taowei 已提交
594
    uniformedMachineStateChecker machineStateChecker;
T
Taowei 已提交
595 596
    /* vbox API features */
    bool domainEventCallbacks;
T
Taowei 已提交
597 598
    bool chipsetType;
    bool accelerate2DVideo;
T
Taowei 已提交
599
    bool oldMediumInterface;
600
    bool vboxSnapshotRedefine;
T
Taowei 已提交
601
    bool networkRemoveInterface;
T
Taowei 已提交
602 603
} vboxUniformedAPI;

T
Taowei 已提交
604 605
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
                                    const unsigned char *uuid);
T
Taowei 已提交
606 607 608 609 610 611 612 613

/* Version specified functions for installing uniformed API */
void vbox40InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
void vbox41InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
void vbox42InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
void vbox42_20InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
void vbox43InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
void vbox43_4InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
M
Martin Pietsch 已提交
614
void vbox50InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
615
void vbox51InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
T
Taowei 已提交
616 617

#endif /* VBOX_UNIFORMED_API_H */