VirtualBox

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

Last change on this file since 98341 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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