VirtualBox

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

Last change on this file since 56290 was 54992, checked in by vboxsync, 10 years ago

Main/Progress: big cleanup eliminating inconsistencies and redundant code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: ProgressImpl.h 54992 2015-03-27 15:45:03Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2015 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 bstrFirstOperationDescription
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
143protected:
144 DECLARE_EMPTY_CTOR_DTOR(Progress)
145
146#if !defined(VBOX_COM_INPROC)
147 /** Weak parent. */
148 VirtualBox * const mParent;
149#endif
150
151 const ComPtr<IUnknown> mInitiator;
152
153 const Guid mId;
154 const com::Utf8Str mDescription;
155
156 uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation
157
158 void (*m_pfnCancelCallback)(void *);
159 void *m_pvCancelUserArg;
160
161 /* The fields below are to be properly initialized by subclasses */
162
163 BOOL mCompleted;
164 BOOL mCancelable;
165 BOOL mCanceled;
166 HRESULT mResultCode;
167 ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
168
169 ULONG m_cOperations; // number of operations (so that progress dialog can
170 // display something like 1/3)
171 ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor
172
173 ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0
174
175 ULONG m_ulCurrentOperation; // operations counter, incremented with
176 // each setNextOperation()
177 com::Utf8Str m_operationDescription; // name of current operation; initially
178 // from constructor, changed with setNextOperation()
179 ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()
180 ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()
181 ULONG m_cMsTimeout; /**< Automatic timeout value. 0 means none. */
182
183private:
184 // wrapped IProgress properties
185 HRESULT getId(com::Guid &aId);
186 HRESULT getDescription(com::Utf8Str &aDescription);
187 HRESULT getInitiator(ComPtr<IUnknown> &aInitiator);
188 HRESULT getCancelable(BOOL *aCancelable);
189 HRESULT getPercent(ULONG *aPercent);
190 HRESULT getTimeRemaining(LONG *aTimeRemaining);
191 HRESULT getCompleted(BOOL *aCompleted);
192 HRESULT getCanceled(BOOL *aCanceled);
193 HRESULT getResultCode(LONG *aResultCode);
194 HRESULT getErrorInfo(ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
195 HRESULT getOperationCount(ULONG *aOperationCount);
196 HRESULT getOperation(ULONG *aOperation);
197 HRESULT getOperationDescription(com::Utf8Str &aOperationDescription);
198 HRESULT getOperationPercent(ULONG *aOperationPercent);
199 HRESULT getOperationWeight(ULONG *aOperationWeight);
200 HRESULT getTimeout(ULONG *aTimeout);
201 HRESULT setTimeout(ULONG aTimeout);
202
203 // wrapped IProgress methods
204 HRESULT setCurrentOperationProgress(ULONG aPercent);
205 HRESULT setNextOperation(const com::Utf8Str &aNextOperationDescription,
206 ULONG aNextOperationsWeight);
207 HRESULT waitForCompletion(LONG aTimeout);
208 HRESULT waitForOperationCompletion(ULONG aOperation,
209 LONG aTimeout);
210 HRESULT waitForAsyncProgressCompletion(const ComPtr<IProgress> &aPProgressAsync);
211 HRESULT cancel();
212
213 // internal helper methods
214 double i_calcTotalPercent();
215 void i_checkForAutomaticTimeout(void);
216
217 RTSEMEVENTMULTI mCompletedSem;
218 ULONG mWaitersCount;
219};
220
221#endif /* ____H_PROGRESSIMPL */
222
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