VirtualBox

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

Last change on this file since 29853 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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