Changeset 25859 in vbox for trunk/src/VBox/Main/include/ProgressCombinedImpl.h
- Timestamp:
- Jan 15, 2010 1:27:16 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56658
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ProgressCombinedImpl.h
r25855 r25859 6 6 7 7 /* 8 * Copyright (C) 2006-20 09Sun Microsystems, Inc.8 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 */ 22 22 23 #ifndef ____H_PROGRESS IMPL24 #define ____H_PROGRESS IMPL23 #ifndef ____H_PROGRESSCOMBINEDIMPL 24 #define ____H_PROGRESSCOMBINEDIMPL 25 25 26 #include "VirtualBoxBase.h" 27 28 #include <VBox/com/SupportErrorInfo.h> 29 30 #include <iprt/semaphore.h> 26 #include "ProgressImpl.h" 27 #include "AutoCaller.h" 31 28 32 29 #include <vector> 33 34 class VirtualBox;35 36 ////////////////////////////////////////////////////////////////////////////////37 38 /**39 * Base component class for progress objects.40 */41 class ATL_NO_VTABLE ProgressBase :42 public VirtualBoxBase,43 public com::SupportErrorInfoBase,44 public VirtualBoxSupportTranslation<ProgressBase>,45 VBOX_SCRIPTABLE_IMPL(IProgress)46 {47 protected:48 49 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (ProgressBase)50 51 DECLARE_EMPTY_CTOR_DTOR (ProgressBase)52 53 HRESULT FinalConstruct();54 55 // protected initializer/uninitializer for internal purposes only56 HRESULT protectedInit (AutoInitSpan &aAutoInitSpan,57 #if !defined (VBOX_COM_INPROC)58 VirtualBox *aParent,59 #endif60 IUnknown *aInitiator,61 CBSTR aDescription, OUT_GUID aId = NULL);62 HRESULT protectedInit (AutoInitSpan &aAutoInitSpan);63 void protectedUninit (AutoUninitSpan &aAutoUninitSpan);64 65 public:66 67 // IProgress properties68 STDMETHOD(COMGETTER(Id)) (BSTR *aId);69 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);70 STDMETHOD(COMGETTER(Initiator)) (IUnknown **aInitiator);71 72 // IProgress properties73 STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);74 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);75 STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);76 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);77 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);78 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);79 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);80 STDMETHOD(COMGETTER(OperationCount)) (ULONG *aOperationCount);81 STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);82 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);83 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);84 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);85 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);86 87 // public methods only for internal purposes88 89 static HRESULT setErrorInfoOnThread (IProgress *aProgress);90 bool setCancelCallback(void (*pfnCallback)(void *), void *pvUser);91 92 93 // unsafe inline public methods for internal purposes only (ensure there is94 // a caller and a read lock before calling them!)95 96 BOOL getCompleted() const { return mCompleted; }97 HRESULT getResultCode() const { return mResultCode; }98 double calcTotalPercent();99 100 protected:101 void checkForAutomaticTimeout(void);102 103 #if !defined (VBOX_COM_INPROC)104 /** Weak parent. */105 const ComObjPtr<VirtualBox, ComWeakRef> mParent;106 #endif107 108 const ComPtr<IUnknown> mInitiator;109 110 const Guid mId;111 const Bstr mDescription;112 113 uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation114 115 void (*m_pfnCancelCallback)(void *);116 void *m_pvCancelUserArg;117 118 /* The fields below are to be properly initalized by subclasses */119 120 BOOL mCompleted;121 BOOL mCancelable;122 BOOL mCanceled;123 HRESULT mResultCode;124 ComPtr<IVirtualBoxErrorInfo> mErrorInfo;125 126 ULONG m_cOperations; // number of operations (so that progress dialog can display something like 1/3)127 ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor128 129 ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0130 131 ULONG m_ulCurrentOperation; // operations counter, incremented with each setNextOperation()132 Bstr m_bstrOperationDescription; // name of current operation; initially from constructor, changed with setNextOperation()133 ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()134 ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()135 ULONG m_cMsTimeout; /**< Automatic timeout value. 0 means none. */136 };137 138 ////////////////////////////////////////////////////////////////////////////////139 140 /**141 * Normal progress object.142 */143 class ATL_NO_VTABLE Progress :144 public com::SupportErrorInfoDerived<ProgressBase, Progress, IProgress>,145 public VirtualBoxSupportTranslation<Progress>146 {147 148 public:149 150 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (Progress)151 152 DECLARE_NOT_AGGREGATABLE (Progress)153 154 DECLARE_PROTECT_FINAL_CONSTRUCT()155 156 BEGIN_COM_MAP (Progress)157 COM_INTERFACE_ENTRY (ISupportErrorInfo)158 COM_INTERFACE_ENTRY (IProgress)159 COM_INTERFACE_ENTRY2 (IDispatch, IProgress)160 END_COM_MAP()161 162 HRESULT FinalConstruct();163 void FinalRelease();164 165 // public initializer/uninitializer for internal purposes only166 167 /**168 * Simplified constructor for progress objects that have only one169 * operation as a task.170 * @param aParent171 * @param aInitiator172 * @param aDescription173 * @param aCancelable174 * @param aId175 * @return176 */177 HRESULT init(178 #if !defined (VBOX_COM_INPROC)179 VirtualBox *aParent,180 #endif181 IUnknown *aInitiator,182 CBSTR aDescription,183 BOOL aCancelable,184 OUT_GUID aId = NULL)185 {186 return init(187 #if !defined (VBOX_COM_INPROC)188 aParent,189 #endif190 aInitiator,191 aDescription,192 aCancelable,193 1, // cOperations194 1, // ulTotalOperationsWeight195 aDescription, // bstrFirstOperationDescription196 1, // ulFirstOperationWeight197 aId);198 }199 200 /**201 * Not quite so simplified constructor for progress objects that have202 * more than one operation, but all sub-operations are weighed the same.203 * @param aParent204 * @param aInitiator205 * @param aDescription206 * @param aCancelable207 * @param cOperations208 * @param bstrFirstOperationDescription209 * @param aId210 * @return211 */212 HRESULT init(213 #if !defined (VBOX_COM_INPROC)214 VirtualBox *aParent,215 #endif216 IUnknown *aInitiator,217 CBSTR aDescription, BOOL aCancelable,218 ULONG cOperations,219 CBSTR bstrFirstOperationDescription,220 OUT_GUID aId = NULL)221 {222 return init(223 #if !defined (VBOX_COM_INPROC)224 aParent,225 #endif226 aInitiator,227 aDescription,228 aCancelable,229 cOperations, // cOperations230 cOperations, // ulTotalOperationsWeight = cOperations231 bstrFirstOperationDescription, // bstrFirstOperationDescription232 1, // ulFirstOperationWeight: weigh them all the same233 aId);234 }235 236 HRESULT init(237 #if !defined (VBOX_COM_INPROC)238 VirtualBox *aParent,239 #endif240 IUnknown *aInitiator,241 CBSTR aDescription,242 BOOL aCancelable,243 ULONG cOperations,244 ULONG ulTotalOperationsWeight,245 CBSTR bstrFirstOperationDescription,246 ULONG ulFirstOperationWeight,247 OUT_GUID aId = NULL);248 249 HRESULT init(BOOL aCancelable,250 ULONG aOperationCount,251 CBSTR aOperationDescription);252 253 void uninit();254 255 // IProgress methods256 STDMETHOD(WaitForCompletion)(LONG aTimeout);257 STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);258 STDMETHOD(Cancel)();259 260 STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);261 STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);262 263 // public methods only for internal purposes264 265 HRESULT setResultCode(HRESULT aResultCode);266 267 HRESULT notifyComplete(HRESULT aResultCode);268 HRESULT notifyComplete(HRESULT aResultCode,269 const GUID &aIID,270 const Bstr &aComponent,271 const char *aText, ...);272 bool notifyPointOfNoReturn(void);273 274 /** For com::SupportErrorInfoImpl. */275 static const char *ComponentName() { return "Progress"; }276 277 private:278 279 RTSEMEVENTMULTI mCompletedSem;280 ULONG mWaitersCount;281 };282 283 ////////////////////////////////////////////////////////////////////////////////284 30 285 31 /** … … 449 195 }; 450 196 451 #endif /* ____H_PROGRESS IMPL */197 #endif /* ____H_PROGRESSCOMBINEDIMPL */ 452 198
Note:
See TracChangeset
for help on using the changeset viewer.