VirtualBox

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

Last change on this file since 67728 was 67245, checked in by vboxsync, 8 years ago

Main/ProgresImpl: Added a callback method for VD as well (i_vdProgressCallback). Identical to the IPRT one, except the parameters are switched around.

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