third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 * Implementation for saving the machine settings into the given
 * settings::MachineConfigFile instance. This copies machine extradata
 * from the previous machine config file in the instance data, if any.
 *
 * This gets called from two locations:
 *
 *  --  Machine::i_saveSettings(), during the regular XML writing;
 *
 *  --  Appliance::buildXMLForOneVirtualSystem(), when a machine gets
 *      exported to OVF and we write the VirtualBox proprietary XML
 *      into a <vbox:Machine> tag.
 *
 * This routine fills all the fields in there, including snapshots, *except*
 * for the following:
 *
 * -- fCurrentStateModified. There is some special logic associated with that.
 *
 * The caller can then call MachineConfigFile::write() or do something else
 * with it.
 *
 * Caller must hold the machine lock!
 *
 * This throws XML errors and HRESULT, so the caller must have a catch block!
 */
Implementation for saving the machine settings into the given
settings::MachineConfigFile instance. This copies machine extradata
from the previous machine config file in the instance data, if any.

This gets called from two locations.

:i_saveSettings(), during the regular XML writing.

:buildXMLForOneVirtualSystem(), when a machine gets
exported to OVF and we write the VirtualBox proprietary XML
into a  tag.

This routine fills all the fields in there, including snapshots, *except
for the following.



The caller can then call MachineConfigFile::write() or do something else
with it.

Caller must hold the machine lock!

This throws XML errors and HRESULT, so the caller must have a catch block!
Implementation for saving the machine settings into the given settings :: MachineConfigFile instance . This copies machine extradata from the previous machine config file in the instance data if any . This gets called from two locations . : i_saveSettings () during the regular XML writing . : buildXMLForOneVirtualSystem () when a machine gets exported to OVF and we write the VirtualBox proprietary XML into a tag . This routine fills all the fields in there including snapshots * except for the following . The caller can then call MachineConfigFile :: write () or do something else with it . Caller must hold the machine lock! This throws XML errors and HRESULT so the caller must have a catch block!
void Machine::i_copyMachineDataToSettings(settings::MachineConfigFile &config)
{
    if (&config != mData->pMachineConfigFile)
        config.mapExtraDataItems = mData->pMachineConfigFile->mapExtraDataItems;
    config.uuid = mData->mUuid;
    config.machineUserData = mUserData->s;
    if (    mData->mMachineState == MachineState_Saved
         || mData->mMachineState == MachineState_Restoring
         || (    (   mData->mMachineState == MachineState_Snapshotting
                  || mData->mMachineState == MachineState_DeletingSnapshot
                  || mData->mMachineState == MachineState_RestoringSnapshot)
              && (!mSSData->strStateFilePath.isEmpty())
            )
        )
    {
        Assert(!mSSData->strStateFilePath.isEmpty());
        i_copyPathRelativeToMachine(mSSData->strStateFilePath, config.strStateFile);
    }
    else
    {
        Assert(mSSData->strStateFilePath.isEmpty() || mData->mMachineState == MachineState_Saving);
        config.strStateFile.setNull();
    }
    if (mData->mCurrentSnapshot)
        config.uuidCurrentSnapshot = mData->mCurrentSnapshot->i_getId();
    else
        config.uuidCurrentSnapshot.clear();
    config.timeLastStateChange = mData->mLastStateChange;
    config.fAborted = (mData->mMachineState == MachineState_Aborted);
    HRESULT rc = i_saveHardware(config.hardwareMachine, &config.debugging, &config.autostart);
    if (FAILED(rc)) throw rc;
    if (config.canHaveOwnMediaRegistry())
    {
        Utf8Str strMachineFolder = i_getSettingsFileFull();
        strMachineFolder.stripFilename();
        mParent->i_saveMediaRegistry(config.mediaRegistry,
                                     i_getId(),             
                                     strMachineFolder);
    }
    rc = i_saveAllSnapshots(config);
    if (FAILED(rc)) throw rc;
}
void Machine :: i_copyMachineDataToSettings ( settings :: MachineConfigFile & config ) { if ( & config != mData -> pMachineConfigFile ) config . mapExtraDataItems = mData -> pMachineConfigFile -> mapExtraDataItems ; config . uuid = mData -> mUuid ; config . machineUserData = mUserData -> s ; if ( mData -> mMachineState == MachineState_Saved || mData -> mMachineState == MachineState_Restoring || ( ( mData -> mMachineState == MachineState_Snapshotting || mData -> mMachineState == MachineState_DeletingSnapshot || mData -> mMachineState == MachineState_RestoringSnapshot ) && ( ! mSSData -> strStateFilePath . isEmpty ( ) ) ) ) { Assert ( ! mSSData -> strStateFilePath . isEmpty ( ) ) ; i_copyPathRelativeToMachine ( mSSData -> strStateFilePath , config . strStateFile ) ; } else { Assert ( mSSData -> strStateFilePath . isEmpty ( ) || mData -> mMachineState == MachineState_Saving ) ; config . strStateFile . setNull ( ) ; } if ( mData -> mCurrentSnapshot ) config . uuidCurrentSnapshot = mData -> mCurrentSnapshot -> i_getId ( ) ; else config . uuidCurrentSnapshot . clear ( ) ; config . timeLastStateChange = mData -> mLastStateChange ; config . fAborted = ( mData -> mMachineState == MachineState_Aborted ) ; HRESULT rc = i_saveHardware ( config . hardwareMachine , & config . debugging , & config . autostart ) ; if ( FAILED ( rc ) ) throw rc ; if ( config . canHaveOwnMediaRegistry ( ) ) { Utf8Str strMachineFolder = i_getSettingsFileFull ( ) ; strMachineFolder . stripFilename ( ) ; mParent -> i_saveMediaRegistry ( config . mediaRegistry , i_getId ( ) , strMachineFolder ) ; } rc = i_saveAllSnapshots ( config ) ; if ( FAILED ( rc ) ) throw rc ; }
Implementation for saving the machine settings into the given
 settings::MachineConfigFile instance.
Implementation for saving the machine settings into the given settings :: MachineConfigFile instance .
// deep copy extradata, being extra careful with self assignment (the STL // map assignment on Mac OS X clang based Xcode isn't checking) // copy name, description, OS type, teleport, UTC etc. // when doing certain snapshot operations we may or may not have // a saved state in the current state, so keep everything as is /* try to make the file name relative to the settings file dir */ /// @todo Live Migration:        config.fTeleported = (mData->mMachineState == MachineState_Teleported); // save machine's media registry if this is VirtualBox 4.0 or later // determine machine folder // only media with registry ID == machine UUID // this throws HRESULT // save snapshots