[13580] | 1 | /* $Id: ProgressImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * VirtualBox COM class implementation
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[98103] | 8 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 9 | *
|
---|
[96407] | 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
|
---|
[1] | 27 | */
|
---|
| 28 |
|
---|
[76562] | 29 | #ifndef MAIN_INCLUDED_ProgressImpl_h
|
---|
| 30 | #define MAIN_INCLUDED_ProgressImpl_h
|
---|
[76487] | 31 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 32 | # pragma once
|
---|
| 33 | #endif
|
---|
[1] | 34 |
|
---|
[50874] | 35 | #include "ProgressWrap.h"
|
---|
[1] | 36 | #include "VirtualBoxBase.h"
|
---|
[69002] | 37 | #include "EventImpl.h"
|
---|
[1] | 38 |
|
---|
| 39 | #include <iprt/semaphore.h>
|
---|
| 40 |
|
---|
| 41 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 42 |
|
---|
[13580] | 43 | /**
|
---|
[44288] | 44 | * Class for progress objects.
|
---|
[13580] | 45 | */
|
---|
[44288] | 46 | class ATL_NO_VTABLE Progress :
|
---|
[50874] | 47 | public ProgressWrap
|
---|
[1] | 48 | {
|
---|
| 49 | public:
|
---|
[54992] | 50 | DECLARE_NOT_AGGREGATABLE(Progress)
|
---|
[1] | 51 |
|
---|
| 52 | HRESULT FinalConstruct();
|
---|
| 53 | void FinalRelease();
|
---|
| 54 |
|
---|
| 55 | // public initializer/uninitializer for internal purposes only
|
---|
| 56 |
|
---|
[18269] | 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(
|
---|
[54992] | 67 | #if !defined(VBOX_COM_INPROC)
|
---|
[1] | 68 | VirtualBox *aParent,
|
---|
| 69 | #endif
|
---|
| 70 | IUnknown *aInitiator,
|
---|
[73824] | 71 | const Utf8Str &aDescription,
|
---|
[51687] | 72 | BOOL aCancelable)
|
---|
[1] | 73 | {
|
---|
[18269] | 74 | return init(
|
---|
[54992] | 75 | #if !defined(VBOX_COM_INPROC)
|
---|
[1] | 76 | aParent,
|
---|
| 77 | #endif
|
---|
[18269] | 78 | aInitiator,
|
---|
[26603] | 79 | aDescription,
|
---|
[18269] | 80 | aCancelable,
|
---|
| 81 | 1, // cOperations
|
---|
| 82 | 1, // ulTotalOperationsWeight
|
---|
[50874] | 83 | aDescription, // aFirstOperationDescription
|
---|
[51687] | 84 | 1); // ulFirstOperationWeight
|
---|
[1] | 85 | }
|
---|
| 86 |
|
---|
[18269] | 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
|
---|
[65103] | 95 | * @param aFirstOperationDescription
|
---|
[18269] | 96 | * @return
|
---|
| 97 | */
|
---|
| 98 | HRESULT init(
|
---|
[54992] | 99 | #if !defined(VBOX_COM_INPROC)
|
---|
[1] | 100 | VirtualBox *aParent,
|
---|
| 101 | #endif
|
---|
| 102 | IUnknown *aInitiator,
|
---|
[73824] | 103 | const Utf8Str &aDescription, BOOL aCancelable,
|
---|
[18269] | 104 | ULONG cOperations,
|
---|
[73824] | 105 | const Utf8Str &aFirstOperationDescription)
|
---|
[18269] | 106 | {
|
---|
| 107 | return init(
|
---|
[54992] | 108 | #if !defined(VBOX_COM_INPROC)
|
---|
[18269] | 109 | aParent,
|
---|
| 110 | #endif
|
---|
| 111 | aInitiator,
|
---|
[26603] | 112 | aDescription,
|
---|
[18269] | 113 | aCancelable,
|
---|
| 114 | cOperations, // cOperations
|
---|
| 115 | cOperations, // ulTotalOperationsWeight = cOperations
|
---|
[50874] | 116 | aFirstOperationDescription, // aFirstOperationDescription
|
---|
[51687] | 117 | 1); // ulFirstOperationWeight: weigh them all the same
|
---|
[18269] | 118 | }
|
---|
| 119 |
|
---|
| 120 | HRESULT init(
|
---|
[54992] | 121 | #if !defined(VBOX_COM_INPROC)
|
---|
[18269] | 122 | VirtualBox *aParent,
|
---|
| 123 | #endif
|
---|
| 124 | IUnknown *aInitiator,
|
---|
[73824] | 125 | const Utf8Str &aDescription,
|
---|
[23223] | 126 | BOOL aCancelable,
|
---|
| 127 | ULONG cOperations,
|
---|
| 128 | ULONG ulTotalOperationsWeight,
|
---|
[73824] | 129 | const Utf8Str &aFirstOperationDescription,
|
---|
[51687] | 130 | ULONG ulFirstOperationWeight);
|
---|
[1] | 131 |
|
---|
[23223] | 132 | HRESULT init(BOOL aCancelable,
|
---|
| 133 | ULONG aOperationCount,
|
---|
[73824] | 134 | const Utf8Str &aOperationDescription);
|
---|
[1] | 135 |
|
---|
| 136 | void uninit();
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | // public methods only for internal purposes
|
---|
[50874] | 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);
|
---|
[78666] | 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);
|
---|
[54992] | 163 |
|
---|
[50874] | 164 | bool i_setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
|
---|
[44288] | 165 |
|
---|
[67242] | 166 | static DECLCALLBACK(int) i_iprtProgressCallback(unsigned uPercentage, void *pvUser);
|
---|
[67245] | 167 | static DECLCALLBACK(int) i_vdProgressCallback(void *pvUser, unsigned uPercentage);
|
---|
[67230] | 168 |
|
---|
[54992] | 169 | protected:
|
---|
[90828] | 170 | DECLARE_COMMON_CLASS_METHODS(Progress)
|
---|
[44288] | 171 |
|
---|
[54992] | 172 | #if !defined(VBOX_COM_INPROC)
|
---|
| 173 | /** Weak parent. */
|
---|
| 174 | VirtualBox * const mParent;
|
---|
| 175 | #endif
|
---|
[69002] | 176 | const ComObjPtr<EventSource> pEventSource;
|
---|
[54992] | 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 |
|
---|
[1] | 209 | private:
|
---|
[54992] | 210 | // wrapped IProgress properties
|
---|
[50874] | 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);
|
---|
[69002] | 228 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
[54992] | 229 |
|
---|
| 230 | // wrapped IProgress methods
|
---|
[50874] | 231 | HRESULT waitForCompletion(LONG aTimeout);
|
---|
| 232 | HRESULT waitForOperationCompletion(ULONG aOperation,
|
---|
| 233 | LONG aTimeout);
|
---|
| 234 | HRESULT cancel();
|
---|
| 235 |
|
---|
[74804] | 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 |
|
---|
[54992] | 246 | // internal helper methods
|
---|
[85251] | 247 | HRESULT i_notifyCompleteWorker(HRESULT aResultCode, const ComPtr<IVirtualBoxErrorInfo> &aErrorInfo);
|
---|
[54992] | 248 | double i_calcTotalPercent();
|
---|
| 249 | void i_checkForAutomaticTimeout(void);
|
---|
[50874] | 250 |
|
---|
[1] | 251 | RTSEMEVENTMULTI mCompletedSem;
|
---|
| 252 | ULONG mWaitersCount;
|
---|
[63147] | 253 |
|
---|
| 254 | private:
|
---|
| 255 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Progress); /* Shuts up MSC warning C4625. */
|
---|
[1] | 256 | };
|
---|
| 257 |
|
---|
[76562] | 258 | #endif /* !MAIN_INCLUDED_ProgressImpl_h */
|
---|
[18269] | 259 |
|
---|