VirtualBox

Changeset 35460 in vbox


Ignore:
Timestamp:
Jan 10, 2011 2:24:13 PM (14 years ago)
Author:
vboxsync
Message:

Main/Console+Machine: move PowerDown progress object to VBoxSVC, plus VMTask cleanup

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r35358 r35460  
    33<!--
    44
    5     Copyright (C) 2006-2010 Oracle Corporation
     5    Copyright (C) 2006-2011 Oracle Corporation
    66
    77    This file is part of VirtualBox Open Source Edition (OSE), as
     
    29072907  <interface
    29082908    name="IInternalMachineControl" extends="$unknown"
    2909     uuid="476126af-e223-4490-a8a0-b1f1575be013"
     2909    uuid="8e723ab0-812c-5662-dd8e-7ebc89637acf"
    29102910    internal="yes"
    29112911    wsmap="suppress"
     
    29572957      </desc>
    29582958      <param name="result" type="long" dir="in"/>
     2959    </method>
     2960
     2961    <method name="beginPoweringDown">
     2962      <desc>
     2963        Called by the VM process to inform the server it wants to
     2964        stop the VM execution and power down.
     2965      </desc>
     2966      <param name="progress" type="IProgress" dir="out">
     2967        <desc>
     2968          Progress object created by VBoxSVC to wait until
     2969          the VM is powered down.
     2970        </desc>
     2971      </param>
     2972    </method>
     2973
     2974    <method name="endPoweringDown">
     2975      <desc>
     2976        Called by the VM process to inform the server that powering
     2977        down previously requested by #beginPoweringDown is either
     2978        successfully finished or there was a failure.
     2979
     2980        <result name="VBOX_E_FILE_ERROR">
     2981          Settings file not accessible.
     2982        </result>
     2983        <result name="VBOX_E_XML_ERROR">
     2984          Could not parse the settings file.
     2985        </result>
     2986
     2987      </desc>
     2988
     2989      <param name="result" type="long" dir="in">
     2990        <desc>@c S_OK to indicate success.
     2991        </desc>
     2992      </param>
     2993      <param name="errMsg" type="wstring" dir="in">
     2994        <desc>@c human readable error message in case of failure.
     2995        </desc>
     2996      </param>
    29592997    </method>
    29602998
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r35369 r35460  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    435435
    436436    HRESULT powerUp(IProgress **aProgress, bool aPaused);
    437     HRESULT powerDown(Progress *aProgress = NULL);
     437    HRESULT powerDown(IProgress *aProgress = NULL);
    438438
    439439    HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
  • trunk/src/VBox/Main/include/MachineImpl.h

    r35358 r35460  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    927927    STDMETHOD(BeginPowerUp)(IProgress *aProgress);
    928928    STDMETHOD(EndPowerUp)(LONG iResult);
     929    STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
     930    STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
    929931    STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
    930932    STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r35421 r35460  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    142142struct VMTask
    143143{
    144     VMTask(Console *aConsole, bool aUsesVMPtr)
     144    VMTask(Console *aConsole,
     145           Progress *aProgress,
     146           const ComPtr<IProgress> &aServerProgress,
     147           bool aUsesVMPtr)
    145148        : mConsole(aConsole),
    146149          mConsoleCaller(aConsole),
     150          mProgress(aProgress),
     151          mServerProgress(aServerProgress),
    147152          mVMCallerAdded(false)
    148153    {
     
    178183    const ComObjPtr<Console> mConsole;
    179184    AutoCaller mConsoleCaller;
     185    const ComObjPtr<Progress> mProgress;
     186    Utf8Str mErrorMsg;
     187    const ComPtr<IProgress> mServerProgress;
    180188
    181189private:
     
    185193};
    186194
    187 struct VMProgressTask : public VMTask
    188 {
    189     VMProgressTask(Console *aConsole,
    190                    Progress *aProgress,
    191                    bool aUsesVMPtr)
    192         : VMTask(aConsole, aUsesVMPtr),
    193           mProgress(aProgress)
    194     {}
    195 
    196     const ComObjPtr<Progress> mProgress;
    197 
    198     Utf8Str mErrorMsg;
    199 };
    200 
    201 struct VMTakeSnapshotTask : public VMProgressTask
     195struct VMTakeSnapshotTask : public VMTask
    202196{
    203197    VMTakeSnapshotTask(Console *aConsole,
     
    205199                       IN_BSTR aName,
    206200                       IN_BSTR aDescription)
    207         : VMProgressTask(aConsole, aProgress, false /* aUsesVMPtr */),
     201        : VMTask(aConsole, aProgress, NULL /* aServerProgress */,
     202                 false /* aUsesVMPtr */),
    208203          bstrName(aName),
    209204          bstrDescription(aDescription),
     
    219214};
    220215
    221 struct VMPowerUpTask : public VMProgressTask
     216struct VMPowerUpTask : public VMTask
    222217{
    223218    VMPowerUpTask(Console *aConsole,
    224219                  Progress *aProgress)
    225         : VMProgressTask(aConsole, aProgress, false /* aUsesVMPtr */),
     220        : VMTask(aConsole, aProgress, NULL /* aServerProgress */,
     221                 false /* aUsesVMPtr */),
    226222          mConfigConstructor(NULL),
    227223          mStartPaused(false),
     
    242238};
    243239
    244 struct VMSaveTask : public VMProgressTask
    245 {
    246     VMSaveTask(Console *aConsole, Progress *aProgress, const ComPtr<IProgress> &aServerProgress)
    247         : VMProgressTask(aConsole, aProgress, true /* aUsesVMPtr */),
    248           mLastMachineState(MachineState_Null),
    249           mServerProgress(aServerProgress)
     240struct VMPowerDownTask : public VMTask
     241{
     242    VMPowerDownTask(Console *aConsole,
     243                    const ComPtr<IProgress> &aServerProgress,
     244                    MachineState_T aLastMachineState)
     245        : VMTask(aConsole, NULL /* aProgress */, aServerProgress,
     246                 true /* aUsesVMPtr */),
     247          mLastMachineState(aLastMachineState)
     248    {}
     249
     250    MachineState_T mLastMachineState;
     251};
     252
     253struct VMSaveTask : public VMTask
     254{
     255    VMSaveTask(Console *aConsole,
     256               const ComPtr<IProgress> &aServerProgress,
     257               const Utf8Str &aSavedStateFile,
     258               MachineState_T aLastMachineState)
     259        : VMTask(aConsole, NULL /* aProgress */, aServerProgress,
     260                 true /* aUsesVMPtr */),
     261          mSavedStateFile(aSavedStateFile),
     262          mLastMachineState(aLastMachineState)
    250263    {}
    251264
    252265    Utf8Str mSavedStateFile;
    253266    MachineState_T mLastMachineState;
    254     ComPtr<IProgress> mServerProgress;
    255267};
    256268
     
    13981410    {
    13991411        LogFunc(("Console::doGuestPropNotification: hrc=%Rhrc pCBData={.pcszName=%s, .pcszValue=%s, .pcszFlags=%s}\n",
    1400                  pCBData->pcszName, pCBData->pcszValue, pCBData->pcszFlags));
     1412                 hrc, pCBData->pcszName, pCBData->pcszValue, pCBData->pcszFlags));
    14011413        rc = Global::vboxStatusCodeFromCOM(hrc);
    14021414    }
     
    17231735STDMETHODIMP Console::PowerDown(IProgress **aProgress)
    17241736{
    1725     if (aProgress == NULL)
    1726         return E_POINTER;
    1727 
    17281737    LogFlowThisFuncEnter();
    17291738    LogFlowThisFunc(("mMachineState=%d\n", mMachineState));
     1739
     1740    CheckComArgOutPointerValid(aProgress);
    17301741
    17311742    AutoCaller autoCaller(this);
     
    17851796    LogFlowThisFunc(("Initiating SHUTDOWN request...\n"));
    17861797
    1787     /* create an IProgress object to track progress of this operation */
    1788     ComObjPtr<Progress> pProgress;
    1789     pProgress.createObject();
    1790     pProgress->init(static_cast<IConsole *>(this),
    1791                     Bstr(tr("Stopping virtual machine")).raw(),
    1792                     FALSE /* aCancelable */);
    1793 
    1794     /* setup task object and thread to carry out the operation asynchronously */
    1795     std::auto_ptr<VMProgressTask> task(new VMProgressTask(this, pProgress, true /* aUsesVMPtr */));
    1796     AssertReturn(task->isOk(), E_FAIL);
    1797 
    1798     int vrc = RTThreadCreate(NULL, Console::powerDownThread,
    1799                              (void *) task.get(), 0,
    1800                              RTTHREADTYPE_MAIN_WORKER, 0,
    1801                              "VMPowerDown");
    1802     if (RT_FAILURE(vrc))
    1803         return setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
    1804 
    1805     /* task is now owned by powerDownThread(), so release it */
    1806     task.release();
    1807 
    1808     /* go to Stopping state to forbid state-dependent operations */
    1809     setMachineState(MachineState_Stopping);
    1810 
    1811     /* pass the progress to the caller */
    1812     pProgress.queryInterfaceTo(aProgress);
    1813 
     1798    /* memorize the current machine state */
     1799    MachineState_T lastMachineState = mMachineState;
     1800
     1801    HRESULT rc = S_OK;
     1802    bool fBeganPowerDown = false;
     1803
     1804    do
     1805    {
     1806        ComPtr<IProgress> pProgress;
     1807
     1808        /*
     1809         * request a progress object from the server
     1810         * (this will set the machine state to Stopping on the server to block
     1811         * others from accessing this machine)
     1812         */
     1813        rc = mControl->BeginPoweringDown(pProgress.asOutParam());
     1814        if (FAILED(rc))
     1815            break;
     1816
     1817        fBeganPowerDown = true;
     1818
     1819        /* sync the state with the server */
     1820        setMachineStateLocally(MachineState_Stopping);
     1821
     1822        /* setup task object and thread to carry out the operation asynchronously */
     1823        std::auto_ptr<VMPowerDownTask> task(new VMPowerDownTask(this, pProgress,
     1824                                                                lastMachineState));
     1825        AssertBreakStmt(task->isOk(), rc = E_FAIL);
     1826
     1827        int vrc = RTThreadCreate(NULL, Console::powerDownThread,
     1828                                 (void *) task.get(), 0,
     1829                                 RTTHREADTYPE_MAIN_WORKER, 0,
     1830                                 "VMPowerDown");
     1831        if (RT_FAILURE(vrc))
     1832        {
     1833            rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
     1834            break;
     1835        }
     1836
     1837        /* task is now owned by powerDownThread(), so release it */
     1838        task.release();
     1839
     1840        /* pass the progress to the caller */
     1841        pProgress.queryInterfaceTo(aProgress);
     1842    }
     1843    while (0);
     1844
     1845    if (FAILED(rc))
     1846    {
     1847        /* preserve existing error info */
     1848        ErrorInfoKeeper eik;
     1849
     1850        if (fBeganPowerDown)
     1851        {
     1852            /*
     1853             * cancel the requested power down procedure.
     1854             * This will reset the machine state to the state it had right
     1855             * before calling mControl->BeginPoweringDown().
     1856             */
     1857            mControl->EndPoweringDown(eik.getResultCode(), eik.getText().raw());        }
     1858
     1859        setMachineStateLocally(lastMachineState);
     1860    }
     1861
     1862    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    18141863    LogFlowThisFuncLeave();
    18151864
    1816     return S_OK;
     1865    return rc;
    18171866}
    18181867
     
    18481897                 vrc);
    18491898
    1850     LogFlowThisFunc(("mMachineState=%d, rc=%08X\n", mMachineState, rc));
     1899    LogFlowThisFunc(("mMachineState=%d, rc=%Rhrc\n", mMachineState, rc));
    18511900    LogFlowThisFuncLeave();
    18521901    return rc;
     
    19782027                      tr("Hot-Remove was aborted because the CPU may still be used by the guest"), VERR_RESOURCE_BUSY);
    19792028
    1980     LogFlowThisFunc(("mMachineState=%d, rc=%08X\n", mMachineState, rc));
     2029    LogFlowThisFunc(("mMachineState=%d, rc=%Rhrc\n", mMachineState, rc));
    19812030    LogFlowThisFuncLeave();
    19822031    return rc;
     
    20952144    }
    20962145
    2097     LogFlowThisFunc(("mMachineState=%d, rc=%08X\n", mMachineState, rc));
     2146    LogFlowThisFunc(("mMachineState=%d, rc=%Rhrc\n", mMachineState, rc));
    20982147    LogFlowThisFuncLeave();
    20992148    return rc;
     
    21862235                 vrc);
    21872236
    2188     LogFlowThisFunc(("rc=%08X\n", rc));
     2237    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    21892238    LogFlowThisFuncLeave();
    21902239    return rc;
     
    22242273                 vrc);
    22252274
    2226     LogFlowThisFunc(("rc=%08X\n", rc));
     2275    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    22272276    LogFlowThisFuncLeave();
    22282277    return rc;
     
    22682317    *aHandled = handled;
    22692318
    2270     LogFlowThisFunc(("rc=%08X\n", rc));
     2319    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    22712320    LogFlowThisFuncLeave();
    22722321    return rc;
     
    23432392            vrc);
    23442393
    2345     LogFlowThisFunc(("rc=%08X\n", rc));
     2394    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    23462395    LogFlowThisFuncLeave();
    23472396    return rc;
     
    23992448        /* sync the state with the server */
    24002449        setMachineStateLocally(MachineState_Saving);
    2401 
    2402         /* create a task object early to ensure mpVM protection is successful */
    2403         std::auto_ptr<VMSaveTask> task(new VMSaveTask(this, NULL, pProgress));
    2404         rc = task->rc();
    2405         /*
    2406          * If we fail here it means a PowerDown() call happened on another
    2407          * thread while we were doing Pause() (which leaves the Console lock).
    2408          * We assign PowerDown() a higher precedence than SaveState(),
    2409          * therefore just return the error to the caller.
    2410          */
    2411         if (FAILED(rc))
    2412         {
    2413             fTaskCreationFailed = true;
    2414             break;
    2415         }
    24162450
    24172451        /* ensure the directory for the saved state file exists */
     
    24322466        }
    24332467
    2434         /* setup task object and thread to carry out the operation asynchronously */
    2435         task->mSavedStateFile = stateFilePath;
    2436         /* set the state the operation thread will restore when it is finished */
    2437         task->mLastMachineState = lastMachineState;
     2468        /* create a task object early to ensure mpVM protection is successful */
     2469        std::auto_ptr<VMSaveTask> task(new VMSaveTask(this, pProgress,
     2470                                                      stateFilePath,
     2471                                                      lastMachineState));
     2472        rc = task->rc();
     2473        /*
     2474         * If we fail here it means a PowerDown() call happened on another
     2475         * thread while we were doing Pause() (which leaves the Console lock).
     2476         * We assign PowerDown() a higher precedence than SaveState(),
     2477         * therefore just return the error to the caller.
     2478         */
     2479        if (FAILED(rc))
     2480        {
     2481            fTaskCreationFailed = true;
     2482            break;
     2483        }
    24382484
    24392485        /* create a thread to wait until the VM state is saved */
     
    24802526    }
    24812527
    2482     LogFlowThisFunc(("rc=%08X\n", rc));
     2528    LogFlowThisFunc(("rc=%Rhrc\n", rc));
    24832529    LogFlowThisFuncLeave();
    24842530    return rc;
     
    29172963{
    29182964    LogFlowThisFuncEnter();
    2919     LogFlowThisFunc(("aName='%ls' mMachineState=%08X\n", aName, mMachineState));
     2965    LogFlowThisFunc(("aName='%ls' mMachineState=%d\n", aName, mMachineState));
    29202966
    29212967    CheckComArgStrNotEmptyOrNull(aName);
     
    30373083    {
    30383084        delete pTask;
    3039         NOREF(erc);
     3085        rc = erc;
    30403086        mptrCancelableProgress.setNull();
    30413087    }
     
    53075353 * @param   aProgress       Where to return the progress object.
    53085354 * @param   aPaused         true if PowerUpPaused called.
    5309  *
    5310  * @todo move down to powerDown();
    53115355 */
    53125356HRESULT Console::powerUp(IProgress **aProgress, bool aPaused)
    53135357{
    5314     if (aProgress == NULL)
    5315         return E_POINTER;
    5316 
    53175358    LogFlowThisFuncEnter();
    53185359    LogFlowThisFunc(("mMachineState=%d\n", mMachineState));
     5360
     5361    CheckComArgOutPointerValid(aProgress);
    53195362
    53205363    AutoCaller autoCaller(this);
     
    57055748 *       release(). Otherwise it will deadlock.
    57065749 */
    5707 HRESULT Console::powerDown(Progress *aProgress /*= NULL*/)
     5750HRESULT Console::powerDown(IProgress *aProgress /*= NULL*/)
    57085751{
    57095752    LogFlowThisFuncEnter();
     
    58485891        alock.enter();
    58495892    }
    5850     else
    5851     {
    5852         /** @todo r=bird: Doesn't make sense. Please remove after 3.1 has been branched
    5853          *        off. */
    5854         /* reset the flag for future re-use */
    5855         mVMPoweredOff = false;
    5856     }
    58575893
    58585894    /* advance percent count */
     
    59696005    if (SUCCEEDED(rc))
    59706006        mCallbackData.clear();
    5971 
    5972     /* complete the progress */
    5973     if (aProgress)
    5974         aProgress->notifyComplete(rc);
    59756007
    59766008    LogFlowThisFuncLeave();
     
    60256057            LogFlowThisFunc(("Doing mControl->UpdateState()...\n"));
    60266058            rc = mControl->UpdateState(aMachineState);
    6027             LogFlowThisFunc(("mControl->UpdateState()=%08X\n", rc));
     6059            LogFlowThisFunc(("mControl->UpdateState()=%Rhrc\n", rc));
    60286060        }
    60296061    }
     
    64226454                 * deadlock).
    64236455                 */
    6424                 std::auto_ptr<VMProgressTask> task(new VMProgressTask(that, NULL /* aProgress */,
    6425                                                                       true /* aUsesVMPtr */));
     6456                std::auto_ptr<VMPowerDownTask> task(new VMPowerDownTask(that,
     6457                                                                        NULL /* aServerProgress */,
     6458                                                                        MachineState_Null));
    64266459
    64276460                 /* If creating a task failed, this can currently mean one of
     
    66596692
    66606693#ifdef VBOX_WITH_USB
    6661 
    66626694/**
    66636695 * Sends a request to VMM to attach the given host device.
     
    68926924    return vrc;
    68936925}
    6894 
    68956926#endif /* VBOX_WITH_USB */
    6896 #if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
    6897 
     6927
     6928#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT))
    68986929/**
    68996930 * Helper function to handle host interface device creation and attachment.
     
    71307161    return rc;
    71317162}
    7132 
    71337163#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
    71347164
     
    71647194        if (attachment == NetworkAttachmentType_Bridged)
    71657195        {
    7166 #if defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)
     7196#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT))
    71677197            HRESULT rc2 = detachFromTapInterface(pNetworkAdapter);
    71687198            if (FAILED(rc2) && SUCCEEDED(rc))
    71697199                rc = rc2;
    7170 #endif
     7200#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
    71717201        }
    71727202    }
     
    75207550                                     COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
    75217551                                     COINIT_SPEED_OVER_MEMORY);
    7522         LogFlowFunc(("CoInitializeEx()=%08X\n", hrc));
     7552        LogFlowFunc(("CoInitializeEx()=%Rhrc\n", hrc));
    75237553    }
    75247554#endif
     
    84388468    LogFlowFuncEnter();
    84398469
    8440     std::auto_ptr<VMProgressTask> task(static_cast<VMProgressTask *>(pvUser));
     8470    std::auto_ptr<VMPowerDownTask> task(static_cast<VMPowerDownTask *>(pvUser));
    84418471    AssertReturn(task.get(), VERR_INVALID_PARAMETER);
    84428472
    84438473    AssertReturn(task->isOk(), VERR_GENERAL_FAILURE);
     8474
     8475    Assert(task->mProgress.isNull());
    84448476
    84458477    const ComObjPtr<Console> &that = task->mConsole;
     
    84548486    task->releaseVMCaller();
    84558487
    8456     that->powerDown(task->mProgress);
     8488    that->powerDown(task->mServerProgress);
     8489
     8490    /* complete the operation */
     8491    that->mControl->EndPoweringDown(S_OK, Bstr().raw());
    84578492
    84588493    LogFlowFuncLeave();
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r35429 r35460  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1047910479}
    1048010480
    10481 
    1048210481/**
    1048310482 *  @note Locks this object for writing.
     
    1051310512    return S_OK;
    1051410513}
     10514
     10515/**
     10516 *  @note Locks this object for writing.
     10517 */
     10518STDMETHODIMP SessionMachine::BeginPoweringDown(IProgress **aProgress)
     10519{
     10520    LogFlowThisFuncEnter();
     10521
     10522    CheckComArgOutPointerValid(aProgress);
     10523
     10524    AutoCaller autoCaller(this);
     10525    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     10526
     10527    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     10528
     10529    AssertReturn(mConsoleTaskData.mLastState == MachineState_Null,
     10530                 E_FAIL);
     10531
     10532    /* create a progress object to track operation completion */
     10533    ComObjPtr<Progress> pProgress;
     10534    pProgress.createObject();
     10535    pProgress->init(getVirtualBox(),
     10536                    static_cast<IMachine *>(this) /* aInitiator */,
     10537                    Bstr(tr("Stopping the virtual machine")).raw(),
     10538                    FALSE /* aCancelable */);
     10539
     10540    /* fill in the console task data */
     10541    mConsoleTaskData.mLastState = mData->mMachineState;
     10542    mConsoleTaskData.mProgress = pProgress;
     10543
     10544    /* set the state to Stopping (this is expected by Console::PowerDown()) */
     10545    setMachineState(MachineState_Stopping);
     10546
     10547    pProgress.queryInterfaceTo(aProgress);
     10548
     10549    return S_OK;
     10550}
     10551
     10552/**
     10553 *  @note Locks this object for writing.
     10554 */
     10555STDMETHODIMP SessionMachine::EndPoweringDown(LONG iResult, IN_BSTR aErrMsg)
     10556{
     10557    LogFlowThisFuncEnter();
     10558
     10559    AutoCaller autoCaller(this);
     10560    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
     10561
     10562    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     10563
     10564    AssertReturn(    (   (SUCCEEDED(iResult) && mData->mMachineState == MachineState_PoweredOff)
     10565                      || (FAILED(iResult) && mData->mMachineState == MachineState_Stopping))
     10566                  && mConsoleTaskData.mLastState != MachineState_Null,
     10567                 E_FAIL);
     10568
     10569    /*
     10570     * On failure, set the state to the state we had when BeginPoweringDown()
     10571     * was called (this is expected by Console::PowerDown() and the associated
     10572     * task). On success the VM process already changed the state to
     10573     * MachineState_PoweredOff, so no need to do anything.
     10574     */
     10575    if (FAILED(iResult))
     10576        setMachineState(mConsoleTaskData.mLastState);
     10577
     10578    /* notify the progress object about operation completion */
     10579    Assert(mConsoleTaskData.mProgress);
     10580    if (SUCCEEDED(iResult))
     10581        mConsoleTaskData.mProgress->notifyComplete(S_OK);
     10582    else
     10583    {
     10584        Utf8Str strErrMsg(aErrMsg);
     10585        if (strErrMsg.length())
     10586            mConsoleTaskData.mProgress->notifyComplete(iResult,
     10587                                                       COM_IIDOF(ISession),
     10588                                                       getComponentName(),
     10589                                                       strErrMsg.c_str());
     10590        else
     10591            mConsoleTaskData.mProgress->notifyComplete(iResult);
     10592    }
     10593
     10594    /* clear out the temporary saved state data */
     10595    mConsoleTaskData.mLastState = MachineState_Null;
     10596    mConsoleTaskData.mProgress.setNull();
     10597
     10598    LogFlowThisFuncLeave();
     10599    return S_OK;
     10600}
     10601
    1051510602
    1051610603/**
     
    1077910866    }
    1078010867
    10781     /* fill in the snapshot data */
     10868    /* fill in the console task data */
    1078210869    mConsoleTaskData.mLastState = mData->mMachineState;
    1078310870    mConsoleTaskData.mStateFilePath = stateFilePath;
     
    1154111628        if (aErrMsg.length())
    1154211629            mConsoleTaskData.mProgress->notifyComplete(aRc,
    11543                                                     COM_IIDOF(ISession),
    11544                                                     getComponentName(),
    11545                                                     aErrMsg.c_str());
     11630                                                       COM_IIDOF(ISession),
     11631                                                       getComponentName(),
     11632                                                       aErrMsg.c_str());
    1154611633        else
    1154711634            mConsoleTaskData.mProgress->notifyComplete(aRc);
Note: See TracChangeset for help on using the changeset viewer.

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