Changeset 23879 in vbox
- Timestamp:
- Oct 19, 2009 5:26:44 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53659
- Location:
- trunk/src/VBox
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp
r23570 r23879 181 181 182 182 ComPtr<IProgress> progress; 183 CHECK_ERROR_BREAK(console, D iscardSnapshot(guid, progress.asOutParam()));183 CHECK_ERROR_BREAK(console, DeleteSnapshot(guid, progress.asOutParam())); 184 184 185 185 showProgress(progress); … … 200 200 if ( (a->argc != 3) 201 201 || ( strcmp(a->argv[2], "--state") 202 && strcmp(a->argv[2], "-state") 203 && strcmp(a->argv[2], "--all") 204 && strcmp(a->argv[2], "-all"))) 202 && strcmp(a->argv[2], "-state"))) 205 203 { 206 204 errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(a->argv[2]).raw()); … … 208 206 break; 209 207 } 210 bool fAll = false; 211 if ( !strcmp(a->argv[2], "--all") 212 || !strcmp(a->argv[2], "-all")) 213 fAll = true; 214 215 ComPtr<IProgress> progress; 216 217 if (fAll) 218 { 219 CHECK_ERROR_BREAK(console, DiscardCurrentSnapshotAndState(progress.asOutParam())); 220 } 221 else 222 { 223 CHECK_ERROR_BREAK(console, DiscardCurrentState(progress.asOutParam())); 224 } 225 226 showProgress(progress); 208 209 ComPtr<ISnapshot> pCurrentSnapshot; 210 CHECK_ERROR_BREAK(machine, COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam())); 211 212 ComPtr<IProgress> pProgress; 213 CHECK_ERROR_BREAK(console, RestoreSnapshot(pCurrentSnapshot, pProgress.asOutParam())); 214 215 showProgress(pProgress); 227 216 LONG iRc; 228 p rogress->COMGETTER(ResultCode)(&iRc);217 pProgress->COMGETTER(ResultCode)(&iRc); 229 218 rc = iRc; 230 219 if (FAILED(rc)) 231 220 { 232 com::ProgressErrorInfo info(p rogress);221 com::ProgressErrorInfo info(pProgress); 233 222 if (info.isBasicAvailable()) 234 RTPrintf("Error: failed to discard. Error message: %lS\n", info.getText().raw());235 else 236 RTPrintf("Error: failed to discard. No error message available!\n");223 RTPrintf("Error: failed to restore snapshot. Error message: %lS\n", info.getText().raw()); 224 else 225 RTPrintf("Error: failed to restore snapshot. No error message available!\n"); 237 226 } 238 227 -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r23825 r23879 602 602 switch (machineState) 603 603 { 604 case MachineState_Null: return "<null>"; 605 case MachineState_Running: return "Running"; 606 case MachineState_Restoring: return "Restoring"; 607 case MachineState_TeleportingFrom: return "TeleportingFrom"; 608 case MachineState_Starting: return "Starting"; 609 case MachineState_PoweredOff: return "PoweredOff"; 610 case MachineState_Saved: return "Saved"; 611 case MachineState_Aborted: return "Aborted"; 612 case MachineState_Stopping: return "Stopping"; 613 case MachineState_Paused: return "Paused"; 614 case MachineState_Stuck: return "Stuck"; 615 case MachineState_Saving: return "Saving"; 616 case MachineState_Discarding: return "Discarding"; 617 case MachineState_SettingUp: return "SettingUp"; 618 default: return "no idea"; 604 case MachineState_Null: return "<null>"; 605 case MachineState_PoweredOff: return "PoweredOff"; 606 case MachineState_Saved: return "Saved"; 607 case MachineState_Aborted: return "Aborted"; 608 case MachineState_Running: return "Running"; 609 case MachineState_Paused: return "Paused"; 610 case MachineState_Stuck: return "GuruMeditation"; 611 case MachineState_Starting: return "Starting"; 612 case MachineState_Stopping: return "Stopping"; 613 case MachineState_Saving: return "Saving"; 614 case MachineState_Restoring: return "Restoring"; 615 case MachineState_TeleportingFrom: return "TeleportingFrom"; 616 case MachineState_RestoringSnapshot: return "RestoringSnapshot"; 617 case MachineState_DeletingSnapshot: return "DeletingSnapshot"; 618 case MachineState_SettingUp: return "SettingUp"; 619 default: return "no idea"; 619 620 } 620 621 } … … 1774 1775 { 1775 1776 gProgress = NULL; 1776 CHECK_ERROR(gConsole, DiscardCurrentState(gProgress.asOutParam())); 1777 1778 ComPtr<ISnapshot> pCurrentSnapshot; 1779 CHECK_ERROR_BREAK(gMachine, COMGETTER(CurrentSnapshot)(pCurrentSnapshot.asOutParam())); 1780 1781 CHECK_ERROR(gConsole, RestoreSnapshot(pCurrentSnapshot, gProgress.asOutParam())); 1777 1782 rc = gProgress->WaitForCompletion(-1); 1778 1783 } -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxSnapshotsWgt.h
r19239 r23879 60 60 void takeSnapshot(); 61 61 void discardCurState(); 62 void discardCurSnapAndState();63 62 void showSnapshotDetails(); 64 63 … … 91 90 QAction *mTakeSnapshotAction; 92 91 QAction *mRevertToCurSnapAction; 93 QAction *mDiscardCurSnapAndStateAction;94 92 QAction *mShowSnapshotDetailsAction; 95 93 }; -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r23734 r23879 1388 1388 if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo (&dlg)) 1389 1389 { 1390 CProgress progress = console. DiscardCurrentState();1390 CProgress progress = console.RestoreSnapshot(machine.GetCurrentSnapshot()); 1391 1391 if (console.isOk()) 1392 1392 { -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r23801 r23879 2643 2643 mMachineStates [KMachineState_Restoring] = tr ("Restoring", "MachineState"); 2644 2644 mMachineStates [KMachineState_TeleportingFrom] = tr ("Teleporting From", "MachineState"); 2645 mMachineStates [KMachineState_Discarding] = tr ("Discarding", "MachineState"); 2645 mMachineStates [KMachineState_RestoringSnapshot] = tr ("Restoring Snapshot", "MachineState"); 2646 mMachineStates [KMachineState_DeletingSnapshot] = tr ("Deleting Snapshot", "MachineState"); 2646 2647 mMachineStates [KMachineState_SettingUp] = tr ("Setting Up", "MachineState"); 2647 2648 … … 4613 4614 {KMachineState_Restoring, ":/state_restoring_16px.png"}, 4614 4615 {KMachineState_TeleportingFrom, ":/state_restoring_16px.png"}, /** @todo Live Migration: New icon? (not really important) */ 4615 {KMachineState_Discarding, ":/state_discarding_16px.png"}, 4616 {KMachineState_RestoringSnapshot, ":/state_discarding_16px.png"}, 4617 {KMachineState_DeletingSnapshot, ":/state_discarding_16px.png"}, 4616 4618 {KMachineState_SettingUp, ":/settings_16px.png"}, 4617 4619 }; … … 4635 4637 mVMStateColors.insert (KMachineState_Restoring, new QColor (Qt::green)); 4636 4638 mVMStateColors.insert (KMachineState_TeleportingFrom, new QColor (Qt::green)); 4637 mVMStateColors.insert (KMachineState_Discarding, new QColor (Qt::green)); 4639 mVMStateColors.insert (KMachineState_RestoringSnapshot, new QColor (Qt::green)); 4640 mVMStateColors.insert (KMachineState_DeletingSnapshot, new QColor (Qt::green)); 4638 4641 mVMStateColors.insert (KMachineState_SettingUp, new QColor (Qt::green)); 4639 4642 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotsWgt.cpp
r22329 r23879 256 256 , mTakeSnapshotAction (new QAction (this)) 257 257 , mRevertToCurSnapAction (new QAction (mCurStateActionGroup)) 258 , mDiscardCurSnapAndStateAction (new QAction (mCurStateActionGroup))259 258 , mShowSnapshotDetailsAction (new QAction (this)) 260 259 { … … 292 291 ":/discard_cur_state_22px.png", ":/discard_cur_state_16px.png", 293 292 ":/discard_cur_state_dis_22px.png", ":/discard_cur_state_dis_16px.png")); 294 mDiscardCurSnapAndStateAction->setIcon (VBoxGlobal::iconSetFull (295 QSize (22, 22), QSize (16, 16),296 ":/discard_cur_state_snapshot_22px.png", ":/discard_cur_state_snapshot_16px.png",297 ":/discard_cur_state_snapshot_dis_22px.png", ":/discard_cur_state_snapshot_dis_16px.png"));298 293 mShowSnapshotDetailsAction->setIcon (VBoxGlobal::iconSetFull ( 299 294 QSize (22, 22), QSize (16, 16), … … 304 299 mTakeSnapshotAction->setShortcut (QString ("Ctrl+Shift+S")); 305 300 mRevertToCurSnapAction->setShortcut (QString ("Ctrl+Shift+R")); 306 mDiscardCurSnapAndStateAction->setShortcut (QString ("Ctrl+Shift+B"));307 301 mShowSnapshotDetailsAction->setShortcut (QString ("Ctrl+Space")); 308 302 … … 321 315 connect (mRevertToCurSnapAction, SIGNAL (triggered()), 322 316 this, SLOT (discardCurState())); 323 connect (mDiscardCurSnapAndStateAction, SIGNAL (triggered()),324 this, SLOT (discardCurSnapAndState()));325 317 connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), 326 318 this, SLOT (showSnapshotDetails())); … … 467 459 468 460 CConsole console = session.GetConsole(); 469 CProgress progress = console.D iscardSnapshot(snapId);461 CProgress progress = console.DeleteSnapshot(snapId); 470 462 if (console.isOk()) 471 463 { … … 552 544 553 545 CConsole console = session.GetConsole(); 554 CProgress progress = console. DiscardCurrentState();546 CProgress progress = console.RestoreSnapshot(mMachine.GetCurrentSnapshot()); 555 547 if (console.isOk()) 556 548 { … … 564 556 else 565 557 vboxProblem().cannotDiscardCurrentState (console); 566 567 session.Close();568 }569 570 void VBoxSnapshotsWgt::discardCurSnapAndState()571 {572 if (!vboxProblem().askAboutSnapshotAndStateDiscarding())573 return;574 575 SnapshotWgtItem *item = mTreeWidget->selectedItems().isEmpty() ? 0 :576 static_cast<SnapshotWgtItem*> (mTreeWidget->selectedItems() [0]);577 AssertReturn (item, (void) 0);578 579 /* Open a direct session (this call will handle all errors) */580 CSession session = vboxGlobal().openSession (mMachineId);581 if (session.isNull())582 return;583 584 CConsole console = session.GetConsole();585 CProgress progress = console.DiscardCurrentSnapshotAndState();586 if (console.isOk())587 {588 /* Show the progress dialog */589 vboxProblem().showModalProgressDialog (progress, mMachine.GetName(),590 vboxProblem().mainWindowShown());591 592 if (progress.GetResultCode() != 0)593 vboxProblem().cannotDiscardCurrentSnapshotAndState (progress);594 }595 else596 vboxProblem().cannotDiscardCurrentSnapshotAndState (console);597 558 598 559 session.Close(); … … 688 649 mTakeSnapshotAction->setText (tr ("Take &Snapshot")); 689 650 mRevertToCurSnapAction->setText (tr ("&Revert to Current Snapshot")); 690 mDiscardCurSnapAndStateAction->setText (tr ("D&iscard Current Snapshot and State"));691 651 mShowSnapshotDetailsAction->setText (tr ("S&how Details")); 692 652 … … 694 654 mTakeSnapshotAction->setStatusTip (tr ("Take a snapshot of the current virtual machine state")); 695 655 mRevertToCurSnapAction->setStatusTip (tr ("Restore the virtual machine state from the state stored in the current snapshot")); 696 mDiscardCurSnapAndStateAction->setStatusTip (tr ("Discard the current snapshot and revert the machine to the state it had before the snapshot was taken"));697 656 mShowSnapshotDetailsAction->setStatusTip (tr ("Show details of the selected snapshot")); 698 657 … … 703 662 mRevertToCurSnapAction->setToolTip (mRevertToCurSnapAction->text().remove ('&').remove ('.') + 704 663 QString (" (%1)").arg (mRevertToCurSnapAction->shortcut().toString())); 705 mDiscardCurSnapAndStateAction->setToolTip (mDiscardCurSnapAndStateAction->text().remove ('&').remove ('.') +706 QString (" (%1)").arg (mDiscardCurSnapAndStateAction->shortcut().toString()));707 664 mShowSnapshotDetailsAction->setToolTip (mShowSnapshotDetailsAction->text().remove ('&').remove ('.') + 708 665 QString (" (%1)").arg (mShowSnapshotDetailsAction->shortcut().toString())); -
trunk/src/VBox/Main/ConsoleImpl.cpp
r23841 r23879 2516 2516 } 2517 2517 2518 STDMETHODIMP Console::D iscardSnapshot(IN_BSTR aId, IProgress **aProgress)2518 STDMETHODIMP Console::DeleteSnapshot(IN_BSTR aId, IProgress **aProgress) 2519 2519 { 2520 2520 CheckComArgExpr(aId, Guid(aId).isEmpty() == false); … … 2532 2532 2533 2533 MachineState_T machineState = MachineState_Null; 2534 HRESULT rc = mControl->D iscardSnapshot(this, aId, &machineState, aProgress);2534 HRESULT rc = mControl->DeleteSnapshot(this, aId, &machineState, aProgress); 2535 2535 CheckComRCReturnRC(rc); 2536 2536 … … 2539 2539 } 2540 2540 2541 STDMETHODIMP Console:: DiscardCurrentState(IProgress **aProgress)2541 STDMETHODIMP Console::RestoreSnapshot(ISnapshot *aSnapshot, IProgress **aProgress) 2542 2542 { 2543 2543 AutoCaller autoCaller(this); … … 2548 2548 if (Global::IsOnlineOrTransient(mMachineState)) 2549 2549 return setError(VBOX_E_INVALID_VM_STATE, 2550 tr("Cannot discard the current state of the running machine (machine state: %s)"),2551 Global::stringifyMachineState(mMachineState));2550 tr("Cannot discard the current state of the running machine (machine state: %s)"), 2551 Global::stringifyMachineState(mMachineState)); 2552 2552 2553 2553 MachineState_T machineState = MachineState_Null; 2554 HRESULT rc = mControl->DiscardCurrentState(this, &machineState, aProgress); 2555 CheckComRCReturnRC(rc); 2556 2557 setMachineStateLocally(machineState); 2558 return S_OK; 2559 } 2560 2561 STDMETHODIMP Console::DiscardCurrentSnapshotAndState(IProgress **aProgress) 2562 { 2563 AutoCaller autoCaller(this); 2564 CheckComRCReturnRC(autoCaller.rc()); 2565 2566 AutoWriteLock alock(this); 2567 2568 if (Global::IsOnlineOrTransient(mMachineState)) 2569 return setError(VBOX_E_INVALID_VM_STATE, 2570 tr("Cannot discard the current snapshot and state of the running machine (machine state: %s)"), 2571 Global::stringifyMachineState(mMachineState)); 2572 2573 MachineState_T machineState = MachineState_Null; 2574 HRESULT rc = 2575 mControl->DiscardCurrentSnapshotAndState(this, &machineState, aProgress); 2554 HRESULT rc = mControl->RestoreSnapshot(this, aSnapshot, &machineState, aProgress); 2576 2555 CheckComRCReturnRC(rc); 2577 2556 … … 4031 4010 AutoWriteLock alock(this); 4032 4011 4033 AssertReturn(mMachineState == MachineState_Saving || 4034 mMachineState == MachineState_Discarding, 4035 E_FAIL); 4012 AssertReturn( mMachineState == MachineState_Saving 4013 || mMachineState == MachineState_RestoringSnapshot 4014 || mMachineState == MachineState_DeletingSnapshot, 4015 E_FAIL); 4036 4016 4037 4017 return setMachineStateLocally(aMachineState); -
trunk/src/VBox/Main/Global.cpp
r23801 r23879 186 186 switch (aState) 187 187 { 188 case MachineState_Null: return "Null"; 189 case MachineState_PoweredOff: return "PoweredOff"; 190 case MachineState_Saved: return "Saved"; 191 case MachineState_Aborted: return "Aborted"; 192 case MachineState_Running: return "Running"; 193 case MachineState_Paused: return "Paused"; 194 case MachineState_Stuck: return "GuruMeditation"; 195 case MachineState_Starting: return "Starting"; 196 case MachineState_Stopping: return "Stopping"; 197 case MachineState_Saving: return "Saving"; 198 case MachineState_Restoring: return "Restoring"; 199 case MachineState_TeleportingFrom: return "TeleportingFrom"; 200 case MachineState_Discarding: return "Discarding"; 201 case MachineState_SettingUp: return "SettingUp"; 188 case MachineState_Null: return "Null"; 189 case MachineState_PoweredOff: return "PoweredOff"; 190 case MachineState_Saved: return "Saved"; 191 case MachineState_Aborted: return "Aborted"; 192 case MachineState_Running: return "Running"; 193 case MachineState_Paused: return "Paused"; 194 case MachineState_Stuck: return "GuruMeditation"; 195 case MachineState_Starting: return "Starting"; 196 case MachineState_Stopping: return "Stopping"; 197 case MachineState_Saving: return "Saving"; 198 case MachineState_Restoring: return "Restoring"; 199 case MachineState_TeleportingFrom: return "TeleportingFrom"; 200 case MachineState_RestoringSnapshot: return "RestoringSnapshot"; 201 case MachineState_DeletingSnapshot: return "DeletingSnapshot"; 202 case MachineState_SettingUp: return "SettingUp"; 202 203 default: 203 204 { -
trunk/src/VBox/Main/MachineImpl.cpp
r23801 r23879 6528 6528 6529 6529 /* must be in a protective state because we leave the lock below */ 6530 AssertReturn( mData->mMachineState == MachineState_Saving 6531 || mData->mMachineState == MachineState_Discarding, E_FAIL); 6530 AssertReturn( mData->mMachineState == MachineState_Saving 6531 || mData->mMachineState == MachineState_RestoringSnapshot 6532 || mData->mMachineState == MachineState_DeletingSnapshot, 6533 E_FAIL); 6532 6534 6533 6535 HRESULT rc = S_OK; … … 6744 6746 * protected) */ 6745 6747 MachineState_T oldState = mData->mMachineState; 6746 if (oldState != MachineState_Saving && 6747 oldState != MachineState_Discarding) 6748 { 6748 if ( oldState != MachineState_Saving 6749 && oldState != MachineState_RestoringSnapshot 6750 && oldState != MachineState_DeletingSnapshot 6751 ) 6749 6752 setMachineState (MachineState_SettingUp); 6750 }6751 6753 6752 6754 alock.leave(); … … 7573 7575 7574 7576 /** Discard snapshot task */ 7575 struct SessionMachine::D iscardSnapshotTask7577 struct SessionMachine::DeleteSnapshotTask 7576 7578 : public SessionMachine::Task 7577 7579 { 7578 D iscardSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s)7579 : Task 7580 snapshot 7580 DeleteSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s) 7581 : Task(m, p), 7582 snapshot(s) 7581 7583 {} 7582 7584 7583 D iscardSnapshotTask (const Task &task, Snapshot *s)7584 : Task 7585 , snapshot 7585 DeleteSnapshotTask (const Task &task, Snapshot *s) 7586 : Task(task) 7587 , snapshot(s) 7586 7588 {} 7587 7589 … … 7594 7596 }; 7595 7597 7596 /** Discard current state task */7597 struct SessionMachine:: DiscardCurrentStateTask7598 /** Restore snapshot state task */ 7599 struct SessionMachine::RestoreSnapshotTask 7598 7600 : public SessionMachine::Task 7599 7601 { 7600 DiscardCurrentStateTask(SessionMachine *m, Progress *p, bool discardCurSnapshot)7602 RestoreSnapshotTask(SessionMachine *m, Progress *p, bool discardCurSnapshot) 7601 7603 : Task(m, p), 7602 7604 discardCurrentSnapshot(discardCurSnapshot) … … 7605 7607 void handler() 7606 7608 { 7607 machine-> discardCurrentStateHandler(*this);7609 machine->restoreSnapshotHandler(*this); 7608 7610 } 7609 7611 … … 8605 8607 * @note Locks mParent + this + children objects for writing! 8606 8608 */ 8607 STDMETHODIMP SessionMachine::D iscardSnapshot(IConsole *aInitiator,8608 8609 8610 8609 STDMETHODIMP SessionMachine::DeleteSnapshot(IConsole *aInitiator, 8610 IN_BSTR aId, 8611 MachineState_T *aMachineState, 8612 IProgress **aProgress) 8611 8613 { 8612 8614 LogFlowThisFunc(("\n")); … … 8648 8650 { 8649 8651 rc = saveSettings(); 8650 CheckComRCReturnRC 8652 CheckComRCReturnRC(rc); 8651 8653 } 8652 8654 } … … 8657 8659 ComObjPtr<Progress> progress; 8658 8660 progress.createObject(); 8659 rc = progress->init 8660 Bstr(Utf8StrFmt(tr("Discarding snapshot '%s'"),8661 snapshot->getName().c_str())),8662 8663 8664 8665 8666 AssertComRCReturn 8661 rc = progress->init(mParent, aInitiator, 8662 BstrFmt(tr("Discarding snapshot '%s'"), 8663 snapshot->getName().c_str()), 8664 FALSE /* aCancelable */, 8665 1 + (ULONG)snapshot->getSnapshotMachine()->mMediaData->mAttachments.size() + 8666 (snapshot->stateFilePath().isNull() ? 0 : 1), 8667 Bstr (tr ("Preparing to discard snapshot"))); 8668 AssertComRCReturn(rc, rc); 8667 8669 8668 8670 /* create and start the task on a separate thread */ 8669 DiscardSnapshotTask *task = new DiscardSnapshotTask (this, progress, snapshot); 8670 int vrc = RTThreadCreate (NULL, taskHandler, 8671 (void *) task, 8672 0, RTTHREADTYPE_MAIN_WORKER, 0, "DiscardSnapshot"); 8671 DeleteSnapshotTask *task = new DeleteSnapshotTask(this, progress, snapshot); 8672 int vrc = RTThreadCreate(NULL, 8673 taskHandler, 8674 (void*)task, 8675 0, 8676 RTTHREADTYPE_MAIN_WORKER, 8677 0, 8678 "DeleteSnapshot"); 8673 8679 if (RT_FAILURE(vrc)) 8674 8680 delete task; … … 8676 8682 8677 8683 /* set the proper machine state (note: after creating a Task instance) */ 8678 setMachineState(MachineState_D iscarding);8684 setMachineState(MachineState_DeletingSnapshot); 8679 8685 8680 8686 /* return the progress to the caller */ … … 8690 8696 * @note Locks this + children objects for writing! 8691 8697 */ 8692 STDMETHODIMP SessionMachine::DiscardCurrentState ( 8693 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress) 8698 STDMETHODIMP SessionMachine::RestoreSnapshot(IConsole *aInitiator, 8699 ISnapshot *aSnapshot, 8700 MachineState_T *aMachineState, 8701 IProgress **aProgress) 8694 8702 { 8695 8703 LogFlowThisFunc(("\n")); … … 8703 8711 AutoWriteLock alock(this); 8704 8712 8705 ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 8713 ComAssertRet(!Global::IsOnlineOrTransient(mData->mMachineState), 8714 E_FAIL); 8706 8715 8707 8716 if (mData->mCurrentSnapshot.isNull()) … … 8726 8735 /* create and start the task on a separate thread (note that it will not 8727 8736 * start working until we release alock) */ 8728 DiscardCurrentStateTask *task = 8729 new DiscardCurrentStateTask (this, progress, false /* discardCurSnapshot */); 8730 int vrc = RTThreadCreate (NULL, taskHandler, 8731 (void *) task, 8732 0, RTTHREADTYPE_MAIN_WORKER, 0, "DiscardCurState"); 8733 if (RT_FAILURE(vrc)) 8734 { 8735 delete task; 8736 ComAssertRCRet (vrc, E_FAIL); 8737 } 8738 8739 /* set the proper machine state (note: after creating a Task instance) */ 8740 setMachineState (MachineState_Discarding); 8741 8742 /* return the progress to the caller */ 8743 progress.queryInterfaceTo(aProgress); 8744 8745 /* return the new state to the caller */ 8746 *aMachineState = mData->mMachineState; 8747 8748 return S_OK; 8749 } 8750 8751 /** 8752 * @note Locks thos object for writing! 8753 */ 8754 STDMETHODIMP SessionMachine::DiscardCurrentSnapshotAndState(IConsole *aInitiator, 8755 MachineState_T *aMachineState, 8756 IProgress **aProgress) 8757 { 8758 LogFlowThisFunc(("\n")); 8759 8760 AssertReturn(aInitiator, E_INVALIDARG); 8761 AssertReturn(aMachineState && aProgress, E_POINTER); 8762 8763 AutoCaller autoCaller(this); 8764 AssertComRCReturn (autoCaller.rc(), autoCaller.rc()); 8765 8766 AutoWriteLock alock(this); 8767 8768 ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 8769 8770 if (mData->mCurrentSnapshot.isNull()) 8771 return setError(VBOX_E_INVALID_OBJECT_STATE, 8772 tr("Could not discard the current state of the machine '%ls' " 8773 "because it doesn't have any snapshots"), 8774 mUserData->mName.raw()); 8775 8776 /* create a progress object. The number of operations is: 8777 * 1 (preparing) + # of hard disks in the current snapshot + 8778 * # of hard disks in the previous snapshot + 8779 * 1 if we need to copy the saved state file of the previous snapshot + 8780 * 1 if the current snapshot is online 8781 * or (if there is no previous snapshot): 8782 * 1 (preparing) + # of hard disks in the current snapshot * 2 + 8783 * 1 if we need to copy the saved state file of the current snapshot * 2 8784 */ 8785 ComObjPtr<Progress> progress; 8786 progress.createObject(); 8787 { 8788 ComObjPtr<Snapshot> curSnapshot = mData->mCurrentSnapshot; 8789 ComObjPtr<Snapshot> prevSnapshot = mData->mCurrentSnapshot->parent(); 8790 8791 ULONG opCount = 1; 8792 if (prevSnapshot) 8793 { 8794 opCount += (ULONG)curSnapshot->getSnapshotMachine()->mMediaData->mAttachments.size(); 8795 opCount += (ULONG)prevSnapshot->getSnapshotMachine()->mMediaData->mAttachments.size(); 8796 if (prevSnapshot->stateFilePath()) 8797 ++opCount; 8798 if (curSnapshot->stateFilePath()) 8799 ++opCount; 8800 } 8801 else 8802 { 8803 opCount += 8804 (ULONG)curSnapshot->getSnapshotMachine()->mMediaData->mAttachments.size() * 2; 8805 if (curSnapshot->stateFilePath()) 8806 opCount += 2; 8807 } 8808 8809 progress->init(mParent, aInitiator, 8810 Bstr (tr ("Discarding current machine snapshot and state")), 8811 FALSE /* aCancelable */, opCount, 8812 Bstr (tr ("Preparing to discard current snapshot and state"))); 8813 } 8814 8815 /* create and start the task on a separate thread */ 8816 DiscardCurrentStateTask *task = 8817 new DiscardCurrentStateTask (this, progress, true /* discardCurSnapshot */); 8818 int vrc = RTThreadCreate(NULL, taskHandler, 8819 (void *) task, 8820 0, RTTHREADTYPE_MAIN_WORKER, 0, "DiscardCurStSnp"); 8737 RestoreSnapshotTask *task = new RestoreSnapshotTask(this, progress, false /* discardCurSnapshot */); 8738 int vrc = RTThreadCreate(NULL, 8739 taskHandler, 8740 (void*)task, 8741 0, 8742 RTTHREADTYPE_MAIN_WORKER, 8743 0, 8744 "DiscardCurState"); 8821 8745 if (RT_FAILURE(vrc)) 8822 8746 { … … 8826 8750 8827 8751 /* set the proper machine state (note: after creating a Task instance) */ 8828 setMachineState(MachineState_ Discarding);8752 setMachineState(MachineState_RestoringSnapshot); 8829 8753 8830 8754 /* return the progress to the caller */ … … 9558 9482 /** 9559 9483 * Discard snapshot task handler. Must be called only by 9560 * D iscardSnapshotTask::handler()!9484 * DeleteSnapshotTask::handler()! 9561 9485 * 9562 9486 * When aTask.subTask is true, the associated progress object is left … … 9566 9490 * @note Locks mParent + this + child objects for writing! 9567 9491 */ 9568 void SessionMachine::discardSnapshotHandler(D iscardSnapshotTask &aTask)9492 void SessionMachine::discardSnapshotHandler(DeleteSnapshotTask &aTask) 9569 9493 { 9570 9494 LogFlowThisFuncEnter(); … … 9843 9767 9844 9768 /** 9845 * Discard current state task handler. Must be called only by9846 * DiscardCurrentStateTask::handler()!9769 * Restore snapshot state task handler. Must be called only by 9770 * RestoreSnapshotTask::handler()! 9847 9771 * 9848 9772 * @note Locks mParent + this object for writing. 9849 9773 */ 9850 void SessionMachine:: discardCurrentStateHandler (DiscardCurrentStateTask &aTask)9774 void SessionMachine::restoreSnapshotHandler(RestoreSnapshotTask &aTask) 9851 9775 { 9852 9776 LogFlowThisFuncEnter(); … … 9859 9783 /* we might have been uninitialized because the session was accidentally 9860 9784 * closed by the client, so don't assert */ 9861 aTask.progress->notifyComplete ( 9862 E_FAIL, COM_IIDOF (IMachine), getComponentName(), 9863 tr ("The session has been accidentally closed")); 9785 aTask.progress->notifyComplete(E_FAIL, 9786 COM_IIDOF(IMachine), 9787 getComponentName(), 9788 tr("The session has been accidentally closed")); 9864 9789 9865 9790 LogFlowThisFuncLeave(); … … 9881 9806 * session) */ 9882 9807 if (isModified()) 9883 rollback 9808 rollback(false /* aNotify */); 9884 9809 9885 9810 HRESULT rc = S_OK; … … 9910 9835 * snapshot first */ 9911 9836 9912 D iscardSnapshotTask subTask (aTask, mData->mCurrentSnapshot);9837 DeleteSnapshotTask subTask (aTask, mData->mCurrentSnapshot); 9913 9838 subTask.subTask = true; 9914 9839 discardSnapshotHandler (subTask); … … 10059 9984 * after discarding the current state. */ 10060 9985 10061 D iscardSnapshotTask subTask (aTask, mData->mCurrentSnapshot);9986 DeleteSnapshotTask subTask (aTask, mData->mCurrentSnapshot); 10062 9987 subTask.subTask = true; 10063 9988 discardSnapshotHandler (subTask); … … 10395 10320 } 10396 10321 else if ( oldMachineState >= MachineState_Running 10397 && oldMachineState != MachineState_Discarding 10322 && oldMachineState != MachineState_RestoringSnapshot 10323 && oldMachineState != MachineState_DeletingSnapshot 10398 10324 && oldMachineState != MachineState_SettingUp 10399 10325 && aMachineState < MachineState_Running -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r23823 r23879 574 574 +-> PoweredOff --+ 575 575 | | 576 | Aborted -----+-->[ discardSnapshot() ]-------------> Discarding --+577 | | [d iscardCurrentState()] |578 +-> Saved -------+ [discardCurrentSnapshotAndState()]|576 | Aborted -----+-->[restoreSnapshot() ]-------> RestoringSnapshot -+ 577 | | [deleteSnapshot() ]-------> DeletingSnapshot --+ 578 +-> Saved -------+ | 579 579 | | 580 580 +---(Saved if restored from an online snapshot, PoweredOff otherwise)---+ … … 678 678 </desc> 679 679 </const> 680 <const name="Discarding" value="12"> 681 <desc> 682 Snapshot of the machine is being discarded. 683 </desc> 684 </const> 685 <const name="SettingUp" value="13"> 680 <const name="RestoringSnapshot" value="12"> 681 <desc> 682 A machine snapshot is being restored; this typically does not take long. 683 </desc> 684 </const> 685 <const name="DeletingSnapshot" value="13"> 686 <desc> 687 A machine snapshot is being deleted; this can take a long time since this 688 may require merging differencing hard disk images. 689 </desc> 690 </const> 691 <const name="SettingUp" value="14"> 686 692 <desc> 687 693 Lengthy setup operation is in progress. … … 705 711 </desc> 706 712 </const> 707 <const name="LastTransient" value="1 3" wsmap="suppress"> <!-- SettingUp -->713 <const name="LastTransient" value="14" wsmap="suppress"> <!-- SettingUp --> 708 714 <desc> 709 715 Pseudo-state: last transient state (for use in relational expressions). … … 3631 3637 <interface 3632 3638 name="IInternalMachineControl" extends="$unknown" 3633 uuid=" 6c08103e-b8e6-44fb-bc6c-36067153d4bd"3639 uuid="4e2b8f0f-6575-49d2-bb19-5cd15a6ca2f0" 3634 3640 internal="yes" 3635 3641 wsmap="suppress" … … 3854 3860 </method> 3855 3861 3856 <method name="d iscardSnapshot">3857 <desc> 3858 Gets called by IConsole::d iscardSnapshot.3862 <method name="deleteSnapshot"> 3863 <desc> 3864 Gets called by IConsole::deleteSnapshot. 3859 3865 <result name="VBOX_E_INVALID_OBJECT_STATE"> 3860 3866 Snapshot has more than one child snapshot. … … 3875 3881 </method> 3876 3882 3877 <method name="discardCurrentState"> 3878 <desc> 3879 Gets called by IConsole::discardCurrentState. 3880 <result name="VBOX_E_INVALID_OBJECT_STATE"> 3881 Virtual machine does not have any snapshot. 3882 </result> 3883 <method name="restoreSnapshot"> 3884 <desc> 3885 Gets called by IConsole::RestoreSnapshot. 3883 3886 </desc> 3884 3887 <param name="initiator" type="IConsole" dir="in"> 3885 3888 <desc>The console object that initiated this call.</desc> 3886 3889 </param> 3887 <param name="machineState" type="MachineState" dir="out"> 3888 <desc>New machine state after this operation is started.</desc> 3889 </param> 3890 <param name="progress" type="IProgress" dir="return"> 3891 <desc>Progress object to track the operation completion.</desc> 3892 </param> 3893 </method> 3894 3895 <method name="discardCurrentSnapshotAndState"> 3896 <desc> 3897 Gets called by IConsole::discardCurrentSnapshotAndState. 3898 <result name="VBOX_E_INVALID_OBJECT_STATE"> 3899 Virtual machine does not have any snapshot. 3900 </result> 3901 </desc> 3902 <param name="initiator" type="IConsole" dir="in"> 3903 <desc>The console object that initiated this call.</desc> 3890 <param name="snapshot" type="ISnapshot" dir="in"> 3891 <desc>The snapshot to restore the VM state from.</desc> 3904 3892 </param> 3905 3893 <param name="machineState" type="MachineState" dir="out"> … … 4454 4442 <desc> 4455 4443 Current snapshot of this machine. This is @c null if the machine 4456 currently has no snapshots. Otherwise, this is always the last snapshot 4457 in the current implementation; see <link to="ISnapshot"/> for details. 4444 currently has no snapshots. If it is not @c null, then it was 4445 set by one of <link to="Console::takeSnapshot" />, 4446 <link to="Console::deleteSnapshot" /> 4447 or <link to="Console::restoreSnapshot" />, depending on which 4448 was called last. See <link to="ISnapshot"/> for details. 4458 4449 </desc> 4459 4450 </attribute> … … 4471 4462 identical to the state stored in the current snapshot. 4472 4463 4473 The current state is identical to the current snapshot right 4474 after one of the following calls are made: 4464 The current state is identical to the current snapshot only 4465 directly after one of the following calls are made: 4466 4475 4467 <ul> 4476 <li><link to="IConsole::discardCurrentState"/> or 4477 <link to="IConsole::discardCurrentSnapshotAndState"/> 4468 <li><link to="IConsole::restoreSnapshot"/> 4478 4469 </li> 4479 4470 <li><link to="IConsole::takeSnapshot"/> (issued on a 4480 powered off or savedmachine, for which4471 "powered off" or "saved" machine, for which 4481 4472 <link to="#settingsModified"/> returns @c false) 4482 4473 </li> … … 6088 6079 <interface 6089 6080 name="IConsole" extends="$unknown" 6090 uuid=" 03312360-0364-4b7a-ad71-1a8450133774"6081 uuid="55dd56a5-1d1d-4d81-b742-b082b9571be6" 6091 6082 wsmap="managed" 6092 6083 > … … 6642 6633 </method> 6643 6634 6644 <method name="d iscardSnapshot">6635 <method name="deleteSnapshot"> 6645 6636 <desc> 6646 6637 Starts discarding the specified snapshot asynchronously. … … 6738 6729 </method> 6739 6730 6740 <method name=" discardCurrentState">6731 <method name="restoreSnapshot"> 6741 6732 <desc> 6742 6733 Starts resetting the machine's current state to the state contained 6743 in the currentsnapshot, asynchronously. All current settings of the6734 in the given snapshot, asynchronously. All current settings of the 6744 6735 machine will be reset and changes stored in differencing media 6745 6736 will be lost. … … 6749 6740 media are created for all normal media of the machine. 6750 6741 6751 If the current snapshot of the machine is an online snapshot, the6752 machine will go to the <link to="MachineState_Saved"> saved6753 state</link>, so that the next time it is powered on, the execution6754 state will be restored from the currentsnapshot.6742 If the given snapshot is an online snapshot, the machine will go to 6743 the <link to="MachineState_Saved"> saved state</link>, so that the 6744 next time it is powered on, the execution state will be restored 6745 from the state of the snapshot. 6755 6746 6756 6747 <note> … … 6769 6760 </result> 6770 6761 </desc> 6771 <param name="progress" type="IProgress" dir="return"> 6772 <desc>Progress object to track the operation completion.</desc> 6773 </param> 6774 </method> 6775 6776 <method name="discardCurrentSnapshotAndState"> 6777 <desc> 6778 6779 This method is equivalent to 6780 doing <link to="IConsole::discardSnapshot">discardSnapshot</link> 6781 (currentSnapshot.id(), progress) followed by 6782 <link to="IConsole::discardCurrentState"/>. 6783 6784 As a result, the machine will be fully restored from the 6785 snapshot preceding the current snapshot, while both the current 6786 snapshot and the current machine state will be discarded. 6787 6788 If the current snapshot is the first snapshot of the machine (i.e. it 6789 has the only snapshot), the current machine state will be 6790 discarded <b>before</b> discarding the snapshot. In other words, the 6791 machine will be restored from its last snapshot, before discarding 6792 it. This differs from performing a single 6793 <link to="IConsole::discardSnapshot"/> call (note that no 6794 <link to="IConsole::discardCurrentState"/> will be possible after it) 6795 to the effect that the latter will preserve the current state instead of 6796 discarding it. 6797 6798 Unless explicitly mentioned otherwise, all remarks and 6799 limitations of the above two methods also apply to this method. 6800 6801 <note> 6802 The machine must not be running, otherwise the operation 6803 will fail. 6804 </note> 6805 6806 <note> 6807 If the machine state is <link to="MachineState_Saved">Saved</link> 6808 prior to this operation, the saved state file will be implicitly 6809 discarded (as if <link to="#forgetSavedState"/> were 6810 called). 6811 </note> 6812 6813 <note> 6814 This method is more efficient than calling both of the above 6815 methods separately: it requires less IPC calls and provides 6816 a single progress object. 6817 </note> 6818 6819 <result name="VBOX_E_INVALID_VM_STATE"> 6820 Virtual machine is running. 6821 </result> 6822 </desc> 6762 <param name="snapshot" type="ISnapshot" dir="in"> 6763 <desc>The snapshot to restore the VM state from.</desc> 6764 </param> 6823 6765 <param name="progress" type="IProgress" dir="return"> 6824 6766 <desc>Progress object to track the operation completion.</desc> … … 8174 8116 </li> 8175 8117 8176 <li><link to="IConsole:: discardCurrentState"/>: this goes back to8118 <li><link to="IConsole::restoreSnapshot"/>: this goes back to 8177 8119 a previous snapshot. This resets the machine's state to that of 8178 8120 the previous snapshot by deleting the differencing image of each … … 8183 8125 </li> 8184 8126 8185 <li><link to="IConsole::d iscardSnapshot"/>: deletes a snapshot8127 <li><link to="IConsole::deleteSnapshot"/>: deletes a snapshot 8186 8128 without affecting the current machine state. 8187 8129 … … 8194 8136 by this operation, except that parent disk images will be modified 8195 8137 to contain the disk data associated with the snapshot being deleted. 8196 </li>8197 8198 <li><link to="IConsole::discardCurrentSnapshotAndState"/>:8199 this completely reverts the virtual machine to the state it was in8200 before the current snapshot has been taken. Effectively, this goes8201 back to the state before the current snapshot, which might be8202 an earlier snapshot.8203 8204 The current state, as well as the current snapshot, are lost.8205 8138 </li> 8206 8139 </ul> -
trunk/src/VBox/Main/include/ConsoleImpl.h
r23827 r23879 145 145 STDMETHOD(TakeSnapshot) (IN_BSTR aName, IN_BSTR aDescription, 146 146 IProgress **aProgress); 147 STDMETHOD(DiscardSnapshot) (IN_BSTR aId, IProgress **aProgress); 148 STDMETHOD(DiscardCurrentState) (IProgress **aProgress); 149 STDMETHOD(DiscardCurrentSnapshotAndState) (IProgress **aProgress); 147 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress); 148 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress); 150 149 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, IProgress **aProgress); 151 150 STDMETHOD(RegisterCallback) (IConsoleCallback *aCallback); -
trunk/src/VBox/Main/include/MachineImpl.h
r23801 r23879 968 968 BSTR *aStateFilePath); 969 969 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess); 970 STDMETHOD(D iscardSnapshot)(IConsole *aInitiator, IN_BSTR aId,971 972 STDMETHOD( DiscardCurrentState)(IConsole *aInitiator, MachineState_T *aMachineState,973 IProgress **aProgress);974 STDMETHOD(DiscardCurrentSnapshotAndState)(IConsole *aInitiator,MachineState_T *aMachineState,975 970 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId, 971 MachineState_T *aMachineState, IProgress **aProgress); 972 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator, 973 ISnapshot *aSnapshot, 974 MachineState_T *aMachineState, 975 IProgress **aProgress); 976 976 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), 977 977 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags)); … … 1024 1024 1025 1025 struct Task; 1026 struct D iscardSnapshotTask;1027 struct DiscardCurrentStateTask;1028 1029 friend struct D iscardSnapshotTask;1030 friend struct DiscardCurrentStateTask;1026 struct DeleteSnapshotTask; 1027 struct RestoreSnapshotTask; 1028 1029 friend struct DeleteSnapshotTask; 1030 friend struct RestoreSnapshotTask; 1031 1031 1032 1032 void uninit(Uninit::Reason aReason); … … 1037 1037 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines; 1038 1038 1039 void discardSnapshotHandler(D iscardSnapshotTask &aTask);1040 void discardCurrentStateHandler(DiscardCurrentStateTask &aTask);1039 void discardSnapshotHandler(DeleteSnapshotTask &aTask); 1040 void restoreSnapshotHandler(RestoreSnapshotTask &aTask); 1041 1041 1042 1042 HRESULT lockMedia();
Note:
See TracChangeset
for help on using the changeset viewer.