VirtualBox

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


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

Location:
trunk/src/VBox/Main
Files:
1 deleted
3 edited

Legend:

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

    r37069 r44288  
    2727
    2828/**
    29  * Base component class for progress objects.
     29 * Class for progress objects.
    3030 */
    31 class ATL_NO_VTABLE ProgressBase :
     31class ATL_NO_VTABLE Progress :
    3232    public VirtualBoxBase,
    3333    VBOX_SCRIPTABLE_IMPL(IProgress)
     
    3535protected:
    3636
    37 //  VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(ProgressBase, IProgress)
    38 //  cannot be added here or Windows will not buuld; as a result, ProgressBase cannot be
    39 //  instantiated, but we're not doing that anyway (but only its children)
    40 
    41     DECLARE_EMPTY_CTOR_DTOR (ProgressBase)
     37    DECLARE_EMPTY_CTOR_DTOR (Progress)
     38
     39
     40    void checkForAutomaticTimeout(void);
     41
     42#if !defined (VBOX_COM_INPROC)
     43    /** Weak parent. */
     44    VirtualBox * const      mParent;
     45#endif
     46
     47    const ComPtr<IUnknown>  mInitiator;
     48
     49    const Guid mId;
     50    const Bstr mDescription;
     51
     52    uint64_t m_ullTimestamp;                        // progress object creation timestamp, for ETA computation
     53
     54    void (*m_pfnCancelCallback)(void *);
     55    void *m_pvCancelUserArg;
     56
     57    /* The fields below are to be properly initialized by subclasses */
     58
     59    BOOL mCompleted;
     60    BOOL mCancelable;
     61    BOOL mCanceled;
     62    HRESULT mResultCode;
     63    ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
     64
     65    ULONG m_cOperations;                            // number of operations (so that progress dialog can display something like 1/3)
     66    ULONG m_ulTotalOperationsWeight;                // sum of weights of all operations, given to constructor
     67
     68    ULONG m_ulOperationsCompletedWeight;            // summed-up weight of operations that have been completed; initially 0
     69
     70    ULONG m_ulCurrentOperation;                     // operations counter, incremented with each setNextOperation()
     71    Bstr m_bstrOperationDescription;                // name of current operation; initially from constructor, changed with setNextOperation()
     72    ULONG m_ulCurrentOperationWeight;               // weight of current operation, given to setNextOperation()
     73    ULONG m_ulOperationPercent;                     // percentage of current operation, set with setCurrentOperationProgress()
     74    ULONG m_cMsTimeout;                             /**< Automatic timeout value. 0 means none. */
     75
     76public:
     77    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Progress, IProgress)
     78
     79    DECLARE_NOT_AGGREGATABLE (Progress)
     80
     81    DECLARE_PROTECT_FINAL_CONSTRUCT()
     82
     83    BEGIN_COM_MAP (Progress)
     84        VBOX_DEFAULT_INTERFACE_ENTRIES (IProgress)
     85    END_COM_MAP()
    4286
    4387    HRESULT FinalConstruct();
    44 
    45     // protected initializer/uninitializer for internal purposes only
    46     HRESULT protectedInit(AutoInitSpan &aAutoInitSpan,
     88    void FinalRelease();
     89
     90    // public initializer/uninitializer for internal purposes only
     91
     92    /**
     93     * Simplified constructor for progress objects that have only one
     94     * operation as a task.
     95     * @param aParent
     96     * @param aInitiator
     97     * @param aDescription
     98     * @param aCancelable
     99     * @param aId
     100     * @return
     101     */
     102    HRESULT init(
    47103#if !defined (VBOX_COM_INPROC)
    48104                  VirtualBox *aParent,
    49105#endif
    50106                  IUnknown *aInitiator,
    51                   CBSTR aDescription, OUT_GUID aId = NULL);
    52     HRESULT protectedInit(AutoInitSpan &aAutoInitSpan);
    53     void protectedUninit(AutoUninitSpan &aAutoUninitSpan);
    54 
    55 public:
     107                  CBSTR aDescription,
     108                  BOOL aCancelable,
     109                  OUT_GUID aId = NULL)
     110    {
     111        return init(
     112#if !defined (VBOX_COM_INPROC)
     113            aParent,
     114#endif
     115            aInitiator,
     116            aDescription,
     117            aCancelable,
     118            1,      // cOperations
     119            1,      // ulTotalOperationsWeight
     120            aDescription, // bstrFirstOperationDescription
     121            1,      // ulFirstOperationWeight
     122            aId);
     123    }
     124
     125    /**
     126     * Not quite so simplified constructor for progress objects that have
     127     * more than one operation, but all sub-operations are weighed the same.
     128     * @param aParent
     129     * @param aInitiator
     130     * @param aDescription
     131     * @param aCancelable
     132     * @param cOperations
     133     * @param bstrFirstOperationDescription
     134     * @param aId
     135     * @return
     136     */
     137    HRESULT init(
     138#if !defined (VBOX_COM_INPROC)
     139                  VirtualBox *aParent,
     140#endif
     141                  IUnknown *aInitiator,
     142                  CBSTR aDescription, BOOL aCancelable,
     143                  ULONG cOperations,
     144                  CBSTR bstrFirstOperationDescription,
     145                  OUT_GUID aId = NULL)
     146    {
     147        return init(
     148#if !defined (VBOX_COM_INPROC)
     149            aParent,
     150#endif
     151            aInitiator,
     152            aDescription,
     153            aCancelable,
     154            cOperations,      // cOperations
     155            cOperations,      // ulTotalOperationsWeight = cOperations
     156            bstrFirstOperationDescription, // bstrFirstOperationDescription
     157            1,      // ulFirstOperationWeight: weigh them all the same
     158            aId);
     159    }
     160
     161    HRESULT init(
     162#if !defined (VBOX_COM_INPROC)
     163                  VirtualBox *aParent,
     164#endif
     165                  IUnknown *aInitiator,
     166                  CBSTR aDescription,
     167                  BOOL aCancelable,
     168                  ULONG cOperations,
     169                  ULONG ulTotalOperationsWeight,
     170                  CBSTR bstrFirstOperationDescription,
     171                  ULONG ulFirstOperationWeight,
     172                  OUT_GUID aId = NULL);
     173
     174    HRESULT init(BOOL aCancelable,
     175                 ULONG aOperationCount,
     176                 CBSTR aOperationDescription);
     177
     178//   initializer/uninitializer for internal purposes only
     179    HRESULT init(AutoInitSpan &aAutoInitSpan,
     180#if !defined (VBOX_COM_INPROC)
     181               VirtualBox *aParent,
     182#endif
     183               IUnknown *aInitiator,
     184               CBSTR aDescription, OUT_GUID aId = NULL);
     185    HRESULT init(AutoInitSpan &aAutoInitSpan);
     186    void init(AutoUninitSpan &aAutoUninitSpan);
     187    void uninit();
     188    void uninit(AutoUninitSpan &aAutoUninitSpan);
     189
     190    // IProgress methods
     191    STDMETHOD(WaitForCompletion)(LONG aTimeout);
     192    STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);
     193    STDMETHOD(WaitForAsyncProgressCompletion)(IProgress *pProgressAsync);
     194    STDMETHOD(Cancel)();
     195
     196    STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);
     197    STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);
     198
     199    // public methods only for internal purposes
     200
     201    HRESULT setResultCode(HRESULT aResultCode);
     202
     203    HRESULT notifyComplete(HRESULT aResultCode);
     204    HRESULT notifyComplete(HRESULT aResultCode,
     205                           const GUID &aIID,
     206                           const char *pcszComponent,
     207                           const char *aText,
     208                           ...);
     209    HRESULT notifyCompleteV(HRESULT aResultCode,
     210                            const GUID &aIID,
     211                            const char *pcszComponent,
     212                            const char *aText,
     213                            va_list va);
     214    bool notifyPointOfNoReturn(void);
    56215
    57216    // IProgress properties
     
    83242    // unsafe inline public methods for internal purposes only (ensure there is
    84243    // a caller and a read lock before calling them!)
    85 
    86244    BOOL getCompleted() const { return mCompleted; }
    87245    HRESULT getResultCode() const { return mResultCode; }
    88246    double calcTotalPercent();
    89247
    90 protected:
    91     void checkForAutomaticTimeout(void);
    92 
    93 #if !defined (VBOX_COM_INPROC)
    94     /** Weak parent. */
    95     VirtualBox * const      mParent;
    96 #endif
    97 
    98     const ComPtr<IUnknown>  mInitiator;
    99 
    100     const Guid mId;
    101     const Bstr mDescription;
    102 
    103     uint64_t m_ullTimestamp;                        // progress object creation timestamp, for ETA computation
    104 
    105     void (*m_pfnCancelCallback)(void *);
    106     void *m_pvCancelUserArg;
    107 
    108     /* The fields below are to be properly initialized by subclasses */
    109 
    110     BOOL mCompleted;
    111     BOOL mCancelable;
    112     BOOL mCanceled;
    113     HRESULT mResultCode;
    114     ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
    115 
    116     ULONG m_cOperations;                            // number of operations (so that progress dialog can display something like 1/3)
    117     ULONG m_ulTotalOperationsWeight;                // sum of weights of all operations, given to constructor
    118 
    119     ULONG m_ulOperationsCompletedWeight;            // summed-up weight of operations that have been completed; initially 0
    120 
    121     ULONG m_ulCurrentOperation;                     // operations counter, incremented with each setNextOperation()
    122     Bstr m_bstrOperationDescription;                // name of current operation; initially from constructor, changed with setNextOperation()
    123     ULONG m_ulCurrentOperationWeight;               // weight of current operation, given to setNextOperation()
    124     ULONG m_ulOperationPercent;                     // percentage of current operation, set with setCurrentOperationProgress()
    125     ULONG m_cMsTimeout;                             /**< Automatic timeout value. 0 means none. */
    126 };
    127 
    128 ////////////////////////////////////////////////////////////////////////////////
    129 
    130 /**
    131  * Normal progress object.
    132  */
    133 class ATL_NO_VTABLE Progress :
    134     public ProgressBase
    135 {
    136 
    137 public:
    138     VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Progress, IProgress)
    139 
    140     DECLARE_NOT_AGGREGATABLE (Progress)
    141 
    142     DECLARE_PROTECT_FINAL_CONSTRUCT()
    143 
    144     BEGIN_COM_MAP (Progress)
    145         VBOX_DEFAULT_INTERFACE_ENTRIES (IProgress)
    146     END_COM_MAP()
    147 
    148     HRESULT FinalConstruct();
    149     void FinalRelease();
    150 
    151     // public initializer/uninitializer for internal purposes only
    152 
    153     /**
    154      * Simplified constructor for progress objects that have only one
    155      * operation as a task.
    156      * @param aParent
    157      * @param aInitiator
    158      * @param aDescription
    159      * @param aCancelable
    160      * @param aId
    161      * @return
    162      */
    163     HRESULT init(
    164 #if !defined (VBOX_COM_INPROC)
    165                   VirtualBox *aParent,
    166 #endif
    167                   IUnknown *aInitiator,
    168                   CBSTR aDescription,
    169                   BOOL aCancelable,
    170                   OUT_GUID aId = NULL)
    171     {
    172         return init(
    173 #if !defined (VBOX_COM_INPROC)
    174             aParent,
    175 #endif
    176             aInitiator,
    177             aDescription,
    178             aCancelable,
    179             1,      // cOperations
    180             1,      // ulTotalOperationsWeight
    181             aDescription, // bstrFirstOperationDescription
    182             1,      // ulFirstOperationWeight
    183             aId);
    184     }
    185 
    186     /**
    187      * Not quite so simplified constructor for progress objects that have
    188      * more than one operation, but all sub-operations are weighed the same.
    189      * @param aParent
    190      * @param aInitiator
    191      * @param aDescription
    192      * @param aCancelable
    193      * @param cOperations
    194      * @param bstrFirstOperationDescription
    195      * @param aId
    196      * @return
    197      */
    198     HRESULT init(
    199 #if !defined (VBOX_COM_INPROC)
    200                   VirtualBox *aParent,
    201 #endif
    202                   IUnknown *aInitiator,
    203                   CBSTR aDescription, BOOL aCancelable,
    204                   ULONG cOperations,
    205                   CBSTR bstrFirstOperationDescription,
    206                   OUT_GUID aId = NULL)
    207     {
    208         return init(
    209 #if !defined (VBOX_COM_INPROC)
    210             aParent,
    211 #endif
    212             aInitiator,
    213             aDescription,
    214             aCancelable,
    215             cOperations,      // cOperations
    216             cOperations,      // ulTotalOperationsWeight = cOperations
    217             bstrFirstOperationDescription, // bstrFirstOperationDescription
    218             1,      // ulFirstOperationWeight: weigh them all the same
    219             aId);
    220     }
    221 
    222     HRESULT init(
    223 #if !defined (VBOX_COM_INPROC)
    224                   VirtualBox *aParent,
    225 #endif
    226                   IUnknown *aInitiator,
    227                   CBSTR aDescription,
    228                   BOOL aCancelable,
    229                   ULONG cOperations,
    230                   ULONG ulTotalOperationsWeight,
    231                   CBSTR bstrFirstOperationDescription,
    232                   ULONG ulFirstOperationWeight,
    233                   OUT_GUID aId = NULL);
    234 
    235     HRESULT init(BOOL aCancelable,
    236                  ULONG aOperationCount,
    237                  CBSTR aOperationDescription);
    238 
    239     void uninit();
    240 
    241     // IProgress methods
    242     STDMETHOD(WaitForCompletion)(LONG aTimeout);
    243     STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);
    244     STDMETHOD(WaitForAsyncProgressCompletion)(IProgress *pProgressAsync);
    245     STDMETHOD(Cancel)();
    246 
    247     STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);
    248     STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);
    249 
    250     // public methods only for internal purposes
    251 
    252     HRESULT setResultCode(HRESULT aResultCode);
    253 
    254     HRESULT notifyComplete(HRESULT aResultCode);
    255     HRESULT notifyComplete(HRESULT aResultCode,
    256                            const GUID &aIID,
    257                            const char *pcszComponent,
    258                            const char *aText,
    259                            ...);
    260     HRESULT notifyCompleteV(HRESULT aResultCode,
    261                             const GUID &aIID,
    262                             const char *pcszComponent,
    263                             const char *aText,
    264                             va_list va);
    265     bool notifyPointOfNoReturn(void);
    266 
    267248private:
    268249
  • 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
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r44191 r44288  
    59625962    AutoCaller autoCaller(this);
    59635963    AssertComRCReturnVoid(autoCaller.rc());
    5964 
    59655964    fireStateChangedEvent(mEventSource, machineState);
    59665965}
     
    63296328HRESULT Console::powerUp(IProgress **aProgress, bool aPaused)
    63306329{
     6330
    63316331    LogFlowThisFuncEnter();
    63326332    LogFlowThisFunc(("mMachineState=%d\n", mMachineState));
     
    63436343    bool fBeganPoweringUp = false;
    63446344
     6345    LONG cOperations = 1;
     6346    LONG ulTotalOperationsWeight = 1;
     6347
    63456348    try
    63466349    {
     6350
    63476351        if (Global::IsOnlineOrTransient(mMachineState))
    63486352            throw setError(VBOX_E_INVALID_VM_STATE,
     
    63616365        if (FAILED(rc))
    63626366            throw rc;
     6367
    63636368#if 0 /** @todo we should save it afterwards, but that isn't necessarily a good idea. Find a better place for this (VBoxSVC).  */
    63646369        if (fTeleporterEnabled)
     
    63916396        else
    63926397            progressDesc = tr("Starting virtual machine");
    6393         if (    mMachineState == MachineState_Saved
     6398
     6399        /* Check all types of shared folders and compose a single list */
     6400        SharedFolderDataMap sharedFolders;
     6401        {
     6402            /* first, insert global folders */
     6403            for (SharedFolderDataMap::const_iterator it = m_mapGlobalSharedFolders.begin();
     6404                 it != m_mapGlobalSharedFolders.end();
     6405                 ++it)
     6406            {
     6407                const SharedFolderData &d = it->second;
     6408                sharedFolders[it->first] = d;
     6409            }
     6410
     6411            /* second, insert machine folders */
     6412            for (SharedFolderDataMap::const_iterator it = m_mapMachineSharedFolders.begin();
     6413                 it != m_mapMachineSharedFolders.end();
     6414                 ++it)
     6415            {
     6416                const SharedFolderData &d = it->second;
     6417                sharedFolders[it->first] = d;
     6418            }
     6419
     6420            /* third, insert console folders */
     6421            for (SharedFolderMap::const_iterator it = m_mapSharedFolders.begin();
     6422                 it != m_mapSharedFolders.end();
     6423                 ++it)
     6424            {
     6425                SharedFolder *pSF = it->second;
     6426                AutoCaller sfCaller(pSF);
     6427                AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS);
     6428                sharedFolders[it->first] = SharedFolderData(pSF->getHostPath(),
     6429                                                            pSF->isWritable(),
     6430                                                            pSF->isAutoMounted());
     6431            }
     6432        }
     6433
     6434        Bstr savedStateFile;
     6435
     6436        /*
     6437         * Saved VMs will have to prove that their saved states seem kosher.
     6438         */
     6439        if (mMachineState == MachineState_Saved)
     6440        {
     6441            rc = mMachine->COMGETTER(StateFilePath)(savedStateFile.asOutParam());
     6442            if (FAILED(rc))
     6443                throw rc;
     6444            ComAssertRet(!savedStateFile.isEmpty(), E_FAIL);
     6445            int vrc = SSMR3ValidateFile(Utf8Str(savedStateFile).c_str(), false /* fChecksumIt */);
     6446            if (RT_FAILURE(vrc))
     6447                throw setError(VBOX_E_FILE_ERROR,
     6448                               tr("VM cannot start because the saved state file '%ls' is invalid (%Rrc). Delete the saved state prior to starting the VM"),
     6449                               savedStateFile.raw(), vrc);
     6450        }
     6451
     6452        /* Setup task object and thread to carry out the operaton
     6453         * Asycnhronously */
     6454        std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
     6455        ComAssertComRCRetRC(task->rc());
     6456
     6457        task->mConfigConstructor = configConstructor;
     6458        task->mSharedFolders = sharedFolders;
     6459        task->mStartPaused = aPaused;
     6460        if (mMachineState == MachineState_Saved)
     6461            task->mSavedStateFile = savedStateFile;
     6462        task->mTeleporterEnabled = fTeleporterEnabled;
     6463        task->mEnmFaultToleranceState = enmFaultToleranceState;
     6464
     6465        /* Reset differencing hard disks for which autoReset is true,
     6466         * but only if the machine has no snapshots OR the current snapshot
     6467         * is an OFFLINE snapshot; otherwise we would reset the current
     6468         * differencing image of an ONLINE snapshot which contains the disk
     6469         * state of the machine while it was previously running, but without
     6470         * the corresponding machine state, which is equivalent to powering
     6471         * off a running machine and not good idea
     6472         */
     6473        ComPtr<ISnapshot> pCurrentSnapshot;
     6474        rc = mMachine->COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam());
     6475        if (FAILED(rc))
     6476            throw rc;
     6477
     6478        BOOL fCurrentSnapshotIsOnline = false;
     6479        if (pCurrentSnapshot)
     6480        {
     6481            rc = pCurrentSnapshot->COMGETTER(Online)(&fCurrentSnapshotIsOnline);
     6482            if (FAILED(rc))
     6483                throw rc;
     6484        }
     6485
     6486        if (!fCurrentSnapshotIsOnline)
     6487        {
     6488            LogFlowThisFunc(("Looking for immutable images to reset\n"));
     6489
     6490            com::SafeIfaceArray<IMediumAttachment> atts;
     6491            rc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(atts));
     6492            if (FAILED(rc))
     6493                throw rc;
     6494
     6495            for (size_t i = 0;
     6496                 i < atts.size();
     6497                 ++i)
     6498            {
     6499                DeviceType_T devType;
     6500                rc = atts[i]->COMGETTER(Type)(&devType);
     6501                /** @todo later applies to floppies as well */
     6502                if (devType == DeviceType_HardDisk)
     6503                {
     6504                    ComPtr<IMedium> pMedium;
     6505                    rc = atts[i]->COMGETTER(Medium)(pMedium.asOutParam());
     6506                    if (FAILED(rc))
     6507                        throw rc;
     6508
     6509                    /* needs autoreset? */
     6510                    BOOL autoReset = FALSE;
     6511                    rc = pMedium->COMGETTER(AutoReset)(&autoReset);
     6512                    if (FAILED(rc))
     6513                        throw rc;
     6514
     6515                    if (autoReset)
     6516                    {
     6517                        ComPtr<IProgress> pResetProgress;
     6518                        rc = pMedium->Reset(pResetProgress.asOutParam());
     6519                        if (FAILED(rc))
     6520                            throw rc;
     6521
     6522                        /* save for later use on the powerup thread */
     6523                        task->hardDiskProgresses.push_back(pResetProgress);
     6524                    }
     6525                }
     6526            }
     6527        }
     6528        else
     6529            LogFlowThisFunc(("Machine has a current snapshot which is online, skipping immutable images reset\n"));
     6530
     6531        /* setup task object and thread to carry out the operation
     6532         * asynchronously */
     6533
     6534#ifdef VBOX_WITH_EXTPACK
     6535        mptrExtPackManager->dumpAllToReleaseLog();
     6536#endif
     6537
     6538#ifdef RT_OS_SOLARIS
     6539        /* setup host core dumper for the VM */
     6540        Bstr value;
     6541        HRESULT hrc = mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpEnabled").raw(), value.asOutParam());
     6542        if (SUCCEEDED(hrc) && value == "1")
     6543        {
     6544            Bstr coreDumpDir, coreDumpReplaceSys, coreDumpLive;
     6545            mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpDir").raw(), coreDumpDir.asOutParam());
     6546            mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpReplaceSystemDump").raw(), coreDumpReplaceSys.asOutParam());
     6547            mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpLive").raw(), coreDumpLive.asOutParam());
     6548
     6549            uint32_t fCoreFlags = 0;
     6550            if (   coreDumpReplaceSys.isEmpty() == false
     6551                && Utf8Str(coreDumpReplaceSys).toUInt32() == 1)
     6552                fCoreFlags |= RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP;
     6553
     6554            if (   coreDumpLive.isEmpty() == false
     6555                && Utf8Str(coreDumpLive).toUInt32() == 1)
     6556                fCoreFlags |= RTCOREDUMPER_FLAGS_LIVE_CORE;
     6557
     6558            Utf8Str strDumpDir(coreDumpDir);
     6559            const char *pszDumpDir = strDumpDir.c_str();
     6560            if (   pszDumpDir
     6561                && *pszDumpDir == '\0')
     6562                pszDumpDir = NULL;
     6563
     6564            int vrc;
     6565            if (   pszDumpDir
     6566                && !RTDirExists(pszDumpDir))
     6567            {
     6568                /*
     6569                 * Try create the directory.
     6570                 */
     6571                vrc = RTDirCreateFullPath(pszDumpDir, 0700);
     6572                if (RT_FAILURE(vrc))
     6573                    throw setError(E_FAIL, "Failed to setup CoreDumper. Couldn't create dump directory '%s' (%Rrc)\n", pszDumpDir, vrc);
     6574            }
     6575
     6576            vrc = RTCoreDumperSetup(pszDumpDir, fCoreFlags);
     6577            if (RT_FAILURE(vrc))
     6578                throw setError(E_FAIL, "Failed to setup CoreDumper (%Rrc)", vrc);
     6579            else
     6580                LogRel(("CoreDumper setup successful. pszDumpDir=%s fFlags=%#x\n", pszDumpDir ? pszDumpDir : ".", fCoreFlags));
     6581        }
     6582#endif
     6583
     6584
     6585        // If there is immutable drive the process that.
     6586        VMPowerUpTask::ProgressList progresses(task->hardDiskProgresses);
     6587        if (aProgress && progresses.size() > 0){
     6588
     6589            for (VMPowerUpTask::ProgressList::const_iterator it = progresses.begin(); it !=  progresses.end(); ++it)
     6590            {
     6591                ++cOperations;
     6592                ulTotalOperationsWeight += 1;
     6593            }
     6594            rc = pPowerupProgress->init(static_cast<IConsole *>(this),
     6595                                        progressDesc.raw(),
     6596                                        TRUE, // Cancelable
     6597                                        cOperations,
     6598                                        ulTotalOperationsWeight,
     6599                                        Bstr(tr("Starting Hard Disk operations")).raw(),
     6600                                        1,
     6601                                        NULL);
     6602            AssertComRCReturnRC(rc);
     6603        }
     6604        else if (    mMachineState == MachineState_Saved
    63946605            ||  (!fTeleporterEnabled && !fFaultToleranceSyncEnabled))
     6606        {
    63956607            rc = pPowerupProgress->init(static_cast<IConsole *>(this),
    63966608                                        progressDesc.raw(),
    63976609                                        FALSE /* aCancelable */);
    6398         else
    6399         if (fTeleporterEnabled)
     6610        }
     6611        else if (fTeleporterEnabled)
     6612        {
    64006613            rc = pPowerupProgress->init(static_cast<IConsole *>(this),
    64016614                                        progressDesc.raw(),
     
    64066619                                        1    /* ulFirstOperationWeight */,
    64076620                                        NULL);
    6408         else
    6409         if (fFaultToleranceSyncEnabled)
     6621        }
     6622        else if (fFaultToleranceSyncEnabled)
     6623        {
    64106624            rc = pPowerupProgress->init(static_cast<IConsole *>(this),
    64116625                                        progressDesc.raw(),
     
    64166630                                        1    /* ulFirstOperationWeight */,
    64176631                                        NULL);
     6632        }
    64186633
    64196634        if (FAILED(rc))
     
    64306645        }
    64316646        fBeganPoweringUp = true;
     6647
     6648        LogFlowThisFunc(("Checking if canceled...\n"));
     6649        BOOL fCanceled;
     6650        rc = pPowerupProgress->COMGETTER(Canceled)(&fCanceled);
     6651        if (FAILED(rc))
     6652            throw rc;
     6653
     6654        if (fCanceled)
     6655        {
     6656            LogFlowThisFunc(("Canceled in BeginPowerUp\n"));
     6657            throw setError(E_FAIL, tr("Powerup was canceled"));
     6658        }
     6659        LogFlowThisFunc(("Not canceled yet.\n"));
    64326660
    64336661        /** @todo this code prevents starting a VM with unavailable bridged
     
    64906718            throw rc;
    64916719
    6492         /* Check all types of shared folders and compose a single list */
    6493         SharedFolderDataMap sharedFolders;
    6494         {
    6495             /* first, insert global folders */
    6496             for (SharedFolderDataMap::const_iterator it = m_mapGlobalSharedFolders.begin();
    6497                  it != m_mapGlobalSharedFolders.end();
    6498                  ++it)
    6499             {
    6500                 const SharedFolderData &d = it->second;
    6501                 sharedFolders[it->first] = d;
    6502             }
    6503 
    6504             /* second, insert machine folders */
    6505             for (SharedFolderDataMap::const_iterator it = m_mapMachineSharedFolders.begin();
    6506                  it != m_mapMachineSharedFolders.end();
    6507                  ++it)
    6508             {
    6509                 const SharedFolderData &d = it->second;
    6510                 sharedFolders[it->first] = d;
    6511             }
    6512 
    6513             /* third, insert console folders */
    6514             for (SharedFolderMap::const_iterator it = m_mapSharedFolders.begin();
    6515                  it != m_mapSharedFolders.end();
    6516                  ++it)
    6517             {
    6518                 SharedFolder *pSF = it->second;
    6519                 AutoCaller sfCaller(pSF);
    6520                 AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS);
    6521                 sharedFolders[it->first] = SharedFolderData(pSF->getHostPath(),
    6522                                                             pSF->isWritable(),
    6523                                                             pSF->isAutoMounted());
    6524             }
    6525         }
    6526 
    6527         Bstr savedStateFile;
    6528 
    6529         /*
    6530          * Saved VMs will have to prove that their saved states seem kosher.
    6531          */
    6532         if (mMachineState == MachineState_Saved)
    6533         {
    6534             rc = mMachine->COMGETTER(StateFilePath)(savedStateFile.asOutParam());
    6535             if (FAILED(rc))
    6536                 throw rc;
    6537             ComAssertRet(!savedStateFile.isEmpty(), E_FAIL);
    6538             int vrc = SSMR3ValidateFile(Utf8Str(savedStateFile).c_str(), false /* fChecksumIt */);
    6539             if (RT_FAILURE(vrc))
    6540                 throw setError(VBOX_E_FILE_ERROR,
    6541                                 tr("VM cannot start because the saved state file '%ls' is invalid (%Rrc). Delete the saved state prior to starting the VM"),
    6542                                 savedStateFile.raw(), vrc);
    6543         }
    6544 
    6545         LogFlowThisFunc(("Checking if canceled...\n"));
    6546         BOOL fCanceled;
    6547         rc = pPowerupProgress->COMGETTER(Canceled)(&fCanceled);
    6548         if (FAILED(rc))
    6549             throw rc;
    6550         if (fCanceled)
    6551         {
    6552             LogFlowThisFunc(("Canceled in BeginPowerUp\n"));
    6553             throw setError(E_FAIL, tr("Powerup was canceled"));
    6554         }
    6555         LogFlowThisFunc(("Not canceled yet.\n"));
    6556 
    65576720        /* setup task object and thread to carry out the operation
    65586721         * asynchronously */
    6559 
    6560         std::auto_ptr<VMPowerUpTask> task(new VMPowerUpTask(this, pPowerupProgress));
    6561         ComAssertComRCRetRC(task->rc());
    6562 
    6563         task->mConfigConstructor = configConstructor;
    6564         task->mSharedFolders = sharedFolders;
    6565         task->mStartPaused = aPaused;
    6566         if (mMachineState == MachineState_Saved)
    6567             task->mSavedStateFile = savedStateFile;
    6568         task->mTeleporterEnabled = fTeleporterEnabled;
    6569         task->mEnmFaultToleranceState = enmFaultToleranceState;
    6570 
    6571         /* Reset differencing hard disks for which autoReset is true,
    6572          * but only if the machine has no snapshots OR the current snapshot
    6573          * is an OFFLINE snapshot; otherwise we would reset the current
    6574          * differencing image of an ONLINE snapshot which contains the disk
    6575          * state of the machine while it was previously running, but without
    6576          * the corresponding machine state, which is equivalent to powering
    6577          * off a running machine and not good idea
    6578          */
    6579         ComPtr<ISnapshot> pCurrentSnapshot;
    6580         rc = mMachine->COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam());
    6581         if (FAILED(rc))
    6582             throw rc;
    6583 
    6584         BOOL fCurrentSnapshotIsOnline = false;
    6585         if (pCurrentSnapshot)
    6586         {
    6587             rc = pCurrentSnapshot->COMGETTER(Online)(&fCurrentSnapshotIsOnline);
    6588             if (FAILED(rc))
    6589                 throw rc;
    6590         }
    6591 
    6592         if (!fCurrentSnapshotIsOnline)
    6593         {
    6594             LogFlowThisFunc(("Looking for immutable images to reset\n"));
    6595 
    6596             com::SafeIfaceArray<IMediumAttachment> atts;
    6597             rc = mMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(atts));
    6598             if (FAILED(rc))
    6599                 throw rc;
    6600 
    6601             for (size_t i = 0;
    6602                  i < atts.size();
    6603                  ++i)
    6604             {
    6605                 DeviceType_T devType;
    6606                 rc = atts[i]->COMGETTER(Type)(&devType);
    6607                 /** @todo later applies to floppies as well */
    6608                 if (devType == DeviceType_HardDisk)
    6609                 {
    6610                     ComPtr<IMedium> pMedium;
    6611                     rc = atts[i]->COMGETTER(Medium)(pMedium.asOutParam());
    6612                     if (FAILED(rc))
    6613                         throw rc;
    6614 
    6615                     /* needs autoreset? */
    6616                     BOOL autoReset = FALSE;
    6617                     rc = pMedium->COMGETTER(AutoReset)(&autoReset);
    6618                     if (FAILED(rc))
    6619                         throw rc;
    6620 
    6621                     if (autoReset)
    6622                     {
    6623                         ComPtr<IProgress> pResetProgress;
    6624                         rc = pMedium->Reset(pResetProgress.asOutParam());
    6625                         if (FAILED(rc))
    6626                             throw rc;
    6627 
    6628                         /* save for later use on the powerup thread */
    6629                         task->hardDiskProgresses.push_back(pResetProgress);
    6630                     }
    6631                 }
    6632             }
    6633         }
    6634         else
    6635             LogFlowThisFunc(("Machine has a current snapshot which is online, skipping immutable images reset\n"));
    6636 
    6637 #ifdef VBOX_WITH_EXTPACK
    6638         mptrExtPackManager->dumpAllToReleaseLog();
    6639 #endif
    6640 
    6641 #ifdef RT_OS_SOLARIS
    6642         /* setup host core dumper for the VM */
    6643         Bstr value;
    6644         HRESULT hrc = mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpEnabled").raw(), value.asOutParam());
    6645         if (SUCCEEDED(hrc) && value == "1")
    6646         {
    6647             Bstr coreDumpDir, coreDumpReplaceSys, coreDumpLive;
    6648             mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpDir").raw(), coreDumpDir.asOutParam());
    6649             mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpReplaceSystemDump").raw(), coreDumpReplaceSys.asOutParam());
    6650             mMachine->GetExtraData(Bstr("VBoxInternal2/CoreDumpLive").raw(), coreDumpLive.asOutParam());
    6651 
    6652             uint32_t fCoreFlags = 0;
    6653             if (   coreDumpReplaceSys.isEmpty() == false
    6654                 && Utf8Str(coreDumpReplaceSys).toUInt32() == 1)
    6655             {
    6656                 fCoreFlags |= RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP;
    6657             }
    6658 
    6659             if (   coreDumpLive.isEmpty() == false
    6660                 && Utf8Str(coreDumpLive).toUInt32() == 1)
    6661             {
    6662                 fCoreFlags |= RTCOREDUMPER_FLAGS_LIVE_CORE;
    6663             }
    6664 
    6665             Utf8Str strDumpDir(coreDumpDir);
    6666             const char *pszDumpDir = strDumpDir.c_str();
    6667             if (   pszDumpDir
    6668                 && *pszDumpDir == '\0')
    6669                 pszDumpDir = NULL;
    6670 
    6671             int vrc;
    6672             if (   pszDumpDir
    6673                 && !RTDirExists(pszDumpDir))
    6674             {
    6675                 /*
    6676                  * Try create the directory.
    6677                  */
    6678                 vrc = RTDirCreateFullPath(pszDumpDir, 0700);
    6679                 if (RT_FAILURE(vrc))
    6680                     throw setError(E_FAIL, "Failed to setup CoreDumper. Couldn't create dump directory '%s' (%Rrc)\n", pszDumpDir, vrc);
    6681             }
    6682 
    6683             vrc = RTCoreDumperSetup(pszDumpDir, fCoreFlags);
    6684             if (RT_FAILURE(vrc))
    6685                 throw setError(E_FAIL, "Failed to setup CoreDumper (%Rrc)", vrc);
    6686             else
    6687                 LogRel(("CoreDumper setup successful. pszDumpDir=%s fFlags=%#x\n", pszDumpDir ? pszDumpDir : ".", fCoreFlags));
    6688         }
    6689 #endif
    6690 
    6691         /* pass the progress object to the caller if requested */
    6692         if (aProgress)
    6693         {
    6694             if (task->hardDiskProgresses.size() == 0)
    6695             {
    6696                 /* there are no other operations to track, return the powerup
    6697                  * progress only */
    6698                 pPowerupProgress.queryInterfaceTo(aProgress);
    6699             }
    6700             else
    6701             {
    6702                 // Create a simple progress object
    6703                 ComObjPtr<Progress> pProgress;
    6704                 pProgress.createObject();
    6705 
    6706                 // Assign hard disk progresses to the progresses list
    6707                 VMPowerUpTask::ProgressList progresses(task->hardDiskProgresses);
    6708 
    6709                 // Setup params to be used to initialize Progress object properties.
    6710                 ULONG cOperations = 1;
    6711                 ULONG ulTotalOperationsWeight = 1;
    6712 
    6713                 // Go round them and set number of operations and weight.
    6714                 for (VMPowerUpTask::ProgressList::const_iterator it = progresses.begin(); it !=  progresses.end(); ++it)
    6715                 {
    6716                     ++cOperations;
    6717                     ulTotalOperationsWeight += 1;
    6718                 }
    6719 
    6720                 rc = pProgress->init(static_cast<IConsole *>(this),
    6721                                      progressDesc.raw(),
    6722                                      TRUE, // Cancelable
    6723                                      cOperations,
    6724                                      ulTotalOperationsWeight,
    6725                                      Bstr(tr("Starting Hard Disk operations")).raw(), // first sub-op decription
    6726                                      1 );
    6727                 AssertComRCReturnRC(rc);
    6728 
    6729                 // Perform all the necessary operations.
    6730                 for (VMPowerUpTask::ProgressList::const_iterator it = progresses.begin(); it !=  progresses.end(); ++it)
    6731                 {
    6732                     rc = pProgress->SetNextOperation(BstrFmt(tr("Disk Image Reset Operation - Immutable Image")).raw(), 1);
    6733                     AssertComRCReturnRC(rc);
    6734                     rc = pProgress.queryInterfaceTo(aProgress);
    6735                     AssertComRCReturnRC(rc);
    6736                 }
    6737 
    6738                 // Now do the power up.
     6722        if (aProgress){
    67396723                rc = pPowerupProgress.queryInterfaceTo(aProgress);
    67406724                AssertComRCReturnRC(rc);
    6741             }
    67426725        }
    67436726
     
    67576740            setMachineState(MachineState_Restoring);
    67586741        else if (fTeleporterEnabled)
    6759             setMachineState(MachineState_TeleportingIn);
     6742           setMachineState(MachineState_TeleportingIn);
    67606743        else if (enmFaultToleranceState == FaultToleranceState_Standby)
    67616744            setMachineState(MachineState_FaultTolerantSyncing);
     
    88128795            HRESULT rc2 = (*it)->WaitForCompletion(-1);
    88138796            AssertComRC(rc2);
     8797
     8798            rc = task->mProgress->SetNextOperation(BstrFmt(tr("Disk Image Reset Operation - Immutable Image")).raw(), 1);
     8799            AssertComRCReturnRC(rc);
    88148800        }
    88158801
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