VirtualBox

Ignore:
Timestamp:
Oct 2, 2015 8:13:15 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103021
Message:

pr7179. First part. The tasks VMPowerDownTask, VMPowerUpTask, TaskOVF were changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r57828 r57996  
    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
     
    21362156        try
    21372157        {
    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            
    21442158            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))
     2159            if (!task->isOk())
    21512160            {
    2152                 rc = setError(E_FAIL, "Could not create VMPowerDown thread (%Rrc)", vrc);
    2153                 break;
     2161                throw E_FAIL;
    21542162            }
    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());
     2163        }
     2164        catch(...)
     2165        {
     2166            delete task;
     2167            rc = setError(E_FAIL, "Could not create VMPowerDownTask object \n");
    21612168            break;
    21622169        }
     2170
     2171        rc = task->createThread();
    21632172
    21642173        /* pass the progress to the caller */
     
    21692178    if (FAILED(rc))
    21702179    {
    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         }
    21782180        /* preserve existing error info */
    21792181        ErrorInfoKeeper eik;
     
    69786980HRESULT Console::i_powerUp(IProgress **aProgress, bool aPaused)
    69796981{
    6980 
    69816982    LogFlowThisFuncEnter();
    69826983
     
    69956996    LONG cOperations = 1;
    69966997    LONG ulTotalOperationsWeight = 1;
     6998    VMPowerUpTask* task = NULL;
    69976999
    69987000    try
     
    71127114        /* Setup task object and thread to carry out the operation
    71137115         * asynchronously */
    7114         std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
    7115         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        }
    71167130
    71177131        task->mConfigConstructor = i_configConstructor;
     
    73717385#endif // 0
    73727386
     7387       
    73737388        /* setup task object and thread to carry out the operation
    73747389         * asynchronously */
     
    73787393        }
    73797394
    7380         int vrc = RTThreadCreate(NULL, Console::i_powerUpThread,
    7381                                  (void *)task.get(), 0,
    7382                                  RTTHREADTYPE_MAIN_WORKER, 0, "VMPwrUp");
    7383         if (RT_FAILURE(vrc))
    7384             throw setError(E_FAIL, "Could not create VMPowerUp thread (%Rrc)", vrc);
    7385 
    7386         /* task is now owned by powerUpThread(), so release it */
    7387         task.release();
     7395        rc = task->createThread();
     7396
     7397        if (FAILED(rc))
     7398            throw rc;
    73887399
    73897400        /* finally, set the state: no right to fail in this method afterwards
     
    82528263                    if (!task->isOk())
    82538264                    {
    8254                         LogFlowFunc(("Console is already being uninitialized.\n"));
    8255                     }
    8256                     else
    8257                     {
    8258                         /*
    8259                          * We are going to pass ownership of task pointer to another thread.
    8260                          * So we are in charge of deletion this task pointer in case if RTThreadCreate
    8261                          * returns not successful result or in case of any exception
    8262                          */
    8263                         int vrc = RTThreadCreate(NULL, Console::i_powerDownThread,
    8264                                                  (void *) task, 0,
    8265                                                  RTTHREADTYPE_MAIN_WORKER, 0,
    8266                                                  "VMPwrDwn");
    8267                         if (RT_FAILURE(vrc))
    8268                         {
    8269                             rc = E_FAIL;
    8270                             LogFlowFunc(("Could not create VMPowerDown thread (%Rrc)\n", vrc));
    8271                         }
     8265                        LogFlowFunc(("Console is already being uninitialized. \n"));
     8266                        throw E_FAIL;
    82728267                    }
    82738268                }
    8274                 catch(const std::exception &e)
     8269                catch(...)
    82758270                {
    8276                     rc = E_FAIL;
    8277                     LogFlowFunc(("Cought exception! Could not create VMPowerDown thread (%s)\n", e.what()));
     8271                    delete task;
     8272                    LogFlowFunc(("Problem with creating VMPowerDownTask object. \n"));
    82788273                }
    82798274
    8280                 if(FAILED(rc) || !task->isOk())
     8275                rc = task->createThread();
     8276
     8277                if (FAILED(rc))
    82818278                {
    8282                     LogFlowFunc(("Delete task VMPowerDownTask from Console::i_vmstateChangeCallback()\n"));
    8283                     delete task;
     8279                    LogFlowFunc(("Problem with creating thread for VMPowerDownTask. \n"));
    82848280                }
     8281
    82858282            }
    82868283            break;
     
    94409437    LogFlowFuncEnter();
    94419438
    9442     std::auto_ptr<VMPowerUpTask> task(static_cast<VMPowerUpTask *>(pvUser));
    9443     AssertReturn(task.get(), VERR_INVALID_PARAMETER);
     9439    VMPowerUpTask* task = static_cast<VMPowerUpTask *>(pvUser);
     9440    AssertReturn(task, VERR_INVALID_PARAMETER);
    94449441
    94459442    AssertReturn(!task->mConsole.isNull(), VERR_INVALID_PARAMETER);
     
    1000610003    }
    1000710004
    10008     LogFlowFunc(("Delete task VMPowerDownTask from Console::i_powerDownThread()\n"));
    10009     delete task;
    1001010005    LogFlowFuncLeave();
    1001110006    return rc;
    1001210007}
    10013 
    1001410008
    1001510009/**
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