VirtualBox

Changeset 44288 in vbox for trunk/src/VBox/Main/src-all


Ignore:
Timestamp:
Jan 14, 2013 6:22:18 PM (12 years ago)
Author:
vboxsync
Message:

Eliminate last use of CombinedProgress class etc xtracker id id 6167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/ProgressImpl.cpp

    r44124 r44288  
    4040#include "AutoCaller.h"
    4141
    42 ////////////////////////////////////////////////////////////////////////////////
    43 // ProgressBase class
    44 ////////////////////////////////////////////////////////////////////////////////
    45 
    46 // constructor / destructor
    47 ////////////////////////////////////////////////////////////////////////////////
    48 
    49 ProgressBase::ProgressBase()
     42
     43Progress::Progress()
    5044#if !defined(VBOX_COM_INPROC)
    5145    : mParent(NULL)
     
    5448}
    5549
    56 ProgressBase::~ProgressBase()
    57 {
    58 }
    59 
    60 
    61 /**
    62  * Subclasses must call this method from their FinalConstruct() implementations.
    63  */
    64 HRESULT ProgressBase::FinalConstruct()
    65 {
    66     mCancelable = FALSE;
    67     mCompleted = FALSE;
    68     mCanceled = FALSE;
    69     mResultCode = S_OK;
    70 
    71     m_cOperations
    72         = m_ulTotalOperationsWeight
    73         = m_ulOperationsCompletedWeight
    74         = m_ulCurrentOperation
    75         = m_ulCurrentOperationWeight
    76         = m_ulOperationPercent
    77         = m_cMsTimeout
    78         = 0;
    79 
    80     // get creation timestamp
    81     m_ullTimestamp = RTTimeMilliTS();
    82 
    83     m_pfnCancelCallback = NULL;
    84     m_pvCancelUserArg = NULL;
    85 
    86     return BaseFinalConstruct();
    87 }
    88 
    89 // protected initializer/uninitializer for internal purposes only
    90 ////////////////////////////////////////////////////////////////////////////////
    91 
    92 /**
    93  * Initializes the progress base object.
    94  *
    95  * Subclasses should call this or any other #protectedInit() method from their
    96  * init() implementations.
    97  *
    98  * @param aAutoInitSpan AutoInitSpan object instantiated by a subclass.
    99  * @param aParent       Parent object (only for server-side Progress objects).
    100  * @param aInitiator    Initiator of the task (for server-side objects. Can be
    101  *                      NULL which means initiator = parent, otherwise must not
    102  *                      be NULL).
    103  * @param aDescription  ask description.
    104  * @param aID           Address of result GUID structure (optional).
    105  *
    106  * @return              COM result indicator.
    107  */
    108 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan,
    109 #if !defined(VBOX_COM_INPROC)
    110                                     VirtualBox *aParent,
    111 #endif
    112                                     IUnknown *aInitiator,
    113                                     CBSTR aDescription,
    114                                     OUT_GUID aId /* = NULL */)
    115 {
    116     /* Guarantees subclasses call this method at the proper time */
    117     NOREF(aAutoInitSpan);
    118 
    119     AutoCaller autoCaller(this);
    120     AssertReturn(autoCaller.state() == InInit, E_FAIL);
    121 
    122 #if !defined(VBOX_COM_INPROC)
    123     AssertReturn(aParent, E_INVALIDARG);
    124 #else
    125     AssertReturn(aInitiator, E_INVALIDARG);
    126 #endif
    127 
    128     AssertReturn(aDescription, E_INVALIDARG);
    129 
    130 #if !defined(VBOX_COM_INPROC)
    131     /* share parent weakly */
    132     unconst(mParent) = aParent;
    133 #endif
    134 
    135 #if !defined(VBOX_COM_INPROC)
    136     /* assign (and therefore addref) initiator only if it is not VirtualBox
    137      * (to avoid cycling); otherwise mInitiator will remain null which means
    138      * that it is the same as the parent */
    139     if (aInitiator)
    140     {
    141         ComObjPtr<VirtualBox> pVirtualBox(mParent);
    142         if (!(pVirtualBox == aInitiator))
    143             unconst(mInitiator) = aInitiator;
    144     }
    145 #else
    146     unconst(mInitiator) = aInitiator;
    147 #endif
    148 
    149     unconst(mId).create();
    150     if (aId)
    151         mId.cloneTo(aId);
    152 
    153 #if !defined(VBOX_COM_INPROC)
    154     /* add to the global collection of progress operations (note: after
    155      * creating mId) */
    156     mParent->addProgress(this);
    157 #endif
    158 
    159     unconst(mDescription) = aDescription;
    160 
    161     return S_OK;
    162 }
    163 
    164 /**
    165  * Initializes the progress base object.
    166  *
    167  * This is a special initializer that doesn't initialize any field. Used by one
    168  * of the Progress::init() forms to create sub-progress operations combined
    169  * together using a CombinedProgress instance, so it doesn't require the parent,
    170  * initiator, description and doesn't create an ID.
    171  *
    172  * Subclasses should call this or any other #protectedInit() method from their
    173  * init() implementations.
    174  *
    175  * @param aAutoInitSpan AutoInitSpan object instantiated by a subclass.
    176  */
    177 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan)
    178 {
    179     /* Guarantees subclasses call this method at the proper time */
    180     NOREF(aAutoInitSpan);
    181 
    182     return S_OK;
    183 }
    184 
    185 /**
    186  * Uninitializes the instance.
    187  *
    188  * Subclasses should call this from their uninit() implementations.
    189  *
    190  * @param aAutoUninitSpan   AutoUninitSpan object instantiated by a subclass.
    191  *
    192  * @note Using the mParent member after this method returns is forbidden.
    193  */
    194 void ProgressBase::protectedUninit(AutoUninitSpan &aAutoUninitSpan)
    195 {
    196     /* release initiator (effective only if mInitiator has been assigned in
    197      * init()) */
    198     unconst(mInitiator).setNull();
    199 
    200 #if !defined(VBOX_COM_INPROC)
    201     if (mParent)
    202     {
    203         /* remove the added progress on failure to complete the initialization */
    204         if (aAutoUninitSpan.initFailed() && mId.isValid() && !mId.isZero())
    205             mParent->removeProgress(mId.ref());
    206 
    207         unconst(mParent) = NULL;
    208     }
    209 #endif
    210 }
     50Progress::~Progress()
     51{
     52}
     53
    21154
    21255// IProgress properties
    21356/////////////////////////////////////////////////////////////////////////////
    21457
    215 STDMETHODIMP ProgressBase::COMGETTER(Id)(BSTR *aId)
     58STDMETHODIMP Progress::COMGETTER(Id)(BSTR *aId)
    21659{
    21760    CheckComArgOutPointerValid(aId);
     
    22669}
    22770
    228 STDMETHODIMP ProgressBase::COMGETTER(Description)(BSTR *aDescription)
     71STDMETHODIMP Progress::COMGETTER(Description)(BSTR *aDescription)
    22972{
    23073    CheckComArgOutPointerValid(aDescription);
     
    23982}
    24083
    241 STDMETHODIMP ProgressBase::COMGETTER(Initiator)(IUnknown **aInitiator)
     84STDMETHODIMP Progress::COMGETTER(Initiator)(IUnknown **aInitiator)
    24285{
    24386    CheckComArgOutPointerValid(aInitiator);
     
    263106}
    264107
    265 STDMETHODIMP ProgressBase::COMGETTER(Cancelable)(BOOL *aCancelable)
     108STDMETHODIMP Progress::COMGETTER(Cancelable)(BOOL *aCancelable)
    266109{
    267110    CheckComArgOutPointerValid(aCancelable);
     
    286129 * @return fractional percentage as a double value.
    287130 */
    288 double ProgressBase::calcTotalPercent()
     131double Progress::calcTotalPercent()
    289132{
    290133    // avoid division by zero
     
    304147 * The caller should hold the object write lock.
    305148 */
    306 void ProgressBase::checkForAutomaticTimeout(void)
     149void Progress::checkForAutomaticTimeout(void)
    307150{
    308151    if (   m_cMsTimeout
     
    315158
    316159
    317 STDMETHODIMP ProgressBase::COMGETTER(TimeRemaining)(LONG *aTimeRemaining)
     160STDMETHODIMP Progress::COMGETTER(TimeRemaining)(LONG *aTimeRemaining)
    318161{
    319162    CheckComArgOutPointerValid(aTimeRemaining);
     
    338181            uint64_t ullTimeRemaining = ullTimeTotal - ullTimeElapsed;
    339182
    340 //             Log(("ProgressBase::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n",
     183//             Log(("Progress::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n",
    341184//                         (uint32_t)dPercentDone, ullTimeNow, ullTimeElapsed, ullTimeTotal, ullTimeRemaining));
    342185
     
    348191}
    349192
    350 STDMETHODIMP ProgressBase::COMGETTER(Percent)(ULONG *aPercent)
     193STDMETHODIMP Progress::COMGETTER(Percent)(ULONG *aPercent)
    351194{
    352195    CheckComArgOutPointerValid(aPercent);
     
    381224}
    382225
    383 STDMETHODIMP ProgressBase::COMGETTER(Completed)(BOOL *aCompleted)
     226STDMETHODIMP Progress::COMGETTER(Completed)(BOOL *aCompleted)
    384227{
    385228    CheckComArgOutPointerValid(aCompleted);
     
    395238}
    396239
    397 STDMETHODIMP ProgressBase::COMGETTER(Canceled)(BOOL *aCanceled)
     240STDMETHODIMP Progress::COMGETTER(Canceled)(BOOL *aCanceled)
    398241{
    399242    CheckComArgOutPointerValid(aCanceled);
     
    409252}
    410253
    411 STDMETHODIMP ProgressBase::COMGETTER(ResultCode)(LONG *aResultCode)
     254STDMETHODIMP Progress::COMGETTER(ResultCode)(LONG *aResultCode)
    412255{
    413256    CheckComArgOutPointerValid(aResultCode);
     
    427270}
    428271
    429 STDMETHODIMP ProgressBase::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo)
     272STDMETHODIMP Progress::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo)
    430273{
    431274    CheckComArgOutPointerValid(aErrorInfo);
     
    445288}
    446289
    447 STDMETHODIMP ProgressBase::COMGETTER(OperationCount)(ULONG *aOperationCount)
     290STDMETHODIMP Progress::COMGETTER(OperationCount)(ULONG *aOperationCount)
    448291{
    449292    CheckComArgOutPointerValid(aOperationCount);
     
    459302}
    460303
    461 STDMETHODIMP ProgressBase::COMGETTER(Operation)(ULONG *aOperation)
     304STDMETHODIMP Progress::COMGETTER(Operation)(ULONG *aOperation)
    462305{
    463306    CheckComArgOutPointerValid(aOperation);
     
    473316}
    474317
    475 STDMETHODIMP ProgressBase::COMGETTER(OperationDescription)(BSTR *aOperationDescription)
     318STDMETHODIMP Progress::COMGETTER(OperationDescription)(BSTR *aOperationDescription)
    476319{
    477320    CheckComArgOutPointerValid(aOperationDescription);
     
    487330}
    488331
    489 STDMETHODIMP ProgressBase::COMGETTER(OperationPercent)(ULONG *aOperationPercent)
     332STDMETHODIMP Progress::COMGETTER(OperationPercent)(ULONG *aOperationPercent)
    490333{
    491334    CheckComArgOutPointerValid(aOperationPercent);
     
    504347}
    505348
    506 STDMETHODIMP ProgressBase::COMGETTER(OperationWeight)(ULONG *aOperationWeight)
     349STDMETHODIMP Progress::COMGETTER(OperationWeight)(ULONG *aOperationWeight)
    507350{
    508351    CheckComArgOutPointerValid(aOperationWeight);
     
    518361}
    519362
    520 STDMETHODIMP ProgressBase::COMSETTER(Timeout)(ULONG aTimeout)
     363STDMETHODIMP Progress::COMSETTER(Timeout)(ULONG aTimeout)
    521364{
    522365    AutoCaller autoCaller(this);
     
    534377}
    535378
    536 STDMETHODIMP ProgressBase::COMGETTER(Timeout)(ULONG *aTimeout)
     379STDMETHODIMP Progress::COMGETTER(Timeout)(ULONG *aTimeout)
    537380{
    538381    CheckComArgOutPointerValid(aTimeout);
     
    561404 * @param   pvUser          The callback argument.
    562405 */
    563 bool ProgressBase::setCancelCallback(void (*pfnCallback)(void *), void *pvUser)
     406bool Progress::setCancelCallback(void (*pfnCallback)(void *), void *pvUser)
    564407{
    565408    AutoCaller autoCaller(this);
     
    577420}
    578421
    579 ////////////////////////////////////////////////////////////////////////////////
    580 // Progress class
    581 ////////////////////////////////////////////////////////////////////////////////
    582 
    583422HRESULT Progress::FinalConstruct()
    584423{
    585     HRESULT rc = ProgressBase::FinalConstruct();
     424    mCancelable = FALSE;
     425    mCompleted = FALSE;
     426    mCanceled = FALSE;
     427    mResultCode = S_OK;
     428
     429    m_cOperations
     430        = m_ulTotalOperationsWeight
     431        = m_ulOperationsCompletedWeight
     432        = m_ulCurrentOperation
     433        = m_ulCurrentOperationWeight
     434        = m_ulOperationPercent
     435        = m_cMsTimeout
     436        = 0;
     437
     438    // get creation timestamp
     439    m_ullTimestamp = RTTimeMilliTS();
     440
     441    m_pfnCancelCallback = NULL;
     442    m_pvCancelUserArg = NULL;
     443
     444    HRESULT rc = Progress::BaseFinalConstruct();
    586445    if (FAILED(rc)) return rc;
    587446
     
    639498 * ulTotalOperationsWeight = ulFirstOperationWeight = 1.
    640499 *
    641  * @param aParent           See ProgressBase::init().
    642  * @param aInitiator        See ProgressBase::init().
    643  * @param aDescription      See ProgressBase::init().
     500 * @param aParent           See Progress::init().
     501 * @param aInitiator        See Progress::init().
     502 * @param aDescription      See Progress::init().
    644503 * @param aCancelable       Flag whether the task maybe canceled.
    645504 * @param cOperations       Number of operations within this task (at least 1).
     
    648507 * @param bstrFirstOperationDescription Description of the first operation.
    649508 * @param ulFirstOperationWeight Weight of first sub-operation.
    650  * @param aId               See ProgressBase::init().
     509 * @param aId               See Progress::init().
    651510 */
    652511HRESULT Progress::init(
     
    679538    HRESULT rc = S_OK;
    680539
    681     rc = ProgressBase::protectedInit(autoInitSpan,
     540//    rc = Progress::init(
     541//#if !defined(VBOX_COM_INPROC)
     542//                        aParent,
     543//#endif
     544//                         aInitiator, aDescription, FALSE, aId);
     545// NA
    682546#if !defined(VBOX_COM_INPROC)
    683                                      aParent,
     547    AssertReturn(aParent, E_INVALIDARG);
     548#else
     549    AssertReturn(aInitiator, E_INVALIDARG);
    684550#endif
    685                                      aInitiator, aDescription, aId);
     551
     552    AssertReturn(aDescription, E_INVALIDARG);
     553
     554#if !defined(VBOX_COM_INPROC)
     555    /* share parent weakly */
     556    unconst(mParent) = aParent;
     557#endif
     558
     559#if !defined(VBOX_COM_INPROC)
     560    /* assign (and therefore addref) initiator only if it is not VirtualBox
     561 *      * (to avoid cycling); otherwise mInitiator will remain null which means
     562 *           * that it is the same as the parent */
     563    if (aInitiator)
     564    {
     565        ComObjPtr<VirtualBox> pVirtualBox(mParent);
     566        if (!(pVirtualBox == aInitiator))
     567            unconst(mInitiator) = aInitiator;
     568    }
     569#else
     570    unconst(mInitiator) = aInitiator;
     571#endif
     572
     573    unconst(mId).create();
     574    if (aId)
     575        mId.cloneTo(aId);
     576
     577#if !defined(VBOX_COM_INPROC)
     578    /* add to the global collection of progress operations (note: after
     579 *      * creating mId) */
     580    mParent->addProgress(this);
     581#endif
     582
     583    unconst(mDescription) = aDescription;
     584
     585
     586// end of assertion
     587
     588
    686589    if (FAILED(rc)) return rc;
    687590
     
    713616 *
    714617 * Objects initialized with this method are then combined together into the
    715  * single task using a CombinedProgress instance, so it doesn't require the
     618 * single task using a Progress instance, so it doesn't require the
    716619 * parent, initiator, description and doesn't create an ID. Note that calling
    717620 * respective getter methods on an object initialized with this method is
     
    734637
    735638    HRESULT rc = S_OK;
    736 
    737     rc = ProgressBase::protectedInit(autoInitSpan);
     639    /* Guarantees subclasses call this method at the proper time */
     640    NOREF(autoInitSpan);
     641
    738642    if (FAILED(rc)) return rc;
    739643
     
    762666}
    763667
     668
    764669/**
    765670 * Uninitializes the instance and sets the ready flag to FALSE.
     
    786691    RTSemEventMultiDestroy(mCompletedSem);
    787692
    788     ProgressBase::protectedUninit(autoUninitSpan);
    789 }
     693    /* release initiator (effective only if mInitiator has been assigned in
     694 *      * init()) */
     695    unconst(mInitiator).setNull();
     696
     697#if !defined(VBOX_COM_INPROC)
     698    if (mParent)
     699    {
     700        /* remove the added progress on failure to complete the initialization */
     701        if (autoUninitSpan.initFailed() && mId.isValid() && !mId.isZero())
     702            mParent->removeProgress(mId.ref());
     703
     704        unconst(mParent) = NULL;
     705    }
     706#endif
     707}
     708
    790709
    791710// IProgress properties
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