vbox_tmpl.c 166.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/** @file vbox_tmpl.c
 * Template File to support multiple versions of VirtualBox
 * at runtime :).
 *
 * IMPORTANT:
 * Please dont include this file in the src/Makefile.am, it
 * is automatically include by other files.
 */

/*
11
 * Copyright (C) 2010-2014 Red Hat, Inc.
12 13 14 15 16
 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
 *
 * This file is part of a free software library; you can redistribute
 * it and/or modify it under the terms of the GNU Lesser General
 * Public License version 2.1 as published by the Free Software
17
 * Foundation and shipped in the "COPYING.LESSER" file with this library.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 * The library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY of any kind.
 *
 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if
 * any license choice other than GPL or LGPL is available it will
 * apply instead, Sun elects to use only the Lesser General Public
 * License version 2.1 (LGPLv2) at this time for any software where
 * a choice of LGPL license versions is made available with the
 * language indicating that LGPLv2 or any later version may be used,
 * or where a choice of which version of the LGPL is applied is
 * otherwise unspecified.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 * additional information or have any questions.
 */

#include <config.h>

37
#include <unistd.h>
38 39 40
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
41 42 43 44

#include "internal.h"
#include "datatypes.h"
#include "domain_conf.h"
45
#include "domain_event.h"
46
#include "viralloc.h"
47
#include "virlog.h"
48
#include "virstring.h"
49
#include "virutil.h"
50 51

/* This one changes from version to version. */
52
#if VBOX_API_VERSION == 2002000
53
# include "vbox_CAPI_v2_2.h"
54
#elif VBOX_API_VERSION == 3000000
55
# include "vbox_CAPI_v3_0.h"
56
#elif VBOX_API_VERSION == 3001000
57
# include "vbox_CAPI_v3_1.h"
58
#elif VBOX_API_VERSION == 3002000
59
# include "vbox_CAPI_v3_2.h"
60
#elif VBOX_API_VERSION == 4000000
61
# include "vbox_CAPI_v4_0.h"
62
#elif VBOX_API_VERSION == 4001000
63
# include "vbox_CAPI_v4_1.h"
64
#elif VBOX_API_VERSION == 4002000
65
# include "vbox_CAPI_v4_2.h"
66 67 68
#elif VBOX_API_VERSION == 4002020
# include "vbox_CAPI_v4_2_20.h"
#elif VBOX_API_VERSION == 4003000
R
Ryota Ozaki 已提交
69
# include "vbox_CAPI_v4_3.h"
70 71
#elif VBOX_API_VERSION == 4003004
# include "vbox_CAPI_v4_3_4.h"
72 73
#else
# error "Unsupport VBOX_API_VERSION"
74 75
#endif

76
/* Include this *last* or we'll get the wrong vbox_CAPI_*.h. */
77
#include "vbox_glue.h"
T
Taowei 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90

#if VBOX_API_VERSION < 4000000
typedef IVRDPServer IVRDxServer;
#else /* VBOX_API_VERSION >= 4000000 */
typedef IVRDEServer IVRDxServer;
#endif /* VBOX_API_VERSION >= 4000000 */

#if VBOX_API_VERSION < 4003000
typedef IUSBController IUSBCommon;
#else /* VBOX_API_VERSION >= 4003000 */
typedef IUSBDeviceFilters IUSBCommon;
#endif /* VBOX_API_VERSION >= 4003000 */

T
Taowei 已提交
91 92
#if VBOX_API_VERSION < 3001000
typedef IHardDiskAttachment IMediumAttachment;
93 94 95
#else  /* VBOX_API_VERSION >= 3001000 */
typedef IMedium IHardDisk;
#endif /* VBOX_API_VERSION >= 3001000 */
T
Taowei 已提交
96

T
Taowei 已提交
97
#include "vbox_uniformed_api.h"
98

99
#define VIR_FROM_THIS                   VIR_FROM_VBOX
100 101 102

VIR_LOG_INIT("vbox.vbox_tmpl");

T
Taowei 已提交
103 104 105
#define vboxUnsupported() \
    VIR_WARN("No %s in current vbox version %d.", __FUNCTION__, VBOX_API_VERSION);

J
John Ferlan 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#define VBOX_UTF16_FREE(arg)                                            \
    do {                                                                \
        if (arg) {                                                      \
            data->pFuncs->pfnUtf16Free(arg);                            \
            (arg) = NULL;                                               \
        }                                                               \
    } while (0)

#define VBOX_UTF8_FREE(arg)                                             \
    do {                                                                \
        if (arg) {                                                      \
            data->pFuncs->pfnUtf8Free(arg);                             \
            (arg) = NULL;                                               \
        }                                                               \
    } while (0)

122 123 124
#define VBOX_UTF16_TO_UTF8(arg1, arg2)  data->pFuncs->pfnUtf16ToUtf8(arg1, arg2)
#define VBOX_UTF8_TO_UTF16(arg1, arg2)  data->pFuncs->pfnUtf8ToUtf16(arg1, arg2)

125 126 127 128 129 130 131
#define VBOX_RELEASE(arg)                                                     \
    do {                                                                      \
        if (arg) {                                                            \
            (arg)->vtbl->nsisupports.Release((nsISupports *)(arg));           \
            (arg) = NULL;                                                     \
        }                                                                     \
    } while (0)
132

133
#if VBOX_API_VERSION < 3001000
134
# define VBOX_MEDIUM_RELEASE(arg) \
135
if (arg)\
136
    (arg)->vtbl->imedium.nsisupports.Release((nsISupports *)(arg))
137
#else  /* VBOX_API_VERSION >= 3001000 */
138
# define VBOX_MEDIUM_RELEASE(arg) VBOX_RELEASE(arg)
139
#endif /* VBOX_API_VERSION >= 3001000 */
140

141 142 143 144 145 146
#define DEBUGPRUnichar(msg, strUtf16) \
if (strUtf16) {\
    char *strUtf8 = NULL;\
\
    g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(strUtf16, &strUtf8);\
    if (strUtf8) {\
147
        VIR_DEBUG("%s: %s", msg, strUtf8);\
148 149 150 151 152 153
        g_pVBoxGlobalData->pFuncs->pfnUtf8Free(strUtf8);\
    }\
}

#define DEBUGUUID(msg, iid) \
{\
T
Taowei 已提交
154
    VIR_DEBUG("%s: {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", msg,\
155 156 157 158 159 160 161 162 163 164 165 166 167
          (unsigned)(iid)->m0,\
          (unsigned)(iid)->m1,\
          (unsigned)(iid)->m2,\
          (unsigned)(iid)->m3[0],\
          (unsigned)(iid)->m3[1],\
          (unsigned)(iid)->m3[2],\
          (unsigned)(iid)->m3[3],\
          (unsigned)(iid)->m3[4],\
          (unsigned)(iid)->m3[5],\
          (unsigned)(iid)->m3[6],\
          (unsigned)(iid)->m3[7]);\
}\

T
Taowei 已提交
168
#if VBOX_API_VERSION > 2002000
169

170 171 172 173 174 175 176 177 178 179
/* g_pVBoxGlobalData has to be global variable,
 * there is no other way to make the callbacks
 * work other then having g_pVBoxGlobalData as
 * global, because the functions namely AddRef,
 * Release, etc consider it as global and you
 * can't change the function definition as it
 * is XPCOM nsISupport::* function and it expects
 * them that way
 */

180
static vboxGlobalData *g_pVBoxGlobalData;
181

182
#endif /* !(VBOX_API_VERSION == 2002000) */
183

184
#if VBOX_API_VERSION < 4000000
185 186 187 188 189 190 191

# define VBOX_SESSION_OPEN(/* in */ iid_value, /* unused */ machine) \
    data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, iid_value)

# define VBOX_SESSION_CLOSE() \
    data->vboxSession->vtbl->Close(data->vboxSession)

192
#else /* VBOX_API_VERSION >= 4000000 */
193 194 195 196 197 198 199

# define VBOX_SESSION_OPEN(/* unused */ iid_value, /* in */ machine) \
    machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Write)

# define VBOX_SESSION_CLOSE() \
    data->vboxSession->vtbl->UnlockMachine(data->vboxSession)

200
#endif /* VBOX_API_VERSION >= 4000000 */
201

202 203 204 205 206
#if VBOX_API_VERSION > 2002000 && VBOX_API_VERSION < 4000000
/* Since vboxConnectGetCapabilities has been rewritten,
 * vboxDriverLock and vboxDriverUnlock only be used in code for
 * 3.x release. */

207 208
static void vboxDriverLock(vboxGlobalData *data)
{
209 210 211
    virMutexLock(&data->lock);
}

212 213
static void vboxDriverUnlock(vboxGlobalData *data)
{
214 215 216
    virMutexUnlock(&data->lock);
}

217 218
#endif

219
#if VBOX_API_VERSION == 2002000
220

221 222
static void nsIDtoChar(unsigned char *uuid, const nsID *iid)
{
223 224 225
    char uuidstrsrc[VIR_UUID_STRING_BUFLEN];
    char uuidstrdst[VIR_UUID_STRING_BUFLEN];
    unsigned char uuidinterim[VIR_UUID_BUFLEN];
226
    size_t i;
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

    memcpy(uuidinterim, iid, VIR_UUID_BUFLEN);
    virUUIDFormat(uuidinterim, uuidstrsrc);

    uuidstrdst[0]  = uuidstrsrc[6];
    uuidstrdst[1]  = uuidstrsrc[7];
    uuidstrdst[2]  = uuidstrsrc[4];
    uuidstrdst[3]  = uuidstrsrc[5];
    uuidstrdst[4]  = uuidstrsrc[2];
    uuidstrdst[5]  = uuidstrsrc[3];
    uuidstrdst[6]  = uuidstrsrc[0];
    uuidstrdst[7]  = uuidstrsrc[1];

    uuidstrdst[8]  = uuidstrsrc[8];

    uuidstrdst[9]  = uuidstrsrc[11];
    uuidstrdst[10] = uuidstrsrc[12];
    uuidstrdst[11] = uuidstrsrc[9];
    uuidstrdst[12] = uuidstrsrc[10];

    uuidstrdst[13] = uuidstrsrc[13];

    uuidstrdst[14] = uuidstrsrc[16];
    uuidstrdst[15] = uuidstrsrc[17];
    uuidstrdst[16] = uuidstrsrc[14];
    uuidstrdst[17] = uuidstrsrc[15];

254
    for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++)
255 256 257
        uuidstrdst[i] = uuidstrsrc[i];

    uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0';
258
    ignore_value(virUUIDParse(uuidstrdst, uuid));
259 260
}

261 262
static void nsIDFromChar(nsID *iid, const unsigned char *uuid)
{
263 264 265
    char uuidstrsrc[VIR_UUID_STRING_BUFLEN];
    char uuidstrdst[VIR_UUID_STRING_BUFLEN];
    unsigned char uuidinterim[VIR_UUID_BUFLEN];
266
    size_t i;
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

    virUUIDFormat(uuid, uuidstrsrc);

    uuidstrdst[0]  = uuidstrsrc[6];
    uuidstrdst[1]  = uuidstrsrc[7];
    uuidstrdst[2]  = uuidstrsrc[4];
    uuidstrdst[3]  = uuidstrsrc[5];
    uuidstrdst[4]  = uuidstrsrc[2];
    uuidstrdst[5]  = uuidstrsrc[3];
    uuidstrdst[6]  = uuidstrsrc[0];
    uuidstrdst[7]  = uuidstrsrc[1];

    uuidstrdst[8]  = uuidstrsrc[8];

    uuidstrdst[9]  = uuidstrsrc[11];
    uuidstrdst[10] = uuidstrsrc[12];
    uuidstrdst[11] = uuidstrsrc[9];
    uuidstrdst[12] = uuidstrsrc[10];

    uuidstrdst[13] = uuidstrsrc[13];

    uuidstrdst[14] = uuidstrsrc[16];
    uuidstrdst[15] = uuidstrsrc[17];
    uuidstrdst[16] = uuidstrsrc[14];
    uuidstrdst[17] = uuidstrsrc[15];

293
    for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++)
294 295 296
        uuidstrdst[i] = uuidstrsrc[i];

    uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0';
297
    ignore_value(virUUIDParse(uuidstrdst, uuidinterim));
298 299 300
    memcpy(iid, uuidinterim, VIR_UUID_BUFLEN);
}

301
# ifdef WIN32
302

303 304 305 306
typedef struct _vboxIID_v2_x_WIN32 vboxIID;
typedef struct _vboxIID_v2_x_WIN32 vboxIID_v2_x_WIN32;

#  define VBOX_IID_INITIALIZER { { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } } }
T
Taowei 已提交
307
#  define IID_MEMBER(name) (iidu->vboxIID_v2_x_WIN32.name)
308 309 310 311 312 313

static void
vboxIIDUnalloc_v2_x_WIN32(vboxGlobalData *data ATTRIBUTE_UNUSED,
                          vboxIID_v2_x_WIN32 *iid ATTRIBUTE_UNUSED)
{
    /* Nothing to free */
314
}
315

T
Taowei 已提交
316 317 318 319 320 321 322
static void
_vboxIIDUnalloc(vboxGlobalData *data ATTRIBUTE_UNUSED,
                vboxIIDUnion *iid ATTRIBUTE_UNUSED)
{
    /* Nothing to free */
}

323 324 325 326 327
static void
vboxIIDToUUID_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid, unsigned char *uuid)
{
    nsIDtoChar(uuid, (nsID *)&iid->value);
}
328

T
Taowei 已提交
329 330 331 332 333 334
static void
_vboxIIDToUUID(vboxGlobalData *data ATTRIBUTE_UNUSED, vboxIIDUnion *iidu, unsigned char *uuid)
{
    vboxIIDToUUID_v2_x_WIN32(&iidu->vboxIID_v2_x_WIN32, uuid);
}

335 336 337 338 339
static void
vboxIIDFromUUID_v2_x_WIN32(vboxGlobalData *data, vboxIID_v2_x_WIN32 *iid,
                           const unsigned char *uuid)
{
    vboxIIDUnalloc_v2_x_WIN32(data, iid);
340

341
    nsIDFromChar((nsID *)&iid->value, uuid);
342 343
}

T
Taowei 已提交
344 345 346 347 348 349 350
static void
_vboxIIDFromUUID(vboxGlobalData *data, vboxIIDUnion *iidu,
                 const unsigned char *uuid)
{
    vboxIIDFromUUID_v2_x_WIN32(data, &iidu->vboxIID_v2_x_WIN32, uuid);
}

351 352 353
static bool
vboxIIDIsEqual_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid1, vboxIID_v2_x_WIN32 *iid2)
{
354
    return memcmp(&iid1->value, &iid2->value, sizeof(GUID)) == 0;
355
}
356

T
Taowei 已提交
357 358 359 360 361 362
static bool
_vboxIIDIsEqual(vboxGlobalData *data ATTRIBUTE_UNUSED, vboxIIDUnion *iidu1, vboxIIDUnion *iidu2)
{
    return vboxIIDIsEqual_v2_x_WIN32(&iidu1->vboxIID_v2_x_WIN32, &iidu2->vboxIID_v2_x_WIN32);
}

363 364 365 366 367 368 369 370
static void
vboxIIDFromArrayItem_v2_x_WIN32(vboxGlobalData *data, vboxIID_v2_x_WIN32 *iid,
                                vboxArray *array, int idx)
{
    GUID *items = (GUID *)array->items;

    vboxIIDUnalloc_v2_x_WIN32(data, iid);

371
    memcpy(&iid->value, &items[idx], sizeof(GUID));
372 373
}

T
Taowei 已提交
374 375 376 377 378 379 380
static void
_vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion *iidu,
                      vboxArray *array, int idx)
{
    vboxIIDFromArrayItem_v2_x_WIN32(data, &iidu->vboxIID_v2_x_WIN32, array, idx);
}

381 382 383 384 385 386 387 388 389 390 391 392 393 394
#  define vboxIIDUnalloc(iid) vboxIIDUnalloc_v2_x_WIN32(data, iid)
#  define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v2_x_WIN32(iid, uuid)
#  define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v2_x_WIN32(data, iid, uuid)
#  define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v2_x_WIN32(iid1, iid2)
#  define vboxIIDFromArrayItem(iid, array, idx) \
    vboxIIDFromArrayItem_v2_x_WIN32(data, iid, array, idx)
#  define DEBUGIID(msg, iid) DEBUGUUID(msg, (nsID *)&(iid))

# else /* !WIN32 */

typedef struct _vboxIID_v2_x vboxIID;
typedef struct _vboxIID_v2_x vboxIID_v2_x;

#  define VBOX_IID_INITIALIZER { NULL, { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } } }
T
Taowei 已提交
395
#  define IID_MEMBER(name) (iidu->vboxIID_v2_x.name)
396 397 398 399

static void
vboxIIDUnalloc_v2_x(vboxGlobalData *data, vboxIID_v2_x *iid)
{
400
    if (iid->value == NULL)
401 402
        return;

403
    if (iid->value != &iid->backing)
404 405 406 407 408
        data->pFuncs->pfnComUnallocMem(iid->value);

    iid->value = NULL;
}

T
Taowei 已提交
409 410 411 412 413 414
static void
_vboxIIDUnalloc(vboxGlobalData *data, vboxIIDUnion *iidu)
{
    vboxIIDUnalloc_v2_x(data, &iidu->vboxIID_v2_x);
}

415 416 417 418 419 420
static void
vboxIIDToUUID_v2_x(vboxIID_v2_x *iid, unsigned char *uuid)
{
    nsIDtoChar(uuid, iid->value);
}

T
Taowei 已提交
421 422 423 424 425 426 427
static void
_vboxIIDToUUID(vboxGlobalData *data ATTRIBUTE_UNUSED,
               vboxIIDUnion *iidu, unsigned char *uuid)
{
    vboxIIDToUUID_v2_x(&iidu->vboxIID_v2_x, uuid);
}

428 429 430 431 432 433 434 435
static void
vboxIIDFromUUID_v2_x(vboxGlobalData *data, vboxIID_v2_x *iid,
                     const unsigned char *uuid)
{
    vboxIIDUnalloc_v2_x(data, iid);

    iid->value = &iid->backing;

436
    sa_assert(iid->value);
437
    nsIDFromChar(iid->value, uuid);
438 439
}

T
Taowei 已提交
440 441 442 443 444 445 446
static void
_vboxIIDFromUUID(vboxGlobalData *data, vboxIIDUnion *iidu,
                 const unsigned char *uuid)
{
    vboxIIDFromUUID_v2_x(data, &iidu->vboxIID_v2_x, uuid);
}

447 448 449
static bool
vboxIIDIsEqual_v2_x(vboxIID_v2_x *iid1, vboxIID_v2_x *iid2)
{
450
    return memcmp(iid1->value, iid2->value, sizeof(nsID)) == 0;
451 452
}

T
Taowei 已提交
453 454 455 456 457 458 459
static bool
_vboxIIDIsEqual(vboxGlobalData *data ATTRIBUTE_UNUSED,
                vboxIIDUnion *iidu1, vboxIIDUnion *iidu2)
{
    return vboxIIDIsEqual_v2_x(&iidu1->vboxIID_v2_x, &iidu2->vboxIID_v2_x);
}

460 461 462 463 464 465 466 467
static void
vboxIIDFromArrayItem_v2_x(vboxGlobalData *data, vboxIID_v2_x *iid,
                          vboxArray *array, int idx)
{
    vboxIIDUnalloc_v2_x(data, iid);

    iid->value = &iid->backing;

468
    memcpy(iid->value, array->items[idx], sizeof(nsID));
469 470
}

T
Taowei 已提交
471 472 473 474 475 476 477
static void
_vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion *iidu,
                      vboxArray *array, int idx)
{
    vboxIIDFromArrayItem_v2_x(data, &iidu->vboxIID_v2_x, array, idx);
}

478 479 480 481 482 483 484 485 486 487
#  define vboxIIDUnalloc(iid) vboxIIDUnalloc_v2_x(data, iid)
#  define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v2_x(iid, uuid)
#  define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v2_x(data, iid, uuid)
#  define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v2_x(iid1, iid2)
#  define vboxIIDFromArrayItem(iid, array, idx) \
    vboxIIDFromArrayItem_v2_x(data, iid, array, idx)
#  define DEBUGIID(msg, iid) DEBUGUUID(msg, iid)

# endif /* !WIN32 */

488
#else /* VBOX_API_VERSION != 2002000 */
489

490 491 492 493
typedef struct _vboxIID_v3_x vboxIID;
typedef struct _vboxIID_v3_x vboxIID_v3_x;

# define VBOX_IID_INITIALIZER { NULL, true }
T
Taowei 已提交
494
# define IID_MEMBER(name) (iidu->vboxIID_v3_x.name)
495 496 497 498

static void
vboxIIDUnalloc_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid)
{
499
    if (iid->value != NULL && iid->owner)
500 501 502 503
        data->pFuncs->pfnUtf16Free(iid->value);

    iid->value = NULL;
    iid->owner = true;
504 505
}

T
Taowei 已提交
506 507 508 509 510 511
static void
_vboxIIDUnalloc(vboxGlobalData *data, vboxIIDUnion *iidu)
{
    vboxIIDUnalloc_v3_x(data, &iidu->vboxIID_v3_x);
}

512 513 514 515 516 517 518 519
static void
vboxIIDToUUID_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid,
                   unsigned char *uuid)
{
    char *utf8 = NULL;

    data->pFuncs->pfnUtf16ToUtf8(iid->value, &utf8);

520
    ignore_value(virUUIDParse(utf8, uuid));
521 522

    data->pFuncs->pfnUtf8Free(utf8);
523 524
}

T
Taowei 已提交
525 526 527 528 529 530 531
static void
_vboxIIDToUUID(vboxGlobalData *data, vboxIIDUnion *iidu,
               unsigned char *uuid)
{
    vboxIIDToUUID_v3_x(data, &iidu->vboxIID_v3_x, uuid);
}

532 533 534 535 536
static void
vboxIIDFromUUID_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid,
                     const unsigned char *uuid)
{
    char utf8[VIR_UUID_STRING_BUFLEN];
537

538
    vboxIIDUnalloc_v3_x(data, iid);
539

540
    virUUIDFormat(uuid, utf8);
541

542 543
    data->pFuncs->pfnUtf8ToUtf16(utf8, &iid->value);
}
544

T
Taowei 已提交
545 546 547 548 549 550 551
static void
_vboxIIDFromUUID(vboxGlobalData *data, vboxIIDUnion *iidu,
                 const unsigned char *uuid)
{
    vboxIIDFromUUID_v3_x(data, &iidu->vboxIID_v3_x, uuid);
}

552 553 554 555 556 557
static bool
vboxIIDIsEqual_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid1,
                    vboxIID_v3_x *iid2)
{
    unsigned char uuid1[VIR_UUID_BUFLEN];
    unsigned char uuid2[VIR_UUID_BUFLEN];
558 559

    /* Note: we can't directly compare the utf8 strings here
E
Eric Blake 已提交
560
     * cause the two UUID's may have separators as space or '-'
561 562
     * or mixture of both and we don't want to fail here by
     * using direct string comparison. Here virUUIDParse() takes
563 564 565
     * care of these cases. */
    vboxIIDToUUID_v3_x(data, iid1, uuid1);
    vboxIIDToUUID_v3_x(data, iid2, uuid2);
566

567 568
    return memcmp(uuid1, uuid2, VIR_UUID_BUFLEN) == 0;
}
569

T
Taowei 已提交
570 571 572 573 574 575
static bool
_vboxIIDIsEqual(vboxGlobalData *data, vboxIIDUnion *iidu1,
                vboxIIDUnion *iidu2)
{
    return vboxIIDIsEqual_v3_x(data, &iidu1->vboxIID_v3_x, &iidu2->vboxIID_v3_x);
}
576

577 578 579 580 581
static void
vboxIIDFromArrayItem_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid,
                          vboxArray *array, int idx)
{
    vboxIIDUnalloc_v3_x(data, iid);
582

583 584
    iid->value = array->items[idx];
    iid->owner = false;
585 586
}

T
Taowei 已提交
587 588 589 590 591 592 593
static void
_vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion *iidu,
                      vboxArray *array, int idx)
{
    vboxIIDFromArrayItem_v3_x(data, &iidu->vboxIID_v3_x, array, idx);
}

594 595 596 597 598 599 600
# define vboxIIDUnalloc(iid) vboxIIDUnalloc_v3_x(data, iid)
# define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v3_x(data, iid, uuid)
# define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v3_x(data, iid, uuid)
# define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v3_x(data, iid1, iid2)
# define vboxIIDFromArrayItem(iid, array, idx) \
    vboxIIDFromArrayItem_v3_x(data, iid, array, idx)
# define DEBUGIID(msg, strUtf16) DEBUGPRUnichar(msg, strUtf16)
601

T
Taowei 已提交
602 603
#endif /* !(VBOX_API_VERSION == 2002000) */

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
/**
 * function to get the StorageBus, Port number
 * and Device number for the given devicename
 * e.g: hda has StorageBus = IDE, port = 0,
 *      device = 0
 *
 * @returns     true on Success, false on failure.
 * @param       deviceName      Input device name
 * @param       aMaxPortPerInst Input array of max port per device instance
 * @param       aMaxSlotPerPort Input array of max slot per device port
 * @param       storageBus      Input storage bus type
 * @param       deviceInst      Output device instance number
 * @param       devicePort      Output port number
 * @param       deviceSlot      Output slot number
 *
 */
T
Taowei 已提交
620
#if VBOX_API_VERSION >= 3001000
T
Taowei 已提交
621 622
# if VBOX_API_VERSION < 4000000
/* Only 3.x will use this function. */
623 624 625 626 627 628 629 630 631 632 633
static bool vboxGetDeviceDetails(const char *deviceName,
                                 PRUint32   *aMaxPortPerInst,
                                 PRUint32   *aMaxSlotPerPort,
                                 PRUint32    storageBus,
                                 PRInt32    *deviceInst,
                                 PRInt32    *devicePort,
                                 PRInt32    *deviceSlot) {
    int total = 0;
    PRUint32 maxPortPerInst = 0;
    PRUint32 maxSlotPerPort = 0;

634 635 636 637 638 639
    if (!deviceName ||
        !deviceInst ||
        !devicePort ||
        !deviceSlot ||
        !aMaxPortPerInst ||
        !aMaxSlotPerPort)
640 641
        return false;

642 643
    if ((storageBus < StorageBus_IDE) ||
        (storageBus > StorageBus_Floppy))
644 645 646 647 648 649 650
        return false;

    total = virDiskNameToIndex(deviceName);

    maxPortPerInst = aMaxPortPerInst[storageBus];
    maxSlotPerPort = aMaxSlotPerPort[storageBus];

651 652 653
    if (!maxPortPerInst ||
        !maxSlotPerPort ||
        (total < 0))
654 655 656 657 658 659
        return false;

    *deviceInst = total / (maxPortPerInst * maxSlotPerPort);
    *devicePort = (total % (maxPortPerInst * maxSlotPerPort)) / maxSlotPerPort;
    *deviceSlot = (total % (maxPortPerInst * maxSlotPerPort)) % maxSlotPerPort;

660
    VIR_DEBUG("name=%s, total=%d, storageBus=%u, deviceInst=%d, "
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
          "devicePort=%d deviceSlot=%d, maxPortPerInst=%u maxSlotPerPort=%u",
          deviceName, total, storageBus, *deviceInst, *devicePort,
          *deviceSlot, maxPortPerInst, maxSlotPerPort);

    return true;
}

/**
 * function to get the values for max port per
 * instance and max slots per port for the devices
 *
 * @returns     true on Success, false on failure.
 * @param       vbox            Input IVirtualBox pointer
 * @param       maxPortPerInst  Output array of max port per instance
 * @param       maxSlotPerPort  Output array of max slot per port
 *
 */

679 680
/* This function would not be used in 4.1 and later since
 * vboxDomainSnapshotGetXMLDesc is written*/
681 682
static bool vboxGetMaxPortSlotValues(IVirtualBox *vbox,
                                     PRUint32 *maxPortPerInst,
683 684
                                     PRUint32 *maxSlotPerPort)
{
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
    ISystemProperties *sysProps = NULL;

    if (!vbox)
        return false;

    vbox->vtbl->GetSystemProperties(vbox, &sysProps);

    if (!sysProps)
        return false;

    sysProps->vtbl->GetMaxPortCountForStorageBus(sysProps,
                                                 StorageBus_IDE,
                                                 &maxPortPerInst[StorageBus_IDE]);
    sysProps->vtbl->GetMaxPortCountForStorageBus(sysProps,
                                                 StorageBus_SATA,
                                                 &maxPortPerInst[StorageBus_SATA]);
    sysProps->vtbl->GetMaxPortCountForStorageBus(sysProps,
                                                 StorageBus_SCSI,
                                                 &maxPortPerInst[StorageBus_SCSI]);
    sysProps->vtbl->GetMaxPortCountForStorageBus(sysProps,
                                                 StorageBus_Floppy,
                                                 &maxPortPerInst[StorageBus_Floppy]);

    sysProps->vtbl->GetMaxDevicesPerPortForStorageBus(sysProps,
                                                      StorageBus_IDE,
                                                      &maxSlotPerPort[StorageBus_IDE]);
    sysProps->vtbl->GetMaxDevicesPerPortForStorageBus(sysProps,
                                                      StorageBus_SATA,
                                                      &maxSlotPerPort[StorageBus_SATA]);
    sysProps->vtbl->GetMaxDevicesPerPortForStorageBus(sysProps,
                                                      StorageBus_SCSI,
                                                      &maxSlotPerPort[StorageBus_SCSI]);
    sysProps->vtbl->GetMaxDevicesPerPortForStorageBus(sysProps,
                                                      StorageBus_Floppy,
                                                      &maxSlotPerPort[StorageBus_Floppy]);

    VBOX_RELEASE(sysProps);

    return true;
}
725
# endif /* VBOX_API_VERSION < 4000000 */
726 727 728 729

/**
 * Converts Utf-16 string to int
 */
730 731
static int PRUnicharToInt(PRUnichar *strUtf16)
{
732 733 734 735 736 737 738 739 740 741
    char *strUtf8 = NULL;
    int ret = 0;

    if (!strUtf16)
        return -1;

    g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(strUtf16, &strUtf8);
    if (!strUtf8)
        return -1;

742 743 744
    if (virStrToLong_i(strUtf8, NULL, 10, &ret) < 0)
        ret = -1;

745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
    g_pVBoxGlobalData->pFuncs->pfnUtf8Free(strUtf8);

    return ret;
}

/**
 * Converts int to Utf-16 string
 */
static PRUnichar *PRUnicharFromInt(int n) {
    PRUnichar *strUtf16 = NULL;
    char s[24];

    snprintf(s, sizeof(s), "%d", n);

    g_pVBoxGlobalData->pFuncs->pfnUtf8ToUtf16(s, &strUtf16);

    return strUtf16;
}

T
Taowei 已提交
764
#endif /* VBOX_API_VERSION >= 3001000 */
765

T
Taowei 已提交
766
static virDomainState _vboxConvertState(PRUint32 state)
767
{
768 769 770 771 772 773 774 775 776 777
    switch (state) {
        case MachineState_Running:
            return VIR_DOMAIN_RUNNING;
        case MachineState_Stuck:
            return VIR_DOMAIN_BLOCKED;
        case MachineState_Paused:
            return VIR_DOMAIN_PAUSED;
        case MachineState_Stopping:
            return VIR_DOMAIN_SHUTDOWN;
        case MachineState_PoweredOff:
R
Ryota Ozaki 已提交
778
        case MachineState_Saved:
779 780 781 782 783 784 785 786 787
            return VIR_DOMAIN_SHUTOFF;
        case MachineState_Aborted:
            return VIR_DOMAIN_CRASHED;
        case MachineState_Null:
        default:
            return VIR_DOMAIN_NOSTATE;
    }
}

T
Taowei 已提交
788
#if VBOX_API_VERSION < 3001000
789

E
Eric Blake 已提交
790
static void
T
Taowei 已提交
791
_vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
E
Eric Blake 已提交
792
{
793
    size_t i;
E
Eric Blake 已提交
794
    nsresult rc;
795

E
Eric Blake 已提交
796 797 798 799
    if (def->ndisks == 0)
        return;

    for (i = 0; i < def->ndisks; i++) {
800 801 802 803 804
        const char *src = virDomainDiskGetSource(def->disks[i]);
        int type = virDomainDiskGetType(def->disks[i]);
        int format = virDomainDiskGetFormat(def->disks[i]);

        VIR_DEBUG("disk(%zu) type:       %d", i, type);
805 806
        VIR_DEBUG("disk(%zu) device:     %d", i, def->disks[i]->device);
        VIR_DEBUG("disk(%zu) bus:        %d", i, def->disks[i]->bus);
807
        VIR_DEBUG("disk(%zu) src:        %s", i, src);
808
        VIR_DEBUG("disk(%zu) dst:        %s", i, def->disks[i]->dst);
809 810
        VIR_DEBUG("disk(%zu) driverName: %s", i,
                  virDomainDiskGetDriver(def->disks[i]));
811
        VIR_DEBUG("disk(%zu) driverType: %s", i,
812
                  virStorageFileFormatTypeToString(format));
813
        VIR_DEBUG("disk(%zu) cachemode:  %d", i, def->disks[i]->cachemode);
814
        VIR_DEBUG("disk(%zu) readonly:   %s", i, (def->disks[i]->src->readonly
E
Eric Blake 已提交
815
                                             ? "True" : "False"));
816
        VIR_DEBUG("disk(%zu) shared:     %s", i, (def->disks[i]->src->shared
E
Eric Blake 已提交
817 818 819
                                             ? "True" : "False"));

        if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
E
Eric Blake 已提交
820
            if (type == VIR_STORAGE_TYPE_FILE && src) {
E
Eric Blake 已提交
821 822 823 824 825 826 827
                IDVDDrive *dvdDrive = NULL;
                /* Currently CDROM/DVD Drive is always IDE
                 * Secondary Master so neglecting the following
                 * parameters:
                 *      def->disks[i]->bus
                 *      def->disks[i]->dst
                 */
828

E
Eric Blake 已提交
829 830 831 832
                machine->vtbl->GetDVDDrive(machine, &dvdDrive);
                if (dvdDrive) {
                    IDVDImage *dvdImage          = NULL;
                    PRUnichar *dvdfileUtf16      = NULL;
833 834
                    vboxIID dvduuid = VBOX_IID_INITIALIZER;
                    vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
835

836
                    VBOX_UTF8_TO_UTF16(src, &dvdfileUtf16);
837

E
Eric Blake 已提交
838 839 840 841 842
                    data->vboxObj->vtbl->FindDVDImage(data->vboxObj,
                                                      dvdfileUtf16, &dvdImage);
                    if (!dvdImage) {
                        data->vboxObj->vtbl->OpenDVDImage(data->vboxObj,
                                                          dvdfileUtf16,
843
                                                          dvdemptyuuid.value,
E
Eric Blake 已提交
844 845 846 847
                                                          &dvdImage);
                    }
                    if (dvdImage) {
                        rc = dvdImage->vtbl->imedium.GetId((IMedium *)dvdImage,
848
                                                           &dvduuid.value);
E
Eric Blake 已提交
849
                        if (NS_FAILED(rc)) {
850 851 852
                            virReportError(VIR_ERR_INTERNAL_ERROR,
                                           _("can't get the uuid of the file to "
                                             "be attached to cdrom: %s, rc=%08x"),
853
                                           src, (unsigned)rc);
E
Eric Blake 已提交
854
                        } else {
855
                            rc = dvdDrive->vtbl->MountImage(dvdDrive, dvduuid.value);
E
Eric Blake 已提交
856
                            if (NS_FAILED(rc)) {
857 858
                                virReportError(VIR_ERR_INTERNAL_ERROR,
                                               _("could not attach the file to cdrom: %s, rc=%08x"),
859
                                               src, (unsigned)rc);
E
Eric Blake 已提交
860
                            } else {
861
                                DEBUGIID("CD/DVDImage UUID:", dvduuid.value);
862
                            }
863
                        }
E
Eric Blake 已提交
864 865

                        VBOX_MEDIUM_RELEASE(dvdImage);
866
                    }
867
                    vboxIIDUnalloc(&dvduuid);
E
Eric Blake 已提交
868 869 870
                    VBOX_UTF16_FREE(dvdfileUtf16);
                    VBOX_RELEASE(dvdDrive);
                }
E
Eric Blake 已提交
871
            } else if (type == VIR_STORAGE_TYPE_BLOCK) {
E
Eric Blake 已提交
872 873
            }
        } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
E
Eric Blake 已提交
874
            if (type == VIR_STORAGE_TYPE_FILE && src) {
E
Eric Blake 已提交
875 876
                IHardDisk *hardDisk     = NULL;
                PRUnichar *hddfileUtf16 = NULL;
877
                vboxIID hdduuid = VBOX_IID_INITIALIZER;
E
Eric Blake 已提交
878 879 880 881 882 883
                PRUnichar *hddEmpty     = NULL;
                /* Current Limitation: Harddisk can't be connected to
                 * Secondary Master as Secondary Master is always used
                 * for CD/DVD Drive, so don't connect the harddisk if it
                 * is requested to be connected to Secondary master
                 */
884

885
                VBOX_UTF8_TO_UTF16(src, &hddfileUtf16);
E
Eric Blake 已提交
886
                VBOX_UTF8_TO_UTF16("", &hddEmpty);
887

E
Eric Blake 已提交
888 889
                data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddfileUtf16,
                                                  &hardDisk);
890

E
Eric Blake 已提交
891
                if (!hardDisk) {
892
# if VBOX_API_VERSION == 2002000
E
Eric Blake 已提交
893 894 895 896
                    data->vboxObj->vtbl->OpenHardDisk(data->vboxObj,
                                                      hddfileUtf16,
                                                      AccessMode_ReadWrite,
                                                      &hardDisk);
897
# else
E
Eric Blake 已提交
898 899 900 901 902 903 904 905
                    data->vboxObj->vtbl->OpenHardDisk(data->vboxObj,
                                                      hddfileUtf16,
                                                      AccessMode_ReadWrite,
                                                      0,
                                                      hddEmpty,
                                                      0,
                                                      hddEmpty,
                                                      &hardDisk);
906
# endif
E
Eric Blake 已提交
907
                }
908

E
Eric Blake 已提交
909 910
                if (hardDisk) {
                    rc = hardDisk->vtbl->imedium.GetId((IMedium *)hardDisk,
911
                                                       &hdduuid.value);
E
Eric Blake 已提交
912
                    if (NS_FAILED(rc)) {
913 914 915
                        virReportError(VIR_ERR_INTERNAL_ERROR,
                                       _("can't get the uuid of the file to be "
                                         "attached as harddisk: %s, rc=%08x"),
916
                                       src, (unsigned)rc);
E
Eric Blake 已提交
917
                    } else {
918
                        if (def->disks[i]->src->readonly) {
E
Eric Blake 已提交
919 920
                            hardDisk->vtbl->SetType(hardDisk,
                                                    HardDiskType_Immutable);
921
                            VIR_DEBUG("setting harddisk to readonly");
922
                        } else if (!def->disks[i]->src->readonly) {
E
Eric Blake 已提交
923 924
                            hardDisk->vtbl->SetType(hardDisk,
                                                    HardDiskType_Normal);
925
                            VIR_DEBUG("setting harddisk type to normal");
E
Eric Blake 已提交
926 927 928
                        }
                        if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_IDE) {
                            if (STREQ(def->disks[i]->dst, "hdc")) {
929
                                VIR_DEBUG("Not connecting harddisk to hdc as hdc"
E
Eric Blake 已提交
930
                                       " is taken by CD/DVD Drive");
931
                            } else {
E
Eric Blake 已提交
932 933 934 935
                                PRInt32 channel          = 0;
                                PRInt32 device           = 0;
                                PRUnichar *hddcnameUtf16 = NULL;

936 937
                                char *hddcname;
                                ignore_value(VIR_STRDUP(hddcname, "IDE"));
E
Eric Blake 已提交
938 939 940 941 942 943 944 945 946 947 948 949
                                VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16);
                                VIR_FREE(hddcname);

                                if (STREQ(def->disks[i]->dst, "hda")) {
                                    channel = 0;
                                    device  = 0;
                                } else if (STREQ(def->disks[i]->dst, "hdb")) {
                                    channel = 0;
                                    device  = 1;
                                } else if (STREQ(def->disks[i]->dst, "hdd")) {
                                    channel = 1;
                                    device  = 1;
950
                                }
E
Eric Blake 已提交
951 952

                                rc = machine->vtbl->AttachHardDisk(machine,
953
                                                                   hdduuid.value,
E
Eric Blake 已提交
954 955 956 957 958 959
                                                                   hddcnameUtf16,
                                                                   channel,
                                                                   device);
                                VBOX_UTF16_FREE(hddcnameUtf16);

                                if (NS_FAILED(rc)) {
960 961 962
                                    virReportError(VIR_ERR_INTERNAL_ERROR,
                                                   _("could not attach the file as "
                                                     "harddisk: %s, rc=%08x"),
963
                                                   src, (unsigned)rc);
E
Eric Blake 已提交
964
                                } else {
965
                                    DEBUGIID("Attached HDD with UUID", hdduuid.value);
966 967 968
                                }
                            }
                        }
969
                    }
E
Eric Blake 已提交
970 971
                    VBOX_MEDIUM_RELEASE(hardDisk);
                }
972
                vboxIIDUnalloc(&hdduuid);
E
Eric Blake 已提交
973 974
                VBOX_UTF16_FREE(hddEmpty);
                VBOX_UTF16_FREE(hddfileUtf16);
E
Eric Blake 已提交
975
            } else if (type == VIR_STORAGE_TYPE_BLOCK) {
E
Eric Blake 已提交
976 977
            }
        } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
E
Eric Blake 已提交
978
            if (type == VIR_STORAGE_TYPE_FILE && src) {
E
Eric Blake 已提交
979 980 981 982 983 984 985
                IFloppyDrive *floppyDrive;
                machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
                if (floppyDrive) {
                    rc = floppyDrive->vtbl->SetEnabled(floppyDrive, 1);
                    if (NS_SUCCEEDED(rc)) {
                        IFloppyImage *floppyImage   = NULL;
                        PRUnichar *fdfileUtf16      = NULL;
986 987
                        vboxIID fduuid = VBOX_IID_INITIALIZER;
                        vboxIID fdemptyuuid = VBOX_IID_INITIALIZER;
988

989
                        VBOX_UTF8_TO_UTF16(src, &fdfileUtf16);
E
Eric Blake 已提交
990 991 992
                        rc = data->vboxObj->vtbl->FindFloppyImage(data->vboxObj,
                                                                  fdfileUtf16,
                                                                  &floppyImage);
993

E
Eric Blake 已提交
994 995 996
                        if (!floppyImage) {
                            data->vboxObj->vtbl->OpenFloppyImage(data->vboxObj,
                                                                 fdfileUtf16,
997
                                                                 fdemptyuuid.value,
E
Eric Blake 已提交
998 999
                                                                 &floppyImage);
                        }
1000

E
Eric Blake 已提交
1001 1002
                        if (floppyImage) {
                            rc = floppyImage->vtbl->imedium.GetId((IMedium *)floppyImage,
1003
                                                                  &fduuid.value);
E
Eric Blake 已提交
1004
                            if (NS_FAILED(rc)) {
1005 1006 1007
                                virReportError(VIR_ERR_INTERNAL_ERROR,
                                               _("can't get the uuid of the file to "
                                                 "be attached to floppy drive: %s, rc=%08x"),
1008
                                               src, (unsigned)rc);
E
Eric Blake 已提交
1009 1010
                            } else {
                                rc = floppyDrive->vtbl->MountImage(floppyDrive,
1011
                                                                   fduuid.value);
E
Eric Blake 已提交
1012
                                if (NS_FAILED(rc)) {
1013 1014 1015
                                    virReportError(VIR_ERR_INTERNAL_ERROR,
                                                   _("could not attach the file to "
                                                     "floppy drive: %s, rc=%08x"),
1016
                                                   src, (unsigned)rc);
E
Eric Blake 已提交
1017
                                } else {
1018
                                    DEBUGIID("floppyImage UUID", fduuid.value);
1019 1020
                                }
                            }
E
Eric Blake 已提交
1021
                            VBOX_MEDIUM_RELEASE(floppyImage);
1022
                        }
1023
                        vboxIIDUnalloc(&fduuid);
E
Eric Blake 已提交
1024
                        VBOX_UTF16_FREE(fdfileUtf16);
1025
                    }
E
Eric Blake 已提交
1026
                    VBOX_RELEASE(floppyDrive);
1027
                }
E
Eric Blake 已提交
1028
            } else if (type == VIR_STORAGE_TYPE_BLOCK) {
1029
            }
1030
        }
E
Eric Blake 已提交
1031
    }
T
Taowei 已提交
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
}

#elif VBOX_API_VERSION < 4000000

static void
_vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
    size_t i;
    nsresult rc;

E
Eric Blake 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
    PRUint32 maxPortPerInst[StorageBus_Floppy + 1] = {};
    PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] = {};
    PRUnichar *storageCtlName = NULL;
    bool error = false;

    /* get the max port/slots/etc for the given storage bus */
    error = !vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst,
                                      maxSlotPerPort);

    /* add a storage controller for the mediums to be attached */
    /* this needs to change when multiple controller are supported for
     * ver > 3.1 */
1054
    {
E
Eric Blake 已提交
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
        IStorageController *storageCtl = NULL;
        PRUnichar *sName = NULL;

        VBOX_UTF8_TO_UTF16("IDE Controller", &sName);
        machine->vtbl->AddStorageController(machine,
                                            sName,
                                            StorageBus_IDE,
                                            &storageCtl);
        VBOX_UTF16_FREE(sName);
        VBOX_RELEASE(storageCtl);

        VBOX_UTF8_TO_UTF16("SATA Controller", &sName);
        machine->vtbl->AddStorageController(machine,
                                            sName,
                                            StorageBus_SATA,
                                            &storageCtl);
        VBOX_UTF16_FREE(sName);
        VBOX_RELEASE(storageCtl);

        VBOX_UTF8_TO_UTF16("SCSI Controller", &sName);
        machine->vtbl->AddStorageController(machine,
                                            sName,
                                            StorageBus_SCSI,
                                            &storageCtl);
        VBOX_UTF16_FREE(sName);
        VBOX_RELEASE(storageCtl);

        VBOX_UTF8_TO_UTF16("Floppy Controller", &sName);
        machine->vtbl->AddStorageController(machine,
                                            sName,
                                            StorageBus_Floppy,
                                            &storageCtl);
        VBOX_UTF16_FREE(sName);
        VBOX_RELEASE(storageCtl);
    }
1090

E
Eric Blake 已提交
1091
    for (i = 0; i < def->ndisks && !error; i++) {
1092 1093 1094 1095 1096
        const char *src = virDomainDiskGetSource(def->disks[i]);
        int type = virDomainDiskGetType(def->disks[i]);
        int format = virDomainDiskGetFormat(def->disks[i]);

        VIR_DEBUG("disk(%zu) type:       %d", i, type);
1097 1098
        VIR_DEBUG("disk(%zu) device:     %d", i, def->disks[i]->device);
        VIR_DEBUG("disk(%zu) bus:        %d", i, def->disks[i]->bus);
1099
        VIR_DEBUG("disk(%zu) src:        %s", i, src);
1100
        VIR_DEBUG("disk(%zu) dst:        %s", i, def->disks[i]->dst);
1101 1102
        VIR_DEBUG("disk(%zu) driverName: %s", i,
                  virDomainDiskGetDriver(def->disks[i]));
1103
        VIR_DEBUG("disk(%zu) driverType: %s", i,
1104
                  virStorageFileFormatTypeToString(format));
1105
        VIR_DEBUG("disk(%zu) cachemode:  %d", i, def->disks[i]->cachemode);
1106
        VIR_DEBUG("disk(%zu) readonly:   %s", i, (def->disks[i]->src->readonly
E
Eric Blake 已提交
1107
                                             ? "True" : "False"));
1108
        VIR_DEBUG("disk(%zu) shared:     %s", i, (def->disks[i]->src->shared
E
Eric Blake 已提交
1109 1110
                                             ? "True" : "False"));

E
Eric Blake 已提交
1111
        if (type == VIR_STORAGE_TYPE_FILE && src) {
E
Eric Blake 已提交
1112 1113 1114 1115 1116 1117 1118 1119 1120
            IMedium   *medium          = NULL;
            PRUnichar *mediumUUID      = NULL;
            PRUnichar *mediumFileUtf16 = NULL;
            PRUint32   storageBus      = StorageBus_Null;
            PRUint32   deviceType      = DeviceType_Null;
            PRInt32    deviceInst      = 0;
            PRInt32    devicePort      = 0;
            PRInt32    deviceSlot      = 0;

1121
            VBOX_UTF8_TO_UTF16(src, &mediumFileUtf16);
E
Eric Blake 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138

            if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
                deviceType = DeviceType_HardDisk;
                data->vboxObj->vtbl->FindHardDisk(data->vboxObj,
                                                  mediumFileUtf16, &medium);
            } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
                deviceType = DeviceType_DVD;
                data->vboxObj->vtbl->FindDVDImage(data->vboxObj,
                                                  mediumFileUtf16, &medium);
            } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
                deviceType = DeviceType_Floppy;
                data->vboxObj->vtbl->FindFloppyImage(data->vboxObj,
                                                     mediumFileUtf16, &medium);
            } else {
                VBOX_UTF16_FREE(mediumFileUtf16);
                continue;
            }
1139

E
Eric Blake 已提交
1140 1141
            if (!medium) {
                PRUnichar *mediumEmpty = NULL;
1142

E
Eric Blake 已提交
1143
                VBOX_UTF8_TO_UTF16("", &mediumEmpty);
1144 1145

                if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
1146 1147 1148 1149 1150 1151 1152 1153
                    rc = data->vboxObj->vtbl->OpenHardDisk(data->vboxObj,
                                                           mediumFileUtf16,
                                                           AccessMode_ReadWrite,
                                                           false,
                                                           mediumEmpty,
                                                           false,
                                                           mediumEmpty,
                                                           &medium);
E
Eric Blake 已提交
1154 1155
                } else if (def->disks[i]->device ==
                           VIR_DOMAIN_DISK_DEVICE_CDROM) {
1156 1157 1158 1159
                    rc = data->vboxObj->vtbl->OpenDVDImage(data->vboxObj,
                                                           mediumFileUtf16,
                                                           mediumEmpty,
                                                           &medium);
E
Eric Blake 已提交
1160 1161
                } else if (def->disks[i]->device ==
                           VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
1162 1163 1164 1165 1166 1167
                    rc = data->vboxObj->vtbl->OpenFloppyImage(data->vboxObj,
                                                              mediumFileUtf16,
                                                              mediumEmpty,
                                                              &medium);
                } else {
                    rc = 0;
1168
                }
E
Eric Blake 已提交
1169 1170
                VBOX_UTF16_FREE(mediumEmpty);
            }
1171

E
Eric Blake 已提交
1172
            if (!medium) {
1173 1174 1175
                virReportError(VIR_ERR_INTERNAL_ERROR,
                               _("Failed to attach the following disk/dvd/floppy "
                                 "to the machine: %s, rc=%08x"),
1176
                               src, (unsigned)rc);
E
Eric Blake 已提交
1177 1178 1179
                VBOX_UTF16_FREE(mediumFileUtf16);
                continue;
            }
1180

E
Eric Blake 已提交
1181 1182
            rc = medium->vtbl->GetId(medium, &mediumUUID);
            if (NS_FAILED(rc)) {
1183 1184 1185
                virReportError(VIR_ERR_INTERNAL_ERROR,
                               _("can't get the uuid of the file to be attached "
                                 "as harddisk/dvd/floppy: %s, rc=%08x"),
1186
                               src, (unsigned)rc);
E
Eric Blake 已提交
1187 1188 1189 1190
                VBOX_RELEASE(medium);
                VBOX_UTF16_FREE(mediumFileUtf16);
                continue;
            }
1191

E
Eric Blake 已提交
1192
            if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
1193
                if (def->disks[i]->src->readonly) {
E
Eric Blake 已提交
1194
                    medium->vtbl->SetType(medium, MediumType_Immutable);
1195
                    VIR_DEBUG("setting harddisk to immutable");
1196
                } else if (!def->disks[i]->src->readonly) {
E
Eric Blake 已提交
1197
                    medium->vtbl->SetType(medium, MediumType_Normal);
1198
                    VIR_DEBUG("setting harddisk type to normal");
1199
                }
E
Eric Blake 已提交
1200
            }
1201

E
Eric Blake 已提交
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
            if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_IDE) {
                VBOX_UTF8_TO_UTF16("IDE Controller", &storageCtlName);
                storageBus = StorageBus_IDE;
            } else if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_SATA) {
                VBOX_UTF8_TO_UTF16("SATA Controller", &storageCtlName);
                storageBus = StorageBus_SATA;
            } else if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
                VBOX_UTF8_TO_UTF16("SCSI Controller", &storageCtlName);
                storageBus = StorageBus_SCSI;
            } else if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_FDC) {
                VBOX_UTF8_TO_UTF16("Floppy Controller", &storageCtlName);
                storageBus = StorageBus_Floppy;
            }
1215

E
Eric Blake 已提交
1216 1217 1218 1219 1220 1221 1222 1223
            /* get the device details i.e instance, port and slot */
            if (!vboxGetDeviceDetails(def->disks[i]->dst,
                                      maxPortPerInst,
                                      maxSlotPerPort,
                                      storageBus,
                                      &deviceInst,
                                      &devicePort,
                                      &deviceSlot)) {
1224
                virReportError(VIR_ERR_INTERNAL_ERROR,
1225 1226 1227
                               _("can't get the port/slot number of "
                                 "harddisk/dvd/floppy to be attached: "
                                 "%s, rc=%08x"),
1228
                               src, (unsigned)rc);
1229 1230 1231
                VBOX_RELEASE(medium);
                VBOX_UTF16_FREE(mediumUUID);
                VBOX_UTF16_FREE(mediumFileUtf16);
E
Eric Blake 已提交
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
                continue;
            }

            /* attach the harddisk/dvd/Floppy to the storage controller */
            rc = machine->vtbl->AttachDevice(machine,
                                             storageCtlName,
                                             devicePort,
                                             deviceSlot,
                                             deviceType,
                                             mediumUUID);

            if (NS_FAILED(rc)) {
1244
                virReportError(VIR_ERR_INTERNAL_ERROR,
1245 1246
                               _("could not attach the file as "
                                 "harddisk/dvd/floppy: %s, rc=%08x"),
1247
                               src, (unsigned)rc);
E
Eric Blake 已提交
1248 1249
            } else {
                DEBUGIID("Attached HDD/DVD/Floppy with UUID", mediumUUID);
1250
            }
E
Eric Blake 已提交
1251 1252 1253 1254 1255

            VBOX_RELEASE(medium);
            VBOX_UTF16_FREE(mediumUUID);
            VBOX_UTF16_FREE(mediumFileUtf16);
            VBOX_UTF16_FREE(storageCtlName);
1256 1257
        }
    }
E
Eric Blake 已提交
1258
}
1259

T
Taowei 已提交
1260
#else /* VBOX_API_VERSION >= 4000000 */
E
Eric Blake 已提交
1261 1262

static void
T
Taowei 已提交
1263 1264 1265
_vboxAttachDrivesOld(virDomainDefPtr def ATTRIBUTE_UNUSED,
                     vboxGlobalData *data ATTRIBUTE_UNUSED,
                     IMachine *machine ATTRIBUTE_UNUSED)
E
Eric Blake 已提交
1266
{
T
Taowei 已提交
1267 1268
    vboxUnsupported();
}
1269

1270
#endif /* VBOX_API_VERSION >= 4000000 */
E
Eric Blake 已提交
1271

1272
#if VBOX_API_VERSION < 3001000
J
Jiri Denemark 已提交
1273
static int
1274
_vboxDomainSnapshotRestore(virDomainPtr dom,
J
Jiri Denemark 已提交
1275 1276 1277
                          IMachine *machine,
                          ISnapshot *snapshot)
{
T
Taowei Luo 已提交
1278
    vboxGlobalData *data = dom->conn->privateData;
1279
    vboxIID iid = VBOX_IID_INITIALIZER;
J
Jiri Denemark 已提交
1280
    nsresult rc;
T
Taowei Luo 已提交
1281 1282 1283 1284
    int ret = -1;

    if (!data->vboxObj)
        return ret;
J
Jiri Denemark 已提交
1285

1286 1287
    rc = snapshot->vtbl->GetId(snapshot, &iid.value);
    if (NS_FAILED(rc)) {
1288 1289
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("could not get snapshot UUID"));
J
Jiri Denemark 已提交
1290 1291 1292
        goto cleanup;
    }

1293
    rc = machine->vtbl->SetCurrentSnapshot(machine, iid.value);
J
Jiri Denemark 已提交
1294
    if (NS_FAILED(rc)) {
1295 1296
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not restore snapshot for domain %s"), dom->name);
J
Jiri Denemark 已提交
1297 1298 1299 1300 1301
        goto cleanup;
    }

    ret = 0;

1302
 cleanup:
1303
    vboxIIDUnalloc(&iid);
J
Jiri Denemark 已提交
1304 1305 1306 1307
    return ret;
}
#else
static int
1308
_vboxDomainSnapshotRestore(virDomainPtr dom,
J
Jiri Denemark 已提交
1309 1310 1311
                          IMachine *machine,
                          ISnapshot *snapshot)
{
T
Taowei Luo 已提交
1312
    vboxGlobalData *data = dom->conn->privateData;
J
Jiri Denemark 已提交
1313 1314 1315 1316 1317
    IConsole *console = NULL;
    IProgress *progress = NULL;
    PRUint32 state;
    nsresult rc;
    PRInt32 result;
1318
    vboxIID domiid = VBOX_IID_INITIALIZER;
T
Taowei Luo 已提交
1319 1320 1321 1322
    int ret = -1;

    if (!data->vboxObj)
        return ret;
J
Jiri Denemark 已提交
1323

1324 1325
    rc = machine->vtbl->GetId(machine, &domiid.value);
    if (NS_FAILED(rc)) {
1326 1327
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("could not get domain UUID"));
J
Jiri Denemark 已提交
1328 1329 1330 1331 1332
        goto cleanup;
    }

    rc = machine->vtbl->GetState(machine, &state);
    if (NS_FAILED(rc)) {
1333 1334
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("could not get domain state"));
J
Jiri Denemark 已提交
1335 1336 1337 1338 1339
        goto cleanup;
    }

    if (state >= MachineState_FirstOnline
        && state <= MachineState_LastOnline) {
1340 1341
        virReportError(VIR_ERR_OPERATION_INVALID,
                       _("domain %s is already running"), dom->name);
J
Jiri Denemark 已提交
1342 1343 1344
        goto cleanup;
    }

1345
    rc = VBOX_SESSION_OPEN(domiid.value, machine);
J
Jiri Denemark 已提交
1346 1347 1348
    if (NS_SUCCEEDED(rc))
        rc = data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
    if (NS_FAILED(rc)) {
1349 1350 1351
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not open VirtualBox session with domain %s"),
                       dom->name);
J
Jiri Denemark 已提交
1352 1353 1354 1355 1356 1357
        goto cleanup;
    }

    rc = console->vtbl->RestoreSnapshot(console, snapshot, &progress);
    if (NS_FAILED(rc) || !progress) {
        if (rc == VBOX_E_INVALID_VM_STATE) {
1358 1359
            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                           _("cannot restore domain snapshot for running domain"));
J
Jiri Denemark 已提交
1360
        } else {
1361 1362 1363
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("could not restore snapshot for domain %s"),
                           dom->name);
J
Jiri Denemark 已提交
1364 1365 1366 1367 1368 1369 1370
        }
        goto cleanup;
    }

    progress->vtbl->WaitForCompletion(progress, -1);
    progress->vtbl->GetResultCode(progress, &result);
    if (NS_FAILED(result)) {
1371 1372
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not restore snapshot for domain %s"), dom->name);
J
Jiri Denemark 已提交
1373 1374 1375 1376 1377
        goto cleanup;
    }

    ret = 0;

1378
 cleanup:
J
Jiri Denemark 已提交
1379 1380
    VBOX_RELEASE(progress);
    VBOX_RELEASE(console);
1381
    VBOX_SESSION_CLOSE();
1382
    vboxIIDUnalloc(&domiid);
J
Jiri Denemark 已提交
1383 1384 1385 1386
    return ret;
}
#endif

1387
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
1388
    /* No Callback support for VirtualBox 2.2.* series */
1389
    /* No Callback support for VirtualBox 4.* series */
T
Taowei 已提交
1390 1391

static void
1392
_registerDomainEvent(virHypervisorDriverPtr driver)
T
Taowei 已提交
1393 1394 1395 1396 1397 1398 1399
{
    driver->connectDomainEventRegister = NULL;
    driver->connectDomainEventDeregister = NULL;
    driver->connectDomainEventRegisterAny = NULL;
    driver->connectDomainEventDeregisterAny = NULL;
}

1400
#else /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
1401 1402

/* Functions needed for Callbacks */
1403
static nsresult PR_COM_METHOD
1404
vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
1405 1406
                                 PRUnichar *machineId, PRUint32 state)
{
1407 1408 1409 1410 1411 1412
    virDomainPtr dom = NULL;
    int event        = 0;
    int detail       = 0;

    vboxDriverLock(g_pVBoxGlobalData);

1413
    VIR_DEBUG("IVirtualBoxCallback: %p, State: %d", pThis, state);
1414 1415 1416 1417 1418 1419 1420
    DEBUGPRUnichar("machineId", machineId);

    if (machineId) {
        char *machineIdUtf8       = NULL;
        unsigned char uuid[VIR_UUID_BUFLEN];

        g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
1421
        ignore_value(virUUIDParse(machineIdUtf8, uuid));
1422 1423 1424

        dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
        if (dom) {
1425
            virObjectEventPtr ev;
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455

            if (state == MachineState_Starting) {
                event  = VIR_DOMAIN_EVENT_STARTED;
                detail = VIR_DOMAIN_EVENT_STARTED_BOOTED;
            } else if (state == MachineState_Restoring) {
                event  = VIR_DOMAIN_EVENT_STARTED;
                detail = VIR_DOMAIN_EVENT_STARTED_RESTORED;
            } else if (state == MachineState_Paused) {
                event  = VIR_DOMAIN_EVENT_SUSPENDED;
                detail = VIR_DOMAIN_EVENT_SUSPENDED_PAUSED;
            } else if (state == MachineState_Running) {
                event  = VIR_DOMAIN_EVENT_RESUMED;
                detail = VIR_DOMAIN_EVENT_RESUMED_UNPAUSED;
            } else if (state == MachineState_PoweredOff) {
                event  = VIR_DOMAIN_EVENT_STOPPED;
                detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
            } else if (state == MachineState_Stopping) {
                event  = VIR_DOMAIN_EVENT_STOPPED;
                detail = VIR_DOMAIN_EVENT_STOPPED_DESTROYED;
            } else if (state == MachineState_Aborted) {
                event  = VIR_DOMAIN_EVENT_STOPPED;
                detail = VIR_DOMAIN_EVENT_STOPPED_CRASHED;
            } else if (state == MachineState_Saving) {
                event  = VIR_DOMAIN_EVENT_STOPPED;
                detail = VIR_DOMAIN_EVENT_STOPPED_SAVED;
            } else {
                event  = VIR_DOMAIN_EVENT_STOPPED;
                detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
            }

1456
            ev = virDomainEventLifecycleNewFromDom(dom, event, detail);
1457

1458
            if (ev)
1459
                virObjectEventStateQueue(g_pVBoxGlobalData->domainEvents, ev);
1460 1461 1462 1463 1464 1465 1466 1467
        }
    }

    vboxDriverUnlock(g_pVBoxGlobalData);

    return NS_OK;
}

1468
static nsresult PR_COM_METHOD
1469
vboxCallbackOnMachineDataChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
1470 1471
                                PRUnichar *machineId)
{
1472
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1473 1474 1475 1476 1477
    DEBUGPRUnichar("machineId", machineId);

    return NS_OK;
}

1478
static nsresult PR_COM_METHOD
1479
vboxCallbackOnExtraDataCanChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
1480 1481 1482
                                 PRUnichar *machineId, PRUnichar *key,
                                 PRUnichar *value,
                                 PRUnichar **error ATTRIBUTE_UNUSED,
1483
                                 PRBool *allowChange ATTRIBUTE_UNUSED)
1484
{
1485
    VIR_DEBUG("IVirtualBoxCallback: %p, allowChange: %s", pThis, *allowChange ? "true" : "false");
1486 1487 1488 1489 1490 1491 1492
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("key", key);
    DEBUGPRUnichar("value", value);

    return NS_OK;
}

1493
static nsresult PR_COM_METHOD
1494 1495
vboxCallbackOnExtraDataChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                              PRUnichar *machineId,
1496 1497
                              PRUnichar *key, PRUnichar *value)
{
1498
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1499 1500 1501 1502 1503 1504 1505
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("key", key);
    DEBUGPRUnichar("value", value);

    return NS_OK;
}

1506
# if VBOX_API_VERSION < 3001000
1507
static nsresult PR_COM_METHOD
1508 1509 1510 1511
vboxCallbackOnMediaRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                              PRUnichar *mediaId,
                              PRUint32 mediaType ATTRIBUTE_UNUSED,
                              PRBool registered ATTRIBUTE_UNUSED)
1512
{
1513 1514
    VIR_DEBUG("IVirtualBoxCallback: %p, registered: %s", pThis, registered ? "true" : "false");
    VIR_DEBUG("mediaType: %d", mediaType);
1515 1516 1517 1518
    DEBUGPRUnichar("mediaId", mediaId);

    return NS_OK;
}
1519 1520
# else  /* VBOX_API_VERSION >= 3001000 */
# endif /* VBOX_API_VERSION >= 3001000 */
1521

1522
static nsresult PR_COM_METHOD
1523
vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
1524 1525
                                PRUnichar *machineId, PRBool registered)
{
1526 1527 1528 1529 1530 1531
    virDomainPtr dom = NULL;
    int event        = 0;
    int detail       = 0;

    vboxDriverLock(g_pVBoxGlobalData);

1532
    VIR_DEBUG("IVirtualBoxCallback: %p, registered: %s", pThis, registered ? "true" : "false");
1533 1534 1535 1536 1537 1538 1539
    DEBUGPRUnichar("machineId", machineId);

    if (machineId) {
        char *machineIdUtf8       = NULL;
        unsigned char uuid[VIR_UUID_BUFLEN];

        g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
1540
        ignore_value(virUUIDParse(machineIdUtf8, uuid));
1541 1542 1543

        dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
        if (dom) {
1544
            virObjectEventPtr ev;
1545 1546

            /* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED
J
Ján Tomko 已提交
1547
             * event because the when the machine is de-registered the call
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
             * to vboxDomainLookupByUUID fails and thus we don't get any
             * dom pointer which is necessary (null dom pointer doesn't work)
             * to show the VIR_DOMAIN_EVENT_UNDEFINED event
             */
            if (registered) {
                event  = VIR_DOMAIN_EVENT_DEFINED;
                detail = VIR_DOMAIN_EVENT_DEFINED_ADDED;
            } else {
                event  = VIR_DOMAIN_EVENT_UNDEFINED;
                detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED;
            }

1560
            ev = virDomainEventLifecycleNewFromDom(dom, event, detail);
1561

1562
            if (ev)
1563
                virObjectEventStateQueue(g_pVBoxGlobalData->domainEvents, ev);
1564 1565 1566 1567 1568 1569 1570 1571
        }
    }

    vboxDriverUnlock(g_pVBoxGlobalData);

    return NS_OK;
}

1572
static nsresult PR_COM_METHOD
1573 1574 1575
vboxCallbackOnSessionStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                                 PRUnichar *machineId,
                                 PRUint32 state ATTRIBUTE_UNUSED)
1576
{
1577
    VIR_DEBUG("IVirtualBoxCallback: %p, state: %d", pThis, state);
1578 1579 1580 1581 1582
    DEBUGPRUnichar("machineId", machineId);

    return NS_OK;
}

1583
static nsresult PR_COM_METHOD
1584 1585
vboxCallbackOnSnapshotTaken(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                            PRUnichar *machineId,
1586 1587
                            PRUnichar *snapshotId)
{
1588
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1589 1590 1591 1592 1593 1594
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("snapshotId", snapshotId);

    return NS_OK;
}

1595
static nsresult PR_COM_METHOD
1596 1597
vboxCallbackOnSnapshotDiscarded(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                                PRUnichar *machineId,
1598 1599
                                PRUnichar *snapshotId)
{
1600
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1601 1602 1603 1604 1605 1606
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("snapshotId", snapshotId);

    return NS_OK;
}

1607
static nsresult PR_COM_METHOD
1608 1609
vboxCallbackOnSnapshotChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                             PRUnichar *machineId,
1610 1611
                             PRUnichar *snapshotId)
{
1612
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1613 1614 1615 1616 1617 1618
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("snapshotId", snapshotId);

    return NS_OK;
}

1619
static nsresult PR_COM_METHOD
1620
vboxCallbackOnGuestPropertyChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
1621 1622 1623
                                  PRUnichar *machineId, PRUnichar *name,
                                  PRUnichar *value, PRUnichar *flags)
{
1624
    VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
1625 1626 1627 1628 1629 1630 1631 1632
    DEBUGPRUnichar("machineId", machineId);
    DEBUGPRUnichar("name", name);
    DEBUGPRUnichar("value", value);
    DEBUGPRUnichar("flags", flags);

    return NS_OK;
}

1633
static nsresult PR_COM_METHOD
1634
vboxCallbackAddRef(nsISupports *pThis ATTRIBUTE_UNUSED)
1635
{
1636 1637 1638 1639
    nsresult c;

    c = ++g_pVBoxGlobalData->vboxCallBackRefCount;

1640
    VIR_DEBUG("pThis: %p, vboxCallback AddRef: %d", pThis, c);
1641 1642 1643 1644

    return c;
}

1645 1646 1647
static nsresult PR_COM_METHOD
vboxCallbackRelease(nsISupports *pThis)
{
1648 1649 1650 1651 1652 1653 1654 1655 1656
    nsresult c;

    c = --g_pVBoxGlobalData->vboxCallBackRefCount;
    if (c == 0) {
        /* delete object */
        VIR_FREE(pThis->vtbl);
        VIR_FREE(pThis);
    }

1657
    VIR_DEBUG("pThis: %p, vboxCallback Release: %d", pThis, c);
1658 1659 1660 1661

    return c;
}

1662 1663 1664
static nsresult PR_COM_METHOD
vboxCallbackQueryInterface(nsISupports *pThis, const nsID *iid, void **resultp)
{
1665 1666 1667 1668 1669
    IVirtualBoxCallback *that = (IVirtualBoxCallback *)pThis;
    static const nsID ivirtualboxCallbackUUID = IVIRTUALBOXCALLBACK_IID;
    static const nsID isupportIID = NS_ISUPPORTS_IID;

    /* Match UUID for IVirtualBoxCallback class */
1670 1671
    if (memcmp(iid, &ivirtualboxCallbackUUID, sizeof(nsID)) == 0 ||
        memcmp(iid, &isupportIID, sizeof(nsID)) == 0) {
1672 1673 1674
        g_pVBoxGlobalData->vboxCallBackRefCount++;
        *resultp = that;

1675
        VIR_DEBUG("pThis: %p, vboxCallback QueryInterface: %d", pThis, g_pVBoxGlobalData->vboxCallBackRefCount);
1676 1677 1678 1679 1680

        return NS_OK;
    }


1681
    VIR_DEBUG("pThis: %p, vboxCallback QueryInterface didn't find a matching interface", pThis);
1682 1683 1684 1685 1686 1687
    DEBUGUUID("The UUID Callback Interface expects", iid);
    DEBUGUUID("The UUID Callback Interface got", &ivirtualboxCallbackUUID);
    return NS_NOINTERFACE;
}


1688
static IVirtualBoxCallback *vboxAllocCallbackObj(void) {
1689 1690
    IVirtualBoxCallback *vboxCallback = NULL;

1691
    /* Allocate, Initialize and return a valid
1692 1693 1694
     * IVirtualBoxCallback object here
     */
    if ((VIR_ALLOC(vboxCallback) < 0) || (VIR_ALLOC(vboxCallback->vtbl) < 0)) {
1695
        VIR_FREE(vboxCallback);
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706
        return NULL;
    }

    {
        vboxCallback->vtbl->nsisupports.AddRef          = &vboxCallbackAddRef;
        vboxCallback->vtbl->nsisupports.Release         = &vboxCallbackRelease;
        vboxCallback->vtbl->nsisupports.QueryInterface  = &vboxCallbackQueryInterface;
        vboxCallback->vtbl->OnMachineStateChange        = &vboxCallbackOnMachineStateChange;
        vboxCallback->vtbl->OnMachineDataChange         = &vboxCallbackOnMachineDataChange;
        vboxCallback->vtbl->OnExtraDataCanChange        = &vboxCallbackOnExtraDataCanChange;
        vboxCallback->vtbl->OnExtraDataChange           = &vboxCallbackOnExtraDataChange;
1707
# if VBOX_API_VERSION < 3001000
1708
        vboxCallback->vtbl->OnMediaRegistered           = &vboxCallbackOnMediaRegistered;
1709 1710
# else  /* VBOX_API_VERSION >= 3001000 */
# endif /* VBOX_API_VERSION >= 3001000 */
1711 1712 1713
        vboxCallback->vtbl->OnMachineRegistered         = &vboxCallbackOnMachineRegistered;
        vboxCallback->vtbl->OnSessionStateChange        = &vboxCallbackOnSessionStateChange;
        vboxCallback->vtbl->OnSnapshotTaken             = &vboxCallbackOnSnapshotTaken;
1714
# if VBOX_API_VERSION < 3002000
1715
        vboxCallback->vtbl->OnSnapshotDiscarded         = &vboxCallbackOnSnapshotDiscarded;
1716
# else /* VBOX_API_VERSION >= 3002000 */
1717
        vboxCallback->vtbl->OnSnapshotDeleted           = &vboxCallbackOnSnapshotDiscarded;
1718
# endif /* VBOX_API_VERSION >= 3002000 */
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730
        vboxCallback->vtbl->OnSnapshotChange            = &vboxCallbackOnSnapshotChange;
        vboxCallback->vtbl->OnGuestPropertyChange       = &vboxCallbackOnGuestPropertyChange;
        g_pVBoxGlobalData->vboxCallBackRefCount = 1;

    }

    return vboxCallback;
}

static void vboxReadCallback(int watch ATTRIBUTE_UNUSED,
                             int fd,
                             int events ATTRIBUTE_UNUSED,
1731 1732
                             void *opaque ATTRIBUTE_UNUSED)
{
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
    if (fd >= 0) {
        g_pVBoxGlobalData->vboxQueue->vtbl->ProcessPendingEvents(g_pVBoxGlobalData->vboxQueue);
    } else {
        nsresult rc;
        PLEvent *pEvent = NULL;

        rc = g_pVBoxGlobalData->vboxQueue->vtbl->WaitForEvent(g_pVBoxGlobalData->vboxQueue, &pEvent);
        if (NS_SUCCEEDED(rc))
            g_pVBoxGlobalData->vboxQueue->vtbl->HandleEvent(g_pVBoxGlobalData->vboxQueue, pEvent);
    }
}

1745 1746 1747 1748 1749 1750
static int
vboxConnectDomainEventRegister(virConnectPtr conn,
                               virConnectDomainEventCallback callback,
                               void *opaque,
                               virFreeCallback freecb)
{
T
Taowei Luo 已提交
1751
    vboxGlobalData *data = conn->privateData;
1752
    int vboxRet          = -1;
1753
    nsresult rc;
T
Taowei Luo 已提交
1754 1755 1756 1757
    int ret = -1;

    if (!data->vboxObj)
        return ret;
1758 1759 1760 1761 1762 1763

    /* Locking has to be there as callbacks are not
     * really fully thread safe
     */
    vboxDriverLock(data);

1764
    if (data->vboxCallback == NULL) {
1765
        data->vboxCallback = vboxAllocCallbackObj();
1766 1767
        if (data->vboxCallback != NULL) {
            rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback);
1768
            if (NS_SUCCEEDED(rc))
1769
                vboxRet = 0;
1770
        }
1771 1772 1773
    } else {
        vboxRet = 0;
    }
1774

1775 1776 1777 1778 1779 1780 1781
    /* Get the vbox file handle and add a event handle to it
     * so that the events can be passed down to the user
     */
    if (vboxRet == 0) {
        if (data->fdWatch < 0) {
            PRInt32 vboxFileHandle;
            vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue);
1782

1783 1784
            data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, NULL, NULL);
        }
1785

1786 1787 1788 1789 1790
        if (data->fdWatch >= 0) {
            /* Once a callback is registered with virtualbox, use a list
             * to store the callbacks registered with libvirt so that
             * later you can iterate over them
             */
1791

1792
            ret = virDomainEventStateRegister(conn, data->domainEvents,
1793
                                              callback, opaque, freecb);
1794
            VIR_DEBUG("virObjectEventStateRegister (ret = %d) (conn: %p, "
1795
                      "callback: %p, opaque: %p, "
1796
                      "freecb: %p)", ret, conn, callback,
1797
                      opaque, freecb);
1798 1799 1800 1801 1802 1803
        }
    }

    vboxDriverUnlock(data);

    if (ret >= 0) {
1804
        return 0;
1805
    } else {
1806
        if (data->vboxObj && data->vboxCallback)
1807 1808 1809 1810 1811
            data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
        return -1;
    }
}

1812 1813 1814 1815
static int
vboxConnectDomainEventDeregister(virConnectPtr conn,
                                 virConnectDomainEventCallback callback)
{
T
Taowei Luo 已提交
1816
    vboxGlobalData *data = conn->privateData;
1817
    int cnt;
T
Taowei Luo 已提交
1818 1819 1820 1821
    int ret = -1;

    if (!data->vboxObj)
        return ret;
1822 1823 1824 1825 1826 1827

    /* Locking has to be there as callbacks are not
     * really fully thread safe
     */
    vboxDriverLock(data);

1828 1829
    cnt = virDomainEventStateDeregister(conn, data->domainEvents,
                                        callback);
1830

1831 1832 1833
    if (data->vboxCallback && cnt == 0) {
        data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
        VBOX_RELEASE(data->vboxCallback);
1834

1835 1836 1837
        /* Remove the Event file handle on which we are listening as well */
        virEventRemoveHandle(data->fdWatch);
        data->fdWatch = -1;
1838 1839 1840 1841
    }

    vboxDriverUnlock(data);

1842 1843 1844
    if (cnt >= 0)
        ret = 0;

1845 1846 1847
    return ret;
}

1848 1849 1850 1851 1852
static int vboxConnectDomainEventRegisterAny(virConnectPtr conn,
                                             virDomainPtr dom,
                                             int eventID,
                                             virConnectDomainEventGenericCallback callback,
                                             void *opaque,
1853 1854
                                             virFreeCallback freecb)
{
T
Taowei Luo 已提交
1855
    vboxGlobalData *data = conn->privateData;
1856 1857
    int vboxRet          = -1;
    nsresult rc;
T
Taowei Luo 已提交
1858 1859 1860 1861
    int ret = -1;

    if (!data->vboxObj)
        return ret;
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871

    /* Locking has to be there as callbacks are not
     * really fully thread safe
     */
    vboxDriverLock(data);

    if (data->vboxCallback == NULL) {
        data->vboxCallback = vboxAllocCallbackObj();
        if (data->vboxCallback != NULL) {
            rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback);
1872
            if (NS_SUCCEEDED(rc))
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
                vboxRet = 0;
        }
    } else {
        vboxRet = 0;
    }

    /* Get the vbox file handle and add a event handle to it
     * so that the events can be passed down to the user
     */
    if (vboxRet == 0) {
        if (data->fdWatch < 0) {
            PRInt32 vboxFileHandle;
            vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue);

            data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, NULL, NULL);
        }

        if (data->fdWatch >= 0) {
            /* Once a callback is registered with virtualbox, use a list
             * to store the callbacks registered with libvirt so that
             * later you can iterate over them
             */

1896
            if (virDomainEventStateRegisterID(conn, data->domainEvents,
1897 1898
                                              dom, eventID,
                                              callback, opaque, freecb, &ret) < 0)
1899
                ret = -1;
1900
            VIR_DEBUG("virDomainEventStateRegisterID (ret = %d) (conn: %p, "
1901
                      "callback: %p, opaque: %p, "
1902
                      "freecb: %p)", ret, conn, callback,
1903
                      opaque, freecb);
1904 1905 1906 1907 1908 1909 1910 1911
        }
    }

    vboxDriverUnlock(data);

    if (ret >= 0) {
        return ret;
    } else {
1912
        if (data->vboxObj && data->vboxCallback)
1913 1914 1915 1916 1917
            data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
        return -1;
    }
}

1918 1919 1920 1921
static int
vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
                                    int callbackID)
{
T
Taowei Luo 已提交
1922
    vboxGlobalData *data = conn->privateData;
1923
    int cnt;
T
Taowei Luo 已提交
1924 1925 1926 1927
    int ret = -1;

    if (!data->vboxObj)
        return ret;
1928 1929 1930 1931 1932 1933

    /* Locking has to be there as callbacks are not
     * really fully thread safe
     */
    vboxDriverLock(data);

1934
    cnt = virObjectEventStateDeregisterID(conn, data->domainEvents,
1935
                                          callbackID);
1936

1937 1938 1939
    if (data->vboxCallback && cnt == 0) {
        data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
        VBOX_RELEASE(data->vboxCallback);
1940

1941 1942 1943
        /* Remove the Event file handle on which we are listening as well */
        virEventRemoveHandle(data->fdWatch);
        data->fdWatch = -1;
1944 1945 1946 1947
    }

    vboxDriverUnlock(data);

1948 1949 1950
    if (cnt >= 0)
        ret = 0;

1951 1952 1953
    return ret;
}

T
Taowei 已提交
1954
static void
1955
_registerDomainEvent(virHypervisorDriverPtr driver)
T
Taowei 已提交
1956 1957 1958 1959 1960 1961 1962
{
    driver->connectDomainEventRegister = vboxConnectDomainEventRegister; /* 0.7.0 */
    driver->connectDomainEventDeregister = vboxConnectDomainEventDeregister; /* 0.7.0 */
    driver->connectDomainEventRegisterAny = vboxConnectDomainEventRegisterAny; /* 0.8.0 */
    driver->connectDomainEventDeregisterAny = vboxConnectDomainEventDeregisterAny; /* 0.8.0 */
}

1963
#endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
1964

T
Taowei 已提交
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
static int _pfnInitialize(vboxGlobalData *data)
{
    data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
    if (data->pFuncs == NULL)
        return -1;
#if VBOX_XPCOMC_VERSION == 0x00010000U
    data->pFuncs->pfnComInitialize(&data->vboxObj, &data->vboxSession);
#else  /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
    data->pFuncs->pfnComInitialize(IVIRTUALBOX_IID_STR, &data->vboxObj, ISESSION_IID_STR, &data->vboxSession);
#endif /* !(VBOX_XPCOMC_VERSION == 0x00010000U) */
    return 0;
}
1977

T
Taowei 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
static int
_initializeDomainEvent(vboxGlobalData *data ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
    /* No event queue functionality in 2.2.* and 4.* as of now */
    vboxUnsupported();
#else /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
    /* Initialize the fWatch needed for Event Callbacks */
    data->fdWatch = -1;
    data->pFuncs->pfnGetEventQueue(&data->vboxQueue);
    if (data->vboxQueue == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("nsIEventQueue object is null"));
        return -1;
    }
#endif /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
    return 0;
}
1996

T
Taowei 已提交
1997 1998 1999 2000 2001 2002 2003 2004 2005
static
void _registerGlobalData(vboxGlobalData *data ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION == 2002000
    vboxUnsupported();
#else /* VBOX_API_VERSION != 2002000 */
    g_pVBoxGlobalData = data;
#endif /* VBOX_API_VERSION != 2002000 */
}
2006

T
Taowei 已提交
2007
#if VBOX_API_VERSION < 4000000
2008

T
Taowei 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028
# if VBOX_API_VERSION < 3001000
static void
_detachDevices(vboxGlobalData *data ATTRIBUTE_UNUSED,
               IMachine *machine, PRUnichar *hddcnameUtf16)
{
    /* Disconnect all the drives if present */
    machine->vtbl->DetachHardDisk(machine, hddcnameUtf16, 0, 0);
    machine->vtbl->DetachHardDisk(machine, hddcnameUtf16, 0, 1);
    machine->vtbl->DetachHardDisk(machine, hddcnameUtf16, 1, 1);
}
# else  /* VBOX_API_VERSION >= 3001000 */
static void
_detachDevices(vboxGlobalData *data, IMachine *machine,
               PRUnichar *hddcnameUtf16 ATTRIBUTE_UNUSED)
{
    /* get all the controller first, then the attachments and
    * remove them all so that the machine can be undefined
    */
   vboxArray storageControllers = VBOX_ARRAY_INITIALIZER;
   size_t i = 0, j = 0;
2029

T
Taowei 已提交
2030 2031
   vboxArrayGet(&storageControllers, machine,
                machine->vtbl->GetStorageControllers);
2032

T
Taowei 已提交
2033 2034 2035 2036
   for (i = 0; i < storageControllers.count; i++) {
       IStorageController *strCtl = storageControllers.items[i];
       PRUnichar *strCtlName = NULL;
       vboxArray mediumAttachments = VBOX_ARRAY_INITIALIZER;
2037

T
Taowei 已提交
2038 2039
       if (!strCtl)
           continue;
2040

T
Taowei 已提交
2041 2042 2043 2044
       strCtl->vtbl->GetName(strCtl, &strCtlName);
       vboxArrayGetWithPtrArg(&mediumAttachments, machine,
                              machine->vtbl->GetMediumAttachmentsOfController,
                              strCtlName);
2045

T
Taowei 已提交
2046 2047 2048 2049
       for (j = 0; j < mediumAttachments.count; j++) {
           IMediumAttachment *medAtt = mediumAttachments.items[j];
           PRInt32 port = ~0U;
           PRInt32 device = ~0U;
2050

T
Taowei 已提交
2051 2052
           if (!medAtt)
               continue;
2053

T
Taowei 已提交
2054 2055
           medAtt->vtbl->GetPort(medAtt, &port);
           medAtt->vtbl->GetDevice(medAtt, &device);
2056

T
Taowei 已提交
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
           if ((port != ~0U) && (device != ~0U)) {
               machine->vtbl->DetachDevice(machine,
                                           strCtlName,
                                           port,
                                           device);
           }
       }
       vboxArrayRelease(&storageControllers);
       machine->vtbl->RemoveStorageController(machine, strCtlName);
       VBOX_UTF16_FREE(strCtlName);
   }
   vboxArrayRelease(&storageControllers);
}
# endif /* VBOX_API_VERSION >= 3001000 */
2071

T
Taowei 已提交
2072 2073 2074 2075 2076
static nsresult
_unregisterMachine(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine)
{
    return data->vboxObj->vtbl->UnregisterMachine(data->vboxObj, IID_MEMBER(value), machine);
}
2077

T
Taowei 已提交
2078 2079 2080 2081 2082
static void
_deleteConfig(IMachine *machine)
{
    machine->vtbl->DeleteSettings(machine);
}
2083

T
Taowei 已提交
2084
#else /* VBOX_API_VERSION >= 4000000 */
2085

T
Taowei 已提交
2086 2087 2088 2089 2090 2091 2092
static void
_detachDevices(vboxGlobalData *data ATTRIBUTE_UNUSED,
               IMachine *machine ATTRIBUTE_UNUSED,
               PRUnichar *hddcnameUtf16 ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
}
2093

T
Taowei 已提交
2094 2095 2096 2097 2098
static nsresult
_unregisterMachine(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine **machine)
{
    nsresult rc;
    vboxArray media = VBOX_ARRAY_INITIALIZER;
2099
    rc = data->vboxObj->vtbl->FindMachine(data->vboxObj, IID_MEMBER(value), machine);
T
Taowei 已提交
2100 2101 2102 2103 2104
    if (NS_FAILED(rc)) {
        virReportError(VIR_ERR_NO_DOMAIN, "%s",
                       _("no domain with matching uuid"));
        return rc;
    }
2105

T
Taowei 已提交
2106 2107 2108 2109 2110 2111 2112 2113 2114
    /* We're not interested in the array returned by the Unregister method,
     * but in the side effect of unregistering the virtual machine. In order
     * to call the Unregister method correctly we need to use the vboxArray
     * wrapper here. */
    rc = vboxArrayGetWithUintArg(&media, *machine, (*machine)->vtbl->Unregister,
                                 CleanupMode_DetachAllReturnNone);
    vboxArrayUnalloc(&media);
    return rc;
}
2115

T
Taowei 已提交
2116 2117 2118 2119
static void
_deleteConfig(IMachine *machine)
{
    IProgress *progress = NULL;
2120

T
Taowei 已提交
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130
    /* The IMachine Delete method takes an array of IMedium items to be
     * deleted along with the virtual machine. We just want to pass an
     * empty array. But instead of adding a full vboxArraySetWithReturn to
     * the glue layer (in order to handle the required signature of the
     * Delete method) we use a local solution here. */
# ifdef WIN32
    SAFEARRAY *safeArray = NULL;
    typedef HRESULT __stdcall (*IMachine_Delete)(IMachine *self,
                                                 SAFEARRAY **media,
                                                 IProgress **progress);
2131

T
Taowei 已提交
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
#  if VBOX_API_VERSION < 4003000
    ((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress);
#  else
    ((IMachine_Delete)machine->vtbl->DeleteConfig)(machine, &safeArray, &progress);
#  endif
# else
    /* XPCOM doesn't like NULL as an array, even when the array size is 0.
     * Instead pass it a dummy array to avoid passing NULL. */
    IMedium *array[] = { NULL };
#  if VBOX_API_VERSION < 4003000
    machine->vtbl->Delete(machine, 0, array, &progress);
#  else
    machine->vtbl->DeleteConfig(machine, 0, array, &progress);
#  endif
# endif
    if (progress != NULL) {
        progress->vtbl->WaitForCompletion(progress, -1);
        VBOX_RELEASE(progress);
2150
    }
T
Taowei 已提交
2151
}
2152

T
Taowei 已提交
2153
#endif /* VBOX_API_VERSION >= 4000000 */
2154

T
Taowei 已提交
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189
#if VBOX_API_VERSION < 3001000

static void
_dumpIDEHDDsOld(virDomainDefPtr def,
                vboxGlobalData *data,
                IMachine *machine)
{
    PRInt32       hddNum                = 0;
    IHardDisk    *hardDiskPM            = NULL;
    IHardDisk    *hardDiskPS            = NULL;
    IHardDisk    *hardDiskSS            = NULL;
    const char   *hddBus                = "IDE";
    PRUnichar    *hddBusUtf16           = NULL;

    /* dump IDE hdds if present */
    VBOX_UTF8_TO_UTF16(hddBus, &hddBusUtf16);

    def->ndisks = 0;
    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 0,  &hardDiskPM);
    if (hardDiskPM)
        def->ndisks++;

    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 1,  &hardDiskPS);
    if (hardDiskPS)
        def->ndisks++;

    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 1, 1,  &hardDiskSS);
    if (hardDiskSS)
        def->ndisks++;

    VBOX_UTF16_FREE(hddBusUtf16);

    if ((def->ndisks > 0) && (VIR_ALLOC_N(def->disks, def->ndisks) >= 0)) {
        size_t i;
        for (i = 0; i < def->ndisks; i++) {
2190
            if ((def->disks[i] = virDomainDiskDefNew(NULL))) {
T
Taowei 已提交
2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
                def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK;
                def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE;
                virDomainDiskSetType(def->disks[i],
                                     VIR_STORAGE_TYPE_FILE);
            }
        }
    }

    if (hardDiskPM) {
        PRUnichar *hddlocationUtf16 = NULL;
        char *hddlocation           = NULL;
        PRUint32 hddType            = HardDiskType_Normal;

        hardDiskPM->vtbl->imedium.GetLocation((IMedium *)hardDiskPM, &hddlocationUtf16);
        VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);

        hardDiskPM->vtbl->GetType(hardDiskPM, &hddType);

        if (hddType == HardDiskType_Immutable)
            def->disks[hddNum]->src->readonly = true;
        ignore_value(virDomainDiskSetSource(def->disks[hddNum],
                                            hddlocation));
        ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hda"));
        hddNum++;

        VBOX_UTF8_FREE(hddlocation);
        VBOX_UTF16_FREE(hddlocationUtf16);
        VBOX_MEDIUM_RELEASE(hardDiskPM);
    }

    if (hardDiskPS) {
        PRUnichar *hddlocationUtf16 = NULL;
        char *hddlocation           = NULL;
        PRUint32 hddType            = HardDiskType_Normal;

        hardDiskPS->vtbl->imedium.GetLocation((IMedium *)hardDiskPS, &hddlocationUtf16);
        VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);

        hardDiskPS->vtbl->GetType(hardDiskPS, &hddType);

        if (hddType == HardDiskType_Immutable)
            def->disks[hddNum]->src->readonly = true;
        ignore_value(virDomainDiskSetSource(def->disks[hddNum],
                                            hddlocation));
        ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hdb"));
        hddNum++;

        VBOX_UTF8_FREE(hddlocation);
        VBOX_UTF16_FREE(hddlocationUtf16);
        VBOX_MEDIUM_RELEASE(hardDiskPS);
    }

    if (hardDiskSS) {
        PRUnichar *hddlocationUtf16 = NULL;
        char *hddlocation           = NULL;
        PRUint32 hddType            = HardDiskType_Normal;

        hardDiskSS->vtbl->imedium.GetLocation((IMedium *)hardDiskSS, &hddlocationUtf16);
        VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);

        hardDiskSS->vtbl->GetType(hardDiskSS, &hddType);

        if (hddType == HardDiskType_Immutable)
            def->disks[hddNum]->src->readonly = true;
        ignore_value(virDomainDiskSetSource(def->disks[hddNum],
                                            hddlocation));
        ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hdd"));
        hddNum++;

        VBOX_UTF8_FREE(hddlocation);
        VBOX_UTF16_FREE(hddlocationUtf16);
        VBOX_MEDIUM_RELEASE(hardDiskSS);
    }
}

static void
_dumpDVD(virDomainDefPtr def,
         vboxGlobalData *data,
         IMachine *machine)
{
    IDVDDrive *dvdDrive      = NULL;
    IDVDImage *dvdImage      = NULL;
    PRUnichar *locationUtf16 = NULL;
    char *location           = NULL;


    /* dump CDROM/DVD if the drive is attached and has DVD/CD in it */
    machine->vtbl->GetDVDDrive(machine, &dvdDrive);
    if (!dvdDrive)
        return;

    PRUint32 state = DriveState_Null;

    dvdDrive->vtbl->GetState(dvdDrive, &state);
    if (state != DriveState_ImageMounted)
        goto cleanupDVDDrive;


    dvdDrive->vtbl->GetImage(dvdDrive, &dvdImage);
    if (!dvdImage)
        goto cleanupDVDDrive;

    dvdImage->vtbl->imedium.GetLocation((IMedium *)dvdImage, &locationUtf16);
    VBOX_UTF16_TO_UTF8(locationUtf16, &location);

    def->ndisks++;
    if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) {
2298
        if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew(NULL))) {
T
Taowei 已提交
2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321
            def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
            def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE;
            virDomainDiskSetType(def->disks[def->ndisks - 1],
                                 VIR_STORAGE_TYPE_FILE);
            def->disks[def->ndisks - 1]->src->readonly = true;
            ignore_value(virDomainDiskSetSource(def->disks[def->ndisks - 1], location));
            ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "hdc"));
            def->ndisks--;
        } else {
            def->ndisks--;
        }
    } else {
        def->ndisks--;
    }

    VBOX_UTF8_FREE(location);
    VBOX_UTF16_FREE(locationUtf16);
    VBOX_MEDIUM_RELEASE(dvdImage);

 cleanupDVDDrive:
    VBOX_RELEASE(dvdDrive);
}

T
Taowei 已提交
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
static int
_attachDVD(vboxGlobalData *data, IMachine *machine, const char *src)
{
    IDVDDrive *dvdDrive     = NULL;
    IDVDImage *dvdImage     = NULL;
    PRUnichar *dvdfileUtf16 = NULL;
    vboxIID dvduuid = VBOX_IID_INITIALIZER;
    vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
    nsresult rc;
    int ret = -1;

    /* Currently CDROM/DVD Drive is always IDE
     * Secondary Master so neglecting the following
     * parameter dev->data.disk->bus
     */
    machine->vtbl->GetDVDDrive(machine, &dvdDrive);
    if (!dvdDrive)
        return ret;

    VBOX_UTF8_TO_UTF16(src, &dvdfileUtf16);

    data->vboxObj->vtbl->FindDVDImage(data->vboxObj, dvdfileUtf16, &dvdImage);
2344
    if (!dvdImage)
T
Taowei 已提交
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377
        data->vboxObj->vtbl->OpenDVDImage(data->vboxObj, dvdfileUtf16, dvdemptyuuid.value, &dvdImage);

    if (!dvdImage)
        goto cleanup;

    rc = dvdImage->vtbl->imedium.GetId((IMedium *)dvdImage, &dvduuid.value);
    if (NS_FAILED(rc)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("can't get the uuid of the file to "
                         "be attached to cdrom: %s, rc=%08x"),
                       src, (unsigned)rc);
    } else {
        /* unmount the previous mounted image */
        dvdDrive->vtbl->Unmount(dvdDrive);
        rc = dvdDrive->vtbl->MountImage(dvdDrive, dvduuid.value);
        if (NS_FAILED(rc)) {
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("could not attach the file to cdrom: %s, rc=%08x"),
                           src, (unsigned)rc);
        } else {
            ret = 0;
            DEBUGIID("CD/DVD Image UUID:", dvduuid.value);
        }
    }

    VBOX_MEDIUM_RELEASE(dvdImage);
 cleanup:
    vboxIIDUnalloc(&dvduuid);
    VBOX_UTF16_FREE(dvdfileUtf16);
    VBOX_RELEASE(dvdDrive);
    return ret;
}

T
Taowei 已提交
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404
static int
_detachDVD(IMachine *machine)
{
    IDVDDrive *dvdDrive = NULL;
    int ret = -1;
    nsresult rc;
    /* Currently CDROM/DVD Drive is always IDE
     * Secondary Master so neglecting the following
     * parameter dev->data.disk->bus
     */
    machine->vtbl->GetDVDDrive(machine, &dvdDrive);
    if (!dvdDrive)
        return ret;

    rc = dvdDrive->vtbl->Unmount(dvdDrive);
    if (NS_FAILED(rc)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not de-attach the mounted ISO, rc=%08x"),
                       (unsigned)rc);
    } else {
        ret = 0;
    }
    VBOX_RELEASE(dvdDrive);

    return ret;
}

T
Taowei 已提交
2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
static void
_dumpFloppy(virDomainDefPtr def,
            vboxGlobalData *data,
            IMachine *machine)
{
    IFloppyDrive *floppyDrive = NULL;
    IFloppyImage *floppyImage = NULL;
    PRUnichar *locationUtf16  = NULL;
    char *location            = NULL;
    PRBool enabled            = PR_FALSE;
    PRUint32 state            = DriveState_Null;

    /* dump Floppy if the drive is attached and has floppy in it */
    machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
    if (!floppyDrive)
        return;

    floppyDrive->vtbl->GetEnabled(floppyDrive, &enabled);
    if (!enabled)
        goto cleanupFloppyDrive;


    floppyDrive->vtbl->GetState(floppyDrive, &state);
    if (state != DriveState_ImageMounted)
        goto cleanupFloppyDrive;

    floppyDrive->vtbl->GetImage(floppyDrive, &floppyImage);
    if (!floppyImage)
        goto cleanupFloppyDrive;

    floppyImage->vtbl->imedium.GetLocation((IMedium *)floppyImage, &locationUtf16);
    VBOX_UTF16_TO_UTF8(locationUtf16, &location);

    def->ndisks++;
    if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) {
2440
        if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew(NULL))) {
T
Taowei 已提交
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
            def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
            def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC;
            virDomainDiskSetType(def->disks[def->ndisks - 1],
                                 VIR_STORAGE_TYPE_FILE);
            def->disks[def->ndisks - 1]->src->readonly = false;
            ignore_value(virDomainDiskSetSource(def->disks[def->ndisks - 1], location));
            ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "fda"));
            def->ndisks--;
        } else {
            def->ndisks--;
        }
    } else {
        def->ndisks--;
    }

    VBOX_UTF8_FREE(location);
    VBOX_UTF16_FREE(locationUtf16);
    VBOX_MEDIUM_RELEASE(floppyImage);

 cleanupFloppyDrive:
    VBOX_RELEASE(floppyDrive);
}

T
Taowei 已提交
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522
static int
_attachFloppy(vboxGlobalData *data, IMachine *machine, const char *src)
{
    IFloppyDrive *floppyDrive;
    IFloppyImage *floppyImage   = NULL;
    PRUnichar *fdfileUtf16      = NULL;
    vboxIID fduuid = VBOX_IID_INITIALIZER;
    vboxIID fdemptyuuid = VBOX_IID_INITIALIZER;
    nsresult rc;
    int ret = -1;

    machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
    if (!floppyDrive)
        return ret;

    rc = floppyDrive->vtbl->SetEnabled(floppyDrive, 1);
    if (NS_FAILED(rc))
        goto cleanup;

    VBOX_UTF8_TO_UTF16(src, &fdfileUtf16);
    rc = data->vboxObj->vtbl->FindFloppyImage(data->vboxObj,
                                              fdfileUtf16,
                                              &floppyImage);

    if (!floppyImage) {
        data->vboxObj->vtbl->OpenFloppyImage(data->vboxObj,
                                             fdfileUtf16,
                                             fdemptyuuid.value,
                                             &floppyImage);
    }

    if (floppyImage) {
        rc = floppyImage->vtbl->imedium.GetId((IMedium *)floppyImage, &fduuid.value);
        if (NS_FAILED(rc)) {
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("can't get the uuid of the file to be "
                             "attached to floppy drive: %s, rc=%08x"),
                           src, (unsigned)rc);
        } else {
            rc = floppyDrive->vtbl->MountImage(floppyDrive, fduuid.value);
            if (NS_FAILED(rc)) {
                virReportError(VIR_ERR_INTERNAL_ERROR,
                               _("could not attach the file to floppy drive: %s, rc=%08x"),
                               src, (unsigned)rc);
            } else {
                ret = 0;
                DEBUGIID("attached floppy, UUID:", fduuid.value);
            }
        }
        VBOX_MEDIUM_RELEASE(floppyImage);
    }
    vboxIIDUnalloc(&fduuid);
    VBOX_UTF16_FREE(fdfileUtf16);

 cleanup:
    VBOX_RELEASE(floppyDrive);
    return ret;
}

T
Taowei 已提交
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
static int
_detachFloppy(IMachine *machine)
{
    IFloppyDrive *floppyDrive;
    int ret = -1;
    nsresult rc;

    machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
    if (!floppyDrive)
        return ret;

    PRBool enabled = PR_FALSE;

    floppyDrive->vtbl->GetEnabled(floppyDrive, &enabled);
    if (enabled) {
        rc = floppyDrive->vtbl->Unmount(floppyDrive);
        if (NS_FAILED(rc)) {
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("could not attach the file "
                             "to floppy drive, rc=%08x"),
                           (unsigned)rc);
        } else {
            ret = 0;
        }
    } else {
        /* If you are here means floppy drive is already unmounted
         * so don't flag error, just say everything is fine and quit
         */
        ret = 0;
    }
    VBOX_RELEASE(floppyDrive);

    return ret;
}

T
Taowei 已提交
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575
#else  /* VBOX_API_VERSION >= 3001000 */

static void
_dumpIDEHDDsOld(virDomainDefPtr def ATTRIBUTE_UNUSED,
                vboxGlobalData *data ATTRIBUTE_UNUSED,
                IMachine *machine ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
}

static void
_dumpDVD(virDomainDefPtr def ATTRIBUTE_UNUSED,
         vboxGlobalData *data ATTRIBUTE_UNUSED,
         IMachine *machine ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
}

T
Taowei 已提交
2576 2577 2578 2579 2580 2581 2582 2583 2584
static int
_attachDVD(vboxGlobalData *data ATTRIBUTE_UNUSED,
           IMachine *machine ATTRIBUTE_UNUSED,
           const char *src ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

T
Taowei 已提交
2585 2586 2587 2588 2589 2590 2591
static int
_detachDVD(IMachine *machine ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

T
Taowei 已提交
2592 2593 2594 2595 2596 2597 2598 2599
static void
_dumpFloppy(virDomainDefPtr def ATTRIBUTE_UNUSED,
            vboxGlobalData *data ATTRIBUTE_UNUSED,
            IMachine *machine ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
}

T
Taowei 已提交
2600 2601 2602 2603 2604 2605 2606 2607 2608
static int
_attachFloppy(vboxGlobalData *data ATTRIBUTE_UNUSED,
              IMachine *machine ATTRIBUTE_UNUSED,
              const char *src ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

T
Taowei 已提交
2609 2610 2611 2612 2613 2614 2615
static int
_detachFloppy(IMachine *machine ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

T
Taowei 已提交
2616 2617
#endif  /* VBOX_API_VERSION >= 3001000 */

T
Taowei 已提交
2618 2619 2620 2621
static void _pfnUninitialize(vboxGlobalData *data)
{
    if (data->pFuncs)
        data->pFuncs->pfnComUninitialize();
2622
}
2623

T
Taowei 已提交
2624
static void _pfnComUnallocMem(PCVBOXXPCOM pFuncs, void *pv)
2625
{
T
Taowei 已提交
2626 2627
    pFuncs->pfnComUnallocMem(pv);
}
2628

T
Taowei 已提交
2629 2630 2631 2632
static void _pfnUtf16Free(PCVBOXXPCOM pFuncs, PRUnichar *pwszString)
{
    pFuncs->pfnUtf16Free(pwszString);
}
E
Eric Blake 已提交
2633

T
Taowei 已提交
2634 2635 2636 2637
static void _pfnUtf8Free(PCVBOXXPCOM pFuncs, char *pszString)
{
    pFuncs->pfnUtf8Free(pszString);
}
2638

T
Taowei 已提交
2639 2640 2641 2642
static int _pfnUtf16ToUtf8(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString)
{
    return pFuncs->pfnUtf16ToUtf8(pwszString, ppszString);
}
2643

T
Taowei 已提交
2644 2645 2646 2647
static int _pfnUtf8ToUtf16(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString)
{
    return pFuncs->pfnUtf8ToUtf16(pszString, ppwszString);
}
2648

T
Taowei 已提交
2649
#if VBOX_API_VERSION == 2002000
2650

T
Taowei 已提交
2651 2652 2653 2654
static void _vboxIIDInitialize(vboxIIDUnion *iidu)
{
    memset(iidu, 0, sizeof(vboxIIDUnion));
}
2655

T
Taowei 已提交
2656 2657 2658 2659 2660 2661 2662 2663
static void _DEBUGIID(const char *msg, vboxIIDUnion *iidu)
{
# ifdef WIN32
    DEBUGUUID(msg, (nsID *)&IID_MEMBER(value));
# else /* !WIN32 */
    DEBUGUUID(msg, IID_MEMBER(value));
# endif /* !WIN32 */
}
2664

T
Taowei 已提交
2665
#else /* VBOX_API_VERSION != 2002000 */
2666

T
Taowei 已提交
2667 2668 2669 2670 2671
static void _vboxIIDInitialize(vboxIIDUnion *iidu)
{
    memset(iidu, 0, sizeof(vboxIIDUnion));
    IID_MEMBER(owner) = true;
}
2672

T
Taowei 已提交
2673 2674 2675 2676
static void _DEBUGIID(const char *msg, vboxIIDUnion *iidu)
{
    DEBUGPRUnichar(msg, IID_MEMBER(value));
}
2677

T
Taowei 已提交
2678
#endif /* VBOX_API_VERSION != 2002000 */
2679

2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691
static void
_vboxIIDToUtf8(vboxGlobalData *data ATTRIBUTE_UNUSED,
               vboxIIDUnion *iidu ATTRIBUTE_UNUSED,
               char **utf8 ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION == 2002000
    vboxUnsupported();
#else /* !(VBOX_API_VERSION == 2002000) */
    data->pFuncs->pfnUtf16ToUtf8(IID_MEMBER(value), utf8);
#endif /* !(VBOX_API_VERSION == 2002000) */
}

2692 2693 2694 2695 2696 2697
static nsresult
_vboxArrayGetWithIIDArg(vboxArray *array, void *self, void *getter, vboxIIDUnion *iidu)
{
    return vboxArrayGetWithPtrArg(array, self, getter, IID_MEMBER(value));
}

T
Taowei 已提交
2698 2699 2700 2701
static void* _handleGetMachines(IVirtualBox *vboxObj)
{
    return vboxObj->vtbl->GetMachines;
}
2702

2703 2704 2705 2706 2707
static void* _handleGetHardDisks(IVirtualBox *vboxObj)
{
    return vboxObj->vtbl->GetHardDisks;
}

T
Taowei 已提交
2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726
static void* _handleUSBGetDeviceFilters(IUSBCommon *USBCommon)
{
    return USBCommon->vtbl->GetDeviceFilters;
}

static void* _handleMachineGetMediumAttachments(IMachine *machine)
{
#if VBOX_API_VERSION < 3001000
    return machine->vtbl->GetHardDiskAttachments;
#else /* VBOX_API_VERSION >= 3001000 */
    return machine->vtbl->GetMediumAttachments;
#endif /* VBOX_API_VERSION >= 3001000 */
}

static void* _handleMachineGetSharedFolders(IMachine *machine)
{
    return machine->vtbl->GetSharedFolders;
}

2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
static void* _handleSnapshotGetChildren(ISnapshot *snapshot)
{
    return snapshot->vtbl->GetChildren;
}

static void* _handleMediumGetChildren(IMedium *medium ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 3001000
    vboxUnsupported();
    return 0;
#else /* VBOX_API_VERSION >= 3001000 */
    return medium->vtbl->GetChildren;
#endif /* VBOX_API_VERSION >= 3001000 */
}

static void* _handleMediumGetSnapshotIds(IMedium *medium)
{
    return medium->vtbl->GetSnapshotIds;
}

T
Taowei Luo 已提交
2747 2748 2749 2750 2751
static void* _handleMediumGetMachineIds(IMedium *medium)
{
    return medium->vtbl->GetMachineIds;
}

T
Taowei 已提交
2752 2753 2754 2755 2756
static void* _handleHostGetNetworkInterfaces(IHost *host)
{
    return host->vtbl->GetNetworkInterfaces;
}

T
Taowei 已提交
2757 2758 2759 2760
static nsresult _nsisupportsRelease(nsISupports *nsi)
{
    return nsi->vtbl->Release(nsi);
}
2761

2762 2763 2764 2765 2766
static nsresult _nsisupportsAddRef(nsISupports *nsi)
{
    return nsi->vtbl->AddRef(nsi);
}

T
Taowei 已提交
2767 2768 2769 2770 2771
static nsresult
_virtualboxGetVersion(IVirtualBox *vboxObj, PRUnichar **versionUtf16)
{
    return vboxObj->vtbl->GetVersion(vboxObj, versionUtf16);
}
2772

T
Taowei 已提交
2773
#if VBOX_API_VERSION < 4000000
2774

T
Taowei 已提交
2775 2776 2777 2778 2779
static nsresult
_virtualboxGetMachine(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine)
{
    return vboxObj->vtbl->GetMachine(vboxObj, IID_MEMBER(value), machine);
}
2780

T
Taowei 已提交
2781
#else /* VBOX_API_VERSION >= 4000000 */
2782

T
Taowei 已提交
2783 2784 2785 2786
static nsresult
_virtualboxGetMachine(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine)
{
    return vboxObj->vtbl->FindMachine(vboxObj, IID_MEMBER(value), machine);
2787
}
T
Taowei 已提交
2788

2789
#endif /* VBOX_API_VERSION >= 4000000 */
2790

2791 2792 2793 2794 2795 2796
static nsresult
_virtualboxOpenMachine(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine)
{
    return vboxObj->vtbl->OpenMachine(vboxObj, settingsFile, machine);
}

T
Taowei 已提交
2797 2798 2799 2800 2801
static nsresult
_virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemProperties)
{
    return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
}
2802

T
Taowei 已提交
2803 2804 2805 2806 2807 2808
static nsresult
_virtualboxGetHost(IVirtualBox *vboxObj, IHost **host)
{
    return vboxObj->vtbl->GetHost(vboxObj, host);
}

T
Taowei 已提交
2809 2810
static nsresult
_virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED)
2811 2812
{
    vboxIID iid = VBOX_IID_INITIALIZER;
T
Taowei 已提交
2813
    PRUnichar *machineNameUtf16 = NULL;
2814 2815
    nsresult rc;

T
Taowei 已提交
2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866
    VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
    vboxIIDFromUUID(&iid, def->uuid);
    {
#if VBOX_API_VERSION < 3002000
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                    machineNameUtf16,
                                                    NULL,
                                                    NULL,
                                                    iid.value,
                                                    machine);
#elif VBOX_API_VERSION < 4000000 /* 3002000 <= VBOX_API_VERSION < 4000000 */
        PRBool override             = PR_FALSE;
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                machineNameUtf16,
                                                NULL,
                                                NULL,
                                                iid.value,
                                                override,
                                                machine);
#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
        PRBool override             = PR_FALSE;
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                NULL,
                                                machineNameUtf16,
                                                NULL,
                                                iid.value,
                                                override,
                                                machine);
#else /* VBOX_API_VERSION >= 4002000 */
        const char *flagsUUIDPrefix = "UUID=";
        const char *flagsForceOverwrite = "forceOverwrite=0";
        const char *flagsSeparator = ",";
        char createFlags[strlen(flagsUUIDPrefix) + VIR_UUID_STRING_BUFLEN + strlen(flagsSeparator) + strlen(flagsForceOverwrite) + 1];
        PRUnichar *createFlagsUtf16 = NULL;

        snprintf(createFlags, sizeof(createFlags), "%s%s%s%s",
                 flagsUUIDPrefix,
                 uuidstr,
                 flagsSeparator,
                 flagsForceOverwrite
                );
        VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                NULL,
                                                machineNameUtf16,
                                                0,
                                                nsnull,
                                                nsnull,
                                                createFlagsUtf16,
                                                machine);
#endif /* VBOX_API_VERSION >= 4002000 */
2867
    }
T
Taowei 已提交
2868 2869 2870 2871
    VBOX_UTF16_FREE(machineNameUtf16);
    vboxIIDUnalloc(&iid);
    return rc;
}
2872

2873
static nsresult
2874 2875
_virtualboxCreateHardDisk(IVirtualBox *vboxObj, PRUnichar *format,
                          PRUnichar *location, IHardDisk **hardDisk)
2876
{
2877 2878 2879 2880
    /* In vbox 2.2 and 3.0, this function will create a IHardDisk object.
     * In vbox 3.1 and later, this function will create a IMedium object.
     */
    return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, hardDisk);
2881 2882
}

T
Taowei 已提交
2883 2884 2885 2886 2887
static nsresult
_virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine)
{
    return vboxObj->vtbl->RegisterMachine(vboxObj, machine);
}
2888

T
Taowei 已提交
2889
static nsresult
2890 2891 2892 2893
_virtualboxFindHardDisk(IVirtualBox *vboxObj, PRUnichar *location,
                        PRUint32 deviceType ATTRIBUTE_UNUSED,
                        PRUint32 accessMode ATTRIBUTE_UNUSED,
                        IHardDisk **hardDisk)
T
Taowei 已提交
2894
{
2895 2896 2897 2898 2899 2900
    /* In vbox 2.2 and 3.0, this function will create a IHardDisk object.
     * In vbox 3.1 and later, this function will create a IMedium object.
     */
#if VBOX_API_VERSION < 4000000
    return vboxObj->vtbl->FindHardDisk(vboxObj, location, hardDisk);
#elif VBOX_API_VERSION < 4002000
T
Taowei 已提交
2901
    return vboxObj->vtbl->FindMedium(vboxObj, location,
2902 2903
                                     deviceType, hardDisk);
#else /* VBOX_API_VERSION >= 4002000 */
T
Taowei 已提交
2904
    return vboxObj->vtbl->OpenMedium(vboxObj, location,
2905 2906
                                     deviceType, accessMode, PR_FALSE, hardDisk);
#endif /* VBOX_API_VERSION >= 4002000 */
T
Taowei 已提交
2907
}
2908

T
Taowei 已提交
2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931
static nsresult
_virtualboxOpenMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED,
                      PRUnichar *location ATTRIBUTE_UNUSED,
                      PRUint32 deviceType ATTRIBUTE_UNUSED,
                      PRUint32 accessMode ATTRIBUTE_UNUSED,
                      IMedium **medium ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION == 4000000
    return vboxObj->vtbl->OpenMedium(vboxObj,
                                     location,
                                     deviceType, accessMode,
                                     medium);
#elif VBOX_API_VERSION >= 4001000
    return vboxObj->vtbl->OpenMedium(vboxObj,
                                     location,
                                     deviceType, accessMode,
                                     false,
                                     medium);
#else
    vboxUnsupported();
    return 0;
#endif
}
2932

2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946
static nsresult
_virtualboxGetHardDiskByIID(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk)
{
#if VBOX_API_VERSION < 4000000
    return vboxObj->vtbl->GetHardDisk(vboxObj, IID_MEMBER(value), hardDisk);
#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
    return vboxObj->vtbl->FindMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk,
                                     hardDisk);
#else /* VBOX_API_VERSION >= 4002000 */
    return vboxObj->vtbl->OpenMedium(vboxObj, IID_MEMBER(value), DeviceType_HardDisk,
                                     AccessMode_ReadWrite, PR_FALSE, hardDisk);
#endif /* VBOX_API_VERSION >= 4002000 */
}

T
Taowei 已提交
2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958
static nsresult
_virtualboxFindDHCPServerByNetworkName(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server)
{
    return vboxObj->vtbl->FindDHCPServerByNetworkName(vboxObj, name, server);
}

static nsresult
_virtualboxCreateDHCPServer(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server)
{
    return vboxObj->vtbl->CreateDHCPServer(vboxObj, name, server);
}

T
Taowei 已提交
2959 2960 2961 2962 2963 2964
static nsresult
_virtualboxRemoveDHCPServer(IVirtualBox *vboxObj, IDHCPServer *server)
{
    return vboxObj->vtbl->RemoveDHCPServer(vboxObj, server);
}

T
Taowei 已提交
2965 2966 2967 2968 2969 2970 2971 2972
static nsresult
_machineAddStorageController(IMachine *machine, PRUnichar *name,
                             PRUint32 connectionType,
                             IStorageController **controller)
{
    return machine->vtbl->AddStorageController(machine, name, connectionType,
                                               controller);
}
2973

T
Taowei 已提交
2974 2975 2976 2977 2978 2979 2980 2981
static nsresult
_machineGetStorageControllerByName(IMachine *machine, PRUnichar *name,
                                   IStorageController **storageController)
{
    return machine->vtbl->GetStorageControllerByName(machine, name,
                                                     storageController);
}

T
Taowei 已提交
2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997
static nsresult
_machineAttachDevice(IMachine *machine ATTRIBUTE_UNUSED,
                     PRUnichar *name ATTRIBUTE_UNUSED,
                     PRInt32 controllerPort ATTRIBUTE_UNUSED,
                     PRInt32 device ATTRIBUTE_UNUSED,
                     PRUint32 type ATTRIBUTE_UNUSED,
                     IMedium * medium ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION >= 4000000
    return machine->vtbl->AttachDevice(machine, name, controllerPort,
                                       device, type, medium);
#else /* VBOX_API_VERSION < 4000000 */
    vboxUnsupported();
    return 0;
#endif /* VBOX_API_VERSION < 4000000 */
}
2998

T
Taowei 已提交
2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011
static nsresult
_machineCreateSharedFolder(IMachine *machine, PRUnichar *name,
                           PRUnichar *hostPath, PRBool writable,
                           PRBool automount ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 4000000
    return machine->vtbl->CreateSharedFolder(machine, name, hostPath,
                                             writable);
#else /* VBOX_API_VERSION >= 4000000 */
    return machine->vtbl->CreateSharedFolder(machine, name, hostPath,
                                             writable, automount);
#endif /* VBOX_API_VERSION >= 4000000 */
}
3012

T
Taowei 已提交
3013 3014 3015 3016 3017 3018
static nsresult
_machineRemoveSharedFolder(IMachine *machine, PRUnichar *name)
{
    return machine->vtbl->RemoveSharedFolder(machine, name);
}

T
Taowei 已提交
3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037
static nsresult
_machineLaunchVMProcess(vboxGlobalData *data,
                        IMachine *machine ATTRIBUTE_UNUSED,
                        vboxIIDUnion *iidu ATTRIBUTE_UNUSED,
                        PRUnichar *sessionType, PRUnichar *env,
                        IProgress **progress)
{
#if VBOX_API_VERSION < 4000000
    return data->vboxObj->vtbl->OpenRemoteSession(data->vboxObj,
                                                  data->vboxSession,
                                                  IID_MEMBER(value),
                                                  sessionType,
                                                  env,
                                                  progress);
#else /* VBOX_API_VERSION >= 4000000 */
    return machine->vtbl->LaunchVMProcess(machine, data->vboxSession,
                                          sessionType, env, progress);
#endif /* VBOX_API_VERSION >= 4000000 */
}
3038

3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052
static nsresult
_machineUnregister(IMachine *machine ATTRIBUTE_UNUSED,
                   PRUint32 cleanupMode ATTRIBUTE_UNUSED,
                   PRUint32 *aMediaSize ATTRIBUTE_UNUSED,
                   IMedium ***aMedia ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 4000000
    vboxUnsupported();
    return 0;
#else /* VBOX_API_VERSION >= 4000000 */
    return machine->vtbl->Unregister(machine, cleanupMode, aMediaSize, aMedia);
#endif /* VBOX_API_VERSION >= 4000000 */
}

3053 3054 3055 3056 3057 3058 3059 3060 3061 3062
static nsresult
_machineFindSnapshot(IMachine *machine, vboxIIDUnion *iidu, ISnapshot **snapshot)
{
#if VBOX_API_VERSION < 4000000
    return machine->vtbl->GetSnapshot(machine, IID_MEMBER(value), snapshot);
#else /* VBOX_API_VERSION >= 4000000 */
    return machine->vtbl->FindSnapshot(machine, IID_MEMBER(value), snapshot);
#endif /* VBOX_API_VERSION >= 4000000 */
}

T
Taowei Luo 已提交
3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073
static nsresult
_machineDetachDevice(IMachine *machine, PRUnichar *name,
                     PRInt32 controllerPort, PRInt32 device)
{
#if VBOX_API_VERSION < 3001000
    return machine->vtbl->DetachHardDisk(machine, name, controllerPort, device);
#else  /* VBOX_API_VERSION >= 3001000 */
    return machine->vtbl->DetachDevice(machine, name, controllerPort, device);
#endif /* VBOX_API_VERSION >= 3001000 */
}

T
Taowei 已提交
3074 3075 3076 3077 3078
static nsresult
_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
{
    return machine->vtbl->GetAccessible(machine, isAccessible);
}
3079

T
Taowei 已提交
3080 3081 3082 3083 3084
static nsresult
_machineGetState(IMachine *machine, PRUint32 *state)
{
    return machine->vtbl->GetState(machine, state);
}
3085

T
Taowei 已提交
3086 3087 3088 3089 3090
static nsresult
_machineGetName(IMachine *machine, PRUnichar **name)
{
    return machine->vtbl->GetName(machine, name);
}
3091

T
Taowei 已提交
3092 3093 3094 3095 3096
static nsresult
_machineGetId(IMachine *machine, vboxIIDUnion *iidu)
{
    return machine->vtbl->GetId(machine, &IID_MEMBER(value));
}
3097

T
Taowei 已提交
3098 3099 3100 3101 3102
static nsresult
_machineGetBIOSSettings(IMachine *machine, IBIOSSettings **bios)
{
    return machine->vtbl->GetBIOSSettings(machine, bios);
}
3103

T
Taowei 已提交
3104 3105 3106 3107 3108
static nsresult
_machineGetAudioAdapter(IMachine *machine, IAudioAdapter **audioadapter)
{
    return machine->vtbl->GetAudioAdapter(machine, audioadapter);
}
3109

T
Taowei 已提交
3110 3111 3112 3113 3114
static nsresult
_machineGetNetworkAdapter(IMachine *machine, PRUint32 slot, INetworkAdapter **adapter)
{
    return machine->vtbl->GetNetworkAdapter(machine, slot, adapter);
}
3115

T
Taowei 已提交
3116 3117 3118 3119 3120 3121 3122 3123 3124 3125
static nsresult
_machineGetChipsetType(IMachine *machine ATTRIBUTE_UNUSED, PRUint32 *chipsetType ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION >= 4001000
    return machine->vtbl->GetChipsetType(machine, chipsetType);
#else /* VBOX_API_VERSION < 4001000 */
    vboxUnsupported();
    return 0;
#endif /* VBOX_API_VERSION < 4001000 */
}
3126

T
Taowei 已提交
3127 3128 3129 3130
static nsresult
_machineGetSerialPort(IMachine *machine, PRUint32 slot, ISerialPort **port)
{
    return machine->vtbl->GetSerialPort(machine, slot, port);
3131 3132
}

T
Taowei 已提交
3133 3134 3135 3136 3137
static nsresult
_machineGetParallelPort(IMachine *machine, PRUint32 slot, IParallelPort **port)
{
    return machine->vtbl->GetParallelPort(machine, slot, port);
}
3138

T
Taowei 已提交
3139 3140
static nsresult
_machineGetVRDxServer(IMachine *machine, IVRDxServer **VRDxServer)
3141
{
T
Taowei 已提交
3142 3143 3144 3145 3146
#if VBOX_API_VERSION < 4000000
    return machine->vtbl->GetVRDPServer(machine, VRDxServer);
#else /* VBOX_API_VERSION >= 4000000 */
    return machine->vtbl->GetVRDEServer(machine, VRDxServer);
#endif /* VBOX_API_VERSION >= 4000000 */
3147 3148
}

T
Taowei 已提交
3149 3150 3151 3152 3153 3154 3155 3156 3157
static nsresult
_machineGetUSBCommon(IMachine *machine, IUSBCommon **USBCommon)
{
#if VBOX_API_VERSION < 4003000
    return machine->vtbl->GetUSBController(machine, USBCommon);
#else
    return machine->vtbl->GetUSBDeviceFilters(machine, USBCommon);
#endif
}
3158

3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170
static nsresult
_machineGetCurrentSnapshot(IMachine *machine, ISnapshot **currentSnapshot)
{
    return machine->vtbl->GetCurrentSnapshot(machine, currentSnapshot);
}

static nsresult
_machineGetSettingsFilePath(IMachine *machine, PRUnichar **settingsFilePath)
{
    return machine->vtbl->GetSettingsFilePath(machine, settingsFilePath);
}

T
Taowei 已提交
3171 3172 3173 3174 3175 3176
static nsresult
_machineGetCPUCount(IMachine *machine, PRUint32 *CPUCount)
{
    return machine->vtbl->GetCPUCount(machine, CPUCount);
}

T
Taowei 已提交
3177 3178
static nsresult
_machineSetCPUCount(IMachine *machine, PRUint32 CPUCount)
3179
{
T
Taowei 已提交
3180
    return machine->vtbl->SetCPUCount(machine, CPUCount);
3181 3182
}

T
Taowei 已提交
3183 3184 3185 3186 3187 3188
static nsresult
_machineGetMemorySize(IMachine *machine, PRUint32 *memorySize)
{
    return machine->vtbl->GetMemorySize(machine, memorySize);
}

T
Taowei 已提交
3189 3190 3191 3192 3193
static nsresult
_machineSetMemorySize(IMachine *machine, PRUint32 memorySize)
{
    return machine->vtbl->SetMemorySize(machine, memorySize);
}
3194

T
Taowei 已提交
3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206
static nsresult
_machineGetCPUProperty(IMachine *machine, PRUint32 property ATTRIBUTE_UNUSED, PRBool *value)
{
#if VBOX_API_VERSION < 3001000
    return machine->vtbl->GetPAEEnabled(machine, value);
#elif VBOX_API_VERSION == 3001000
    return machine->vtbl->GetCpuProperty(machine, property, value);
#elif VBOX_API_VERSION >= 3002000
    return machine->vtbl->GetCPUProperty(machine, property, value);
#endif
}

T
Taowei 已提交
3207 3208
static nsresult
_machineSetCPUProperty(IMachine *machine, PRUint32 property ATTRIBUTE_UNUSED, PRBool value)
3209
{
T
Taowei 已提交
3210 3211 3212 3213 3214 3215 3216
#if VBOX_API_VERSION < 3001000
    return machine->vtbl->SetPAEEnabled(machine, value);
#elif VBOX_API_VERSION == 3001000
    return machine->vtbl->SetCpuProperty(machine, property, value);
#elif VBOX_API_VERSION >= 3002000
    return machine->vtbl->SetCPUProperty(machine, property, value);
#endif
3217 3218
}

T
Taowei 已提交
3219 3220 3221 3222 3223 3224
static nsresult
_machineGetBootOrder(IMachine *machine, PRUint32 position, PRUint32 *device)
{
    return machine->vtbl->GetBootOrder(machine, position, device);
}

T
Taowei 已提交
3225 3226 3227 3228 3229
static nsresult
_machineSetBootOrder(IMachine *machine, PRUint32 position, PRUint32 device)
{
    return machine->vtbl->SetBootOrder(machine, position, device);
}
3230

T
Taowei 已提交
3231 3232 3233 3234 3235 3236
static nsresult
_machineGetVRAMSize(IMachine *machine, PRUint32 *VRAMSize)
{
    return machine->vtbl->GetVRAMSize(machine, VRAMSize);
}

T
Taowei 已提交
3237 3238
static nsresult
_machineSetVRAMSize(IMachine *machine, PRUint32 VRAMSize)
3239
{
T
Taowei 已提交
3240 3241
    return machine->vtbl->SetVRAMSize(machine, VRAMSize);
}
3242

T
Taowei 已提交
3243 3244 3245 3246 3247 3248
static nsresult
_machineGetMonitorCount(IMachine *machine, PRUint32 *monitorCount)
{
    return machine->vtbl->GetMonitorCount(machine, monitorCount);
}

T
Taowei 已提交
3249 3250 3251 3252
static nsresult
_machineSetMonitorCount(IMachine *machine, PRUint32 monitorCount)
{
    return machine->vtbl->SetMonitorCount(machine, monitorCount);
3253 3254
}

T
Taowei 已提交
3255 3256 3257 3258 3259 3260
static nsresult
_machineGetAccelerate3DEnabled(IMachine *machine, PRBool *accelerate3DEnabled)
{
    return machine->vtbl->GetAccelerate3DEnabled(machine, accelerate3DEnabled);
}

T
Taowei 已提交
3261 3262
static nsresult
_machineSetAccelerate3DEnabled(IMachine *machine, PRBool accelerate3DEnabled)
T
Taowei 已提交
3263
{
T
Taowei 已提交
3264
    return machine->vtbl->SetAccelerate3DEnabled(machine, accelerate3DEnabled);
T
Taowei 已提交
3265 3266
}

T
Taowei 已提交
3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278
static nsresult
_machineGetAccelerate2DVideoEnabled(IMachine *machine ATTRIBUTE_UNUSED,
                                    PRBool *accelerate2DVideoEnabled ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION >= 3001000
    return machine->vtbl->GetAccelerate2DVideoEnabled(machine, accelerate2DVideoEnabled);
#else /* VBOX_API_VERSION < 3001000 */
    vboxUnsupported();
    return 0;
#endif /* VBOX_API_VERSION < 3001000 */
}

T
Taowei 已提交
3279 3280 3281
static nsresult
_machineSetAccelerate2DVideoEnabled(IMachine *machine ATTRIBUTE_UNUSED,
                                    PRBool accelerate2DVideoEnabled ATTRIBUTE_UNUSED)
T
Taowei 已提交
3282
{
T
Taowei 已提交
3283 3284 3285
#if VBOX_API_VERSION >= 3001000
    return machine->vtbl->SetAccelerate2DVideoEnabled(machine, accelerate2DVideoEnabled);
#else /* VBOX_API_VERSION < 3001000 */
T
Taowei 已提交
3286 3287
    vboxUnsupported();
    return 0;
T
Taowei 已提交
3288
#endif /* VBOX_API_VERSION < 3001000 */
T
Taowei 已提交
3289 3290
}

T
Taowei 已提交
3291 3292 3293 3294 3295 3296
static nsresult
_machineGetExtraData(IMachine *machine, PRUnichar *key, PRUnichar **value)
{
    return machine->vtbl->GetExtraData(machine, key, value);
}

T
Taowei 已提交
3297 3298
static nsresult
_machineSetExtraData(IMachine *machine, PRUnichar *key, PRUnichar *value)
T
Taowei 已提交
3299
{
T
Taowei 已提交
3300 3301 3302
    return machine->vtbl->SetExtraData(machine, key, value);
}

3303 3304 3305 3306 3307 3308
static nsresult
_machineGetSnapshotCount(IMachine *machine, PRUint32 *snapshotCount)
{
    return machine->vtbl->GetSnapshotCount(machine, snapshotCount);
}

T
Taowei 已提交
3309 3310 3311 3312
static nsresult
_machineSaveSettings(IMachine *machine)
{
    return machine->vtbl->SaveSettings(machine);
T
Taowei 已提交
3313 3314
}

T
Taowei 已提交
3315 3316
#if VBOX_API_VERSION < 4000000

T
Taowei 已提交
3317 3318
static nsresult
_sessionOpen(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine ATTRIBUTE_UNUSED)
T
Taowei 已提交
3319
{
T
Taowei 已提交
3320
    return data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, IID_MEMBER(value));
T
Taowei 已提交
3321
}
T
Taowei 已提交
3322 3323 3324

static nsresult
_sessionOpenExisting(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine ATTRIBUTE_UNUSED)
T
Taowei 已提交
3325
{
T
Taowei 已提交
3326 3327
    return data->vboxObj->vtbl->OpenExistingSession(data->vboxObj, data->vboxSession, IID_MEMBER(value));
}
T
Taowei 已提交
3328

T
Taowei 已提交
3329 3330 3331 3332 3333
static nsresult
_sessionClose(ISession *session)
{
    return session->vtbl->Close(session);
}
T
Taowei 已提交
3334

T
Taowei 已提交
3335
#else /* VBOX_API_VERSION >= 4000000 */
T
Taowei 已提交
3336

T
Taowei 已提交
3337 3338 3339 3340 3341
static nsresult
_sessionOpen(vboxGlobalData *data, vboxIIDUnion *iidu ATTRIBUTE_UNUSED, IMachine *machine)
{
    return machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Write);
}
T
Taowei 已提交
3342

T
Taowei 已提交
3343 3344 3345 3346 3347
static nsresult
_sessionOpenExisting(vboxGlobalData *data, vboxIIDUnion *iidu ATTRIBUTE_UNUSED, IMachine *machine)
{
    return machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Shared);
}
T
Taowei 已提交
3348

T
Taowei 已提交
3349 3350 3351 3352 3353
static nsresult
_sessionClose(ISession *session)
{
    return session->vtbl->UnlockMachine(session);
}
T
Taowei 已提交
3354

T
Taowei 已提交
3355
#endif /* VBOX_API_VERSION >= 4000000 */
T
Taowei 已提交
3356

T
Taowei 已提交
3357 3358 3359 3360 3361
static nsresult
_sessionGetConsole(ISession *session, IConsole **console)
{
    return session->vtbl->GetConsole(session, console);
}
T
Taowei 已提交
3362

T
Taowei 已提交
3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374
static nsresult
_sessionGetMachine(ISession *session, IMachine **machine)
{
    return session->vtbl->GetMachine(session, machine);
}

static nsresult
_consoleSaveState(IConsole *console, IProgress **progress)
{
    return console->vtbl->SaveState(console, progress);
}

T
Taowei 已提交
3375 3376 3377 3378 3379 3380
static nsresult
_consolePause(IConsole *console)
{
    return console->vtbl->Pause(console);
}

T
Taowei 已提交
3381 3382 3383 3384 3385 3386
static nsresult
_consoleResume(IConsole *console)
{
    return console->vtbl->Resume(console);
}

T
Taowei 已提交
3387 3388 3389 3390 3391 3392
static nsresult
_consolePowerButton(IConsole *console)
{
    return console->vtbl->PowerButton(console);
}

T
Taowei 已提交
3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409
static nsresult
_consolePowerDown(IConsole *console)
{
    nsresult rc;
#if VBOX_API_VERSION == 2002000
    rc = console->vtbl->PowerDown(console);
#else
    IProgress *progress = NULL;
    rc = console->vtbl->PowerDown(console, &progress);
    if (progress) {
        rc = progress->vtbl->WaitForCompletion(progress, -1);
        VBOX_RELEASE(progress);
    }
#endif
    return rc;
}

T
Taowei 已提交
3410 3411 3412 3413 3414 3415
static nsresult
_consoleReset(IConsole *console)
{
    return console->vtbl->Reset(console);
}

3416 3417 3418 3419 3420 3421 3422
static nsresult
_consoleTakeSnapshot(IConsole *console, PRUnichar *name,
                     PRUnichar *description, IProgress **progress)
{
    return console->vtbl->TakeSnapshot(console, name, description, progress);
}

T
Taowei 已提交
3423 3424 3425 3426 3427 3428 3429 3430 3431 3432
static nsresult
_consoleDeleteSnapshot(IConsole *console, vboxIIDUnion *iidu, IProgress **progress)
{
#if VBOX_API_VERSION < 3001000
    return console->vtbl->DiscardSnapshot(console, IID_MEMBER(value), progress);
#else /* VBOX_API_VERSION >= 3001000 */
    return console->vtbl->DeleteSnapshot(console, IID_MEMBER(value), progress);
#endif /* VBOX_API_VERSION >= 3001000 */
}

T
Taowei 已提交
3433 3434 3435 3436 3437 3438
static nsresult
_consoleGetDisplay(IConsole *console, IDisplay **display)
{
    return console->vtbl->GetDisplay(console, display);
}

3439 3440 3441 3442 3443 3444
static nsresult
_consoleGetKeyboard(IConsole *console, IKeyboard **keyboard)
{
    return console->vtbl->GetKeyboard(console, keyboard);
}

T
Taowei 已提交
3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460
static nsresult
_progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
{
    return progress->vtbl->WaitForCompletion(progress, timeout);
}

static nsresult
_progressGetResultCode(IProgress *progress, resultCodeUnion *resultCode)
{
#if VBOX_API_VERSION == 2002000
    return progress->vtbl->GetResultCode(progress, &resultCode->uResultCode);
#else /* VBOX_API_VERSION != 2002000 */
    return progress->vtbl->GetResultCode(progress, &resultCode->resultCode);
#endif /* VBOX_API_VERSION != 2002000 */
}

T
Taowei 已提交
3461 3462 3463 3464 3465 3466
static nsresult
_progressGetCompleted(IProgress *progress, PRBool *completed)
{
    return progress->vtbl->GetCompleted(progress, completed);
}

T
Taowei 已提交
3467 3468 3469 3470
static nsresult
_systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, PRUint32 *maxCPUCount)
{
    return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
T
Taowei 已提交
3471 3472 3473
}

static nsresult
T
Taowei 已提交
3474
_systemPropertiesGetMaxBootPosition(ISystemProperties *systemProperties, PRUint32 *maxBootPosition)
T
Taowei 已提交
3475
{
T
Taowei 已提交
3476
    return systemProperties->vtbl->GetMaxBootPosition(systemProperties, maxBootPosition);
T
Taowei 已提交
3477 3478
}

T
Taowei 已提交
3479 3480 3481
static nsresult
_systemPropertiesGetMaxNetworkAdapters(ISystemProperties *systemProperties, PRUint32 chipset ATTRIBUTE_UNUSED,
                                       PRUint32 *maxNetworkAdapters)
T
Taowei 已提交
3482
{
T
Taowei 已提交
3483 3484 3485 3486 3487 3488 3489
#if VBOX_API_VERSION < 4001000
        return systemProperties->vtbl->GetNetworkAdapterCount(systemProperties,
                                                              maxNetworkAdapters);
#else  /* VBOX_API_VERSION >= 4000000 */
        return systemProperties->vtbl->GetMaxNetworkAdapters(systemProperties, chipset,
                                                             maxNetworkAdapters);
#endif /* VBOX_API_VERSION >= 4000000 */
T
Taowei 已提交
3490 3491
}

T
Taowei 已提交
3492 3493
static nsresult
_systemPropertiesGetSerialPortCount(ISystemProperties *systemProperties, PRUint32 *SerialPortCount)
T
Taowei 已提交
3494
{
T
Taowei 已提交
3495
    return systemProperties->vtbl->GetSerialPortCount(systemProperties, SerialPortCount);
T
Taowei 已提交
3496 3497 3498
}

static nsresult
T
Taowei 已提交
3499
_systemPropertiesGetParallelPortCount(ISystemProperties *systemProperties, PRUint32 *ParallelPortCount)
T
Taowei 已提交
3500
{
T
Taowei 已提交
3501 3502
    return systemProperties->vtbl->GetParallelPortCount(systemProperties, ParallelPortCount);
}
T
Taowei 已提交
3503

T
Taowei 已提交
3504 3505 3506 3507 3508 3509
#if VBOX_API_VERSION >= 3001000
static nsresult
_systemPropertiesGetMaxPortCountForStorageBus(ISystemProperties *systemProperties, PRUint32 bus,
                                              PRUint32 *maxPortCount)
{
    return systemProperties->vtbl->GetMaxPortCountForStorageBus(systemProperties, bus, maxPortCount);
T
Taowei 已提交
3510 3511
}

T
Taowei 已提交
3512 3513 3514
static nsresult
_systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProperties,
                                                   PRUint32 bus, PRUint32 *maxDevicesPerPort)
T
Taowei 已提交
3515
{
T
Taowei 已提交
3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527
    return systemProperties->vtbl->GetMaxDevicesPerPortForStorageBus(systemProperties,
                                                                     bus, maxDevicesPerPort);
}
#else /* VBOX_API_VERSION < 3001000 */
static nsresult
_systemPropertiesGetMaxPortCountForStorageBus(ISystemProperties *systemProperties ATTRIBUTE_UNUSED,
                                              PRUint32 bus ATTRIBUTE_UNUSED,
                                              PRUint32 *maxPortCount ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}
T
Taowei 已提交
3528

T
Taowei 已提交
3529 3530 3531 3532 3533 3534 3535 3536 3537
static nsresult
_systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProperties ATTRIBUTE_UNUSED,
                                                   PRUint32 bus ATTRIBUTE_UNUSED,
                                                   PRUint32 *maxDevicesPerPort ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}
#endif
T
Taowei 已提交
3538

T
Taowei 已提交
3539 3540 3541 3542 3543 3544
static nsresult
_systemPropertiesGetMaxGuestRAM(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM)
{
    return systemProperties->vtbl->GetMaxGuestRAM(systemProperties, maxGuestRAM);
}

T
Taowei 已提交
3545 3546 3547 3548 3549 3550
static nsresult
_biosSettingsGetACPIEnabled(IBIOSSettings *bios, PRBool *ACPIEnabled)
{
    return bios->vtbl->GetACPIEnabled(bios, ACPIEnabled);
}

T
Taowei 已提交
3551 3552 3553 3554
static nsresult
_biosSettingsSetACPIEnabled(IBIOSSettings *bios, PRBool ACPIEnabled)
{
    return bios->vtbl->SetACPIEnabled(bios, ACPIEnabled);
T
Taowei 已提交
3555 3556
}

T
Taowei 已提交
3557 3558 3559 3560 3561 3562
static nsresult
_biosSettingsGetIOAPICEnabled(IBIOSSettings *bios, PRBool *IOAPICEnabled)
{
    return bios->vtbl->GetIOAPICEnabled(bios, IOAPICEnabled);
}

T
Taowei 已提交
3563 3564 3565 3566 3567
static nsresult
_biosSettingsSetIOAPICEnabled(IBIOSSettings *bios, PRBool IOAPICEnabled)
{
    return bios->vtbl->SetIOAPICEnabled(bios, IOAPICEnabled);
}
T
Taowei 已提交
3568

T
Taowei 已提交
3569 3570 3571 3572 3573 3574
static nsresult
_audioAdapterGetEnabled(IAudioAdapter *audioAdapter, PRBool *enabled)
{
    return audioAdapter->vtbl->GetEnabled(audioAdapter, enabled);
}

T
Taowei 已提交
3575 3576
static nsresult
_audioAdapterSetEnabled(IAudioAdapter *audioAdapter, PRBool enabled)
T
Taowei 已提交
3577
{
T
Taowei 已提交
3578
    return audioAdapter->vtbl->SetEnabled(audioAdapter, enabled);
T
Taowei 已提交
3579 3580
}

T
Taowei 已提交
3581 3582 3583 3584 3585 3586
static nsresult
_audioAdapterGetAudioController(IAudioAdapter *audioAdapter, PRUint32 *audioController)
{
    return audioAdapter->vtbl->GetAudioController(audioAdapter, audioController);
}

T
Taowei 已提交
3587 3588
static nsresult
_audioAdapterSetAudioController(IAudioAdapter *audioAdapter, PRUint32 audioController)
T
Taowei 已提交
3589
{
T
Taowei 已提交
3590
    return audioAdapter->vtbl->SetAudioController(audioAdapter, audioController);
T
Taowei 已提交
3591 3592
}

T
Taowei 已提交
3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604
static nsresult
_networkAdapterGetAttachmentType(INetworkAdapter *adapter, PRUint32 *attachmentType)
{
    return adapter->vtbl->GetAttachmentType(adapter, attachmentType);
}

static nsresult
_networkAdapterGetEnabled(INetworkAdapter *adapter, PRBool *enabled)
{
    return adapter->vtbl->GetEnabled(adapter, enabled);
}

T
Taowei 已提交
3605 3606
static nsresult
_networkAdapterSetEnabled(INetworkAdapter *adapter, PRBool enabled)
T
Taowei 已提交
3607
{
T
Taowei 已提交
3608
    return adapter->vtbl->SetEnabled(adapter, enabled);
T
Taowei 已提交
3609 3610
}

T
Taowei 已提交
3611 3612 3613 3614 3615 3616
static nsresult
_networkAdapterGetAdapterType(INetworkAdapter *adapter, PRUint32 *adapterType)
{
    return adapter->vtbl->GetAdapterType(adapter, adapterType);
}

T
Taowei 已提交
3617 3618
static nsresult
_networkAdapterSetAdapterType(INetworkAdapter *adapter, PRUint32 adapterType)
T
Taowei 已提交
3619
{
T
Taowei 已提交
3620
    return adapter->vtbl->SetAdapterType(adapter, adapterType);
T
Taowei 已提交
3621 3622
}

T
Taowei 已提交
3623 3624 3625 3626 3627 3628
static nsresult
_networkAdapterGetInternalNetwork(INetworkAdapter *adapter, PRUnichar **internalNetwork)
{
    return adapter->vtbl->GetInternalNetwork(adapter, internalNetwork);
}

T
Taowei 已提交
3629 3630
static nsresult
_networkAdapterSetInternalNetwork(INetworkAdapter *adapter, PRUnichar *internalNetwork)
T
Taowei 已提交
3631
{
T
Taowei 已提交
3632
    return adapter->vtbl->SetInternalNetwork(adapter, internalNetwork);
T
Taowei 已提交
3633 3634
}

T
Taowei 已提交
3635 3636 3637 3638 3639 3640
static nsresult
_networkAdapterGetMACAddress(INetworkAdapter *adapter, PRUnichar **MACAddress)
{
    return adapter->vtbl->GetMACAddress(adapter, MACAddress);
}

T
Taowei 已提交
3641 3642
static nsresult
_networkAdapterSetMACAddress(INetworkAdapter *adapter, PRUnichar *MACAddress)
T
Taowei 已提交
3643
{
T
Taowei 已提交
3644
    return adapter->vtbl->SetMACAddress(adapter, MACAddress);
T
Taowei 已提交
3645 3646
}

T
Taowei 已提交
3647
#if VBOX_API_VERSION < 4001000
T
Taowei 已提交
3648

T
Taowei 已提交
3649 3650 3651 3652 3653 3654
static nsresult
_networkAdapterGetBridgedInterface(INetworkAdapter *adapter, PRUnichar **hostInterface)
{
    return adapter->vtbl->GetHostInterface(adapter, hostInterface);
}

T
Taowei 已提交
3655 3656
static nsresult
_networkAdapterSetBridgedInterface(INetworkAdapter *adapter, PRUnichar *hostInterface)
T
Taowei 已提交
3657
{
T
Taowei 已提交
3658
    return adapter->vtbl->SetHostInterface(adapter, hostInterface);
T
Taowei 已提交
3659 3660
}

T
Taowei 已提交
3661 3662 3663 3664 3665 3666
static nsresult
_networkAdapterGetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface)
{
    return adapter->vtbl->GetHostInterface(adapter, hostOnlyInterface);
}

T
Taowei 已提交
3667 3668
static nsresult
_networkAdapterSetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface)
T
Taowei 已提交
3669
{
T
Taowei 已提交
3670
    return adapter->vtbl->SetHostInterface(adapter, hostOnlyInterface);
T
Taowei 已提交
3671 3672
}

T
Taowei 已提交
3673 3674
static nsresult
_networkAdapterAttachToBridgedInterface(INetworkAdapter *adapter)
T
Taowei 已提交
3675
{
T
Taowei 已提交
3676
    return adapter->vtbl->AttachToBridgedInterface(adapter);
T
Taowei 已提交
3677 3678
}

T
Taowei 已提交
3679 3680
static nsresult
_networkAdapterAttachToInternalNetwork(INetworkAdapter *adapter)
T
Taowei 已提交
3681
{
T
Taowei 已提交
3682
    return adapter->vtbl->AttachToInternalNetwork(adapter);
T
Taowei 已提交
3683 3684
}

T
Taowei 已提交
3685 3686 3687 3688 3689
static nsresult
_networkAdapterAttachToHostOnlyInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->AttachToHostOnlyInterface(adapter);
}
T
Taowei 已提交
3690

T
Taowei 已提交
3691 3692
static nsresult
_networkAdapterAttachToNAT(INetworkAdapter *adapter)
T
Taowei 已提交
3693
{
T
Taowei 已提交
3694
    return adapter->vtbl->AttachToNAT(adapter);
T
Taowei 已提交
3695 3696
}

T
Taowei 已提交
3697 3698
#else /* VBOX_API_VERSION >= 4001000 */

T
Taowei 已提交
3699 3700 3701 3702 3703 3704
static nsresult
_networkAdapterGetBridgedInterface(INetworkAdapter *adapter, PRUnichar **bridgedInterface)
{
    return adapter->vtbl->GetBridgedInterface(adapter, bridgedInterface);
}

T
Taowei 已提交
3705 3706
static nsresult
_networkAdapterSetBridgedInterface(INetworkAdapter *adapter, PRUnichar *bridgedInterface)
T
Taowei 已提交
3707
{
T
Taowei 已提交
3708
    return adapter->vtbl->SetBridgedInterface(adapter, bridgedInterface);
T
Taowei 已提交
3709 3710
}

T
Taowei 已提交
3711 3712 3713 3714 3715 3716
static nsresult
_networkAdapterGetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface)
{
    return adapter->vtbl->GetHostOnlyInterface(adapter, hostOnlyInterface);
}

T
Taowei 已提交
3717
static nsresult
T
Taowei 已提交
3718
_networkAdapterSetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface)
T
Taowei 已提交
3719
{
T
Taowei 已提交
3720
    return adapter->vtbl->SetHostOnlyInterface(adapter, hostOnlyInterface);
T
Taowei 已提交
3721 3722
}

T
Taowei 已提交
3723 3724 3725 3726 3727
static nsresult
_networkAdapterAttachToBridgedInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_Bridged);
}
T
Taowei 已提交
3728 3729

static nsresult
T
Taowei 已提交
3730
_networkAdapterAttachToInternalNetwork(INetworkAdapter *adapter)
T
Taowei 已提交
3731
{
T
Taowei 已提交
3732
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_Internal);
T
Taowei 已提交
3733 3734
}

T
Taowei 已提交
3735 3736 3737 3738 3739
static nsresult
_networkAdapterAttachToHostOnlyInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_HostOnly);
}
T
Taowei 已提交
3740 3741

static nsresult
T
Taowei 已提交
3742
_networkAdapterAttachToNAT(INetworkAdapter *adapter)
T
Taowei 已提交
3743
{
T
Taowei 已提交
3744
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_NAT);
T
Taowei 已提交
3745 3746
}

T
Taowei 已提交
3747
#endif /* VBOX_API_VERSION >= 4001000 */
T
Taowei 已提交
3748

T
Taowei 已提交
3749 3750 3751 3752 3753 3754
static nsresult
_serialPortGetEnabled(ISerialPort *port, PRBool *enabled)
{
    return port->vtbl->GetEnabled(port, enabled);
}

T
Taowei 已提交
3755
static nsresult
T
Taowei 已提交
3756
_serialPortSetEnabled(ISerialPort *port, PRBool enabled)
T
Taowei 已提交
3757
{
T
Taowei 已提交
3758
    return port->vtbl->SetEnabled(port, enabled);
T
Taowei 已提交
3759 3760
}

T
Taowei 已提交
3761 3762 3763 3764 3765 3766
static nsresult
_serialPortGetPath(ISerialPort *port, PRUnichar **path)
{
    return port->vtbl->GetPath(port, path);
}

T
Taowei 已提交
3767
static nsresult
T
Taowei 已提交
3768
_serialPortSetPath(ISerialPort *port, PRUnichar *path)
T
Taowei 已提交
3769
{
T
Taowei 已提交
3770
    return port->vtbl->SetPath(port, path);
T
Taowei 已提交
3771 3772
}

T
Taowei 已提交
3773 3774 3775 3776 3777 3778
static nsresult
_serialPortGetIRQ(ISerialPort *port, PRUint32 *IRQ)
{
    return port->vtbl->GetIRQ(port, IRQ);
}

T
Taowei 已提交
3779
static nsresult
T
Taowei 已提交
3780
_serialPortSetIRQ(ISerialPort *port, PRUint32 IRQ)
T
Taowei 已提交
3781
{
T
Taowei 已提交
3782
    return port->vtbl->SetIRQ(port, IRQ);
T
Taowei 已提交
3783 3784
}

T
Taowei 已提交
3785 3786 3787 3788 3789 3790
static nsresult
_serialPortGetIOBase(ISerialPort *port, PRUint32 *IOBase)
{
    return port->vtbl->GetIOBase(port, IOBase);
}

T
Taowei 已提交
3791
static nsresult
T
Taowei 已提交
3792
_serialPortSetIOBase(ISerialPort *port, PRUint32 IOBase)
T
Taowei 已提交
3793
{
T
Taowei 已提交
3794
    return port->vtbl->SetIOBase(port, IOBase);
T
Taowei 已提交
3795 3796
}

T
Taowei 已提交
3797 3798 3799 3800 3801 3802
static nsresult
_serialPortGetHostMode(ISerialPort *port, PRUint32 *hostMode)
{
    return port->vtbl->GetHostMode(port, hostMode);
}

T
Taowei 已提交
3803
static nsresult
T
Taowei 已提交
3804
_serialPortSetHostMode(ISerialPort *port, PRUint32 hostMode)
T
Taowei 已提交
3805
{
T
Taowei 已提交
3806
    return port->vtbl->SetHostMode(port, hostMode);
T
Taowei 已提交
3807 3808
}

T
Taowei 已提交
3809 3810 3811 3812 3813 3814
static nsresult
_parallelPortGetEnabled(IParallelPort *port, PRBool *enabled)
{
    return port->vtbl->GetEnabled(port, enabled);
}

T
Taowei 已提交
3815
static nsresult
T
Taowei 已提交
3816
_parallelPortSetEnabled(IParallelPort *port, PRBool enabled)
T
Taowei 已提交
3817
{
T
Taowei 已提交
3818
    return port->vtbl->SetEnabled(port, enabled);
T
Taowei 已提交
3819 3820
}

T
Taowei 已提交
3821 3822 3823 3824 3825 3826
static nsresult
_parallelPortGetPath(IParallelPort *port, PRUnichar **path)
{
    return port->vtbl->GetPath(port, path);
}

T
Taowei 已提交
3827
static nsresult
T
Taowei 已提交
3828
_parallelPortSetPath(IParallelPort *port, PRUnichar *path)
T
Taowei 已提交
3829
{
T
Taowei 已提交
3830
    return port->vtbl->SetPath(port, path);
T
Taowei 已提交
3831 3832
}

T
Taowei 已提交
3833 3834 3835 3836 3837 3838
static nsresult
_parallelPortGetIRQ(IParallelPort *port, PRUint32 *IRQ)
{
    return port->vtbl->GetIRQ(port, IRQ);
}

T
Taowei 已提交
3839
static nsresult
T
Taowei 已提交
3840
_parallelPortSetIRQ(IParallelPort *port, PRUint32 IRQ)
T
Taowei 已提交
3841
{
T
Taowei 已提交
3842
    return port->vtbl->SetIRQ(port, IRQ);
T
Taowei 已提交
3843 3844
}

T
Taowei 已提交
3845 3846 3847 3848 3849 3850
static nsresult
_parallelPortGetIOBase(IParallelPort *port, PRUint32 *IOBase)
{
    return port->vtbl->GetIOBase(port, IOBase);
}

T
Taowei 已提交
3851
static nsresult
T
Taowei 已提交
3852
_parallelPortSetIOBase(IParallelPort *port, PRUint32 IOBase)
T
Taowei 已提交
3853
{
T
Taowei 已提交
3854
    return port->vtbl->SetIOBase(port, IOBase);
T
Taowei 已提交
3855 3856
}

T
Taowei 已提交
3857 3858 3859 3860 3861 3862
static nsresult
_vrdxServerGetEnabled(IVRDxServer *VRDxServer, PRBool *enabled)
{
    return VRDxServer->vtbl->GetEnabled(VRDxServer, enabled);
}

T
Taowei 已提交
3863 3864 3865 3866 3867
static nsresult
_vrdxServerSetEnabled(IVRDxServer *VRDxServer, PRBool enabled)
{
    return VRDxServer->vtbl->SetEnabled(VRDxServer, enabled);
}
T
Taowei 已提交
3868

T
Taowei 已提交
3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908
static nsresult
_vrdxServerGetPorts(vboxGlobalData *data ATTRIBUTE_UNUSED,
                    IVRDxServer *VRDxServer, virDomainGraphicsDefPtr graphics)
{
    nsresult rc;
#if VBOX_API_VERSION < 3001000
    PRUint32 VRDPport = 0;
    rc = VRDxServer->vtbl->GetPort(VRDxServer, &VRDPport);
    if (VRDPport) {
        graphics->data.rdp.port = VRDPport;
    } else {
        graphics->data.rdp.autoport = true;
    }
#elif VBOX_API_VERSION < 4000000 /* 3001000 <= VBOX_API_VERSION < 4000000 */
    PRUnichar *VRDPport = NULL;
    rc = VRDxServer->vtbl->GetPorts(VRDxServer, &VRDPport);
    if (VRDPport) {
        /* even if vbox supports mutilpe ports, single port for now here */
        graphics->data.rdp.port = PRUnicharToInt(VRDPport);
        VBOX_UTF16_FREE(VRDPport);
    } else {
        graphics->data.rdp.autoport = true;
    }
#else /* VBOX_API_VERSION >= 4000000 */
    PRUnichar *VRDEPortsKey = NULL;
    PRUnichar *VRDEPortsValue = NULL;
    VBOX_UTF8_TO_UTF16("TCP/Ports", &VRDEPortsKey);
    rc = VRDxServer->vtbl->GetVRDEProperty(VRDxServer, VRDEPortsKey, &VRDEPortsValue);
    VBOX_UTF16_FREE(VRDEPortsKey);
    if (VRDEPortsValue) {
        /* even if vbox supports mutilpe ports, single port for now here */
        graphics->data.rdp.port = PRUnicharToInt(VRDEPortsValue);
        VBOX_UTF16_FREE(VRDEPortsValue);
    } else {
        graphics->data.rdp.autoport = true;
    }
#endif /* VBOX_API_VERSION >= 4000000 */
    return rc;
}

T
Taowei 已提交
3909
static nsresult
T
Taowei 已提交
3910 3911
_vrdxServerSetPorts(vboxGlobalData *data ATTRIBUTE_UNUSED,
                    IVRDxServer *VRDxServer, virDomainGraphicsDefPtr graphics)
T
Taowei 已提交
3912
{
T
Taowei 已提交
3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942
    nsresult rc = 0;
#if VBOX_API_VERSION < 3001000
    if (graphics->data.rdp.port) {
        rc = VRDxServer->vtbl->SetPort(VRDxServer,
                                       graphics->data.rdp.port);
        VIR_DEBUG("VRDP Port changed to: %d",
                  graphics->data.rdp.port);
    } else if (graphics->data.rdp.autoport) {
        /* Setting the port to 0 will reset its value to
         * the default one which is 3389 currently
         */
        rc = VRDxServer->vtbl->SetPort(VRDxServer, 0);
        VIR_DEBUG("VRDP Port changed to default, which is 3389 currently");
    }
#elif VBOX_API_VERSION < 4000000 /* 3001000 <= VBOX_API_VERSION < 4000000 */
    PRUnichar *portUtf16 = NULL;
    portUtf16 = PRUnicharFromInt(graphics->data.rdp.port);
    rc = VRDxServer->vtbl->SetPorts(VRDxServer, portUtf16);
    VBOX_UTF16_FREE(portUtf16);
#else /* VBOX_API_VERSION >= 4000000 */
    PRUnichar *VRDEPortsKey = NULL;
    PRUnichar *VRDEPortsValue = NULL;
    VBOX_UTF8_TO_UTF16("TCP/Ports", &VRDEPortsKey);
    VRDEPortsValue = PRUnicharFromInt(graphics->data.rdp.port);
    rc = VRDxServer->vtbl->SetVRDEProperty(VRDxServer, VRDEPortsKey,
                                           VRDEPortsValue);
    VBOX_UTF16_FREE(VRDEPortsKey);
    VBOX_UTF16_FREE(VRDEPortsValue);
#endif /* VBOX_API_VERSION >= 4000000 */
    return rc;
T
Taowei 已提交
3943 3944
}

T
Taowei 已提交
3945 3946 3947 3948 3949 3950
static nsresult
_vrdxServerGetReuseSingleConnection(IVRDxServer *VRDxServer, PRBool *enabled)
{
    return VRDxServer->vtbl->GetReuseSingleConnection(VRDxServer, enabled);
}

T
Taowei 已提交
3951
static nsresult
T
Taowei 已提交
3952
_vrdxServerSetReuseSingleConnection(IVRDxServer *VRDxServer, PRBool enabled)
T
Taowei 已提交
3953
{
T
Taowei 已提交
3954
    return VRDxServer->vtbl->SetReuseSingleConnection(VRDxServer, enabled);
T
Taowei 已提交
3955 3956
}

T
Taowei 已提交
3957 3958 3959 3960 3961 3962
static nsresult
_vrdxServerGetAllowMultiConnection(IVRDxServer *VRDxServer, PRBool *enabled)
{
    return VRDxServer->vtbl->GetAllowMultiConnection(VRDxServer, enabled);
}

T
Taowei 已提交
3963
static nsresult
T
Taowei 已提交
3964
_vrdxServerSetAllowMultiConnection(IVRDxServer *VRDxServer, PRBool enabled)
T
Taowei 已提交
3965
{
T
Taowei 已提交
3966
    return VRDxServer->vtbl->SetAllowMultiConnection(VRDxServer, enabled);
T
Taowei 已提交
3967 3968
}

T
Taowei 已提交
3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984
static nsresult
_vrdxServerGetNetAddress(vboxGlobalData *data ATTRIBUTE_UNUSED,
                         IVRDxServer *VRDxServer, PRUnichar **netAddress)
{
#if VBOX_API_VERSION >= 4000000
    PRUnichar *VRDENetAddressKey = NULL;
    nsresult rc;
    VBOX_UTF8_TO_UTF16("TCP/Address", &VRDENetAddressKey);
    rc = VRDxServer->vtbl->GetVRDEProperty(VRDxServer, VRDENetAddressKey, netAddress);
    VBOX_UTF16_FREE(VRDENetAddressKey);
    return rc;
#else /* VBOX_API_VERSION < 4000000 */
    return VRDxServer->vtbl->GetNetAddress(VRDxServer, netAddress);
#endif /* VBOX_API_VERSION < 4000000 */
}

T
Taowei 已提交
3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999
static nsresult
_vrdxServerSetNetAddress(vboxGlobalData *data ATTRIBUTE_UNUSED,
                         IVRDxServer *VRDxServer, PRUnichar *netAddress)
{
#if VBOX_API_VERSION < 4000000
    return VRDxServer->vtbl->SetNetAddress(VRDxServer,
                                           netAddress);
#else /* VBOX_API_VERSION >= 4000000 */
    PRUnichar *netAddressKey = NULL;
    nsresult rc;
    VBOX_UTF8_TO_UTF16("TCP/Address", &netAddressKey);
    rc = VRDxServer->vtbl->SetVRDEProperty(VRDxServer, netAddressKey,
                                           netAddress);
    VBOX_UTF16_FREE(netAddressKey);
    return rc;
T
Taowei 已提交
4000
#endif /* VBOX_API_VERSION >= 4000000 */
T
Taowei 已提交
4001
}
T
Taowei 已提交
4002 4003

static nsresult
T
Taowei 已提交
4004
_usbCommonEnable(IUSBCommon *USBCommon ATTRIBUTE_UNUSED)
T
Taowei 已提交
4005
{
T
Taowei 已提交
4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016
    nsresult rc = 0;
#if VBOX_API_VERSION < 4003000
    USBCommon->vtbl->SetEnabled(USBCommon, 1);
# if VBOX_API_VERSION < 4002000
    rc = USBCommon->vtbl->SetEnabledEhci(USBCommon, 1);
# else /* VBOX_API_VERSION >= 4002000 */
    rc = USBCommon->vtbl->SetEnabledEHCI(USBCommon, 1);
# endif /* VBOX_API_VERSION >= 4002000 */
#endif /* VBOX_API_VERSION >= 4003000 */
    /* We don't need to set usb enabled for vbox 4.3 and later */
    return rc;
T
Taowei 已提交
4017 4018
}

T
Taowei 已提交
4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029
static nsresult
_usbCommonGetEnabled(IUSBCommon *USBCommon ATTRIBUTE_UNUSED, PRBool *enabled)
{
#if VBOX_API_VERSION < 4003000
    return USBCommon->vtbl->GetEnabled(USBCommon, enabled);
#else /* VBOX_API_VERSION >= 4003000 */
    *enabled = true;
    return 0;
#endif /* VBOX_API_VERSION >= 4003000 */
}

T
Taowei 已提交
4030
static nsresult
T
Taowei 已提交
4031 4032
_usbCommonCreateDeviceFilter(IUSBCommon *USBCommon, PRUnichar *name,
                             IUSBDeviceFilter **filter)
T
Taowei 已提交
4033
{
T
Taowei 已提交
4034
    return USBCommon->vtbl->CreateDeviceFilter(USBCommon, name, filter);
T
Taowei 已提交
4035 4036
}

T
Taowei 已提交
4037
static nsresult
T
Taowei 已提交
4038 4039
_usbCommonInsertDeviceFilter(IUSBCommon *USBCommon, PRUint32 position,
                             IUSBDeviceFilter *filter)
T
Taowei 已提交
4040
{
T
Taowei 已提交
4041
    return USBCommon->vtbl->InsertDeviceFilter(USBCommon, position, filter);
T
Taowei 已提交
4042 4043
}

T
Taowei 已提交
4044 4045 4046 4047 4048 4049
static nsresult
_usbDeviceFilterGetProductId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **productId)
{
    return USBDeviceFilter->vtbl->GetProductId(USBDeviceFilter, productId);
}

T
Taowei 已提交
4050
static nsresult
T
Taowei 已提交
4051
_usbDeviceFilterSetProductId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *productId)
T
Taowei 已提交
4052
{
T
Taowei 已提交
4053
    return USBDeviceFilter->vtbl->SetProductId(USBDeviceFilter, productId);
T
Taowei 已提交
4054 4055
}

T
Taowei 已提交
4056 4057 4058 4059 4060 4061
static nsresult
_usbDeviceFilterGetActive(IUSBDeviceFilter *USBDeviceFilter, PRBool *active)
{
    return USBDeviceFilter->vtbl->GetActive(USBDeviceFilter, active);
}

T
Taowei 已提交
4062
static nsresult
T
Taowei 已提交
4063
_usbDeviceFilterSetActive(IUSBDeviceFilter *USBDeviceFilter, PRBool active)
T
Taowei 已提交
4064
{
T
Taowei 已提交
4065
    return USBDeviceFilter->vtbl->SetActive(USBDeviceFilter, active);
T
Taowei 已提交
4066 4067
}

T
Taowei 已提交
4068 4069 4070 4071 4072 4073
static nsresult
_usbDeviceFilterGetVendorId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **vendorId)
{
    return USBDeviceFilter->vtbl->GetVendorId(USBDeviceFilter, vendorId);
}

T
Taowei 已提交
4074
static nsresult
T
Taowei 已提交
4075
_usbDeviceFilterSetVendorId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *vendorId)
T
Taowei 已提交
4076
{
T
Taowei 已提交
4077 4078 4079 4080 4081 4082 4083 4084
    return USBDeviceFilter->vtbl->SetVendorId(USBDeviceFilter, vendorId);
}

static nsresult _mediumGetId(IMedium *medium, vboxIIDUnion *iidu)
{
    return medium->vtbl->GetId(medium, &IID_MEMBER(value));
}

T
Taowei 已提交
4085 4086 4087 4088 4089
static nsresult _mediumGetLocation(IMedium *medium, PRUnichar **location)
{
    return medium->vtbl->GetLocation(medium, location);
}

4090 4091 4092 4093 4094
static nsresult _mediumGetState(IMedium *medium, PRUint32 *state)
{
    return medium->vtbl->GetState(medium, state);
}

4095 4096 4097 4098 4099
static nsresult _mediumGetName(IMedium *medium, PRUnichar **name)
{
    return medium->vtbl->GetName(medium, name);
}

T
Taowei Luo 已提交
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112
static nsresult _mediumGetSize(IMedium *medium, PRUint64 *uSize)
{
#if VBOX_API_VERSION < 4000000
    return medium->vtbl->GetSize(medium, uSize);
#else /* VBOX_API_VERSION >= 4000000 */
    nsresult rc;
    PRInt64 Size;
    rc = medium->vtbl->GetSize(medium, &Size);
    *uSize = Size;
    return rc;
#endif /* VBOX_API_VERSION >= 4000000 */
}

T
Taowei 已提交
4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123
static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED,
                                   PRBool *readOnly ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 3001000
    vboxUnsupported();
    return 0;
#else /* VBOX_API_VERSION >= 3001000 */
    return medium->vtbl->GetReadOnly(medium, readOnly);
#endif /* VBOX_API_VERSION >= 3001000 */
}

4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183
#if VBOX_API_VERSION < 3001000

static nsresult _mediumGetParent(IMedium *medium ATTRIBUTE_UNUSED,
                                 IMedium **parent ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

static nsresult _mediumGetChildren(IMedium *medium ATTRIBUTE_UNUSED,
                                   PRUint32 *childrenSize ATTRIBUTE_UNUSED,
                                   IMedium ***children ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

static nsresult _mediumGetFormat(IMedium *medium ATTRIBUTE_UNUSED,
                                 PRUnichar **format ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

static nsresult _mediumDeleteStorage(IMedium *medium ATTRIBUTE_UNUSED,
                                     IProgress **progress ATTRIBUTE_UNUSED)
{
    vboxUnsupported();
    return 0;
}

#else /* VBOX_API_VERSION >= 3001000 */

static nsresult _mediumGetParent(IMedium *medium,
                                 IMedium **parent)
{
    return medium->vtbl->GetParent(medium, parent);
}

static nsresult _mediumGetChildren(IMedium *medium,
                                   PRUint32 *childrenSize,
                                   IMedium ***children)
{
    return medium->vtbl->GetChildren(medium, childrenSize, children);
}

static nsresult _mediumGetFormat(IMedium *medium,
                                 PRUnichar **format)
{
    return medium->vtbl->GetFormat(medium, format);
}

static nsresult _mediumDeleteStorage(IMedium *medium,
                                     IProgress **progress)
{
    return medium->vtbl->DeleteStorage(medium, progress);
}

#endif /* VBOX_API_VERSION >= 3001000 */

T
Taowei 已提交
4184 4185 4186 4187
static nsresult _mediumRelease(IMedium *medium)
{
    return medium->vtbl->nsisupports.Release((nsISupports *)medium);
}
4188 4189 4190 4191
static nsresult _mediumClose(IMedium *medium)
{
    return medium->vtbl->Close(medium);
}
T
Taowei 已提交
4192 4193 4194 4195 4196 4197 4198 4199 4200 4201

static nsresult _mediumSetType(IMedium *medium ATTRIBUTE_UNUSED,
                               PRUint32 type ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION > 3000000
    return medium->vtbl->SetType(medium, type);
#else
    vboxUnsupported();
    return 0;
#endif
T
Taowei 已提交
4202 4203
}

4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224
static nsresult
_mediumCreateDiffStorage(IMedium *medium ATTRIBUTE_UNUSED,
                         IMedium *target ATTRIBUTE_UNUSED,
                         PRUint32 variantSize ATTRIBUTE_UNUSED,
                         PRUint32 *variant ATTRIBUTE_UNUSED,
                         IProgress **progress ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 3001000
    vboxUnsupported();
    return 0;
#elif VBOX_API_VERSION < 4003000
    if (variantSize == 0)
        return 0;
    if (variantSize > 1)
        VIR_WARN("Only one variant is avaible in current version");
    return medium->vtbl->CreateDiffStorage(medium, target, variant[0], progress);
#else /* VBOX_API_VERSION >= 4003000 */
    return medium->vtbl->CreateDiffStorage(medium, target, variantSize, variant, progress);
#endif /* VBOX_API_VERSION >= 4003000 */
}

T
Taowei 已提交
4225
static nsresult
4226 4227
_mediumAttachmentGetMedium(IMediumAttachment *mediumAttachment,
                           IHardDisk **hardDisk)
T
Taowei 已提交
4228 4229
{
#if VBOX_API_VERSION < 3001000
4230
    return mediumAttachment->vtbl->GetHardDisk(mediumAttachment, hardDisk);
T
Taowei 已提交
4231
#else /* VBOX_API_VERSION >= 3001000 */
4232
    return mediumAttachment->vtbl->GetMedium(mediumAttachment, hardDisk);
T
Taowei 已提交
4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290
#endif /* VBOX_API_VERSION >= 3001000 */
}

static nsresult
_mediumAttachmentGetController(IMediumAttachment *mediumAttachment,
                               PRUnichar **controller)
{
    return mediumAttachment->vtbl->GetController(mediumAttachment, controller);
}

static nsresult
_mediumAttachmentGetType(IMediumAttachment *mediumAttachment ATTRIBUTE_UNUSED,
                         PRUint32 *type ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 3001000
    vboxUnsupported();
    return 0;
#else /* VBOX_API_VERSION >= 3001000 */
    return mediumAttachment->vtbl->GetType(mediumAttachment, type);
#endif /* VBOX_API_VERSION >= 3001000 */
}

static nsresult
_mediumAttachmentGetPort(IMediumAttachment *mediumAttachment, PRInt32 *port)
{
    return mediumAttachment->vtbl->GetPort(mediumAttachment, port);
}

static nsresult
_mediumAttachmentGetDevice(IMediumAttachment *mediumAttachment, PRInt32 *device)
{
    return mediumAttachment->vtbl->GetDevice(mediumAttachment, device);
}

static nsresult
_storageControllerGetBus(IStorageController *storageController, PRUint32 *bus)
{
    return storageController->vtbl->GetBus(storageController, bus);
}

static nsresult
_sharedFolderGetHostPath(ISharedFolder *sharedFolder, PRUnichar **hostPath)
{
    return sharedFolder->vtbl->GetHostPath(sharedFolder, hostPath);
}

static nsresult
_sharedFolderGetName(ISharedFolder *sharedFolder, PRUnichar **name)
{
    return sharedFolder->vtbl->GetName(sharedFolder, name);
}

static nsresult
_sharedFolderGetWritable(ISharedFolder *sharedFolder, PRBool *writable)
{
    return sharedFolder->vtbl->GetWritable(sharedFolder, writable);
}

4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332
static nsresult
_snapshotGetName(ISnapshot *snapshot, PRUnichar **name)
{
    return snapshot->vtbl->GetName(snapshot, name);
}

static nsresult
_snapshotGetId(ISnapshot *snapshot, vboxIIDUnion *iidu)
{
    return snapshot->vtbl->GetId(snapshot, &IID_MEMBER(value));
}

static nsresult
_snapshotGetMachine(ISnapshot *snapshot, IMachine **machine)
{
    return snapshot->vtbl->GetMachine(snapshot, machine);
}

static nsresult
_snapshotGetDescription(ISnapshot *snapshot, PRUnichar **description)
{
    return snapshot->vtbl->GetDescription(snapshot, description);
}

static nsresult
_snapshotGetTimeStamp(ISnapshot *snapshot, PRInt64 *timeStamp)
{
    return snapshot->vtbl->GetTimeStamp(snapshot, timeStamp);
}

static nsresult
_snapshotGetParent(ISnapshot *snapshot, ISnapshot **parent)
{
    return snapshot->vtbl->GetParent(snapshot, parent);
}

static nsresult
_snapshotGetOnline(ISnapshot *snapshot, PRBool *online)
{
    return snapshot->vtbl->GetOnline(snapshot, online);
}

T
Taowei 已提交
4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372
static nsresult
_displayGetScreenResolution(IDisplay *display ATTRIBUTE_UNUSED,
                            PRUint32 screenId ATTRIBUTE_UNUSED,
                            PRUint32 *width ATTRIBUTE_UNUSED,
                            PRUint32 *height ATTRIBUTE_UNUSED,
                            PRUint32 *bitsPerPixel ATTRIBUTE_UNUSED,
                            PRInt32 *xOrigin ATTRIBUTE_UNUSED,
                            PRInt32 *yOrigin ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 3002000
    vboxUnsupported();
    return 0;
#elif VBOX_API_VERSION < 4003000
    return display->vtbl->GetScreenResolution(display, screenId, width,
                                              height, bitsPerPixel);
#else /* VBOX_API_VERSION >= 4003000 */
    return display->vtbl->GetScreenResolution(display, screenId, width,
                                              height, bitsPerPixel,
                                              xOrigin, yOrigin);
#endif /* VBOX_API_VERSION >= 4003000 */
}

static nsresult
_displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED,
                                 PRUint32 screenId ATTRIBUTE_UNUSED,
                                 PRUint32 width ATTRIBUTE_UNUSED,
                                 PRUint32 height ATTRIBUTE_UNUSED,
                                 PRUint32 *screenDataSize ATTRIBUTE_UNUSED,
                                 PRUint8** screenData ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION < 4000000
    vboxUnsupported();
    return 0;
#else /* VBOX_API_VERSION >= 4000000 */
    return display->vtbl->TakeScreenShotPNGToArray(display, screenId, width,
                                                   height, screenDataSize,
                                                   screenData);
#endif /* VBOX_API_VERSION >= 4000000 */
}

T
Taowei 已提交
4373 4374 4375 4376 4377 4378 4379 4380
static nsresult
_hostFindHostNetworkInterfaceById(IHost *host, vboxIIDUnion *iidu,
                                  IHostNetworkInterface **networkInterface)
{
    return host->vtbl->FindHostNetworkInterfaceById(host, IID_MEMBER(value),
                                                    networkInterface);
}

T
Taowei 已提交
4381 4382 4383 4384 4385 4386 4387 4388
static nsresult
_hostFindHostNetworkInterfaceByName(IHost *host, PRUnichar *name,
                                    IHostNetworkInterface **networkInterface)
{
    return host->vtbl->FindHostNetworkInterfaceByName(host, name,
                                                      networkInterface);
}

T
Taowei 已提交
4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423
static nsresult
_hostCreateHostOnlyNetworkInterface(vboxGlobalData *data ATTRIBUTE_UNUSED,
                                    IHost *host, char *name ATTRIBUTE_UNUSED,
                                    IHostNetworkInterface **networkInterface)
{
    nsresult rc = -1;
#if VBOX_API_VERSION == 2002000
    if (STREQ(name, "vboxnet0")) {
        PRUint32 interfaceType = 0;
        PRUnichar *networkInterfaceNameUtf16 = NULL;

        VBOX_UTF8_TO_UTF16(name, &networkInterfaceNameUtf16);
        host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, networkInterface);

        (*networkInterface)->vtbl->GetInterfaceType(*networkInterface, &interfaceType);
        if (interfaceType != HostNetworkInterfaceType_HostOnly) {
            VBOX_RELEASE(*networkInterface);
            *networkInterface = NULL;
        } else {
            rc = 0;
        }
    }
#else /* VBOX_API_VERSION != 2002000 */
    IProgress *progress = NULL;
    host->vtbl->CreateHostOnlyNetworkInterface(host, networkInterface,
                                               &progress);

    if (progress) {
        rc = progress->vtbl->WaitForCompletion(progress, -1);
        VBOX_RELEASE(progress);
    }
#endif /* VBOX_API_VERSION != 2002000 */
    return rc;
}

T
Taowei 已提交
4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442
static nsresult
_hostRemoveHostOnlyNetworkInterface(IHost *host ATTRIBUTE_UNUSED,
                                    vboxIIDUnion *iidu ATTRIBUTE_UNUSED,
                                    IProgress **progress ATTRIBUTE_UNUSED)
{
#if VBOX_API_VERSION == 2002000
    vboxUnsupported();
    return 0;
#elif VBOX_API_VERSION == 3000000
    nsresult rc;
    IHostNetworkInterface *netInt = NULL;
    rc = host->vtbl->RemoveHostOnlyNetworkInterface(host, IID_MEMBER(value), &netInt, progress);
    VBOX_RELEASE(netInt);
    return rc;
#else  /* VBOX_API_VERSION > 3000000 */
    return host->vtbl->RemoveHostOnlyNetworkInterface(host, IID_MEMBER(value), progress);
#endif /* VBOX_API_VERSION > 3000000 */
}

T
Taowei 已提交
4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454
static nsresult
_hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType)
{
    return hni->vtbl->GetInterfaceType(hni, interfaceType);
}

static nsresult
_hnInterfaceGetStatus(IHostNetworkInterface *hni, PRUint32 *status)
{
    return hni->vtbl->GetStatus(hni, status);
}

T
Taowei 已提交
4455 4456 4457 4458 4459 4460
static nsresult
_hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name)
{
    return hni->vtbl->GetName(hni, name);
}

T
Taowei 已提交
4461 4462 4463 4464 4465 4466
static nsresult
_hnInterfaceGetId(IHostNetworkInterface *hni, vboxIIDUnion *iidu)
{
    return hni->vtbl->GetId(hni, &IID_MEMBER(value));
}

T
Taowei 已提交
4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484
static nsresult
_hnInterfaceGetHardwareAddress(IHostNetworkInterface *hni, PRUnichar **hardwareAddress)
{
    return hni->vtbl->GetHardwareAddress(hni, hardwareAddress);
}

static nsresult
_hnInterfaceGetIPAddress(IHostNetworkInterface *hni, PRUnichar **IPAddress)
{
    return hni->vtbl->GetIPAddress(hni, IPAddress);
}

static nsresult
_hnInterfaceGetNetworkMask(IHostNetworkInterface *hni, PRUnichar **networkMask)
{
    return hni->vtbl->GetNetworkMask(hni, networkMask);
}

T
Taowei 已提交
4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515
static nsresult
_hnInterfaceEnableStaticIPConfig(IHostNetworkInterface *hni, PRUnichar *IPAddress,
                                 PRUnichar *networkMask)
{
#if VBOX_API_VERSION < 4002000
    return hni->vtbl->EnableStaticIpConfig(hni, IPAddress, networkMask);
#else
    return hni->vtbl->EnableStaticIPConfig(hni, IPAddress, networkMask);
#endif
}

static nsresult
_hnInterfaceEnableDynamicIPConfig(IHostNetworkInterface *hni)
{
#if VBOX_API_VERSION < 4002000
    return hni->vtbl->EnableDynamicIpConfig(hni);
#else
    return hni->vtbl->EnableDynamicIPConfig(hni);
#endif
}

static nsresult
_hnInterfaceDHCPRediscover(IHostNetworkInterface *hni)
{
#if VBOX_API_VERSION < 4002000
    return hni->vtbl->DhcpRediscover(hni);
#else
    return hni->vtbl->DHCPRediscover(hni);
#endif
}

T
Taowei 已提交
4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539
static nsresult
_dhcpServerGetIPAddress(IDHCPServer *dhcpServer, PRUnichar **IPAddress)
{
    return dhcpServer->vtbl->GetIPAddress(dhcpServer, IPAddress);
}

static nsresult
_dhcpServerGetNetworkMask(IDHCPServer *dhcpServer, PRUnichar **networkMask)
{
    return dhcpServer->vtbl->GetNetworkMask(dhcpServer, networkMask);
}

static nsresult
_dhcpServerGetLowerIP(IDHCPServer *dhcpServer, PRUnichar **lowerIP)
{
    return dhcpServer->vtbl->GetLowerIP(dhcpServer, lowerIP);
}

static nsresult
_dhcpServerGetUpperIP(IDHCPServer *dhcpServer, PRUnichar **upperIP)
{
    return dhcpServer->vtbl->GetUpperIP(dhcpServer, upperIP);
}

T
Taowei 已提交
4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563
static nsresult
_dhcpServerSetEnabled(IDHCPServer *dhcpServer, PRBool enabled)
{
    return dhcpServer->vtbl->SetEnabled(dhcpServer, enabled);
}

static nsresult
_dhcpServerSetConfiguration(IDHCPServer *dhcpServer, PRUnichar *IPAddress,
                            PRUnichar *networkMask, PRUnichar *FromIPAddress,
                            PRUnichar *ToIPAddress)
{
    return dhcpServer->vtbl->SetConfiguration(dhcpServer, IPAddress,
                                              networkMask, FromIPAddress,
                                              ToIPAddress);
}

static nsresult
_dhcpServerStart(IDHCPServer *dhcpServer, PRUnichar *networkName,
                 PRUnichar *trunkName, PRUnichar *trunkType)
{
    return dhcpServer->vtbl->Start(dhcpServer, networkName,
                                   trunkName, trunkType);
}

T
Taowei 已提交
4564 4565 4566 4567 4568 4569
static nsresult
_dhcpServerStop(IDHCPServer *dhcpServer)
{
    return dhcpServer->vtbl->Stop(dhcpServer);
}

T
Taowei Luo 已提交
4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580
static nsresult
_hardDiskCreateBaseStorage(IHardDisk *hardDisk, PRUint64 logicalSize,
                           PRUint32 variant, IProgress **progress)
{
#if VBOX_API_VERSION < 4003000
    return hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, variant, progress);
#else
    return hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, 1, &variant, progress);
#endif
}

T
Taowei Luo 已提交
4581 4582 4583 4584 4585 4586
static nsresult
_hardDiskDeleteStorage(IHardDisk *hardDisk, IProgress **progress)
{
    return hardDisk->vtbl->DeleteStorage(hardDisk, progress);
}

T
Taowei Luo 已提交
4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601
static nsresult
_hardDiskGetLogicalSizeInByte(IHardDisk *hardDisk, PRUint64 *uLogicalSize)
{
    nsresult rc;
#if VBOX_API_VERSION < 4000000
    rc = hardDisk->vtbl->GetLogicalSize(hardDisk, uLogicalSize);
    *uLogicalSize *= 1024 * 1024; /* MB => Bytes */
#else /* VBOX_API_VERSION >= 4000000 */
    PRInt64 logicalSize;
    rc = hardDisk->vtbl->GetLogicalSize(hardDisk, &logicalSize);
    *uLogicalSize = logicalSize;
#endif /* VBOX_API_VERSION >= 4000000 */
    return rc;
}

4602 4603 4604 4605 4606 4607
static nsresult
_hardDiskGetFormat(IHardDisk *hardDisk, PRUnichar **format)
{
    return hardDisk->vtbl->GetFormat(hardDisk, format);
}

4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621
static nsresult
_keyboardPutScancode(IKeyboard *keyboard, PRInt32 scancode)
{
    return keyboard->vtbl->PutScancode(keyboard, scancode);
}

static nsresult
_keyboardPutScancodes(IKeyboard *keyboard, PRUint32 scancodesSize,
                      PRInt32 *scanCodes, PRUint32 *codesStored)
{
    return keyboard->vtbl->PutScancodes(keyboard, scancodesSize, scanCodes,
                                        codesStored);
}

T
Taowei 已提交
4622 4623 4624 4625 4626 4627
static bool _machineStateOnline(PRUint32 state)
{
    return ((state >= MachineState_FirstOnline) &&
            (state <= MachineState_LastOnline));
}

4628 4629
static bool _machineStateInactive(PRUint32 state)
{
4630 4631
    return ((state < MachineState_FirstOnline) ||
            (state > MachineState_LastOnline));
4632 4633
}

T
Taowei 已提交
4634 4635 4636 4637 4638 4639 4640
static bool _machineStateNotStart(PRUint32 state)
{
    return ((state == MachineState_PoweredOff) ||
            (state == MachineState_Saved) ||
            (state == MachineState_Aborted));
}

T
Taowei 已提交
4641 4642 4643 4644 4645
static bool _machineStateRunning(PRUint32 state)
{
    return state == MachineState_Running;
}

T
Taowei 已提交
4646 4647 4648 4649 4650
static bool _machineStatePaused(PRUint32 state)
{
    return state == MachineState_Paused;
}

T
Taowei 已提交
4651 4652 4653 4654 4655
static bool _machineStatePoweredOff(PRUint32 state)
{
    return state == MachineState_PoweredOff;
}

T
Taowei 已提交
4656 4657 4658 4659 4660 4661 4662 4663 4664 4665
static vboxUniformedPFN _UPFN = {
    .Initialize = _pfnInitialize,
    .Uninitialize = _pfnUninitialize,
    .ComUnallocMem = _pfnComUnallocMem,
    .Utf16Free = _pfnUtf16Free,
    .Utf8Free = _pfnUtf8Free,
    .Utf16ToUtf8 = _pfnUtf16ToUtf8,
    .Utf8ToUtf16 = _pfnUtf8ToUtf16,
};

T
Taowei 已提交
4666 4667 4668 4669 4670 4671 4672
static vboxUniformedIID _UIID = {
    .vboxIIDInitialize = _vboxIIDInitialize,
    .vboxIIDUnalloc = _vboxIIDUnalloc,
    .vboxIIDToUUID = _vboxIIDToUUID,
    .vboxIIDFromUUID = _vboxIIDFromUUID,
    .vboxIIDIsEqual = _vboxIIDIsEqual,
    .vboxIIDFromArrayItem = _vboxIIDFromArrayItem,
4673
    .vboxIIDToUtf8 = _vboxIIDToUtf8,
T
Taowei 已提交
4674 4675 4676
    .DEBUGIID = _DEBUGIID,
};

T
Taowei 已提交
4677 4678
static vboxUniformedArray _UArray = {
    .vboxArrayGet = vboxArrayGet,
4679
    .vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg,
T
Taowei 已提交
4680
    .vboxArrayRelease = vboxArrayRelease,
T
Taowei Luo 已提交
4681
    .vboxArrayUnalloc = vboxArrayUnalloc,
T
Taowei 已提交
4682
    .handleGetMachines = _handleGetMachines,
4683
    .handleGetHardDisks = _handleGetHardDisks,
T
Taowei 已提交
4684 4685 4686
    .handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters,
    .handleMachineGetMediumAttachments = _handleMachineGetMediumAttachments,
    .handleMachineGetSharedFolders = _handleMachineGetSharedFolders,
4687 4688 4689
    .handleSnapshotGetChildren = _handleSnapshotGetChildren,
    .handleMediumGetChildren = _handleMediumGetChildren,
    .handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds,
T
Taowei Luo 已提交
4690
    .handleMediumGetMachineIds = _handleMediumGetMachineIds,
T
Taowei 已提交
4691
    .handleHostGetNetworkInterfaces = _handleHostGetNetworkInterfaces,
T
Taowei 已提交
4692 4693
};

T
Taowei 已提交
4694 4695
static vboxUniformednsISupports _nsUISupports = {
    .Release = _nsisupportsRelease,
4696
    .AddRef = _nsisupportsAddRef,
T
Taowei 已提交
4697 4698
};

T
Taowei 已提交
4699 4700
static vboxUniformedIVirtualBox _UIVirtualBox = {
    .GetVersion = _virtualboxGetVersion,
T
Taowei 已提交
4701
    .GetMachine = _virtualboxGetMachine,
4702
    .OpenMachine = _virtualboxOpenMachine,
T
Taowei 已提交
4703
    .GetSystemProperties = _virtualboxGetSystemProperties,
T
Taowei 已提交
4704
    .GetHost = _virtualboxGetHost,
T
Taowei 已提交
4705
    .CreateMachine = _virtualboxCreateMachine,
4706
    .CreateHardDisk = _virtualboxCreateHardDisk,
T
Taowei 已提交
4707
    .RegisterMachine = _virtualboxRegisterMachine,
4708
    .FindHardDisk = _virtualboxFindHardDisk,
T
Taowei 已提交
4709
    .OpenMedium = _virtualboxOpenMedium,
4710
    .GetHardDiskByIID = _virtualboxGetHardDiskByIID,
T
Taowei 已提交
4711 4712
    .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
    .CreateDHCPServer = _virtualboxCreateDHCPServer,
T
Taowei 已提交
4713
    .RemoveDHCPServer = _virtualboxRemoveDHCPServer,
T
Taowei 已提交
4714 4715
};

T
Taowei 已提交
4716
static vboxUniformedIMachine _UIMachine = {
T
Taowei 已提交
4717
    .AddStorageController = _machineAddStorageController,
T
Taowei 已提交
4718
    .GetStorageControllerByName = _machineGetStorageControllerByName,
T
Taowei 已提交
4719 4720
    .AttachDevice = _machineAttachDevice,
    .CreateSharedFolder = _machineCreateSharedFolder,
T
Taowei 已提交
4721
    .RemoveSharedFolder = _machineRemoveSharedFolder,
T
Taowei 已提交
4722
    .LaunchVMProcess = _machineLaunchVMProcess,
4723
    .Unregister = _machineUnregister,
4724
    .FindSnapshot = _machineFindSnapshot,
T
Taowei Luo 已提交
4725
    .DetachDevice = _machineDetachDevice,
T
Taowei 已提交
4726 4727
    .GetAccessible = _machineGetAccessible,
    .GetState = _machineGetState,
T
Taowei 已提交
4728 4729
    .GetName = _machineGetName,
    .GetId = _machineGetId,
T
Taowei 已提交
4730 4731 4732 4733 4734 4735 4736 4737
    .GetBIOSSettings = _machineGetBIOSSettings,
    .GetAudioAdapter = _machineGetAudioAdapter,
    .GetNetworkAdapter = _machineGetNetworkAdapter,
    .GetChipsetType = _machineGetChipsetType,
    .GetSerialPort = _machineGetSerialPort,
    .GetParallelPort = _machineGetParallelPort,
    .GetVRDxServer = _machineGetVRDxServer,
    .GetUSBCommon = _machineGetUSBCommon,
4738 4739
    .GetCurrentSnapshot = _machineGetCurrentSnapshot,
    .GetSettingsFilePath = _machineGetSettingsFilePath,
T
Taowei 已提交
4740
    .GetCPUCount = _machineGetCPUCount,
T
Taowei 已提交
4741
    .SetCPUCount = _machineSetCPUCount,
T
Taowei 已提交
4742
    .GetMemorySize = _machineGetMemorySize,
T
Taowei 已提交
4743
    .SetMemorySize = _machineSetMemorySize,
T
Taowei 已提交
4744
    .GetCPUProperty = _machineGetCPUProperty,
T
Taowei 已提交
4745
    .SetCPUProperty = _machineSetCPUProperty,
T
Taowei 已提交
4746
    .GetBootOrder = _machineGetBootOrder,
T
Taowei 已提交
4747
    .SetBootOrder = _machineSetBootOrder,
T
Taowei 已提交
4748
    .GetVRAMSize = _machineGetVRAMSize,
T
Taowei 已提交
4749
    .SetVRAMSize = _machineSetVRAMSize,
T
Taowei 已提交
4750
    .GetMonitorCount = _machineGetMonitorCount,
T
Taowei 已提交
4751
    .SetMonitorCount = _machineSetMonitorCount,
T
Taowei 已提交
4752
    .GetAccelerate3DEnabled = _machineGetAccelerate3DEnabled,
T
Taowei 已提交
4753
    .SetAccelerate3DEnabled = _machineSetAccelerate3DEnabled,
T
Taowei 已提交
4754
    .GetAccelerate2DVideoEnabled = _machineGetAccelerate2DVideoEnabled,
T
Taowei 已提交
4755
    .SetAccelerate2DVideoEnabled = _machineSetAccelerate2DVideoEnabled,
T
Taowei 已提交
4756
    .GetExtraData = _machineGetExtraData,
T
Taowei 已提交
4757
    .SetExtraData = _machineSetExtraData,
4758
    .GetSnapshotCount = _machineGetSnapshotCount,
T
Taowei 已提交
4759
    .SaveSettings = _machineSaveSettings,
T
Taowei 已提交
4760 4761
};

T
Taowei 已提交
4762
static vboxUniformedISession _UISession = {
T
Taowei 已提交
4763
    .Open = _sessionOpen,
T
Taowei 已提交
4764 4765
    .OpenExisting = _sessionOpenExisting,
    .GetConsole = _sessionGetConsole,
T
Taowei 已提交
4766
    .GetMachine = _sessionGetMachine,
T
Taowei 已提交
4767 4768 4769 4770 4771
    .Close = _sessionClose,
};

static vboxUniformedIConsole _UIConsole = {
    .SaveState = _consoleSaveState,
T
Taowei 已提交
4772
    .Pause = _consolePause,
T
Taowei 已提交
4773
    .Resume = _consoleResume,
T
Taowei 已提交
4774
    .PowerButton = _consolePowerButton,
T
Taowei 已提交
4775
    .PowerDown = _consolePowerDown,
T
Taowei 已提交
4776
    .Reset = _consoleReset,
4777
    .TakeSnapshot = _consoleTakeSnapshot,
T
Taowei 已提交
4778
    .DeleteSnapshot = _consoleDeleteSnapshot,
T
Taowei 已提交
4779
    .GetDisplay = _consoleGetDisplay,
4780
    .GetKeyboard = _consoleGetKeyboard,
T
Taowei 已提交
4781 4782 4783 4784 4785
};

static vboxUniformedIProgress _UIProgress = {
    .WaitForCompletion = _progressWaitForCompletion,
    .GetResultCode = _progressGetResultCode,
T
Taowei 已提交
4786
    .GetCompleted = _progressGetCompleted,
T
Taowei 已提交
4787 4788
};

T
Taowei 已提交
4789 4790
static vboxUniformedISystemProperties _UISystemProperties = {
    .GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
T
Taowei 已提交
4791 4792 4793 4794 4795 4796
    .GetMaxBootPosition = _systemPropertiesGetMaxBootPosition,
    .GetMaxNetworkAdapters = _systemPropertiesGetMaxNetworkAdapters,
    .GetSerialPortCount = _systemPropertiesGetSerialPortCount,
    .GetParallelPortCount = _systemPropertiesGetParallelPortCount,
    .GetMaxPortCountForStorageBus = _systemPropertiesGetMaxPortCountForStorageBus,
    .GetMaxDevicesPerPortForStorageBus = _systemPropertiesGetMaxDevicesPerPortForStorageBus,
T
Taowei 已提交
4797
    .GetMaxGuestRAM = _systemPropertiesGetMaxGuestRAM,
T
Taowei 已提交
4798 4799 4800
};

static vboxUniformedIBIOSSettings _UIBIOSSettings = {
T
Taowei 已提交
4801
    .GetACPIEnabled = _biosSettingsGetACPIEnabled,
T
Taowei 已提交
4802
    .SetACPIEnabled = _biosSettingsSetACPIEnabled,
T
Taowei 已提交
4803
    .GetIOAPICEnabled = _biosSettingsGetIOAPICEnabled,
T
Taowei 已提交
4804 4805 4806 4807
    .SetIOAPICEnabled = _biosSettingsSetIOAPICEnabled,
};

static vboxUniformedIAudioAdapter _UIAudioAdapter = {
T
Taowei 已提交
4808
    .GetEnabled = _audioAdapterGetEnabled,
T
Taowei 已提交
4809
    .SetEnabled = _audioAdapterSetEnabled,
T
Taowei 已提交
4810
    .GetAudioController = _audioAdapterGetAudioController,
T
Taowei 已提交
4811 4812 4813 4814
    .SetAudioController = _audioAdapterSetAudioController,
};

static vboxUniformedINetworkAdapter _UINetworkAdapter = {
T
Taowei 已提交
4815 4816
    .GetAttachmentType = _networkAdapterGetAttachmentType,
    .GetEnabled = _networkAdapterGetEnabled,
T
Taowei 已提交
4817
    .SetEnabled = _networkAdapterSetEnabled,
T
Taowei 已提交
4818
    .GetAdapterType = _networkAdapterGetAdapterType,
T
Taowei 已提交
4819
    .SetAdapterType = _networkAdapterSetAdapterType,
T
Taowei 已提交
4820
    .GetBridgedInterface = _networkAdapterGetBridgedInterface,
T
Taowei 已提交
4821
    .SetBridgedInterface = _networkAdapterSetBridgedInterface,
T
Taowei 已提交
4822
    .GetInternalNetwork = _networkAdapterGetInternalNetwork,
T
Taowei 已提交
4823
    .SetInternalNetwork = _networkAdapterSetInternalNetwork,
T
Taowei 已提交
4824
    .GetHostOnlyInterface = _networkAdapterGetHostOnlyInterface,
T
Taowei 已提交
4825
    .SetHostOnlyInterface = _networkAdapterSetHostOnlyInterface,
T
Taowei 已提交
4826
    .GetMACAddress = _networkAdapterGetMACAddress,
T
Taowei 已提交
4827 4828 4829 4830 4831 4832 4833 4834
    .SetMACAddress = _networkAdapterSetMACAddress,
    .AttachToBridgedInterface = _networkAdapterAttachToBridgedInterface,
    .AttachToInternalNetwork = _networkAdapterAttachToInternalNetwork,
    .AttachToHostOnlyInterface = _networkAdapterAttachToHostOnlyInterface,
    .AttachToNAT = _networkAdapterAttachToNAT,
};

static vboxUniformedISerialPort _UISerialPort = {
T
Taowei 已提交
4835
    .GetEnabled = _serialPortGetEnabled,
T
Taowei 已提交
4836
    .SetEnabled = _serialPortSetEnabled,
T
Taowei 已提交
4837
    .GetPath = _serialPortGetPath,
T
Taowei 已提交
4838
    .SetPath = _serialPortSetPath,
T
Taowei 已提交
4839
    .GetIRQ = _serialPortGetIRQ,
T
Taowei 已提交
4840
    .SetIRQ = _serialPortSetIRQ,
T
Taowei 已提交
4841
    .GetIOBase = _serialPortGetIOBase,
T
Taowei 已提交
4842
    .SetIOBase = _serialPortSetIOBase,
T
Taowei 已提交
4843
    .GetHostMode = _serialPortGetHostMode,
T
Taowei 已提交
4844 4845 4846 4847
    .SetHostMode = _serialPortSetHostMode,
};

static vboxUniformedIParallelPort _UIParallelPort = {
T
Taowei 已提交
4848
    .GetEnabled = _parallelPortGetEnabled,
T
Taowei 已提交
4849
    .SetEnabled = _parallelPortSetEnabled,
T
Taowei 已提交
4850
    .GetPath = _parallelPortGetPath,
T
Taowei 已提交
4851
    .SetPath = _parallelPortSetPath,
T
Taowei 已提交
4852
    .GetIRQ = _parallelPortGetIRQ,
T
Taowei 已提交
4853
    .SetIRQ = _parallelPortSetIRQ,
T
Taowei 已提交
4854
    .GetIOBase = _parallelPortGetIOBase,
T
Taowei 已提交
4855 4856 4857 4858
    .SetIOBase = _parallelPortSetIOBase,
};

static vboxUniformedIVRDxServer _UIVRDxServer = {
T
Taowei 已提交
4859
    .GetEnabled = _vrdxServerGetEnabled,
T
Taowei 已提交
4860
    .SetEnabled = _vrdxServerSetEnabled,
T
Taowei 已提交
4861
    .GetPorts = _vrdxServerGetPorts,
T
Taowei 已提交
4862
    .SetPorts = _vrdxServerSetPorts,
T
Taowei 已提交
4863
    .GetReuseSingleConnection = _vrdxServerGetReuseSingleConnection,
T
Taowei 已提交
4864
    .SetReuseSingleConnection = _vrdxServerSetReuseSingleConnection,
T
Taowei 已提交
4865
    .GetAllowMultiConnection = _vrdxServerGetAllowMultiConnection,
T
Taowei 已提交
4866
    .SetAllowMultiConnection = _vrdxServerSetAllowMultiConnection,
T
Taowei 已提交
4867
    .GetNetAddress = _vrdxServerGetNetAddress,
T
Taowei 已提交
4868 4869 4870 4871 4872
    .SetNetAddress = _vrdxServerSetNetAddress,
};

static vboxUniformedIUSBCommon _UIUSBCommon = {
    .Enable = _usbCommonEnable,
T
Taowei 已提交
4873
    .GetEnabled = _usbCommonGetEnabled,
T
Taowei 已提交
4874 4875 4876 4877 4878
    .CreateDeviceFilter = _usbCommonCreateDeviceFilter,
    .InsertDeviceFilter = _usbCommonInsertDeviceFilter,
};

static vboxUniformedIUSBDeviceFilter _UIUSBDeviceFilter = {
T
Taowei 已提交
4879
    .GetProductId = _usbDeviceFilterGetProductId,
T
Taowei 已提交
4880
    .SetProductId = _usbDeviceFilterSetProductId,
T
Taowei 已提交
4881
    .GetActive = _usbDeviceFilterGetActive,
T
Taowei 已提交
4882
    .SetActive = _usbDeviceFilterSetActive,
T
Taowei 已提交
4883
    .GetVendorId = _usbDeviceFilterGetVendorId,
T
Taowei 已提交
4884 4885 4886 4887 4888
    .SetVendorId = _usbDeviceFilterSetVendorId,
};

static vboxUniformedIMedium _UIMedium = {
    .GetId = _mediumGetId,
T
Taowei 已提交
4889
    .GetLocation = _mediumGetLocation,
4890
    .GetState = _mediumGetState,
4891
    .GetName = _mediumGetName,
T
Taowei Luo 已提交
4892
    .GetSize = _mediumGetSize,
T
Taowei 已提交
4893
    .GetReadOnly = _mediumGetReadOnly,
4894 4895 4896 4897
    .GetParent = _mediumGetParent,
    .GetChildren = _mediumGetChildren,
    .GetFormat = _mediumGetFormat,
    .DeleteStorage = _mediumDeleteStorage,
T
Taowei 已提交
4898
    .Release = _mediumRelease,
4899
    .Close = _mediumClose,
T
Taowei 已提交
4900
    .SetType = _mediumSetType,
4901
    .CreateDiffStorage = _mediumCreateDiffStorage,
T
Taowei 已提交
4902 4903
};

T
Taowei 已提交
4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921
static vboxUniformedIMediumAttachment _UIMediumAttachment = {
    .GetMedium = _mediumAttachmentGetMedium,
    .GetController = _mediumAttachmentGetController,
    .GetType = _mediumAttachmentGetType,
    .GetPort = _mediumAttachmentGetPort,
    .GetDevice = _mediumAttachmentGetDevice,
};

static vboxUniformedIStorageController _UIStorageController = {
    .GetBus = _storageControllerGetBus,
};

static vboxUniformedISharedFolder _UISharedFolder = {
    .GetHostPath = _sharedFolderGetHostPath,
    .GetName = _sharedFolderGetName,
    .GetWritable = _sharedFolderGetWritable,
};

4922 4923 4924 4925 4926 4927 4928 4929 4930 4931
static vboxUniformedISnapshot _UISnapshot = {
    .GetName = _snapshotGetName,
    .GetId = _snapshotGetId,
    .GetMachine = _snapshotGetMachine,
    .GetDescription = _snapshotGetDescription,
    .GetTimeStamp = _snapshotGetTimeStamp,
    .GetParent = _snapshotGetParent,
    .GetOnline = _snapshotGetOnline,
};

T
Taowei 已提交
4932 4933 4934 4935 4936
static vboxUniformedIDisplay _UIDisplay = {
    .GetScreenResolution = _displayGetScreenResolution,
    .TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray,
};

T
Taowei 已提交
4937 4938
static vboxUniformedIHost _UIHost = {
    .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById,
T
Taowei 已提交
4939
    .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName,
T
Taowei 已提交
4940
    .CreateHostOnlyNetworkInterface = _hostCreateHostOnlyNetworkInterface,
T
Taowei 已提交
4941
    .RemoveHostOnlyNetworkInterface = _hostRemoveHostOnlyNetworkInterface,
T
Taowei 已提交
4942 4943
};

T
Taowei 已提交
4944 4945 4946
static vboxUniformedIHNInterface _UIHNInterface = {
    .GetInterfaceType = _hnInterfaceGetInterfaceType,
    .GetStatus = _hnInterfaceGetStatus,
T
Taowei 已提交
4947
    .GetName = _hnInterfaceGetName,
T
Taowei 已提交
4948
    .GetId = _hnInterfaceGetId,
T
Taowei 已提交
4949 4950 4951
    .GetHardwareAddress = _hnInterfaceGetHardwareAddress,
    .GetIPAddress = _hnInterfaceGetIPAddress,
    .GetNetworkMask = _hnInterfaceGetNetworkMask,
T
Taowei 已提交
4952 4953 4954 4955 4956 4957
    .EnableStaticIPConfig = _hnInterfaceEnableStaticIPConfig,
    .EnableDynamicIPConfig = _hnInterfaceEnableDynamicIPConfig,
    .DHCPRediscover = _hnInterfaceDHCPRediscover,
};

static vboxUniformedIDHCPServer _UIDHCPServer = {
T
Taowei 已提交
4958 4959 4960 4961
    .GetIPAddress = _dhcpServerGetIPAddress,
    .GetNetworkMask = _dhcpServerGetNetworkMask,
    .GetLowerIP = _dhcpServerGetLowerIP,
    .GetUpperIP = _dhcpServerGetUpperIP,
T
Taowei 已提交
4962 4963 4964
    .SetEnabled = _dhcpServerSetEnabled,
    .SetConfiguration = _dhcpServerSetConfiguration,
    .Start = _dhcpServerStart,
T
Taowei 已提交
4965
    .Stop = _dhcpServerStop,
T
Taowei 已提交
4966 4967
};

T
Taowei Luo 已提交
4968 4969
static vboxUniformedIHardDisk _UIHardDisk = {
    .CreateBaseStorage = _hardDiskCreateBaseStorage,
T
Taowei Luo 已提交
4970
    .DeleteStorage = _hardDiskDeleteStorage,
T
Taowei Luo 已提交
4971
    .GetLogicalSizeInByte = _hardDiskGetLogicalSizeInByte,
4972
    .GetFormat = _hardDiskGetFormat,
T
Taowei Luo 已提交
4973 4974
};

4975 4976 4977 4978 4979
static vboxUniformedIKeyboard _UIKeyboard = {
    .PutScancode = _keyboardPutScancode,
    .PutScancodes = _keyboardPutScancodes,
};

T
Taowei 已提交
4980 4981
static uniformedMachineStateChecker _machineStateChecker = {
    .Online = _machineStateOnline,
4982
    .Inactive = _machineStateInactive,
T
Taowei 已提交
4983
    .NotStart = _machineStateNotStart,
T
Taowei 已提交
4984
    .Running = _machineStateRunning,
T
Taowei 已提交
4985
    .Paused = _machineStatePaused,
T
Taowei 已提交
4986
    .PoweredOff = _machineStatePoweredOff,
T
Taowei 已提交
4987 4988
};

T
Taowei 已提交
4989 4990 4991 4992 4993 4994
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
{
    pVBoxAPI->APIVersion = VBOX_API_VERSION;
    pVBoxAPI->XPCOMCVersion = VBOX_XPCOMC_VERSION;
    pVBoxAPI->initializeDomainEvent = _initializeDomainEvent;
    pVBoxAPI->registerGlobalData = _registerGlobalData;
T
Taowei 已提交
4995 4996 4997
    pVBoxAPI->detachDevices = _detachDevices;
    pVBoxAPI->unregisterMachine = _unregisterMachine;
    pVBoxAPI->deleteConfig = _deleteConfig;
T
Taowei 已提交
4998
    pVBoxAPI->vboxAttachDrivesOld = _vboxAttachDrivesOld;
T
Taowei 已提交
4999
    pVBoxAPI->vboxConvertState = _vboxConvertState;
T
Taowei 已提交
5000 5001
    pVBoxAPI->dumpIDEHDDsOld = _dumpIDEHDDsOld;
    pVBoxAPI->dumpDVD = _dumpDVD;
T
Taowei 已提交
5002
    pVBoxAPI->attachDVD = _attachDVD;
T
Taowei 已提交
5003
    pVBoxAPI->detachDVD = _detachDVD;
T
Taowei 已提交
5004
    pVBoxAPI->dumpFloppy = _dumpFloppy;
T
Taowei 已提交
5005
    pVBoxAPI->attachFloppy = _attachFloppy;
T
Taowei 已提交
5006
    pVBoxAPI->detachFloppy = _detachFloppy;
5007
    pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
T
Taowei 已提交
5008
    pVBoxAPI->registerDomainEvent = _registerDomainEvent;
T
Taowei 已提交
5009
    pVBoxAPI->UPFN = _UPFN;
T
Taowei 已提交
5010
    pVBoxAPI->UIID = _UIID;
T
Taowei 已提交
5011
    pVBoxAPI->UArray = _UArray;
T
Taowei 已提交
5012
    pVBoxAPI->nsUISupports = _nsUISupports;
T
Taowei 已提交
5013
    pVBoxAPI->UIVirtualBox = _UIVirtualBox;
T
Taowei 已提交
5014
    pVBoxAPI->UIMachine = _UIMachine;
T
Taowei 已提交
5015 5016 5017
    pVBoxAPI->UISession = _UISession;
    pVBoxAPI->UIConsole = _UIConsole;
    pVBoxAPI->UIProgress = _UIProgress;
T
Taowei 已提交
5018
    pVBoxAPI->UISystemProperties = _UISystemProperties;
T
Taowei 已提交
5019 5020 5021 5022 5023 5024 5025 5026 5027
    pVBoxAPI->UIBIOSSettings = _UIBIOSSettings;
    pVBoxAPI->UIAudioAdapter = _UIAudioAdapter;
    pVBoxAPI->UINetworkAdapter = _UINetworkAdapter;
    pVBoxAPI->UISerialPort = _UISerialPort;
    pVBoxAPI->UIParallelPort = _UIParallelPort;
    pVBoxAPI->UIVRDxServer = _UIVRDxServer;
    pVBoxAPI->UIUSBCommon = _UIUSBCommon;
    pVBoxAPI->UIUSBDeviceFilter = _UIUSBDeviceFilter;
    pVBoxAPI->UIMedium = _UIMedium;
T
Taowei 已提交
5028 5029 5030
    pVBoxAPI->UIMediumAttachment = _UIMediumAttachment;
    pVBoxAPI->UIStorageController = _UIStorageController;
    pVBoxAPI->UISharedFolder = _UISharedFolder;
5031
    pVBoxAPI->UISnapshot = _UISnapshot;
T
Taowei 已提交
5032
    pVBoxAPI->UIDisplay = _UIDisplay;
T
Taowei 已提交
5033
    pVBoxAPI->UIHost = _UIHost;
T
Taowei 已提交
5034
    pVBoxAPI->UIHNInterface = _UIHNInterface;
T
Taowei 已提交
5035
    pVBoxAPI->UIDHCPServer = _UIDHCPServer;
T
Taowei Luo 已提交
5036
    pVBoxAPI->UIHardDisk = _UIHardDisk;
5037
    pVBoxAPI->UIKeyboard = _UIKeyboard;
T
Taowei 已提交
5038
    pVBoxAPI->machineStateChecker = _machineStateChecker;
T
Taowei 已提交
5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051

#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
    pVBoxAPI->domainEventCallbacks = 0;
#else /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
    pVBoxAPI->domainEventCallbacks = 1;
#endif /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */

#if VBOX_API_VERSION == 2002000
    pVBoxAPI->hasStaticGlobalData = 0;
#else /* VBOX_API_VERSION > 2002000 */
    pVBoxAPI->hasStaticGlobalData = 1;
#endif /* VBOX_API_VERSION > 2002000 */

T
Taowei 已提交
5052 5053 5054
#if VBOX_API_VERSION >= 4000000
    /* Get machine for the call to VBOX_SESSION_OPEN_EXISTING */
    pVBoxAPI->getMachineForSession = 1;
T
Taowei 已提交
5055
    pVBoxAPI->detachDevicesExplicitly = 0;
T
Taowei 已提交
5056
    pVBoxAPI->vboxAttachDrivesUseOld = 0;
T
Taowei 已提交
5057
    pVBoxAPI->supportScreenshot = 1;
T
Taowei 已提交
5058 5059
#else /* VBOX_API_VERSION < 4000000 */
    pVBoxAPI->getMachineForSession = 0;
T
Taowei 已提交
5060
    pVBoxAPI->detachDevicesExplicitly = 1;
T
Taowei 已提交
5061
    pVBoxAPI->vboxAttachDrivesUseOld = 1;
T
Taowei 已提交
5062
    pVBoxAPI->supportScreenshot = 0;
T
Taowei 已提交
5063
#endif /* VBOX_API_VERSION < 4000000 */
T
Taowei 已提交
5064 5065 5066 5067 5068 5069 5070 5071 5072

#if VBOX_API_VERSION >= 4001000
    pVBoxAPI->chipsetType = 1;
#else /* VBOX_API_VERSION < 4001000 */
    pVBoxAPI->chipsetType = 0;
#endif /* VBOX_API_VERSION < 4001000 */

#if VBOX_API_VERSION >= 3001000
    pVBoxAPI->accelerate2DVideo = 1;
T
Taowei 已提交
5073
    pVBoxAPI->oldMediumInterface = 0;
T
Taowei 已提交
5074 5075
#else /* VBOX_API_VERSION < 3001000 */
    pVBoxAPI->accelerate2DVideo = 0;
T
Taowei 已提交
5076
    pVBoxAPI->oldMediumInterface = 1;
T
Taowei 已提交
5077
#endif /* VBOX_API_VERSION < 3001000 */
5078 5079 5080 5081 5082 5083

#if VBOX_API_VERSION >= 4002000
    pVBoxAPI->vboxSnapshotRedefine = 1;
#else /* VBOX_API_VERSION < 4002000 */
    pVBoxAPI->vboxSnapshotRedefine = 0;
#endif /* VBOX_API_VERSION < 4002000 */
T
Taowei 已提交
5084 5085 5086 5087 5088 5089

#if VBOX_API_VERSION == 2002000
    pVBoxAPI->networkRemoveInterface = 0;
#else /* VBOX_API_VERSION > 2002000 */
    pVBoxAPI->networkRemoveInterface = 1;
#endif /* VBOX_API_VERSION > 2002000 */
T
Taowei 已提交
5090
}