vbox_tmpl.c 80.6 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 == 4000000
53
# include "vbox_CAPI_v4_0.h"
54
#elif VBOX_API_VERSION == 4001000
55
# include "vbox_CAPI_v4_1.h"
56
#elif VBOX_API_VERSION == 4002000
57
# include "vbox_CAPI_v4_2.h"
58 59 60
#elif VBOX_API_VERSION == 4002020
# include "vbox_CAPI_v4_2_20.h"
#elif VBOX_API_VERSION == 4003000
R
Ryota Ozaki 已提交
61
# include "vbox_CAPI_v4_3.h"
62 63
#elif VBOX_API_VERSION == 4003004
# include "vbox_CAPI_v4_3_4.h"
M
Martin Pietsch 已提交
64 65
#elif VBOX_API_VERSION == 5000000
# include "vbox_CAPI_v5_0.h"
66 67
#elif VBOX_API_VERSION == 5001000
# include "vbox_CAPI_v5_1.h"
D
Dawid Zamirski 已提交
68 69
#elif VBOX_API_VERSION == 5002000
# include "vbox_CAPI_v5_2.h"
70 71
#else
# error "Unsupport VBOX_API_VERSION"
72 73
#endif

74
/* Include this *last* or we'll get the wrong vbox_CAPI_*.h. */
75
#include "vbox_glue.h"
T
Taowei 已提交
76 77 78 79 80 81 82

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

T
Taowei 已提交
83

T
Taowei 已提交
84
#include "vbox_uniformed_api.h"
85

86
#define VIR_FROM_THIS                   VIR_FROM_VBOX
87 88 89

VIR_LOG_INIT("vbox.vbox_tmpl");

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

93 94 95 96 97 98
#define VBOX_UTF16_FREE(arg) \
    do { \
        if (arg) { \
            data->pFuncs->pfnUtf16Free(arg); \
            (arg) = NULL; \
        } \
J
John Ferlan 已提交
99 100
    } while (0)

101 102 103 104 105 106
#define VBOX_UTF8_FREE(arg) \
    do { \
        if (arg) { \
            data->pFuncs->pfnUtf8Free(arg); \
            (arg) = NULL; \
        } \
J
John Ferlan 已提交
107 108
    } while (0)

109 110 111
#define VBOX_UTF16_TO_UTF8(arg1, arg2)  data->pFuncs->pfnUtf16ToUtf8(arg1, arg2)
#define VBOX_UTF8_TO_UTF16(arg1, arg2)  data->pFuncs->pfnUtf8ToUtf16(arg1, arg2)

112 113 114 115 116 117
#define VBOX_RELEASE(arg) \
    do { \
        if (arg) { \
            (arg)->vtbl->nsisupports.Release((nsISupports *)(arg)); \
            (arg) = NULL; \
        } \
118
    } while (0)
119

120
#define VBOX_MEDIUM_RELEASE(arg) VBOX_RELEASE(arg)
121

122 123 124 125
#define DEBUGPRUnichar(msg, strUtf16) \
if (strUtf16) {\
    char *strUtf8 = NULL;\
\
126
    data->pFuncs->pfnUtf16ToUtf8(strUtf16, &strUtf8);\
127
    if (strUtf8) {\
128
        VIR_DEBUG("%s: %s", msg, strUtf8);\
129
        data->pFuncs->pfnUtf8Free(strUtf8);\
130 131 132 133 134
    }\
}

#define DEBUGUUID(msg, iid) \
{\
T
Taowei 已提交
135
    VIR_DEBUG("%s: {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", msg,\
136 137 138 139 140 141 142 143 144 145 146 147 148
          (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]);\
}\

149
#define VBOX_IID_INITIALIZER { NULL, true }
150

151 152 153
/* default RDP port range to use for auto-port setting */
#define VBOX_RDP_AUTOPORT_RANGE "3389-3689"

154
static void
155
_vboxIIDUnalloc(vboxDriverPtr data, vboxIID *iid)
156
{
157
    if (iid->value != NULL && iid->owner)
158 159 160 161
        data->pFuncs->pfnUtf16Free(iid->value);

    iid->value = NULL;
    iid->owner = true;
162 163
}

T
Taowei 已提交
164
static void
165 166
_vboxIIDToUUID(vboxDriverPtr data, vboxIID *iid,
               unsigned char *uuid)
167 168 169 170 171
{
    char *utf8 = NULL;

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

172
    ignore_value(virUUIDParse(utf8, uuid));
173 174

    data->pFuncs->pfnUtf8Free(utf8);
175 176
}

T
Taowei 已提交
177
static void
178 179
_vboxIIDFromUUID(vboxDriverPtr data, vboxIID *iid,
                 const unsigned char *uuid)
180 181
{
    char utf8[VIR_UUID_STRING_BUFLEN];
182

183
    _vboxIIDUnalloc(data, iid);
184

185
    virUUIDFormat(uuid, utf8);
186

187 188
    data->pFuncs->pfnUtf8ToUtf16(utf8, &iid->value);
}
189

190
static bool
191 192
_vboxIIDIsEqual(vboxDriverPtr data, vboxIID *iid1,
                vboxIID *iid2)
193 194 195
{
    unsigned char uuid1[VIR_UUID_BUFLEN];
    unsigned char uuid2[VIR_UUID_BUFLEN];
196 197

    /* Note: we can't directly compare the utf8 strings here
E
Eric Blake 已提交
198
     * cause the two UUID's may have separators as space or '-'
199 200
     * or mixture of both and we don't want to fail here by
     * using direct string comparison. Here virUUIDParse() takes
201
     * care of these cases. */
202 203
    _vboxIIDToUUID(data, iid1, uuid1);
    _vboxIIDToUUID(data, iid2, uuid2);
204

205 206
    return memcmp(uuid1, uuid2, VIR_UUID_BUFLEN) == 0;
}
207

208
static void
209 210
_vboxIIDFromArrayItem(vboxDriverPtr data, vboxIID *iid,
                      vboxArray *array, int idx)
211
{
212
    _vboxIIDUnalloc(data, iid);
213

214 215
    iid->value = array->items[idx];
    iid->owner = false;
216 217
}

218 219 220 221
#define vboxIIDUnalloc(iid) _vboxIIDUnalloc(data, iid)
#define vboxIIDToUUID(iid, uuid) _vboxIIDToUUID(data, iid, uuid)
#define vboxIIDFromUUID(iid, uuid) _vboxIIDFromUUID(data, iid, uuid)
#define vboxIIDIsEqual(iid1, iid2) _vboxIIDIsEqual(data, iid1, iid2)
222
#define vboxIIDFromArrayItem(iid, array, idx) \
223
    _vboxIIDFromArrayItem(data, iid, array, idx)
224
#define DEBUGIID(msg, strUtf16) DEBUGPRUnichar(msg, strUtf16)
225 226 227 228

/**
 * Converts int to Utf-16 string
 */
229
static PRUnichar *PRUnicharFromInt(PCVBOXXPCOM pFuncs, int n) {
230 231 232 233 234
    PRUnichar *strUtf16 = NULL;
    char s[24];

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

235
    pFuncs->pfnUtf8ToUtf16(s, &strUtf16);
236 237 238 239

    return strUtf16;
}

T
Taowei 已提交
240
static virDomainState _vboxConvertState(PRUint32 state)
241
{
242 243 244 245 246 247 248 249 250 251
    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 已提交
252
        case MachineState_Saved:
253 254 255 256 257 258 259 260 261
            return VIR_DOMAIN_SHUTOFF;
        case MachineState_Aborted:
            return VIR_DOMAIN_CRASHED;
        case MachineState_Null:
        default:
            return VIR_DOMAIN_NOSTATE;
    }
}

262 263 264 265 266 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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

static int
vboxGetActiveVRDEServerPort(ISession *session, IMachine *machine)
{
    nsresult rc;
    PRInt32 port = -1;
    IVRDEServerInfo *vrdeInfo = NULL;
    IConsole *console = NULL;

    rc = machine->vtbl->LockMachine(machine, session, LockType_Shared);
    if (NS_FAILED(rc)) {
        VIR_WARN("Could not obtain shared lock on VBox VM, rc=%08x", rc);
        return -1;
    }

    rc = session->vtbl->GetConsole(session, &console);
    if (NS_FAILED(rc)) {
        VIR_WARN("Could not get VBox session console, rc=%08x", rc);
        goto cleanup;
    }

    /* it may be null if VM is not running */
    if (!console)
        goto cleanup;

    rc = console->vtbl->GetVRDEServerInfo(console, &vrdeInfo);

    if (NS_FAILED(rc) || !vrdeInfo) {
        VIR_WARN("Could not get VBox VM VRDEServerInfo, rc=%08x", rc);
        goto cleanup;
    }

    rc = vrdeInfo->vtbl->GetPort(vrdeInfo, &port);

    if (NS_FAILED(rc)) {
        VIR_WARN("Could not read port from VRDEServerInfo, rc=%08x", rc);
        goto cleanup;
    }

 cleanup:
    VBOX_RELEASE(console);
    VBOX_RELEASE(vrdeInfo);
    session->vtbl->UnlockMachine(session);

    return port;
}


J
Jiri Denemark 已提交
310
static int
311
_vboxDomainSnapshotRestore(virDomainPtr dom,
J
Jiri Denemark 已提交
312 313 314
                          IMachine *machine,
                          ISnapshot *snapshot)
{
315
    vboxDriverPtr data = dom->conn->privateData;
316
#if VBOX_API_VERSION < 5000000
J
Jiri Denemark 已提交
317
    IConsole *console = NULL;
318
#endif /*VBOX_API_VERSION < 5000000*/
J
Jiri Denemark 已提交
319 320 321 322
    IProgress *progress = NULL;
    PRUint32 state;
    nsresult rc;
    PRInt32 result;
323
    vboxIID domiid = VBOX_IID_INITIALIZER;
T
Taowei Luo 已提交
324 325 326 327
    int ret = -1;

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

329 330
    rc = machine->vtbl->GetId(machine, &domiid.value);
    if (NS_FAILED(rc)) {
331 332
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("could not get domain UUID"));
J
Jiri Denemark 已提交
333 334 335 336 337
        goto cleanup;
    }

    rc = machine->vtbl->GetState(machine, &state);
    if (NS_FAILED(rc)) {
338 339
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("could not get domain state"));
J
Jiri Denemark 已提交
340 341 342 343 344
        goto cleanup;
    }

    if (state >= MachineState_FirstOnline
        && state <= MachineState_LastOnline) {
345 346
        virReportError(VIR_ERR_OPERATION_INVALID,
                       _("domain %s is already running"), dom->name);
J
Jiri Denemark 已提交
347 348 349
        goto cleanup;
    }

350
    rc = machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Write);
351
#if VBOX_API_VERSION < 5000000
J
Jiri Denemark 已提交
352 353
    if (NS_SUCCEEDED(rc))
        rc = data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
354
#endif /*VBOX_API_VERSION < 5000000*/
J
Jiri Denemark 已提交
355
    if (NS_FAILED(rc)) {
356 357 358
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not open VirtualBox session with domain %s"),
                       dom->name);
J
Jiri Denemark 已提交
359 360 361
        goto cleanup;
    }

362
#if VBOX_API_VERSION < 5000000
J
Jiri Denemark 已提交
363
    rc = console->vtbl->RestoreSnapshot(console, snapshot, &progress);
364
#elif VBOX_API_VERSION >= 5000000  /*VBOX_API_VERSION < 5000000*/
M
Martin Pietsch 已提交
365
    rc = machine->vtbl->RestoreSnapshot(machine, snapshot, &progress);
366
#endif /*VBOX_API_VERSION >= 5000000*/
M
Martin Pietsch 已提交
367

J
Jiri Denemark 已提交
368 369
    if (NS_FAILED(rc) || !progress) {
        if (rc == VBOX_E_INVALID_VM_STATE) {
370 371
            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                           _("cannot restore domain snapshot for running domain"));
J
Jiri Denemark 已提交
372
        } else {
373 374 375
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("could not restore snapshot for domain %s"),
                           dom->name);
J
Jiri Denemark 已提交
376 377 378 379 380 381 382
        }
        goto cleanup;
    }

    progress->vtbl->WaitForCompletion(progress, -1);
    progress->vtbl->GetResultCode(progress, &result);
    if (NS_FAILED(result)) {
383 384
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("could not restore snapshot for domain %s"), dom->name);
J
Jiri Denemark 已提交
385 386 387 388 389
        goto cleanup;
    }

    ret = 0;

390
 cleanup:
J
Jiri Denemark 已提交
391
    VBOX_RELEASE(progress);
392
#if VBOX_API_VERSION < 5000000
J
Jiri Denemark 已提交
393
    VBOX_RELEASE(console);
394
#endif /*VBOX_API_VERSION < 5000000*/
395
    data->vboxSession->vtbl->UnlockMachine(data->vboxSession);
396
    vboxIIDUnalloc(&domiid);
J
Jiri Denemark 已提交
397 398 399
    return ret;
}

400
static nsresult
401
_unregisterMachine(vboxDriverPtr data, vboxIID *iid, IMachine **machine)
T
Taowei 已提交
402 403
{
    nsresult rc;
404
    vboxArray media = VBOX_ARRAY_INITIALIZER;
405 406
    size_t i;

407
    rc = data->vboxObj->vtbl->FindMachine(data->vboxObj, iid->value, machine);
408 409 410 411 412
    if (NS_FAILED(rc)) {
        virReportError(VIR_ERR_NO_DOMAIN, "%s",
                       _("no domain with matching uuid"));
        return rc;
    }
T
Taowei 已提交
413

414
    rc = vboxArrayGetWithUintArg(&media, *machine, (*machine)->vtbl->Unregister,
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
                                 CleanupMode_DetachAllReturnHardDisksOnly);

    if (NS_FAILED(rc))
        goto cleanup;

    /* close each medium attached to VM to remove from media registry */
    for (i = 0; i < media.count; i++) {
        IMedium *medium = media.items[i];

        if (!medium)
            continue;

        /* it's ok to ignore failure here - e.g. it may be used by another VM */
        ignore_value(medium->vtbl->Close(medium));
    }

 cleanup:
432 433 434
    vboxArrayUnalloc(&media);
    return rc;
}
T
Taowei 已提交
435

436 437 438 439
static void
_deleteConfig(IMachine *machine)
{
    IProgress *progress = NULL;
T
Taowei 已提交
440

441 442 443 444 445 446 447 448 449 450
    /* 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);
T
Taowei 已提交
451

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
# 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);
    }
T
Taowei 已提交
471 472
}

473
static int _pfnInitialize(vboxDriverPtr driver)
T
Taowei 已提交
474
{
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
    if (!(driver->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION)))
        return -1;
#if VBOX_API_VERSION == 4002020 || VBOX_API_VERSION >= 4004004
    nsresult rc;

    rc = driver->pFuncs->pfnClientInitialize(IVIRTUALBOXCLIENT_IID_STR,
                                             &driver->vboxClient);

    if (NS_FAILED(rc)) {
        return -1;
    } else {
        driver->vboxClient->vtbl->GetVirtualBox(driver->vboxClient, &driver->vboxObj);
        driver->vboxClient->vtbl->GetSession(driver->vboxClient, &driver->vboxSession);
    }
#else
    driver->pFuncs->pfnComInitialize(IVIRTUALBOX_IID_STR, &driver->vboxObj,
                                     ISESSION_IID_STR, &driver->vboxSession);
#endif

    return 0;
}

static void _pfnUninitialize(vboxDriverPtr data)
{
    if (data->pFuncs) {
#if VBOX_API_VERSION == 4002020 || VBOX_API_VERSION >= 4003004
        VBOX_RELEASE(data->vboxObj);
        VBOX_RELEASE(data->vboxSession);
        VBOX_RELEASE(data->vboxClient);

        data->pFuncs->pfnClientUninitialize();
#else
T
Taowei 已提交
507
        data->pFuncs->pfnComUninitialize();
508 509
#endif
    }
510
}
511

T
Taowei 已提交
512
static void _pfnComUnallocMem(PCVBOXXPCOM pFuncs, void *pv)
513
{
T
Taowei 已提交
514 515
    pFuncs->pfnComUnallocMem(pv);
}
516

T
Taowei 已提交
517 518 519 520
static void _pfnUtf16Free(PCVBOXXPCOM pFuncs, PRUnichar *pwszString)
{
    pFuncs->pfnUtf16Free(pwszString);
}
E
Eric Blake 已提交
521

T
Taowei 已提交
522 523 524 525
static void _pfnUtf8Free(PCVBOXXPCOM pFuncs, char *pszString)
{
    pFuncs->pfnUtf8Free(pszString);
}
526

T
Taowei 已提交
527 528 529 530
static int _pfnUtf16ToUtf8(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString)
{
    return pFuncs->pfnUtf16ToUtf8(pwszString, ppszString);
}
531

T
Taowei 已提交
532 533 534 535
static int _pfnUtf8ToUtf16(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString)
{
    return pFuncs->pfnUtf8ToUtf16(pszString, ppwszString);
}
536

537
static void _vboxIIDInitialize(vboxIID *iid)
T
Taowei 已提交
538
{
539 540
    memset(iid, 0, sizeof(vboxIID));
    iid->owner = true;
T
Taowei 已提交
541
}
542

543
static void _DEBUGIID(vboxDriverPtr data, const char *msg, vboxIID *iid)
T
Taowei 已提交
544
{
545
    DEBUGPRUnichar(msg, iid->value);
T
Taowei 已提交
546
}
547

548
static void
549
_vboxIIDToUtf8(vboxDriverPtr data ATTRIBUTE_UNUSED,
550
               vboxIID *iid ATTRIBUTE_UNUSED,
551 552
               char **utf8 ATTRIBUTE_UNUSED)
{
553
    data->pFuncs->pfnUtf16ToUtf8(iid->value, utf8);
554 555
}

556
static nsresult
557
_vboxArrayGetWithIIDArg(vboxArray *array, void *self, void *getter, vboxIID *iid)
558
{
559
    return vboxArrayGetWithPtrArg(array, self, getter, iid->value);
560 561
}

T
Taowei 已提交
562 563 564 565
static void* _handleGetMachines(IVirtualBox *vboxObj)
{
    return vboxObj->vtbl->GetMachines;
}
566

567 568 569 570 571
static void* _handleGetHardDisks(IVirtualBox *vboxObj)
{
    return vboxObj->vtbl->GetHardDisks;
}

T
Taowei 已提交
572 573 574 575 576
static void* _handleUSBGetDeviceFilters(IUSBCommon *USBCommon)
{
    return USBCommon->vtbl->GetDeviceFilters;
}

577 578 579 580 581
static void* _handleMachineGetStorageControllers(IMachine *machine)
{
    return machine->vtbl->GetStorageControllers;
}

T
Taowei 已提交
582 583 584 585 586 587 588 589 590 591
static void* _handleMachineGetMediumAttachments(IMachine *machine)
{
    return machine->vtbl->GetMediumAttachments;
}

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

592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
static void* _handleSnapshotGetChildren(ISnapshot *snapshot)
{
    return snapshot->vtbl->GetChildren;
}

static void* _handleMediumGetChildren(IMedium *medium ATTRIBUTE_UNUSED)
{
    return medium->vtbl->GetChildren;
}

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

T
Taowei Luo 已提交
607 608 609 610 611
static void* _handleMediumGetMachineIds(IMedium *medium)
{
    return medium->vtbl->GetMachineIds;
}

T
Taowei 已提交
612 613 614 615 616
static void* _handleHostGetNetworkInterfaces(IHost *host)
{
    return host->vtbl->GetNetworkInterfaces;
}

T
Taowei 已提交
617 618 619 620
static nsresult _nsisupportsRelease(nsISupports *nsi)
{
    return nsi->vtbl->Release(nsi);
}
621

622 623 624 625 626
static nsresult _nsisupportsAddRef(nsISupports *nsi)
{
    return nsi->vtbl->AddRef(nsi);
}

T
Taowei 已提交
627 628 629 630 631
static nsresult
_virtualboxGetVersion(IVirtualBox *vboxObj, PRUnichar **versionUtf16)
{
    return vboxObj->vtbl->GetVersion(vboxObj, versionUtf16);
}
632

T
Taowei 已提交
633
static nsresult
634
_virtualboxGetMachine(IVirtualBox *vboxObj, vboxIID *iid, IMachine **machine)
T
Taowei 已提交
635
{
636
    return vboxObj->vtbl->FindMachine(vboxObj, iid->value, machine);
637
}
T
Taowei 已提交
638

639 640 641 642 643 644
static nsresult
_virtualboxOpenMachine(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine)
{
    return vboxObj->vtbl->OpenMachine(vboxObj, settingsFile, machine);
}

T
Taowei 已提交
645 646 647 648 649
static nsresult
_virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemProperties)
{
    return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
}
650

T
Taowei 已提交
651 652 653 654 655 656
static nsresult
_virtualboxGetHost(IVirtualBox *vboxObj, IHost **host)
{
    return vboxObj->vtbl->GetHost(vboxObj, host);
}

T
Taowei 已提交
657
static nsresult
658
_virtualboxCreateMachine(vboxDriverPtr data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED)
659 660
{
    vboxIID iid = VBOX_IID_INITIALIZER;
T
Taowei 已提交
661
    PRUnichar *machineNameUtf16 = NULL;
662
    nsresult rc = -1;
663

T
Taowei 已提交
664 665 666
    VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
    vboxIIDFromUUID(&iid, def->uuid);
    {
667
#if VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
668
        PRBool override = PR_FALSE;
T
Taowei 已提交
669 670 671 672 673 674 675 676
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                NULL,
                                                machineNameUtf16,
                                                NULL,
                                                iid.value,
                                                override,
                                                machine);
#else /* VBOX_API_VERSION >= 4002000 */
677
        char *createFlags = NULL;
T
Taowei 已提交
678 679
        PRUnichar *createFlagsUtf16 = NULL;

680 681 682
        if (virAsprintf(&createFlags,
                        "UUID=%s,forceOverwrite=0", uuidstr) < 0)
            goto cleanup;
T
Taowei 已提交
683 684 685 686 687 688 689 690 691
        VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
        rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                NULL,
                                                machineNameUtf16,
                                                0,
                                                nsnull,
                                                nsnull,
                                                createFlagsUtf16,
                                                machine);
692 693
 cleanup:
        VIR_FREE(createFlags);
T
Taowei 已提交
694
#endif /* VBOX_API_VERSION >= 4002000 */
695
    }
T
Taowei 已提交
696 697 698 699
    VBOX_UTF16_FREE(machineNameUtf16);
    vboxIIDUnalloc(&iid);
    return rc;
}
700

701
static nsresult
702
_virtualboxCreateHardDisk(IVirtualBox *vboxObj, PRUnichar *format,
703
                          PRUnichar *location, IMedium **medium)
704
{
705 706 707
    /* 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.
     */
M
Martin Pietsch 已提交
708
#if VBOX_API_VERSION < 5000000
709
    return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, medium);
M
Martin Pietsch 已提交
710
#elif VBOX_API_VERSION >= 5000000 /*VBOX_API_VERSION >= 5000000*/
711 712 713
    return vboxObj->vtbl->CreateMedium(vboxObj, format, location,
                                       AccessMode_ReadWrite,
                                       DeviceType_HardDisk, medium);
M
Martin Pietsch 已提交
714
#endif /*VBOX_API_VERSION >= 5000000*/
715 716
}

T
Taowei 已提交
717 718 719 720 721
static nsresult
_virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine)
{
    return vboxObj->vtbl->RegisterMachine(vboxObj, machine);
}
722

T
Taowei 已提交
723
static nsresult
724 725 726
_virtualboxFindHardDisk(IVirtualBox *vboxObj,
                        PRUnichar *location,
                        PRUint32 deviceType,
727
                        PRUint32 accessMode ATTRIBUTE_UNUSED,
728
                        IMedium **medium)
T
Taowei 已提交
729
{
730
#if VBOX_API_VERSION < 4002000
731
    return vboxObj->vtbl->FindMedium(vboxObj, location, deviceType, medium);
732
#else /* VBOX_API_VERSION >= 4002000 */
733 734
    return vboxObj->vtbl->OpenMedium(vboxObj, location, deviceType, accessMode,
                                     PR_FALSE, medium);
735
#endif /* VBOX_API_VERSION >= 4002000 */
T
Taowei 已提交
736
}
737

T
Taowei 已提交
738
static nsresult
739 740 741 742 743
_virtualboxOpenMedium(IVirtualBox *vboxObj,
                      PRUnichar *location,
                      PRUint32 deviceType,
                      PRUint32 accessMode,
                      IMedium **medium)
T
Taowei 已提交
744 745
{
#if VBOX_API_VERSION == 4000000
746
    return vboxObj->vtbl->OpenMedium(vboxObj, location, deviceType, accessMode,
T
Taowei 已提交
747 748
                                     medium);
#elif VBOX_API_VERSION >= 4001000
749 750
    return vboxObj->vtbl->OpenMedium(vboxObj, location, deviceType, accessMode,
                                     false, medium);
T
Taowei 已提交
751 752
#endif
}
753

754
static nsresult
755
_virtualboxGetHardDiskByIID(IVirtualBox *vboxObj, vboxIID *iid, IMedium **medium)
756
{
757
#if VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
758
    return vboxObj->vtbl->FindMedium(vboxObj, iid->value, DeviceType_HardDisk,
759
                                     medium);
760
#else /* VBOX_API_VERSION >= 4002000 */
761
    return vboxObj->vtbl->OpenMedium(vboxObj, iid->value, DeviceType_HardDisk,
762
                                     AccessMode_ReadWrite, PR_FALSE, medium);
763 764 765
#endif /* VBOX_API_VERSION >= 4002000 */
}

T
Taowei 已提交
766 767 768 769 770 771 772 773 774 775 776 777
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 已提交
778 779 780 781 782 783
static nsresult
_virtualboxRemoveDHCPServer(IVirtualBox *vboxObj, IDHCPServer *server)
{
    return vboxObj->vtbl->RemoveDHCPServer(vboxObj, server);
}

T
Taowei 已提交
784 785 786 787 788 789 790 791
static nsresult
_machineAddStorageController(IMachine *machine, PRUnichar *name,
                             PRUint32 connectionType,
                             IStorageController **controller)
{
    return machine->vtbl->AddStorageController(machine, name, connectionType,
                                               controller);
}
792

T
Taowei 已提交
793 794 795 796 797 798 799 800
static nsresult
_machineGetStorageControllerByName(IMachine *machine, PRUnichar *name,
                                   IStorageController **storageController)
{
    return machine->vtbl->GetStorageControllerByName(machine, name,
                                                     storageController);
}

T
Taowei 已提交
801
static nsresult
802 803 804 805 806 807
_machineAttachDevice(IMachine *machine,
                     PRUnichar *name,
                     PRInt32 controllerPort,
                     PRInt32 device,
                     PRUint32 type,
                     IMedium * medium)
T
Taowei 已提交
808 809 810 811
{
    return machine->vtbl->AttachDevice(machine, name, controllerPort,
                                       device, type, medium);
}
812

T
Taowei 已提交
813 814 815 816 817 818 819 820
static nsresult
_machineCreateSharedFolder(IMachine *machine, PRUnichar *name,
                           PRUnichar *hostPath, PRBool writable,
                           PRBool automount ATTRIBUTE_UNUSED)
{
    return machine->vtbl->CreateSharedFolder(machine, name, hostPath,
                                             writable, automount);
}
821

T
Taowei 已提交
822 823 824 825 826 827
static nsresult
_machineRemoveSharedFolder(IMachine *machine, PRUnichar *name)
{
    return machine->vtbl->RemoveSharedFolder(machine, name);
}

T
Taowei 已提交
828
static nsresult
829
_machineLaunchVMProcess(vboxDriverPtr data,
T
Taowei 已提交
830
                        IMachine *machine ATTRIBUTE_UNUSED,
831
                        vboxIID *iid ATTRIBUTE_UNUSED,
T
Taowei 已提交
832 833 834 835 836 837
                        PRUnichar *sessionType, PRUnichar *env,
                        IProgress **progress)
{
    return machine->vtbl->LaunchVMProcess(machine, data->vboxSession,
                                          sessionType, env, progress);
}
838

839 840 841 842 843 844 845 846 847
static nsresult
_machineUnregister(IMachine *machine ATTRIBUTE_UNUSED,
                   PRUint32 cleanupMode ATTRIBUTE_UNUSED,
                   PRUint32 *aMediaSize ATTRIBUTE_UNUSED,
                   IMedium ***aMedia ATTRIBUTE_UNUSED)
{
    return machine->vtbl->Unregister(machine, cleanupMode, aMediaSize, aMedia);
}

848
static nsresult
849
_machineFindSnapshot(IMachine *machine, vboxIID *iid, ISnapshot **snapshot)
850
{
851
    return machine->vtbl->FindSnapshot(machine, iid->value, snapshot);
852 853
}

T
Taowei Luo 已提交
854 855 856 857 858 859 860
static nsresult
_machineDetachDevice(IMachine *machine, PRUnichar *name,
                     PRInt32 controllerPort, PRInt32 device)
{
    return machine->vtbl->DetachDevice(machine, name, controllerPort, device);
}

T
Taowei 已提交
861 862 863 864 865
static nsresult
_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
{
    return machine->vtbl->GetAccessible(machine, isAccessible);
}
866

T
Taowei 已提交
867 868 869 870 871
static nsresult
_machineGetState(IMachine *machine, PRUint32 *state)
{
    return machine->vtbl->GetState(machine, state);
}
872

T
Taowei 已提交
873 874 875 876 877
static nsresult
_machineGetName(IMachine *machine, PRUnichar **name)
{
    return machine->vtbl->GetName(machine, name);
}
878

T
Taowei 已提交
879
static nsresult
880
_machineGetId(IMachine *machine, vboxIID *iid)
T
Taowei 已提交
881
{
882
    return machine->vtbl->GetId(machine, &iid->value);
T
Taowei 已提交
883
}
884

T
Taowei 已提交
885 886 887 888 889
static nsresult
_machineGetBIOSSettings(IMachine *machine, IBIOSSettings **bios)
{
    return machine->vtbl->GetBIOSSettings(machine, bios);
}
890

T
Taowei 已提交
891 892 893 894 895
static nsresult
_machineGetAudioAdapter(IMachine *machine, IAudioAdapter **audioadapter)
{
    return machine->vtbl->GetAudioAdapter(machine, audioadapter);
}
896

T
Taowei 已提交
897 898 899 900 901
static nsresult
_machineGetNetworkAdapter(IMachine *machine, PRUint32 slot, INetworkAdapter **adapter)
{
    return machine->vtbl->GetNetworkAdapter(machine, slot, adapter);
}
902

T
Taowei 已提交
903 904 905 906 907
static nsresult
_machineGetChipsetType(IMachine *machine ATTRIBUTE_UNUSED, PRUint32 *chipsetType ATTRIBUTE_UNUSED)
{
    return machine->vtbl->GetChipsetType(machine, chipsetType);
}
908

T
Taowei 已提交
909 910 911 912
static nsresult
_machineGetSerialPort(IMachine *machine, PRUint32 slot, ISerialPort **port)
{
    return machine->vtbl->GetSerialPort(machine, slot, port);
913 914
}

T
Taowei 已提交
915 916 917 918 919
static nsresult
_machineGetParallelPort(IMachine *machine, PRUint32 slot, IParallelPort **port)
{
    return machine->vtbl->GetParallelPort(machine, slot, port);
}
920

T
Taowei 已提交
921
static nsresult
922
_machineGetVRDEServer(IMachine *machine, IVRDEServer **VRDEServer)
923
{
924
    return machine->vtbl->GetVRDEServer(machine, VRDEServer);
925 926
}

T
Taowei 已提交
927 928 929 930 931 932 933 934 935
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
}
936

937 938 939 940 941 942 943 944 945 946 947 948
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 已提交
949 950 951 952 953 954
static nsresult
_machineGetCPUCount(IMachine *machine, PRUint32 *CPUCount)
{
    return machine->vtbl->GetCPUCount(machine, CPUCount);
}

T
Taowei 已提交
955 956
static nsresult
_machineSetCPUCount(IMachine *machine, PRUint32 CPUCount)
957
{
T
Taowei 已提交
958
    return machine->vtbl->SetCPUCount(machine, CPUCount);
959 960
}

T
Taowei 已提交
961 962 963 964 965 966
static nsresult
_machineGetMemorySize(IMachine *machine, PRUint32 *memorySize)
{
    return machine->vtbl->GetMemorySize(machine, memorySize);
}

T
Taowei 已提交
967 968 969 970 971
static nsresult
_machineSetMemorySize(IMachine *machine, PRUint32 memorySize)
{
    return machine->vtbl->SetMemorySize(machine, memorySize);
}
972

T
Taowei 已提交
973 974 975 976 977 978
static nsresult
_machineGetCPUProperty(IMachine *machine, PRUint32 property ATTRIBUTE_UNUSED, PRBool *value)
{
    return machine->vtbl->GetCPUProperty(machine, property, value);
}

T
Taowei 已提交
979 980
static nsresult
_machineSetCPUProperty(IMachine *machine, PRUint32 property ATTRIBUTE_UNUSED, PRBool value)
981
{
T
Taowei 已提交
982
    return machine->vtbl->SetCPUProperty(machine, property, value);
983 984
}

T
Taowei 已提交
985 986 987 988 989 990
static nsresult
_machineGetBootOrder(IMachine *machine, PRUint32 position, PRUint32 *device)
{
    return machine->vtbl->GetBootOrder(machine, position, device);
}

T
Taowei 已提交
991 992 993 994 995
static nsresult
_machineSetBootOrder(IMachine *machine, PRUint32 position, PRUint32 device)
{
    return machine->vtbl->SetBootOrder(machine, position, device);
}
996

T
Taowei 已提交
997 998 999 1000 1001 1002
static nsresult
_machineGetVRAMSize(IMachine *machine, PRUint32 *VRAMSize)
{
    return machine->vtbl->GetVRAMSize(machine, VRAMSize);
}

T
Taowei 已提交
1003 1004
static nsresult
_machineSetVRAMSize(IMachine *machine, PRUint32 VRAMSize)
1005
{
T
Taowei 已提交
1006 1007
    return machine->vtbl->SetVRAMSize(machine, VRAMSize);
}
1008

T
Taowei 已提交
1009 1010 1011 1012 1013 1014
static nsresult
_machineGetMonitorCount(IMachine *machine, PRUint32 *monitorCount)
{
    return machine->vtbl->GetMonitorCount(machine, monitorCount);
}

T
Taowei 已提交
1015 1016 1017 1018
static nsresult
_machineSetMonitorCount(IMachine *machine, PRUint32 monitorCount)
{
    return machine->vtbl->SetMonitorCount(machine, monitorCount);
1019 1020
}

T
Taowei 已提交
1021 1022 1023 1024 1025 1026
static nsresult
_machineGetAccelerate3DEnabled(IMachine *machine, PRBool *accelerate3DEnabled)
{
    return machine->vtbl->GetAccelerate3DEnabled(machine, accelerate3DEnabled);
}

T
Taowei 已提交
1027 1028
static nsresult
_machineSetAccelerate3DEnabled(IMachine *machine, PRBool accelerate3DEnabled)
T
Taowei 已提交
1029
{
T
Taowei 已提交
1030
    return machine->vtbl->SetAccelerate3DEnabled(machine, accelerate3DEnabled);
T
Taowei 已提交
1031 1032
}

T
Taowei 已提交
1033
static nsresult
1034 1035
_machineGetAccelerate2DVideoEnabled(IMachine *machine,
                                    PRBool *accelerate2DVideoEnabled)
T
Taowei 已提交
1036 1037 1038 1039
{
    return machine->vtbl->GetAccelerate2DVideoEnabled(machine, accelerate2DVideoEnabled);
}

T
Taowei 已提交
1040
static nsresult
1041 1042
_machineSetAccelerate2DVideoEnabled(IMachine *machine,
                                    PRBool accelerate2DVideoEnabled)
T
Taowei 已提交
1043
{
T
Taowei 已提交
1044
    return machine->vtbl->SetAccelerate2DVideoEnabled(machine, accelerate2DVideoEnabled);
T
Taowei 已提交
1045 1046
}

T
Taowei 已提交
1047 1048 1049 1050 1051 1052
static nsresult
_machineGetExtraData(IMachine *machine, PRUnichar *key, PRUnichar **value)
{
    return machine->vtbl->GetExtraData(machine, key, value);
}

T
Taowei 已提交
1053 1054
static nsresult
_machineSetExtraData(IMachine *machine, PRUnichar *key, PRUnichar *value)
T
Taowei 已提交
1055
{
T
Taowei 已提交
1056 1057 1058
    return machine->vtbl->SetExtraData(machine, key, value);
}

1059 1060 1061 1062 1063 1064
static nsresult
_machineGetSnapshotCount(IMachine *machine, PRUint32 *snapshotCount)
{
    return machine->vtbl->GetSnapshotCount(machine, snapshotCount);
}

T
Taowei 已提交
1065 1066 1067 1068
static nsresult
_machineSaveSettings(IMachine *machine)
{
    return machine->vtbl->SaveSettings(machine);
T
Taowei 已提交
1069 1070
}

T
Taowei 已提交
1071
static nsresult
1072
_sessionOpen(vboxDriverPtr data, vboxIID *iid ATTRIBUTE_UNUSED, IMachine *machine)
T
Taowei 已提交
1073 1074 1075
{
    return machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Write);
}
T
Taowei 已提交
1076

T
Taowei 已提交
1077
static nsresult
1078
_sessionOpenExisting(vboxDriverPtr data, vboxIID *iid ATTRIBUTE_UNUSED, IMachine *machine)
T
Taowei 已提交
1079 1080 1081
{
    return machine->vtbl->LockMachine(machine, data->vboxSession, LockType_Shared);
}
T
Taowei 已提交
1082

T
Taowei 已提交
1083 1084 1085 1086 1087
static nsresult
_sessionClose(ISession *session)
{
    return session->vtbl->UnlockMachine(session);
}
T
Taowei 已提交
1088

T
Taowei 已提交
1089 1090 1091 1092 1093
static nsresult
_sessionGetConsole(ISession *session, IConsole **console)
{
    return session->vtbl->GetConsole(session, console);
}
T
Taowei 已提交
1094

T
Taowei 已提交
1095 1096 1097 1098 1099 1100 1101 1102 1103
static nsresult
_sessionGetMachine(ISession *session, IMachine **machine)
{
    return session->vtbl->GetMachine(session, machine);
}

static nsresult
_consoleSaveState(IConsole *console, IProgress **progress)
{
M
Martin Pietsch 已提交
1104
#if VBOX_API_VERSION < 5000000
T
Taowei 已提交
1105
    return console->vtbl->SaveState(console, progress);
M
Martin Pietsch 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
#else /*VBOX_API_VERSION < 5000000*/
    IMachine *machine;
    nsresult rc;

    rc = console->vtbl->GetMachine(console, &machine);

    if (NS_SUCCEEDED(rc))
        rc = machine->vtbl->SaveState(machine, progress);
    else
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("unable to get machine from console. (error %d)"), rc);

    return rc;

#endif /*VBOX_API_VERSION >= 5000000*/
T
Taowei 已提交
1121 1122
}

T
Taowei 已提交
1123 1124 1125 1126 1127 1128
static nsresult
_consolePause(IConsole *console)
{
    return console->vtbl->Pause(console);
}

T
Taowei 已提交
1129 1130 1131 1132 1133 1134
static nsresult
_consoleResume(IConsole *console)
{
    return console->vtbl->Resume(console);
}

T
Taowei 已提交
1135 1136 1137 1138 1139 1140
static nsresult
_consolePowerButton(IConsole *console)
{
    return console->vtbl->PowerButton(console);
}

T
Taowei 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
static nsresult
_consolePowerDown(IConsole *console)
{
    nsresult rc;
    IProgress *progress = NULL;
    rc = console->vtbl->PowerDown(console, &progress);
    if (progress) {
        rc = progress->vtbl->WaitForCompletion(progress, -1);
        VBOX_RELEASE(progress);
    }
1151

T
Taowei 已提交
1152 1153 1154
    return rc;
}

T
Taowei 已提交
1155 1156 1157 1158 1159 1160
static nsresult
_consoleReset(IConsole *console)
{
    return console->vtbl->Reset(console);
}

1161 1162 1163 1164
static nsresult
_consoleTakeSnapshot(IConsole *console, PRUnichar *name,
                     PRUnichar *description, IProgress **progress)
{
M
Martin Pietsch 已提交
1165
#if VBOX_API_VERSION < 5000000
1166
    return console->vtbl->TakeSnapshot(console, name, description, progress);
M
Martin Pietsch 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
#else
    IMachine *machine;
    nsresult rc;
    PRUnichar *id = NULL;
    bool bpause = true; /*NO live snapshot*/

    rc = console->vtbl->GetMachine(console, &machine);

    if (NS_SUCCEEDED(rc))
        rc = machine->vtbl->TakeSnapshot(machine, name, description, bpause, &id, progress);
    else
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("unable to get machine from console. (error %d)"), rc);

    VBOX_RELEASE(machine);
    return rc;
#endif /* VBOX_API_VERSION >= 5000000 */
1184 1185
}

T
Taowei 已提交
1186
static nsresult
1187
_consoleDeleteSnapshot(IConsole *console, vboxIID *iid, IProgress **progress)
T
Taowei 已提交
1188
{
1189
#if VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION < 5000000 */
1190
    return console->vtbl->DeleteSnapshot(console, iid->value, progress);
M
Martin Pietsch 已提交
1191 1192 1193 1194 1195 1196 1197
#else /* VBOX_API_VERSION >= 5000000 */
    IMachine *machine;
    nsresult rc;

    rc = console->vtbl->GetMachine(console, &machine);

    if (NS_SUCCEEDED(rc))
1198
        rc = machine->vtbl->DeleteSnapshot(machine, iid->value, progress);
M
Martin Pietsch 已提交
1199 1200 1201 1202 1203 1204 1205 1206
    else
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("unable to get machine from console. (error %d)"), rc);

    VBOX_RELEASE(machine);

    return rc;
#endif /* VBOX_API_VERSION >= 5000000 */
T
Taowei 已提交
1207 1208
}

T
Taowei 已提交
1209 1210 1211 1212 1213 1214
static nsresult
_consoleGetDisplay(IConsole *console, IDisplay **display)
{
    return console->vtbl->GetDisplay(console, display);
}

1215 1216 1217 1218 1219 1220
static nsresult
_consoleGetKeyboard(IConsole *console, IKeyboard **keyboard)
{
    return console->vtbl->GetKeyboard(console, keyboard);
}

T
Taowei 已提交
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
static nsresult
_progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
{
    return progress->vtbl->WaitForCompletion(progress, timeout);
}

static nsresult
_progressGetResultCode(IProgress *progress, resultCodeUnion *resultCode)
{
    return progress->vtbl->GetResultCode(progress, &resultCode->resultCode);
}

T
Taowei 已提交
1233 1234 1235 1236 1237 1238
static nsresult
_progressGetCompleted(IProgress *progress, PRBool *completed)
{
    return progress->vtbl->GetCompleted(progress, completed);
}

T
Taowei 已提交
1239 1240 1241 1242
static nsresult
_systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, PRUint32 *maxCPUCount)
{
    return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
T
Taowei 已提交
1243 1244 1245
}

static nsresult
T
Taowei 已提交
1246
_systemPropertiesGetMaxBootPosition(ISystemProperties *systemProperties, PRUint32 *maxBootPosition)
T
Taowei 已提交
1247
{
T
Taowei 已提交
1248
    return systemProperties->vtbl->GetMaxBootPosition(systemProperties, maxBootPosition);
T
Taowei 已提交
1249 1250
}

T
Taowei 已提交
1251 1252 1253
static nsresult
_systemPropertiesGetMaxNetworkAdapters(ISystemProperties *systemProperties, PRUint32 chipset ATTRIBUTE_UNUSED,
                                       PRUint32 *maxNetworkAdapters)
T
Taowei 已提交
1254
{
T
Taowei 已提交
1255 1256 1257 1258 1259 1260 1261
#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 已提交
1262 1263
}

T
Taowei 已提交
1264 1265
static nsresult
_systemPropertiesGetSerialPortCount(ISystemProperties *systemProperties, PRUint32 *SerialPortCount)
T
Taowei 已提交
1266
{
T
Taowei 已提交
1267
    return systemProperties->vtbl->GetSerialPortCount(systemProperties, SerialPortCount);
T
Taowei 已提交
1268 1269 1270
}

static nsresult
T
Taowei 已提交
1271
_systemPropertiesGetParallelPortCount(ISystemProperties *systemProperties, PRUint32 *ParallelPortCount)
T
Taowei 已提交
1272
{
T
Taowei 已提交
1273 1274
    return systemProperties->vtbl->GetParallelPortCount(systemProperties, ParallelPortCount);
}
T
Taowei 已提交
1275

T
Taowei 已提交
1276 1277 1278 1279 1280
static nsresult
_systemPropertiesGetMaxPortCountForStorageBus(ISystemProperties *systemProperties, PRUint32 bus,
                                              PRUint32 *maxPortCount)
{
    return systemProperties->vtbl->GetMaxPortCountForStorageBus(systemProperties, bus, maxPortCount);
T
Taowei 已提交
1281 1282
}

T
Taowei 已提交
1283 1284 1285
static nsresult
_systemPropertiesGetMaxDevicesPerPortForStorageBus(ISystemProperties *systemProperties,
                                                   PRUint32 bus, PRUint32 *maxDevicesPerPort)
T
Taowei 已提交
1286
{
T
Taowei 已提交
1287 1288 1289
    return systemProperties->vtbl->GetMaxDevicesPerPortForStorageBus(systemProperties,
                                                                     bus, maxDevicesPerPort);
}
T
Taowei 已提交
1290

T
Taowei 已提交
1291 1292 1293 1294 1295 1296
static nsresult
_systemPropertiesGetMaxGuestRAM(ISystemProperties *systemProperties, PRUint32 *maxGuestRAM)
{
    return systemProperties->vtbl->GetMaxGuestRAM(systemProperties, maxGuestRAM);
}

T
Taowei 已提交
1297 1298 1299 1300 1301 1302
static nsresult
_biosSettingsGetACPIEnabled(IBIOSSettings *bios, PRBool *ACPIEnabled)
{
    return bios->vtbl->GetACPIEnabled(bios, ACPIEnabled);
}

T
Taowei 已提交
1303 1304 1305 1306
static nsresult
_biosSettingsSetACPIEnabled(IBIOSSettings *bios, PRBool ACPIEnabled)
{
    return bios->vtbl->SetACPIEnabled(bios, ACPIEnabled);
T
Taowei 已提交
1307 1308
}

T
Taowei 已提交
1309 1310 1311 1312 1313 1314
static nsresult
_biosSettingsGetIOAPICEnabled(IBIOSSettings *bios, PRBool *IOAPICEnabled)
{
    return bios->vtbl->GetIOAPICEnabled(bios, IOAPICEnabled);
}

T
Taowei 已提交
1315 1316 1317 1318 1319
static nsresult
_biosSettingsSetIOAPICEnabled(IBIOSSettings *bios, PRBool IOAPICEnabled)
{
    return bios->vtbl->SetIOAPICEnabled(bios, IOAPICEnabled);
}
T
Taowei 已提交
1320

T
Taowei 已提交
1321 1322 1323 1324 1325 1326
static nsresult
_audioAdapterGetEnabled(IAudioAdapter *audioAdapter, PRBool *enabled)
{
    return audioAdapter->vtbl->GetEnabled(audioAdapter, enabled);
}

T
Taowei 已提交
1327 1328
static nsresult
_audioAdapterSetEnabled(IAudioAdapter *audioAdapter, PRBool enabled)
T
Taowei 已提交
1329
{
T
Taowei 已提交
1330
    return audioAdapter->vtbl->SetEnabled(audioAdapter, enabled);
T
Taowei 已提交
1331 1332
}

T
Taowei 已提交
1333 1334 1335 1336 1337 1338
static nsresult
_audioAdapterGetAudioController(IAudioAdapter *audioAdapter, PRUint32 *audioController)
{
    return audioAdapter->vtbl->GetAudioController(audioAdapter, audioController);
}

T
Taowei 已提交
1339 1340
static nsresult
_audioAdapterSetAudioController(IAudioAdapter *audioAdapter, PRUint32 audioController)
T
Taowei 已提交
1341
{
T
Taowei 已提交
1342
    return audioAdapter->vtbl->SetAudioController(audioAdapter, audioController);
T
Taowei 已提交
1343 1344
}

T
Taowei 已提交
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
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 已提交
1357 1358
static nsresult
_networkAdapterSetEnabled(INetworkAdapter *adapter, PRBool enabled)
T
Taowei 已提交
1359
{
T
Taowei 已提交
1360
    return adapter->vtbl->SetEnabled(adapter, enabled);
T
Taowei 已提交
1361 1362
}

T
Taowei 已提交
1363 1364 1365 1366 1367 1368
static nsresult
_networkAdapterGetAdapterType(INetworkAdapter *adapter, PRUint32 *adapterType)
{
    return adapter->vtbl->GetAdapterType(adapter, adapterType);
}

T
Taowei 已提交
1369 1370
static nsresult
_networkAdapterSetAdapterType(INetworkAdapter *adapter, PRUint32 adapterType)
T
Taowei 已提交
1371
{
T
Taowei 已提交
1372
    return adapter->vtbl->SetAdapterType(adapter, adapterType);
T
Taowei 已提交
1373 1374
}

T
Taowei 已提交
1375 1376 1377 1378 1379 1380
static nsresult
_networkAdapterGetInternalNetwork(INetworkAdapter *adapter, PRUnichar **internalNetwork)
{
    return adapter->vtbl->GetInternalNetwork(adapter, internalNetwork);
}

T
Taowei 已提交
1381 1382
static nsresult
_networkAdapterSetInternalNetwork(INetworkAdapter *adapter, PRUnichar *internalNetwork)
T
Taowei 已提交
1383
{
T
Taowei 已提交
1384
    return adapter->vtbl->SetInternalNetwork(adapter, internalNetwork);
T
Taowei 已提交
1385 1386
}

T
Taowei 已提交
1387 1388 1389 1390 1391 1392
static nsresult
_networkAdapterGetMACAddress(INetworkAdapter *adapter, PRUnichar **MACAddress)
{
    return adapter->vtbl->GetMACAddress(adapter, MACAddress);
}

T
Taowei 已提交
1393 1394
static nsresult
_networkAdapterSetMACAddress(INetworkAdapter *adapter, PRUnichar *MACAddress)
T
Taowei 已提交
1395
{
T
Taowei 已提交
1396
    return adapter->vtbl->SetMACAddress(adapter, MACAddress);
T
Taowei 已提交
1397 1398
}

T
Taowei 已提交
1399
#if VBOX_API_VERSION < 4001000
T
Taowei 已提交
1400

T
Taowei 已提交
1401 1402 1403 1404 1405 1406
static nsresult
_networkAdapterGetBridgedInterface(INetworkAdapter *adapter, PRUnichar **hostInterface)
{
    return adapter->vtbl->GetHostInterface(adapter, hostInterface);
}

T
Taowei 已提交
1407 1408
static nsresult
_networkAdapterSetBridgedInterface(INetworkAdapter *adapter, PRUnichar *hostInterface)
T
Taowei 已提交
1409
{
T
Taowei 已提交
1410
    return adapter->vtbl->SetHostInterface(adapter, hostInterface);
T
Taowei 已提交
1411 1412
}

T
Taowei 已提交
1413 1414 1415 1416 1417 1418
static nsresult
_networkAdapterGetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface)
{
    return adapter->vtbl->GetHostInterface(adapter, hostOnlyInterface);
}

T
Taowei 已提交
1419 1420
static nsresult
_networkAdapterSetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface)
T
Taowei 已提交
1421
{
T
Taowei 已提交
1422
    return adapter->vtbl->SetHostInterface(adapter, hostOnlyInterface);
T
Taowei 已提交
1423 1424
}

T
Taowei 已提交
1425 1426
static nsresult
_networkAdapterAttachToBridgedInterface(INetworkAdapter *adapter)
T
Taowei 已提交
1427
{
T
Taowei 已提交
1428
    return adapter->vtbl->AttachToBridgedInterface(adapter);
T
Taowei 已提交
1429 1430
}

T
Taowei 已提交
1431 1432
static nsresult
_networkAdapterAttachToInternalNetwork(INetworkAdapter *adapter)
T
Taowei 已提交
1433
{
T
Taowei 已提交
1434
    return adapter->vtbl->AttachToInternalNetwork(adapter);
T
Taowei 已提交
1435 1436
}

T
Taowei 已提交
1437 1438 1439 1440 1441
static nsresult
_networkAdapterAttachToHostOnlyInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->AttachToHostOnlyInterface(adapter);
}
T
Taowei 已提交
1442

T
Taowei 已提交
1443 1444
static nsresult
_networkAdapterAttachToNAT(INetworkAdapter *adapter)
T
Taowei 已提交
1445
{
T
Taowei 已提交
1446
    return adapter->vtbl->AttachToNAT(adapter);
T
Taowei 已提交
1447 1448
}

T
Taowei 已提交
1449 1450
#else /* VBOX_API_VERSION >= 4001000 */

T
Taowei 已提交
1451 1452 1453 1454 1455 1456
static nsresult
_networkAdapterGetBridgedInterface(INetworkAdapter *adapter, PRUnichar **bridgedInterface)
{
    return adapter->vtbl->GetBridgedInterface(adapter, bridgedInterface);
}

T
Taowei 已提交
1457 1458
static nsresult
_networkAdapterSetBridgedInterface(INetworkAdapter *adapter, PRUnichar *bridgedInterface)
T
Taowei 已提交
1459
{
T
Taowei 已提交
1460
    return adapter->vtbl->SetBridgedInterface(adapter, bridgedInterface);
T
Taowei 已提交
1461 1462
}

T
Taowei 已提交
1463 1464 1465 1466 1467 1468
static nsresult
_networkAdapterGetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar **hostOnlyInterface)
{
    return adapter->vtbl->GetHostOnlyInterface(adapter, hostOnlyInterface);
}

T
Taowei 已提交
1469
static nsresult
T
Taowei 已提交
1470
_networkAdapterSetHostOnlyInterface(INetworkAdapter *adapter, PRUnichar *hostOnlyInterface)
T
Taowei 已提交
1471
{
T
Taowei 已提交
1472
    return adapter->vtbl->SetHostOnlyInterface(adapter, hostOnlyInterface);
T
Taowei 已提交
1473 1474
}

T
Taowei 已提交
1475 1476 1477 1478 1479
static nsresult
_networkAdapterAttachToBridgedInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_Bridged);
}
T
Taowei 已提交
1480 1481

static nsresult
T
Taowei 已提交
1482
_networkAdapterAttachToInternalNetwork(INetworkAdapter *adapter)
T
Taowei 已提交
1483
{
T
Taowei 已提交
1484
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_Internal);
T
Taowei 已提交
1485 1486
}

T
Taowei 已提交
1487 1488 1489 1490 1491
static nsresult
_networkAdapterAttachToHostOnlyInterface(INetworkAdapter *adapter)
{
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_HostOnly);
}
T
Taowei 已提交
1492 1493

static nsresult
T
Taowei 已提交
1494
_networkAdapterAttachToNAT(INetworkAdapter *adapter)
T
Taowei 已提交
1495
{
T
Taowei 已提交
1496
    return adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_NAT);
T
Taowei 已提交
1497 1498
}

T
Taowei 已提交
1499
#endif /* VBOX_API_VERSION >= 4001000 */
T
Taowei 已提交
1500

T
Taowei 已提交
1501 1502 1503 1504 1505 1506
static nsresult
_serialPortGetEnabled(ISerialPort *port, PRBool *enabled)
{
    return port->vtbl->GetEnabled(port, enabled);
}

T
Taowei 已提交
1507
static nsresult
T
Taowei 已提交
1508
_serialPortSetEnabled(ISerialPort *port, PRBool enabled)
T
Taowei 已提交
1509
{
T
Taowei 已提交
1510
    return port->vtbl->SetEnabled(port, enabled);
T
Taowei 已提交
1511 1512
}

T
Taowei 已提交
1513 1514 1515 1516 1517 1518
static nsresult
_serialPortGetPath(ISerialPort *port, PRUnichar **path)
{
    return port->vtbl->GetPath(port, path);
}

T
Taowei 已提交
1519
static nsresult
T
Taowei 已提交
1520
_serialPortSetPath(ISerialPort *port, PRUnichar *path)
T
Taowei 已提交
1521
{
T
Taowei 已提交
1522
    return port->vtbl->SetPath(port, path);
T
Taowei 已提交
1523 1524
}

T
Taowei 已提交
1525 1526 1527 1528 1529 1530
static nsresult
_serialPortGetIRQ(ISerialPort *port, PRUint32 *IRQ)
{
    return port->vtbl->GetIRQ(port, IRQ);
}

T
Taowei 已提交
1531
static nsresult
T
Taowei 已提交
1532
_serialPortSetIRQ(ISerialPort *port, PRUint32 IRQ)
T
Taowei 已提交
1533
{
T
Taowei 已提交
1534
    return port->vtbl->SetIRQ(port, IRQ);
T
Taowei 已提交
1535 1536
}

T
Taowei 已提交
1537 1538 1539 1540 1541 1542
static nsresult
_serialPortGetIOBase(ISerialPort *port, PRUint32 *IOBase)
{
    return port->vtbl->GetIOBase(port, IOBase);
}

T
Taowei 已提交
1543
static nsresult
T
Taowei 已提交
1544
_serialPortSetIOBase(ISerialPort *port, PRUint32 IOBase)
T
Taowei 已提交
1545
{
T
Taowei 已提交
1546
    return port->vtbl->SetIOBase(port, IOBase);
T
Taowei 已提交
1547 1548
}

T
Taowei 已提交
1549 1550 1551 1552 1553 1554
static nsresult
_serialPortGetHostMode(ISerialPort *port, PRUint32 *hostMode)
{
    return port->vtbl->GetHostMode(port, hostMode);
}

T
Taowei 已提交
1555
static nsresult
T
Taowei 已提交
1556
_serialPortSetHostMode(ISerialPort *port, PRUint32 hostMode)
T
Taowei 已提交
1557
{
T
Taowei 已提交
1558
    return port->vtbl->SetHostMode(port, hostMode);
T
Taowei 已提交
1559 1560
}

T
Taowei 已提交
1561 1562 1563 1564 1565 1566
static nsresult
_parallelPortGetEnabled(IParallelPort *port, PRBool *enabled)
{
    return port->vtbl->GetEnabled(port, enabled);
}

T
Taowei 已提交
1567
static nsresult
T
Taowei 已提交
1568
_parallelPortSetEnabled(IParallelPort *port, PRBool enabled)
T
Taowei 已提交
1569
{
T
Taowei 已提交
1570
    return port->vtbl->SetEnabled(port, enabled);
T
Taowei 已提交
1571 1572
}

T
Taowei 已提交
1573 1574 1575 1576 1577 1578
static nsresult
_parallelPortGetPath(IParallelPort *port, PRUnichar **path)
{
    return port->vtbl->GetPath(port, path);
}

T
Taowei 已提交
1579
static nsresult
T
Taowei 已提交
1580
_parallelPortSetPath(IParallelPort *port, PRUnichar *path)
T
Taowei 已提交
1581
{
T
Taowei 已提交
1582
    return port->vtbl->SetPath(port, path);
T
Taowei 已提交
1583 1584
}

T
Taowei 已提交
1585 1586 1587 1588 1589 1590
static nsresult
_parallelPortGetIRQ(IParallelPort *port, PRUint32 *IRQ)
{
    return port->vtbl->GetIRQ(port, IRQ);
}

T
Taowei 已提交
1591
static nsresult
T
Taowei 已提交
1592
_parallelPortSetIRQ(IParallelPort *port, PRUint32 IRQ)
T
Taowei 已提交
1593
{
T
Taowei 已提交
1594
    return port->vtbl->SetIRQ(port, IRQ);
T
Taowei 已提交
1595 1596
}

T
Taowei 已提交
1597 1598 1599 1600 1601 1602
static nsresult
_parallelPortGetIOBase(IParallelPort *port, PRUint32 *IOBase)
{
    return port->vtbl->GetIOBase(port, IOBase);
}

T
Taowei 已提交
1603
static nsresult
T
Taowei 已提交
1604
_parallelPortSetIOBase(IParallelPort *port, PRUint32 IOBase)
T
Taowei 已提交
1605
{
T
Taowei 已提交
1606
    return port->vtbl->SetIOBase(port, IOBase);
T
Taowei 已提交
1607 1608
}

T
Taowei 已提交
1609
static nsresult
1610
_vrdeServerGetEnabled(IVRDEServer *VRDEServer, PRBool *enabled)
T
Taowei 已提交
1611
{
1612
    return VRDEServer->vtbl->GetEnabled(VRDEServer, enabled);
T
Taowei 已提交
1613 1614
}

T
Taowei 已提交
1615
static nsresult
1616
_vrdeServerSetEnabled(IVRDEServer *VRDEServer, PRBool enabled)
T
Taowei 已提交
1617
{
1618
    return VRDEServer->vtbl->SetEnabled(VRDEServer, enabled);
T
Taowei 已提交
1619
}
T
Taowei 已提交
1620

T
Taowei 已提交
1621
static nsresult
1622 1623
_vrdeServerGetPorts(vboxDriverPtr data, IVRDEServer *VRDEServer,
                    IMachine *machine, virDomainGraphicsDefPtr graphics)
T
Taowei 已提交
1624 1625 1626 1627
{
    nsresult rc;
    PRUnichar *VRDEPortsKey = NULL;
    PRUnichar *VRDEPortsValue = NULL;
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
    PRInt32 port = -1;
    ssize_t nmatches = 0;
    char **matches = NULL;
    char *portUtf8 = NULL;

    /* get active (effective) port - available only when VM is running and has
     * the VBOX extensions installed (without extenstions RDP server
     * functionality is disabled)
     */
    port = vboxGetActiveVRDEServerPort(data->vboxSession, machine);
1638

1639 1640 1641 1642 1643 1644
    if (port > 0)
        graphics->data.rdp.port = port;

    /* get the port (or port range) set in VM properties, this info will
     * be used to determine whether to set autoport flag
     */
T
Taowei 已提交
1645
    VBOX_UTF8_TO_UTF16("TCP/Ports", &VRDEPortsKey);
1646 1647 1648 1649 1650 1651 1652 1653
    rc = VRDEServer->vtbl->GetVRDEProperty(VRDEServer, VRDEPortsKey,
                                           &VRDEPortsValue);

    if (NS_FAILED(rc)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Failed to read RDP port value, rc=%08x"),
                       (unsigned) rc);
       goto cleanup;
T
Taowei 已提交
1654
    }
1655

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
    VBOX_UTF16_TO_UTF8(VRDEPortsValue, &portUtf8);

    if (portUtf8) {
        /* does the string contain digits only */
        nmatches = virStringSearch(portUtf8, "(^[[:digit:]]+$)", 1, &matches);

        /* the port property is not numeric, then it must be a port range or
         * port list or combination of the two, either way it's an autoport
         */
        if (nmatches != 1)
            graphics->data.rdp.autoport = true;

        /* no active port available, e.g. VM is powered off, try to get it from
         * the property string
         */
        if (port < 0) {
            if (nmatches == 1 && virStrToLong_i(portUtf8, NULL, 10, &port) == 0)
                graphics->data.rdp.port = port;
        }
    }

 cleanup:
    virStringListFree(matches);
    VBOX_UTF8_FREE(portUtf8);
    VBOX_UTF16_FREE(VRDEPortsValue);
    VBOX_UTF16_FREE(VRDEPortsKey);

T
Taowei 已提交
1683 1684 1685
    return rc;
}

T
Taowei 已提交
1686
static nsresult
1687 1688
_vrdeServerSetPorts(vboxDriverPtr data, IVRDEServer *VRDEServer,
                    virDomainGraphicsDefPtr graphics)
T
Taowei 已提交
1689
{
T
Taowei 已提交
1690 1691 1692
    nsresult rc = 0;
    PRUnichar *VRDEPortsKey = NULL;
    PRUnichar *VRDEPortsValue = NULL;
1693

T
Taowei 已提交
1694
    VBOX_UTF8_TO_UTF16("TCP/Ports", &VRDEPortsKey);
1695 1696 1697 1698 1699 1700 1701

    if (graphics->data.rdp.autoport)
        VBOX_UTF8_TO_UTF16(VBOX_RDP_AUTOPORT_RANGE, &VRDEPortsValue);
    else
        VRDEPortsValue = PRUnicharFromInt(data->pFuncs,
                                          graphics->data.rdp.port);

1702
    rc = VRDEServer->vtbl->SetVRDEProperty(VRDEServer, VRDEPortsKey,
T
Taowei 已提交
1703 1704 1705
                                           VRDEPortsValue);
    VBOX_UTF16_FREE(VRDEPortsKey);
    VBOX_UTF16_FREE(VRDEPortsValue);
1706

T
Taowei 已提交
1707
    return rc;
T
Taowei 已提交
1708 1709
}

T
Taowei 已提交
1710
static nsresult
1711
_vrdeServerGetReuseSingleConnection(IVRDEServer *VRDEServer, PRBool *enabled)
T
Taowei 已提交
1712
{
1713
    return VRDEServer->vtbl->GetReuseSingleConnection(VRDEServer, enabled);
T
Taowei 已提交
1714 1715
}

T
Taowei 已提交
1716
static nsresult
1717
_vrdeServerSetReuseSingleConnection(IVRDEServer *VRDEServer, PRBool enabled)
T
Taowei 已提交
1718
{
1719
    return VRDEServer->vtbl->SetReuseSingleConnection(VRDEServer, enabled);
T
Taowei 已提交
1720 1721
}

T
Taowei 已提交
1722
static nsresult
1723
_vrdeServerGetAllowMultiConnection(IVRDEServer *VRDEServer, PRBool *enabled)
T
Taowei 已提交
1724
{
1725
    return VRDEServer->vtbl->GetAllowMultiConnection(VRDEServer, enabled);
T
Taowei 已提交
1726 1727
}

T
Taowei 已提交
1728
static nsresult
1729
_vrdeServerSetAllowMultiConnection(IVRDEServer *VRDEServer, PRBool enabled)
T
Taowei 已提交
1730
{
1731
    return VRDEServer->vtbl->SetAllowMultiConnection(VRDEServer, enabled);
T
Taowei 已提交
1732 1733
}

T
Taowei 已提交
1734
static nsresult
1735 1736
_vrdeServerGetNetAddress(vboxDriverPtr data ATTRIBUTE_UNUSED,
                         IVRDEServer *VRDEServer, PRUnichar **netAddress)
T
Taowei 已提交
1737 1738 1739
{
    PRUnichar *VRDENetAddressKey = NULL;
    nsresult rc;
1740

T
Taowei 已提交
1741
    VBOX_UTF8_TO_UTF16("TCP/Address", &VRDENetAddressKey);
1742
    rc = VRDEServer->vtbl->GetVRDEProperty(VRDEServer, VRDENetAddressKey, netAddress);
T
Taowei 已提交
1743
    VBOX_UTF16_FREE(VRDENetAddressKey);
1744

T
Taowei 已提交
1745 1746 1747
    return rc;
}

T
Taowei 已提交
1748
static nsresult
1749 1750
_vrdeServerSetNetAddress(vboxDriverPtr data ATTRIBUTE_UNUSED,
                         IVRDEServer *VRDEServer, PRUnichar *netAddress)
T
Taowei 已提交
1751 1752 1753
{
    PRUnichar *netAddressKey = NULL;
    nsresult rc;
1754

T
Taowei 已提交
1755
    VBOX_UTF8_TO_UTF16("TCP/Address", &netAddressKey);
1756
    rc = VRDEServer->vtbl->SetVRDEProperty(VRDEServer, netAddressKey,
T
Taowei 已提交
1757 1758
                                           netAddress);
    VBOX_UTF16_FREE(netAddressKey);
1759

T
Taowei 已提交
1760 1761
    return rc;
}
T
Taowei 已提交
1762 1763

static nsresult
T
Taowei 已提交
1764
_usbCommonEnable(IUSBCommon *USBCommon ATTRIBUTE_UNUSED)
T
Taowei 已提交
1765
{
T
Taowei 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
    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 已提交
1777 1778
}

T
Taowei 已提交
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
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 已提交
1790
static nsresult
T
Taowei 已提交
1791 1792
_usbCommonCreateDeviceFilter(IUSBCommon *USBCommon, PRUnichar *name,
                             IUSBDeviceFilter **filter)
T
Taowei 已提交
1793
{
T
Taowei 已提交
1794
    return USBCommon->vtbl->CreateDeviceFilter(USBCommon, name, filter);
T
Taowei 已提交
1795 1796
}

T
Taowei 已提交
1797
static nsresult
T
Taowei 已提交
1798 1799
_usbCommonInsertDeviceFilter(IUSBCommon *USBCommon, PRUint32 position,
                             IUSBDeviceFilter *filter)
T
Taowei 已提交
1800
{
T
Taowei 已提交
1801
    return USBCommon->vtbl->InsertDeviceFilter(USBCommon, position, filter);
T
Taowei 已提交
1802 1803
}

T
Taowei 已提交
1804 1805 1806 1807 1808 1809
static nsresult
_usbDeviceFilterGetProductId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **productId)
{
    return USBDeviceFilter->vtbl->GetProductId(USBDeviceFilter, productId);
}

T
Taowei 已提交
1810
static nsresult
T
Taowei 已提交
1811
_usbDeviceFilterSetProductId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *productId)
T
Taowei 已提交
1812
{
T
Taowei 已提交
1813
    return USBDeviceFilter->vtbl->SetProductId(USBDeviceFilter, productId);
T
Taowei 已提交
1814 1815
}

T
Taowei 已提交
1816 1817 1818 1819 1820 1821
static nsresult
_usbDeviceFilterGetActive(IUSBDeviceFilter *USBDeviceFilter, PRBool *active)
{
    return USBDeviceFilter->vtbl->GetActive(USBDeviceFilter, active);
}

T
Taowei 已提交
1822
static nsresult
T
Taowei 已提交
1823
_usbDeviceFilterSetActive(IUSBDeviceFilter *USBDeviceFilter, PRBool active)
T
Taowei 已提交
1824
{
T
Taowei 已提交
1825
    return USBDeviceFilter->vtbl->SetActive(USBDeviceFilter, active);
T
Taowei 已提交
1826 1827
}

T
Taowei 已提交
1828 1829 1830 1831 1832 1833
static nsresult
_usbDeviceFilterGetVendorId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar **vendorId)
{
    return USBDeviceFilter->vtbl->GetVendorId(USBDeviceFilter, vendorId);
}

T
Taowei 已提交
1834
static nsresult
T
Taowei 已提交
1835
_usbDeviceFilterSetVendorId(IUSBDeviceFilter *USBDeviceFilter, PRUnichar *vendorId)
T
Taowei 已提交
1836
{
T
Taowei 已提交
1837 1838 1839
    return USBDeviceFilter->vtbl->SetVendorId(USBDeviceFilter, vendorId);
}

1840
static nsresult _mediumGetId(IMedium *medium, vboxIID *iid)
T
Taowei 已提交
1841
{
1842
    return medium->vtbl->GetId(medium, &iid->value);
T
Taowei 已提交
1843 1844
}

T
Taowei 已提交
1845 1846 1847 1848 1849
static nsresult _mediumGetLocation(IMedium *medium, PRUnichar **location)
{
    return medium->vtbl->GetLocation(medium, location);
}

1850 1851 1852 1853 1854
static nsresult _mediumGetState(IMedium *medium, PRUint32 *state)
{
    return medium->vtbl->GetState(medium, state);
}

1855 1856 1857 1858 1859
static nsresult _mediumGetName(IMedium *medium, PRUnichar **name)
{
    return medium->vtbl->GetName(medium, name);
}

T
Taowei Luo 已提交
1860 1861 1862 1863
static nsresult _mediumGetSize(IMedium *medium, PRUint64 *uSize)
{
    nsresult rc;
    PRInt64 Size;
1864

T
Taowei Luo 已提交
1865 1866
    rc = medium->vtbl->GetSize(medium, &Size);
    *uSize = Size;
1867

T
Taowei Luo 已提交
1868 1869 1870
    return rc;
}

T
Taowei 已提交
1871 1872 1873 1874
static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED,
                                   PRBool *readOnly ATTRIBUTE_UNUSED)
{
    return medium->vtbl->GetReadOnly(medium, readOnly);
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
}

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);
}

T
Taowei 已提交
1902 1903 1904 1905
static nsresult _mediumRelease(IMedium *medium)
{
    return medium->vtbl->nsisupports.Release((nsISupports *)medium);
}
1906 1907 1908 1909
static nsresult _mediumClose(IMedium *medium)
{
    return medium->vtbl->Close(medium);
}
T
Taowei 已提交
1910 1911 1912 1913 1914

static nsresult _mediumSetType(IMedium *medium ATTRIBUTE_UNUSED,
                               PRUint32 type ATTRIBUTE_UNUSED)
{
    return medium->vtbl->SetType(medium, type);
T
Taowei 已提交
1915 1916
}

1917 1918 1919 1920 1921 1922 1923
static nsresult
_mediumCreateDiffStorage(IMedium *medium ATTRIBUTE_UNUSED,
                         IMedium *target ATTRIBUTE_UNUSED,
                         PRUint32 variantSize ATTRIBUTE_UNUSED,
                         PRUint32 *variant ATTRIBUTE_UNUSED,
                         IProgress **progress ATTRIBUTE_UNUSED)
{
1924
#if VBOX_API_VERSION < 4003000
1925 1926 1927
    if (variantSize == 0)
        return 0;
    if (variantSize > 1)
1928
        VIR_WARN("Only one variant is available in current version");
1929 1930 1931 1932 1933 1934
    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 */
}

1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
static nsresult
_mediumCreateBaseStorage(IMedium *medium, PRUint64 logicalSize,
                           PRUint32 variant, IProgress **progress)
{
#if VBOX_API_VERSION < 4003000
    return medium->vtbl->CreateBaseStorage(medium, logicalSize, variant, progress);
#else
    return medium->vtbl->CreateBaseStorage(medium, logicalSize, 1, &variant, progress);
#endif
}

static nsresult
_mediumGetLogicalSize(IMedium *medium, PRUint64 *uLogicalSize)
{
    nsresult rc;
    PRInt64 logicalSize;

    rc = medium->vtbl->GetLogicalSize(medium, &logicalSize);
    *uLogicalSize = logicalSize;

    return rc;
}

T
Taowei 已提交
1958
static nsresult
1959
_mediumAttachmentGetMedium(IMediumAttachment *mediumAttachment,
1960
                           IMedium **medium)
T
Taowei 已提交
1961
{
1962
    return mediumAttachment->vtbl->GetMedium(mediumAttachment, medium);
T
Taowei 已提交
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
}

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

static nsresult
_mediumAttachmentGetType(IMediumAttachment *mediumAttachment ATTRIBUTE_UNUSED,
                         PRUint32 *type ATTRIBUTE_UNUSED)
{
    return mediumAttachment->vtbl->GetType(mediumAttachment, type);
}

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);
}

1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
static nsresult
_storageControllerGetControllerType(IStorageController *storageController, PRUint32 *controllerType)
{
    return storageController->vtbl->GetControllerType(storageController, controllerType);
}

static nsresult
_storageControllerSetControllerType(IStorageController *storageController, PRUint32 controllerType)
{
    return storageController->vtbl->SetControllerType(storageController, controllerType);
}

T
Taowei 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
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);
}

2027 2028 2029 2030 2031 2032 2033
static nsresult
_snapshotGetName(ISnapshot *snapshot, PRUnichar **name)
{
    return snapshot->vtbl->GetName(snapshot, name);
}

static nsresult
2034
_snapshotGetId(ISnapshot *snapshot, vboxIID *iid)
2035
{
2036
    return snapshot->vtbl->GetId(snapshot, &iid->value);
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068
}

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 已提交
2069 2070 2071 2072 2073 2074 2075 2076 2077
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)
{
2078
#if VBOX_API_VERSION < 4003000
T
Taowei 已提交
2079 2080
    return display->vtbl->GetScreenResolution(display, screenId, width,
                                              height, bitsPerPixel);
M
Martin Pietsch 已提交
2081
#elif VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION >= 4003000 */
T
Taowei 已提交
2082 2083 2084
    return display->vtbl->GetScreenResolution(display, screenId, width,
                                              height, bitsPerPixel,
                                              xOrigin, yOrigin);
M
Martin Pietsch 已提交
2085 2086 2087 2088 2089 2090 2091
#else /*VBOX_API_VERSION >= 5000000 */
    PRUint32 gms;

    return display->vtbl->GetScreenResolution(display, screenId, width,
                                              height, bitsPerPixel,
                                              xOrigin, yOrigin, &gms);
#endif /* VBOX_API_VERSION >= 5000000 */
T
Taowei 已提交
2092 2093 2094
}

static nsresult
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
_displayTakeScreenShotPNGToArray(IDisplay *display, PRUint32 screenId,
                                 PRUint32 width, PRUint32 height,
                                 PRUint32 *screenDataSize,
                                 PRUint8** screenData)
{
#if VBOX_API_VERSION >= 5000000
    return display->vtbl->TakeScreenShotToArray(display, screenId, width,
                                                height, BitmapFormat_PNG,
                                                screenDataSize, screenData);
#else /* VBOX_API_VERSION < 5000000 */
T
Taowei 已提交
2105 2106 2107
    return display->vtbl->TakeScreenShotPNGToArray(display, screenId, width,
                                                   height, screenDataSize,
                                                   screenData);
2108
#endif /* VBOX_API_VERSION >= 5000000 */
T
Taowei 已提交
2109 2110
}

T
Taowei 已提交
2111
static nsresult
2112
_hostFindHostNetworkInterfaceById(IHost *host, vboxIID *iid,
T
Taowei 已提交
2113 2114
                                  IHostNetworkInterface **networkInterface)
{
2115
    return host->vtbl->FindHostNetworkInterfaceById(host, iid->value,
T
Taowei 已提交
2116 2117 2118
                                                    networkInterface);
}

T
Taowei 已提交
2119 2120 2121 2122 2123 2124 2125 2126
static nsresult
_hostFindHostNetworkInterfaceByName(IHost *host, PRUnichar *name,
                                    IHostNetworkInterface **networkInterface)
{
    return host->vtbl->FindHostNetworkInterfaceByName(host, name,
                                                      networkInterface);
}

T
Taowei 已提交
2127
static nsresult
2128
_hostCreateHostOnlyNetworkInterface(vboxDriverPtr data ATTRIBUTE_UNUSED,
T
Taowei 已提交
2129 2130 2131 2132 2133
                                    IHost *host, char *name ATTRIBUTE_UNUSED,
                                    IHostNetworkInterface **networkInterface)
{
    nsresult rc = -1;
    IProgress *progress = NULL;
2134

T
Taowei 已提交
2135 2136 2137 2138 2139 2140 2141
    host->vtbl->CreateHostOnlyNetworkInterface(host, networkInterface,
                                               &progress);

    if (progress) {
        rc = progress->vtbl->WaitForCompletion(progress, -1);
        VBOX_RELEASE(progress);
    }
2142

T
Taowei 已提交
2143 2144 2145
    return rc;
}

T
Taowei 已提交
2146 2147
static nsresult
_hostRemoveHostOnlyNetworkInterface(IHost *host ATTRIBUTE_UNUSED,
2148
                                    vboxIID *iid ATTRIBUTE_UNUSED,
T
Taowei 已提交
2149 2150
                                    IProgress **progress ATTRIBUTE_UNUSED)
{
2151
    return host->vtbl->RemoveHostOnlyNetworkInterface(host, iid->value, progress);
T
Taowei 已提交
2152 2153
}

T
Taowei 已提交
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165
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 已提交
2166 2167 2168 2169 2170 2171
static nsresult
_hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name)
{
    return hni->vtbl->GetName(hni, name);
}

T
Taowei 已提交
2172
static nsresult
2173
_hnInterfaceGetId(IHostNetworkInterface *hni, vboxIID *iid)
T
Taowei 已提交
2174
{
2175
    return hni->vtbl->GetId(hni, &iid->value);
T
Taowei 已提交
2176 2177
}

T
Taowei 已提交
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
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 已提交
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
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 已提交
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250
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 已提交
2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
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 已提交
2275 2276 2277 2278 2279 2280
static nsresult
_dhcpServerStop(IDHCPServer *dhcpServer)
{
    return dhcpServer->vtbl->Stop(dhcpServer);
}

2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
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 已提交
2295 2296 2297 2298 2299 2300
static bool _machineStateOnline(PRUint32 state)
{
    return ((state >= MachineState_FirstOnline) &&
            (state <= MachineState_LastOnline));
}

2301 2302
static bool _machineStateInactive(PRUint32 state)
{
2303 2304
    return ((state < MachineState_FirstOnline) ||
            (state > MachineState_LastOnline));
2305 2306
}

T
Taowei 已提交
2307 2308 2309 2310 2311 2312 2313
static bool _machineStateNotStart(PRUint32 state)
{
    return ((state == MachineState_PoweredOff) ||
            (state == MachineState_Saved) ||
            (state == MachineState_Aborted));
}

T
Taowei 已提交
2314 2315 2316 2317 2318
static bool _machineStateRunning(PRUint32 state)
{
    return state == MachineState_Running;
}

T
Taowei 已提交
2319 2320 2321 2322 2323
static bool _machineStatePaused(PRUint32 state)
{
    return state == MachineState_Paused;
}

T
Taowei 已提交
2324 2325 2326 2327 2328
static bool _machineStatePoweredOff(PRUint32 state)
{
    return state == MachineState_PoweredOff;
}

T
Taowei 已提交
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338
static vboxUniformedPFN _UPFN = {
    .Initialize = _pfnInitialize,
    .Uninitialize = _pfnUninitialize,
    .ComUnallocMem = _pfnComUnallocMem,
    .Utf16Free = _pfnUtf16Free,
    .Utf8Free = _pfnUtf8Free,
    .Utf16ToUtf8 = _pfnUtf16ToUtf8,
    .Utf8ToUtf16 = _pfnUtf8ToUtf16,
};

T
Taowei 已提交
2339 2340 2341 2342 2343 2344 2345
static vboxUniformedIID _UIID = {
    .vboxIIDInitialize = _vboxIIDInitialize,
    .vboxIIDUnalloc = _vboxIIDUnalloc,
    .vboxIIDToUUID = _vboxIIDToUUID,
    .vboxIIDFromUUID = _vboxIIDFromUUID,
    .vboxIIDIsEqual = _vboxIIDIsEqual,
    .vboxIIDFromArrayItem = _vboxIIDFromArrayItem,
2346
    .vboxIIDToUtf8 = _vboxIIDToUtf8,
T
Taowei 已提交
2347 2348 2349
    .DEBUGIID = _DEBUGIID,
};

T
Taowei 已提交
2350 2351
static vboxUniformedArray _UArray = {
    .vboxArrayGet = vboxArrayGet,
2352
    .vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg,
T
Taowei 已提交
2353
    .vboxArrayRelease = vboxArrayRelease,
T
Taowei Luo 已提交
2354
    .vboxArrayUnalloc = vboxArrayUnalloc,
T
Taowei 已提交
2355
    .handleGetMachines = _handleGetMachines,
2356
    .handleGetHardDisks = _handleGetHardDisks,
T
Taowei 已提交
2357
    .handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters,
2358
    .handleMachineGetStorageControllers = _handleMachineGetStorageControllers,
T
Taowei 已提交
2359 2360
    .handleMachineGetMediumAttachments = _handleMachineGetMediumAttachments,
    .handleMachineGetSharedFolders = _handleMachineGetSharedFolders,
2361 2362 2363
    .handleSnapshotGetChildren = _handleSnapshotGetChildren,
    .handleMediumGetChildren = _handleMediumGetChildren,
    .handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds,
T
Taowei Luo 已提交
2364
    .handleMediumGetMachineIds = _handleMediumGetMachineIds,
T
Taowei 已提交
2365
    .handleHostGetNetworkInterfaces = _handleHostGetNetworkInterfaces,
T
Taowei 已提交
2366 2367
};

T
Taowei 已提交
2368 2369
static vboxUniformednsISupports _nsUISupports = {
    .Release = _nsisupportsRelease,
2370
    .AddRef = _nsisupportsAddRef,
T
Taowei 已提交
2371 2372
};

T
Taowei 已提交
2373 2374
static vboxUniformedIVirtualBox _UIVirtualBox = {
    .GetVersion = _virtualboxGetVersion,
T
Taowei 已提交
2375
    .GetMachine = _virtualboxGetMachine,
2376
    .OpenMachine = _virtualboxOpenMachine,
T
Taowei 已提交
2377
    .GetSystemProperties = _virtualboxGetSystemProperties,
T
Taowei 已提交
2378
    .GetHost = _virtualboxGetHost,
T
Taowei 已提交
2379
    .CreateMachine = _virtualboxCreateMachine,
2380
    .CreateHardDisk = _virtualboxCreateHardDisk,
T
Taowei 已提交
2381
    .RegisterMachine = _virtualboxRegisterMachine,
2382
    .FindHardDisk = _virtualboxFindHardDisk,
T
Taowei 已提交
2383
    .OpenMedium = _virtualboxOpenMedium,
2384
    .GetHardDiskByIID = _virtualboxGetHardDiskByIID,
T
Taowei 已提交
2385 2386
    .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
    .CreateDHCPServer = _virtualboxCreateDHCPServer,
T
Taowei 已提交
2387
    .RemoveDHCPServer = _virtualboxRemoveDHCPServer,
T
Taowei 已提交
2388 2389
};

T
Taowei 已提交
2390
static vboxUniformedIMachine _UIMachine = {
T
Taowei 已提交
2391
    .AddStorageController = _machineAddStorageController,
T
Taowei 已提交
2392
    .GetStorageControllerByName = _machineGetStorageControllerByName,
T
Taowei 已提交
2393 2394
    .AttachDevice = _machineAttachDevice,
    .CreateSharedFolder = _machineCreateSharedFolder,
T
Taowei 已提交
2395
    .RemoveSharedFolder = _machineRemoveSharedFolder,
T
Taowei 已提交
2396
    .LaunchVMProcess = _machineLaunchVMProcess,
2397
    .Unregister = _machineUnregister,
2398
    .FindSnapshot = _machineFindSnapshot,
T
Taowei Luo 已提交
2399
    .DetachDevice = _machineDetachDevice,
T
Taowei 已提交
2400 2401
    .GetAccessible = _machineGetAccessible,
    .GetState = _machineGetState,
T
Taowei 已提交
2402 2403
    .GetName = _machineGetName,
    .GetId = _machineGetId,
T
Taowei 已提交
2404 2405 2406 2407 2408 2409
    .GetBIOSSettings = _machineGetBIOSSettings,
    .GetAudioAdapter = _machineGetAudioAdapter,
    .GetNetworkAdapter = _machineGetNetworkAdapter,
    .GetChipsetType = _machineGetChipsetType,
    .GetSerialPort = _machineGetSerialPort,
    .GetParallelPort = _machineGetParallelPort,
2410
    .GetVRDEServer = _machineGetVRDEServer,
T
Taowei 已提交
2411
    .GetUSBCommon = _machineGetUSBCommon,
2412 2413
    .GetCurrentSnapshot = _machineGetCurrentSnapshot,
    .GetSettingsFilePath = _machineGetSettingsFilePath,
T
Taowei 已提交
2414
    .GetCPUCount = _machineGetCPUCount,
T
Taowei 已提交
2415
    .SetCPUCount = _machineSetCPUCount,
T
Taowei 已提交
2416
    .GetMemorySize = _machineGetMemorySize,
T
Taowei 已提交
2417
    .SetMemorySize = _machineSetMemorySize,
T
Taowei 已提交
2418
    .GetCPUProperty = _machineGetCPUProperty,
T
Taowei 已提交
2419
    .SetCPUProperty = _machineSetCPUProperty,
T
Taowei 已提交
2420
    .GetBootOrder = _machineGetBootOrder,
T
Taowei 已提交
2421
    .SetBootOrder = _machineSetBootOrder,
T
Taowei 已提交
2422
    .GetVRAMSize = _machineGetVRAMSize,
T
Taowei 已提交
2423
    .SetVRAMSize = _machineSetVRAMSize,
T
Taowei 已提交
2424
    .GetMonitorCount = _machineGetMonitorCount,
T
Taowei 已提交
2425
    .SetMonitorCount = _machineSetMonitorCount,
T
Taowei 已提交
2426
    .GetAccelerate3DEnabled = _machineGetAccelerate3DEnabled,
T
Taowei 已提交
2427
    .SetAccelerate3DEnabled = _machineSetAccelerate3DEnabled,
T
Taowei 已提交
2428
    .GetAccelerate2DVideoEnabled = _machineGetAccelerate2DVideoEnabled,
T
Taowei 已提交
2429
    .SetAccelerate2DVideoEnabled = _machineSetAccelerate2DVideoEnabled,
T
Taowei 已提交
2430
    .GetExtraData = _machineGetExtraData,
T
Taowei 已提交
2431
    .SetExtraData = _machineSetExtraData,
2432
    .GetSnapshotCount = _machineGetSnapshotCount,
T
Taowei 已提交
2433
    .SaveSettings = _machineSaveSettings,
T
Taowei 已提交
2434 2435
};

T
Taowei 已提交
2436
static vboxUniformedISession _UISession = {
T
Taowei 已提交
2437
    .Open = _sessionOpen,
T
Taowei 已提交
2438 2439
    .OpenExisting = _sessionOpenExisting,
    .GetConsole = _sessionGetConsole,
T
Taowei 已提交
2440
    .GetMachine = _sessionGetMachine,
T
Taowei 已提交
2441 2442 2443 2444 2445
    .Close = _sessionClose,
};

static vboxUniformedIConsole _UIConsole = {
    .SaveState = _consoleSaveState,
T
Taowei 已提交
2446
    .Pause = _consolePause,
T
Taowei 已提交
2447
    .Resume = _consoleResume,
T
Taowei 已提交
2448
    .PowerButton = _consolePowerButton,
T
Taowei 已提交
2449
    .PowerDown = _consolePowerDown,
T
Taowei 已提交
2450
    .Reset = _consoleReset,
2451
    .TakeSnapshot = _consoleTakeSnapshot,
T
Taowei 已提交
2452
    .DeleteSnapshot = _consoleDeleteSnapshot,
T
Taowei 已提交
2453
    .GetDisplay = _consoleGetDisplay,
2454
    .GetKeyboard = _consoleGetKeyboard,
T
Taowei 已提交
2455 2456 2457 2458 2459
};

static vboxUniformedIProgress _UIProgress = {
    .WaitForCompletion = _progressWaitForCompletion,
    .GetResultCode = _progressGetResultCode,
T
Taowei 已提交
2460
    .GetCompleted = _progressGetCompleted,
T
Taowei 已提交
2461 2462
};

T
Taowei 已提交
2463 2464
static vboxUniformedISystemProperties _UISystemProperties = {
    .GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
T
Taowei 已提交
2465 2466 2467 2468 2469 2470
    .GetMaxBootPosition = _systemPropertiesGetMaxBootPosition,
    .GetMaxNetworkAdapters = _systemPropertiesGetMaxNetworkAdapters,
    .GetSerialPortCount = _systemPropertiesGetSerialPortCount,
    .GetParallelPortCount = _systemPropertiesGetParallelPortCount,
    .GetMaxPortCountForStorageBus = _systemPropertiesGetMaxPortCountForStorageBus,
    .GetMaxDevicesPerPortForStorageBus = _systemPropertiesGetMaxDevicesPerPortForStorageBus,
T
Taowei 已提交
2471
    .GetMaxGuestRAM = _systemPropertiesGetMaxGuestRAM,
T
Taowei 已提交
2472 2473 2474
};

static vboxUniformedIBIOSSettings _UIBIOSSettings = {
T
Taowei 已提交
2475
    .GetACPIEnabled = _biosSettingsGetACPIEnabled,
T
Taowei 已提交
2476
    .SetACPIEnabled = _biosSettingsSetACPIEnabled,
T
Taowei 已提交
2477
    .GetIOAPICEnabled = _biosSettingsGetIOAPICEnabled,
T
Taowei 已提交
2478 2479 2480 2481
    .SetIOAPICEnabled = _biosSettingsSetIOAPICEnabled,
};

static vboxUniformedIAudioAdapter _UIAudioAdapter = {
T
Taowei 已提交
2482
    .GetEnabled = _audioAdapterGetEnabled,
T
Taowei 已提交
2483
    .SetEnabled = _audioAdapterSetEnabled,
T
Taowei 已提交
2484
    .GetAudioController = _audioAdapterGetAudioController,
T
Taowei 已提交
2485 2486 2487 2488
    .SetAudioController = _audioAdapterSetAudioController,
};

static vboxUniformedINetworkAdapter _UINetworkAdapter = {
T
Taowei 已提交
2489 2490
    .GetAttachmentType = _networkAdapterGetAttachmentType,
    .GetEnabled = _networkAdapterGetEnabled,
T
Taowei 已提交
2491
    .SetEnabled = _networkAdapterSetEnabled,
T
Taowei 已提交
2492
    .GetAdapterType = _networkAdapterGetAdapterType,
T
Taowei 已提交
2493
    .SetAdapterType = _networkAdapterSetAdapterType,
T
Taowei 已提交
2494
    .GetBridgedInterface = _networkAdapterGetBridgedInterface,
T
Taowei 已提交
2495
    .SetBridgedInterface = _networkAdapterSetBridgedInterface,
T
Taowei 已提交
2496
    .GetInternalNetwork = _networkAdapterGetInternalNetwork,
T
Taowei 已提交
2497
    .SetInternalNetwork = _networkAdapterSetInternalNetwork,
T
Taowei 已提交
2498
    .GetHostOnlyInterface = _networkAdapterGetHostOnlyInterface,
T
Taowei 已提交
2499
    .SetHostOnlyInterface = _networkAdapterSetHostOnlyInterface,
T
Taowei 已提交
2500
    .GetMACAddress = _networkAdapterGetMACAddress,
T
Taowei 已提交
2501 2502 2503 2504 2505 2506 2507 2508
    .SetMACAddress = _networkAdapterSetMACAddress,
    .AttachToBridgedInterface = _networkAdapterAttachToBridgedInterface,
    .AttachToInternalNetwork = _networkAdapterAttachToInternalNetwork,
    .AttachToHostOnlyInterface = _networkAdapterAttachToHostOnlyInterface,
    .AttachToNAT = _networkAdapterAttachToNAT,
};

static vboxUniformedISerialPort _UISerialPort = {
T
Taowei 已提交
2509
    .GetEnabled = _serialPortGetEnabled,
T
Taowei 已提交
2510
    .SetEnabled = _serialPortSetEnabled,
T
Taowei 已提交
2511
    .GetPath = _serialPortGetPath,
T
Taowei 已提交
2512
    .SetPath = _serialPortSetPath,
T
Taowei 已提交
2513
    .GetIRQ = _serialPortGetIRQ,
T
Taowei 已提交
2514
    .SetIRQ = _serialPortSetIRQ,
T
Taowei 已提交
2515
    .GetIOBase = _serialPortGetIOBase,
T
Taowei 已提交
2516
    .SetIOBase = _serialPortSetIOBase,
T
Taowei 已提交
2517
    .GetHostMode = _serialPortGetHostMode,
T
Taowei 已提交
2518 2519 2520 2521
    .SetHostMode = _serialPortSetHostMode,
};

static vboxUniformedIParallelPort _UIParallelPort = {
T
Taowei 已提交
2522
    .GetEnabled = _parallelPortGetEnabled,
T
Taowei 已提交
2523
    .SetEnabled = _parallelPortSetEnabled,
T
Taowei 已提交
2524
    .GetPath = _parallelPortGetPath,
T
Taowei 已提交
2525
    .SetPath = _parallelPortSetPath,
T
Taowei 已提交
2526
    .GetIRQ = _parallelPortGetIRQ,
T
Taowei 已提交
2527
    .SetIRQ = _parallelPortSetIRQ,
T
Taowei 已提交
2528
    .GetIOBase = _parallelPortGetIOBase,
T
Taowei 已提交
2529 2530 2531
    .SetIOBase = _parallelPortSetIOBase,
};

2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
static vboxUniformedIVRDEServer _UIVRDEServer = {
    .GetEnabled = _vrdeServerGetEnabled,
    .SetEnabled = _vrdeServerSetEnabled,
    .GetPorts = _vrdeServerGetPorts,
    .SetPorts = _vrdeServerSetPorts,
    .GetReuseSingleConnection = _vrdeServerGetReuseSingleConnection,
    .SetReuseSingleConnection = _vrdeServerSetReuseSingleConnection,
    .GetAllowMultiConnection = _vrdeServerGetAllowMultiConnection,
    .SetAllowMultiConnection = _vrdeServerSetAllowMultiConnection,
    .GetNetAddress = _vrdeServerGetNetAddress,
    .SetNetAddress = _vrdeServerSetNetAddress,
T
Taowei 已提交
2543 2544 2545 2546
};

static vboxUniformedIUSBCommon _UIUSBCommon = {
    .Enable = _usbCommonEnable,
T
Taowei 已提交
2547
    .GetEnabled = _usbCommonGetEnabled,
T
Taowei 已提交
2548 2549 2550 2551 2552
    .CreateDeviceFilter = _usbCommonCreateDeviceFilter,
    .InsertDeviceFilter = _usbCommonInsertDeviceFilter,
};

static vboxUniformedIUSBDeviceFilter _UIUSBDeviceFilter = {
T
Taowei 已提交
2553
    .GetProductId = _usbDeviceFilterGetProductId,
T
Taowei 已提交
2554
    .SetProductId = _usbDeviceFilterSetProductId,
T
Taowei 已提交
2555
    .GetActive = _usbDeviceFilterGetActive,
T
Taowei 已提交
2556
    .SetActive = _usbDeviceFilterSetActive,
T
Taowei 已提交
2557
    .GetVendorId = _usbDeviceFilterGetVendorId,
T
Taowei 已提交
2558 2559 2560 2561 2562
    .SetVendorId = _usbDeviceFilterSetVendorId,
};

static vboxUniformedIMedium _UIMedium = {
    .GetId = _mediumGetId,
T
Taowei 已提交
2563
    .GetLocation = _mediumGetLocation,
2564
    .GetState = _mediumGetState,
2565
    .GetName = _mediumGetName,
T
Taowei Luo 已提交
2566
    .GetSize = _mediumGetSize,
T
Taowei 已提交
2567
    .GetReadOnly = _mediumGetReadOnly,
2568 2569 2570 2571
    .GetParent = _mediumGetParent,
    .GetChildren = _mediumGetChildren,
    .GetFormat = _mediumGetFormat,
    .DeleteStorage = _mediumDeleteStorage,
T
Taowei 已提交
2572
    .Release = _mediumRelease,
2573
    .Close = _mediumClose,
T
Taowei 已提交
2574
    .SetType = _mediumSetType,
2575
    .CreateDiffStorage = _mediumCreateDiffStorage,
2576 2577
    .CreateBaseStorage = _mediumCreateBaseStorage,
    .GetLogicalSize = _mediumGetLogicalSize,
T
Taowei 已提交
2578 2579
};

T
Taowei 已提交
2580 2581 2582 2583 2584 2585 2586 2587 2588 2589
static vboxUniformedIMediumAttachment _UIMediumAttachment = {
    .GetMedium = _mediumAttachmentGetMedium,
    .GetController = _mediumAttachmentGetController,
    .GetType = _mediumAttachmentGetType,
    .GetPort = _mediumAttachmentGetPort,
    .GetDevice = _mediumAttachmentGetDevice,
};

static vboxUniformedIStorageController _UIStorageController = {
    .GetBus = _storageControllerGetBus,
2590 2591
    .GetControllerType = _storageControllerGetControllerType,
    .SetControllerType = _storageControllerSetControllerType,
T
Taowei 已提交
2592 2593 2594 2595 2596 2597 2598 2599
};

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

2600 2601 2602 2603 2604 2605 2606 2607 2608 2609
static vboxUniformedISnapshot _UISnapshot = {
    .GetName = _snapshotGetName,
    .GetId = _snapshotGetId,
    .GetMachine = _snapshotGetMachine,
    .GetDescription = _snapshotGetDescription,
    .GetTimeStamp = _snapshotGetTimeStamp,
    .GetParent = _snapshotGetParent,
    .GetOnline = _snapshotGetOnline,
};

T
Taowei 已提交
2610 2611 2612 2613 2614
static vboxUniformedIDisplay _UIDisplay = {
    .GetScreenResolution = _displayGetScreenResolution,
    .TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray,
};

T
Taowei 已提交
2615 2616
static vboxUniformedIHost _UIHost = {
    .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById,
T
Taowei 已提交
2617
    .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName,
T
Taowei 已提交
2618
    .CreateHostOnlyNetworkInterface = _hostCreateHostOnlyNetworkInterface,
T
Taowei 已提交
2619
    .RemoveHostOnlyNetworkInterface = _hostRemoveHostOnlyNetworkInterface,
T
Taowei 已提交
2620 2621
};

T
Taowei 已提交
2622 2623 2624
static vboxUniformedIHNInterface _UIHNInterface = {
    .GetInterfaceType = _hnInterfaceGetInterfaceType,
    .GetStatus = _hnInterfaceGetStatus,
T
Taowei 已提交
2625
    .GetName = _hnInterfaceGetName,
T
Taowei 已提交
2626
    .GetId = _hnInterfaceGetId,
T
Taowei 已提交
2627 2628 2629
    .GetHardwareAddress = _hnInterfaceGetHardwareAddress,
    .GetIPAddress = _hnInterfaceGetIPAddress,
    .GetNetworkMask = _hnInterfaceGetNetworkMask,
T
Taowei 已提交
2630 2631 2632 2633 2634 2635
    .EnableStaticIPConfig = _hnInterfaceEnableStaticIPConfig,
    .EnableDynamicIPConfig = _hnInterfaceEnableDynamicIPConfig,
    .DHCPRediscover = _hnInterfaceDHCPRediscover,
};

static vboxUniformedIDHCPServer _UIDHCPServer = {
T
Taowei 已提交
2636 2637 2638 2639
    .GetIPAddress = _dhcpServerGetIPAddress,
    .GetNetworkMask = _dhcpServerGetNetworkMask,
    .GetLowerIP = _dhcpServerGetLowerIP,
    .GetUpperIP = _dhcpServerGetUpperIP,
T
Taowei 已提交
2640 2641 2642
    .SetEnabled = _dhcpServerSetEnabled,
    .SetConfiguration = _dhcpServerSetConfiguration,
    .Start = _dhcpServerStart,
T
Taowei 已提交
2643
    .Stop = _dhcpServerStop,
T
Taowei 已提交
2644 2645
};

2646 2647 2648 2649 2650
static vboxUniformedIKeyboard _UIKeyboard = {
    .PutScancode = _keyboardPutScancode,
    .PutScancodes = _keyboardPutScancodes,
};

T
Taowei 已提交
2651 2652
static uniformedMachineStateChecker _machineStateChecker = {
    .Online = _machineStateOnline,
2653
    .Inactive = _machineStateInactive,
T
Taowei 已提交
2654
    .NotStart = _machineStateNotStart,
T
Taowei 已提交
2655
    .Running = _machineStateRunning,
T
Taowei 已提交
2656
    .Paused = _machineStatePaused,
T
Taowei 已提交
2657
    .PoweredOff = _machineStatePoweredOff,
T
Taowei 已提交
2658 2659
};

T
Taowei 已提交
2660 2661 2662 2663
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
{
    pVBoxAPI->APIVersion = VBOX_API_VERSION;
    pVBoxAPI->XPCOMCVersion = VBOX_XPCOMC_VERSION;
T
Taowei 已提交
2664 2665
    pVBoxAPI->unregisterMachine = _unregisterMachine;
    pVBoxAPI->deleteConfig = _deleteConfig;
T
Taowei 已提交
2666
    pVBoxAPI->vboxConvertState = _vboxConvertState;
2667
    pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
T
Taowei 已提交
2668
    pVBoxAPI->UPFN = _UPFN;
T
Taowei 已提交
2669
    pVBoxAPI->UIID = _UIID;
T
Taowei 已提交
2670
    pVBoxAPI->UArray = _UArray;
T
Taowei 已提交
2671
    pVBoxAPI->nsUISupports = _nsUISupports;
T
Taowei 已提交
2672
    pVBoxAPI->UIVirtualBox = _UIVirtualBox;
T
Taowei 已提交
2673
    pVBoxAPI->UIMachine = _UIMachine;
T
Taowei 已提交
2674 2675 2676
    pVBoxAPI->UISession = _UISession;
    pVBoxAPI->UIConsole = _UIConsole;
    pVBoxAPI->UIProgress = _UIProgress;
T
Taowei 已提交
2677
    pVBoxAPI->UISystemProperties = _UISystemProperties;
T
Taowei 已提交
2678 2679 2680 2681 2682
    pVBoxAPI->UIBIOSSettings = _UIBIOSSettings;
    pVBoxAPI->UIAudioAdapter = _UIAudioAdapter;
    pVBoxAPI->UINetworkAdapter = _UINetworkAdapter;
    pVBoxAPI->UISerialPort = _UISerialPort;
    pVBoxAPI->UIParallelPort = _UIParallelPort;
2683
    pVBoxAPI->UIVRDEServer = _UIVRDEServer;
T
Taowei 已提交
2684 2685 2686
    pVBoxAPI->UIUSBCommon = _UIUSBCommon;
    pVBoxAPI->UIUSBDeviceFilter = _UIUSBDeviceFilter;
    pVBoxAPI->UIMedium = _UIMedium;
T
Taowei 已提交
2687 2688 2689
    pVBoxAPI->UIMediumAttachment = _UIMediumAttachment;
    pVBoxAPI->UIStorageController = _UIStorageController;
    pVBoxAPI->UISharedFolder = _UISharedFolder;
2690
    pVBoxAPI->UISnapshot = _UISnapshot;
T
Taowei 已提交
2691
    pVBoxAPI->UIDisplay = _UIDisplay;
T
Taowei 已提交
2692
    pVBoxAPI->UIHost = _UIHost;
T
Taowei 已提交
2693
    pVBoxAPI->UIHNInterface = _UIHNInterface;
T
Taowei 已提交
2694
    pVBoxAPI->UIDHCPServer = _UIDHCPServer;
2695
    pVBoxAPI->UIKeyboard = _UIKeyboard;
T
Taowei 已提交
2696
    pVBoxAPI->machineStateChecker = _machineStateChecker;
T
Taowei 已提交
2697

T
Taowei 已提交
2698 2699 2700 2701 2702 2703
#if VBOX_API_VERSION >= 4001000
    pVBoxAPI->chipsetType = 1;
#else /* VBOX_API_VERSION < 4001000 */
    pVBoxAPI->chipsetType = 0;
#endif /* VBOX_API_VERSION < 4001000 */

2704 2705 2706 2707 2708
#if VBOX_API_VERSION >= 4002000
    pVBoxAPI->vboxSnapshotRedefine = 1;
#else /* VBOX_API_VERSION < 4002000 */
    pVBoxAPI->vboxSnapshotRedefine = 0;
#endif /* VBOX_API_VERSION < 4002000 */
T
Taowei 已提交
2709
}