VirtualBox

Ignore:
Timestamp:
Jul 22, 2010 3:24:27 PM (14 years ago)
Author:
vboxsync
Message:

Main: reorganize session APIs

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r30321 r31008  
    18641864        CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[0]), ptrMachine.asOutParam()), 1);
    18651865
    1866     Bstr bstrMachineUuid;
    1867     CHECK_ERROR_RET(ptrMachine, COMGETTER(Id)(bstrMachineUuid.asOutParam()), 1);
    1868     CHECK_ERROR_RET(aVirtualBox, OpenExistingSession(aSession, bstrMachineUuid), 1);
     1866    CHECK_ERROR_RET(ptrMachine, LockForSession(aSession, true /* fPermitShared */, NULL), 1);
    18691867
    18701868    /*
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp

    r30396 r31008  
    7373    /* try to find the given machine */
    7474    ComPtr <IMachine> machine;
    75     Bstr machineuuid (a->argv[0]);
     75    Bstr machineuuid(a->argv[0]);
    7676    if (!Guid(machineuuid).isEmpty())
    7777    {
     
    8888
    8989    /* open a session for the VM */
    90     CHECK_ERROR_RET(a->virtualBox, OpenExistingSession(a->session, machineuuid), 1);
     90    CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    9191
    9292    do
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r30681 r31008  
    285285        do
    286286        {
    287             Bstr uuid;
    288             machine->COMGETTER(Id)(uuid.asOutParam());
    289 
    290             /* open an existing session for VM - so the VM has to be running */
    291             CHECK_ERROR_BREAK(a->virtualBox, OpenExistingSession(a->session, uuid));
     287            /* open an existing session for VM */
     288            CHECK_ERROR_BREAK(machine, LockForSession(a->session, true /* fPermitShared */, NULL));
     289            // @todo r=dj assert that it's an existing session
    292290
    293291            /* get the mutable session machine */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestProp.cpp

    r30871 r31008  
    8787    if (machine)
    8888    {
    89         Bstr uuid;
    90         machine->COMGETTER(Id)(uuid.asOutParam());
    91 
    9289        /* open a session for the VM - new or existing */
    93         if (FAILED (a->virtualBox->OpenSession(a->session, uuid)))
    94             CHECK_ERROR_RET(a->virtualBox, OpenExistingSession(a->session, uuid), 1);
     90        CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    9591
    9692        /* get the mutable session machine */
     
    156152    if (machine)
    157153    {
    158         Bstr uuid;
    159         machine->COMGETTER(Id)(uuid.asOutParam());
    160 
    161154        /* open a session for the VM - new or existing */
    162         if (FAILED (a->virtualBox->OpenSession(a->session, uuid)))
    163             CHECK_ERROR_RET (a->virtualBox, OpenExistingSession(a->session, uuid), 1);
     155        CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    164156
    165157        /* get the mutable session machine */
     
    220212    if (machine)
    221213    {
    222         Bstr uuid;
    223         machine->COMGETTER(Id)(uuid.asOutParam());
    224 
    225214        /* open a session for the VM - new or existing */
    226         if (FAILED(a->virtualBox->OpenSession(a->session, uuid)))
    227             CHECK_ERROR_RET (a->virtualBox, OpenExistingSession(a->session, uuid), 1);
     215        CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    228216
    229217        /* get the mutable session machine */
    230218        a->session->COMGETTER(Machine)(machine.asOutParam());
    231219
    232         com::SafeArray <BSTR> names;
    233         com::SafeArray <BSTR> values;
    234         com::SafeArray <ULONG64> timestamps;
    235         com::SafeArray <BSTR> flags;
     220        com::SafeArray<BSTR> names;
     221        com::SafeArray<BSTR> values;
     222        com::SafeArray<ULONG64> timestamps;
     223        com::SafeArray<BSTR> flags;
    236224        CHECK_ERROR(machine, EnumerateGuestProperties(Bstr(Utf8Patterns),
    237225                                                      ComSafeArrayAsOutParam(names),
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r30976 r31008  
    21322132            details = VMINFO_STANDARD;
    21332133
    2134         ComPtr <IConsole> console;
     2134        ComPtr<IConsole> console;
    21352135
    21362136        /* open an existing session for the VM */
    2137         rc = a->virtualBox->OpenExistingSession(a->session, uuid);
     2137        rc = machine->LockForSession(a->session, true /* fPermitShared */, NULL);
    21382138        if (SUCCEEDED(rc))
    21392139            /* get the session machine */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r31002 r31008  
    356356    if (machine)
    357357    {
    358         Bstr uuid;
    359         machine->COMGETTER(Id)(uuid.asOutParam());
    360 
    361 
    362358        Bstr env;
    363359#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
     
    373369#endif
    374370        ComPtr<IProgress> progress;
    375         CHECK_ERROR_RET(a->virtualBox, OpenRemoteSession(a->session, uuid, sessionType,
    376                                                          env, progress.asOutParam()), rc);
     371        CHECK_ERROR_RET(machine, LaunchVMProcess(a->session, sessionType, env, progress.asOutParam()), rc);
    377372        RTPrintf("Waiting for the VM to power on...\n");
    378373        CHECK_ERROR_RET(progress, WaitForCompletion(-1), 1);
     
    423418        {
    424419            /* we have to open a session for this task */
    425             Bstr guid;
    426             machine->COMGETTER(Id)(guid.asOutParam());
    427             CHECK_ERROR_BREAK(a->virtualBox, OpenSession(a->session, guid));
     420            CHECK_ERROR_BREAK(machine, LockForSession(a->session, false /* fPermitShared */, NULL));
    428421            do
    429422            {
     
    459452        {
    460453            /* we have to open a session for this task */
    461             Bstr guid;
    462             machine->COMGETTER(Id)(guid.asOutParam());
    463             CHECK_ERROR_BREAK(a->virtualBox, OpenSession(a->session, guid));
     454            CHECK_ERROR_BREAK(machine, LockForSession(a->session, false /* fPermitShared */, NULL));
    464455            do
    465456            {
     
    671662    if (!machine)
    672663        return 1;
    673     Bstr uuid;
    674     machine->COMGETTER(Id)(uuid.asOutParam());
    675664
    676665    if (!strcmp(a->argv[0], "add"))
     
    737726
    738727            /* open an existing session for the VM */
    739             CHECK_ERROR_RET(a->virtualBox, OpenExistingSession(a->session, uuid), 1);
     728            CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    740729            /* get the session machine */
    741730            CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
     
    751740        {
    752741            /* open a session for the VM */
    753             CHECK_ERROR_RET(a->virtualBox, OpenSession(a->session, uuid), 1);
     742            CHECK_ERROR_RET(machine, LockForSession(a->session, false /* fPermitShared */, NULL), 1);
    754743
    755744            /* get the mutable session machine */
     
    801790
    802791            /* open an existing session for the VM */
    803             CHECK_ERROR_RET(a->virtualBox, OpenExistingSession(a->session, uuid), 1);
     792            CHECK_ERROR_RET(machine, LockForSession(a->session, true /* fPermitShared */, NULL), 1);
    804793            /* get the session machine */
    805794            CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
     
    815804        {
    816805            /* open a session for the VM */
    817             CHECK_ERROR_RET(a->virtualBox, OpenSession(a->session, uuid), 1);
     806            CHECK_ERROR_RET(machine, LockForSession(a->session, false /* fPermitShared */, NULL), 1);
    818807
    819808            /* get the mutable session machine */
     
    842831
    843832    /* try to find the given machine */
    844     ComPtr <IMachine> machine;
    845     Bstr uuid (a->argv[0]);
    846     if (!Guid (a->argv[0]).isEmpty())
     833    ComPtr<IMachine> machine;
     834    Bstr uuid(a->argv[0]);
     835    if (!Guid(a->argv[0]).isEmpty())
    847836        CHECK_ERROR(a->virtualBox, GetMachine(uuid, machine.asOutParam()));
    848837    else
    849838    {
    850839        CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
    851         if (SUCCEEDED (rc))
     840        if (SUCCEEDED(rc))
    852841            machine->COMGETTER(Id)(uuid.asOutParam());
    853842    }
     
    885874
    886875    /* open an existing session for the VM. */
    887     CHECK_ERROR(a->virtualBox, OpenExistingSession(a->session, uuid));
     876    CHECK_ERROR(machine, LockForSession(a->session, true /* fPermitShared */, NULL));
    888877    if (SUCCEEDED(rc))
    889878    {
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r30976 r31008  
    275275    HRESULT rc;
    276276    Bstr name;
    277     Bstr machineuuid (a->argv[0]);
     277    Bstr machineuuid(a->argv[0]);
    278278    RTGETOPTUNION ValueUnion;
    279279    RTGETOPTSTATE GetOptState;
     
    312312
    313313    /* open a session for the VM */
    314     CHECK_ERROR_RET(a->virtualBox, OpenSession(a->session, machineuuid), 1);
     314    CHECK_ERROR_RET(machine, LockForSession(a->session, false /* fPermitShared */, NULL), 1);
    315315
    316316    /* get the mutable session machine */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp

    r28870 r31008  
    236236    if (!pMachine)
    237237        return 1;
    238     Bstr guidMachine;
    239     pMachine->COMGETTER(Id)(guidMachine.asOutParam());
    240238
    241239    do
    242240    {
    243         /* we have to open a session for this task. First try an existing session */
    244         rc = a->virtualBox->OpenExistingSession(a->session, guidMachine);
    245         if (FAILED(rc))
    246             CHECK_ERROR_BREAK(a->virtualBox, OpenSession(a->session, guidMachine));
     241        /* we have to open a session for this task (new or shared) */
     242        rc = pMachine->LockForSession(a->session, true /* fPermitShared */, NULL);
    247243        ComPtr<IConsole> console;
    248244        CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp

    r30403 r31008  
    6060    ULONG port   = ~0U;
    6161    ULONG device = ~0U;
    62     bool fRunTime = false;
    6362    bool fForceUnmount = false;
    6463    const char *pszCtl  = NULL;
     
    148147        }
    149148    }
    150    
     149
    151150    if (FAILED(rc))
    152151        return 1;
     
    173172    }
    174173
    175     /* open a session for the VM */
    176     rc = a->virtualBox->OpenSession(a->session, machineuuid);
    177     if (FAILED(rc))
    178     {
    179         /* try to open an existing session for the VM */
    180         CHECK_ERROR_RET(a->virtualBox, OpenExistingSession(a->session, machineuuid), 1);
    181         fRunTime = true;
    182     }
    183 
     174    /* open a session for the VM (new or shared) */
     175    SessionType_T type;
     176    rc = machine->LockForSession(a->session, true /* fPermitShared */, &type);
     177    bool fRunTime = (type == SessionType_Shared);
    184178    if (fRunTime && !RTStrICmp(pszType, "hdd"))
    185179    {
     
    761755
    762756    /* open a session for the VM */
    763     CHECK_ERROR_RET(a->virtualBox, OpenSession (a->session, machineuuid), 1);
     757    CHECK_ERROR_RET(machine, LockForSession(a->session, false /* fPermitShared */, NULL), 1);
    764758
    765759    /* get the mutable session machine */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageUSB.cpp

    r28800 r31008  
    416416    else
    417417    {
    418         Bstr uuid;
    419         cmd.mMachine->COMGETTER(Id)(uuid.asOutParam());
    420418        /* open a session for the VM */
    421         CHECK_ERROR_RET (a->virtualBox, OpenSession(a->session, uuid), 1);
     419        CHECK_ERROR_RET(cmd.mMachine, LockForSession(a->session, false /* fPermitShared */, NULL), 1);
    422420        /* get the mutable session machine */
    423421        a->session->COMGETTER(Machine)(cmd.mMachine.asOutParam());
    424422        /* and get the USB controller */
    425         CHECK_ERROR_RET (cmd.mMachine, COMGETTER(USBController) (ctl.asOutParam()), 1);
     423        CHECK_ERROR_RET(cmd.mMachine, COMGETTER(USBController)(ctl.asOutParam()), 1);
    426424    }
    427425
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette