1 | /* $Id: ProgressImpl.h 76562 2019-01-01 03:22:50Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2019 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 |
|
---|
142 | bool i_setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
|
---|
143 |
|
---|
144 | static DECLCALLBACK(int) i_iprtProgressCallback(unsigned uPercentage, void *pvUser);
|
---|
145 | static DECLCALLBACK(int) i_vdProgressCallback(void *pvUser, unsigned uPercentage);
|
---|
146 |
|
---|
147 | protected:
|
---|
148 | DECLARE_EMPTY_CTOR_DTOR(Progress)
|
---|
149 |
|
---|
150 | #if !defined(VBOX_COM_INPROC)
|
---|
151 | /** Weak parent. */
|
---|
152 | VirtualBox * const mParent;
|
---|
153 | #endif
|
---|
154 | const ComObjPtr<EventSource> pEventSource;
|
---|
155 | const ComPtr<IUnknown> mInitiator;
|
---|
156 |
|
---|
157 | const Guid mId;
|
---|
158 | const com::Utf8Str mDescription;
|
---|
159 |
|
---|
160 | uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation
|
---|
161 |
|
---|
162 | void (*m_pfnCancelCallback)(void *);
|
---|
163 | void *m_pvCancelUserArg;
|
---|
164 |
|
---|
165 | /* The fields below are to be properly initialized by subclasses */
|
---|
166 |
|
---|
167 | BOOL mCompleted;
|
---|
168 | BOOL mCancelable;
|
---|
169 | BOOL mCanceled;
|
---|
170 | HRESULT mResultCode;
|
---|
171 | ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
|
---|
172 |
|
---|
173 | ULONG m_cOperations; // number of operations (so that progress dialog can
|
---|
174 | // display something like 1/3)
|
---|
175 | ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor
|
---|
176 |
|
---|
177 | ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0
|
---|
178 |
|
---|
179 | ULONG m_ulCurrentOperation; // operations counter, incremented with
|
---|
180 | // each setNextOperation()
|
---|
181 | com::Utf8Str m_operationDescription; // name of current operation; initially
|
---|
182 | // from constructor, changed with setNextOperation()
|
---|
183 | ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()
|
---|
184 | ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()
|
---|
185 | ULONG m_cMsTimeout; /**< Automatic timeout value. 0 means none. */
|
---|
186 |
|
---|
187 | private:
|
---|
188 | // wrapped IProgress properties
|
---|
189 | HRESULT getId(com::Guid &aId);
|
---|
190 | HRESULT getDescription(com::Utf8Str &aDescription);
|
---|
191 | HRESULT getInitiator(ComPtr<IUnknown> &aInitiator);
|
---|
192 | HRESULT getCancelable(BOOL *aCancelable);
|
---|
193 | HRESULT getPercent(ULONG *aPercent);
|
---|
194 | HRESULT getTimeRemaining(LONG *aTimeRemaining);
|
---|
195 | HRESULT getCompleted(BOOL *aCompleted);
|
---|
196 | HRESULT getCanceled(BOOL *aCanceled);
|
---|
197 | HRESULT getResultCode(LONG *aResultCode);
|
---|
198 | HRESULT getErrorInfo(ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
199 | HRESULT getOperationCount(ULONG *aOperationCount);
|
---|
200 | HRESULT getOperation(ULONG *aOperation);
|
---|
201 | HRESULT getOperationDescription(com::Utf8Str &aOperationDescription);
|
---|
202 | HRESULT getOperationPercent(ULONG *aOperationPercent);
|
---|
203 | HRESULT getOperationWeight(ULONG *aOperationWeight);
|
---|
204 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
205 | HRESULT setTimeout(ULONG aTimeout);
|
---|
206 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
207 |
|
---|
208 | // wrapped IProgress methods
|
---|
209 | HRESULT waitForCompletion(LONG aTimeout);
|
---|
210 | HRESULT waitForOperationCompletion(ULONG aOperation,
|
---|
211 | LONG aTimeout);
|
---|
212 | HRESULT cancel();
|
---|
213 |
|
---|
214 | // wrapped IInternalProgressControl methods
|
---|
215 | HRESULT setCurrentOperationProgress(ULONG aPercent);
|
---|
216 | HRESULT waitForOtherProgressCompletion(const ComPtr<IProgress> &aProgressOther,
|
---|
217 | ULONG aTimeoutMS);
|
---|
218 | HRESULT setNextOperation(const com::Utf8Str &aNextOperationDescription,
|
---|
219 | ULONG aNextOperationsWeight);
|
---|
220 | HRESULT notifyPointOfNoReturn();
|
---|
221 | HRESULT notifyComplete(LONG aResultCode,
|
---|
222 | const ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
223 |
|
---|
224 | // internal helper methods
|
---|
225 | double i_calcTotalPercent();
|
---|
226 | void i_checkForAutomaticTimeout(void);
|
---|
227 |
|
---|
228 | RTSEMEVENTMULTI mCompletedSem;
|
---|
229 | ULONG mWaitersCount;
|
---|
230 |
|
---|
231 | private:
|
---|
232 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Progress); /* Shuts up MSC warning C4625. */
|
---|
233 | };
|
---|
234 |
|
---|
235 | #endif /* !MAIN_INCLUDED_ProgressImpl_h */
|
---|
236 |
|
---|