VirtualBox

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

Last change on this file since 26018 was 25859, checked in by vboxsync, 15 years ago

Main: cleanup: get rid of VirtualBoxBaseProto, move AutoCaller*/*Span* classes out of VirtualBoxBaseProto class scope and into separate header; move CombinedProgress into separate header (it's only used by Console any more)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: ProgressImpl.h 25859 2010-01-15 13:27:16Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifndef ____H_PROGRESSIMPL
24#define ____H_PROGRESSIMPL
25
26#include "VirtualBoxBase.h"
27
28#include <VBox/com/SupportErrorInfo.h>
29
30#include <iprt/semaphore.h>
31
32class VirtualBox;
33
34////////////////////////////////////////////////////////////////////////////////
35
36/**
37 * Base component class for progress objects.
38 */
39class ATL_NO_VTABLE ProgressBase :
40 public VirtualBoxBase,
41 public com::SupportErrorInfoBase,
42 public VirtualBoxSupportTranslation<ProgressBase>,
43 VBOX_SCRIPTABLE_IMPL(IProgress)
44{
45protected:
46
47 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (ProgressBase)
48
49 DECLARE_EMPTY_CTOR_DTOR (ProgressBase)
50
51 HRESULT FinalConstruct();
52
53 // protected initializer/uninitializer for internal purposes only
54 HRESULT protectedInit(AutoInitSpan &aAutoInitSpan,
55#if !defined (VBOX_COM_INPROC)
56 VirtualBox *aParent,
57#endif
58 IUnknown *aInitiator,
59 CBSTR aDescription, OUT_GUID aId = NULL);
60 HRESULT protectedInit(AutoInitSpan &aAutoInitSpan);
61 void protectedUninit(AutoUninitSpan &aAutoUninitSpan);
62
63public:
64
65 // IProgress properties
66 STDMETHOD(COMGETTER(Id)) (BSTR *aId);
67 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
68 STDMETHOD(COMGETTER(Initiator)) (IUnknown **aInitiator);
69
70 // IProgress properties
71 STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);
72 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
73 STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);
74 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
75 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
76 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
77 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
78 STDMETHOD(COMGETTER(OperationCount)) (ULONG *aOperationCount);
79 STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);
80 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
81 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
82 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);
83 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);
84
85 // public methods only for internal purposes
86
87 static HRESULT setErrorInfoOnThread (IProgress *aProgress);
88 bool setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
89
90
91 // unsafe inline public methods for internal purposes only (ensure there is
92 // a caller and a read lock before calling them!)
93
94 BOOL getCompleted() const { return mCompleted; }
95 HRESULT getResultCode() const { return mResultCode; }
96 double calcTotalPercent();
97
98protected:
99 void checkForAutomaticTimeout(void);
100
101#if !defined (VBOX_COM_INPROC)
102 /** Weak parent. */
103 const ComObjPtr<VirtualBox, ComWeakRef> mParent;
104#endif
105
106 const ComPtr<IUnknown> mInitiator;
107
108 const Guid mId;
109 const Bstr mDescription;
110
111 uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation
112
113 void (*m_pfnCancelCallback)(void *);
114 void *m_pvCancelUserArg;
115
116 /* The fields below are to be properly initalized by subclasses */
117
118 BOOL mCompleted;
119 BOOL mCancelable;
120 BOOL mCanceled;
121 HRESULT mResultCode;
122 ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
123
124 ULONG m_cOperations; // number of operations (so that progress dialog can display something like 1/3)
125 ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor
126
127 ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0
128
129 ULONG m_ulCurrentOperation; // operations counter, incremented with each setNextOperation()
130 Bstr m_bstrOperationDescription; // name of current operation; initially from constructor, changed with setNextOperation()
131 ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()
132 ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()
133 ULONG m_cMsTimeout; /**< Automatic timeout value. 0 means none. */
134};
135
136////////////////////////////////////////////////////////////////////////////////
137
138/**
139 * Normal progress object.
140 */
141class ATL_NO_VTABLE Progress :
142 public com::SupportErrorInfoDerived<ProgressBase, Progress, IProgress>,
143 public VirtualBoxSupportTranslation<Progress>
144{
145
146public:
147
148 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (Progress)
149
150 DECLARE_NOT_AGGREGATABLE (Progress)
151
152 DECLARE_PROTECT_FINAL_CONSTRUCT()
153
154 BEGIN_COM_MAP (Progress)
155 COM_INTERFACE_ENTRY (ISupportErrorInfo)
156 COM_INTERFACE_ENTRY (IProgress)
157 COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
158 END_COM_MAP()
159
160 HRESULT FinalConstruct();
161 void FinalRelease();
162
163 // public initializer/uninitializer for internal purposes only
164
165 /**
166 * Simplified constructor for progress objects that have only one
167 * operation as a task.
168 * @param aParent
169 * @param aInitiator
170 * @param aDescription
171 * @param aCancelable
172 * @param aId
173 * @return
174 */
175 HRESULT init(
176#if !defined (VBOX_COM_INPROC)
177 VirtualBox *aParent,
178#endif
179 IUnknown *aInitiator,
180 CBSTR aDescription,
181 BOOL aCancelable,
182 OUT_GUID aId = NULL)
183 {
184 return init(
185#if !defined (VBOX_COM_INPROC)
186 aParent,
187#endif
188 aInitiator,
189 aDescription,
190 aCancelable,
191 1, // cOperations
192 1, // ulTotalOperationsWeight
193 aDescription, // bstrFirstOperationDescription
194 1, // ulFirstOperationWeight
195 aId);
196 }
197
198 /**
199 * Not quite so simplified constructor for progress objects that have
200 * more than one operation, but all sub-operations are weighed the same.
201 * @param aParent
202 * @param aInitiator
203 * @param aDescription
204 * @param aCancelable
205 * @param cOperations
206 * @param bstrFirstOperationDescription
207 * @param aId
208 * @return
209 */
210 HRESULT init(
211#if !defined (VBOX_COM_INPROC)
212 VirtualBox *aParent,
213#endif
214 IUnknown *aInitiator,
215 CBSTR aDescription, BOOL aCancelable,
216 ULONG cOperations,
217 CBSTR bstrFirstOperationDescription,
218 OUT_GUID aId = NULL)
219 {
220 return init(
221#if !defined (VBOX_COM_INPROC)
222 aParent,
223#endif
224 aInitiator,
225 aDescription,
226 aCancelable,
227 cOperations, // cOperations
228 cOperations, // ulTotalOperationsWeight = cOperations
229 bstrFirstOperationDescription, // bstrFirstOperationDescription
230 1, // ulFirstOperationWeight: weigh them all the same
231 aId);
232 }
233
234 HRESULT init(
235#if !defined (VBOX_COM_INPROC)
236 VirtualBox *aParent,
237#endif
238 IUnknown *aInitiator,
239 CBSTR aDescription,
240 BOOL aCancelable,
241 ULONG cOperations,
242 ULONG ulTotalOperationsWeight,
243 CBSTR bstrFirstOperationDescription,
244 ULONG ulFirstOperationWeight,
245 OUT_GUID aId = NULL);
246
247 HRESULT init(BOOL aCancelable,
248 ULONG aOperationCount,
249 CBSTR aOperationDescription);
250
251 void uninit();
252
253 // IProgress methods
254 STDMETHOD(WaitForCompletion)(LONG aTimeout);
255 STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);
256 STDMETHOD(Cancel)();
257
258 STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);
259 STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);
260
261 // public methods only for internal purposes
262
263 HRESULT setResultCode(HRESULT aResultCode);
264
265 HRESULT notifyComplete(HRESULT aResultCode);
266 HRESULT notifyComplete(HRESULT aResultCode,
267 const GUID &aIID,
268 const Bstr &aComponent,
269 const char *aText, ...);
270 bool notifyPointOfNoReturn(void);
271
272 /** For com::SupportErrorInfoImpl. */
273 static const char *ComponentName() { return "Progress"; }
274
275private:
276
277 RTSEMEVENTMULTI mCompletedSem;
278 ULONG mWaitersCount;
279};
280
281#endif /* ____H_PROGRESSIMPL */
282
Note: See TracBrowser for help on using the repository browser.

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