third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Initializes a new machine instance; this init() variant creates a new, empty machine.
 *  This gets called from VirtualBox::CreateMachine().
 *
 *  @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 strName      name for the machine
 *  @param llGroups     list of groups for the machine
 *  @param aOsType      OS Type of this machine or NULL.
 *  @param aId          UUID for the new machine.
 *  @param fForceOverwrite Whether to overwrite an existing machine settings file.
 *  @param fDirectoryIncludesUUID Whether the use a special VM directory naming
 *                      scheme (includes the UUID).
 *
 *  @return  Success indicator. if not S_OK, the machine object is invalid
 */
Initializes a new machine instance; this init() variant creates a new, empty machine.

@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 strName      name for the machine
@param llGroups     list of groups for the machine
@param aOsType      OS Type of this machine or NULL.
@param aId          UUID for the new machine.
@param fForceOverwrite Whether to overwrite an existing machine settings file.
@param fDirectoryIncludesUUID Whether the use a special VM directory naming
scheme (includes the UUID).

@return  Success indicator. if not S_OK, the machine object is invalid
Initializes a new machine instance ; this init () variant creates a new empty machine . @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 strName name for the machine @param llGroups list of groups for the machine @param aOsType OS Type of this machine or NULL . @param aId UUID for the new machine . @param fForceOverwrite Whether to overwrite an existing machine settings file . @param fDirectoryIncludesUUID Whether the use a special VM directory naming scheme ( includes the UUID ) . @return Success indicator . if not S_OK the machine object is invalid
HRESULT Machine::init(VirtualBox *aParent,
                      const Utf8Str &strConfigFile,
                      const Utf8Str &strName,
                      const StringsList &llGroups,
                      GuestOSType *aOsType,
                      const Guid &aId,
                      bool fForceOverwrite,
                      bool fDirectoryIncludesUUID)
{
    LogFlowThisFuncEnter();
    LogFlowThisFunc(("(Init_New) aConfigFile='%s'\n", strConfigFile.c_str()));
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    HRESULT rc = initImpl(aParent, strConfigFile);
    if (FAILED(rc)) return rc;
    rc = i_tryCreateMachineConfigFile(fForceOverwrite);
    if (FAILED(rc)) return rc;
    if (SUCCEEDED(rc))
    {
        mData->pMachineConfigFile = new settings::MachineConfigFile(NULL);
        rc = initDataAndChildObjects();
    }
    if (SUCCEEDED(rc))
    {
        mData->mAccessible = TRUE;
        unconst(mData->mUuid) = aId;
        mUserData->s.strName = strName;
        mUserData->s.llGroups = llGroups;
        mUserData->s.fDirectoryIncludesUUID = fDirectoryIncludesUUID;
        mUserData->s.fNameSync = i_isInOwnDir();
        rc = COMSETTER(SnapshotFolder)(NULL);
        AssertComRC(rc);
        if (aOsType)
        {
            mUserData->s.strOsType = aOsType->i_id();
            mBIOSSettings->i_applyDefaults(aOsType);
            mHWData->mLongMode = aOsType->i_is64Bit()
                               ? settings::Hardware::LongMode_Enabled : settings::Hardware::LongMode_Disabled;
            mHWData->mX2APIC = aOsType->i_recommendedX2APIC();
        }
        for (ULONG slot = 0; slot < mNetworkAdapters.size(); ++slot)
            mNetworkAdapters[slot]->i_applyDefaults(aOsType);
        for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); ++slot)
            mSerialPorts[slot]->i_applyDefaults(aOsType);
        for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); ++slot)
            mParallelPorts[slot]->i_applyDefaults();
        i_allowStateModification();
        i_commit();
    }
    if (SUCCEEDED(rc))
    {
        if (mData->mAccessible)
            autoInitSpan.setSucceeded();
        else
            autoInitSpan.setLimited();
    }
    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 & strConfigFile , const Utf8Str & strName , const StringsList & llGroups , GuestOSType * aOsType , const Guid & aId , bool fForceOverwrite , bool fDirectoryIncludesUUID ) { LogFlowThisFuncEnter ( ) ; LogFlowThisFunc ( ( " \n " , strConfigFile . c_str ( ) ) ) ; AutoInitSpan autoInitSpan ( this ) ; AssertReturn ( autoInitSpan . isOk ( ) , E_FAIL ) ; HRESULT rc = initImpl ( aParent , strConfigFile ) ; if ( FAILED ( rc ) ) return rc ; rc = i_tryCreateMachineConfigFile ( fForceOverwrite ) ; if ( FAILED ( rc ) ) return rc ; if ( SUCCEEDED ( rc ) ) { mData -> pMachineConfigFile = new settings :: MachineConfigFile ( NULL ) ; rc = initDataAndChildObjects ( ) ; } if ( SUCCEEDED ( rc ) ) { mData -> mAccessible = TRUE ; unconst ( mData -> mUuid ) = aId ; mUserData -> s . strName = strName ; mUserData -> s . llGroups = llGroups ; mUserData -> s . fDirectoryIncludesUUID = fDirectoryIncludesUUID ; mUserData -> s . fNameSync = i_isInOwnDir ( ) ; rc = COMSETTER ( SnapshotFolder ) ( NULL ) ; AssertComRC ( rc ) ; if ( aOsType ) { mUserData -> s . strOsType = aOsType -> i_id ( ) ; mBIOSSettings -> i_applyDefaults ( aOsType ) ; mHWData -> mLongMode = aOsType -> i_is64Bit ( ) ? settings :: Hardware :: LongMode_Enabled : settings :: Hardware :: LongMode_Disabled ; mHWData -> mX2APIC = aOsType -> i_recommendedX2APIC ( ) ; } for ( ULONG slot = 0 ; slot < mNetworkAdapters . size ( ) ; ++ slot ) mNetworkAdapters [ slot ] -> i_applyDefaults ( aOsType ) ; for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mSerialPorts ) ; ++ slot ) mSerialPorts [ slot ] -> i_applyDefaults ( aOsType ) ; for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mParallelPorts ) ; ++ slot ) mParallelPorts [ slot ] -> i_applyDefaults ( ) ; i_allowStateModification ( ) ; i_commit ( ) ; } if ( SUCCEEDED ( rc ) ) { if ( mData -> mAccessible ) autoInitSpan . setSucceeded ( ) ; else autoInitSpan . setLimited ( ) ; } LogFlowThisFunc ( ( " \n " , ! ! mUserData ? mUserData -> s . strName . c_str ( ) : " " , mData -> mRegistered , mData -> mAccessible , rc ) ) ; LogFlowThisFuncLeave ( ) ; return rc ; }
Initializes a new machine instance; this init() variant creates a new, empty machine.
Initializes a new machine instance ; this init () variant creates a new empty machine .
/* Enclose the state transition NotReady->InInit->Ready */ // create an empty machine config // set to true now to cause uninit() to call uninitDataAndChildObjects() on failure // the "name sync" flag determines whether the machine directory gets renamed along // with the machine file; say so if the settings file name is the same as the // settings file parent directory (machine directory) // initialize the default snapshots folder /* Store OS type */ /* Apply BIOS defaults */ /* Let the OS type select 64-bit ness. */ /* Let the OS type enable the X2APIC */ /* Apply network adapters defaults */ /* Apply serial port defaults */ /* Apply parallel port defaults */ /* 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 */