VirtualBox

source: vbox/trunk/src/VBox/Main/include/ProgressImpl.h@ 33004

Last change on this file since 33004 was 31625, checked in by vboxsync, 14 years ago

Main: add a getter in IProgress for getting the current operation weight

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/* $Id: ProgressImpl.h 31625 2010-08-13 00:33:16Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2010 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ____H_PROGRESSIMPL
20#define ____H_PROGRESSIMPL
21
22#include "VirtualBoxBase.h"
23
24#include <iprt/semaphore.h>
25
26////////////////////////////////////////////////////////////////////////////////
27
28/**
29 * Base component class for progress objects.
30 */
31class ATL_NO_VTABLE ProgressBase :
32 public VirtualBoxBase,
33 VBOX_SCRIPTABLE_IMPL(IProgress)
34{
35protected:
36
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)
42
43 HRESULT FinalConstruct();
44
45 // protected initializer/uninitializer for internal purposes only
46 HRESULT protectedInit(AutoInitSpan &aAutoInitSpan,
47#if !defined (VBOX_COM_INPROC)
48 VirtualBox *aParent,
49#endif
50 IUnknown *aInitiator,
51 CBSTR aDescription, OUT_GUID aId = NULL);
52 HRESULT protectedInit(AutoInitSpan &aAutoInitSpan);
53 void protectedUninit(AutoUninitSpan &aAutoUninitSpan);
54
55public:
56
57 // IProgress properties
58 STDMETHOD(COMGETTER(Id)) (BSTR *aId);
59 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
60 STDMETHOD(COMGETTER(Initiator)) (IUnknown **aInitiator);
61
62 // IProgress properties
63 STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);
64 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
65 STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);
66 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
67 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
68 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
69 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
70 STDMETHOD(COMGETTER(OperationCount)) (ULONG *aOperationCount);
71 STDMETHOD(COMGETTER(Operation)) (ULONG *aOperation);
72 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
73 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
74 STDMETHOD(COMGETTER(OperationWeight)) (ULONG *aOperationWeight);
75 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);
76 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);
77
78 // public methods only for internal purposes
79
80 bool setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
81
82
83 // unsafe inline public methods for internal purposes only (ensure there is
84 // a caller and a read lock before calling them!)
85
86 BOOL getCompleted() const { return mCompleted; }
87 HRESULT getResultCode() const { return mResultCode; }
88 double calcTotalPercent();
89
90protected:
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 initalized 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 */
133class ATL_NO_VTABLE Progress :
134 public ProgressBase
135{
136
137public:
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 COM_INTERFACE_ENTRY (ISupportErrorInfo)
146 COM_INTERFACE_ENTRY (IProgress)
147 COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
148 END_COM_MAP()
149
150 HRESULT FinalConstruct();
151 void FinalRelease();
152
153 // public initializer/uninitializer for internal purposes only
154
155 /**
156 * Simplified constructor for progress objects that have only one
157 * operation as a task.
158 * @param aParent
159 * @param aInitiator
160 * @param aDescription
161 * @param aCancelable
162 * @param aId
163 * @return
164 */
165 HRESULT init(
166#if !defined (VBOX_COM_INPROC)
167 VirtualBox *aParent,
168#endif
169 IUnknown *aInitiator,
170 CBSTR aDescription,
171 BOOL aCancelable,
172 OUT_GUID aId = NULL)
173 {
174 return init(
175#if !defined (VBOX_COM_INPROC)
176 aParent,
177#endif
178 aInitiator,
179 aDescription,
180 aCancelable,
181 1, // cOperations
182 1, // ulTotalOperationsWeight
183 aDescription, // bstrFirstOperationDescription
184 1, // ulFirstOperationWeight
185 aId);
186 }
187
188 /**
189 * Not quite so simplified constructor for progress objects that have
190 * more than one operation, but all sub-operations are weighed the same.
191 * @param aParent
192 * @param aInitiator
193 * @param aDescription
194 * @param aCancelable
195 * @param cOperations
196 * @param bstrFirstOperationDescription
197 * @param aId
198 * @return
199 */
200 HRESULT init(
201#if !defined (VBOX_COM_INPROC)
202 VirtualBox *aParent,
203#endif
204 IUnknown *aInitiator,
205 CBSTR aDescription, BOOL aCancelable,
206 ULONG cOperations,
207 CBSTR bstrFirstOperationDescription,
208 OUT_GUID aId = NULL)
209 {
210 return init(
211#if !defined (VBOX_COM_INPROC)
212 aParent,
213#endif
214 aInitiator,
215 aDescription,
216 aCancelable,
217 cOperations, // cOperations
218 cOperations, // ulTotalOperationsWeight = cOperations
219 bstrFirstOperationDescription, // bstrFirstOperationDescription
220 1, // ulFirstOperationWeight: weigh them all the same
221 aId);
222 }
223
224 HRESULT init(
225#if !defined (VBOX_COM_INPROC)
226 VirtualBox *aParent,
227#endif
228 IUnknown *aInitiator,
229 CBSTR aDescription,
230 BOOL aCancelable,
231 ULONG cOperations,
232 ULONG ulTotalOperationsWeight,
233 CBSTR bstrFirstOperationDescription,
234 ULONG ulFirstOperationWeight,
235 OUT_GUID aId = NULL);
236
237 HRESULT init(BOOL aCancelable,
238 ULONG aOperationCount,
239 CBSTR aOperationDescription);
240
241 void uninit();
242
243 // IProgress methods
244 STDMETHOD(WaitForCompletion)(LONG aTimeout);
245 STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);
246 STDMETHOD(Cancel)();
247
248 STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);
249 STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);
250
251 // public methods only for internal purposes
252
253 HRESULT setResultCode(HRESULT aResultCode);
254
255 HRESULT notifyComplete(HRESULT aResultCode);
256 HRESULT notifyComplete(HRESULT aResultCode,
257 const GUID &aIID,
258 const char *pcszComponent,
259 const char *aText,
260 ...);
261 HRESULT notifyCompleteV(HRESULT aResultCode,
262 const GUID &aIID,
263 const char *pcszComponent,
264 const char *aText,
265 va_list va);
266 bool notifyPointOfNoReturn(void);
267
268private:
269
270 RTSEMEVENTMULTI mCompletedSem;
271 ULONG mWaitersCount;
272};
273
274#endif /* ____H_PROGRESSIMPL */
275
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette