VirtualBox

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

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

Main: mark CombinedProgress deprecated

  • 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 29923 2010-05-31 17:55:44Z 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 VirtualBoxSupportTranslation<CombinedProgress>
70{
71
72public:
73
74 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (CombinedProgress)
75
76 DECLARE_NOT_AGGREGATABLE (CombinedProgress)
77
78 DECLARE_PROTECT_FINAL_CONSTRUCT()
79
80 BEGIN_COM_MAP (CombinedProgress)
81 COM_INTERFACE_ENTRY (ISupportErrorInfo)
82 COM_INTERFACE_ENTRY (IProgress)
83 COM_INTERFACE_ENTRY2 (IDispatch, IProgress)
84 END_COM_MAP()
85
86 HRESULT FinalConstruct();
87 void FinalRelease();
88
89 // public initializer/uninitializer for internal purposes only
90
91 HRESULT init (
92#if !defined (VBOX_COM_INPROC)
93 VirtualBox *aParent,
94#endif
95 IUnknown *aInitiator,
96 CBSTR aDescription,
97 IProgress *aProgress1, IProgress *aProgress2,
98 OUT_GUID aId = NULL);
99
100 /**
101 * Initializes the combined progress object given the first and the last
102 * normal progress object from the list.
103 *
104 * @param aParent See ProgressBase::init().
105 * @param aInitiator See ProgressBase::init().
106 * @param aDescription See ProgressBase::init().
107 * @param aFirstProgress Iterator of the first normal progress object.
108 * @param aSecondProgress Iterator of the last normal progress object.
109 * @param aId See ProgressBase::init().
110 */
111 template <typename InputIterator>
112 HRESULT init (
113#if !defined (VBOX_COM_INPROC)
114 VirtualBox *aParent,
115#endif
116 IUnknown *aInitiator,
117 CBSTR aDescription,
118 InputIterator aFirstProgress, InputIterator aLastProgress,
119 OUT_GUID aId = NULL)
120 {
121 /* Enclose the state transition NotReady->InInit->Ready */
122 AutoInitSpan autoInitSpan (this);
123 AssertReturn (autoInitSpan.isOk(), E_FAIL);
124
125 mProgresses = ProgressVector (aFirstProgress, aLastProgress);
126
127 HRESULT rc = protectedInit (autoInitSpan,
128#if !defined (VBOX_COM_INPROC)
129 aParent,
130#endif
131 aInitiator, aDescription, aId);
132
133 /* Confirm a successful initialization when it's the case */
134 if (SUCCEEDED(rc))
135 autoInitSpan.setSucceeded();
136
137 return rc;
138 }
139
140protected:
141
142 HRESULT protectedInit (AutoInitSpan &aAutoInitSpan,
143#if !defined (VBOX_COM_INPROC)
144 VirtualBox *aParent,
145#endif
146 IUnknown *aInitiator,
147 CBSTR aDescription, OUT_GUID aId);
148
149public:
150
151 void uninit();
152
153 // IProgress properties
154 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
155 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
156 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
157 STDMETHOD(COMGETTER(ResultCode)) (LONG *aResultCode);
158 STDMETHOD(COMGETTER(ErrorInfo)) (IVirtualBoxErrorInfo **aErrorInfo);
159 STDMETHOD(COMGETTER(Operation)) (ULONG *aCount);
160 STDMETHOD(COMGETTER(OperationDescription)) (BSTR *aOperationDescription);
161 STDMETHOD(COMGETTER(OperationPercent)) (ULONG *aOperationPercent);
162 STDMETHOD(COMSETTER(Timeout)) (ULONG aTimeout);
163 STDMETHOD(COMGETTER(Timeout)) (ULONG *aTimeout);
164
165 // IProgress methods
166 STDMETHOD(WaitForCompletion) (LONG aTimeout);
167 STDMETHOD(WaitForOperationCompletion) (ULONG aOperation, LONG aTimeout);
168 STDMETHOD(Cancel)();
169
170 STDMETHOD(SetCurrentOperationProgress)(ULONG aPercent)
171 {
172 NOREF(aPercent);
173 return E_NOTIMPL;
174 }
175
176 STDMETHOD(SetNextOperation)(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight)
177 {
178 NOREF(bstrNextOperationDescription); NOREF(ulNextOperationsWeight);
179 return E_NOTIMPL;
180 }
181
182 // public methods only for internal purposes
183
184 /** For com::SupportErrorInfoImpl. */
185 static const char *ComponentName() { return "CombinedProgress"; }
186
187private:
188
189 HRESULT checkProgress();
190
191 typedef std::vector <ComPtr<IProgress> > ProgressVector;
192 ProgressVector mProgresses;
193
194 size_t mProgress;
195 ULONG mCompletedOperations;
196};
197
198#endif /* ____H_PROGRESSCOMBINEDIMPL */
199
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