VirtualBox

Changeset 23879 in vbox


Ignore:
Timestamp:
Oct 19, 2009 5:26:44 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53659
Message:

Main: rename snapshot APIs, remove DiscardCurrentSnapshotAndState; tree snapshots implementation still missing

Location:
trunk/src/VBox
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp

    r23570 r23879  
    181181
    182182            ComPtr<IProgress> progress;
    183             CHECK_ERROR_BREAK(console, DiscardSnapshot(guid, progress.asOutParam()));
     183            CHECK_ERROR_BREAK(console, DeleteSnapshot(guid, progress.asOutParam()));
    184184
    185185            showProgress(progress);
     
    200200            if (   (a->argc != 3)
    201201                || (   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")))
    205203            {
    206204                errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(a->argv[2]).raw());
     
    208206                break;
    209207            }
    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);
    227216            LONG iRc;
    228             progress->COMGETTER(ResultCode)(&iRc);
     217            pProgress->COMGETTER(ResultCode)(&iRc);
    229218            rc = iRc;
    230219            if (FAILED(rc))
    231220            {
    232                 com::ProgressErrorInfo info(progress);
     221                com::ProgressErrorInfo info(pProgress);
    233222                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");
    237226            }
    238227
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r23825 r23879  
    602602        switch (machineState)
    603603        {
    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";
    619620        }
    620621    }
     
    17741775        {
    17751776            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()));
    17771782            rc = gProgress->WaitForCompletion(-1);
    17781783        }
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxSnapshotsWgt.h

    r19239 r23879  
    6060    void takeSnapshot();
    6161    void discardCurState();
    62     void discardCurSnapAndState();
    6362    void showSnapshotDetails();
    6463
     
    9190    QAction         *mTakeSnapshotAction;
    9291    QAction         *mRevertToCurSnapAction;
    93     QAction         *mDiscardCurSnapAndStateAction;
    9492    QAction         *mShowSnapshotDetailsAction;
    9593};
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r23734 r23879  
    13881388                        if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo (&dlg))
    13891389                        {
    1390                             CProgress progress = console.DiscardCurrentState();
     1390                            CProgress progress = console.RestoreSnapshot(machine.GetCurrentSnapshot());
    13911391                            if (console.isOk())
    13921392                            {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r23801 r23879  
    26432643    mMachineStates [KMachineState_Restoring] =  tr ("Restoring", "MachineState");
    26442644    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");
    26462647    mMachineStates [KMachineState_SettingUp] =  tr ("Setting Up", "MachineState");
    26472648
     
    46134614        {KMachineState_Restoring, ":/state_restoring_16px.png"},
    46144615        {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"},
    46164618        {KMachineState_SettingUp, ":/settings_16px.png"},
    46174619    };
     
    46354637    mVMStateColors.insert (KMachineState_Restoring,     new QColor (Qt::green));
    46364638    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));
    46384641    mVMStateColors.insert (KMachineState_SettingUp,     new QColor (Qt::green));
    46394642
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotsWgt.cpp

    r22329 r23879  
    256256    , mTakeSnapshotAction (new QAction (this))
    257257    , mRevertToCurSnapAction (new QAction (mCurStateActionGroup))
    258     , mDiscardCurSnapAndStateAction (new QAction (mCurStateActionGroup))
    259258    , mShowSnapshotDetailsAction (new QAction (this))
    260259{
     
    292291        ":/discard_cur_state_22px.png", ":/discard_cur_state_16px.png",
    293292        ":/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"));
    298293    mShowSnapshotDetailsAction->setIcon (VBoxGlobal::iconSetFull (
    299294        QSize (22, 22), QSize (16, 16),
     
    304299    mTakeSnapshotAction->setShortcut (QString ("Ctrl+Shift+S"));
    305300    mRevertToCurSnapAction->setShortcut (QString ("Ctrl+Shift+R"));
    306     mDiscardCurSnapAndStateAction->setShortcut (QString ("Ctrl+Shift+B"));
    307301    mShowSnapshotDetailsAction->setShortcut (QString ("Ctrl+Space"));
    308302
     
    321315    connect (mRevertToCurSnapAction, SIGNAL (triggered()),
    322316             this, SLOT (discardCurState()));
    323     connect (mDiscardCurSnapAndStateAction, SIGNAL (triggered()),
    324              this, SLOT (discardCurSnapAndState()));
    325317    connect (mShowSnapshotDetailsAction, SIGNAL (triggered()),
    326318             this, SLOT (showSnapshotDetails()));
     
    467459
    468460    CConsole console = session.GetConsole();
    469     CProgress progress = console.DiscardSnapshot (snapId);
     461    CProgress progress = console.DeleteSnapshot(snapId);
    470462    if (console.isOk())
    471463    {
     
    552544
    553545    CConsole console = session.GetConsole();
    554     CProgress progress = console.DiscardCurrentState();
     546    CProgress progress = console.RestoreSnapshot(mMachine.GetCurrentSnapshot());
    555547    if (console.isOk())
    556548    {
     
    564556    else
    565557        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     else
    596         vboxProblem().cannotDiscardCurrentSnapshotAndState (console);
    597558
    598559    session.Close();
     
    688649    mTakeSnapshotAction->setText (tr ("Take &Snapshot"));
    689650    mRevertToCurSnapAction->setText (tr ("&Revert to Current Snapshot"));
    690     mDiscardCurSnapAndStateAction->setText (tr ("D&iscard Current Snapshot and State"));
    691651    mShowSnapshotDetailsAction->setText (tr ("S&how Details"));
    692652
     
    694654    mTakeSnapshotAction->setStatusTip (tr ("Take a snapshot of the current virtual machine state"));
    695655    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"));
    697656    mShowSnapshotDetailsAction->setStatusTip (tr ("Show details of the selected snapshot"));
    698657
     
    703662    mRevertToCurSnapAction->setToolTip (mRevertToCurSnapAction->text().remove ('&').remove ('.') +
    704663        QString (" (%1)").arg (mRevertToCurSnapAction->shortcut().toString()));
    705     mDiscardCurSnapAndStateAction->setToolTip (mDiscardCurSnapAndStateAction->text().remove ('&').remove ('.') +
    706         QString (" (%1)").arg (mDiscardCurSnapAndStateAction->shortcut().toString()));
    707664    mShowSnapshotDetailsAction->setToolTip (mShowSnapshotDetailsAction->text().remove ('&').remove ('.') +
    708665        QString (" (%1)").arg (mShowSnapshotDetailsAction->shortcut().toString()));
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r23841 r23879  
    25162516}
    25172517
    2518 STDMETHODIMP Console::DiscardSnapshot(IN_BSTR aId, IProgress **aProgress)
     2518STDMETHODIMP Console::DeleteSnapshot(IN_BSTR aId, IProgress **aProgress)
    25192519{
    25202520    CheckComArgExpr(aId, Guid(aId).isEmpty() == false);
     
    25322532
    25332533    MachineState_T machineState = MachineState_Null;
    2534     HRESULT rc = mControl->DiscardSnapshot(this, aId, &machineState, aProgress);
     2534    HRESULT rc = mControl->DeleteSnapshot(this, aId, &machineState, aProgress);
    25352535    CheckComRCReturnRC(rc);
    25362536
     
    25392539}
    25402540
    2541 STDMETHODIMP Console::DiscardCurrentState(IProgress **aProgress)
     2541STDMETHODIMP Console::RestoreSnapshot(ISnapshot *aSnapshot, IProgress **aProgress)
    25422542{
    25432543    AutoCaller autoCaller(this);
     
    25482548    if (Global::IsOnlineOrTransient(mMachineState))
    25492549        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));
    25522552
    25532553    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);
    25762555    CheckComRCReturnRC(rc);
    25772556
     
    40314010    AutoWriteLock alock(this);
    40324011
    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);
    40364016
    40374017    return setMachineStateLocally(aMachineState);
  • trunk/src/VBox/Main/Global.cpp

    r23801 r23879  
    186186    switch (aState)
    187187    {
    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";
    202203        default:
    203204        {
  • trunk/src/VBox/Main/MachineImpl.cpp

    r23801 r23879  
    65286528
    65296529    /* 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);
    65326534
    65336535    HRESULT rc = S_OK;
     
    67446746         * protected) */
    67456747        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           )
    67496752            setMachineState (MachineState_SettingUp);
    6750         }
    67516753
    67526754        alock.leave();
     
    75737575
    75747576/** Discard snapshot task */
    7575 struct SessionMachine::DiscardSnapshotTask
     7577struct SessionMachine::DeleteSnapshotTask
    75767578    : public SessionMachine::Task
    75777579{
    7578     DiscardSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s)
    7579         : Task (m, p),
    7580           snapshot (s)
     7580    DeleteSnapshotTask(SessionMachine *m, Progress *p, Snapshot *s)
     7581        : Task(m, p),
     7582          snapshot(s)
    75817583    {}
    75827584
    7583     DiscardSnapshotTask (const Task &task, Snapshot *s)
    7584         : Task (task)
    7585         , snapshot (s)
     7585    DeleteSnapshotTask (const Task &task, Snapshot *s)
     7586        : Task(task)
     7587        , snapshot(s)
    75867588    {}
    75877589
     
    75947596};
    75957597
    7596 /** Discard current state task */
    7597 struct SessionMachine::DiscardCurrentStateTask
     7598/** Restore snapshot state task */
     7599struct SessionMachine::RestoreSnapshotTask
    75987600    : public SessionMachine::Task
    75997601{
    7600     DiscardCurrentStateTask(SessionMachine *m, Progress *p, bool discardCurSnapshot)
     7602    RestoreSnapshotTask(SessionMachine *m, Progress *p, bool discardCurSnapshot)
    76017603        : Task(m, p),
    76027604          discardCurrentSnapshot(discardCurSnapshot)
     
    76057607    void handler()
    76067608    {
    7607         machine->discardCurrentStateHandler(*this);
     7609        machine->restoreSnapshotHandler(*this);
    76087610    }
    76097611
     
    86058607 *  @note Locks mParent + this + children objects for writing!
    86068608 */
    8607 STDMETHODIMP SessionMachine::DiscardSnapshot(IConsole *aInitiator,
    8608                                              IN_BSTR aId,
    8609                                              MachineState_T *aMachineState,
    8610                                              IProgress **aProgress)
     8609STDMETHODIMP SessionMachine::DeleteSnapshot(IConsole *aInitiator,
     8610                                            IN_BSTR aId,
     8611                                            MachineState_T *aMachineState,
     8612                                            IProgress **aProgress)
    86118613{
    86128614    LogFlowThisFunc(("\n"));
     
    86488650        {
    86498651            rc = saveSettings();
    8650             CheckComRCReturnRC (rc);
     8652            CheckComRCReturnRC(rc);
    86518653        }
    86528654    }
     
    86578659    ComObjPtr<Progress> progress;
    86588660    progress.createObject();
    8659     rc = progress->init (mParent, aInitiator,
    8660                          Bstr(Utf8StrFmt(tr("Discarding snapshot '%s'"),
    8661                                             snapshot->getName().c_str())),
    8662                          FALSE /* aCancelable */,
    8663                          1 + (ULONG)snapshot->getSnapshotMachine()->mMediaData->mAttachments.size() +
    8664                          (snapshot->stateFilePath().isNull() ? 0 : 1),
    8665                          Bstr (tr ("Preparing to discard snapshot")));
    8666     AssertComRCReturn (rc, rc);
     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);
    86678669
    86688670    /* 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");
    86738679    if (RT_FAILURE(vrc))
    86748680        delete task;
     
    86768682
    86778683    /* set the proper machine state (note: after creating a Task instance) */
    8678     setMachineState(MachineState_Discarding);
     8684    setMachineState(MachineState_DeletingSnapshot);
    86798685
    86808686    /* return the progress to the caller */
     
    86908696 *  @note Locks this + children objects for writing!
    86918697 */
    8692 STDMETHODIMP SessionMachine::DiscardCurrentState (
    8693     IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress)
     8698STDMETHODIMP SessionMachine::RestoreSnapshot(IConsole *aInitiator,
     8699                                             ISnapshot *aSnapshot,
     8700                                             MachineState_T *aMachineState,
     8701                                             IProgress **aProgress)
    86948702{
    86958703    LogFlowThisFunc(("\n"));
     
    87038711    AutoWriteLock alock(this);
    87048712
    8705     ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL);
     8713    ComAssertRet(!Global::IsOnlineOrTransient(mData->mMachineState),
     8714                 E_FAIL);
    87068715
    87078716    if (mData->mCurrentSnapshot.isNull())
     
    87268735    /* create and start the task on a separate thread (note that it will not
    87278736     * 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");
    88218745    if (RT_FAILURE(vrc))
    88228746    {
     
    88268750
    88278751    /* set the proper machine state (note: after creating a Task instance) */
    8828     setMachineState(MachineState_Discarding);
     8752    setMachineState(MachineState_RestoringSnapshot);
    88298753
    88308754    /* return the progress to the caller */
     
    95589482/**
    95599483 * Discard snapshot task handler. Must be called only by
    9560  * DiscardSnapshotTask::handler()!
     9484 * DeleteSnapshotTask::handler()!
    95619485 *
    95629486 * When aTask.subTask is true, the associated progress object is left
     
    95669490 * @note Locks mParent + this + child objects for writing!
    95679491 */
    9568 void SessionMachine::discardSnapshotHandler(DiscardSnapshotTask &aTask)
     9492void SessionMachine::discardSnapshotHandler(DeleteSnapshotTask &aTask)
    95699493{
    95709494    LogFlowThisFuncEnter();
     
    98439767
    98449768/**
    9845  * Discard current state task handler. Must be called only by
    9846  * DiscardCurrentStateTask::handler()!
     9769 * Restore snapshot state task handler. Must be called only by
     9770 * RestoreSnapshotTask::handler()!
    98479771 *
    98489772 * @note Locks mParent + this object for writing.
    98499773 */
    9850 void SessionMachine::discardCurrentStateHandler (DiscardCurrentStateTask &aTask)
     9774void SessionMachine::restoreSnapshotHandler(RestoreSnapshotTask &aTask)
    98519775{
    98529776    LogFlowThisFuncEnter();
     
    98599783        /* we might have been uninitialized because the session was accidentally
    98609784         * 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"));
    98649789
    98659790        LogFlowThisFuncLeave();
     
    98819806     * session) */
    98829807    if (isModified())
    9883         rollback (false /* aNotify */);
     9808        rollback(false /* aNotify */);
    98849809
    98859810    HRESULT rc = S_OK;
     
    99109835             * snapshot first */
    99119836
    9912             DiscardSnapshotTask subTask (aTask, mData->mCurrentSnapshot);
     9837            DeleteSnapshotTask subTask (aTask, mData->mCurrentSnapshot);
    99139838            subTask.subTask = true;
    99149839            discardSnapshotHandler (subTask);
     
    100599984             * after discarding the current state. */
    100609985
    10061             DiscardSnapshotTask subTask (aTask, mData->mCurrentSnapshot);
     9986            DeleteSnapshotTask subTask (aTask, mData->mCurrentSnapshot);
    100629987            subTask.subTask = true;
    100639988            discardSnapshotHandler (subTask);
     
    1039510320    }
    1039610321    else if (   oldMachineState >= MachineState_Running
    10397              && oldMachineState != MachineState_Discarding
     10322             && oldMachineState != MachineState_RestoringSnapshot
     10323             && oldMachineState != MachineState_DeletingSnapshot
    1039810324             && oldMachineState != MachineState_SettingUp
    1039910325             && aMachineState < MachineState_Running
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r23823 r23879  
    574574    +-&gt; PoweredOff --+
    575575    |                |
    576     |   Aborted -----+--&gt;[discardSnapshot()    ]-------------&gt; Discarding --+
    577     |                |   [discardCurrentState()]                            |
    578     +-&gt; Saved -------+   [discardCurrentSnapshotAndState()]                 |
     576    |   Aborted -----+--&gt;[restoreSnapshot()    ]-------&gt; RestoringSnapshot -+
     577    |                |   [deleteSnapshot()     ]-------&gt; DeletingSnapshot --+
     578    +-&gt; Saved -------+                                                      |
    579579    |                                                                       |
    580580    +---(Saved if restored from an online snapshot, PoweredOff otherwise)---+
     
    678678      </desc>
    679679    </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">
    686692      <desc>
    687693        Lengthy setup operation is in progress.
     
    705711      </desc>
    706712    </const>
    707     <const name="LastTransient"  value="13" wsmap="suppress"> <!-- SettingUp -->
     713    <const name="LastTransient"  value="14" wsmap="suppress"> <!-- SettingUp -->
    708714      <desc>
    709715        Pseudo-state: last transient state (for use in relational expressions).
     
    36313637  <interface
    36323638     name="IInternalMachineControl" extends="$unknown"
    3633      uuid="6c08103e-b8e6-44fb-bc6c-36067153d4bd"
     3639     uuid="4e2b8f0f-6575-49d2-bb19-5cd15a6ca2f0"
    36343640     internal="yes"
    36353641     wsmap="suppress"
     
    38543860    </method>
    38553861
    3856     <method name="discardSnapshot">
    3857       <desc>
    3858         Gets called by IConsole::discardSnapshot.
     3862    <method name="deleteSnapshot">
     3863      <desc>
     3864        Gets called by IConsole::deleteSnapshot.
    38593865        <result name="VBOX_E_INVALID_OBJECT_STATE">
    38603866          Snapshot has more than one child snapshot.
     
    38753881    </method>
    38763882
    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.
    38833886      </desc>
    38843887      <param name="initiator" type="IConsole" dir="in">
    38853888        <desc>The console object that initiated this call.</desc>
    38863889      </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>
    39043892      </param>
    39053893      <param name="machineState" type="MachineState" dir="out">
     
    44544442      <desc>
    44554443        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.
    44584449      </desc>
    44594450    </attribute>
     
    44714462        identical to the state stored in the current snapshot.
    44724463
    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
    44754467        <ul>
    4476           <li><link to="IConsole::discardCurrentState"/> or
    4477             <link to="IConsole::discardCurrentSnapshotAndState"/>
     4468          <li><link to="IConsole::restoreSnapshot"/>
    44784469          </li>
    44794470          <li><link to="IConsole::takeSnapshot"/> (issued on a
    4480             powered off or saved machine, for which
     4471            "powered off" or "saved" machine, for which
    44814472            <link to="#settingsModified"/> returns @c false)
    44824473          </li>
     
    60886079  <interface
    60896080     name="IConsole" extends="$unknown"
    6090      uuid="03312360-0364-4b7a-ad71-1a8450133774"
     6081     uuid="55dd56a5-1d1d-4d81-b742-b082b9571be6"
    60916082     wsmap="managed"
    60926083     >
     
    66426633    </method>
    66436634
    6644     <method name="discardSnapshot">
     6635    <method name="deleteSnapshot">
    66456636      <desc>
    66466637        Starts discarding the specified snapshot asynchronously.
     
    67386729    </method>
    67396730
    6740     <method name="discardCurrentState">
     6731    <method name="restoreSnapshot">
    67416732      <desc>
    67426733        Starts resetting the machine's current state to the state contained
    6743         in the current snapshot, asynchronously. All current settings of the
     6734        in the given snapshot, asynchronously. All current settings of the
    67446735        machine will be reset and changes stored in differencing media
    67456736        will be lost.
     
    67496740        media are created for all normal media of the machine.
    67506741
    6751         If the current snapshot of the machine is an online snapshot, the
    6752         machine will go to the <link to="MachineState_Saved"> saved
    6753         state</link>, so that the next time it is powered on, the execution
    6754         state will be restored from the current snapshot.
     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.
    67556746
    67566747        <note>
     
    67696760        </result>
    67706761      </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>
    68236765      <param name="progress" type="IProgress" dir="return">
    68246766        <desc>Progress object to track the operation completion.</desc>
     
    81748116          </li>
    81758117
    8176           <li><link to="IConsole::discardCurrentState"/>: this goes back to
     8118          <li><link to="IConsole::restoreSnapshot"/>: this goes back to
    81778119              a previous snapshot. This resets the machine's state to that of
    81788120              the previous snapshot by deleting the differencing image of each
     
    81838125          </li>
    81848126
    8185           <li><link to="IConsole::discardSnapshot"/>: deletes a snapshot
     8127          <li><link to="IConsole::deleteSnapshot"/>: deletes a snapshot
    81868128              without affecting the current machine state.
    81878129
     
    81948136              by this operation, except that parent disk images will be modified
    81958137              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 in
    8200               before the current snapshot has been taken. Effectively, this goes
    8201               back to the state before the current snapshot, which might be
    8202               an earlier snapshot.
    8203 
    8204               The current state, as well as the current snapshot, are lost.
    82058138          </li>
    82068139      </ul>
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r23827 r23879  
    145145    STDMETHOD(TakeSnapshot) (IN_BSTR aName, IN_BSTR aDescription,
    146146                             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);
    150149    STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, IProgress **aProgress);
    151150    STDMETHOD(RegisterCallback) (IConsoleCallback *aCallback);
  • trunk/src/VBox/Main/include/MachineImpl.h

    r23801 r23879  
    968968                                   BSTR *aStateFilePath);
    969969    STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
    970     STDMETHOD(DiscardSnapshot)(IConsole *aInitiator, IN_BSTR aId,
    971                                MachineState_T *aMachineState, IProgress **aProgress);
    972     STDMETHOD(DiscardCurrentState)(IConsole *aInitiator, MachineState_T *aMachineState,
    973                                    IProgress **aProgress);
    974     STDMETHOD(DiscardCurrentSnapshotAndState)(IConsole *aInitiator, MachineState_T *aMachineState,
    975                                               IProgress **aProgress);
     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);
    976976    STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
    977977              ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
     
    10241024
    10251025    struct Task;
    1026     struct DiscardSnapshotTask;
    1027     struct DiscardCurrentStateTask;
    1028 
    1029     friend struct DiscardSnapshotTask;
    1030     friend struct DiscardCurrentStateTask;
     1026    struct DeleteSnapshotTask;
     1027    struct RestoreSnapshotTask;
     1028
     1029    friend struct DeleteSnapshotTask;
     1030    friend struct RestoreSnapshotTask;
    10311031
    10321032    void uninit(Uninit::Reason aReason);
     
    10371037    typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
    10381038
    1039     void discardSnapshotHandler(DiscardSnapshotTask &aTask);
    1040     void discardCurrentStateHandler(DiscardCurrentStateTask &aTask);
     1039    void discardSnapshotHandler(DeleteSnapshotTask &aTask);
     1040    void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
    10411041
    10421042    HRESULT lockMedia();
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette