Changeset 23810 in vbox for trunk/src/VBox/Main
- Timestamp:
- Oct 15, 2009 5:00:44 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 53553
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r23801 r23810 4635 4635 progressDesc = tr("Starting virtual machine"); 4636 4636 rc = powerupProgress->init(static_cast<IConsole *>(this), 4637 progressDesc, FALSE /* aCancelable */); 4637 progressDesc, 4638 fTeleporterEnabled /* aCancelable */); 4638 4639 CheckComRCReturnRC(rc); 4639 4640 … … 6763 6764 { 6764 6765 /* -> ConsoleImplTeleporter.cpp */ 6765 vrc = console->teleporterTrg(pVM, pMachine, task->mStartPaused, 6766 static_cast<VMProgressTask*>(task.get())); 6766 vrc = console->teleporterTrg(pVM, pMachine, task->mStartPaused, task->mProgress); 6767 6767 if (RT_FAILURE(vrc)) 6768 6768 VMR3PowerOff(pVM); -
trunk/src/VBox/Main/ConsoleImplTeleporter.cpp
r23806 r23810 54 54 ComPtr<Console> mptrConsole; 55 55 PVM mpVM; 56 ComObjPtr<Progress> mptrProgress; 56 57 Utf8Str mstrPassword; 57 58 bool const mfIsSource; … … 67 68 /** @} */ 68 69 69 TeleporterState(Console *pConsole, PVM pVM, bool fIsSource)70 TeleporterState(Console *pConsole, PVM pVM, Progress *pProgress, bool fIsSource) 70 71 : mptrConsole(pConsole) 71 72 , mpVM(pVM) 73 , mptrProgress(pProgress) 72 74 , mfIsSource(fIsSource) 73 75 , mhSocket(NIL_RTSOCKET) … … 88 90 { 89 91 public: 90 ComPtr<Progress> mptrProgress;91 92 Utf8Str mstrHostname; 92 93 uint32_t muPort; 93 94 94 TeleporterStateSrc(Console *pConsole, PVM pVM )95 : TeleporterState(pConsole, pVM, true /*fIsSource*/)95 TeleporterStateSrc(Console *pConsole, PVM pVM, Progress *pProgress) 96 : TeleporterState(pConsole, pVM, pProgress, true /*fIsSource*/) 96 97 , muPort(UINT32_MAX) 97 98 { … … 107 108 public: 108 109 IMachine *mpMachine; 109 void *mpvVMCallbackTask;110 110 PRTTCPSERVER mhServer; 111 111 PRTTIMERLR mphTimerLR; 112 112 int mRc; 113 113 114 TeleporterStateTrg(Console *pConsole, PVM pVM, IMachine *pMachine, PRTTIMERLR phTimerLR) 115 : TeleporterState(pConsole, pVM, false /*fIsSource*/) 114 TeleporterStateTrg(Console *pConsole, PVM pVM, Progress *pProgress, 115 IMachine *pMachine, PRTTIMERLR phTimerLR) 116 : TeleporterState(pConsole, pVM, pProgress, false /*fIsSource*/) 116 117 , mpMachine(pMachine) 117 , mpvVMCallbackTask(NULL)118 118 , mhServer(NULL) 119 119 , mphTimerLR(phTimerLR) … … 496 496 497 497 /** 498 * Progress cancelation callback. 499 */ 500 static void teleporterProgressCancelCallback(void *pvUser) 501 { 502 TeleporterState *pState = (TeleporterState *)pvUser; 503 SSMR3Cancel(pState->mpVM); 504 if (!pState->mfIsSource) 505 { 506 TeleporterStateTrg *pStateTrg = (TeleporterStateTrg *)pState; 507 RTTcpServerShutdown(pStateTrg->mhServer); 508 } 509 } 510 511 /** 512 * @copydoc PFNVMPROGRESS 513 */ 514 static DECLCALLBACK(int) teleporterProgressCallback(PVM pVM, unsigned uPercent, void *pvUser) 515 { 516 TeleporterState *pState = (TeleporterState *)pvUser; 517 if (pState->mptrProgress) 518 { 519 HRESULT hrc = pState->mptrProgress->SetCurrentOperationProgress(uPercent); 520 if (FAILED(hrc)) 521 { 522 /* check if the failure was caused by cancellation. */ 523 BOOL fCanceled; 524 hrc = pState->mptrProgress->COMGETTER(Canceled)(&fCanceled); 525 if (SUCCEEDED(hrc) && fCanceled) 526 { 527 SSMR3Cancel(pState->mpVM); 528 return VERR_SSM_CANCELLED; 529 } 530 } 531 } 532 533 return VINF_SUCCESS; 534 } 535 536 537 /** 498 538 * @copydoc FNRTTIMERLR 499 539 */ 500 static DECLCALLBACK(void) teleporter Timeout(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick)540 static DECLCALLBACK(void) teleporterDstTimeout(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick) 501 541 { 502 542 /* This is harmless for any open connections. */ … … 573 613 574 614 void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(pState)); 575 vrc = VMR3Teleport(pState->mpVM, &g_teleporterTcpOps, pvUser, NULL/** @todo progress*/, pvUser);615 vrc = VMR3Teleport(pState->mpVM, &g_teleporterTcpOps, pvUser, teleporterProgressCallback, pvUser); 576 616 if (vrc) 577 617 return setError(E_FAIL, tr("VMR3Teleport -> %Rrc"), vrc); … … 660 700 pState->mhSocket = NIL_RTSOCKET; 661 701 } 702 703 pState->mptrProgress->setCancelCallback(NULL, NULL); 662 704 delete pState; 663 705 … … 713 755 LogFlowThisFunc(("Initiating TELEPORTER request...\n")); 714 756 715 ComObjPtr<Progress> ptr TelportationProgress;716 HRESULT hrc = ptr TelportationProgress.createObject();757 ComObjPtr<Progress> ptrProgress; 758 HRESULT hrc = ptrProgress.createObject(); 717 759 CheckComRCReturnRC(hrc); 718 hrc = ptr TelportationProgress->init(static_cast<IConsole *>(this),760 hrc = ptrProgress->init(static_cast<IConsole *>(this), 719 761 Bstr(tr("Teleporter")), 720 762 TRUE /*aCancelable*/); 721 763 CheckComRCReturnRC(hrc); 722 764 723 TeleporterStateSrc *pState = new TeleporterStateSrc(this, mpVM );765 TeleporterStateSrc *pState = new TeleporterStateSrc(this, mpVM, ptrProgress); 724 766 pState->mstrPassword = aPassword; 725 767 pState->mstrHostname = aHostname; 726 768 pState->muPort = aPort; 727 pState->mptrProgress = ptrTelportationProgress; 769 770 void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(pState)); 771 ptrProgress->setCancelCallback(teleporterProgressCancelCallback, pvUser); 728 772 729 773 int vrc = RTThreadCreate(NULL, Console::teleporterSrcThreadWrapper, (void *)pState, 0 /*cbStack*/, … … 733 777 hrc = setMachineState(MachineState_Saving); 734 778 if (SUCCEEDED(hrc)) 735 ptr TelportationProgress.queryInterfaceTo(aProgress);779 ptrProgress.queryInterfaceTo(aProgress); 736 780 else 737 ptr TelportationProgress->Cancel();781 ptrProgress->Cancel(); 738 782 } 739 783 else 740 784 { 785 ptrProgress->setCancelCallback(NULL, NULL); 741 786 delete pState; 742 787 hrc = setError(E_FAIL, tr("RTThreadCreate -> %Rrc"), vrc); … … 756 801 * @param fStartPaused Whether to start it in the Paused (true) or 757 802 * Running (false) state, 758 * @param pvVMCallbackTask The callback task pointer for 759 * stateProgressCallback(). 803 * @param pProgress Pointer to the progress object. 760 804 */ 761 805 int 762 Console::teleporterTrg(PVM pVM, IMachine *pMachine, bool fStartPaused, void *pvVMCallbackTask)806 Console::teleporterTrg(PVM pVM, IMachine *pMachine, bool fStartPaused, Progress *pProgress) 763 807 { 764 808 /* … … 818 862 */ 819 863 RTTIMERLR hTimerLR; 820 vrc = RTTimerLRCreateEx(&hTimerLR, 0 /*ns*/, RTTIMER_FLAGS_CPU_ANY, teleporter Timeout, hServer);864 vrc = RTTimerLRCreateEx(&hTimerLR, 0 /*ns*/, RTTIMER_FLAGS_CPU_ANY, teleporterDstTimeout, hServer); 821 865 if (RT_SUCCESS(vrc)) 822 866 { … … 827 871 * Do the job, when it returns we're done. 828 872 */ 829 TeleporterStateTrg State(this, pVM, p Machine, &hTimerLR);873 TeleporterStateTrg State(this, pVM, pProgress, pMachine, &hTimerLR); 830 874 State.mstrPassword = strPassword; 831 875 State.mhServer = hServer; 832 State.mpvVMCallbackTask = pvVMCallbackTask; 876 877 void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(&State)); 878 pProgress->setCancelCallback(teleporterProgressCancelCallback, pvUser); 833 879 834 880 vrc = RTTcpServerListen(hServer, Console::teleporterTrgServeConnection, &State); … … 846 892 LogRel(("Teleporter: RTTcpServerListen -> %Rrc\n", vrc)); 847 893 } 894 895 pProgress->setCancelCallback(NULL, NULL); 848 896 } 849 897 … … 954 1002 void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(pState)); 955 1003 vrc = VMR3LoadFromStream(pState->mpVM, &g_teleporterTcpOps, pvUser, 956 Console::stateProgressCallback, pState->mpvVMCallbackTask);1004 teleporterProgressCallback, pvUser); 957 1005 if (RT_FAILURE(vrc)) 958 1006 { … … 978 1026 } 979 1027 /** @todo implement config verification and hardware compatability checks. Or 980 * maybe leave part of these to the saved state machinery? */ 1028 * maybe leave part of these to the saved state machinery? 1029 * Update: We're doing as much as possible in the first SSM pass. */ 981 1030 else if (!strcmp(szCmd, "done")) 982 1031 { -
trunk/src/VBox/Main/ProgressImpl.cpp
r23662 r23810 69 69 // get creation timestamp 70 70 m_ullTimestamp = RTTimeMilliTS(); 71 72 m_pfnCancelCallback = NULL; 73 m_pvCancelUserArg = NULL; 71 74 72 75 return S_OK; … … 509 512 return resultCode; 510 513 } 514 515 /** 516 * Sets the cancellation callback. 517 * 518 * @param pfnCallback The function to be called upon cancelation. 519 * @param pvUser The callback argument. 520 */ 521 void ProgressBase::setCancelCallback(void (*pfnCallback)(void *), void *pvUser) 522 { 523 AutoCaller autoCaller(this); 524 AssertComRCReturnVoid(autoCaller.rc()); 525 526 AutoWriteLock alock(this); 527 528 m_pvCancelUserArg = pvUser; 529 m_pfnCancelCallback = pfnCallback; 530 } 531 511 532 512 533 //////////////////////////////////////////////////////////////////////////////// … … 867 888 tr("Operation cannot be canceled")); 868 889 869 mCanceled = TRUE; 890 if (!mCanceled) 891 { 892 mCanceled = TRUE; 893 if (m_pfnCancelCallback) 894 m_pfnCancelCallback(m_pvCancelUserArg); 895 896 } 870 897 return S_OK; 871 898 } … … 1566 1593 return setError (E_FAIL, tr ("Operation cannot be cancelled")); 1567 1594 1568 mCanceled = TRUE; 1595 if (!mCanceled) 1596 { 1597 mCanceled = TRUE; 1598 /** @todo Teleportation: Shouldn't this be propagated to mProgresses? If 1599 * powerUp creates passes a combined progress object to the client, I 1600 * won't get called back since I'm only getting the powerupProgress ... 1601 * Or what? */ 1602 if (m_pfnCancelCallback) 1603 m_pfnCancelCallback(m_pvCancelUserArg); 1604 1605 } 1569 1606 return S_OK; 1570 1607 } -
trunk/src/VBox/Main/include/ConsoleImpl.h
r23801 r23810 523 523 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL); 524 524 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand); 525 int teleporterTrg(PVM pVM, IMachine *pMachine, bool fStartPaused, void *pvVMCallbackTask);525 int teleporterTrg(PVM pVM, IMachine *pMachine, bool fStartPaused, Progress *pProgress); 526 526 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser); 527 527 /** @} */ -
trunk/src/VBox/Main/include/ProgressImpl.h
r23223 r23810 86 86 87 87 static HRESULT setErrorInfoOnThread (IProgress *aProgress); 88 void setCancelCallback(void (*pfnCallback)(void *), void *pvUser); 89 88 90 89 91 // unsafe inline public methods for internal purposes only (ensure there is … … 107 109 108 110 uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation 111 112 void (*m_pfnCancelCallback)(void *); 113 void *m_pvCancelUserArg; 109 114 110 115 /* The fields below are to be properly initalized by subclasses */
Note:
See TracChangeset
for help on using the changeset viewer.