ProgressImpl.h revision c461a5e1d5095c611743c913ccf069cfc085f7d6
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* $Id$ */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** @file
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox COM class implementation
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/*
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * available from http://www.virtualbox.org. This file is free software;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * General Public License (GPL) as published by the Free Software
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * additional information or have any questions.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#ifndef ____H_PROGRESSIMPL
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#define ____H_PROGRESSIMPL
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#include "VirtualBoxBase.h"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <VBox/com/SupportErrorInfo.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <iprt/semaphore.h>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#include <vector>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncclass VirtualBox;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync////////////////////////////////////////////////////////////////////////////////
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Base component class for progress objects.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncclass ATL_NO_VTABLE ProgressBase :
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync public VirtualBoxBase,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync public com::SupportErrorInfoBase,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync public VirtualBoxSupportTranslation<ProgressBase>,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VBOX_SCRIPTABLE_IMPL(IProgress)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprotected:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (ProgressBase)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync DECLARE_EMPTY_CTOR_DTOR (ProgressBase)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync HRESULT FinalConstruct();
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // protected initializer/uninitializer for internal purposes only
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT protectedInit (AutoInitSpan &aAutoInitSpan,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
acca7ab818eb8c2832aa27e27ce53133fba927dbvboxsync VirtualBox *aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IUnknown *aInitiator,
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync CBSTR aDescription, OUT_GUID aId = NULL);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync HRESULT protectedInit (AutoInitSpan &aAutoInitSpan);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync void protectedUninit (AutoUninitSpan &aAutoUninitSpan);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsyncpublic:
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync // IProgress properties
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync STDMETHOD(COMGETTER(Id)) (BSTR *aId);
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync STDMETHOD(COMGETTER(Initiator)) (IUnknown **aInitiator);
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync // IProgress properties
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(OperationCount)) (ULONG *aOperationCount);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // public methods only for internal purposes
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync static HRESULT setErrorInfoOnThread (IProgress *aProgress);
5eb36887f6970e0033f63fa135f3bb8fbfd6059bvboxsync bool setCancelCallback(void (*pfnCallback)(void *), void *pvUser);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // unsafe inline public methods for internal purposes only (ensure there is
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // a caller and a read lock before calling them!)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL completed() const { return mCompleted; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT resultCode() const { return mResultCode; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync double calcTotalPercent();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprotected:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** Weak parent. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const ComObjPtr<VirtualBox, ComWeakRef> mParent;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const ComPtr<IUnknown> mInitiator;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const Guid mId;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const Bstr mDescription;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync void (*m_pfnCancelCallback)(void *);
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync void *m_pvCancelUserArg;
63a3c5be7ac89d0d5b3386988f8c2f78df0cacf6vboxsync
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync /* The fields below are to be properly initalized by subclasses */
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync
47e063db54028c020dd3e85a2467d7a279e47a8avboxsync BOOL mCompleted;
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync BOOL mCancelable;
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync BOOL mCanceled;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT mResultCode;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ComPtr<IVirtualBoxErrorInfo> mErrorInfo;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG m_cOperations; // number of operations (so that progress dialog can display something like 1/3)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG m_ulTotalOperationsWeight; // sum of weights of all operations, given to constructor
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG m_ulOperationsCompletedWeight; // summed-up weight of operations that have been completed; initially 0
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG m_ulCurrentOperation; // operations counter, incremented with each setNextOperation()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Bstr m_bstrOperationDescription; // name of current operation; initially from constructor, changed with setNextOperation()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG m_ulCurrentOperationWeight; // weight of current operation, given to setNextOperation()
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync ULONG m_ulOperationPercent; // percentage of current operation, set with setCurrentOperationProgress()
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync};
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync////////////////////////////////////////////////////////////////////////////////
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync/**
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync * Normal progress object.
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncclass ATL_NO_VTABLE Progress :
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync public com::SupportErrorInfoDerived<ProgressBase, Progress, IProgress>,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync public VirtualBoxSupportTranslation<Progress>
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncpublic:
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (Progress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync DECLARE_NOT_AGGREGATABLE (Progress)
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync BEGIN_COM_MAP (Progress)
221f7b41140948bedfb450353dcefb70c014e12avboxsync COM_INTERFACE_ENTRY (ISupportErrorInfo)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync COM_INTERFACE_ENTRY (IProgress)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync END_COM_MAP()
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync HRESULT FinalConstruct();
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync void FinalRelease();
25c15196ec95f6a53e802167c815286cecfeb278vboxsync
25c15196ec95f6a53e802167c815286cecfeb278vboxsync // public initializer/uninitializer for internal purposes only
25c15196ec95f6a53e802167c815286cecfeb278vboxsync
97803398b9554900b4dd45f88b2eb2056e2c606bvboxsync /**
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync * Simplified constructor for progress objects that have only one
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync * operation as a task.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aParent
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aInitiator
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aDescription
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aCancelable
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aId
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT init(
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VirtualBox *aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IUnknown *aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR aDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OUT_GUID aId = NULL)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return init(
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync 1, // cOperations
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync 1, // ulTotalOperationsWeight
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync aDescription, // bstrFirstOperationDescription
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync 1, // ulFirstOperationWeight
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aId);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /**
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Not quite so simplified constructor for progress objects that have
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * more than one operation, but all sub-operations are weighed the same.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aParent
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aInitiator
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aDescription
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aCancelable
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param cOperations
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param bstrFirstOperationDescription
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aId
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @return
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT init(
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VirtualBox *aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IUnknown *aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR aDescription, BOOL aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG cOperations,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR bstrFirstOperationDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OUT_GUID aId = NULL)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return init(
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync cOperations, // cOperations
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync cOperations, // ulTotalOperationsWeight = cOperations
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync bstrFirstOperationDescription, // bstrFirstOperationDescription
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync 1, // ulFirstOperationWeight: weigh them all the same
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync aId);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT init(
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#if !defined (VBOX_COM_INPROC)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VirtualBox *aParent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IUnknown *aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR aDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync BOOL aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG cOperations,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG ulTotalOperationsWeight,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR bstrFirstOperationDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG ulFirstOperationWeight,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OUT_GUID aId = NULL);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT init(BOOL aCancelable,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG aOperationCount,
7755c0a4b7b215f612d9d27848c2584ffafe7a66vboxsync CBSTR aOperationDescription);
7755c0a4b7b215f612d9d27848c2584ffafe7a66vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync void uninit();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // IProgress methods
316572fd6bf59ec1038f0476f6536fc10163beebvboxsync STDMETHOD(WaitForCompletion)(LONG aTimeout);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(WaitForOperationCompletion)(ULONG aOperation, LONG aTimeout);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(Cancel)();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // public methods only for internal purposes
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync HRESULT setResultCode(HRESULT aResultCode);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync HRESULT notifyComplete(HRESULT aResultCode);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync HRESULT notifyComplete(HRESULT aResultCode,
602e0e27740395dba64bee2e0a8aef023ebd7650vboxsync const GUID &aIID,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const Bstr &aComponent,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *aText, ...);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync bool notifyPointOfNoReturn(void);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync /** For com::SupportErrorInfoImpl. */
221f7b41140948bedfb450353dcefb70c014e12avboxsync static const char *ComponentName() { return "Progress"; }
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsyncprivate:
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync RTSEMEVENTMULTI mCompletedSem;
221f7b41140948bedfb450353dcefb70c014e12avboxsync ULONG mWaitersCount;
221f7b41140948bedfb450353dcefb70c014e12avboxsync};
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync////////////////////////////////////////////////////////////////////////////////
221f7b41140948bedfb450353dcefb70c014e12avboxsync
221f7b41140948bedfb450353dcefb70c014e12avboxsync/**
221f7b41140948bedfb450353dcefb70c014e12avboxsync * The CombinedProgress class allows to combine several progress objects to a
221f7b41140948bedfb450353dcefb70c014e12avboxsync * single progress component. This single progress component will treat all
221f7b41140948bedfb450353dcefb70c014e12avboxsync * operations of individual progress objects as a single sequence of operations
221f7b41140948bedfb450353dcefb70c014e12avboxsync * that follow each other in the same order as progress objects are passed to
221f7b41140948bedfb450353dcefb70c014e12avboxsync * the #init() method.
221f7b41140948bedfb450353dcefb70c014e12avboxsync *
221f7b41140948bedfb450353dcefb70c014e12avboxsync * Individual progress objects are sequentially combined so that this progress
221f7b41140948bedfb450353dcefb70c014e12avboxsync * object:
221f7b41140948bedfb450353dcefb70c014e12avboxsync *
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - is cancelable only if all progresses are cancelable.
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - is canceled once a progress that follows next to successfully completed
221f7b41140948bedfb450353dcefb70c014e12avboxsync * ones reports it was canceled.
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - is completed successfully only after all progresses are completed
221f7b41140948bedfb450353dcefb70c014e12avboxsync * successfully.
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - is completed unsuccessfully once a progress that follows next to
221f7b41140948bedfb450353dcefb70c014e12avboxsync * successfully completed ones reports it was completed unsuccessfully;
221f7b41140948bedfb450353dcefb70c014e12avboxsync * the result code and error info of the unsuccessful progress
221f7b41140948bedfb450353dcefb70c014e12avboxsync * will be reported as the result code and error info of this progress.
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - returns N as the operation number, where N equals to the number of
221f7b41140948bedfb450353dcefb70c014e12avboxsync * operations in all successfully completed progresses starting from the
221f7b41140948bedfb450353dcefb70c014e12avboxsync * first one plus the operation number of the next (not yet complete)
221f7b41140948bedfb450353dcefb70c014e12avboxsync * progress; the operation description of the latter one is reported as
221f7b41140948bedfb450353dcefb70c014e12avboxsync * the operation description of this progress object.
221f7b41140948bedfb450353dcefb70c014e12avboxsync * - returns P as the percent value, where P equals to the sum of percents
221f7b41140948bedfb450353dcefb70c014e12avboxsync * of all successfully completed progresses starting from the
221f7b41140948bedfb450353dcefb70c014e12avboxsync * first one plus the percent value of the next (not yet complete)
221f7b41140948bedfb450353dcefb70c014e12avboxsync * progress, normalized to 100%.
221f7b41140948bedfb450353dcefb70c014e12avboxsync *
221f7b41140948bedfb450353dcefb70c014e12avboxsync * @note It's the respoisibility of the combined progress object creator to
221f7b41140948bedfb450353dcefb70c014e12avboxsync * complete individual progresses in the right order: if, let's say, the
221f7b41140948bedfb450353dcefb70c014e12avboxsync * last progress is completed before all previous ones,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * #WaitForCompletion(-1) will most likely give 100% CPU load because it
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * will be in a loop calling a method that returns immediately.
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync */
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsyncclass ATL_NO_VTABLE CombinedProgress :
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync public com::SupportErrorInfoDerived<ProgressBase, CombinedProgress, IProgress>,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync public VirtualBoxSupportTranslation<CombinedProgress>
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync{
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsyncpublic:
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (CombinedProgress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync DECLARE_NOT_AGGREGATABLE (CombinedProgress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync BEGIN_COM_MAP (CombinedProgress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync COM_INTERFACE_ENTRY (ISupportErrorInfo)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync COM_INTERFACE_ENTRY (IProgress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync END_COM_MAP()
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT FinalConstruct();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync void FinalRelease();
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync // public initializer/uninitializer for internal purposes only
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync HRESULT init (
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync#if !defined (VBOX_COM_INPROC)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync VirtualBox *aParent,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync#endif
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync IUnknown *aInitiator,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync CBSTR aDescription,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync IProgress *aProgress1, IProgress *aProgress2,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync OUT_GUID aId = NULL);
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync /**
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * Initializes the combined progress object given the first and the last
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * normal progress object from the list.
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync *
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aParent See ProgressBase::init().
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aInitiator See ProgressBase::init().
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aDescription See ProgressBase::init().
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aFirstProgress Iterator of the first normal progress object.
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aSecondProgress Iterator of the last normal progress object.
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync * @param aId See ProgressBase::init().
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync */
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync template <typename InputIterator>
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync HRESULT init (
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync#if !defined (VBOX_COM_INPROC)
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync VirtualBox *aParent,
d074b9bd5c1fffc376db9d56ff9d090fb9ced642vboxsync#endif
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync IUnknown *aInitiator,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CBSTR aDescription,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync InputIterator aFirstProgress, InputIterator aLastProgress,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync OUT_GUID aId = NULL)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Enclose the state transition NotReady->InInit->Ready */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync AutoInitSpan autoInitSpan (this);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync AssertReturn (autoInitSpan.isOk(), E_FAIL);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync mProgresses = ProgressVector (aFirstProgress, aLastProgress);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync HRESULT rc = protectedInit (autoInitSpan,
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#if !defined (VBOX_COM_INPROC)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync aParent,
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#endif
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync aInitiator, aDescription, aId);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Confirm a successful initialization when it's the case */
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync if (SUCCEEDED (rc))
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync autoInitSpan.setSucceeded();
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return rc;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprotected:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT protectedInit (AutoInitSpan &aAutoInitSpan,
78df65edff21c11c537f38e736707ea434ab5623vboxsync#if !defined (VBOX_COM_INPROC)
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync VirtualBox *aParent,
78df65edff21c11c537f38e736707ea434ab5623vboxsync#endif
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync IUnknown *aInitiator,
489fcf2b60b2dfc27a2fcb590aad04ad2c4f9b75vboxsync CBSTR aDescription, OUT_GUID aId);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsyncpublic:
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync void uninit();
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync // IProgress properties
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync // IProgress methods
78df65edff21c11c537f38e736707ea434ab5623vboxsync STDMETHOD(WaitForCompletion) (LONG aTimeout);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(WaitForOperationCompletion) (ULONG aOperation, LONG aTimeout);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(Cancel)();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync NOREF(aPercent);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync return E_NOTIMPL;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync }
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync {
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync NOREF(bstrNextOperationDescription); NOREF(ulNextOperationsWeight);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return E_NOTIMPL;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // public methods only for internal purposes
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** For com::SupportErrorInfoImpl. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync static const char *ComponentName() { return "CombinedProgress"; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncprivate:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT checkProgress();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync typedef std::vector <ComPtr<IProgress> > ProgressVector;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ProgressVector mProgresses;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
78df65edff21c11c537f38e736707ea434ab5623vboxsync size_t mProgress;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ULONG mCompletedOperations;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync};
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync#endif /* ____H_PROGRESSIMPL */
23ff0a80f28ba27da3cb458face82665fe65e96cvboxsync
e43d0b86db65e202efb63f0fc5fce1f981267a32vboxsync