VirtualBox

Changeset 57996 in vbox for trunk


Ignore:
Timestamp:
Oct 2, 2015 8:13:15 AM (9 years ago)
Author:
vboxsync
Message:

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

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r57809 r57996  
    359359        src-all/SharedFolderImpl.cpp \
    360360        src-all/AutoCaller.cpp \
     361        src-all/ThreadTask.cpp \
    361362        src-all/VirtualBoxBase.cpp \
    362363        src-all/VirtualBoxErrorInfoImpl.cpp \
     
    737738        src-all/SharedFolderImpl.cpp \
    738739        src-all/AutoCaller.cpp \
     740        src-all/ThreadTask.cpp \
    739741        src-all/VirtualBoxBase.cpp \
    740742        src-all/VirtualBoxErrorInfoImpl.cpp \
     
    857859        src-all/Global.cpp \
    858860        src-all/AutoCaller.cpp \
     861        src-all/ThreadTask.cpp \
    859862        src-all/VirtualBoxBase.cpp \
    860863        src-all/VirtualBoxErrorInfoImpl.cpp \
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r55505 r57996  
    114114
    115115    struct ImportStack;
    116     struct TaskOVF;
     116    class TaskOVF;
    117117    struct Data;            // opaque, defined in ApplianceImpl.cpp
    118118    Data *m;
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r57437 r57996  
    2323#include "ovfreader.h"
    2424#include "SecretKeyStore.h"
     25#include "ThreadTask.h"
    2526#include <map>
    2627#include <vector>
     
    122123};
    123124
    124 struct Appliance::TaskOVF
    125 {
     125class Appliance::TaskOVF: public ThreadTask
     126{
     127public:
    126128    enum TaskType
    127129    {
     
    135137            LocationInfo aLocInfo,
    136138            ComObjPtr<Progress> &aProgress)
    137       : pAppliance(aThat),
     139      : ThreadTask("TaskOVF"),
     140        pAppliance(aThat),
    138141        taskType(aType),
    139142        locInfo(aLocInfo),
     
    141144        enFormat(ovf::OVFVersion_unknown),
    142145        rc(S_OK)
    143     {}
     146    {
     147        switch (taskType)
     148        {
     149            case TaskOVF::Read:     m_strTaskName = "ApplRead"; break;
     150            case TaskOVF::Import:   m_strTaskName = "ApplImp"; break;
     151            case TaskOVF::Write:    m_strTaskName = "ApplWrit"; break;
     152            default:                m_strTaskName = "ApplTask"; break;
     153        }
     154    }
    144155
    145156    static DECLCALLBACK(int) updateProgress(unsigned uPercent, void *pvUser);
    146 
    147     HRESULT startThread();
    148157
    149158    Appliance *pAppliance;
     
    155164
    156165    HRESULT rc;
     166
     167    void handler()
     168    {
     169        int vrc = Appliance::i_taskThreadImportOrExport(NULL, this);
     170    }
    157171};
    158172
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r57524 r57996  
    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

    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/**
  • trunk/src/VBox/Main/src-server/ApplianceImpl.cpp

    r57437 r57996  
    11851185
    11861186/**
    1187  * Starts the worker thread for the task.
    1188  *
    1189  * @return COM status code.
    1190  */
    1191 HRESULT Appliance::TaskOVF::startThread()
    1192 {
    1193     /* Pick a thread name suitable for logging (<= 8 chars). */
    1194     const char *pszTaskNm;
    1195     switch (taskType)
    1196     {
    1197         case TaskOVF::Read:     pszTaskNm = "ApplRead"; break;
    1198         case TaskOVF::Import:   pszTaskNm = "ApplImp"; break;
    1199         case TaskOVF::Write:    pszTaskNm = "ApplWrit"; break;
    1200         default:                pszTaskNm = "ApplTask"; break;
    1201     }
    1202 
    1203     int vrc = RTThreadCreate(NULL, Appliance::i_taskThreadImportOrExport, this,
    1204                              0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0, pszTaskNm);
    1205     if (RT_SUCCESS(vrc))
    1206         return S_OK;
    1207     return Appliance::i_setErrorStatic(E_FAIL, Utf8StrFmt("Could not create OVF task thread (%Rrc)\n", vrc));
    1208 }
    1209 
    1210 /**
    12111187 * Thread function for the thread started in Appliance::readImpl() and Appliance::importImpl()
    12121188 * and Appliance::writeImpl().
     
    12201196DECLCALLBACK(int) Appliance::i_taskThreadImportOrExport(RTTHREAD /* aThread */, void *pvUser)
    12211197{
    1222     std::auto_ptr<TaskOVF> task(static_cast<TaskOVF*>(pvUser));
    1223     AssertReturn(task.get(), VERR_GENERAL_FAILURE);
     1198    TaskOVF* task = static_cast<TaskOVF*>(pvUser);
     1199    AssertReturn(task, VERR_GENERAL_FAILURE);
    12241200
    12251201    Appliance *pAppliance = task->pAppliance;
     
    12341210        case TaskOVF::Read:
    12351211            if (task->locInfo.storageType == VFSType_File)
    1236                 taskrc = pAppliance->i_readFS(task.get());
     1212                taskrc = pAppliance->i_readFS(task);
    12371213            else if (task->locInfo.storageType == VFSType_S3)
    12381214#ifdef VBOX_WITH_S3
    1239                 taskrc = pAppliance->i_readS3(task.get());
     1215                taskrc = pAppliance->i_readS3(task);
    12401216#else
    12411217                taskrc = VERR_NOT_IMPLEMENTED;
     
    12451221        case TaskOVF::Import:
    12461222            if (task->locInfo.storageType == VFSType_File)
    1247                 taskrc = pAppliance->i_importFS(task.get());
     1223                taskrc = pAppliance->i_importFS(task);
    12481224            else if (task->locInfo.storageType == VFSType_S3)
    12491225#ifdef VBOX_WITH_S3
    1250                 taskrc = pAppliance->i_importS3(task.get());
     1226                taskrc = pAppliance->i_importS3(task);
    12511227#else
    12521228                taskrc = VERR_NOT_IMPLEMENTED;
     
    12561232        case TaskOVF::Write:
    12571233            if (task->locInfo.storageType == VFSType_File)
    1258                 taskrc = pAppliance->i_writeFS(task.get());
     1234                taskrc = pAppliance->i_writeFS(task);
    12591235            else if (task->locInfo.storageType == VFSType_S3)
    12601236#ifdef VBOX_WITH_S3
    1261                 taskrc = pAppliance->i_writeS3(task.get());
     1237                taskrc = pAppliance->i_writeS3(task);
    12621238#else
    12631239                taskrc = VERR_NOT_IMPLEMENTED;
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r57277 r57996  
    2828#include "ApplianceImpl.h"
    2929#include "VirtualBoxImpl.h"
    30 
    3130#include "ProgressImpl.h"
    3231#include "MachineImpl.h"
     
    754753
    755754        /* Initialize our worker task */
    756         std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
     755        TaskOVF* task = NULL;
     756        try
     757        {
     758            task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
     759        }
     760        catch(...)
     761        {
     762            delete task;
     763            throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     764                                tr("Could not create TaskOVF object for for writing out the OVF to disk"));
     765        }
     766
    757767        /* The OVF version to write */
    758768        task->enFormat = aFormat;
    759769
    760         rc = task->startThread();
     770        rc = task->createThread();
    761771        if (FAILED(rc)) throw rc;
    762772
    763         /* Don't destruct on success */
    764         task.release();
    765773    }
    766774    catch (HRESULT aRC)
     
    12511259    pelmSystem->createChild("vssd:VirtualSystemIdentifier")->addContent(strVMName);
    12521260    // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
    1253     const char *pcszHardware = "virtualbox-2.2";
     1261    const char *pcszHardware = "virtualbox";
    12541262    if (enFormat == ovf::OVFVersion_0_9)
    12551263        // pretend to be vmware compatible then
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r56599 r57996  
    874874
    875875    /* Initialize our worker task */
    876     std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress));
    877 
    878     rc = task->startThread();
     876    TaskOVF* task = NULL;
     877    try
     878    {
     879        task = new TaskOVF(this, TaskOVF::Read, aLocInfo, aProgress);
     880    }
     881    catch(...)
     882    {
     883        delete task;
     884        throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     885                            tr("Could not create TaskOVF object for reading the OVF from disk"));
     886    }
     887
     888    rc = task->createThread();
    879889    if (FAILED(rc)) throw rc;
    880 
    881     /* Don't destruct on success */
    882     task.release();
    883890
    884891    return rc;
     
    13711378
    13721379    /* Initialize our worker task */
    1373     std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Import, locInfo, progress));
    1374 
    1375     rc = task->startThread();
     1380    TaskOVF* task = NULL;
     1381    try
     1382    {
     1383        task = new TaskOVF(this, TaskOVF::Import, locInfo, progress);
     1384    }
     1385    catch(...)
     1386    {
     1387        delete task;
     1388        throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     1389                            tr("Could not create TaskOVF object for importing OVF data into VirtualBox"));
     1390    }
     1391
     1392    rc = task->createThread();
    13761393    if (FAILED(rc)) throw rc;
    1377 
    1378     /* Don't destruct on success */
    1379     task.release();
    13801394
    13811395    return rc;
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