VirtualBox

Changeset 58519 in vbox for trunk


Ignore:
Timestamp:
Oct 30, 2015 8:17:19 AM (9 years ago)
Author:
vboxsync
Message:

pr7179. DnD part has been changed.

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

Legend:

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

    r58212 r58519  
    110110        RECVDATACTX mRecvCtx;
    111111    } mData;
     112
     113    friend class RecvDataTask;
    112114};
    113115
  • trunk/src/VBox/Main/include/GuestDnDTargetImpl.h

    r58212 r58519  
    102102        uint32_t mcbBlockSize;
    103103    } mData;
     104
     105    friend class SendDataTask;
    104106};
    105107
  • trunk/src/VBox/Main/include/ThreadTask.h

    r58009 r58519  
    2020#include "VBox/com/string.h"
    2121
     22struct ThreadVoidData
     23{
     24public:
     25    ThreadVoidData(){};
     26    virtual ~ThreadVoidData(){};
     27};
     28
    2229class ThreadTask
    2330{
    2431public:
    25     ThreadTask(const Utf8Str &t) : m_strTaskName(t){};
     32    ThreadTask(const Utf8Str &t) : m_pThread(NULL), m_strTaskName(t){};
    2633    virtual ~ThreadTask(){};
    27     HRESULT createThread();
     34    HRESULT createThread(PRTTHREAD pThread = NULL, RTTHREADTYPE enmType = RTTHREADTYPE_MAIN_WORKER);
    2835    virtual void handler() = 0;
    2936    static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
    30     static HRESULT i_setErrorStatic(HRESULT aResultCode, const Utf8Str &aText);
     37    static HRESULT setErrorStatic(HRESULT aResultCode, const Utf8Str &aText);
    3138
    3239    inline Utf8Str getTaskName() const {return m_strTaskName;};
     
    3441protected:
    3542    ThreadTask():m_strTaskName("GenericTask"){};
     43    PRTTHREAD m_pThread;
    3644    Utf8Str m_strTaskName;
    3745};
  • trunk/src/VBox/Main/src-all/ThreadTask.cpp

    r58009 r58519  
    2020#include "ThreadTask.h"
    2121
    22 HRESULT ThreadTask::createThread()
     22HRESULT ThreadTask::createThread(PRTTHREAD pThread, RTTHREADTYPE enmType)
    2323{
    2424    HRESULT rc = S_OK;
    2525    try
    2626    {
    27         int vrc = RTThreadCreate(NULL,
     27        m_pThread = pThread;
     28        int vrc = RTThreadCreate(m_pThread,
    2829                                 taskHandler,
    2930                                 (void *)this,
    3031                                 0,
    31                                  RTTHREADTYPE_MAIN_WORKER,
     32                                 enmType,
    3233                                 0,
    3334                                 this->getTaskName().c_str());
     
    8990}
    9091
    91 /*static*/ HRESULT ThreadTask::i_setErrorStatic(HRESULT aResultCode,
     92/*static*/ HRESULT ThreadTask::setErrorStatic(HRESULT aResultCode,
    9293                                    const Utf8Str &aText)
    9394{
  • trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp

    r58329 r58519  
    2727#include "Global.h"
    2828#include "AutoCaller.h"
     29#include "ThreadTask.h"
    2930
    3031#include <iprt/asm.h>
     
    4748 * Base class for a source task.
    4849 */
    49 class GuestDnDSourceTask
     50class GuestDnDSourceTask : public ThreadTask
    5051{
    5152public:
    5253
    5354    GuestDnDSourceTask(GuestDnDSource *pSource)
    54         : mSource(pSource),
    55           mRC(VINF_SUCCESS) { }
     55        : ThreadTask("GenericGuestDnDSourceTask")
     56        , mSource(pSource)
     57        , mRC(VINF_SUCCESS) { }
    5658
    5759    virtual ~GuestDnDSourceTask(void) { }
     
    7779    RecvDataTask(GuestDnDSource *pSource, PRECVDATACTX pCtx)
    7880        : GuestDnDSourceTask(pSource)
    79         , mpCtx(pCtx) { }
     81        , mpCtx(pCtx)
     82    {
     83        m_strTaskName = "dndSrcRcvData";
     84    }
     85
     86    void handler()
     87    {
     88        int vrc = GuestDnDSource::i_receiveDataThread(*m_pThread, this);
     89    }
    8090
    8191    virtual ~RecvDataTask(void) { }
     
    347357        return hr;
    348358
     359    RecvDataTask *pTask = NULL;
     360    RTTHREAD threadRcv;
     361    int rc = S_OK;
     362
    349363    try
    350364    {
     
    357371        LogRel2(("DnD: Requesting data from guest in format: %s\n", aFormat.c_str()));
    358372
    359         RecvDataTask *pTask = new RecvDataTask(this, &mData.mRecvCtx);
    360         AssertReturn(pTask->isOk(), pTask->getRC());
    361 
    362         LogFlowFunc(("Starting thread ...\n"));
    363 
    364         RTTHREAD threadRcv;
    365         int rc = RTThreadCreate(&threadRcv, GuestDnDSource::i_receiveDataThread,
    366                                 (void *)pTask, 0, RTTHREADTYPE_MAIN_WORKER, 0, "dndSrcRcvData");
     373        pTask = new RecvDataTask(this, &mData.mRecvCtx);
     374        if (!pTask->isOk())
     375        {
     376            delete pTask;
     377            LogRel2(("DnD: Could not create RecvDataTask object \n"));
     378            throw hr = E_FAIL;
     379        }
     380
     381        //this function delete pTask in case of exceptions, so there is no need in the call of delete operator
     382        hr = pTask->createThread(&threadRcv);
     383
     384    }
     385    catch(std::bad_alloc &)
     386    {
     387        hr = setError(E_OUTOFMEMORY);
     388    }
     389    catch(...)
     390    {
     391        LogRel2(("DnD: Could not create thread for RecvDataTask \n"));
     392        hr = E_FAIL;
     393    }
     394
     395    if (SUCCEEDED(hr))
     396    {
     397        rc = RTThreadUserWait(threadRcv, 30 * 1000 /* 30s timeout */);
    367398        if (RT_SUCCESS(rc))
    368399        {
    369             rc = RTThreadUserWait(threadRcv, 30 * 1000 /* 30s timeout */);
    370             if (RT_SUCCESS(rc))
    371             {
    372                 mDataBase.m_cTransfersPending++;
    373 
    374                 hr = pResp->queryProgressTo(aProgress.asOutParam());
    375                 ComAssertComRC(hr);
    376 
    377                 /* Note: pTask is now owned by the worker thread. */
    378             }
    379             else
    380                 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for receiving thread failed (%Rrc)"), rc);
     400            mDataBase.m_cTransfersPending++;
     401
     402            hr = pResp->queryProgressTo(aProgress.asOutParam());
     403            ComAssertComRC(hr);
     404
     405            /* Note: pTask is now owned by the worker thread. */
    381406        }
    382407        else
    383             hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread failed (%Rrc)"), rc);
    384 
    385         if (FAILED(hr))
    386             delete pTask;
    387     }
    388     catch(std::bad_alloc &)
    389     {
    390         hr = setError(E_OUTOFMEMORY);
    391     }
     408            hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for receiving thread failed (%Rrc)"), rc);
     409    }
     410    else
     411        hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread for GuestDnDSource::i_receiveDataThread failed (%Rrc)"), rc);
     412    /* Note: mDataBase.mfTransferIsPending will be set to false again by i_receiveDataThread. */
    392413
    393414    LogFlowFunc(("Returning hr=%Rhrc\n", hr));
     
    10051026    rc = pThis->i_receiveData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
    10061027
    1007     if (pTask)
    1008         delete pTask;
    1009 
    10101028    AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
    10111029
  • trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp

    r58370 r58519  
    2626#include "Global.h"
    2727#include "AutoCaller.h"
     28#include "ThreadTask.h"
    2829
    2930#include <algorithm>        /* For std::find(). */
     
    5152 * Base class for a target task.
    5253 */
    53 class GuestDnDTargetTask
     54class GuestDnDTargetTask : public ThreadTask
    5455{
    5556public:
    5657
    5758    GuestDnDTargetTask(GuestDnDTarget *pTarget)
    58         : mTarget(pTarget),
    59           mRC(VINF_SUCCESS) { }
     59        : ThreadTask("GenericGuestDnDTargetTask")
     60        , mTarget(pTarget)
     61        , mRC(VINF_SUCCESS) { }
    6062
    6163    virtual ~GuestDnDTargetTask(void) { }
     
    8183    SendDataTask(GuestDnDTarget *pTarget, PSENDDATACTX pCtx)
    8284        : GuestDnDTargetTask(pTarget),
    83           mpCtx(pCtx) { }
     85          mpCtx(pCtx)
     86    {
     87        m_strTaskName = "dndTgtSndData";
     88    }
     89
     90    void handler()
     91    {
     92        int vrc = GuestDnDTarget::i_sendDataThread(*m_pThread, this);
     93    }
    8494
    8595    virtual ~SendDataTask(void)
     
    564574
    565575    rc = pThis->i_sendData(pTask->getCtx(), RT_INDEFINITE_WAIT /* msTimeout */);
    566 
    567     if (pTask)
    568         delete pTask;
    569576
    570577    AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
     
    617624        return hr;
    618625
     626    SendDataTask *pTask = NULL;
     627    PSENDDATACTX pSendCtx = NULL;
     628    RTTHREAD threadSnd;
     629    int rc = S_OK;
     630
    619631    try
    620632    {
    621         PSENDDATACTX pSendCtx = new SENDDATACTX;
     633        //pSendCtx is passed into SendDataTask where one is deleted in destructor
     634        pSendCtx = new SENDDATACTX;
    622635        RT_BZERO(pSendCtx, sizeof(SENDDATACTX));
    623636
     
    626639        pSendCtx->mScreenID     = aScreenId;
    627640        pSendCtx->mFmtReq       = aFormat;
    628 
    629641        pSendCtx->mData.getMeta().add(aData);
    630642
    631         SendDataTask *pTask = new SendDataTask(this, pSendCtx);
    632         AssertReturn(pTask->isOk(), pTask->getRC());
    633 
    634         LogFlowFunc(("Starting thread ...\n"));
    635 
    636         RTTHREAD threadSnd;
    637         int rc = RTThreadCreate(&threadSnd, GuestDnDTarget::i_sendDataThread,
    638                                 (void *)pTask, 0, RTTHREADTYPE_MAIN_WORKER, 0, "dndTgtSndData");
     643        /* pTask is responsible for deletion of pSendCtx after creating */
     644        pTask = new SendDataTask(this, pSendCtx);
     645        if (!pTask->isOk())
     646        {
     647            delete pTask;
     648            LogRel2(("DnD: Could not create SendDataTask object \n"));
     649            throw hr = E_FAIL;
     650        }
     651
     652        //this function delete pTask in case of exceptions, so there is no need in the call of delete operator
     653        //pSendCtx is deleted in the pTask destructor
     654        hr = pTask->createThread(&threadSnd);
     655
     656    }
     657    catch(std::bad_alloc &)
     658    {
     659        hr = setError(E_OUTOFMEMORY);
     660    }
     661    catch(...)
     662    {
     663        LogRel2(("DnD: Could not create thread for SendDataTask \n"));
     664        hr = E_FAIL;
     665    }
     666
     667    if (SUCCEEDED(hr))
     668    {
     669        rc = RTThreadUserWait(threadSnd, 30 * 1000 /* 30s timeout */);
    639670        if (RT_SUCCESS(rc))
    640671        {
    641             rc = RTThreadUserWait(threadSnd, 30 * 1000 /* 30s timeout */);
    642             if (RT_SUCCESS(rc))
    643             {
    644                 mDataBase.m_cTransfersPending++;
    645 
    646                 hr = pResp->queryProgressTo(aProgress.asOutParam());
    647                 ComAssertComRC(hr);
    648 
    649                 /* Note: pTask is now owned by the worker thread. */
    650             }
    651             else
    652                 hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for sending thread failed (%Rrc)"), rc);
     672            mDataBase.m_cTransfersPending++;
     673
     674            hr = pResp->queryProgressTo(aProgress.asOutParam());
     675            ComAssertComRC(hr);
     676
     677            /* Note: pTask is now owned by the worker thread. */
    653678        }
    654679        else
    655             hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread failed (%Rrc)"), rc);
    656 
    657         if (FAILED(hr))
    658             delete pSendCtx;
    659     }
    660     catch(std::bad_alloc &)
    661     {
    662         hr = setError(E_OUTOFMEMORY);
    663     }
     680            hr = setError(VBOX_E_IPRT_ERROR, tr("Waiting for sending thread failed (%Rrc)"), rc);
     681    }
     682    else
     683        hr = setError(VBOX_E_IPRT_ERROR, tr("Starting thread for GuestDnDTarget::i_sendDataThread (%Rrc)"), rc);
    664684
    665685    LogFlowFunc(("Returning hr=%Rhrc\n", hr));
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