third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Initializes the registered machine by loading the settings file.
 *  This method is separated from #init() in order to make it possible to
 *  retry the operation after VirtualBox startup instead of refusing to
 *  startup the whole VirtualBox server in case if the settings file of some
 *  registered VM is invalid or inaccessible.
 *
 *  @note Must be always called from this object's write lock
 *        (unless called from #init() that doesn't need any locking).
 *  @note Locks the mUSBController method for writing.
 *  @note Subclasses must not call this method.
 */
Initializes the registered machine by loading the settings file.
This method is separated from #init() in order to make it possible to
retry the operation after VirtualBox startup instead of refusing to
startup the whole VirtualBox server in case if the settings file of some
registered VM is invalid or inaccessible.

@note Must be always called from this object's write lock
(unless called from #init() that doesn't need any locking).
@note Locks the mUSBController method for writing.
@note Subclasses must not call this method.
Initializes the registered machine by loading the settings file . This method is separated from #init () in order to make it possible to retry the operation after VirtualBox startup instead of refusing to startup the whole VirtualBox server in case if the settings file of some registered VM is invalid or inaccessible . @note Must be always called from this object ' s write lock ( unless called from #init () that doesn ' t need any locking ) . @note Locks the mUSBController method for writing . @note Subclasses must not call this method .
HRESULT Machine::i_registeredInit()
{
    AssertReturn(!i_isSessionMachine(), E_FAIL);
    AssertReturn(!i_isSnapshotMachine(), E_FAIL);
    AssertReturn(mData->mUuid.isValid(), E_FAIL);
    AssertReturn(!mData->mAccessible, E_FAIL);
    HRESULT rc = initDataAndChildObjects();
    if (SUCCEEDED(rc))
    {
        mData->mRegistered = FALSE;
        try
        {
            mData->pMachineConfigFile = new settings::MachineConfigFile(&mData->m_strConfigFileFull);
            if (mData->mUuid != mData->pMachineConfigFile->uuid)
                throw setError(E_FAIL,
                               tr("Machine UUID {%RTuuid} in '%s' doesn't match its UUID {%s} in the registry file '%s'"),
                               mData->pMachineConfigFile->uuid.raw(),
                               mData->m_strConfigFileFull.c_str(),
                               mData->mUuid.toString().c_str(),
                               mParent->i_settingsFilePath().c_str());
            rc = i_loadMachineDataFromSettings(*mData->pMachineConfigFile,
                                               NULL );
            if (FAILED(rc)) throw rc;
        }
        catch (HRESULT err)
        {
            rc = err;
        }
        catch (...)
        {
            rc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
        }
        mData->mRegistered = TRUE;
    }
    if (SUCCEEDED(rc))
    {
        mData->mAccessible = TRUE;
        i_commit(); 
    }
    else
    {
        mData->mAccessError = com::ErrorInfo();
        Log1Warning(("Machine {%RTuuid} is inaccessible! [%ls]\n", mData->mUuid.raw(), mData->mAccessError.getText().raw()));
        i_rollback(false );
        mParent->i_unregisterMachineMedia(i_getId());
        uninitDataAndChildObjects();
        rc = S_OK;
    }
    return rc;
}
HRESULT Machine :: i_registeredInit ( ) { AssertReturn ( ! i_isSessionMachine ( ) , E_FAIL ) ; AssertReturn ( ! i_isSnapshotMachine ( ) , E_FAIL ) ; AssertReturn ( mData -> mUuid . isValid ( ) , E_FAIL ) ; AssertReturn ( ! mData -> mAccessible , E_FAIL ) ; HRESULT rc = initDataAndChildObjects ( ) ; if ( SUCCEEDED ( rc ) ) { mData -> mRegistered = FALSE ; try { mData -> pMachineConfigFile = new settings :: MachineConfigFile ( & mData -> m_strConfigFileFull ) ; if ( mData -> mUuid != mData -> pMachineConfigFile -> uuid ) throw setError ( E_FAIL , tr ( " " ) , mData -> pMachineConfigFile -> uuid . raw ( ) , mData -> m_strConfigFileFull . c_str ( ) , mData -> mUuid . toString ( ) . c_str ( ) , mParent -> i_settingsFilePath ( ) . c_str ( ) ) ; rc = i_loadMachineDataFromSettings ( * mData -> pMachineConfigFile , NULL ) ; if ( FAILED ( rc ) ) throw rc ; } catch ( HRESULT err ) { rc = err ; } catch ( ... ) { rc = VirtualBoxBase :: handleUnexpectedExceptions ( this , RT_SRC_POS ) ; } mData -> mRegistered = TRUE ; } if ( SUCCEEDED ( rc ) ) { mData -> mAccessible = TRUE ; i_commit ( ) ; } else { mData -> mAccessError = com :: ErrorInfo ( ) ; Log1Warning ( ( " \n " , mData -> mUuid . raw ( ) , mData -> mAccessError . getText ( ) . raw ( ) ) ) ; i_rollback ( false ) ; mParent -> i_unregisterMachineMedia ( i_getId ( ) ) ; uninitDataAndChildObjects ( ) ; rc = S_OK ; } return rc ; }
Initializes the registered machine by loading the settings file.
Initializes the registered machine by loading the settings file .
/* Temporarily reset the registered flag in order to let setters
         * potentially called from loadSettings() succeed (isMutable() used in
         * all setters will return FALSE for a Machine instance if mRegistered
         * is TRUE). */ // load and parse machine XML; this will throw on XML or logic errors /* const Guid *puuidRegistry */ /* we assume that error info is set by the thrower */ /* Restore the registered flag (even on failure) */ /* Set mAccessible to TRUE only if we successfully locked and loaded
         * the settings file */ /* commit all changes made during loading the settings file */ /// @todo r=dj why do we need a commit during init?!? this is very expensive /// @todo r=klaus for some reason the settings loading logic backs up // the settings, and therefore a commit is needed. Should probably be changed. /* If the machine is registered, then, instead of returning a
         * failure, we mark it as inaccessible and set the result to
         * success to give it a try later */ /* fetch the current error info */ /* rollback all changes */ /* aNotify */ // uninit media from this machine's media registry, or else // reloading the settings will fail /* uninitialize the common part to make sure all data is reset to
         * default (null) values */