VirtualBox

Changeset 31008 in vbox


Ignore:
Timestamp:
Jul 22, 2010 3:24:27 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63924
Message:

Main: reorganize session APIs

Location:
trunk/src
Files:
38 edited

Legend:

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

    r30871 r31008  
    803803        }
    804804
     805        ComPtr<IMachine> m;
     806
    805807        /* find ID by name */
    806808        if (id.isEmpty())
    807809        {
    808             ComPtr <IMachine> m;
    809810            rc = virtualBox->FindMachine(Bstr(name), m.asOutParam());
    810811            if (FAILED(rc))
     
    823824
    824825        // open a session
    825         CHECK_ERROR_BREAK(virtualBox, OpenSession(session, id));
     826        CHECK_ERROR_BREAK(m, LockForSession(session, false /* fPermitShared */, NULL));
    826827        fSessionOpened = true;
    827828
    828829        /* get the console */
    829         ComPtr <IConsole> console;
     830        ComPtr<IConsole> console;
    830831        CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
    831832
    832         /* get the machine */
    833         ComPtr <IMachine> machine;
     833        /* get the mutable machine */
     834        ComPtr<IMachine> machine;
    834835        CHECK_ERROR_BREAK(console, COMGETTER(Machine)(machine.asOutParam()));
    835836
    836         ComPtr <IDisplay> display;
     837        ComPtr<IDisplay> display;
    837838        CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
    838839
  • trunk/src/VBox/Frontends/VBoxHeadless/testcase/tstHeadless.cpp

    r30681 r31008  
    112112        EventQueue eventQ;
    113113
     114        ComPtr <IMachine> m;
     115
    114116        // find ID by name
    115         Bstr id;
    116         {
    117             ComPtr <IMachine> m;
    118             CHECK_ERROR_BREAK (virtualBox, FindMachine (Bstr (name), m.asOutParam()));
    119             CHECK_ERROR_BREAK (m, COMGETTER(Id) (id.asOutParam()));
    120         }
    121 
    122         if (!strcmp (operation, "on"))
     117        CHECK_ERROR_BREAK(virtualBox, FindMachine(Bstr(name), m.asOutParam()));
     118
     119        if (!strcmp(operation, "on"))
    123120        {
    124121            ComPtr <IProgress> progress;
    125122            RTPrintf ("Opening a new (remote) session...\n");
    126             CHECK_ERROR_BREAK (virtualBox,
    127                                OpenRemoteSession (session, id, Bstr ("vrdp"),
    128                                                   NULL, progress.asOutParam()));
     123            CHECK_ERROR_BREAK (m,
     124                               LaunchVMProcess(session, Bstr("vrdp"),
     125                                               NULL, progress.asOutParam()));
    129126
    130127            RTPrintf ("Waiting for the remote session to open...\n");
     
    153150        {
    154151            RTPrintf ("Opening an existing session...\n");
    155             CHECK_ERROR_BREAK (virtualBox, OpenExistingSession (session, id));
     152            CHECK_ERROR_BREAK(m, LockForSession(session, true /* fPermitShared */, NULL));
    156153
    157154            ComPtr <IConsole> console;
    158             CHECK_ERROR_BREAK (session, COMGETTER (Console) (console.asOutParam()));
     155            CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
    159156
    160157            if (!strcmp (operation, "off"))
  • 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
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r30871 r31008  
    13161316    const CLSID sessionID = CLSID_Session;
    13171317
     1318    ComPtr<IMachine> pMachine;
     1319
    13181320    rc = virtualBox.createLocalObject(CLSID_VirtualBox);
    13191321    if (FAILED(rc))
     
    13391341    if (vmName && uuidVM.isEmpty())
    13401342    {
    1341         ComPtr<IMachine> aMachine;
    13421343        Bstr  bstrVMName = vmName;
    1343         rc = virtualBox->FindMachine(bstrVMName, aMachine.asOutParam());
    1344         if ((rc == S_OK) && aMachine)
     1344        rc = virtualBox->FindMachine(bstrVMName, pMachine.asOutParam());
     1345        if ((rc == S_OK) && pMachine)
    13451346        {
    13461347            Bstr id;
    1347             aMachine->COMGETTER(Id)(id.asOutParam());
     1348            pMachine->COMGETTER(Id)(id.asOutParam());
    13481349            uuidVM = Guid(id);
    13491350        }
     
    13641365    AssertReleaseRC(vrc);
    13651366
    1366     rc = virtualBox->OpenSession(session, uuidVM.toUtf16());
     1367    rc = pMachine->LockForSession(session, false /* fPermitShared */, NULL);
    13671368    if (FAILED(rc))
    13681369    {
     
    13791380    }
    13801381    sessionOpened = true;
    1381     // get the VM we're dealing with
     1382    // get the mutable VM we're dealing with
    13821383    session->COMGETTER(Machine)(gMachine.asOutParam());
    13831384    if (!gMachine)
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r30976 r31008  
    21662166 *                      session.
    21672167 */
    2168 CSession VBoxGlobal::openSession (const QString &aId, bool aExisting /* = false */)
     2168CSession VBoxGlobal::openSession(const QString &aId, bool aExisting /* = false */)
    21692169{
    21702170    CSession session;
    2171     session.createInstance (CLSID_Session);
     2171    session.createInstance(CLSID_Session);
    21722172    if (session.isNull())
    21732173    {
     
    21762176    }
    21772177
    2178     if (aExisting)
    2179         mVBox.OpenExistingSession (session, aId);
    2180     else
    2181     {
    2182         mVBox.OpenSession (session, aId);
    2183         CMachine machine = session.GetMachine ();
    2184         /* Make sure that the language is in two letter code.
    2185          * Note: if languageId() returns an empty string lang.name() will
    2186          * return "C" which is an valid language code. */
    2187         QLocale lang (VBoxGlobal::languageId());
    2188         machine.SetGuestPropertyValue ("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
     2178    CMachine foundMachine = CVirtualBox(mVBox).GetMachine(aId);
     2179    if (!foundMachine.isNull())
     2180    {
     2181        KSessionType t = foundMachine.LockForSession(session, aExisting /* fPermitShared */);
     2182        if (t == KSessionType_Shared)
     2183        {
     2184            CMachine machine = session.GetMachine();
     2185            /* Make sure that the language is in two letter code.
     2186             * Note: if languageId() returns an empty string lang.name() will
     2187             * return "C" which is an valid language code. */
     2188            QLocale lang(VBoxGlobal::languageId());
     2189            machine.SetGuestPropertyValue ("/VirtualBox/HostInfo/GUI/LanguageID", lang.name());
     2190        }
    21892191    }
    21902192
    21912193    if (!mVBox.isOk())
    21922194    {
    2193         CMachine machine = CVirtualBox (mVBox).GetMachine (aId);
    2194         vboxProblem().cannotOpenSession (mVBox, machine);
     2195        vboxProblem().cannotOpenSession(mVBox, foundMachine);
    21952196        session.detach();
    21962197    }
     
    26672668    mMachineStates [KMachineState_SettingUp] =  tr ("Setting Up", "MachineState");
    26682669
    2669     mSessionStates [KSessionState_Closed] =     tr ("Closed", "SessionState");
    2670     mSessionStates [KSessionState_Open] =       tr ("Open", "SessionState");
     2670    mSessionStates [KSessionState_Unlocked] =   tr ("Unlocked", "SessionState");
     2671    mSessionStates [KSessionState_Locked] =     tr ("Locked", "SessionState");
    26712672    mSessionStates [KSessionState_Spawning] =   tr ("Spawning", "SessionState");
    2672     mSessionStates [KSessionState_Closing] =    tr ("Closing", "SessionState");
     2673    mSessionStates [KSessionState_Unlocking] =  tr ("Unlocking", "SessionState");
    26732674
    26742675    mDeviceTypes [KDeviceType_Null] =           tr ("None", "DeviceType");
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r30677 r31008  
    510510#endif
    511511
    512     CSession openSession (const QString &aId, bool aExisting = false);
     512    CSession openSession(const QString &aId, bool aExisting = false);
    513513
    514514    /** Shortcut to openSession (aId, true). */
    515     CSession openExistingSession (const QString &aId) { return openSession (aId, true); }
     515    CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
    516516
    517517    bool startMachine(const QString &strId);
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMDesktop.cpp

    r30905 r31008  
    933933    {
    934934        KMachineState state = m_machine.GetState();
    935         bool running = m_machine.GetSessionState() != KSessionState_Closed;
     935        bool running = m_machine.GetSessionState() != KSessionState_Unlocked;
    936936        m_fChangeable = !running && state != KMachineState_Saved;
    937937    }
     
    12531253    {
    12541254        bool saved = m_pVMItem->state() == KMachineState_Saved;
    1255         bool busy = m_pVMItem->sessionState() != KSessionState_Closed;
     1255        bool busy = m_pVMItem->sessionState() != KSessionState_Unlocked;
    12561256        m_pEditBtn->setEnabled(!saved && !busy);
    12571257    }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMListView.cpp

    r30868 r31008  
    215215            QFont f = qApp->font();
    216216            f.setPointSize(f.pointSize());
    217             if (m_VMItemList.at(aIndex.row())->sessionState() != KSessionState_Closed)
     217            if (m_VMItemList.at(aIndex.row())->sessionState() != KSessionState_Unlocked)
    218218                f.setItalic(true);
    219219            v = f;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMPreviewWindow.cpp

    r30981 r31008  
    245245                {
    246246                    CVirtualBox vbox = vboxGlobal().virtualBox();
    247                     vbox.OpenExistingSession(session, m_machine.GetId());
     247                    m_machine.LockForSession(session, true /* fPermitShared */);
    248248                    if (vbox.isOk())
    249249                    {
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp

    r30956 r31008  
    757757#endif
    758758
    759     CProgress progress = vbox.OpenRemoteSession (session, id, "GUI/Qt", env);
     759    CProgress progress = item->machine().LaunchVMProcess(session, "GUI/Qt", env);
    760760    if (!vbox.isOk())
    761761    {
    762         vboxProblem().cannotOpenSession (vbox, item->machine());
     762        vboxProblem().cannotOpenSession(vbox, item->machine());
    763763        return;
    764764    }
     
    791791    if (session.isNull())
    792792    {
    793         vboxProblem().cannotOpenSession (session);
     793        vboxProblem().cannotOpenSession(session);
    794794        return;
    795795    }
    796     vbox.OpenSession (session, id);
     796
     797    CMachine foundMachine = vbox.GetMachine(id);
     798    if (!foundMachine.isNull())
     799        foundMachine.LockForSession(session, false /* fPermitShared */);
    797800    if (!vbox.isOk())
    798801    {
     
    11881191
    11891192        KMachineState state = item->state();
    1190         bool running = item->sessionState() != KSessionState_Closed;
     1193        bool running = item->sessionState() != KSessionState_Unlocked;
    11911194        bool modifyEnabled = !running && state != KMachineState_Saved;
    11921195
     
    16151618        CMachine m = pItem->machine();
    16161619        KMachineState s = pItem->state();
    1617         bool running = pItem->sessionState() != KSessionState_Closed;
     1620        bool running = pItem->sessionState() != KSessionState_Unlocked;
    16181621        bool modifyEnabled = !running && s != KMachineState_Saved;
    16191622
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp

    r30868 r31008  
    444444
    445445    /* Whether another direct session is open or not */
    446     bool busy = mSessionState != KSessionState_Closed;
     446    bool busy = mSessionState != KSessionState_Unlocked;
    447447
    448448    /* Machine state of the current state item */
     
    571571
    572572    /* Open a direct session (this call will handle all errors) */
    573     bool busy = mSessionState != KSessionState_Closed;
     573    bool busy = mSessionState != KSessionState_Unlocked;
    574574    CSession session = vboxGlobal().openSession (mMachineId, busy /* aExisting */);
    575575    if (session.isNull())
     
    641641    {
    642642        /* Open a direct session (this call will handle all errors) */
    643         bool busy = mSessionState != KSessionState_Closed;
     643        bool busy = mSessionState != KSessionState_Unlocked;
    644644        CSession session = vboxGlobal().openSession (mMachineId, busy /* aExisting */);
    645645        if (session.isNull())
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIExportApplianceWzd.cpp

    r29730 r31008  
    181181            strName = m.GetName();
    182182            strUuid = m.GetId();
    183             bEnabled = m.GetSessionState() == KSessionState_Closed;
     183            bEnabled = m.GetSessionState() == KSessionState_Unlocked;
    184184        }
    185185        else
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r30956 r31008  
    12331233        {
    12341234            const MyHardDiskAttachment &mhda = *itM;
    1235             Bstr bstrUuid(mhda.bstrUuid);           // make a copy, Windows can't handle const Bstr
    1236             rc2 = mVirtualBox->OpenSession(stack.pSession, bstrUuid);
     1235            rc2 = mhda.pMachine->LockForSession(stack.pSession, false /* fPermitShared */, NULL);
    12371236            if (SUCCEEDED(rc2))
    12381237            {
     
    17611760        {
    17621761            // to attach things we need to open a session for the new machine
    1763             rc = mVirtualBox->OpenSession(stack.pSession, bstrNewMachineId);
     1762            rc = pNewMachine->LockForSession(stack.pSession, false /* fPermitShared */, NULL);
    17641763            if (FAILED(rc)) DebugBreakThrow(rc);
    17651764            stack.fSessionOpen = true;
     
    17821781                // this is for rollback later
    17831782                MyHardDiskAttachment mhda;
    1784                 mhda.bstrUuid = bstrNewMachineId;
    17851783                mhda.pMachine = pNewMachine;
    17861784                mhda.controllerType = bstrName;
     
    18281826                // this is for rollback later
    18291827                MyHardDiskAttachment mhda;
    1830                 mhda.bstrUuid = bstrNewMachineId;
    18311828                mhda.pMachine = pNewMachine;
    18321829
     
    18751872        {
    18761873            // to attach things we need to open a session for the new machine
    1877             rc = mVirtualBox->OpenSession(stack.pSession, bstrNewMachineId);
     1874            rc = pNewMachine->LockForSession(stack.pSession, false /* fPermitShared */, NULL);
    18781875            if (FAILED(rc)) DebugBreakThrow(rc);
    18791876            stack.fSessionOpen = true;
     
    19211918                // this is for rollback later
    19221919                MyHardDiskAttachment mhda;
    1923                 mhda.bstrUuid = bstrNewMachineId;
    19241920                mhda.pMachine = pNewMachine;
    19251921
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r31002 r31008  
    56645664             * which can lead to various unexpected results (like the machine
    56655665             * state being >= MachineState_Running on the server, while the
    5666              * session state is already SessionState_Closed at the same time
     5666             * session state is already SessionState_Unlocked at the same time
    56675667             * there).
    56685668             *
  • trunk/src/VBox/Main/Global.cpp

    r30825 r31008  
    364364    {
    365365        case SessionState_Null:         return "Null";
    366         case SessionState_Closed:       return "Closed";
    367         case SessionState_Open:         return "Open";
     366        case SessionState_Unlocked:     return "Unlocked";
     367        case SessionState_Locked:       return "Locked";
    368368        case SessionState_Spawning:     return "Spawning";
    369         case SessionState_Closing:      return "Closing";
     369        case SessionState_Unlocking:    return "Unlocking";
    370370        default:
    371371        {
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31002 r31008  
    116116
    117117    mSession.mPid = NIL_RTPROCESS;
    118     mSession.mState = SessionState_Closed;
     118    mSession.mState = SessionState_Unlocked;
    119119}
    120120
     
    26762676
    26772677    return S_OK;
     2678}
     2679
     2680/**
     2681 *  @note Locks objects!
     2682 */
     2683STDMETHODIMP Machine::LockForSession(ISession *aSession,
     2684                                     BOOL fPermitShared,
     2685                                     SessionType_T *pSessionType)
     2686{
     2687    CheckComArgNotNull(aSession);
     2688
     2689    AutoCaller autoCaller(this);
     2690    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2691
     2692    /* check the session state */
     2693    SessionState_T state;
     2694    HRESULT rc = aSession->COMGETTER(State)(&state);
     2695    if (FAILED(rc)) return rc;
     2696
     2697    if (state != SessionState_Unlocked)
     2698        return setError(VBOX_E_INVALID_OBJECT_STATE,
     2699                        tr("The given session is busy"));
     2700
     2701    /* get the IInternalSessionControl interface */
     2702    ComPtr<IInternalSessionControl> control = aSession;
     2703    ComAssertMsgRet(!!control, ("No IInternalSessionControl interface"),
     2704                    E_INVALIDARG);
     2705
     2706    rc = openSession(control);
     2707
     2708    if (FAILED(rc) && fPermitShared)
     2709        // try again @todo r=dj check exact error code!
     2710        rc = openExistingSession(control);
     2711
     2712    if (SUCCEEDED(rc))
     2713    {
     2714        /*
     2715        *  tell the client watcher thread to update the set of
     2716        *  machines that have open sessions
     2717        */
     2718        mParent->updateClientWatcher();
     2719
     2720        /* fire an event */
     2721        mParent->onSessionStateChange(getId(), SessionState_Locked);
     2722
     2723        // return session type to caller
     2724        if (pSessionType)
     2725            aSession->COMGETTER(Type)(pSessionType);
     2726    }
     2727
     2728    return rc;
     2729}
     2730
     2731/**
     2732 *  @note Locks objects!
     2733 */
     2734STDMETHODIMP Machine::LaunchVMProcess(ISession *aSession,
     2735                                      IN_BSTR aType,
     2736                                      IN_BSTR aEnvironment,
     2737                                      IProgress **aProgress)
     2738{
     2739    CheckComArgNotNull(aSession);
     2740    CheckComArgStrNotEmptyOrNull(aType);
     2741    CheckComArgOutSafeArrayPointerValid(aProgress);
     2742
     2743    AutoCaller autoCaller(this);
     2744    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2745
     2746    /* check the session state */
     2747    SessionState_T state;
     2748    HRESULT rc = aSession->COMGETTER(State)(&state);
     2749    if (FAILED(rc)) return rc;
     2750
     2751    if (state != SessionState_Unlocked)
     2752        return setError(VBOX_E_INVALID_OBJECT_STATE,
     2753                        tr("The given session is busy"));
     2754
     2755    /* get the IInternalSessionControl interface */
     2756    ComPtr<IInternalSessionControl> control = aSession;
     2757    ComAssertMsgRet(!!control, ("No IInternalSessionControl interface"),
     2758                      E_INVALIDARG);
     2759
     2760    /* get the teleporter enable state for the progress object init. */
     2761    BOOL fTeleporterEnabled;
     2762    rc = COMGETTER(TeleporterEnabled)(&fTeleporterEnabled);
     2763    if (FAILED(rc))
     2764        return rc;
     2765
     2766    /* create a progress object */
     2767    ComObjPtr<ProgressProxy> progress;
     2768    progress.createObject();
     2769    rc = progress->init(mParent,
     2770                        static_cast<IMachine*>(this),
     2771                        Bstr(tr("Spawning session")),
     2772                        TRUE /* aCancelable */,
     2773                        fTeleporterEnabled ? 20 : 10 /* uTotalOperationsWeight */,
     2774                        Bstr(tr("Spawning session")),
     2775                        2 /* uFirstOperationWeight */,
     2776                        fTeleporterEnabled ? 3 : 1 /* cOtherProgressObjectOperations */);
     2777    if (SUCCEEDED(rc))
     2778    {
     2779        rc = openRemoteSession(control, aType, aEnvironment, progress);
     2780        if (SUCCEEDED(rc))
     2781        {
     2782            progress.queryInterfaceTo(aProgress);
     2783
     2784            /* signal the client watcher thread */
     2785            mParent->updateClientWatcher();
     2786
     2787            /* fire an event */
     2788            mParent->onSessionStateChange(getId(), SessionState_Spawning);
     2789        }
     2790    }
     2791
     2792    return rc;
    26782793}
    26792794
     
    36973812
    36983813    MediaList llMedia;
    3699     if (mData->mSession.mState != SessionState_Closed)
     3814    if (mData->mSession.mState != SessionState_Unlocked)
    37003815        return setError(VBOX_E_INVALID_OBJECT_STATE,
    3701                         tr("Cannot unregister the machine '%ls' because it has an open session"),
     3816                        tr("Cannot unregister the machine '%ls' while it is locked"),
    37023817                           mUserData->mName.raw());
    37033818
     
    40144129        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    40154130
    4016         if (mData->mSession.mState != SessionState_Open)
     4131        if (mData->mSession.mState != SessionState_Locked)
    40174132            return setError(VBOX_E_INVALID_VM_STATE,
    4018                             tr("Machine session is not open (session state: %s)"),
     4133                            tr("Machine is not locked for session (session state: %s)"),
    40194134                            Global::stringifySessionState(mData->mSession.mState));
    40204135
     
    40414156        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    40424157
    4043         if (mData->mSession.mState != SessionState_Open)
     4158        if (mData->mSession.mState != SessionState_Locked)
    40444159            return setError(E_FAIL,
    4045                             tr("Machine session is not open (session state: %s)"),
     4160                            tr("Machine is not locked for session (session state: %s)"),
    40464161                            Global::stringifySessionState(mData->mSession.mState));
    40474162
     
    52655380     * and do a limited wait (max. 1 second). This helps a lot when the system
    52665381     * is busy and thus session closing can take a little while. */
    5267     if (    mData->mSession.mState == SessionState_Closing
     5382    if (    mData->mSession.mState == SessionState_Unlocking
    52685383        &&  mData->mSession.mProgress)
    52695384    {
     
    52745389    }
    52755390
    5276     if (mData->mSession.mState == SessionState_Open ||
    5277         mData->mSession.mState == SessionState_Closing)
     5391    if (    mData->mSession.mState == SessionState_Locked
     5392         || mData->mSession.mState == SessionState_Unlocking
     5393       )
    52785394        return setError(VBOX_E_INVALID_OBJECT_STATE,
    5279                         tr("A session for the machine '%ls' is currently open (or being closed)"),
     5395                        tr("The machine '%ls' is already locked for a session (or being unlocked)"),
    52805396                        mUserData->mName.raw());
    52815397
     
    53015417        if (mData->mSession.mPid != pid)
    53025418            return setError(E_ACCESSDENIED,
    5303                             tr("An unexpected process (PID=0x%08X) has tried to open a direct "
    5304                                "session with the machine named '%ls', while only a process "
    5305                                "started by OpenRemoteSession (PID=0x%08X) is allowed"),
     5419                            tr("An unexpected process (PID=0x%08X) has tried to lock the "
     5420                               "machine '%ls', while only the process started by launchVMProcess (PID=0x%08X) is allowed"),
    53065421                            pid, mUserData->mName.raw(), mData->mSession.mPid);
    53075422    }
     
    54185533
    54195534            mData->mSession.mRemoteControls.clear();
    5420             mData->mSession.mState = SessionState_Closed;
     5535            mData->mSession.mState = SessionState_Unlocked;
    54215536        }
    54225537    }
     
    54325547        /* memorize the direct session control and cache IUnknown for it */
    54335548        mData->mSession.mDirectControl = aControl;
    5434         mData->mSession.mState = SessionState_Open;
     5549        mData->mSession.mState = SessionState_Locked;
    54355550        /* associate the SessionMachine with this Machine */
    54365551        mData->mSession.mMachine = sessionMachine;
     
    54825597    LogFlowThisFunc(("mSession.mState=%s\n", Global::stringifySessionState(mData->mSession.mState)));
    54835598
    5484     if (mData->mSession.mState == SessionState_Open ||
    5485         mData->mSession.mState == SessionState_Spawning ||
    5486         mData->mSession.mState == SessionState_Closing)
     5599    if (    mData->mSession.mState == SessionState_Locked
     5600         || mData->mSession.mState == SessionState_Spawning
     5601         || mData->mSession.mState == SessionState_Unlocking)
    54875602        return setError(VBOX_E_INVALID_OBJECT_STATE,
    5488                         tr("A session for the machine '%ls' is currently open (or being opened or closed)"),
     5603                        tr("The machine '%ls' is already locked by a session (or being locked or unlocked)"),
    54895604                        mUserData->mName.raw());
    54905605
     
    56695784    {
    56705785        /* restore the session state */
    5671         mData->mSession.mState = SessionState_Closed;
     5786        mData->mSession.mState = SessionState_Unlocked;
    56725787        /* The failure may occur w/o any error info (from RPC), so provide one */
    56735788        return setError(VBOX_E_VM_ERROR,
     
    57105825    LogFlowThisFunc(("mSession.state=%s\n", Global::stringifySessionState(mData->mSession.mState)));
    57115826
    5712     if (mData->mSession.mState != SessionState_Open)
     5827    if (mData->mSession.mState != SessionState_Locked)
    57135828        return setError(VBOX_E_INVALID_SESSION_STATE,
    5714                         tr("The machine '%ls' does not have an open session"),
     5829                        tr("The machine '%ls' is not currently locked for a session"),
    57155830                        mUserData->mName.raw());
    57165831
     
    57565871
    57575872    /* need to revalidate the state after entering the lock again */
    5758     if (mData->mSession.mState != SessionState_Open)
     5873    if (mData->mSession.mState != SessionState_Locked)
    57595874    {
    57605875        aControl->Uninitialize();
    57615876
    57625877        return setError(VBOX_E_INVALID_SESSION_STATE,
    5763                         tr("The machine '%ls' does not have an open session"),
     5878                        tr("The machine '%ls' is not currently locked for a session"),
    57645879                        mUserData->mName.raw());
    57655880    }
     
    58105925    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    58115926
    5812     if (mData->mSession.mState == SessionState_Open ||
    5813         (aAllowClosing && mData->mSession.mState == SessionState_Closing))
     5927    if (    mData->mSession.mState == SessionState_Locked
     5928         || (aAllowClosing && mData->mSession.mState == SessionState_Unlocking)
     5929       )
    58145930    {
    58155931        AssertReturn(!mData->mSession.mMachine.isNull(), false);
     
    59616077
    59626078        mData->mSession.mRemoteControls.clear();
    5963         mData->mSession.mState = SessionState_Closed;
     6079        mData->mSession.mState = SessionState_Unlocked;
    59646080
    59656081        /* finalize the progress after setting the state */
     
    59736089        mData->mSession.mPid = NIL_RTPROCESS;
    59746090
    5975         mParent->onSessionStateChange(mData->mUuid, SessionState_Closed);
     6091        mParent->onSessionStateChange(mData->mUuid, SessionState_Unlocked);
    59766092        return true;
    59776093    }
     
    97189834    {
    97199835        /* mType is not null when this machine's process has been started by
    9720          * VirtualBox::OpenRemoteSession(), therefore it is our child.  We
     9836         * Machine::launchVMProcess(), therefore it is our child.  We
    97219837         * need to queue the PID to reap the process (and avoid zombies on
    97229838         * Linux). */
     
    97789894        /* this must be null here (see #OnSessionEnd()) */
    97799895        Assert(mData->mSession.mDirectControl.isNull());
    9780         Assert(mData->mSession.mState == SessionState_Closing);
     9896        Assert(mData->mSession.mState == SessionState_Unlocking);
    97819897        Assert(!mData->mSession.mProgress.isNull());
    97829898    }
     
    97999915    /* reset the rest of session data */
    98009916    mData->mSession.mMachine.setNull();
    9801     mData->mSession.mState = SessionState_Closed;
     9917    mData->mSession.mState = SessionState_Unlocked;
    98029918    mData->mSession.mType.setNull();
    98039919
     
    98239939
    98249940    /* fire an event */
    9825     mParent->onSessionStateChange(mData->mUuid, SessionState_Closed);
     9941    mParent->onSessionStateChange(mData->mUuid, SessionState_Unlocked);
    98269942
    98279943    uninitDataAndChildObjects();
     
    991810034    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    991910035
    9920     if (mData->mSession.mState != SessionState_Open)
     10036    if (mData->mSession.mState != SessionState_Locked)
    992110037        return VBOX_E_INVALID_OBJECT_STATE;
    992210038
     
    993810054    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    993910055
    9940     if (mData->mSession.mState != SessionState_Open)
     10056    if (mData->mSession.mState != SessionState_Locked)
    994110057        return VBOX_E_INVALID_OBJECT_STATE;
    994210058
     
    1013310249        /* go to the closing state (essential for all open*Session() calls and
    1013410250         * for #checkForDeath()) */
    10135         Assert(mData->mSession.mState == SessionState_Open);
    10136         mData->mSession.mState = SessionState_Closing;
     10251        Assert(mData->mSession.mState == SessionState_Locked);
     10252        mData->mSession.mState = SessionState_Unlocking;
    1013710253
    1013810254        /* set direct control to NULL to release the remote instance */
     
    1051310629         * threat the latter also as an abnormal termination (see
    1051410630         * Session::uninit() for details). */
    10515         reason = mData->mSession.mState == SessionState_Closing ?
     10631        reason = mData->mSession.mState == SessionState_Unlocking ?
    1051610632                 Uninit::Normal :
    1051710633                 Uninit::Abnormal;
     
    1126511381         * and simply do nothing here. */
    1126611382
    11267         if (mData->mSession.mState == SessionState_Closing)
     11383        if (mData->mSession.mState == SessionState_Unlocking)
    1126811384            return S_OK;
    1126911385
  • trunk/src/VBox/Main/SessionImpl.cpp

    r30134 r31008  
    4646#define CHECK_OPEN() \
    4747    do { \
    48         if (mState != SessionState_Open) \
    49             return setError(E_UNEXPECTED, tr ("The session is not open (session state: %s)"), Global::stringifySessionState(mState)); \
     48        if (mState != SessionState_Locked) \
     49            return setError(E_UNEXPECTED, tr ("The session is not locked (session state: %s)"), Global::stringifySessionState(mState)); \
    5050    } while (0)
    5151
     
    8181    LogFlowThisFuncEnter();
    8282
    83     mState = SessionState_Closed;
     83    mState = SessionState_Unlocked;
    8484    mType = SessionType_Null;
    8585
     
    126126    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    127127
    128     if (mState != SessionState_Closed)
    129     {
    130         Assert(mState == SessionState_Open ||
     128    if (mState != SessionState_Unlocked)
     129    {
     130        Assert(mState == SessionState_Locked ||
    131131               mState == SessionState_Spawning);
    132132
     
    276276    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    277277
    278     AssertReturn(mState != SessionState_Closed, VBOX_E_INVALID_VM_STATE);
     278    AssertReturn(mState != SessionState_Unlocked, VBOX_E_INVALID_VM_STATE);
    279279
    280280    AssertMsgReturn(mType == SessionType_Direct && !!mConsole,
     
    284284    /* return a failure if the session already transitioned to Closing
    285285     * but the server hasn't processed Machine::OnSessionEnd() yet. */
    286     if (mState != SessionState_Open)
     286    if (mState != SessionState_Locked)
    287287        return VBOX_E_INVALID_VM_STATE;
    288288
     
    304304    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    305305
    306     AssertReturn(mState == SessionState_Closed, VBOX_E_INVALID_VM_STATE);
     306    AssertReturn(mState == SessionState_Unlocked, VBOX_E_INVALID_VM_STATE);
    307307
    308308    if (!aMachine)
     
    310310        /*
    311311         *  A special case: the server informs us that this session has been
    312          *  passed to IVirtualBox::OpenRemoteSession() so this session will
    313          *  become remote (but not existing) when AssignRemoteMachine() is
    314          *  called.
     312         *  passed to IMachine::launchVMProcess() so this session will become
     313         *  remote (but not existing) when AssignRemoteMachine() is called.
    315314         */
    316315
     
    347346    {
    348347        mType = SessionType_Direct;
    349         mState = SessionState_Open;
     348        mState = SessionState_Locked;
    350349    }
    351350    else
     
    375374    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    376375
    377     AssertReturn(mState == SessionState_Closed ||
     376    AssertReturn(mState == SessionState_Unlocked ||
    378377                  mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
    379378
     
    416415         */
    417416        if (mType != SessionType_Remote)
    418             mType = SessionType_Existing;
     417            mType = SessionType_Shared;
    419418        else
    420419            Assert(mState == SessionState_Spawning);
    421420
    422         mState = SessionState_Open;
     421        mState = SessionState_Locked;
    423422    }
    424423    else
     
    452451    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    453452
    454     if (mState == SessionState_Closing)
    455     {
    456         LogFlowThisFunc(("Already being closed.\n"));
     453    if (mState == SessionState_Unlocking)
     454    {
     455        LogFlowThisFunc(("Already being unlocked.\n"));
    457456        return S_OK;
    458457    }
    459458
    460     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     459    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    461460    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    462461
     
    482481        LogFlowThisFunc(("mState=%s, mType=%d\n", Global::stringifySessionState(mState), mType));
    483482
    484         if (mState == SessionState_Closing)
     483        if (mState == SessionState_Unlocking)
    485484        {
    486             LogFlowThisFunc(("Already being closed.\n"));
     485            LogFlowThisFunc(("Already being unlocked.\n"));
    487486            return S_OK;
    488487        }
    489488
    490         AssertReturn(mState == SessionState_Open ||
     489        AssertReturn(mState == SessionState_Locked ||
    491490                      mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
    492491
     
    522521
    523522    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    524     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     523    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    525524    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    526525
     
    536535
    537536    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    538     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     537    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    539538    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    540539
     
    550549
    551550    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    552     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     551    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    553552    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    554553
     
    564563
    565564    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    566     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     565    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    567566    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    568567
     
    578577
    579578    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    580     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     579    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    581580    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    582581
     
    592591
    593592    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    594     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     593    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    595594    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    596595
     
    606605
    607606    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    608     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     607    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    609608    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    610609
     
    620619
    621620    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    622     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     621    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    623622    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    624623
     
    634633
    635634    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    636     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     635    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    637636    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    638637
     
    650649
    651650    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    652     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     651    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    653652    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    654653
     
    665664
    666665    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    667     AssertReturn(mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
     666    AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
    668667    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    669668
     
    680679    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    681680
    682     if (mState != SessionState_Open)
     681    if (mState != SessionState_Locked)
    683682    {
    684683        /* the call from Machine issued when the session is open can arrive
     
    701700    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    702701
    703     if (mState != SessionState_Open)
     702    if (mState != SessionState_Locked)
    704703        return setError(VBOX_E_INVALID_VM_STATE,
    705                         tr("Machine session is not open (session state: %s)."),
     704                        tr("Machine is not locked by session (session state: %s)."),
    706705                        Global::stringifySessionState(mState));
    707706    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
     
    738737    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    739738
    740     if (mState != SessionState_Open)
     739    if (mState != SessionState_Locked)
    741740        return setError(VBOX_E_INVALID_VM_STATE,
    742                         tr("Machine session is not open (session state: %s)."),
     741                        tr("Machine is not locked by session (session state: %s)."),
    743742                        Global::stringifySessionState(mState));
    744743    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
     
    774773    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    775774
    776     if (mState != SessionState_Open)
     775    if (mState != SessionState_Locked)
    777776        return setError(VBOX_E_INVALID_VM_STATE,
    778                         tr("Machine session is not open (session state: %s)."),
     777                        tr("Machine is not locked by session (session state: %s)."),
    779778                        Global::stringifySessionState(mState));
    780779    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
     
    815814    LogFlowThisFunc(("mState=%s, mType=%d\n", Global::stringifySessionState(mState), mType));
    816815
    817     if (mState != SessionState_Open)
     816    if (mState != SessionState_Locked)
    818817    {
    819818        Assert(mState == SessionState_Spawning);
     
    829828        Assert(aFromServer);
    830829
    831         mState = SessionState_Closed;
     830        mState = SessionState_Unlocked;
    832831        mType = SessionType_Null;
    833832#if defined(RT_OS_WINDOWS)
     
    846845
    847846    /* go to the closing state */
    848     mState = SessionState_Closing;
     847    mState = SessionState_Unlocking;
    849848
    850849    if (mType == SessionType_Direct)
     
    919918    }
    920919
    921     mState = SessionState_Closed;
     920    mState = SessionState_Unlocked;
    922921    mType = SessionType_Null;
    923922
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r30884 r31008  
    31203120            AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    31213121
    3122             if (mData->mSession.mState != SessionState_Open)
     3122            if (mData->mSession.mState != SessionState_Locked)
    31233123                throw setError(VBOX_E_INVALID_VM_STATE,
    3124                                 tr("Machine session is not open (session state: %s)"),
     3124                                tr("Machine is not locked by a session (session state: %s)"),
    31253125                                Global::stringifySessionState(mData->mSession.mState));
    31263126            directControl = mData->mSession.mDirectControl;
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31002 r31008  
    18721872}
    18731873
    1874 /**
    1875  *  @note Locks objects!
    1876  */
    1877 STDMETHODIMP VirtualBox::OpenSession(ISession *aSession, IN_BSTR aMachineId)
    1878 {
    1879     CheckComArgNotNull(aSession);
    1880 
    1881     AutoCaller autoCaller(this);
    1882     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1883 
    1884     Guid id(aMachineId);
    1885     ComObjPtr<Machine> machine;
    1886 
    1887     HRESULT rc = findMachine(id,
    1888                              false /* fPermitInaccessible */,
    1889                              true /* setError */,
    1890                              &machine);
    1891     if (FAILED(rc)) return rc;
    1892 
    1893     /* check the session state */
    1894     SessionState_T state;
    1895     rc = aSession->COMGETTER(State)(&state);
    1896     if (FAILED(rc)) return rc;
    1897 
    1898     if (state != SessionState_Closed)
    1899         return setError(VBOX_E_INVALID_OBJECT_STATE,
    1900                         tr("The given session is already open or being opened"));
    1901 
    1902     /* get the IInternalSessionControl interface */
    1903     ComPtr<IInternalSessionControl> control = aSession;
    1904     ComAssertMsgRet(!!control, ("No IInternalSessionControl interface"),
    1905                     E_INVALIDARG);
    1906 
    1907     rc = machine->openSession(control);
    1908 
    1909     if (SUCCEEDED(rc))
    1910     {
    1911         /*
    1912          *  tell the client watcher thread to update the set of
    1913          *  machines that have open sessions
    1914          */
    1915         updateClientWatcher();
    1916 
    1917         /* fire an event */
    1918         onSessionStateChange(id, SessionState_Open);
    1919     }
    1920 
    1921     return rc;
    1922 }
    1923 
    1924 /**
    1925  *  @note Locks objects!
    1926  */
    1927 STDMETHODIMP VirtualBox::OpenRemoteSession(ISession *aSession,
    1928                                            IN_BSTR aMachineId,
    1929                                            IN_BSTR aType,
    1930                                            IN_BSTR aEnvironment,
    1931                                            IProgress **aProgress)
    1932 {
    1933     LogRel(("remotesession=%s\n", Utf8Str(aMachineId).c_str()));
    1934 
    1935     CheckComArgStrNotEmptyOrNull(aMachineId);
    1936     CheckComArgNotNull(aSession);
    1937     CheckComArgStrNotEmptyOrNull(aType);
    1938     CheckComArgOutSafeArrayPointerValid(aProgress);
    1939 
    1940     AutoCaller autoCaller(this);
    1941     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1942 
    1943     Guid id(aMachineId);
    1944     ComObjPtr<Machine> machine;
    1945 
    1946     HRESULT rc = findMachine(id,
    1947                              false /* fPermitInaccessible */,
    1948                              true /* setError */,
    1949                              &machine);
    1950     if (FAILED(rc)) return rc;
    1951 
    1952     /* check the session state */
    1953     SessionState_T state;
    1954     rc = aSession->COMGETTER(State)(&state);
    1955     if (FAILED(rc)) return rc;
    1956 
    1957     if (state != SessionState_Closed)
    1958         return setError(VBOX_E_INVALID_OBJECT_STATE,
    1959                         tr("The given session is already open or being opened"));
    1960 
    1961     /* get the IInternalSessionControl interface */
    1962     ComPtr<IInternalSessionControl> control = aSession;
    1963     ComAssertMsgRet(!!control, ("No IInternalSessionControl interface"),
    1964                     E_INVALIDARG);
    1965 
    1966     /* get the teleporter enable state for the progress object init. */
    1967     BOOL fTeleporterEnabled;
    1968     rc = machine->COMGETTER(TeleporterEnabled)(&fTeleporterEnabled);
    1969     if (FAILED(rc))
    1970         return rc;
    1971 
    1972     /* create a progress object */
    1973     ComObjPtr<ProgressProxy> progress;
    1974     progress.createObject();
    1975     rc = progress->init(this,
    1976                         static_cast<IMachine *>(machine),
    1977                         Bstr(tr("Spawning session")),
    1978                         TRUE /* aCancelable */,
    1979                         fTeleporterEnabled ? 20 : 10 /* uTotalOperationsWeight */,
    1980                         Bstr(tr("Spawning session")),
    1981                         2 /* uFirstOperationWeight */,
    1982                         fTeleporterEnabled ? 3 : 1 /* cOtherProgressObjectOperations */);
    1983     if (SUCCEEDED(rc))
    1984     {
    1985         rc = machine->openRemoteSession(control, aType, aEnvironment, progress);
    1986         if (SUCCEEDED(rc))
    1987         {
    1988             progress.queryInterfaceTo(aProgress);
    1989 
    1990             /* signal the client watcher thread */
    1991             updateClientWatcher();
    1992 
    1993             /* fire an event */
    1994             onSessionStateChange(id, SessionState_Spawning);
    1995         }
    1996     }
    1997 
    1998     return rc;
    1999 }
    2000 
    2001 /**
    2002  *  @note Locks objects!
    2003  */
    2004 STDMETHODIMP VirtualBox::OpenExistingSession(ISession *aSession,
    2005                                              IN_BSTR  aMachineId)
    2006 {
    2007     CheckComArgNotNull(aSession);
    2008 
    2009     AutoCaller autoCaller(this);
    2010     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    2011 
    2012     Guid id(aMachineId);
    2013     ComObjPtr<Machine> machine;
    2014 
    2015     HRESULT rc = findMachine(id,
    2016                              false /* fPermitInaccessible */,
    2017                              true /* setError */,
    2018                              &machine);
    2019     if (FAILED(rc)) return rc;
    2020 
    2021     /* check the session state */
    2022     SessionState_T state;
    2023     rc = aSession->COMGETTER(State)(&state);
    2024     if (FAILED(rc)) return rc;
    2025 
    2026     if (state != SessionState_Closed)
    2027         return setError(VBOX_E_INVALID_OBJECT_STATE,
    2028                         tr("The given session is already open or being opened"));
    2029 
    2030     /* get the IInternalSessionControl interface */
    2031     ComPtr<IInternalSessionControl> control = aSession;
    2032     ComAssertMsgRet(!!control, ("No IInternalSessionControl interface"),
    2033                     E_INVALIDARG);
    2034 
    2035     rc = machine->openExistingSession(control);
    2036 
    2037     return rc;
    2038 }
    2039 
    20401874STDMETHODIMP VirtualBox::WaitForPropertyChange(IN_BSTR /* aWhat */,
    20411875                                               ULONG /* aTimeout */,
     
    38893723/**
    38903724 *  Thread function that watches the termination of all client processes
    3891  *  that have opened sessions using IVirtualBox::OpenSession()
     3725 *  that have opened sessions using IMachine::LockForSession()
    38923726 */
    38933727// static
  • trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c

    r28800 r31008  
    216216    g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType);
    217217
    218     rc = virtualBox->vtbl->OpenRemoteSession(
    219         virtualBox,
     218    rc = machine->vtbl->LaunchVMProcess(machine,
    220219        session,
    221         id,
    222220        sessionType,
    223221        env,
  • trunk/src/VBox/Main/glue/glue-java.xsl

    r30987 r31008  
    24942494    }
    24952495
    2496     public ISession openMachineSession(String mid) throws Exception
     2496    public ISession openMachineSession(IMachine m) throws Exception
    24972497    {
    24982498        ISession s = getSessionObject();
    2499         try {
    2500           this.vbox.openExistingSession(s, mid);
    2501           return s;
    2502         } catch (Exception e) {
    2503           try {
    2504             this.vbox.openSession(s, mid);
    2505             return s;
    2506           } catch (Exception e1) {
    2507             closeMachineSession(s);
    2508             throw e1;
    2509           }
    2510         }
    2511     }
    2512 
    2513     public ISession openMachineSession(IMachine m) throws Exception
    2514     {
    2515           return openMachineSession(m.getId());
     2499        m.lockForSession(s, true /* fPermitShared */);
     2500        return s;
    25162501    }
    25172502
     
    25802565        ISession session = getSessionObject();
    25812566
    2582         String mid = m.getId();
    25832567        if (type == null)
    25842568            type = "gui";
    2585         IProgress p = vbox.openRemoteSession(session, mid, type, "");
     2569        IProgress p = m.launchVMProcess(session, type, "");
    25862570        progressBar(p, timeout);
    25872571        session.close();
     
    34723456    }
    34733457
    3474     public ISession openMachineSession(String mid) throws Exception
     3458    public ISession openMachineSession(IMachine m) throws Exception
    34753459    {
    34763460        ISession s = getSessionObject();
    3477         try {
    3478           this.vbox.openExistingSession(s, mid);
    3479           return s;
    3480         } catch (Exception e) {
    3481           try {
    3482             this.vbox.openSession(s, mid);
    3483             return s;
    3484           } catch (Exception e1) {
    3485             closeMachineSession(s);
    3486             throw e1;
    3487           }
    3488         }
    3489     }
    3490 
    3491     public ISession openMachineSession(IMachine m) throws Exception
    3492     {
    3493           return openMachineSession(m.getId());
     3461        m.lockForSession(s, true /* fPermitShared */ );
     3462        return s;
    34943463    }
    34953464
     
    35403509        ISession session = getSessionObject();
    35413510
    3542         String mid = m.getId();
    35433511        if (type == null)
    35443512            type = "gui";
    3545         IProgress p = vbox.openRemoteSession(session, mid, type, "");
     3513        IProgress p = m.launchVMProcess(session, type, "");
    35463514        progressBar(p, timeout);
    35473515        session.close();
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31002 r31008  
    794794      Session state. This enumeration represents possible values of
    795795      <link to="IMachine::sessionState"/> and <link to="ISession::state"/>
    796       attributes. See individual enumerator descriptions for the meaning for
    797       every value.
     796      attributes.
    798797    </desc>
    799798
     
    801800      <desc>Null value (never used by the API).</desc>
    802801    </const>
    803     <const name="Closed"                value="1">
    804       <desc>
    805         The machine has no open sessions (<link to="IMachine::sessionState"/>);
    806         the session is closed (<link to="ISession::state"/>)
    807       </desc>
    808     </const>
    809     <const name="Open"                  value="2">
    810       <desc>
    811         The machine has an open direct session (<link to="IMachine::sessionState"/>);
    812         the session is open (<link to="ISession::state"/>)
     802    <const name="Unlocked"              value="1">
     803      <desc>
     804        In <link to="IMachine::sessionState"/>, this means that the machine
     805        is not locked for any sessions.
     806
     807        In <link to="ISession::state"/>, this means that no machine is
     808        currently locked for this session.
     809      </desc>
     810    </const>
     811    <const name="Locked"                value="2">
     812      <desc>
     813        In <link to="IMachine::sessionState"/>, this means that the machine
     814        is currently locked for a session, whose process identifier can
     815        then be found in the <link to="IMachine::sessionPid" /> attribute.
     816
     817        In <link to="ISession::state"/>, this means that a machine is
     818        currently locked for this session, and the mutable machine object
     819        can be found in the <link to="ISession::machine"/> attribute
     820        (see <link to="IMachine::lockForSession" /> for details).
    813821      </desc>
    814822    </const>
    815823    <const name="Spawning"              value="3">
    816824      <desc>
    817         A new (direct) session is being opened for the machine as a result of
    818         <link to="IVirtualBox::openRemoteSession"/> call
    819         (<link to="IMachine::sessionState"/> or <link to="ISession::state"/>).
    820         This state also occurs as a short transient state when a new direct
    821         session is opened by calling <link to="IVirtualBox::openSession"/>.
    822       </desc>
    823     </const>
    824     <const name="Closing"               value="4">
    825       <desc>
    826         The direct session is being closed (<link to="IMachine::sessionState"/>);
    827         the session is being closed (<link to="ISession::state"/>)
     825        A new process is being spawned for the machine as a result of
     826        <link to="IMachine::launchVMProcess"/> call. This state also occurs
     827        as a short transient state during an <link to="IMachine::lockForSession"/>
     828        call.
     829      </desc>
     830    </const>
     831    <const name="Unlocking"             value="4">
     832      <desc>
     833        The session is being unlocked.
    828834      </desc>
    829835    </const>
     
    914920      <desc>
    915921        Direct session
    916         (opened by <link to="IVirtualBox::openSession"/>)
     922        (used with <link to="IMachine::lockForSession"/>)
    917923      </desc>
    918924    </const>
    919925    <const name="Remote"                value="2">
    920926      <desc>
    921         Remote session
    922         (opened by <link to="IVirtualBox::openRemoteSession"/>)
    923       </desc>
    924     </const>
    925     <const name="Existing"              value="3">
    926       <desc>
    927         Existing session
    928         (opened by <link to="IVirtualBox::openExistingSession"/>)
     927        Remote VM process
     928        (opened by <link to="IMachine::launchVMProcess"/>)
     929      </desc>
     930    </const>
     931    <const name="Shared"                value="3">
     932      <desc>
     933        Shared session; remote link to an existing direct session opened
     934        by <link to="IMachine::lockForSession"/> with fPermitShared = true
    929935      </desc>
    930936    </const>
     
    22652271      <param name="value" type="wstring" dir="in">
    22662272        <desc>Value to assign to the key.</desc>
    2267       </param>
    2268     </method>
    2269 
    2270     <method name="openSession">
    2271       <desc>
    2272         Opens a new direct session with the given virtual machine.
    2273 
    2274         A direct session acts as a local lock on the given VM.
    2275         There can be only one direct session open at a time for every
    2276         virtual machine, protecting the VM from being manipulated by
    2277         conflicting actions from different processes. Only after a
    2278         direct session has been opened, one can change all VM settings
    2279         and execute the VM in the process space of the session object.
    2280 
    2281         Sessions therefore can be compared to mutex semaphores that
    2282         lock a given VM for modification and execution.
    2283         See <link to="ISession">ISession</link> for details.
    2284 
    2285         <note>Unless you are writing a new VM frontend, you will not
    2286         want to execute a VM in the current process. To spawn a new
    2287         process that executes a VM, use
    2288         <link to="IVirtualBox::openRemoteSession" />
    2289         instead.</note>
    2290 
    2291         Upon successful return, the session object can be used to
    2292         get access to the machine and to the VM console.
    2293 
    2294         In VirtualBox terminology, the machine becomes "mutable" after
    2295         a session has been opened. Note that the "mutable" machine
    2296         object, on which you may invoke IMachine methods to change its
    2297         settings, will be a different object from the immutable IMachine
    2298         objects returned by various IVirtualBox methods. To obtain a
    2299         mutable IMachine object (upon which you can invoke settings methods),
    2300         use the <link to="ISession::machine" /> attribute.
    2301 
    2302         One must always call <link to="ISession::close" /> to release the
    2303         lock on the machine, or the machine's state will eventually be
    2304         set to "Aborted".
    2305 
    2306         In other words, to change settings on a machine, the following
    2307         sequence is typically performed:
    2308 
    2309         <ol>
    2310         <li>Call this method (openSession) to have a machine locked for
    2311         the current session.</li>
    2312 
    2313         <li>Obtain a mutable IMachine object from <link to="ISession::machine" />.</li>
    2314 
    2315         <li>Change the settings of the machine.</li>
    2316 
    2317         <li>Call <link to="IMachine::saveSettings" />.</li>
    2318 
    2319         <li>Close the session by calling <link to="ISession::close"/>.</li>
    2320         </ol>
    2321 
    2322         <result name="E_UNEXPECTED">
    2323           Virtual machine not registered.
    2324         </result>
    2325         <result name="E_ACCESSDENIED">
    2326           Process not started by OpenRemoteSession.
    2327         </result>
    2328         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2329           No matching virtual machine found.
    2330         </result>
    2331         <result name="VBOX_E_INVALID_OBJECT_STATE">
    2332           Session already open or being opened.
    2333         </result>
    2334         <result name="VBOX_E_VM_ERROR">
    2335           Failed to assign machine to session.
    2336         </result>
    2337 
    2338       </desc>
    2339       <param name="session" type="ISession" dir="in">
    2340         <desc>
    2341           Session object that will represent the opened session after
    2342           successful method invocation. This object must not represent
    2343           the already open session.
    2344           <note>
    2345             This session will be automatically closed if the
    2346             VirtualBox server is terminated for some reason.
    2347           </note>
    2348         </desc>
    2349       </param>
    2350       <param name="machineId" type="uuid" mod="string" dir="in">
    2351         <desc>ID of the virtual machine to open a session with.</desc>
    2352       </param>
    2353     </method>
    2354 
    2355     <method name="openRemoteSession">
    2356       <desc>
    2357         Spawns a new process that executes a virtual machine (called a
    2358         "remote session").
    2359 
    2360         Opening a remote session causes the VirtualBox server to start a new
    2361         process that opens a direct session with the given VM. As a result, the
    2362         VM is locked by that direct session in the new process, preventing
    2363         conflicting changes from other processes. Since sessions act as locks
    2364         that prevent conflicting changes, one cannot open a remote session
    2365         for a VM that already has another open session (direct or remote), or
    2366         is currently in the process of opening one (see <link
    2367           to="IMachine::sessionState"/>).
    2368 
    2369         While the remote session still provides some level of control over the
    2370         VM execution to the caller (using the <link to="IConsole" /> interface),
    2371         not all VM settings are available for modification within the remote
    2372         session context.
    2373 
    2374         This operation can take some time (a new VM is started in a new process,
    2375         for which memory and other resources need to be set up). Because of this,
    2376         an <link to="IProgress" /> is returned to allow the caller to wait for this
    2377         asynchronous operation to be completed. Until then, the remote session
    2378         object remains in the closed state, and accessing the machine or its
    2379         console through it is invalid. It is recommended to use
    2380         <link to="IProgress::waitForCompletion" /> or similar calls to wait for
    2381         completion. Completion is signalled when the VM is powered on. Error
    2382         messages etc. can be queried via the progress object, if available.
    2383 
    2384         As with all <link to="ISession" /> objects, it is recommended to call
    2385         <link to="ISession::close" /> on the local session object once openRemoteSession()
    2386         has been called. However, the session's state (see <link to="ISession::state" />)
    2387         will not return to "Closed" until the remote session has also closed (i.e.
    2388         until the VM is no longer running). In that case, however, the state of
    2389         the session will automatically change back to "Closed".
    2390 
    2391         Currently supported session types (values of the @a type
    2392         argument) are:
    2393         <ul>
    2394           <li><tt>"gui"</tt>: VirtualBox Qt GUI session</li>
    2395           <li><tt>"vrdp"</tt>: VirtualBox VRDP Server session</li>
    2396           <li><tt>"sdl"</tt>: VirtualBox SDL GUI session</li>
    2397         </ul>
    2398 
    2399         The @a environment argument is a string containing definitions of
    2400         environment variables in the following format:
    2401         @code
    2402           NAME[=VALUE]\n
    2403           NAME[=VALUE]\n
    2404           ...
    2405         @endcode
    2406         where <tt>\\n</tt> is the new line character. These environment
    2407         variables will be appended to the environment of the VirtualBox server
    2408         process. If an environment variable exists both in the server process
    2409         and in this list, the value from this list takes precedence over the
    2410         server's variable. If the value of the environment variable is
    2411         omitted, this variable will be removed from the resulting environment.
    2412         If the environment string is @c null or empty, the server environment
    2413         is inherited by the started process as is.
    2414 
    2415         The progress object will have at least 2 operation. The first operation
    2416         covers the period up to the new VM process calls powerUp. The
    2417         subsequent operations mirrors the <link to="IConsole::powerUp"/>
    2418         progress object. Because <link to="IConsole::powerUp"/> may require
    2419         some extra operation, the <link to="IProgress::operationCount"/> may
    2420         change at the completion of operation1.
    2421 
    2422         For details on the teleportation progress operation, see
    2423         <link to="IConsole::powerUp"/>.
    2424 
    2425         <see>openExistingSession</see>
    2426 
    2427         <result name="E_UNEXPECTED">
    2428           Virtual machine not registered.
    2429         </result>
    2430         <result name="E_INVALIDARG">
    2431           Invalid session type @a type.
    2432         </result>
    2433         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2434           No machine matching @a machineId found.
    2435         </result>
    2436         <result name="VBOX_E_INVALID_OBJECT_STATE">
    2437           Session already open or being opened.
    2438         </result>
    2439         <result name="VBOX_E_IPRT_ERROR">
    2440           Launching process for machine failed.
    2441         </result>
    2442         <result name="VBOX_E_VM_ERROR">
    2443           Failed to assign machine to session.
    2444         </result>
    2445 
    2446       </desc>
    2447       <param name="session" type="ISession" dir="in">
    2448         <desc>
    2449           Session object that will represent the opened remote session
    2450           after successful method invocation (this object must not
    2451           represent an already open session).
    2452         </desc>
    2453       </param>
    2454       <param name="machineId" type="uuid" mod="string" dir="in">
    2455         <desc>ID of the virtual machine to open a session with.</desc>
    2456       </param>
    2457       <param name="type" type="wstring" dir="in">
    2458         <desc>
    2459           Type of the remote session (case sensitive).
    2460         </desc>
    2461       </param>
    2462       <param name="environment" type="wstring" dir="in">
    2463         <desc>
    2464           Environment to pass to the opened session.
    2465         </desc>
    2466       </param>
    2467       <param name="progress" type="IProgress" dir="return">
    2468         <desc>Progress object to track the operation completion.</desc>
    2469       </param>
    2470     </method>
    2471 
    2472     <method name="openExistingSession">
    2473       <desc>
    2474         Opens a new remote session with the virtual machine for
    2475         which a direct session is already open.
    2476 
    2477         The remote session provides some level of control over the VM
    2478         execution (using the IConsole interface) to the caller; however,
    2479         within the remote session context, not all VM settings are available
    2480         for modification.
    2481 
    2482         As opposed to <link to="#openRemoteSession"/>, the number of
    2483         remote sessions opened this way is not limited by the API
    2484 
    2485         <note>
    2486           It is an error to open a remote session with the machine that
    2487           doesn't have an open direct session.
    2488         </note>
    2489 
    2490         <result name="E_UNEXPECTED">
    2491           Virtual machine not registered.
    2492         </result>
    2493         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2494           No machine matching @a machineId found.
    2495         </result>
    2496         <result name="VBOX_E_INVALID_OBJECT_STATE">
    2497           Session already open or being opened.
    2498         </result>
    2499         <result name="VBOX_E_INVALID_SESSION_STATE">
    2500           Direct session state not Open.
    2501         </result>
    2502         <result name="VBOX_E_VM_ERROR">
    2503           Failed to get console object from direct session or assign
    2504           machine to session.
    2505         </result>
    2506 
    2507         <see>openRemoteSession</see>
    2508       </desc>
    2509       <param name="session" type="ISession" dir="in">
    2510         <desc>
    2511           Session object that will represent the open remote session
    2512           after successful method invocation. This object must not
    2513           represent an already open session.
    2514           <note>
    2515             This session will be automatically closed when the peer
    2516             (direct) session dies or gets closed.
    2517           </note>
    2518         </desc>
    2519       </param>
    2520       <param name="machineId" type="uuid" mod="string" dir="in">
    2521         <desc>ID of the virtual machine to open a session with.</desc>
    25222273      </param>
    25232274    </method>
     
    34573208      <desc>
    34583209        Tells VBoxSVC that <link to="IConsole::powerUp"/> is under ways and
    3459         gives it the progress object that should be part of any pending
    3460         <link to="IVirtualBox::openRemoteSession"/> operations.  The progress
    3461         object may be called back to reflect an early cancelation, so some care
    3462         have to be taken with respect to any cancelation callbacks. The console
    3463         object will call <link to="IInternalMachineControl::endPowerUp"/>
    3464         to signal the completion of the progress object.
     3210        gives it the progress object that should be part of any pending
     3211        <link to="IMachine::launchVMProcess"/> operations.  The progress
     3212        object may be called back to reflect an early cancelation, so some care
     3213        have to be taken with respect to any cancelation callbacks. The console
     3214        object will call <link to="IInternalMachineControl::endPowerUp"/>
     3215        to signal the completion of the progress object.
    34653216      </desc>
    34663217      <param name="progress" type="IProgress" dir="in"/>
     
    34723223        This method may query status information from the progress object it
    34733224        received in <link to="IInternalMachineControl::beginPowerUp"/> and copy
    3474         it over to any in progress <link to="IVirtualBox::openRemoteSession"/>
     3225        it over to any in-progress <link to="IMachine::launchVMProcess"/>
    34753226        call in order to complete that progress object.
    34763227      </desc>
     
    39013652      <link to="IVirtualBox::machines"/> collection, all attributes are
    39023653      read-only unless explicitly stated otherwise in individual attribute
    3903       and method descriptions. In order to change a machine setting, a session
    3904       for this machine must be opened using one of
    3905       <link to="IVirtualBox::openSession"/>,
    3906       <link to="IVirtualBox::openRemoteSession"/> or
    3907       <link to="IVirtualBox::openExistingSession"/> methods. After the
    3908       session has been successfully opened, a mutable machine object needs to
    3909       be queried from the session object and then the desired settings changes
    3910       can be applied to the returned object using IMachine attributes and
     3654      and method descriptions.
     3655
     3656      In order to change a machine setting, a session for this machine must be
     3657      opened using one of the <link to="IMachine::lockForSession" /> or
     3658      <link to="IMachine::launchVMProcess"/> methods. After the
     3659      machine has been successfully locked for a session, a mutable machine object
     3660      needs to be queried from the session object and then the desired settings
     3661      changes can be applied to the returned object using IMachine attributes and
    39113662      methods. See the <link to="ISession"/> interface description for more
    39123663      information about sessions.
     
    42453996        SessionSpawning or SessionOpen, this attribute contains the
    42463997        same value as passed to the
    4247         <link to="IVirtualBox::openRemoteSession"/> method in the
     3998        <link to="IMachine::launchVMProcess"/> method in the
    42483999        @a type parameter. If the session was opened directly using
    4249         <link to="IVirtualBox::openSession"/>, or if
     4000        <link to="IMachine::lockForSession" />, or if
    42504001        <link to="#sessionState"/> is SessionClosed, the value of this
    42514002        attribute is an empty string.
     
    42584009        platform-dependent identifier of the process that has opened a
    42594010        direct session for this machine using the
    4260         <link to="IVirtualBox::openSession"/> call. The returned value
     4011        <link to="IMachine::lockForSession" /> call. The returned value
    42614012        is only valid if <link to="#sessionState"/> is SessionOpen or
    42624013        SessionClosing (i.e. a session is currently open or being
     
    44414192      </desc>
    44424193    </attribute>
     4194
     4195    <method name="lockForSession">
     4196      <desc>
     4197        Locks the machine for the given session to enable the caller
     4198        to make changes to the machine or start the VM.
     4199
     4200        A single machine can only be locked for a single sesseion
     4201        at a time, protecting the VM from being manipulated by
     4202        conflicting actions from different processes. Only after this
     4203        method has been called, one can change all VM settings
     4204        or execute the VM in the process space of the session object.
     4205        See <link to="ISession">ISession</link> for details.
     4206
     4207        Locking the machine for a session creates a second copy of
     4208        the IMachine object. It is this second object upon which
     4209        changes can be made; in VirtualBox terminology, the second
     4210        copy is "mutable". It is only this second, mutable machine
     4211        object upon which you can call methods that change the
     4212        machine state. After having called this method, you can
     4213        obtain this second, mutable machine object using the
     4214        <link to="ISession::machine" /> attribute. This way, you can
     4215        also get access to the <link to="IConsole" /> object which
     4216        controls VM execution.
     4217
     4218        <note>Unless you are writing a new VM frontend, you will not
     4219        want to execute a VM in the current process. To spawn a new
     4220        process that executes a VM, use <link to="IMachine::launchVMProcess" />
     4221        instead.</note>
     4222
     4223        One must always call <link to="ISession::close" /> to release the
     4224        lock on the machine, or the machine's state will eventually be
     4225        set to "Aborted".
     4226
     4227        In other words, to change settings on a machine, the following
     4228        sequence is typically performed:
     4229
     4230        <ol>
     4231          <li>Call this method (openSession) to have a machine locked for
     4232            the current session.</li>
     4233
     4234          <li>Obtain a mutable IMachine object from <link to="ISession::machine" />.</li>
     4235
     4236          <li>Change the settings of the machine.</li>
     4237
     4238          <li>Call <link to="IMachine::saveSettings" />.</li>
     4239
     4240          <li>Close the session by calling <link to="ISession::close"/>.</li>
     4241        </ol>
     4242
     4243        If the @a fPermitShared parameter is set to true, this method will also
     4244        succeed on a machine which has already been locked by another session.
     4245        The caller will then be attached to that existing session, and its own
     4246        session will be marked as "Shared". While not all machine settings can
     4247        be changed in that case, an IConsole object will still be created which
     4248        provides to the caller some level of control over the VM execution, for
     4249        example to pause the machine. The number of such shared sessions per
     4250        machine is not limited by the API.
     4251
     4252        The return value will then indicate whether a direct session was opened
     4253        (<link to="SessionType::Direct" />) or whether an existing direct session
     4254        was shared ((<link to="SessionType::Shared" />).
     4255
     4256        If the @a fPermitShared parameter is @c false, then this can only
     4257        possibly return <link to="SessionType::Direct" />.
     4258
     4259        <result name="E_UNEXPECTED">
     4260          Virtual machine not registered.
     4261        </result>
     4262        <result name="E_ACCESSDENIED">
     4263          Process not started by OpenRemoteSession.
     4264        </result>
     4265        <result name="VBOX_E_INVALID_OBJECT_STATE">
     4266          Session already open or being opened.
     4267        </result>
     4268        <result name="VBOX_E_VM_ERROR">
     4269          Failed to assign machine to session.
     4270        </result>
     4271      </desc>
     4272      <param name="session" type="ISession" dir="in">
     4273        <desc>
     4274          Session object for which the machine will be locked.
     4275        </desc>
     4276      </param>
     4277      <param name="fPermitShared" type="boolean" dir="in">
     4278        <desc>
     4279          Whether to allow for sharing a direct session remotely.
     4280        </desc>
     4281      </param>
     4282      <param name="sessionType" type="SessionType" dir="return">
     4283        <desc>
     4284        </desc>
     4285      </param>
     4286    </method>
     4287
     4288    <method name="launchVMProcess">
     4289      <desc>
     4290        Spawns a new process that will execute the virtual machine.
     4291
     4292        This operation can take some time (a new VM is started in a new process,
     4293        for which memory and other resources need to be set up). Because of this,
     4294        an <link to="IProgress" /> object is returned to allow the caller to wait
     4295        for this asynchronous operation to be completed. Until then, the caller's
     4296        session object remains in the "Unlocked" state, and its <link to="ISession::machine" />
     4297        and <link to="ISession::console" /> attributes cannot be accessed.
     4298        It is recommended to use <link to="IProgress::waitForCompletion" /> or
     4299        similar calls to wait for completion. Completion is signalled when the VM
     4300        is powered on. If launching the VM fails, error messages can be queried
     4301        via the progress object, if available.
     4302
     4303        If launching the VM succeeds, the new VM process will create its own
     4304        session and lock the machine for it, preventing conflicting changes
     4305        from other processes. If the machine is already locked (because it
     4306        is already running or because another session is making changes),
     4307        launching the VM process will therefore fail. Reversely, future
     4308        locking attempts will also fail while the machine is running.
     4309
     4310        The caller's session object remains separate from the session opened
     4311        by the new VM process. It receives its own <link to="IConsole" />
     4312        object which can be used to control machine execution, but it cannot
     4313        be used to change all VM settings which would be available after
     4314        a <link to="#lockForSession" /> call.
     4315
     4316        As with all <link to="ISession" /> objects, it is recommended to call
     4317        <link to="ISession::close" /> on the local session object once this call
     4318        has returned. However, the session's state (see <link to="ISession::state" />)
     4319        will not return to "Unlocked" until the remote session has also unlocked
     4320        the machine.
     4321
     4322        The @a environment argument is a string containing definitions of
     4323        environment variables in the following format:
     4324        @code
     4325        NAME[=VALUE]\n
     4326        NAME[=VALUE]\n
     4327        ...
     4328        @endcode
     4329        where <tt>\\n</tt> is the new line character. These environment
     4330        variables will be appended to the environment of the VirtualBox server
     4331        process. If an environment variable exists both in the server process
     4332        and in this list, the value from this list takes precedence over the
     4333        server's variable. If the value of the environment variable is
     4334        omitted, this variable will be removed from the resulting environment.
     4335        If the environment string is @c null or empty, the server environment
     4336        is inherited by the started process as is.
     4337
     4338        The progress object will have at least 2 sub-operations. The first
     4339        operation covers the period up to the new VM process calls powerUp.
     4340        The subsequent operations mirror the <link to="IConsole::powerUp"/>
     4341        progress object. Because <link to="IConsole::powerUp"/> may require
     4342        some extra sub-operations, the <link to="IProgress::operationCount"/>
     4343        may change at the completion of operation.
     4344
     4345        For details on the teleportation progress operation, see
     4346        <link to="IConsole::powerUp"/>.
     4347
     4348        <result name="E_UNEXPECTED">
     4349          Virtual machine not registered.
     4350        </result>
     4351        <result name="E_INVALIDARG">
     4352          Invalid session type @a type.
     4353        </result>
     4354        <result name="VBOX_E_OBJECT_NOT_FOUND">
     4355          No machine matching @a machineId found.
     4356        </result>
     4357        <result name="VBOX_E_INVALID_OBJECT_STATE">
     4358          Session already open or being opened.
     4359        </result>
     4360        <result name="VBOX_E_IPRT_ERROR">
     4361          Launching process for machine failed.
     4362        </result>
     4363        <result name="VBOX_E_VM_ERROR">
     4364          Failed to assign machine to session.
     4365        </result>
     4366      </desc>
     4367      <param name="session" type="ISession" dir="in">
     4368        <desc>
     4369          Session object that will represent the opened remote session
     4370          after successful method invocation (this object must not
     4371          represent an already open session).
     4372        </desc>
     4373      </param>
     4374      <param name="type" type="wstring" dir="in">
     4375        <desc>
     4376          Type of the remote session (case sensitive). The following are
     4377          currently supported:
     4378          <ul>
     4379            <li><tt>"gui"</tt>: VirtualBox Qt GUI front-end</li>
     4380            <li><tt>"vrdp"</tt>: VBoxHeadless (VRDP Server) front-end</li>
     4381            <li><tt>"sdl"</tt>: VirtualBox SDL front-end</li>
     4382          </ul>
     4383        </desc>
     4384      </param>
     4385      <param name="environment" type="wstring" dir="in">
     4386        <desc>
     4387          Environment to pass to the VM process.
     4388        </desc>
     4389      </param>
     4390      <param name="progress" type="IProgress" dir="return">
     4391        <desc>Progress object to track the operation completion.</desc>
     4392      </param>
     4393    </method>
    44434394
    44444395    <method name="setBootOrder">
     
    59725923      machine execution.
    59735924
    5974       The console object that implements the IConsole interface is obtained
    5975       from a session object after the session for the given machine has been
    5976       opened using one of <link to="IVirtualBox::openSession"/>,
    5977       <link to="IVirtualBox::openRemoteSession"/> or
    5978       <link to="IVirtualBox::openExistingSession"/> methods.
     5925      A console object gets created when a machine has been locked for a
     5926      particular session (client process) using <link to="IMachine::lockForSession" />
     5927      or <link to="IMachine::launchVMProcess"/>. The console object can
     5928      then be found in the session's <link to="ISession::console" /> attribute.
    59795929
    59805930      Methods of the IConsole interface allow the caller to query the current
     
    60996049        current storage devices).
    61006050
     6051        <note>
     6052          This method is only useful for front-ends that want to actually
     6053          execute virtual machines in their own process (like the VirtualBox
     6054          or VBoxSDL front-ends). Unless you are intending to write such a
     6055          front-end, do not call this method.  If you simply want to
     6056          start virtual machine execution using one of the existing front-ends
     6057          (for example the VirtualBox GUI or headless server), use
     6058          <link to="IMachine::launchVMProcess"/> instead; these
     6059          front-ends will power up the machine automatically for you.
     6060        </note>
     6061
    61016062        If the machine is powered off or aborted, the execution will
    61026063        start from the beginning (as if the real hardware were just
     
    61156076        (3) perform teleportation. These operations will be reflected as the
    61166077        last three operations of the progress objected returned by
    6117         <link to="IVirtualBox::openRemoteSession"/> as well.
    6118 
    6119         <note>
    6120           Unless you are trying to write a new VirtualBox front-end that
    6121           performs direct machine execution (like the VirtualBox or VBoxSDL
    6122           front-ends), don't call <link to="IConsole::powerUp"/> in a direct
    6123           session opened by <link to="IVirtualBox::openSession"/> and use this
    6124           session only to change virtual machine settings. If you simply want to
    6125           start virtual machine execution using one of the existing front-ends
    6126           (for example the VirtualBox GUI or headless server), simply use
    6127           <link to="IVirtualBox::openRemoteSession"/>; these front-ends will
    6128           power up the machine automatically for you.
    6129         </note>
     6078        <link to="IMachine::launchVMProcess"/> as well.
    61306079
    61316080        <see>#saveState</see>
     6081
    61326082        <result name="VBOX_E_INVALID_VM_STATE">
    61336083          Virtual machine already running.
     
    1279512745    <desc>
    1279612746      The ISession interface represents a serialization primitive for virtual
    12797       machines.
    12798 
    12799       With VirtualBox, every time one wishes to manipulate a virtual machine
    12800       (e.g. change its settings or start execution), a session object is
    12801       required. Such an object must be passed to one of the session methods
    12802       that open the given session, which then initiates the machine manipulation.
    12803 
    12804       A session serves several purposes: it identifies to the inter-process VirtualBox
    12805       code which process is currently working with the virtual machine, and it ensures
    12806       that there are no incompatible requests from several processes for the
    12807       same virtual machine. Session objects can therefore be thought of as mutex
    12808       semaphores that lock virtual machines to prevent conflicting accesses from
    12809       several processes.
     12747      machines. Any caller wishing to manipulate a virtual machine (represented
     12748      by an IMachine object) needs to create a session object first, which lives
     12749      in its own process space. Such session objects are then attached to the
     12750      <link to="IMachine" /> objects living in the VirtualBox server process to
     12751      coordinate possibly conflicting changes.
     12752
     12753      There are two typical scenarios in which sessions are used:
     12754
     12755      <ul>
     12756        <li>To alter machine settings, one needs to lock a machine for a given session
     12757          (client process) by calling <link to="IMachine::lockForSession"/>. While a
     12758          machine is thus locked, no any other process may lock the machine again.
     12759
     12760          The same applies for any process which indends to actually run a virtual
     12761          machine in its own context, such as the VirtualBox GUI or VBoxHeadless
     12762          executables. They must also lock a machine for their own sessions before
     12763          being allowed to power up the virtual machine.
     12764
     12765          As a result, no machine can be altered while another process is already
     12766          using it, either because that process is modifying machine settings or
     12767          because the machine is running.
     12768        </li>
     12769        <li>
     12770          To initiate virtual machine execution using one of the existing VirtualBox
     12771          front-ends (e.g. the GUI or VBoxHeadless), one would instead call
     12772          <link to="IMachine::launchVMProcess"/>, which also requires a session
     12773          object as its first parameter. This session then identifies the caller
     12774          and lets the caller control the started machine (for example, pause machine
     12775          execution or power it down) as well as be notified about machine execution
     12776          state changes.
     12777        </li>
     12778      </ul>
    1281012779
    1281112780      How sessions objects are used depends on whether you use the Main API
     
    1281312782
    1281412783      <ul>
    12815       <li>When using the COM API directly, an object of the Session class from the
    12816       VirtualBox type library needs to be created. In regular COM C++ client code,
    12817       this can be done by calling <tt>createLocalObject()</tt>, a standard COM API.
    12818       This object will  then act as a local session object in further calls to open
    12819       a session.
    12820       </li>
    12821 
    12822       <li>In the webservice, the session manager (IWebsessionManager) instead creates
    12823       one session object automatically when <link to="IWebsessionManager::logon" />
    12824       is called. A managed object reference to that session object can be retrieved by
    12825       calling <link to="IWebsessionManager::getSessionObject" />. This session object
    12826       reference can then be used to open sessions.
    12827       </li>
     12784        <li>When using the COM API directly, an object of the Session class from the
     12785          VirtualBox type library needs to be created. In regular COM C++ client code,
     12786          this can be done by calling <tt>createLocalObject()</tt>, a standard COM API.
     12787          This object will  then act as a local session object in further calls to open
     12788          a session.
     12789        </li>
     12790
     12791        <li>In the webservice, the session manager (IWebsessionManager) instead creates
     12792          a session object automatically whenever <link to="IWebsessionManager::logon" />
     12793          is called. A managed object reference to that session object can be retrieved by
     12794          calling <link to="IWebsessionManager::getSessionObject" />.
     12795        </li>
    1282812796      </ul>
    12829 
    12830       Sessions are mainly used in two variations:
    12831 
    12832       <ul>
    12833       <li>
    12834       To start a virtual machine in a separate process, one would call
    12835       <link to="IVirtualBox::openRemoteSession"/>, which requires a session
    12836       object as its first parameter. This session then identifies the caller
    12837       and lets him control the started machine (for example, pause machine
    12838       execution or power it down) as well as be notified about machine
    12839       execution state changes.
    12840       </li>
    12841 
    12842       <li>To alter machine settings, or to start machine execution within the
    12843       current process, one needs to open a direct session for the machine first by
    12844       calling <link to="IVirtualBox::openSession"/>. While a direct session
    12845       is open within one process, no any other process may open another direct
    12846       session for the same machine. This prevents the machine from being changed
    12847       by other processes while it is running or while the machine is being configured.
    12848       </li>
    12849       </ul>
    12850 
    12851       One also can attach to an existing direct session already opened by
    12852       another process (for example, in order to send a control request to the
    12853       virtual machine such as the pause or the reset request). This is done by
    12854       calling <link to="IVirtualBox::openExistingSession"/>.
    12855 
    12856       <note>
    12857         Unless you are trying to write a new VirtualBox front-end that
    12858         performs direct machine execution (like the VirtualBox or VBoxSDL
    12859         front-ends), don't call <link to="IConsole::powerUp"/> in a direct
    12860         session opened by <link to="IVirtualBox::openSession"/> and use this
    12861         session only to change virtual machine settings. If you simply want to
    12862         start virtual machine execution using one of the existing front-ends
    12863         (for example the VirtualBox GUI or headless server), simply use
    12864         <link to="IVirtualBox::openRemoteSession"/>; these front-ends
    12865         will power up the machine automatically for you.
    12866       </note>
    1286712797    </desc>
    1286812798
     
    1287412804      <desc>
    1287512805        Type of this session. The value of this attribute is valid only
    12876         if the session is currently open (i.e. its #state is
    12877         SessionType_SessionOpen), otherwise an error will be returned.
     12806        if the session is currently open (i.e. its <link to="#state" /> is
     12807        SessionState_SessionOpen), otherwise an error will be returned.
    1287812808      </desc>
    1287912809    </attribute>
     
    1289112821        Closes a session that was previously opened.
    1289212822
    12893         It is recommended that every time an "open session" method (such as
    12894         <link to="IVirtualBox::openRemoteSession" /> or
    12895         <link to="IVirtualBox::openSession" />) has been called to
    12896         manipulate a virtual machine, the caller invoke
    12897         ISession::close() when it's done doing so. Since sessions are
    12898         serialization primitives much like ordinary mutexes, they are
    12899         best used the same way: for each "open" call, there should be
    12900         a matching "close" call, even when errors occur.
    12901 
    12902         Otherwise, if a direct session for a machine opened with
    12903         <link to="IVirtualBox::openSession"/> is not explicitly closed
    12904         when the application terminates, the state of the machine will
    12905         be set to <link to="MachineState_Aborted" /> on the server.
     12823        Calling this method is eventually required every time a machine has been
     12824        locked for a particular session using the <link to="IMachine::launchVMProcess" />
     12825        or <link to="IMachine::lockForSession" />) calls. Otherwise the state of
     12826        the machine will be set to <link to="MachineState_Aborted" /> on the
     12827        server, and changes made to the machine settings will be lost.
    1290612828
    1290712829        Generally, it is recommended to close all open sessions explicitly
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r30881 r31008  
    127127struct MyHardDiskAttachment
    128128{
    129     Bstr                bstrUuid;
    130129    ComPtr<IMachine>    pMachine;
    131130    Bstr                controllerType;
  • trunk/src/VBox/Main/include/MachineImpl.h

    r31002 r31008  
    115115        struct Session
    116116        {
    117             /** Control of the direct session opened by openSession() */
     117            /** Control of the direct session opened by lockForSession() */
    118118            ComPtr<IInternalSessionControl> mDirectControl;
    119119
     
    455455
    456456    // IMachine methods
     457    STDMETHOD(LockForSession)(ISession *aSession, BOOL fPermitShared, SessionType_T *sessionType);
     458    STDMETHOD(LaunchVMProcess)(ISession *aSession,  IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
     459
    457460    STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
    458461    STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31002 r31008  
    155155    STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
    156156    STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
    157     STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
    158     STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
    159                                   IN_BSTR aType, IN_BSTR aEnvironment,
    160                                   IProgress **aProgress);
    161     STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
    162157
    163158    STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
  • trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp

    r28800 r31008  
    266266        }
    267267
    268         nsXPIDLString machineUUID;
    269         machine->GetId(getter_Copies(machineUUID));
    270         rc = virtualBox->OpenSession(session, machineUUID);
     268        machine->LockForSession(session, false /* fPermitShared */, NULL);
    271269        if (NS_FAILED(rc))
    272270        {
  • trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp

    r30269 r31008  
    209209
    210210            /* Start a VM session using the delivered VBox GUI. */
    211             rc = virtualBox->OpenRemoteSession (session, guid, sessiontype,
    212                                                 NULL, &progress);
     211            rc = machine->LaunchVMProcess(session, sessiontype,
     212                                          NULL, &progress);
    213213            if (!SUCCEEDED(rc))
    214214            {
  • trunk/src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java

    r30170 r31008  
    227227                String env = "DISPLAY=:0.0";
    228228                IProgress oProgress =
    229                     vbox.openRemoteSession(oSession,
    230                                             uuid,
    231                                             sessionType,
    232                                             env);
     229                    oMachine.launchVMProcess(oSession,
     230                                             sessionType,
     231                                             env);
    233232                System.out.println("Session for VM " + uuid + " is opening...");
    234233                oProgress.waitForCompletion(10000);
  • trunk/src/libs/xpcom18a4/java/src/org/virtualbox/VirtualBoxManager.java

    r29230 r31008  
    106106
    107107
    108         String mid = m.getId();
    109108        if (type == null)
    110109            type = "gui";
    111         IProgress p = vbox.openRemoteSession(session, mid, type, "");
     110        IProgress p = m.openRemoteSession(session, type, "");
    112111        progressBar(p, timeout);
    113112        session.close();
Note: See TracChangeset for help on using the changeset viewer.

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