1 | /* $Id: ProgressProxyImpl.cpp 32780 2010-09-27 19:00:22Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IProgress implementation for Machine::openRemoteSession in VBoxSVC.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <iprt/types.h>
|
---|
19 |
|
---|
20 | #if defined (VBOX_WITH_XPCOM)
|
---|
21 | #include <nsIServiceManager.h>
|
---|
22 | #include <nsIExceptionService.h>
|
---|
23 | #include <nsCOMPtr.h>
|
---|
24 | #endif /* defined (VBOX_WITH_XPCOM) */
|
---|
25 |
|
---|
26 | #include "ProgressProxyImpl.h"
|
---|
27 |
|
---|
28 | #include "VirtualBoxImpl.h"
|
---|
29 | #include "VirtualBoxErrorInfoImpl.h"
|
---|
30 |
|
---|
31 | #include "Logging.h"
|
---|
32 |
|
---|
33 | #include <iprt/time.h>
|
---|
34 | #include <iprt/semaphore.h>
|
---|
35 |
|
---|
36 | #include <VBox/err.h>
|
---|
37 |
|
---|
38 | ////////////////////////////////////////////////////////////////////////////////
|
---|
39 | // ProgressProxy class
|
---|
40 | ////////////////////////////////////////////////////////////////////////////////
|
---|
41 |
|
---|
42 | // constructor / destructor / uninitializer
|
---|
43 | ////////////////////////////////////////////////////////////////////////////////
|
---|
44 |
|
---|
45 |
|
---|
46 | HRESULT ProgressProxy::FinalConstruct()
|
---|
47 | {
|
---|
48 | mfMultiOperation = false;
|
---|
49 | muOtherProgressStartWeight = 0;
|
---|
50 | muOtherProgressWeight = 0;
|
---|
51 | muOtherProgressStartOperation = 0;
|
---|
52 |
|
---|
53 | HRESULT rc = Progress::FinalConstruct();
|
---|
54 | return rc;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Initalize it as a one operation Progress object.
|
---|
59 | *
|
---|
60 | * This is used by SessionMachine::OnSessionEnd.
|
---|
61 | */
|
---|
62 | HRESULT ProgressProxy::init(
|
---|
63 | #if !defined (VBOX_COM_INPROC)
|
---|
64 | VirtualBox *pParent,
|
---|
65 | #endif
|
---|
66 | IUnknown *pInitiator,
|
---|
67 | CBSTR bstrDescription,
|
---|
68 | BOOL fCancelable)
|
---|
69 | {
|
---|
70 | mfMultiOperation = false;
|
---|
71 | muOtherProgressStartWeight = 1;
|
---|
72 | muOtherProgressWeight = 1;
|
---|
73 | muOtherProgressStartOperation = 1;
|
---|
74 |
|
---|
75 | return Progress::init(
|
---|
76 | #if !defined (VBOX_COM_INPROC)
|
---|
77 | pParent,
|
---|
78 | #endif
|
---|
79 | pInitiator,
|
---|
80 | bstrDescription,
|
---|
81 | fCancelable,
|
---|
82 | 1 /* cOperations */,
|
---|
83 | 1 /* ulTotalOperationsWeight */,
|
---|
84 | bstrDescription /* bstrFirstOperationDescription */,
|
---|
85 | 1 /* ulFirstOperationWeight */,
|
---|
86 | NULL /* pId */);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Initialize for proxying one other progress object.
|
---|
91 | *
|
---|
92 | * This is tailored explicitly for the openRemoteSession code, so we start out
|
---|
93 | * with one operation where we don't have any remote object (powerUp). Then a
|
---|
94 | * remote object is added and stays with us till the end.
|
---|
95 | *
|
---|
96 | * The user must do normal completion notification or risk leave the threads
|
---|
97 | * waiting forever!
|
---|
98 | */
|
---|
99 | HRESULT ProgressProxy::init(
|
---|
100 | #if !defined (VBOX_COM_INPROC)
|
---|
101 | VirtualBox *pParent,
|
---|
102 | #endif
|
---|
103 | IUnknown *pInitiator,
|
---|
104 | CBSTR bstrDescription,
|
---|
105 | BOOL fCancelable,
|
---|
106 | ULONG uTotalOperationsWeight,
|
---|
107 | CBSTR bstrFirstOperationDescription,
|
---|
108 | ULONG uFirstOperationWeight,
|
---|
109 | ULONG cOtherProgressObjectOperations)
|
---|
110 | {
|
---|
111 | mfMultiOperation = false;
|
---|
112 | muOtherProgressStartWeight = uFirstOperationWeight;
|
---|
113 | muOtherProgressWeight = uTotalOperationsWeight - uFirstOperationWeight;
|
---|
114 | muOtherProgressStartOperation = 1;
|
---|
115 |
|
---|
116 | return Progress::init(
|
---|
117 | #if !defined (VBOX_COM_INPROC)
|
---|
118 | pParent,
|
---|
119 | #endif
|
---|
120 | pInitiator,
|
---|
121 | bstrDescription,
|
---|
122 | fCancelable,
|
---|
123 | 1 + cOtherProgressObjectOperations /* cOperations */,
|
---|
124 | uTotalOperationsWeight,
|
---|
125 | bstrFirstOperationDescription,
|
---|
126 | uFirstOperationWeight,
|
---|
127 | NULL);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void ProgressProxy::FinalRelease()
|
---|
131 | {
|
---|
132 | uninit();
|
---|
133 | mfMultiOperation = false;
|
---|
134 | muOtherProgressStartWeight = 0;
|
---|
135 | muOtherProgressWeight = 0;
|
---|
136 | muOtherProgressStartOperation = 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | void ProgressProxy::uninit()
|
---|
140 | {
|
---|
141 | LogFlowThisFunc(("\n"));
|
---|
142 |
|
---|
143 | mptrOtherProgress.setNull();
|
---|
144 | Progress::uninit();
|
---|
145 | }
|
---|
146 |
|
---|
147 | // Public methods
|
---|
148 | ////////////////////////////////////////////////////////////////////////////////
|
---|
149 |
|
---|
150 | /** Just a wrapper so we can automatically do the handover before setting
|
---|
151 | * the result locally. */
|
---|
152 | HRESULT ProgressProxy::notifyComplete(HRESULT aResultCode)
|
---|
153 | {
|
---|
154 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
155 | clearOtherProgressObjectInternal(true /* fEarly */);
|
---|
156 | HRESULT hrc = S_OK;
|
---|
157 | if (!mCompleted)
|
---|
158 | hrc = Progress::notifyComplete(aResultCode);
|
---|
159 | return hrc;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /** Just a wrapper so we can automatically do the handover before setting
|
---|
163 | * the result locally. */
|
---|
164 | HRESULT ProgressProxy::notifyComplete(HRESULT aResultCode,
|
---|
165 | const GUID &aIID,
|
---|
166 | const char *pcszComponent,
|
---|
167 | const char *aText,
|
---|
168 | ...)
|
---|
169 | {
|
---|
170 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
171 | clearOtherProgressObjectInternal(true /* fEarly */);
|
---|
172 |
|
---|
173 | HRESULT hrc = S_OK;
|
---|
174 | if (!mCompleted)
|
---|
175 | {
|
---|
176 | va_list va;
|
---|
177 | va_start(va, aText);
|
---|
178 | hrc = Progress::notifyCompleteV(aResultCode, aIID, pcszComponent, aText, va);
|
---|
179 | va_end(va);
|
---|
180 | }
|
---|
181 | return hrc;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Sets the other progress object unless the operation has been completed /
|
---|
186 | * canceled already.
|
---|
187 | *
|
---|
188 | * @returns false if failed/canceled, true if not.
|
---|
189 | * @param pOtherProgress The other progress object. Must not be NULL.
|
---|
190 | */
|
---|
191 | bool ProgressProxy::setOtherProgressObject(IProgress *pOtherProgress)
|
---|
192 | {
|
---|
193 | LogFlowThisFunc(("setOtherProgressObject: %p\n", pOtherProgress));
|
---|
194 | ComPtr<IProgress> ptrOtherProgress = pOtherProgress;
|
---|
195 |
|
---|
196 | /*
|
---|
197 | * Query information from the other progress object before we grab the
|
---|
198 | * lock.
|
---|
199 | */
|
---|
200 | ULONG cOperations;
|
---|
201 | HRESULT hrc = pOtherProgress->COMGETTER(OperationCount)(&cOperations);
|
---|
202 | if (FAILED(hrc))
|
---|
203 | cOperations = 1;
|
---|
204 |
|
---|
205 | Bstr bstrOperationDescription;
|
---|
206 | hrc = pOtherProgress->COMGETTER(Description)(bstrOperationDescription.asOutParam());
|
---|
207 | if (FAILED(hrc))
|
---|
208 | bstrOperationDescription = "oops";
|
---|
209 |
|
---|
210 |
|
---|
211 | /*
|
---|
212 | * Take the lock and check for cancelation, cancel the other object if
|
---|
213 | * we've been canceled already.
|
---|
214 | */
|
---|
215 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
216 |
|
---|
217 | BOOL fCompletedOrCanceled = mCompleted || mCanceled;
|
---|
218 | if (!fCompletedOrCanceled)
|
---|
219 | {
|
---|
220 | /*
|
---|
221 | * Advance to the next object and operation. If the other object has
|
---|
222 | * more operations than anticipated, adjust our internal count.
|
---|
223 | */
|
---|
224 | mptrOtherProgress = ptrOtherProgress;
|
---|
225 | mfMultiOperation = cOperations > 1;
|
---|
226 |
|
---|
227 | muOtherProgressStartWeight = m_ulOperationsCompletedWeight + m_ulCurrentOperationWeight;
|
---|
228 | muOtherProgressWeight = m_ulTotalOperationsWeight - muOtherProgressStartWeight;
|
---|
229 | Progress::SetNextOperation(bstrOperationDescription.raw(), muOtherProgressWeight);
|
---|
230 |
|
---|
231 | muOtherProgressStartOperation = m_ulCurrentOperation;
|
---|
232 | m_cOperations = cOperations + m_ulCurrentOperation;
|
---|
233 |
|
---|
234 | /*
|
---|
235 | * Check for cancelation and completion.
|
---|
236 | */
|
---|
237 | BOOL f;
|
---|
238 | hrc = ptrOtherProgress->COMGETTER(Completed)(&f);
|
---|
239 | fCompletedOrCanceled = FAILED(hrc) || f;
|
---|
240 |
|
---|
241 | if (!fCompletedOrCanceled)
|
---|
242 | {
|
---|
243 | hrc = ptrOtherProgress->COMGETTER(Canceled)(&f);
|
---|
244 | fCompletedOrCanceled = SUCCEEDED(hrc) && f;
|
---|
245 | }
|
---|
246 |
|
---|
247 | if (fCompletedOrCanceled)
|
---|
248 | {
|
---|
249 | LogFlowThisFunc(("Other object completed or canceled, clearing...\n"));
|
---|
250 | clearOtherProgressObjectInternal(false /*fEarly*/);
|
---|
251 | }
|
---|
252 | else
|
---|
253 | {
|
---|
254 | /*
|
---|
255 | * Finally, mirror the cancelable property.
|
---|
256 | * Note! Note necessary if we do passthru!
|
---|
257 | */
|
---|
258 | if (mCancelable)
|
---|
259 | {
|
---|
260 | hrc = ptrOtherProgress->COMGETTER(Cancelable)(&f);
|
---|
261 | if (SUCCEEDED(hrc) && !f)
|
---|
262 | {
|
---|
263 | LogFlowThisFunc(("The other progress object is not cancelable\n"));
|
---|
264 | mCancelable = FALSE;
|
---|
265 | }
|
---|
266 | }
|
---|
267 | }
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | LogFlowThisFunc(("mCompleted=%RTbool mCanceled=%RTbool - Canceling the other progress object!\n",
|
---|
272 | mCompleted, mCanceled));
|
---|
273 | hrc = ptrOtherProgress->Cancel();
|
---|
274 | LogFlowThisFunc(("Cancel -> %Rhrc", hrc));
|
---|
275 | }
|
---|
276 |
|
---|
277 | LogFlowThisFunc(("Returns %RTbool\n", !fCompletedOrCanceled));
|
---|
278 | return !fCompletedOrCanceled;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // Internal methods.
|
---|
282 | ////////////////////////////////////////////////////////////////////////////////
|
---|
283 |
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Clear the other progress object reference, first copying over its state.
|
---|
287 | *
|
---|
288 | * This is used internally when completion is signalled one way or another.
|
---|
289 | *
|
---|
290 | * @param fEarly Early clearing or not.
|
---|
291 | */
|
---|
292 | void ProgressProxy::clearOtherProgressObjectInternal(bool fEarly)
|
---|
293 | {
|
---|
294 | if (!mptrOtherProgress.isNull())
|
---|
295 | {
|
---|
296 | ComPtr<IProgress> ptrOtherProgress = mptrOtherProgress;
|
---|
297 | mptrOtherProgress.setNull();
|
---|
298 | copyProgressInfo(ptrOtherProgress, fEarly);
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | /**
|
---|
303 | * Called to copy over the progress information from @a pOtherProgress.
|
---|
304 | *
|
---|
305 | * @param pOtherProgress The source of the information.
|
---|
306 | * @param fEarly Early copy.
|
---|
307 | *
|
---|
308 | * @note The caller owns the write lock and as cleared mptrOtherProgress
|
---|
309 | * already (or we might recurse forever)!
|
---|
310 | */
|
---|
311 | void ProgressProxy::copyProgressInfo(IProgress *pOtherProgress, bool fEarly)
|
---|
312 | {
|
---|
313 | HRESULT hrc;
|
---|
314 | LogFlowThisFunc(("\n"));
|
---|
315 |
|
---|
316 | NOREF(fEarly);
|
---|
317 |
|
---|
318 | /*
|
---|
319 | * No point in doing this if the progress object was canceled already.
|
---|
320 | */
|
---|
321 | if (!mCanceled)
|
---|
322 | {
|
---|
323 | /* Detect if the other progress object was canceled. */
|
---|
324 | BOOL fCanceled;
|
---|
325 | hrc = pOtherProgress->COMGETTER(Canceled)(&fCanceled);
|
---|
326 | if (FAILED(hrc))
|
---|
327 | fCanceled = FALSE;
|
---|
328 | if (fCanceled)
|
---|
329 | {
|
---|
330 | LogFlowThisFunc(("Canceled\n"));
|
---|
331 | mCanceled = TRUE;
|
---|
332 | if (m_pfnCancelCallback)
|
---|
333 | m_pfnCancelCallback(m_pvCancelUserArg);
|
---|
334 | }
|
---|
335 | else
|
---|
336 | {
|
---|
337 | /* Has it completed? */
|
---|
338 | BOOL fCompleted;
|
---|
339 | hrc = pOtherProgress->COMGETTER(Completed)(&fCompleted);
|
---|
340 | if (FAILED(hrc))
|
---|
341 | fCompleted = TRUE;
|
---|
342 | Assert(fCompleted || fEarly);
|
---|
343 | if (fCompleted)
|
---|
344 | {
|
---|
345 | /* Check the result. */
|
---|
346 | LONG hrcResult;
|
---|
347 | hrc = pOtherProgress->COMGETTER(ResultCode)(&hrcResult);
|
---|
348 | if (FAILED(hrc))
|
---|
349 | hrcResult = hrc;
|
---|
350 | if (SUCCEEDED((HRESULT)hrcResult))
|
---|
351 | LogFlowThisFunc(("Succeeded\n"));
|
---|
352 | else
|
---|
353 | {
|
---|
354 | /* Get the error information. */
|
---|
355 | ComPtr<IVirtualBoxErrorInfo> ptrErrorInfo;
|
---|
356 | hrc = pOtherProgress->COMGETTER(ErrorInfo)(ptrErrorInfo.asOutParam());
|
---|
357 | if (SUCCEEDED(hrc))
|
---|
358 | {
|
---|
359 | Bstr bstrIID;
|
---|
360 | hrc = ptrErrorInfo->COMGETTER(InterfaceID)(bstrIID.asOutParam()); AssertComRC(hrc);
|
---|
361 | if (FAILED(hrc))
|
---|
362 | bstrIID.setNull();
|
---|
363 |
|
---|
364 | Bstr bstrComponent;
|
---|
365 | hrc = ptrErrorInfo->COMGETTER(Component)(bstrComponent.asOutParam()); AssertComRC(hrc);
|
---|
366 | if (FAILED(hrc))
|
---|
367 | bstrComponent = "failed";
|
---|
368 |
|
---|
369 | Bstr bstrText;
|
---|
370 | hrc = ptrErrorInfo->COMGETTER(Text)(bstrText.asOutParam()); AssertComRC(hrc);
|
---|
371 | if (FAILED(hrc))
|
---|
372 | bstrText = "<failed>";
|
---|
373 |
|
---|
374 | Utf8Str strText(bstrText);
|
---|
375 | LogFlowThisFunc(("Got ErrorInfo(%s); hrcResult=%Rhrc\n", strText.c_str(), hrcResult));
|
---|
376 | Progress::notifyComplete((HRESULT)hrcResult,
|
---|
377 | Guid(bstrIID).ref(),
|
---|
378 | Utf8Str(bstrComponent).c_str(),
|
---|
379 | "%s", strText.c_str());
|
---|
380 | }
|
---|
381 | else
|
---|
382 | {
|
---|
383 | LogFlowThisFunc(("ErrorInfo failed with hrc=%Rhrc; hrcResult=%Rhrc\n", hrc, hrcResult));
|
---|
384 | Progress::notifyComplete((HRESULT)hrcResult,
|
---|
385 | COM_IIDOF(IProgress),
|
---|
386 | "ProgressProxy",
|
---|
387 | tr("No error info"));
|
---|
388 | }
|
---|
389 | }
|
---|
390 | }
|
---|
391 | else
|
---|
392 | LogFlowThisFunc(("Not completed\n"));
|
---|
393 | }
|
---|
394 | }
|
---|
395 | else
|
---|
396 | LogFlowThisFunc(("Already canceled\n"));
|
---|
397 |
|
---|
398 | /*
|
---|
399 | * Did cancelable state change (point of no return)?
|
---|
400 | */
|
---|
401 | if (mCancelable && !mCompleted && !mCanceled)
|
---|
402 | {
|
---|
403 | BOOL fCancelable;
|
---|
404 | hrc = pOtherProgress->COMGETTER(Cancelable)(&fCancelable); AssertComRC(hrc);
|
---|
405 | if (SUCCEEDED(hrc) && !fCancelable)
|
---|
406 | {
|
---|
407 | LogFlowThisFunc(("point-of-no-return reached\n"));
|
---|
408 | mCancelable = FALSE;
|
---|
409 | }
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 |
|
---|
414 | // IProgress properties
|
---|
415 | ////////////////////////////////////////////////////////////////////////////////
|
---|
416 |
|
---|
417 | STDMETHODIMP ProgressProxy::COMGETTER(Cancelable)(BOOL *aCancelable)
|
---|
418 | {
|
---|
419 | CheckComArgOutPointerValid(aCancelable);
|
---|
420 |
|
---|
421 | AutoCaller autoCaller(this);
|
---|
422 | HRESULT hrc = autoCaller.rc();
|
---|
423 | if (SUCCEEDED(hrc))
|
---|
424 | {
|
---|
425 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
426 |
|
---|
427 | /* ASSUME: The cancelable property can only change to FALSE. */
|
---|
428 | if (!mCancelable || mptrOtherProgress.isNull())
|
---|
429 | *aCancelable = mCancelable;
|
---|
430 | else
|
---|
431 | {
|
---|
432 | hrc = mptrOtherProgress->COMGETTER(Cancelable)(aCancelable);
|
---|
433 | if (SUCCEEDED(hrc) && !*aCancelable)
|
---|
434 | {
|
---|
435 | LogFlowThisFunc(("point-of-no-return reached\n"));
|
---|
436 | mCancelable = FALSE;
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 | return hrc;
|
---|
441 | }
|
---|
442 |
|
---|
443 | STDMETHODIMP ProgressProxy::COMGETTER(Percent)(ULONG *aPercent)
|
---|
444 | {
|
---|
445 | CheckComArgOutPointerValid(aPercent);
|
---|
446 |
|
---|
447 | AutoCaller autoCaller(this);
|
---|
448 | HRESULT hrc = autoCaller.rc();
|
---|
449 | if (SUCCEEDED(hrc))
|
---|
450 | {
|
---|
451 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
452 |
|
---|
453 | if (mptrOtherProgress.isNull())
|
---|
454 | hrc = Progress::COMGETTER(Percent)(aPercent);
|
---|
455 | else
|
---|
456 | {
|
---|
457 | /*
|
---|
458 | * Get the overall percent of the other object and adjust it with
|
---|
459 | * the weighting given to the period before proxying started.
|
---|
460 | */
|
---|
461 | ULONG uPct;
|
---|
462 | hrc = mptrOtherProgress->COMGETTER(Percent)(&uPct);
|
---|
463 | if (SUCCEEDED(hrc))
|
---|
464 | {
|
---|
465 | double rdPercent = ((double)uPct / 100 * muOtherProgressWeight + muOtherProgressStartWeight)
|
---|
466 | / m_ulTotalOperationsWeight * 100;
|
---|
467 | *aPercent = RT_MIN((ULONG)rdPercent, 99); /* mptrOtherProgress is cleared when its completed, so we can never return 100%. */
|
---|
468 | }
|
---|
469 | }
|
---|
470 | }
|
---|
471 | return hrc;
|
---|
472 | }
|
---|
473 |
|
---|
474 | STDMETHODIMP ProgressProxy::COMGETTER(TimeRemaining)(LONG *aTimeRemaining)
|
---|
475 | {
|
---|
476 | CheckComArgOutPointerValid(aTimeRemaining);
|
---|
477 |
|
---|
478 | AutoCaller autoCaller(this);
|
---|
479 | HRESULT hrc = autoCaller.rc();
|
---|
480 | if (SUCCEEDED(hrc))
|
---|
481 | {
|
---|
482 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
483 |
|
---|
484 | if (mptrOtherProgress.isNull())
|
---|
485 | hrc = Progress::COMGETTER(TimeRemaining)(aTimeRemaining);
|
---|
486 | else
|
---|
487 | hrc = mptrOtherProgress->COMGETTER(TimeRemaining)(aTimeRemaining);
|
---|
488 | }
|
---|
489 | return hrc;
|
---|
490 | }
|
---|
491 |
|
---|
492 | STDMETHODIMP ProgressProxy::COMGETTER(Completed)(BOOL *aCompleted)
|
---|
493 | {
|
---|
494 | /* Not proxied since we EXPECT a normal completion notification call. */
|
---|
495 | return Progress::COMGETTER(Completed)(aCompleted);
|
---|
496 | }
|
---|
497 |
|
---|
498 | STDMETHODIMP ProgressProxy::COMGETTER(Canceled)(BOOL *aCanceled)
|
---|
499 | {
|
---|
500 | CheckComArgOutPointerValid(aCanceled);
|
---|
501 |
|
---|
502 | AutoCaller autoCaller(this);
|
---|
503 | HRESULT hrc = autoCaller.rc();
|
---|
504 | if (SUCCEEDED(hrc))
|
---|
505 | {
|
---|
506 | /* Check the local data first, then the other object. */
|
---|
507 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
508 | hrc = Progress::COMGETTER(Canceled)(aCanceled);
|
---|
509 | if ( SUCCEEDED(hrc)
|
---|
510 | && !*aCanceled
|
---|
511 | && !mptrOtherProgress.isNull()
|
---|
512 | && mCancelable)
|
---|
513 | {
|
---|
514 | hrc = mptrOtherProgress->COMGETTER(Canceled)(aCanceled);
|
---|
515 | if (SUCCEEDED(hrc) && *aCanceled)
|
---|
516 | /* This will not complete the object, only mark it as canceled. */
|
---|
517 | clearOtherProgressObjectInternal(false /*fEarly*/);
|
---|
518 | }
|
---|
519 | }
|
---|
520 | return hrc;
|
---|
521 | }
|
---|
522 |
|
---|
523 | STDMETHODIMP ProgressProxy::COMGETTER(ResultCode)(LONG *aResultCode)
|
---|
524 | {
|
---|
525 | /* Not proxied since we EXPECT a normal completion notification call. */
|
---|
526 | return Progress::COMGETTER(ResultCode)(aResultCode);
|
---|
527 | }
|
---|
528 |
|
---|
529 | STDMETHODIMP ProgressProxy::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo)
|
---|
530 | {
|
---|
531 | /* Not proxied since we EXPECT a normal completion notification call. */
|
---|
532 | return Progress::COMGETTER(ErrorInfo)(aErrorInfo);
|
---|
533 | }
|
---|
534 |
|
---|
535 | STDMETHODIMP ProgressProxy::COMGETTER(Operation)(ULONG *aOperation)
|
---|
536 | {
|
---|
537 | CheckComArgOutPointerValid(aOperation);
|
---|
538 |
|
---|
539 | AutoCaller autoCaller(this);
|
---|
540 | HRESULT hrc = autoCaller.rc();
|
---|
541 | if (SUCCEEDED(hrc))
|
---|
542 | {
|
---|
543 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
544 | if (mptrOtherProgress.isNull())
|
---|
545 | hrc = Progress::COMGETTER(Operation)(aOperation);
|
---|
546 | else
|
---|
547 | {
|
---|
548 | ULONG uCurOtherOperation;
|
---|
549 | hrc = mptrOtherProgress->COMGETTER(Operation)(&uCurOtherOperation);
|
---|
550 | if (SUCCEEDED(hrc))
|
---|
551 | *aOperation = uCurOtherOperation + muOtherProgressStartOperation;
|
---|
552 | }
|
---|
553 | }
|
---|
554 | return hrc;
|
---|
555 | }
|
---|
556 |
|
---|
557 | STDMETHODIMP ProgressProxy::COMGETTER(OperationDescription)(BSTR *aOperationDescription)
|
---|
558 | {
|
---|
559 | CheckComArgOutPointerValid(aOperationDescription);
|
---|
560 |
|
---|
561 | AutoCaller autoCaller(this);
|
---|
562 | HRESULT hrc = autoCaller.rc();
|
---|
563 | if (SUCCEEDED(hrc))
|
---|
564 | {
|
---|
565 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
566 | if (mptrOtherProgress.isNull() || !mfMultiOperation)
|
---|
567 | hrc = Progress::COMGETTER(OperationDescription)(aOperationDescription);
|
---|
568 | else
|
---|
569 | hrc = mptrOtherProgress->COMGETTER(OperationDescription)(aOperationDescription);
|
---|
570 | }
|
---|
571 | return hrc;
|
---|
572 | }
|
---|
573 |
|
---|
574 | STDMETHODIMP ProgressProxy::COMGETTER(OperationPercent)(ULONG *aOperationPercent)
|
---|
575 | {
|
---|
576 | CheckComArgOutPointerValid(aOperationPercent);
|
---|
577 |
|
---|
578 | AutoCaller autoCaller(this);
|
---|
579 | HRESULT hrc = autoCaller.rc();
|
---|
580 | if (SUCCEEDED(hrc))
|
---|
581 | {
|
---|
582 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
583 | if (mptrOtherProgress.isNull() || !mfMultiOperation)
|
---|
584 | hrc = Progress::COMGETTER(OperationPercent)(aOperationPercent);
|
---|
585 | else
|
---|
586 | hrc = mptrOtherProgress->COMGETTER(OperationPercent)(aOperationPercent);
|
---|
587 | }
|
---|
588 | return hrc;
|
---|
589 | }
|
---|
590 |
|
---|
591 | STDMETHODIMP ProgressProxy::COMSETTER(Timeout)(ULONG aTimeout)
|
---|
592 | {
|
---|
593 | /* Not currently supported. */
|
---|
594 | NOREF(aTimeout);
|
---|
595 | AssertFailed();
|
---|
596 | return E_NOTIMPL;
|
---|
597 | }
|
---|
598 |
|
---|
599 | STDMETHODIMP ProgressProxy::COMGETTER(Timeout)(ULONG *aTimeout)
|
---|
600 | {
|
---|
601 | /* Not currently supported. */
|
---|
602 | CheckComArgOutPointerValid(aTimeout);
|
---|
603 |
|
---|
604 | AssertFailed();
|
---|
605 | return E_NOTIMPL;
|
---|
606 | }
|
---|
607 |
|
---|
608 | // IProgress methods
|
---|
609 | /////////////////////////////////////////////////////////////////////////////
|
---|
610 |
|
---|
611 | STDMETHODIMP ProgressProxy::WaitForCompletion(LONG aTimeout)
|
---|
612 | {
|
---|
613 | HRESULT hrc;
|
---|
614 | LogFlowThisFuncEnter();
|
---|
615 | LogFlowThisFunc(("aTimeout=%d\n", aTimeout));
|
---|
616 |
|
---|
617 | /* No need to wait on the proxied object for these since we'll get the
|
---|
618 | normal completion notifications. */
|
---|
619 | hrc = Progress::WaitForCompletion(aTimeout);
|
---|
620 |
|
---|
621 | LogFlowThisFuncLeave();
|
---|
622 | return hrc;
|
---|
623 | }
|
---|
624 |
|
---|
625 | STDMETHODIMP ProgressProxy::WaitForOperationCompletion(ULONG aOperation, LONG aTimeout)
|
---|
626 | {
|
---|
627 | LogFlowThisFuncEnter();
|
---|
628 | LogFlowThisFunc(("aOperation=%d aTimeout=%d\n", aOperation, aTimeout));
|
---|
629 |
|
---|
630 | AutoCaller autoCaller(this);
|
---|
631 | HRESULT hrc = autoCaller.rc();
|
---|
632 | if (SUCCEEDED(hrc))
|
---|
633 | {
|
---|
634 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
635 |
|
---|
636 | CheckComArgExpr(aOperation, aOperation < m_cOperations);
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * Check if we can wait locally.
|
---|
640 | */
|
---|
641 | if ( aOperation + 1 == m_cOperations /* final operation */
|
---|
642 | || mptrOtherProgress.isNull())
|
---|
643 | {
|
---|
644 | /* ASSUMES that Progress::WaitForOperationCompletion is using
|
---|
645 | AutoWriteLock::leave() as it saves us from duplicating the code! */
|
---|
646 | hrc = Progress::WaitForOperationCompletion(aOperation, aTimeout);
|
---|
647 | }
|
---|
648 | else
|
---|
649 | {
|
---|
650 | LogFlowThisFunc(("calling the other object...\n"));
|
---|
651 | ComPtr<IProgress> ptrOtherProgress = mptrOtherProgress;
|
---|
652 | alock.release();
|
---|
653 |
|
---|
654 | hrc = ptrOtherProgress->WaitForOperationCompletion(aOperation, aTimeout);
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | LogFlowThisFuncLeave();
|
---|
659 | return hrc;
|
---|
660 | }
|
---|
661 |
|
---|
662 | STDMETHODIMP ProgressProxy::Cancel()
|
---|
663 | {
|
---|
664 | LogFlowThisFunc(("\n"));
|
---|
665 | AutoCaller autoCaller(this);
|
---|
666 | HRESULT hrc = autoCaller.rc();
|
---|
667 | if (SUCCEEDED(hrc))
|
---|
668 | {
|
---|
669 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
670 | if (mptrOtherProgress.isNull() || !mCancelable)
|
---|
671 | hrc = Progress::Cancel();
|
---|
672 | else
|
---|
673 | {
|
---|
674 | hrc = mptrOtherProgress->Cancel();
|
---|
675 | if (SUCCEEDED(hrc))
|
---|
676 | clearOtherProgressObjectInternal(false /*fEarly*/);
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | LogFlowThisFunc(("returns %Rhrc\n", hrc));
|
---|
681 | return hrc;
|
---|
682 | }
|
---|
683 |
|
---|
684 | STDMETHODIMP ProgressProxy::SetCurrentOperationProgress(ULONG aPercent)
|
---|
685 | {
|
---|
686 | /* Not supported - why do we actually expose this? */
|
---|
687 | NOREF(aPercent);
|
---|
688 | return E_NOTIMPL;
|
---|
689 | }
|
---|
690 |
|
---|
691 | STDMETHODIMP ProgressProxy::SetNextOperation(IN_BSTR bstrNextOperationDescription, ULONG ulNextOperationsWeight)
|
---|
692 | {
|
---|
693 | /* Not supported - why do we actually expose this? */
|
---|
694 | NOREF(bstrNextOperationDescription);
|
---|
695 | NOREF(ulNextOperationsWeight);
|
---|
696 | return E_NOTIMPL;
|
---|
697 | }
|
---|
698 |
|
---|
699 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|
700 |
|
---|