VirtualBox

Changeset 58005 in vbox


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

pr7179. Part related to Appliance class and TaskOVF tasks like import, export, reading.

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

Legend:

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

    r58002 r58005  
    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

    r58002 r58005  
    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/src-server/ApplianceImpl.cpp

    r58002 r58005  
    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

    r58002 r58005  
    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)
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r58002 r58005  
    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