third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Recursively loads all snapshots starting from the given.
 *
 *  @param data             snapshot settings.
 *  @param aCurSnapshotId   Current snapshot ID from the settings file.
 *  @param aParentSnapshot  Parent snapshot.
 */
Recursively loads all snapshots starting from the given.
@param data             snapshot settings.
@param aCurSnapshotId   Current snapshot ID from the settings file.
@param aParentSnapshot  Parent snapshot.
Recursively loads all snapshots starting from the given . @param data snapshot settings . @param aCurSnapshotId Current snapshot ID from the settings file . @param aParentSnapshot Parent snapshot .
HRESULT Machine::i_loadSnapshot(const settings::Snapshot &data,
                                const Guid &aCurSnapshotId,
                                Snapshot *aParentSnapshot)
{
    AssertReturn(!i_isSnapshotMachine(), E_FAIL);
    AssertReturn(!i_isSessionMachine(), E_FAIL);
    HRESULT rc = S_OK;
    Utf8Str strStateFile;
    if (!data.strStateFile.isEmpty())
    {
        strStateFile = data.strStateFile;
        int vrc = i_calculateFullPath(strStateFile, strStateFile);
        if (RT_FAILURE(vrc))
            return setError(E_FAIL,
                            tr("Invalid saved state file path '%s' (%Rrc)"),
                            strStateFile.c_str(),
                            vrc);
    }
    ComObjPtr<SnapshotMachine> pSnapshotMachine;
    pSnapshotMachine.createObject();
    rc = pSnapshotMachine->initFromSettings(this,
                                            data.hardware,
                                            &data.debugging,
                                            &data.autostart,
                                            data.uuid.ref(),
                                            strStateFile);
    if (FAILED(rc)) return rc;
    ComObjPtr<Snapshot> pSnapshot;
    pSnapshot.createObject();
    rc = pSnapshot->init(mParent, 
                         data.uuid,
                         data.strName,
                         data.strDescription,
                         data.timestamp,
                         pSnapshotMachine,
                         aParentSnapshot);
    if (FAILED(rc)) return rc;
    if (!mData->mFirstSnapshot)
        mData->mFirstSnapshot = pSnapshot;
    if (    !mData->mCurrentSnapshot
         && pSnapshot->i_getId() == aCurSnapshotId
       )
        mData->mCurrentSnapshot = pSnapshot;
    for (settings::SnapshotsList::const_iterator
         it = data.llChildSnapshots.begin();
         it != data.llChildSnapshots.end();
         ++it)
    {
        const settings::Snapshot &childData = *it;
        rc = i_loadSnapshot(childData,
                            aCurSnapshotId,
                            pSnapshot);       
        if (FAILED(rc)) return rc;
    }
    return rc;
}
HRESULT Machine :: i_loadSnapshot ( const settings :: Snapshot & data , const Guid & aCurSnapshotId , Snapshot * aParentSnapshot ) { AssertReturn ( ! i_isSnapshotMachine ( ) , E_FAIL ) ; AssertReturn ( ! i_isSessionMachine ( ) , E_FAIL ) ; HRESULT rc = S_OK ; Utf8Str strStateFile ; if ( ! data . strStateFile . isEmpty ( ) ) { strStateFile = data . strStateFile ; int vrc = i_calculateFullPath ( strStateFile , strStateFile ) ; if ( RT_FAILURE ( vrc ) ) return setError ( E_FAIL , tr ( " " ) , strStateFile . c_str ( ) , vrc ) ; } ComObjPtr < SnapshotMachine > pSnapshotMachine ; pSnapshotMachine . createObject ( ) ; rc = pSnapshotMachine -> initFromSettings ( this , data . hardware , & data . debugging , & data . autostart , data . uuid . ref ( ) , strStateFile ) ; if ( FAILED ( rc ) ) return rc ; ComObjPtr < Snapshot > pSnapshot ; pSnapshot . createObject ( ) ; rc = pSnapshot -> init ( mParent , data . uuid , data . strName , data . strDescription , data . timestamp , pSnapshotMachine , aParentSnapshot ) ; if ( FAILED ( rc ) ) return rc ; if ( ! mData -> mFirstSnapshot ) mData -> mFirstSnapshot = pSnapshot ; if ( ! mData -> mCurrentSnapshot && pSnapshot -> i_getId ( ) == aCurSnapshotId ) mData -> mCurrentSnapshot = pSnapshot ; for ( settings :: SnapshotsList :: const_iterator it = data . llChildSnapshots . begin ( ) ; it != data . llChildSnapshots . end ( ) ; ++ it ) { const settings :: Snapshot & childData = * it ; rc = i_loadSnapshot ( childData , aCurSnapshotId , pSnapshot ) ; if ( FAILED ( rc ) ) return rc ; } return rc ; }
Recursively loads all snapshots starting from the given.
Recursively loads all snapshots starting from the given .
/* optional */ /* create a snapshot machine object */ /* create a snapshot object */ /* initialize the snapshot */ // VirtualBox object /* memorize the first snapshot if necessary */ /* memorize the current snapshot when appropriate */ // now create the children // recurse // parent = the one we created above