VirtualBox

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

Last change on this file since 74804 was 74804, checked in by vboxsync, 6 years ago

Main/Progress: Split into safe public interface and a private one which is used purely by API implementation code (for updating). Needed quite a few minor adjustments elsewhere.

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