VirtualBox

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

Last change on this file since 46959 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: ProgressImpl.h 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2013 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 * Class for progress objects.
30 */
31class ATL_NO_VTABLE Progress :
32 public VirtualBoxBase,
33 VBOX_SCRIPTABLE_IMPL(IProgress)
34{
35protected:
36
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()
86
87 HRESULT FinalConstruct();
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(
103#if !defined (VBOX_COM_INPROC)
104 VirtualBox *aParent,
105#endif
106 IUnknown *aInitiator,
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);
215
216 // IProgress properties
217 STDMETHOD(COMGETTER(Id)) (BSTR *aId);
218 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
219 STDMETHOD(COMGETTER(Initiator)) (IUnknown **aInitiator);
220
221 // IProgress properties
222 STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);
223 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
224 STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);
225 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
226 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
227 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
228 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
229 STDMETHOD(COMGETTER(OperationCount)) (ULONG *aOperationCount);
230 STDMETHOD(COMGETTER(Operation)) (ULONG *aOperation);
231 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
232 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
233 STDMETHOD(COMGETTER(OperationWeight)) (ULONG *aOperationWeight);
234 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);
235 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);
236
237 // public methods only for internal purposes
238
239 bool setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
240
241
242 // unsafe inline public methods for internal purposes only (ensure there is
243 // a caller and a read lock before calling them!)
244 BOOL getCompleted() const { return mCompleted; }
245 HRESULT getResultCode() const { return mResultCode; }
246 double calcTotalPercent();
247
248private:
249
250 RTSEMEVENTMULTI mCompletedSem;
251 ULONG mWaitersCount;
252};
253
254#endif /* ____H_PROGRESSIMPL */
255
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