1 | /* $Id: ProgressImpl.h 85251 2020-07-11 23:17:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2020 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 MAIN_INCLUDED_ProgressImpl_h
|
---|
20 | #define MAIN_INCLUDED_ProgressImpl_h
|
---|
21 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
22 | # pragma once
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | #include "ProgressWrap.h"
|
---|
26 | #include "VirtualBoxBase.h"
|
---|
27 | #include "EventImpl.h"
|
---|
28 |
|
---|
29 | #include <iprt/semaphore.h>
|
---|
30 |
|
---|
31 | ////////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Class for progress objects.
|
---|
35 | */
|
---|
36 | class ATL_NO_VTABLE Progress :
|
---|
37 | public ProgressWrap
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | DECLARE_NOT_AGGREGATABLE(Progress)
|
---|
41 |
|
---|
42 | HRESULT FinalConstruct();
|
---|
43 | void FinalRelease();
|
---|
44 |
|
---|
45 | // public initializer/uninitializer for internal purposes only
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Simplified constructor for progress objects that have only one
|
---|
49 | * operation as a task.
|
---|
50 | * @param aParent
|
---|
51 | * @param aInitiator
|
---|
52 | * @param aDescription
|
---|
53 | * @param aCancelable
|
---|
54 | * @return
|
---|
55 | */
|
---|
56 | HRESULT init(
|
---|
57 | #if !defined(VBOX_COM_INPROC)
|
---|
58 | VirtualBox *aParent,
|
---|
59 | #endif
|
---|
60 | IUnknown *aInitiator,
|
---|
61 | const Utf8Str &aDescription,
|
---|
62 | BOOL aCancelable)
|
---|
63 | {
|
---|
64 | return init(
|
---|
65 | #if !defined(VBOX_COM_INPROC)
|
---|
66 | aParent,
|
---|
67 | #endif
|
---|
68 | aInitiator,
|
---|
69 | aDescription,
|
---|
70 | aCancelable,
|
---|
71 | 1, // cOperations
|
---|
72 | 1, // ulTotalOperationsWeight
|
---|
73 | aDescription, // aFirstOperationDescription
|
---|
74 | 1); // ulFirstOperationWeight
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Not quite so simplified constructor for progress objects that have
|
---|
79 | * more than one operation, but all sub-operations are weighed the same.
|
---|
80 | * @param aParent
|
---|
81 | * @param aInitiator
|
---|
82 | * @param aDescription
|
---|
83 | * @param aCancelable
|
---|
84 | * @param cOperations
|
---|
85 | * @param aFirstOperationDescription
|
---|
86 | * @return
|
---|
87 | */
|
---|
88 | HRESULT init(
|
---|
89 | #if !defined(VBOX_COM_INPROC)
|
---|
90 | VirtualBox *aParent,
|
---|
91 | #endif
|
---|
92 | IUnknown *aInitiator,
|
---|
93 | const Utf8Str &aDescription, BOOL aCancelable,
|
---|
94 | ULONG cOperations,
|
---|
95 | const Utf8Str &aFirstOperationDescription)
|
---|
96 | {
|
---|
97 | return init(
|
---|
98 | #if !defined(VBOX_COM_INPROC)
|
---|
99 | aParent,
|
---|
100 | #endif
|
---|
101 | aInitiator,
|
---|
102 | aDescription,
|
---|
103 | aCancelable,
|
---|
104 | cOperations, // cOperations
|
---|
105 | cOperations, // ulTotalOperationsWeight = cOperations
|
---|
106 | aFirstOperationDescription, // aFirstOperationDescription
|
---|
107 | 1); // ulFirstOperationWeight: weigh them all the same
|
---|
108 | }
|
---|
109 |
|
---|
110 | HRESULT init(
|
---|
111 | #if !defined(VBOX_COM_INPROC)
|
---|
112 | VirtualBox *aParent,
|
---|
113 | #endif
|
---|
114 | IUnknown *aInitiator,
|
---|
115 | const Utf8Str &aDescription,
|
---|
116 | BOOL aCancelable,
|
---|
117 | ULONG cOperations,
|
---|
118 | ULONG ulTotalOperationsWeight,
|
---|
119 | const Utf8Str &aFirstOperationDescription,
|
---|
120 | ULONG ulFirstOperationWeight);
|
---|
121 |
|
---|
122 | HRESULT init(BOOL aCancelable,
|
---|
123 | ULONG aOperationCount,
|
---|
124 | const Utf8Str &aOperationDescription);
|
---|
125 |
|
---|
126 | void uninit();
|
---|
127 |
|
---|
128 |
|
---|
129 | // public methods only for internal purposes
|
---|
130 | HRESULT i_notifyComplete(HRESULT aResultCode);
|
---|
131 | HRESULT i_notifyComplete(HRESULT aResultCode,
|
---|
132 | const GUID &aIID,
|
---|
133 | const char *pcszComponent,
|
---|
134 | const char *aText,
|
---|
135 | ...);
|
---|
136 | HRESULT i_notifyCompleteV(HRESULT aResultCode,
|
---|
137 | const GUID &aIID,
|
---|
138 | const char *pcszComponent,
|
---|
139 | const char *aText,
|
---|
140 | va_list va);
|
---|
141 | HRESULT i_notifyCompleteBoth(HRESULT aResultCode,
|
---|
142 | int vrc,
|
---|
143 | const GUID &aIID,
|
---|
144 | const char *pcszComponent,
|
---|
145 | const char *aText,
|
---|
146 | ...);
|
---|
147 | HRESULT i_notifyCompleteBothV(HRESULT aResultCode,
|
---|
148 | int vrc,
|
---|
149 | const GUID &aIID,
|
---|
150 | const char *pcszComponent,
|
---|
151 | const char *aText,
|
---|
152 | va_list va);
|
---|
153 |
|
---|
154 | bool i_setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
|
---|
155 |
|
---|
156 | static DECLCALLBACK(int) i_iprtProgressCallback(unsigned uPercentage, void *pvUser);
|
---|
157 | static DECLCALLBACK(int) i_vdProgressCallback(void *pvUser, unsigned uPercentage);
|
---|
158 |
|
---|
159 | protected:
|
---|
160 | DECLARE_EMPTY_CTOR_DTOR(Progress)
|
---|
161 |
|
---|
162 | #if !defined(VBOX_COM_INPROC)
|
---|
163 | /** Weak parent. */
|
---|
164 | VirtualBox * const mParent;
|
---|
165 | #endif
|
---|
166 | const ComObjPtr<EventSource> pEventSource;
|
---|
167 | const ComPtr<IUnknown> mInitiator;
|
---|
168 |
|
---|
169 | const Guid mId;
|
---|
170 | const com::Utf8Str mDescription;
|
---|
171 |
|
---|
172 | uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation
|
---|
173 |
|
---|
174 | void (*m_pfnCancelCallback)(void *);
|
---|
175 | void *m_pvCancelUserArg;
|
---|
176 |
|
---|
177 | /* The fields below are to be properly initialized by subclasses */
|
---|
178 |
|
---|
179 | BOOL mCompleted;
|
---|
180 | BOOL mCancelable;
|
---|
181 | BOOL mCanceled;
|
---|
182 | HRESULT mResultCode;
|
---|
183 | ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
|
---|
184 |
|
---|
185 | ULONG m_cOperations; // number of operations (so that progress dialog can
|
---|
186 | // display something like 1/3)
|
---|
187 | ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor
|
---|
188 |
|
---|
189 | ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0
|
---|
190 |
|
---|
191 | ULONG m_ulCurrentOperation; // operations counter, incremented with
|
---|
192 | // each setNextOperation()
|
---|
193 | com::Utf8Str m_operationDescription; // name of current operation; initially
|
---|
194 | // from constructor, changed with setNextOperation()
|
---|
195 | ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()
|
---|
196 | ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()
|
---|
197 | ULONG m_cMsTimeout; /**< Automatic timeout value. 0 means none. */
|
---|
198 |
|
---|
199 | private:
|
---|
200 | // wrapped IProgress properties
|
---|
201 | HRESULT getId(com::Guid &aId);
|
---|
202 | HRESULT getDescription(com::Utf8Str &aDescription);
|
---|
203 | HRESULT getInitiator(ComPtr<IUnknown> &aInitiator);
|
---|
204 | HRESULT getCancelable(BOOL *aCancelable);
|
---|
205 | HRESULT getPercent(ULONG *aPercent);
|
---|
206 | HRESULT getTimeRemaining(LONG *aTimeRemaining);
|
---|
207 | HRESULT getCompleted(BOOL *aCompleted);
|
---|
208 | HRESULT getCanceled(BOOL *aCanceled);
|
---|
209 | HRESULT getResultCode(LONG *aResultCode);
|
---|
210 | HRESULT getErrorInfo(ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
211 | HRESULT getOperationCount(ULONG *aOperationCount);
|
---|
212 | HRESULT getOperation(ULONG *aOperation);
|
---|
213 | HRESULT getOperationDescription(com::Utf8Str &aOperationDescription);
|
---|
214 | HRESULT getOperationPercent(ULONG *aOperationPercent);
|
---|
215 | HRESULT getOperationWeight(ULONG *aOperationWeight);
|
---|
216 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
217 | HRESULT setTimeout(ULONG aTimeout);
|
---|
218 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
219 |
|
---|
220 | // wrapped IProgress methods
|
---|
221 | HRESULT waitForCompletion(LONG aTimeout);
|
---|
222 | HRESULT waitForOperationCompletion(ULONG aOperation,
|
---|
223 | LONG aTimeout);
|
---|
224 | HRESULT cancel();
|
---|
225 |
|
---|
226 | // wrapped IInternalProgressControl methods
|
---|
227 | HRESULT setCurrentOperationProgress(ULONG aPercent);
|
---|
228 | HRESULT waitForOtherProgressCompletion(const ComPtr<IProgress> &aProgressOther,
|
---|
229 | ULONG aTimeoutMS);
|
---|
230 | HRESULT setNextOperation(const com::Utf8Str &aNextOperationDescription,
|
---|
231 | ULONG aNextOperationsWeight);
|
---|
232 | HRESULT notifyPointOfNoReturn();
|
---|
233 | HRESULT notifyComplete(LONG aResultCode,
|
---|
234 | const ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
235 |
|
---|
236 | // internal helper methods
|
---|
237 | HRESULT i_notifyCompleteWorker(HRESULT aResultCode, const ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
238 | double i_calcTotalPercent();
|
---|
239 | void i_checkForAutomaticTimeout(void);
|
---|
240 |
|
---|
241 | RTSEMEVENTMULTI mCompletedSem;
|
---|
242 | ULONG mWaitersCount;
|
---|
243 |
|
---|
244 | private:
|
---|
245 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Progress); /* Shuts up MSC warning C4625. */
|
---|
246 | };
|
---|
247 |
|
---|
248 | #endif /* !MAIN_INCLUDED_ProgressImpl_h */
|
---|
249 |
|
---|