VirtualBox

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

Last change on this file since 27908 was 26186, checked in by vboxsync, 15 years ago

Main: coding style fixes

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