VirtualBox

source: vbox/trunk/src/VBox/Main/include/ProgressCombinedImpl.h@ 30714

Last change on this file since 30714 was 30714, checked in by vboxsync, 14 years ago

Main: remove SupportErrorInfo template magic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: ProgressCombinedImpl.h 30714 2010-07-07 16:20:03Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2010 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_PROGRESSCOMBINEDIMPL
20#define ____H_PROGRESSCOMBINEDIMPL
21
22#include "ProgressImpl.h"
23#include "AutoCaller.h"
24
25#include <vector>
26
27/**
28 * The CombinedProgress class allows to combine several progress objects to a
29 * single progress component. This single progress component will treat all
30 * operations of individual progress objects as a single sequence of operations
31 * that follow each other in the same order as progress objects are passed to
32 * the #init() method.
33 *
34 * @note CombinedProgress is legacy code and deprecated. It does not support
35 * weighted operations, all suboperations are assumed to take the same
36 * amount of time. For new code, please use IProgress directly which
37 * has supported multiple weighted suboperations since VirtualBox 3.0.
38 *
39 * Individual progress objects are sequentially combined so that this progress
40 * object:
41 *
42 * - is cancelable only if all progresses are cancelable.
43 * - is canceled once a progress that follows next to successfully completed
44 * ones reports it was canceled.
45 * - is completed successfully only after all progresses are completed
46 * successfully.
47 * - is completed unsuccessfully once a progress that follows next to
48 * successfully completed ones reports it was completed unsuccessfully;
49 * the result code and error info of the unsuccessful progress
50 * will be reported as the result code and error info of this progress.
51 * - returns N as the operation number, where N equals to the number of
52 * operations in all successfully completed progresses starting from the
53 * first one plus the operation number of the next (not yet complete)
54 * progress; the operation description of the latter one is reported as
55 * the operation description of this progress object.
56 * - returns P as the percent value, where P equals to the sum of percents
57 * of all successfully completed progresses starting from the
58 * first one plus the percent value of the next (not yet complete)
59 * progress, normalized to 100%.
60 *
61 * @note It's the respoisibility of the combined progress object creator to
62 * complete individual progresses in the right order: if, let's say, the
63 * last progress is completed before all previous ones,
64 * #WaitForCompletion(-1) will most likely give 100% CPU load because it
65 * will be in a loop calling a method that returns immediately.
66 */
67class ATL_NO_VTABLE CombinedProgress :
68// public com::SupportErrorInfoDerived<ProgressBase, CombinedProgress, IProgress>,
69 public Progress,
70 public VirtualBoxSupportTranslation<CombinedProgress>
71{
72
73public:
74 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(CombinedProgress, IProgress)
75
76 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(CombinedProgress)
77
78 DECLARE_NOT_AGGREGATABLE(CombinedProgress)
79
80 DECLARE_PROTECT_FINAL_CONSTRUCT()
81
82 BEGIN_COM_MAP (CombinedProgress)
83 COM_INTERFACE_ENTRY (ISupportErrorInfo)
84 COM_INTERFACE_ENTRY (IProgress)
85 COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
86 END_COM_MAP()
87
88 HRESULT FinalConstruct();
89 void FinalRelease();
90
91 // public initializer/uninitializer for internal purposes only
92
93 HRESULT init (
94#if !defined (VBOX_COM_INPROC)
95 VirtualBox *aParent,
96#endif
97 IUnknown *aInitiator,
98 CBSTR aDescription,
99 IProgress *aProgress1, IProgress *aProgress2,
100 OUT_GUID aId = NULL);
101
102 /**
103 * Initializes the combined progress object given the first and the last
104 * normal progress object from the list.
105 *
106 * @param aParent See ProgressBase::init().
107 * @param aInitiator See ProgressBase::init().
108 * @param aDescription See ProgressBase::init().
109 * @param aFirstProgress Iterator of the first normal progress object.
110 * @param aSecondProgress Iterator of the last normal progress object.
111 * @param aId See ProgressBase::init().
112 */
113 template <typename InputIterator>
114 HRESULT init (
115#if !defined (VBOX_COM_INPROC)
116 VirtualBox *aParent,
117#endif
118 IUnknown *aInitiator,
119 CBSTR aDescription,
120 InputIterator aFirstProgress, InputIterator aLastProgress,
121 OUT_GUID aId = NULL)
122 {
123 /* Enclose the state transition NotReady->InInit->Ready */
124 AutoInitSpan autoInitSpan (this);
125 AssertReturn (autoInitSpan.isOk(), E_FAIL);
126
127 mProgresses = ProgressVector (aFirstProgress, aLastProgress);
128
129 HRESULT rc = protectedInit (autoInitSpan,
130#if !defined (VBOX_COM_INPROC)
131 aParent,
132#endif
133 aInitiator, aDescription, aId);
134
135 /* Confirm a successful initialization when it's the case */
136 if (SUCCEEDED(rc))
137 autoInitSpan.setSucceeded();
138
139 return rc;
140 }
141
142protected:
143
144 HRESULT protectedInit (AutoInitSpan &aAutoInitSpan,
145#if !defined (VBOX_COM_INPROC)
146 VirtualBox *aParent,
147#endif
148 IUnknown *aInitiator,
149 CBSTR aDescription, OUT_GUID aId);
150
151public:
152
153 void uninit();
154
155 // IProgress properties
156 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
157 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
158 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
159 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
160 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
161 STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);
162 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
163 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
164 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);
165 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);
166
167 // IProgress methods
168 STDMETHOD(WaitForCompletion) (LONG aTimeout);
169 STDMETHOD(WaitForOperationCompletion) (ULONG aOperation, LONG aTimeout);
170 STDMETHOD(Cancel)();
171
172 STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent)
173 {
174 NOREF(aPercent);
175 return E_NOTIMPL;
176 }
177
178 STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight)
179 {
180 NOREF(bstrNextOperationDescription); NOREF(ulNextOperationsWeight);
181 return E_NOTIMPL;
182 }
183
184 // public methods only for internal purposes
185
186private:
187
188 HRESULT checkProgress();
189
190 typedef std::vector <ComPtr<IProgress> > ProgressVector;
191 ProgressVector mProgresses;
192
193 size_t mProgress;
194 ULONG mCompletedOperations;
195};
196
197#endif /* ____H_PROGRESSCOMBINEDIMPL */
198
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