1 /*
2  * Copyright (C) 2014, Taowei Luo (uaedante@gmail.com)
3  * Copyright (C) 2008-2009 Sun Microsystems, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library.  If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #ifdef ___VirtualBox_CXPCOM_h
23 # error this file should not be included after vbox_CAPI_v*.h
24 #endif
25 
26 #include "internal.h"
27 #include <stddef.h>
28 #include "wchar.h"
29 
30 /* This file extracts some symbols defined in
31  * vbox_CAPI_v*.h. It tells the vbox_common.c
32  * how to treat with this symbols. This file
33  * can't be included with files such as
34  * vbox_CAPI_v*.h, or it would cause multiple
35  * definitions.
36  *
37  * You can see the more information in vbox_api.h
38  */
39 
40 /* Copied definitions from vbox_CAPI_*.h.
41  * We must MAKE SURE these codes are compatible. */
42 
43 typedef unsigned char PRUint8;
44 #if (defined(HPUX) && defined(__cplusplus) \
45      && !defined(__GNUC__) && __cplusplus < 199707L) \
46     || (defined(SCO) && defined(__cplusplus) \
47         && !defined(__GNUC__) && __cplusplus == 1L)
48 typedef char PRInt8;
49 #else
50 typedef signed char PRInt8;
51 #endif
52 
53 #define PR_INT8_MAX 127
54 #define PR_INT8_MIN (-128)
55 #define PR_UINT8_MAX 255U
56 
57 typedef unsigned short PRUint16;
58 typedef short PRInt16;
59 
60 #define PR_INT16_MAX 32767
61 #define PR_INT16_MIN (-32768)
62 #define PR_UINT16_MAX 65535U
63 
64 typedef unsigned int PRUint32;
65 typedef int PRInt32;
66 #define PR_INT32(x) x
67 #define PR_UINT32(x) x ## U
68 
69 #define PR_INT32_MAX PR_INT32(2147483647)
70 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
71 #define PR_UINT32_MAX PR_UINT32(4294967295)
72 
73 typedef long PRInt64;
74 typedef unsigned long PRUint64;
75 typedef int PRIntn;
76 typedef unsigned int PRUintn;
77 
78 typedef double PRFloat64;
79 typedef size_t PRSize;
80 
81 typedef ptrdiff_t PRPtrdiff;
82 
83 typedef unsigned long PRUptrdiff;
84 
85 typedef PRIntn PRBool;
86 
87 #define PR_TRUE 1
88 #define PR_FALSE 0
89 
90 typedef PRUint8 PRPackedBool;
91 
92 /*
93 ** Status code used by some routines that have a single point of failure or
94 ** special status return.
95 */
96 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
97 
98 #ifndef __PRUNICHAR__
99 # define __PRUNICHAR__
100 # if defined(WIN32) || defined(XP_MAC)
101 typedef wchar_t PRUnichar;
102 # else
103 typedef PRUint16 PRUnichar;
104 # endif
105 #endif
106 
107 typedef long PRWord;
108 typedef unsigned long PRUword;
109 
110 #define nsnull 0
111 typedef PRUint32 nsresult;
112 
113 #if defined(__GNUC__) && (__GNUC__ > 2)
114 # define NS_LIKELY(x)    (__builtin_expect((x), 1))
115 # define NS_UNLIKELY(x)  (__builtin_expect((x), 0))
116 #else
117 # define NS_LIKELY(x)    (x)
118 # define NS_UNLIKELY(x)  (x)
119 #endif
120 
121 #define NS_FAILED(_nsresult) (NS_UNLIKELY((_nsresult) & 0x80000000))
122 #define NS_SUCCEEDED(_nsresult) (NS_LIKELY(!((_nsresult) & 0x80000000)))
123 
124 /**
125  * An "interface id" which can be used to uniquely identify a given
126  * interface.
127  * A "unique identifier". This is modeled after OSF DCE UUIDs.
128  */
129 
130 struct nsID {
131   PRUint32 m0;
132   PRUint16 m1;
133   PRUint16 m2;
134   PRUint8 m3[8];
135 };
136 
137 typedef struct nsID nsID;
138 typedef nsID nsIID;
139 
140 typedef struct _vboxArray vboxArray;
141 
142 #ifdef WIN32
143 
144 struct _vboxArray {
145     void **items;
146     size_t count;
147     void *handle;
148 };
149 # define VBOX_ARRAY_INITIALIZER { NULL, 0, NULL }
150 
151 #else /* !WIN32 */
152 
153 struct _vboxArray {
154     void **items;
155     size_t count;
156 };
157 # define VBOX_ARRAY_INITIALIZER { NULL, 0 }
158 
159 #endif /* !WIN32 */
160 
161 /* We make the assumption that these enum flags
162  * are compatible in all vbox API version.
163  *
164  * Yes it is, as it has been checked from vbox 2.2 to
165  * vbox 4.3.3. And this rule MAY NOT stands for new
166  * vbox versions.
167  * */
168 enum CPUPropertyType
169 {
170     CPUPropertyType_Null = 0,
171     CPUPropertyType_PAE = 1,
172     CPUPropertyType_Synthetic = 2,
173 };
174 
175 enum AudioControllerType
176 {
177     AudioControllerType_AC97 = 0,
178     AudioControllerType_SB16 = 1
179 };
180 
181 enum ChipsetType
182 {
183     ChipsetType_Null = 0,
184     ChipsetType_PIIX3 = 1,
185     ChipsetType_ICH9 = 2
186 };
187 
188 enum NetworkAdapterType
189 {
190     NetworkAdapterType_Null = 0,
191     NetworkAdapterType_Am79C970A = 1,
192     NetworkAdapterType_Am79C973 = 2,
193     NetworkAdapterType_I82540EM = 3,
194     NetworkAdapterType_I82543GC = 4,
195     NetworkAdapterType_I82545EM = 5,
196     NetworkAdapterType_Virtio = 6
197 };
198 
199 enum NetworkAttachmentType
200 {
201     NetworkAttachmentType_Null = 0,
202     NetworkAttachmentType_NAT = 1,
203     NetworkAttachmentType_Bridged = 2,
204     NetworkAttachmentType_Internal = 3,
205     NetworkAttachmentType_HostOnly = 4
206 };
207 
208 enum PortMode
209 {
210     PortMode_Disconnected = 0,
211     PortMode_HostPipe = 1,
212     PortMode_HostDevice = 2,
213     PortMode_RawFile = 3
214 };
215 
216 enum DeviceType
217 {
218     DeviceType_Null = 0,
219     DeviceType_Floppy = 1,
220     DeviceType_DVD = 2,
221     DeviceType_HardDisk = 3,
222     DeviceType_Network = 4,
223     DeviceType_USB = 5,
224     DeviceType_SharedFolder = 6
225 };
226 
227 enum StorageBus
228 {
229     StorageBus_Null = 0,
230     StorageBus_IDE = 1,
231     StorageBus_SATA = 2,
232     StorageBus_SCSI = 3,
233     StorageBus_Floppy = 4,
234     StorageBus_SAS = 5
235 };
236 
237 enum StorageControllerType
238 {
239     StorageControllerType_Null = 0,
240     StorageControllerType_LsiLogic = 1,
241     StorageControllerType_BusLogic = 2,
242     StorageControllerType_IntelAhci = 3,
243     StorageControllerType_PIIX3 = 4,
244     StorageControllerType_PIIX4 = 5,
245     StorageControllerType_ICH6 = 6,
246     StorageControllerType_I82078 = 7,
247     StorageControllerType_LsiLogicSas = 8
248 };
249 
250 enum AccessMode
251 {
252     AccessMode_ReadOnly = 1,
253     AccessMode_ReadWrite = 2
254 };
255 
256 enum MediumType
257 {
258     MediumType_Normal = 0,
259     MediumType_Immutable = 1,
260     MediumType_Writethrough = 2,
261 };
262 
263 enum CleanupMode
264 {
265     CleanupMode_UnregisterOnly = 1,
266     CleanupMode_DetachAllReturnNone = 2,
267     CleanupMode_DetachAllReturnHardDisksOnly = 3,
268     CleanupMode_Full = 4
269 };
270 
271 enum MediumVariant
272 {
273     MediumVariant_Standard = 0,
274     MediumVariant_VmdkSplit2G = 0x01,
275     MediumVariant_VmdkStreamOptimized = 0x04,
276     MediumVariant_VmdkESX = 0x08,
277     MediumVariant_Fixed = 0x10000,
278     MediumVariant_Diff = 0x20000
279 };
280 
281 enum HostNetworkInterfaceStatus
282 {
283     HostNetworkInterfaceStatus_Unknown = 0,
284     HostNetworkInterfaceStatus_Up = 1,
285     HostNetworkInterfaceStatus_Down = 2
286 };
287 
288 enum HostNetworkInterfaceType
289 {
290     HostNetworkInterfaceType_Bridged = 1,
291     HostNetworkInterfaceType_HostOnly = 2
292 };
293 
294 enum MediaState
295 {
296     MediaState_NotCreated = 0,
297     MediaState_Created = 1,
298     MediaState_LockedRead = 2,
299     MediaState_LockedWrite = 3,
300     MediaState_Inaccessible = 4,
301     MediaState_Creating = 5,
302     MediaState_Deleting = 6
303 };
304 
305 enum HardDiskVariant
306 {
307     HardDiskVariant_Standard = 0,
308     HardDiskVariant_VmdkSplit2G = 0x01,
309     HardDiskVariant_VmdkStreamOptimized = 0x04,
310     HardDiskVariant_VmdkESX = 0x08,
311     HardDiskVariant_Fixed = 0x10000,
312     HardDiskVariant_Diff = 0x20000
313 };
314 
315 #define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001
316 #define VBOX_E_INVALID_VM_STATE 0x80BB0002
317 #define VBOX_E_VM_ERROR 0x80BB0003
318 #define VBOX_E_FILE_ERROR 0x80BB0004
319 #define VBOX_E_IPRT_ERROR 0x80BB0005
320 #define VBOX_E_PDM_ERROR 0x80BB0006
321 #define VBOX_E_INVALID_OBJECT_STATE 0x80BB0007
322 #define VBOX_E_HOST_ERROR 0x80BB0008
323 #define VBOX_E_NOT_SUPPORTED 0x80BB0009
324 #define VBOX_E_XML_ERROR 0x80BB000A
325 #define VBOX_E_INVALID_SESSION_STATE 0x80BB000B
326 #define VBOX_E_OBJECT_IN_USE 0x80BB000C
327 
328 /* VBOX storage controller name definitions */
329 
330 #define VBOX_CONTROLLER_IDE_NAME "IDE Controller"
331 #define VBOX_CONTROLLER_FLOPPY_NAME "Floppy Controller"
332 #define VBOX_CONTROLLER_SATA_NAME "SATA Controller"
333 #define VBOX_CONTROLLER_SCSI_NAME "SCSI Controller"
334 #define VBOX_CONTROLLER_SAS_NAME "SAS Controller"
335 
336 /* Simplied definitions in vbox_CAPI_*.h */
337 
338 typedef void const *PCVBOXXPCOM;
339 typedef struct nsISupports nsISupports;
340 typedef nsISupports IVirtualBox;
341 typedef nsISupports ISession;
342 typedef nsISupports IConsole;
343 typedef nsISupports IProgress;
344 typedef nsISupports IMachine;
345 typedef nsISupports ISystemProperties;
346 typedef nsISupports IBIOSSettings;
347 typedef nsISupports IAudioAdapter;
348 typedef nsISupports INetworkAdapter;
349 typedef nsISupports ISerialPort;
350 typedef nsISupports IParallelPort;
351 typedef nsISupports IVRDEServer;
352 typedef nsISupports IUSBCommon;
353 typedef nsISupports IUSBDeviceFilter;
354 typedef nsISupports IMedium;
355 typedef nsISupports IMediumAttachment;
356 typedef nsISupports IStorageController;
357 typedef nsISupports ISharedFolder;
358 typedef nsISupports ISnapshot;
359 typedef nsISupports IDisplay;
360 typedef nsISupports IHost;
361 typedef nsISupports IHostNetworkInterface;
362 typedef nsISupports IDHCPServer;
363 typedef nsISupports IKeyboard;
364 
365 /* Macros for all vbox drivers. */
366 
367 #define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode)
368 #define RC_FAILED(rc) NS_FAILED(rc.resultCode)
369 
370 #define VBOX_UTF16_FREE(arg) \
371     do { \
372         if (arg) { \
373             gVBoxAPI.UPFN.Utf16Free(data->pFuncs, arg); \
374             (arg) = NULL; \
375         } \
376     } while (0)
377 
378 #define VBOX_UTF8_FREE(arg) \
379     do { \
380         if (arg) { \
381             gVBoxAPI.UPFN.Utf8Free(data->pFuncs, arg); \
382             (arg) = NULL; \
383         } \
384     } while (0)
385 
386 #define VBOX_COM_UNALLOC_MEM(arg) \
387     do { \
388         if (arg) { \
389             gVBoxAPI.UPFN.ComUnallocMem(data->pFuncs, arg); \
390             (arg) = NULL; \
391         } \
392     } while (0)
393 
394 #define VBOX_UTF16_TO_UTF8(arg1, arg2) \
395     do { \
396         gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2); \
397         if (!*(arg2)) \
398             abort(); \
399     } while (0)
400 
401 #define VBOX_UTF8_TO_UTF16(arg1, arg2) \
402     do { \
403         gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2); \
404         if (!*(arg2)) \
405             abort(); \
406     } while (0)
407 
408 #define VBOX_ADDREF(arg)                gVBoxAPI.nsUISupports.AddRef((void *)(arg))
409 
410 #define VBOX_RELEASE(arg) \
411     do { \
412         if (arg) { \
413             gVBoxAPI.nsUISupports.Release((void *)arg); \
414             (arg) = NULL; \
415         } \
416     } while (0)
417 
418 #define VBOX_MEDIUM_RELEASE(arg) \
419     do { \
420         if (arg) { \
421             gVBoxAPI.UIMedium.Release(arg); \
422             (arg) = NULL; \
423         } \
424     } while (0)
425 
426 #define vboxIIDUnalloc(iid)                     gVBoxAPI.UIID.vboxIIDUnalloc(data, iid)
427 #define vboxIIDToUUID(iid, uuid)                gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid)
428 #define vboxIIDFromUUID(iid, uuid)              gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid)
429 #define vboxIIDIsEqual(iid1, iid2)              gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2)
430 #define DEBUGIID(msg, iid)                      gVBoxAPI.UIID.DEBUGIID(data, msg, iid)
431 #define vboxIIDFromArrayItem(iid, array, idx) \
432     gVBoxAPI.UIID.vboxIIDFromArrayItem(data, iid, array, idx)
433 
434 #define VBOX_IID_INITIALIZE(iid)                gVBoxAPI.UIID.vboxIIDInitialize(iid)
435 
436 #define ARRAY_GET_MACHINES \
437     (gVBoxAPI.UArray.handleGetMachines(data->vboxObj))
438 
439 /* Set result to -1 in case of failure. */
440 #define installUniformedAPI(gVBoxAPI, result) \
441     do { \
442         result = 0; \
443         if (uVersion >= 5001051 && uVersion < 5002051) { \
444             vbox52InstallUniformedAPI(&gVBoxAPI); \
445         } else if (uVersion >= 6000000 && uVersion < 6000051) { \
446             vbox60InstallUniformedAPI(&gVBoxAPI); \
447         } else if (uVersion >= 6000051 && uVersion < 6001051) { \
448             vbox61InstallUniformedAPI(&gVBoxAPI); \
449         } else { \
450             result = -1; \
451         } \
452     } while (0)
453