third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Initializes a new instance with data from machine XML (formerly Init_Registered).
 *  Gets called in two modes:
 *
 *      -- from VirtualBox::initMachines() during VirtualBox startup; in that case, the
 *         UUID is specified and we mark the machine as "registered";
 *
 *      -- from the public VirtualBox::OpenMachine() API, in which case the UUID is NULL
 *         and the machine remains unregistered until RegisterMachine() is called.
 *
 *  @param aParent      Associated parent object
 *  @param strConfigFile Local file system path to the VM settings file (can
 *                      be relative to the VirtualBox config directory).
 *  @param aId          UUID of the machine or NULL (see above).
 *
 *  @return  Success indicator. if not S_OK, the machine object is invalid
 */
Initializes a new instance with data from machine XML (formerly Init_Registered).
Gets called in two modes.

from VirtualBox::initMachines() during VirtualBox startup; in that case, the
UUID is specified and we mark the machine as "registered".

from the public VirtualBox::OpenMachine() API, in which case the UUID is NULL
and the machine remains unregistered until RegisterMachine() is called.

@param aParent      Associated parent object
@param strConfigFile Local file system path to the VM settings file (can
be relative to the VirtualBox config directory).
@param aId          UUID of the machine or NULL .

@return  Success indicator. if not S_OK, the machine object is invalid
Initializes a new instance with data from machine XML ( formerly Init_Registered ) . Gets called in two modes . from VirtualBox :: initMachines () during VirtualBox startup ; in that case the UUID is specified and we mark the machine as " registered " . from the public VirtualBox :: OpenMachine () API in which case the UUID is NULL and the machine remains unregistered until RegisterMachine () is called . @param aParent Associated parent object @param strConfigFile Local file system path to the VM settings file ( can be relative to the VirtualBox config directory ) . @param aId UUID of the machine or NULL . @return Success indicator . if not S_OK the machine object is invalid
HRESULT Machine::initFromSettings(VirtualBox *aParent,
                                  const Utf8Str &strConfigFile,
                                  const Guid *aId)
{
    LogFlowThisFuncEnter();
    LogFlowThisFunc(("(Init_Registered) aConfigFile='%s\n", strConfigFile.c_str()));
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    HRESULT rc = initImpl(aParent, strConfigFile);
    if (FAILED(rc)) return rc;
    if (aId)
    {
        unconst(mData->mUuid) = *aId;
        mData->mRegistered = TRUE;
        rc = i_registeredInit();
    }
    else
    {
        rc = initDataAndChildObjects();
        if (SUCCEEDED(rc))
        {
            mData->mAccessible = TRUE;
            try
            {
                mData->pMachineConfigFile = new settings::MachineConfigFile(&mData->m_strConfigFileFull);
                if (aParent->i_findMachine(mData->pMachineConfigFile->uuid,
                                           true ,
                                           false ,
                                           NULL) != VBOX_E_OBJECT_NOT_FOUND)
                {
                    throw setError(E_FAIL,
                                   tr("Trying to open a VM config '%s' which has the same UUID as an existing virtual machine"),
                                   mData->m_strConfigFile.c_str());
                }
                unconst(mData->mUuid) = mData->pMachineConfigFile->uuid;
                rc = i_loadMachineDataFromSettings(*mData->pMachineConfigFile,
                                                 NULL );
                if (FAILED(rc)) throw rc;
                i_allowStateModification();
                i_commit();
            }
            catch (HRESULT err)
            {
                rc = err;
            }
            catch (...)
            {
                rc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
            }
        }
    }
    if (SUCCEEDED(rc))
    {
        if (mData->mAccessible)
            autoInitSpan.setSucceeded();
        else
        {
            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 :: initFromSettings ( VirtualBox * aParent , const Utf8Str & strConfigFile , const Guid * aId ) { LogFlowThisFuncEnter ( ) ; LogFlowThisFunc ( ( " \n " , strConfigFile . c_str ( ) ) ) ; AutoInitSpan autoInitSpan ( this ) ; AssertReturn ( autoInitSpan . isOk ( ) , E_FAIL ) ; HRESULT rc = initImpl ( aParent , strConfigFile ) ; if ( FAILED ( rc ) ) return rc ; if ( aId ) { unconst ( mData -> mUuid ) = * aId ; mData -> mRegistered = TRUE ; rc = i_registeredInit ( ) ; } else { rc = initDataAndChildObjects ( ) ; if ( SUCCEEDED ( rc ) ) { mData -> mAccessible = TRUE ; try { mData -> pMachineConfigFile = new settings :: MachineConfigFile ( & mData -> m_strConfigFileFull ) ; if ( aParent -> i_findMachine ( mData -> pMachineConfigFile -> uuid , true , false , NULL ) != VBOX_E_OBJECT_NOT_FOUND ) { throw setError ( E_FAIL , tr ( " " ) , mData -> m_strConfigFile . c_str ( ) ) ; } unconst ( mData -> mUuid ) = mData -> pMachineConfigFile -> uuid ; rc = i_loadMachineDataFromSettings ( * mData -> pMachineConfigFile , NULL ) ; if ( FAILED ( rc ) ) throw rc ; i_allowStateModification ( ) ; i_commit ( ) ; } catch ( HRESULT err ) { rc = err ; } catch ( ... ) { rc = VirtualBoxBase :: handleUnexpectedExceptions ( this , RT_SRC_POS ) ; } } } if ( SUCCEEDED ( rc ) ) { if ( mData -> mAccessible ) autoInitSpan . setSucceeded ( ) ; else { 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 with data from machine XML (formerly Init_Registered).
Initializes a new instance with data from machine XML ( formerly Init_Registered ) .
/* Enclose the state transition NotReady->InInit->Ready */ // loading a registered VM: // now load the settings from XML: // this calls initDataAndChildObjects() and loadSettings() // opening an unregistered VM (VirtualBox::OpenMachine()): // set to true now to cause uninit() to call uninitDataAndChildObjects() on failure // load and parse machine XML; this will throw on XML or logic errors // reject VM UUID duplicates, they can happen if someone // tries to register an already known VM config again /* fPermitInaccessible */ /* aDoSetError */ // use UUID from machine config /* puuidRegistry */ /* At this point the changing of the current state modification
                 * flag is allowed. */ /* we assume that error info is set by the thrower */ /* Confirm a successful initialization when it's the case */ // uninit media from this machine's media registry, or else // reloading the settings will fail