VirtualBox

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

Last change on this file since 53364 was 51687, checked in by vboxsync, 11 years ago

Main/Guid+Progress: big cleanup of Guid.h and some Progress cleanup, mostly removing the totally unused aId parameter of the init method and by deleting long gone initi/uninit methods

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