VirtualBox

Changeset 31070 in vbox


Ignore:
Timestamp:
Jul 23, 2010 4:00:09 PM (14 years ago)
Author:
vboxsync
Message:

Main: rename ISession::close() to ISession::unlockMachine(); API documentation

Location:
trunk/src/VBox
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r31023 r31070  
    11611161         */
    11621162        Log(("VBoxHeadless: Closing the session...\n"));
    1163         session->Close();
     1163        session->UnlockMachine();
    11641164    }
    11651165
  • trunk/src/VBox/Frontends/VBoxHeadless/testcase/tstHeadless.cpp

    r31019 r31070  
    201201        }
    202202
    203         RTPrintf ("Closing the session (may fail after power off)...\n");
    204         CHECK_ERROR (session, Close());
     203        RTPrintf("Closing the session (may fail after power off)...\n");
     204        CHECK_ERROR(session, UnlockMachine());
    205205    }
    206206    while (0);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r28800 r31070  
    416416     * Aborted which may have unwanted side effects like killing the saved
    417417     * state file (if the machine was in the Saved state before). */
    418     session->Close();
     418    session->UnlockMachine();
    419419
    420420    EventQueue::getMainEventQueue()->processEventQueue(0);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp

    r31019 r31070  
    881881    } while (0);
    882882
    883     a->session->Close();
     883    a->session->UnlockMachine();
    884884
    885885    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r31019 r31070  
    520520                }
    521521            }
    522             a->session->Close();
     522            a->session->UnlockMachine();
    523523        } while (0);
    524524    }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestProp.cpp

    r31020 r31070  
    168168            CHECK_ERROR(machine, SaveSettings());
    169169
    170         a->session->Close();
     170        a->session->UnlockMachine();
    171171    }
    172172    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r31019 r31070  
    21462146
    21472147        if (console)
    2148             a->session->Close();
     2148            a->session->UnlockMachine();
    21492149    }
    21502150
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r31019 r31070  
    393393
    394394    /* it's important to always close sessions */
    395     a->session->Close();
     395    a->session->UnlockMachine();
    396396
    397397    return SUCCEEDED(rc) ? 0 : 1;
     
    425425                CHECK_ERROR_BREAK(console, ForgetSavedState(true));
    426426            } while (0);
    427             CHECK_ERROR_BREAK(a->session, Close());
     427            CHECK_ERROR_BREAK(a->session, UnlockMachine());
    428428        } while (0);
    429429    }
     
    459459                CHECK_ERROR_BREAK(console, AdoptSavedState(Bstr(a->argv[1])));
    460460            } while (0);
    461             CHECK_ERROR_BREAK(a->session, Close());
     461            CHECK_ERROR_BREAK(a->session, UnlockMachine());
    462462        } while (0);
    463463    }
     
    735735                                                    fWritable, fAutoMount));
    736736            if (console)
    737                 a->session->Close();
     737                a->session->UnlockMachine();
    738738        }
    739739        else
     
    751751                CHECK_ERROR(machine, SaveSettings());
    752752
    753             a->session->Close();
     753            a->session->UnlockMachine();
    754754        }
    755755    }
     
    800800
    801801            if (console)
    802                 a->session->Close();
     802                a->session->UnlockMachine();
    803803        }
    804804        else
     
    814814            /* commit and close the session */
    815815            CHECK_ERROR(machine, SaveSettings());
    816             a->session->Close();
     816            a->session->UnlockMachine();
    817817        }
    818818    }
     
    904904                }
    905905            }
    906             a->session->Close();
     906            a->session->UnlockMachine();
    907907        }
    908908    }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r31019 r31070  
    20482048
    20492049    /* it's important to always close sessions */
    2050     a->session->Close();
     2050    a->session->UnlockMachine();
    20512051
    20522052    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp

    r31019 r31070  
    499499    } while (0);
    500500
    501     a->session->Close();
     501    a->session->UnlockMachine();
    502502
    503503    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp

    r31019 r31070  
    636636leave:
    637637    /* it's important to always close sessions */
    638     a->session->Close();
     638    a->session->UnlockMachine();
    639639
    640640    return SUCCEEDED(rc) ? 0 : 1;
     
    765765    {
    766766        /* it's important to always close sessions */
    767         a->session->Close();
     767        a->session->UnlockMachine();
    768768        errorSyntax(USAGE_STORAGECONTROLLER, "Storage controller name not specified\n");
    769769        return 1;
     
    954954
    955955    /* it's important to always close sessions */
    956     a->session->Close();
     956    a->session->UnlockMachine();
    957957
    958958    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageUSB.cpp

    r31019 r31070  
    562562        }
    563563        /* close the session */
    564         a->session->Close();
     564        a->session->UnlockMachine();
    565565    }
    566566
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r31019 r31070  
    27472747    if (sessionOpened)
    27482748    {
    2749         rc = session->Close();
     2749        rc = session->UnlockMachine();
    27502750        AssertComRC(rc);
    27512751    }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r30677 r31070  
    12631263    /* If a new session was opened, we must close it */
    12641264    if (!session.isNull())
    1265         session.Close();
     1265        session.UnlockMachine();
    12661266
    12671267    return success;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r30753 r31070  
    418418    delete m_pActionsPool;
    419419    m_pActionsPool = 0;
    420     m_session.Close();
     420    m_session.UnlockMachine();
    421421    m_session.detach();
    422422    QApplication::quit();
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMPreviewWindow.cpp

    r31056 r31070  
    9090    /* Close any open session */
    9191    if (m_session.GetState() == KSessionState_Locked)
    92         m_session.Close();
     92        m_session.UnlockMachine();
    9393}
    9494
     
    363363    /* Close any open session */
    364364    if (m_session.GetState() == KSessionState_Locked)
    365         m_session.Close();
     365        m_session.UnlockMachine();
    366366    if (!m_machine.isNull())
    367367    {
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp

    r31019 r31070  
    628628    mVMListView->setFocus();
    629629
    630     session.Close();
     630    session.UnlockMachine();
    631631}
    632632
     
    672672            else
    673673                ok = true;
    674             session.Close();
     674            session.UnlockMachine();
    675675        }
    676676        else
     
    771771        vboxProblem().cannotOpenSession(vbox, item->machine(), progress);
    772772
    773     session.Close();
     773    session.UnlockMachine();
    774774}
    775775
     
    809809        vboxProblem().cannotDiscardSavedState (console);
    810810
    811     session.Close();
     811    session.UnlockMachine();
    812812}
    813813
     
    841841    }
    842842
    843     session.Close();
     843    session.UnlockMachine();
    844844}
    845845
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp

    r31008 r31070  
    544544        vboxProblem().cannotRestoreSnapshot (progress, snapshot.GetName());
    545545
    546     session.Close();
     546    session.UnlockMachine();
    547547}
    548548
     
    590590        vboxProblem().cannotDeleteSnapshot (console,  snapshot.GetName());
    591591
    592     session.Close();
     592    session.UnlockMachine();
    593593}
    594594
     
    661661            vboxProblem().cannotTakeSnapshot (console);
    662662
    663         session.Close();
     663        session.UnlockMachine();
    664664    }
    665665}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp

    r30956 r31070  
    777777            }
    778778
    779             session.Close();
     779            session.UnlockMachine();
    780780        }
    781781        if (!success)
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r31019 r31070  
    12431243                    rc2 = sMachine->SaveSettings();
    12441244                }
    1245                 stack.pSession->Close();
     1245                stack.pSession->UnlockMachine();
    12461246            }
    12471247        }
     
    18501850
    18511851            // only now that we're done with all disks, close the session
    1852             rc = stack.pSession->Close();
     1852            rc = stack.pSession->UnlockMachine();
    18531853            if (FAILED(rc)) DebugBreakThrow(rc);
    18541854            stack.fSessionOpen = false;
     
    18571857        {
    18581858            if (stack.fSessionOpen)
    1859                 stack.pSession->Close();
     1859                stack.pSession->UnlockMachine();
    18601860
    18611861            throw;
     
    19421942
    19431943            // only now that we're done with all disks, close the session
    1944             rc = stack.pSession->Close();
     1944            rc = stack.pSession->UnlockMachine();
    19451945            if (FAILED(rc)) DebugBreakThrow(rc);
    19461946            stack.fSessionOpen = false;
     
    19491949        {
    19501950            if (stack.fSessionOpen)
    1951                 stack.pSession->Close();
     1951                stack.pSession->UnlockMachine();
    19521952
    19531953            throw;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31063 r31070  
    26982698                        tr("The given session is busy"));
    26992699
    2700     /* get the IInternalSessionControl interface */
     2700    // get the client's IInternalSessionControl interface
    27012701    ComPtr<IInternalSessionControl> pSessionControl = aSession;
    27022702    ComAssertMsgRet(!!pSessionControl, ("No IInternalSessionControl interface"),
     
    27272727
    27282728    // try again now
    2729     if (    mData->mSession.mState == SessionState_Locked
    2730          || mData->mSession.mState == SessionState_Unlocking
     2729    if (    (mData->mSession.mState == SessionState_Locked)         // machine is write-locked already (i.e. session machine exists)
     2730         && (lockType == LockType_Shared)                           // caller wants a shared link to the existing session that holds the write lock:
    27312731       )
    27322732    {
    2733         // If the machine is write-locked already (i.e. SessionMachine exists) and
    2734         // caller permits sharing, then try to do that now
    2735         if (    (mData->mSession.mState == SessionState_Locked)
    2736              && (lockType == LockType_Shared)
    2737            )
    2738         {
    2739             ComAssertRet(!mData->mSession.mDirectControl.isNull(), E_FAIL);
    2740 
    2741             // copy member variables before leaving lock
    2742             ComPtr<IInternalSessionControl> pDirectControl = mData->mSession.mDirectControl;
    2743             ComObjPtr<SessionMachine> pSessionMachine = mData->mSession.mMachine;
    2744             AssertReturn(!pSessionMachine.isNull(), E_FAIL);
    2745 
    2746             /*
    2747              *  Leave the lock before calling the client process. It's safe here
    2748              *  since the only thing to do after we get the lock again is to add
    2749              *  the remote control to the list (which doesn't directly influence
    2750              *  anything).
    2751              */
    2752             alock.leave();
    2753 
    2754             // get the console from the direct session (this is a remote call)
    2755             ComPtr<IConsole> pConsole;
    2756             LogFlowThisFunc(("Calling GetRemoteConsole()...\n"));
    2757             rc = pDirectControl->GetRemoteConsole(pConsole.asOutParam());
    2758             LogFlowThisFunc(("GetRemoteConsole() returned %08X\n", rc));
    2759             if (FAILED(rc))
    2760                 /* The failure may occur w/o any error info (from RPC), so provide one */
    2761                 return setError(VBOX_E_VM_ERROR,
    2762                                 tr("Failed to get a console object from the direct session (%Rrc)"), rc);
    2763 
    2764             ComAssertRet(!pConsole.isNull(), E_FAIL);
    2765 
    2766             /* attach the remote session to the machine */
    2767             LogFlowThisFunc(("Calling AssignRemoteMachine()...\n"));
    2768             rc = pSessionControl->AssignRemoteMachine(pSessionMachine, pConsole);
    2769             LogFlowThisFunc(("AssignRemoteMachine() returned %08X\n", rc));
    2770 
    2771             /* The failure may occur w/o any error info (from RPC), so provide one */
    2772             if (FAILED(rc))
    2773                 return setError(VBOX_E_VM_ERROR,
    2774                                 tr("Failed to assign the machine to the session (%Rrc)"),
    2775                                 rc);
    2776             alock.enter();
    2777 
    2778             /* need to revalidate the state after entering the lock again */
    2779             if (mData->mSession.mState != SessionState_Locked)
    2780             {
    2781                 pSessionControl->Uninitialize();
    2782                 return setError(VBOX_E_INVALID_SESSION_STATE,
    2783                                 tr("The machine '%ls' was unlocked unexpectedly while attempting to share its session"),
    2784                                 mUserData->mName.raw());
    2785             }
    2786 
    2787             // add the caller's control to the list
    2788             mData->mSession.mRemoteControls.push_back(pSessionControl);
    2789         }
    2790         else
    2791             // still unlocking, or caller has not permitted sharing:
    2792             return setError(VBOX_E_INVALID_OBJECT_STATE,
    2793                             tr("The machine '%ls' is already locked for a session (or being unlocked)"),
    2794                             mUserData->mName.raw());
     2733        // OK, share the session... we are now dealing with three processes:
     2734        // 1) VBoxSVC (where this code runs);
     2735        // 2) process C: the caller's client process (who wants a shared session);
     2736        // 3) process W: the process which already holds the write lock on the machine (write-locking session)
     2737
     2738        // copy pointers to W (the write-locking session) before leaving lock (these must not be NULL)
     2739        ComPtr<IInternalSessionControl> pSessionW = mData->mSession.mDirectControl;
     2740        ComAssertRet(!pSessionW.isNull(), E_FAIL);
     2741        ComObjPtr<SessionMachine> pSessionMachine = mData->mSession.mMachine;
     2742        AssertReturn(!pSessionMachine.isNull(), E_FAIL);
     2743
     2744        /*
     2745         *  Leave the lock before calling the client process. It's safe here
     2746         *  since the only thing to do after we get the lock again is to add
     2747         *  the remote control to the list (which doesn't directly influence
     2748         *  anything).
     2749         */
     2750        alock.leave();
     2751
     2752        // get the console of the session holding the write lock (this is a remote call)
     2753        ComPtr<IConsole> pConsoleW;
     2754        LogFlowThisFunc(("Calling GetRemoteConsole()...\n"));
     2755        rc = pSessionW->GetRemoteConsole(pConsoleW.asOutParam());
     2756        LogFlowThisFunc(("GetRemoteConsole() returned %08X\n", rc));
     2757        if (FAILED(rc))
     2758            // the failure may occur w/o any error info (from RPC), so provide one
     2759            return setError(VBOX_E_VM_ERROR,
     2760                            tr("Failed to get a console object from the direct session (%Rrc)"), rc);
     2761
     2762        ComAssertRet(!pConsoleW.isNull(), E_FAIL);
     2763
     2764        // share the session machine and W's console with the caller's session
     2765        LogFlowThisFunc(("Calling AssignRemoteMachine()...\n"));
     2766        rc = pSessionControl->AssignRemoteMachine(pSessionMachine, pConsoleW);
     2767        LogFlowThisFunc(("AssignRemoteMachine() returned %08X\n", rc));
     2768
     2769        if (FAILED(rc))
     2770            // the failure may occur w/o any error info (from RPC), so provide one
     2771            return setError(VBOX_E_VM_ERROR,
     2772                            tr("Failed to assign the machine to the session (%Rrc)"), rc);
     2773        alock.enter();
     2774
     2775        // need to revalidate the state after entering the lock again
     2776        if (mData->mSession.mState != SessionState_Locked)
     2777        {
     2778            pSessionControl->Uninitialize();
     2779            return setError(VBOX_E_INVALID_SESSION_STATE,
     2780                            tr("The machine '%ls' was unlocked unexpectedly while attempting to share its session"),
     2781                               mUserData->mName.raw());
     2782        }
     2783
     2784        // add the caller's session to the list
     2785        mData->mSession.mRemoteControls.push_back(pSessionControl);
     2786    }
     2787    else if (    mData->mSession.mState == SessionState_Locked
     2788              || mData->mSession.mState == SessionState_Unlocking
     2789            )
     2790    {
     2791        // sharing not permitted, or machine still unlocking:
     2792        return setError(VBOX_E_INVALID_OBJECT_STATE,
     2793                        tr("The machine '%ls' is already locked for a session (or being unlocked)"),
     2794                        mUserData->mName.raw());
    27952795    }
    27962796    else
    27972797    {
    2798         // no lock exists or sharing not permitted: then create the session machine
    2799 
    2800         /* may not be busy */
     2798        // machine is not locked: then write-lock the machine (create the session machine)
     2799
     2800        // must not be busy
    28012801        AssertReturn(!Global::IsOnlineOrTransient(mData->mMachineState), E_FAIL);
    28022802
     
    28072807        Assert(pid != NIL_RTPROCESS);
    28082808
    2809         if (mData->mSession.mState == SessionState_Spawning)
    2810         {
    2811             /* This machine is awaiting for a spawning session to be opened, so
    2812              * reject any other open attempts from processes other than one
    2813              * started by #openRemoteSession(). */
     2809        bool fLaunchingVMProcess = (mData->mSession.mState == SessionState_Spawning);
     2810
     2811        if (fLaunchingVMProcess)
     2812        {
     2813            // this machine is awaiting for a spawning session to be opened:
     2814            // then the calling process must be the one that got started by
     2815            // launchVMProcess()
    28142816
    28152817            LogFlowThisFunc(("mSession.mPid=%d(0x%x)\n", mData->mSession.mPid, mData->mSession.mPid));
     
    28672869
    28682870            if (    SUCCEEDED(rc)
    2869                  && origState == SessionState_Spawning
     2871                 && fLaunchingVMProcess
    28702872               )
    28712873            {
     
    29112913        }
    29122914
    2913         /* finalize spawning anyway (this is why we don't return on errors above) */
    2914         if (mData->mSession.mState == SessionState_Spawning)
     2915        // finalize spawning anyway (this is why we don't return on errors above)
     2916        if (fLaunchingVMProcess)
    29152917        {
    29162918            /* Note that the progress object is finalized later */
  • trunk/src/VBox/Main/SessionImpl.cpp

    r31019 r31070  
    6464    LogFlowThisFunc(("\n"));
    6565
    66     uninit(true /* aFinalRelease */);
     66    uninit();
    6767}
    6868
     
    109109 *  @note Locks this object for writing.
    110110 */
    111 void Session::uninit(bool aFinalRelease)
     111void Session::uninit()
    112112{
    113113    LogFlowThisFuncEnter();
    114     LogFlowThisFunc(("aFinalRelease=%d\n", aFinalRelease));
    115114
    116115    /* Enclose the state transition Ready->InUninit->NotReady */
     
    131130               mState == SessionState_Spawning);
    132131
    133         HRESULT rc = close(aFinalRelease, false /* aFromServer */);
     132        HRESULT rc = unlockMachine(true /* aFinalRelease */, false /* aFromServer */);
    134133        AssertComRC(rc);
    135134    }
     
    233232/////////////////////////////////////////////////////////////////////////////
    234233
    235 STDMETHODIMP Session::Close()
     234STDMETHODIMP Session::UnlockMachine()
    236235{
    237236    LogFlowThisFunc(("mState=%d, mType=%d\n", mState, mType));
     
    245244    CHECK_OPEN();
    246245
    247     return close(false /* aFinalRelease */, false /* aFromServer */);
     246    return unlockMachine(false /* aFinalRelease */, false /* aFromServer */);
    248247}
    249248
     
    491490
    492491        /* close ourselves */
    493         rc = close(false /* aFinalRelease */, true /* aFromServer */);
     492        rc = unlockMachine(false /* aFinalRelease */, true /* aFromServer */);
    494493    }
    495494    else if (autoCaller.state() == InUninit)
     
    793792
    794793/**
    795  *  Closes the current session.
     794 *  Unlocks a machine associated with the current session.
    796795 *
    797796 *  @param aFinalRelease    called as a result of FinalRelease()
    798797 *  @param aFromServer      called as a result of Uninitialize()
    799798 *
    800  *  @note To be called only from #uninit(), #Close() or #Uninitialize().
     799 *  @note To be called only from #uninit(), #UnlockMachine() or #Uninitialize().
    801800 *  @note Locks this object for writing.
    802801 */
    803 HRESULT Session::close(bool aFinalRelease, bool aFromServer)
     802HRESULT Session::unlockMachine(bool aFinalRelease, bool aFromServer)
    804803{
    805804    LogFlowThisFuncEnter();
  • trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c

    r31008 r31070  
    365365
    366366    listVMs(vbox, session);
    367     session->vtbl->Close(session);
     367    session->vtbl->UnlockMachine(session);
    368368
    369369    printf("----------------------------------------------------\n");
  • trunk/src/VBox/Main/glue/glue-java.xsl

    r31019 r31070  
    25042504    {
    25052505          if (s != null)
    2506             s.close();
     2506            s.unlockMachine();
    25072507    }
    25082508
     
    25692569        IProgress p = m.launchVMProcess(session, type, "");
    25702570        progressBar(p, timeout);
    2571         session.close();
     2571        session.unlockMachine();
    25722572        return true;
    25732573    }
     
    30203020    {
    30213021          if (s != null)
    3022             s.close();
     3022          s.unlockMachine();
    30233023    }
    30243024
     
    30683068        IProgress p = vbox.openRemoteSession(session, mid, type, "");
    30693069        progressBar(p, timeout);
    3070         session.close();
     3070        session.unlockMachine();
    30713071        return true;
    30723072    }
     
    34663466    {
    34673467          if (s != null)
    3468             s.close();
     3468            s.unlockMachine();
    34693469    }
    34703470
     
    35133513        IProgress p = m.launchVMProcess(session, type, "");
    35143514        progressBar(p, timeout);
    3515         session.close();
     3515        session.unlockMachine();
    35163516        return true;
    35173517    }
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31063 r31070  
    42594259        object which controls VM execution.
    42604260
    4261         Also in all of the above cases, one must always call <link to="ISession::close" />
    4262         to release the lock on the machine, or the machine's state will
    4263         eventually be set to "Aborted".
     4261        Also in all of the above cases, one must always call
     4262        <link to="ISession::unlockMachine" /> to release the lock on the machine, or
     4263        the machine's state will eventually be set to "Aborted".
    42644264
    42654265        To change settings on a machine, the following sequence is typically
     
    42714271          <li>Obtain a mutable IMachine object from <link to="ISession::machine" />.</li>
    42724272
    4273           <li>Change the settings of the machine.</li>
     4273          <li>Change the settings of the machine by invoking IMachine methods.</li>
    42744274
    42754275          <li>Call <link to="IMachine::saveSettings" />.</li>
    42764276
    4277           <li>Close the session by calling <link to="ISession::close"/>.</li>
     4277          <li>Release the write lock by calling <link to="ISession::unlockMachine"/>.</li>
    42784278        </ol>
    42794279
     
    43074307    <method name="launchVMProcess">
    43084308      <desc>
    4309         Spawns a new process that will execute the virtual machine.
    4310 
    4311         This operation can take some time (a new VM is started in a new process,
     4309        Spawns a new process that will execute the virtual machine and obtains a shared
     4310        lock on the machine for the calling session.
     4311
     4312        If launching the VM succeeds, the new VM process will create its own session
     4313        and write-lock the machine for it, preventing conflicting changes from other
     4314        processes. If the machine is already locked (because it is already running or
     4315        because another session has a write lock), launching the VM process will therefore
     4316        fail. Reversely, future attempts to obtain a write lock will also fail while the
     4317        machine is running.
     4318
     4319        The caller's session object remains separate from the session opened by the new
     4320        VM process. It receives its own <link to="IConsole" /> object which can be used
     4321        to control machine execution, but it cannot be used to change all VM settings
     4322        which would be available after a <link to="#lockMachine" /> call.
     4323
     4324        The caller must eventually release the session's shared lock by calling
     4325        <link to="ISession::unlockMachine" /> on the local session object once this call
     4326        has returned. However, the session's state (see <link to="ISession::state" />)
     4327        will not return to "Unlocked" until the remote session has also unlocked
     4328        the machine (i.e. the machine has stopped running).
     4329
     4330        Lauching a VM process can take some time (a new VM is started in a new process,
    43124331        for which memory and other resources need to be set up). Because of this,
    43134332        an <link to="IProgress" /> object is returned to allow the caller to wait
     
    43204339        via the progress object, if available.
    43214340
    4322         If launching the VM succeeds, the new VM process will create its own
    4323         session and lock the machine for it, preventing conflicting changes
    4324         from other processes. If the machine is already locked (because it
    4325         is already running or because another session is making changes),
    4326         launching the VM process will therefore fail. Reversely, future
    4327         locking attempts will also fail while the machine is running.
    4328 
    4329         The caller's session object remains separate from the session opened
    4330         by the new VM process. It receives its own <link to="IConsole" />
    4331         object which can be used to control machine execution, but it cannot
    4332         be used to change all VM settings which would be available after
    4333         a <link to="#lockMachine" /> call.
    4334 
    4335         As with all <link to="ISession" /> objects, it is recommended to call
    4336         <link to="ISession::close" /> on the local session object once this call
    4337         has returned. However, the session's state (see <link to="ISession::state" />)
    4338         will not return to "Unlocked" until the remote session has also unlocked
    4339         the machine.
     4341        The progress object will have at least 2 sub-operations. The first
     4342        operation covers the period up to the new VM process calls powerUp.
     4343        The subsequent operations mirror the <link to="IConsole::powerUp"/>
     4344        progress object. Because <link to="IConsole::powerUp"/> may require
     4345        some extra sub-operations, the <link to="IProgress::operationCount"/>
     4346        may change at the completion of operation.
     4347
     4348        For details on the teleportation progress operation, see
     4349        <link to="IConsole::powerUp"/>.
    43404350
    43414351        The @a environment argument is a string containing definitions of
     
    43544364        If the environment string is @c null or empty, the server environment
    43554365        is inherited by the started process as is.
    4356 
    4357         The progress object will have at least 2 sub-operations. The first
    4358         operation covers the period up to the new VM process calls powerUp.
    4359         The subsequent operations mirror the <link to="IConsole::powerUp"/>
    4360         progress object. Because <link to="IConsole::powerUp"/> may require
    4361         some extra sub-operations, the <link to="IProgress::operationCount"/>
    4362         may change at the completion of operation.
    4363 
    4364         For details on the teleportation progress operation, see
    4365         <link to="IConsole::powerUp"/>.
    43664366
    43674367        <result name="E_UNEXPECTED">
     
    1277112771     >
    1277212772    <desc>
    12773       The ISession interface represents a serialization primitive for virtual
    12774       machines. Any caller wishing to manipulate a virtual machine (represented
    12775       by an IMachine object) needs to create a session object first, which lives
    12776       in its own process space. Such session objects are then attached to the
    12777       <link to="IMachine" /> objects living in the VirtualBox server process to
    12778       coordinate possibly conflicting changes.
     12773      The ISession interface represents a client process and allows for locking
     12774      virtual machines (represented by IMachine objects) to prevent conflicting
     12775      changes to the machine.
     12776
     12777      Any caller wishing to manipulate a virtual machine needs to create a session
     12778      object first, which lives in its own process space. Such session objects are
     12779      then associated with <link to="IMachine" /> objects living in the VirtualBox
     12780      server process to coordinate such changes.
    1277912781
    1278012782      There are two typical scenarios in which sessions are used:
    1278112783
    1278212784      <ul>
    12783         <li>To alter machine settings, one needs to lock a machine for a given session
    12784           (client process) by calling <link to="IMachine::lockMachine"/>. While a
    12785           machine is thus locked, no any other process may lock the machine again.
    12786 
    12787           The same applies for any process which indends to actually run a virtual
    12788           machine in its own context, such as the VirtualBox GUI or VBoxHeadless
    12789           executables. They must also lock a machine for their own sessions before
    12790           being allowed to power up the virtual machine.
    12791 
    12792           As a result, no machine can be altered while another process is already
    12793           using it, either because that process is modifying machine settings or
    12794           because the machine is running.
     12785        <li>To alter machine settings or control a running virtual machine, one
     12786          needs to lock a machine for a given session (client process) by calling
     12787          <link to="IMachine::lockMachine"/>.
     12788
     12789          Whereas multiple sessions may control a running virtual machine, only
     12790          one process can obtain a write lock on the machine to prevent conflicting
     12791          changes. A write lock is also needed if a process wants to actually run a
     12792          virtual machine in its own context, such as the VirtualBox GUI or
     12793          VBoxHeadless front-ends. They must also lock a machine for their own
     12794          sessions before they are allowed to power up the virtual machine.
     12795
     12796          As a result, no machine settings can be altered while another process is
     12797          already using it, either because that process is modifying machine settings
     12798          or because the machine is running.
    1279512799        </li>
    1279612800        <li>
    12797           To initiate virtual machine execution using one of the existing VirtualBox
    12798           front-ends (e.g. the GUI or VBoxHeadless), one would instead call
    12799           <link to="IMachine::launchVMProcess"/>, which also requires a session
    12800           object as its first parameter. This session then identifies the caller
    12801           and lets the caller control the started machine (for example, pause machine
    12802           execution or power it down) as well as be notified about machine execution
    12803           state changes.
     12801          To start a VM using one of the existing VirtualBox front-ends (e.g. the
     12802          VirtualBox GUI or VBoxHeadless), one would use
     12803          <link to="IMachine::launchVMProcess"/>, which also takes a session object
     12804          as its first parameter. This session then identifies the caller and lets the
     12805          caller control the started machine (for example, pause machine execution or
     12806          power it down) as well as be notified about machine execution state changes.
    1280412807        </li>
    1280512808      </ul>
    1280612809
    12807       How sessions objects are used depends on whether you use the Main API
    12808       via COM or via the webservice:
     12810      How sessions objects are created in a client process depends on whether you use
     12811      the Main API via COM or via the webservice:
    1280912812
    1281012813      <ul>
     
    1284412847    </attribute>
    1284512848
    12846     <method name="close">
    12847       <desc>
    12848         Closes a session that was previously opened.
    12849 
    12850         Calling this method is eventually required every time a machine has been
    12851         locked for a particular session using the <link to="IMachine::launchVMProcess" />
    12852         or <link to="IMachine::lockMachine" />) calls. Otherwise the state of
     12849    <method name="unlockMachine">
     12850      <desc>
     12851        Unlocks a machine that was previously locked for the current session.
     12852
     12853        Calling this method is required every time a machine has been locked
     12854        for a particular session using the <link to="IMachine::launchVMProcess" />
     12855        or <link to="IMachine::lockMachine" /> calls. Otherwise the state of
    1285312856        the machine will be set to <link to="MachineState_Aborted" /> on the
    1285412857        server, and changes made to the machine settings will be lost.
    1285512858
    12856         Generally, it is recommended to close all open sessions explicitly
     12859        Generally, it is recommended to unlock all machines explicitly
    1285712860        before terminating the application (regardless of the reason for
    1285812861        the termination).
     
    1286012863        <note>
    1286112864          Do not expect the session state (<link to="ISession::state" />
    12862           to return to "Closed" immediately after you invoke
    12863           ISession::close(), particularly if you have started a remote
    12864           session to execute the VM in a new process. The session state will
    12865           automatically return to "Closed" once the VM is no longer executing,
    12866           which can of course take a very long time.
     12865          to return to "Unlocked" immediately after you invoke this method,
     12866          particularly if you have started a new VM process. The session
     12867          state will automatically return to "Unlocked" once the VM is no
     12868          longer executing, which can of course take a very long time.
    1286712869        </note>
    1286812870
    1286912871        <result name="E_UNEXPECTED">
    12870           Session is not open.
     12872          Session is not locked.
    1287112873        </result>
    1287212874
  • trunk/src/VBox/Main/include/SessionImpl.h

    r30764 r31070  
    6666    // public initializers/uninitializers only for internal purposes
    6767    HRESULT init();
    68     void uninit(bool aFinalRelease);
     68    void uninit();
    6969
    7070    // ISession properties
     
    7575
    7676    // ISession methods
    77     STDMETHOD(Close)();
     77    STDMETHOD(UnlockMachine)();
    7878
    7979    // IInternalSessionControl methods
     
    112112private:
    113113
    114     HRESULT close(bool aFinalRelease, bool aFromServer);
     114    HRESULT unlockMachine(bool aFinalRelease, bool aFromServer);
    115115    HRESULT grabIPCSemaphore();
    116116    void releaseIPCSemaphore();
  • trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp

    r31019 r31070  
    406406     * necessary any more.
    407407     */
    408     session->Close();
     408    session->UnlockMachine();
    409409}
    410410
  • trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp

    r31008 r31070  
    238238
    239239            /* Close the session. */
    240             rc = session->Close();
     240            rc = session->UnlockMachine();
    241241
    242242        } while (0);
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