third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Initializes a new instance from a machine config that is already in memory
 *  (import OVF case). Since we are importing, the UUID in the machine
 *  config is ignored and we always generate a fresh one.
 *
 *  @param aParent  Associated parent object.
 *  @param strName  Name for the new machine; this overrides what is specified in config and is used
 *                  for the settings file as well.
 *  @param config   Machine configuration loaded and parsed from XML.
 *
 *  @return  Success indicator. if not S_OK, the machine object is invalid
 */
Initializes a new instance from a machine config that is already in memory
(import OVF case). Since we are importing, the UUID in the machine
config is ignored and we always generate a fresh one.

@param aParent  Associated parent object.
@param strName  Name for the new machine; this overrides what is specified in config and is used
for the settings file as well.
@param config   Machine configuration loaded and parsed from XML.

@return  Success indicator. if not S_OK, the machine object is invalid
Initializes a new instance from a machine config that is already in memory ( import OVF case ) . Since we are importing the UUID in the machine config is ignored and we always generate a fresh one . @param aParent Associated parent object . @param strName Name for the new machine ; this overrides what is specified in config and is used for the settings file as well . @param config Machine configuration loaded and parsed from XML . @return Success indicator . if not S_OK the machine object is invalid
HRESULT Machine::init(VirtualBox *aParent,
                      const Utf8Str &strName,
                      const settings::MachineConfigFile &config)
{
    LogFlowThisFuncEnter();
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    Utf8Str strConfigFile;
    aParent->i_getDefaultMachineFolder(strConfigFile);
    strConfigFile.append(RTPATH_DELIMITER);
    strConfigFile.append(strName);
    strConfigFile.append(RTPATH_DELIMITER);
    strConfigFile.append(strName);
    strConfigFile.append(".vbox");
    HRESULT rc = initImpl(aParent, strConfigFile);
    if (FAILED(rc)) return rc;
    rc = i_tryCreateMachineConfigFile(false );
    if (FAILED(rc)) return rc;
    rc = initDataAndChildObjects();
    if (SUCCEEDED(rc))
    {
        mData->mAccessible = TRUE;
        mData->pMachineConfigFile = new settings::MachineConfigFile(NULL);
        unconst(mData->mUuid).create();
        rc = i_loadMachineDataFromSettings(config,
                                           &mData->mUuid); 
        mUserData->s.strName = strName;
        if (SUCCEEDED(rc))
        {
            i_allowStateModification();
            i_commit();
        }
    }
    if (SUCCEEDED(rc))
    {
        if (mData->mAccessible)
            autoInitSpan.setSucceeded();
        else
        {
            ErrorInfoKeeper eik;
            autoInitSpan.setLimited();
            mParent->i_unregisterMachineMedia(i_getId());
        }
    }
    LogFlowThisFunc(("mName='%s', mRegistered=%RTbool, mAccessible=%RTbool "
                     "rc=%08X\n",
                      !!mUserData ? mUserData->s.strName.c_str() : "NULL",
                      mData->mRegistered, mData->mAccessible, rc));
    LogFlowThisFuncLeave();
    return rc;
}
HRESULT Machine :: init ( VirtualBox * aParent , const Utf8Str & strName , const settings :: MachineConfigFile & config ) { LogFlowThisFuncEnter ( ) ; AutoInitSpan autoInitSpan ( this ) ; AssertReturn ( autoInitSpan . isOk ( ) , E_FAIL ) ; Utf8Str strConfigFile ; aParent -> i_getDefaultMachineFolder ( strConfigFile ) ; strConfigFile . append ( RTPATH_DELIMITER ) ; strConfigFile . append ( strName ) ; strConfigFile . append ( RTPATH_DELIMITER ) ; strConfigFile . append ( strName ) ; strConfigFile . append ( " " ) ; HRESULT rc = initImpl ( aParent , strConfigFile ) ; if ( FAILED ( rc ) ) return rc ; rc = i_tryCreateMachineConfigFile ( false ) ; if ( FAILED ( rc ) ) return rc ; rc = initDataAndChildObjects ( ) ; if ( SUCCEEDED ( rc ) ) { mData -> mAccessible = TRUE ; mData -> pMachineConfigFile = new settings :: MachineConfigFile ( NULL ) ; unconst ( mData -> mUuid ) . create ( ) ; rc = i_loadMachineDataFromSettings ( config , & mData -> mUuid ) ; mUserData -> s . strName = strName ; if ( SUCCEEDED ( rc ) ) { i_allowStateModification ( ) ; i_commit ( ) ; } } if ( SUCCEEDED ( rc ) ) { if ( mData -> mAccessible ) autoInitSpan . setSucceeded ( ) ; else { ErrorInfoKeeper eik ; autoInitSpan . setLimited ( ) ; mParent -> i_unregisterMachineMedia ( i_getId ( ) ) ; } } LogFlowThisFunc ( ( " " " \n " , ! ! mUserData ? mUserData -> s . strName . c_str ( ) : " " , mData -> mRegistered , mData -> mAccessible , rc ) ) ; LogFlowThisFuncLeave ( ) ; return rc ; }
Initializes a new instance from a machine config that is already in memory
  (import OVF case).
Initializes a new instance from a machine config that is already in memory ( import OVF case ) .
/* Enclose the state transition NotReady->InInit->Ready */ /* fForceOverwrite */ // set to true now to cause uninit() to call uninitDataAndChildObjects() on failure // create empty machine config for instance data // generate fresh UUID, ignore machine config // puuidRegistry: initialize media with this registry ID // override VM name as well, it may be different /* At this point the changing of the current state modification
             * flag is allowed. */ /* commit all changes made during the initialization */ /* Confirm a successful initialization when it's the case */ /* Ignore all errors from unregistering, they would destroy
-            * the more interesting error information we already have,
-            * pinpointing the issue with the VM config. */ // uninit media from this machine's media registry, or else // reloading the settings will fail