VirtualBox

Ignore:
Timestamp:
Jan 18, 2011 11:27:20 AM (14 years ago)
Author:
vboxsync
Message:

Main: fix and clarify that ISnapshot::SetName and SetDescription automatically save the machine settings; API docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r35368 r35602  
    346346STDMETHODIMP Snapshot::COMSETTER(Name)(IN_BSTR aName)
    347347{
     348    HRESULT rc = S_OK;
    348349    CheckComArgStrNotEmptyOrNull(aName);
    349350
     
    358359    {
    359360        m->strName = strName;
    360 
    361361        alock.leave(); /* Important! (child->parent locks are forbidden) */
    362 
    363         // flag the machine as dirty or change won't get saved
    364         AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    365         m->pMachine->setModified(Machine::IsModified_Snapshots);
    366         mlock.leave();
    367 
    368         return m->pMachine->onSnapshotChange(this);
    369     }
    370 
    371     return S_OK;
     362        rc = m->pMachine->onSnapshotChange(this);
     363    }
     364
     365    return rc;
    372366}
    373367
     
    387381STDMETHODIMP Snapshot::COMSETTER(Description)(IN_BSTR aDescription)
    388382{
     383    HRESULT rc = S_OK;
    389384    AutoCaller autoCaller(this);
    390385    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     
    397392    {
    398393        m->strDescription = strDescription;
    399 
    400394        alock.leave(); /* Important! (child->parent locks are forbidden) */
    401 
    402         // flag the machine as dirty or change won't get saved
    403         AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
    404         m->pMachine->setModified(Machine::IsModified_Snapshots);
    405         mlock.leave();
    406 
    407         return m->pMachine->onSnapshotChange(this);
    408     }
    409 
    410     return S_OK;
     395        rc = m->pMachine->onSnapshotChange(this);
     396    }
     397
     398    return rc;
    411399}
    412400
     
    11931181 *  snapshot data such as name or description is changed.
    11941182 *
    1195  *  @note Locks this object for writing.
     1183 *  @warning Caller must hold no locks when calling this.
    11961184 */
    11971185HRESULT SnapshotMachine::onSnapshotChange(Snapshot *aSnapshot)
    11981186{
    1199     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    1200 
    1201     //     mPeer->saveAllSnapshots();  @todo
     1187    AutoMultiWriteLock2 mlock(this, aSnapshot COMMA_LOCKVAL_SRC_POS);
     1188    Guid uuidMachine(mData->mUuid),
     1189         uuidSnapshot(aSnapshot->getId());
     1190    bool fNeedsGlobalSaveSettings = false;
     1191
     1192    // flag the machine as dirty or change won't get saved
     1193    mPeer->setModified(Machine::IsModified_Snapshots);
     1194    HRESULT rc = mPeer->saveSettings(&fNeedsGlobalSaveSettings,
     1195                                     SaveS_Force);        // we know we need saving, no need to check
     1196    mlock.leave();
     1197
     1198    if (SUCCEEDED(rc) && fNeedsGlobalSaveSettings)
     1199    {
     1200        // save the global settings
     1201        AutoWriteLock vboxlock(mParent COMMA_LOCKVAL_SRC_POS);
     1202        rc = mParent->saveSettings();
     1203    }
    12021204
    12031205    /* inform callbacks */
    1204     mParent->onSnapshotChange(mData->mUuid, aSnapshot->getId());
    1205 
    1206     return S_OK;
     1206    mParent->onSnapshotChange(uuidMachine, uuidSnapshot);
     1207
     1208    return rc;
    12071209}
    12081210
Note: See TracChangeset for help on using the changeset viewer.

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