VirtualBox

Changeset 58004 in vbox


Ignore:
Timestamp:
Oct 2, 2015 10:39:07 AM (9 years ago)
Author:
vboxsync
Message:

pr7179. Part related to Console class and VMPowerUpTask, VMPowerDownTask tasks.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r58002 r58004  
    563563    typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
    564564    typedef std::list <USBStorageDevice> USBStorageDeviceList;
     565
     566    static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
     567    static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
    565568
    566569private:
     
    739742    void                        i_detachAllUSBDevices(bool aDone);
    740743
    741     static DECLCALLBACK(int)    i_powerUpThread(RTTHREAD Thread, void *pvUser);
    742     static DECLCALLBACK(int)    i_powerDownThread(RTTHREAD Thread, void *pvUser);
    743744
    744745    static DECLCALLBACK(int)    i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r58002 r58004  
    7373#include "AutoCaller.h"
    7474#include "Logging.h"
     75#include "ThreadTask.h"
    7576
    7677#include <VBox/com/array.h>
     
    150151 * Console::addVMCaller() for more info.
    151152 */
    152 struct VMTask
    153 {
     153class VMTask: public ThreadTask
     154{
     155public:
    154156    VMTask(Console *aConsole,
    155157           Progress *aProgress,
    156158           const ComPtr<IProgress> &aServerProgress,
    157159           bool aUsesVMPtr)
    158         : mConsole(aConsole),
     160        : ThreadTask("GenericVMTask"),
     161          mConsole(aConsole),
    159162          mConsoleCaller(aConsole),
    160163          mProgress(aProgress),
     
    175178    }
    176179
    177     ~VMTask()
     180    virtual ~VMTask()
    178181    {
    179182        releaseVMCaller();
     
    205208
    206209
    207 struct VMPowerUpTask : public VMTask
    208 {
     210class VMPowerUpTask : public VMTask
     211{
     212public:
    209213    VMPowerUpTask(Console *aConsole,
    210214                  Progress *aProgress)
     
    215219          mTeleporterEnabled(FALSE),
    216220          mEnmFaultToleranceState(FaultToleranceState_Inactive)
    217     {}
     221    {
     222        m_strTaskName = "VMPwrUp";
     223    }
    218224
    219225    PFNCFGMCONSTRUCTOR mConfigConstructor;
     
    227233    typedef std::list<ComPtr<IProgress> > ProgressList;
    228234    ProgressList hardDiskProgresses;
     235
     236    void handler()
     237    {
     238        int vrc = Console::i_powerUpThread(NULL, this);
     239    }
     240
    229241};
    230242
    231 struct VMPowerDownTask : public VMTask
    232 {
     243class VMPowerDownTask : public VMTask
     244{
     245public:
    233246    VMPowerDownTask(Console *aConsole,
    234247                    const ComPtr<IProgress> &aServerProgress)
    235248        : VMTask(aConsole, NULL /* aProgress */, aServerProgress,
    236249                 true /* aUsesVMPtr */)
    237     {}
     250    {
     251        m_strTaskName = "VMPwrDwn";
     252    }
     253
     254    void handler()
     255    {
     256        int vrc = Console::i_powerDownThread(NULL, this);
     257    }
    238258};
    239259
     
    20932113                            Global::stringifyMachineState(mMachineState));
    20942114    }
    2095 
    20962115    LogFlowThisFunc(("Initiating SHUTDOWN request...\n"));
    20972116
     
    21362155        try
    21372156        {
    2138             /* Setup task object and thread to carry out the operation asynchronously.
    2139              * We are going to pass ownership of task pointer to another thread.
    2140              * So we are in charge of deletion this task pointer in case if RTThreadCreate
    2141              * returns not successful result or in case of any exception
    2142              */
    2143            
    21442157            task = new VMPowerDownTask(this, pProgress);
    2145             AssertBreakStmt(task->isOk(), rc = E_FAIL);
    2146             int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
    2147                                      (void *) task, 0,
    2148                                      RTTHREADTYPE_MAIN_WORKER, 0,
    2149                                      "VMPwrDwn");
    2150             if (RT_FAILURE(vrc))
     2158            if (!task->isOk())
    21512159            {
    2152                 rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
    2153                 break;
     2160                throw E_FAIL;
    21542161            }
    2155             /* task is now owned by powerDownThread(), so release it */
    2156             //task.release();
    2157         }
    2158         catch(const std::exception &e)
    2159         {
    2160             rc = setError(E_FAIL, "Cought exception! Could not create VMPowerDown thread (%s)", e.what());
     2162        }
     2163        catch(...)
     2164        {
     2165            delete task;
     2166            rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n");
    21612167            break;
    21622168        }
     2169
     2170        rc = task->createThread();
    21632171
    21642172        /* pass the progress to the caller */
     
    21692177    if (FAILED(rc))
    21702178    {
    2171         if (task != NULL)
    2172         {
    2173             //we can delete this pointer because something
    2174             //was wrong and we hadn't passed pointer to another thread
    2175             LogFlowFunc(("Delete task VMPowerDownTask from Console::powerDown()\n"));
    2176             delete task;
    2177         }
    21782179        /* preserve existing error info */
    21792180        ErrorInfoKeeper eik;
     
    69786979HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused)
    69796980{
    6980 
    69816981    LogFlowThisFuncEnter();
    69826982
     
    69956995    LONG cOperations = 1;
    69966996    LONG ulTotalOperationsWeight = 1;
     6997    VMPowerUpTask* task = NULL;
    69976998
    69986999    try
     
    71137114        /* Setup task object and thread to carry out the operation
    71147115         * asynchronously */
    7115         std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
    7116         ComAssertComRCRetRC(task->rc());
     7116        try
     7117        {
     7118            task = new VMPowerUpTask(this, pPowerupProgress);
     7119            if (!task->isOk())
     7120            {
     7121                throw E_FAIL;
     7122            }
     7123        }
     7124        catch(...)
     7125        {
     7126            delete task;
     7127            rc = setError(E_FAIL, "Could not create VMPowerUpTask object \n");
     7128            throw rc;
     7129        }
    71177130
    71187131        task->mConfigConstructor = i_configConstructor;
     
    73727385#endif // 0
    73737386
     7387       
    73747388        /* setup task object and thread to carry out the operation
    73757389         * asynchronously */
     
    73797393        }
    73807394
    7381         int vrc = RTThreadCreate(NULL, Console::i_powerUpThread,
    7382                                  (void *)task.get(), 0,
    7383                                  RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp");
    7384         if (RT_FAILURE(vrc))
    7385             throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc);
    7386 
    7387         /* task is now owned by powerUpThread(), so release it */
    7388         task.release();
     7395        rc = task->createThread();
     7396
     7397        if (FAILED(rc))
     7398            throw rc;
    73897399
    73907400        /* finally, set the state: no right to fail in this method afterwards
     
    82538263                    if (!task->isOk())
    82548264                    {
    8255                         LogFlowFunc(("Console is already being uninitialized.\n"));
    8256                     }
    8257                     else
    8258                     {
    8259                         /*
    8260                          * We are going to pass ownership of task pointer to another thread.
    8261                          * So we are in charge of deletion this task pointer in case if RTThreadCreate
    8262                          * returns not successful result or in case of any exception
    8263                          */
    8264                         int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
    8265                                                  (void *) task, 0,
    8266                                                  RTTHREADTYPE_MAIN_WORKER, 0,
    8267                                                  "VMPwrDwn");
    8268                         if (RT_FAILURE(vrc))
    8269                         {
    8270                             rc = E_FAIL;
    8271                             LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc));
    8272                         }
     8265                        LogFlowFunc(("Console is already being uninitialized. \n"));
     8266                        throw E_FAIL;
    82738267                    }
    82748268                }
    8275                 catch(const std::exception &e)
     8269                catch(...)
    82768270                {
    8277                     rc = E_FAIL;
    8278                     LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));
     8271                    delete task;
     8272                    LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));
    82798273                }
    82808274
    8281                 if(FAILED(rc) || !task->isOk())
     8275                rc = task->createThread();
     8276
     8277                if (FAILED(rc))
    82828278                {
    8283                     LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n"));
    8284                     delete task;
     8279                    LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));
    82858280                }
     8281
    82868282            }
    82878283            break;
     
    94419437    LogFlowFuncEnter();
    94429438
    9443     std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));
    9444     AssertReturn(task.get(), VERR_INVALID_PARAMETER);
     9439    VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);
     9440    AssertReturn(task, VERR_INVALID_PARAMETER);
    94459441
    94469442    AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER);
     
    1000710003    }
    1000810004
    10009     LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n"));
    10010     delete task;
    1001110005    LogFlowFuncLeave();
    1001210006    return rc;
    1001310007}
    10014 
    1001510008
    1001610009/**
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