third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  @note Must be called only by Machine::LockMachine() from its own write lock.
 */
@note Must be called only by Machine::LockMachine() from its own write lock.
@note Must be called only by Machine :: LockMachine () from its own write lock .
HRESULT SessionMachine::init(Machine *aMachine)
{
    LogFlowThisFuncEnter();
    LogFlowThisFunc(("mName={%s}\n", aMachine->mUserData->s.strName.c_str()));
    AssertReturn(aMachine, E_INVALIDARG);
    AssertReturn(aMachine->lockHandle()->isWriteLockOnCurrentThread(), E_FAIL);
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    HRESULT rc = S_OK;
    RT_ZERO(mAuthLibCtx);
    try
    {
        mClientToken = new ClientToken(aMachine, this);
        if (!mClientToken->isReady())
        {
            delete mClientToken;
            mClientToken = NULL;
            rc = E_FAIL;
        }
    }
    catch (std::bad_alloc &)
    {
        rc = E_OUTOFMEMORY;
    }
    if (FAILED(rc))
        return rc;
    unconst(mPeer) = aMachine;
    unconst(mParent) = aMachine->mParent;
    mData.share(aMachine->mData);
    mSSData.share(aMachine->mSSData);
    mUserData.share(aMachine->mUserData);
    mHWData.share(aMachine->mHWData);
    mMediumAttachments.share(aMachine->mMediumAttachments);
    mStorageControllers.allocate();
    for (StorageControllerList::const_iterator
         it = aMachine->mStorageControllers->begin();
         it != aMachine->mStorageControllers->end();
         ++it)
    {
        ComObjPtr<StorageController> ctl;
        ctl.createObject();
        ctl->init(this, *it);
        mStorageControllers->push_back(ctl);
    }
    mUSBControllers.allocate();
    for (USBControllerList::const_iterator
         it = aMachine->mUSBControllers->begin();
         it != aMachine->mUSBControllers->end();
         ++it)
    {
        ComObjPtr<USBController> ctl;
        ctl.createObject();
        ctl->init(this, *it);
        mUSBControllers->push_back(ctl);
    }
    unconst(mBIOSSettings).createObject();
    mBIOSSettings->init(this, aMachine->mBIOSSettings);
    unconst(mVRDEServer).createObject();
    mVRDEServer->init(this, aMachine->mVRDEServer);
    unconst(mAudioAdapter).createObject();
    mAudioAdapter->init(this, aMachine->mAudioAdapter);
    for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); ++slot)
    {
        unconst(mSerialPorts[slot]).createObject();
        mSerialPorts[slot]->init(this, aMachine->mSerialPorts[slot]);
    }
    for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); ++slot)
    {
        unconst(mParallelPorts[slot]).createObject();
        mParallelPorts[slot]->init(this, aMachine->mParallelPorts[slot]);
    }
    unconst(mUSBDeviceFilters).createObject();
    mUSBDeviceFilters->init(this, aMachine->mUSBDeviceFilters);
    mNetworkAdapters.resize(aMachine->mNetworkAdapters.size());
    for (ULONG slot = 0; slot < mNetworkAdapters.size(); ++slot)
    {
        unconst(mNetworkAdapters[slot]).createObject();
        mNetworkAdapters[slot]->init(this, aMachine->mNetworkAdapters[slot]);
    }
    unconst(mBandwidthControl).createObject();
    mBandwidthControl->init(this, aMachine->mBandwidthControl);
    mRemoveSavedState = true;
    autoInitSpan.setSucceeded();
    miNATNetworksStarted = 0;
    LogFlowThisFuncLeave();
    return rc;
}
HRESULT SessionMachine :: init ( Machine * aMachine ) { LogFlowThisFuncEnter ( ) ; LogFlowThisFunc ( ( " \n " , aMachine -> mUserData -> s . strName . c_str ( ) ) ) ; AssertReturn ( aMachine , E_INVALIDARG ) ; AssertReturn ( aMachine -> lockHandle ( ) -> isWriteLockOnCurrentThread ( ) , E_FAIL ) ; AutoInitSpan autoInitSpan ( this ) ; AssertReturn ( autoInitSpan . isOk ( ) , E_FAIL ) ; HRESULT rc = S_OK ; RT_ZERO ( mAuthLibCtx ) ; try { mClientToken = new ClientToken ( aMachine , this ) ; if ( ! mClientToken -> isReady ( ) ) { delete mClientToken ; mClientToken = NULL ; rc = E_FAIL ; } } catch ( std :: bad_alloc & ) { rc = E_OUTOFMEMORY ; } if ( FAILED ( rc ) ) return rc ; unconst ( mPeer ) = aMachine ; unconst ( mParent ) = aMachine -> mParent ; mData . share ( aMachine -> mData ) ; mSSData . share ( aMachine -> mSSData ) ; mUserData . share ( aMachine -> mUserData ) ; mHWData . share ( aMachine -> mHWData ) ; mMediumAttachments . share ( aMachine -> mMediumAttachments ) ; mStorageControllers . allocate ( ) ; for ( StorageControllerList :: const_iterator it = aMachine -> mStorageControllers -> begin ( ) ; it != aMachine -> mStorageControllers -> end ( ) ; ++ it ) { ComObjPtr < StorageController > ctl ; ctl . createObject ( ) ; ctl -> init ( this , * it ) ; mStorageControllers -> push_back ( ctl ) ; } mUSBControllers . allocate ( ) ; for ( USBControllerList :: const_iterator it = aMachine -> mUSBControllers -> begin ( ) ; it != aMachine -> mUSBControllers -> end ( ) ; ++ it ) { ComObjPtr < USBController > ctl ; ctl . createObject ( ) ; ctl -> init ( this , * it ) ; mUSBControllers -> push_back ( ctl ) ; } unconst ( mBIOSSettings ) . createObject ( ) ; mBIOSSettings -> init ( this , aMachine -> mBIOSSettings ) ; unconst ( mVRDEServer ) . createObject ( ) ; mVRDEServer -> init ( this , aMachine -> mVRDEServer ) ; unconst ( mAudioAdapter ) . createObject ( ) ; mAudioAdapter -> init ( this , aMachine -> mAudioAdapter ) ; for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mSerialPorts ) ; ++ slot ) { unconst ( mSerialPorts [ slot ] ) . createObject ( ) ; mSerialPorts [ slot ] -> init ( this , aMachine -> mSerialPorts [ slot ] ) ; } for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mParallelPorts ) ; ++ slot ) { unconst ( mParallelPorts [ slot ] ) . createObject ( ) ; mParallelPorts [ slot ] -> init ( this , aMachine -> mParallelPorts [ slot ] ) ; } unconst ( mUSBDeviceFilters ) . createObject ( ) ; mUSBDeviceFilters -> init ( this , aMachine -> mUSBDeviceFilters ) ; mNetworkAdapters . resize ( aMachine -> mNetworkAdapters . size ( ) ) ; for ( ULONG slot = 0 ; slot < mNetworkAdapters . size ( ) ; ++ slot ) { unconst ( mNetworkAdapters [ slot ] ) . createObject ( ) ; mNetworkAdapters [ slot ] -> init ( this , aMachine -> mNetworkAdapters [ slot ] ) ; } unconst ( mBandwidthControl ) . createObject ( ) ; mBandwidthControl -> init ( this , aMachine -> mBandwidthControl ) ; mRemoveSavedState = true ; autoInitSpan . setSucceeded ( ) ; miNATNetworksStarted = 0 ; LogFlowThisFuncLeave ( ) ; return rc ; }
@note Must be called only by Machine::LockMachine() from its own write lock.
@note Must be called only by Machine :: LockMachine () from its own write lock .
/* Enclose the state transition NotReady->InInit->Ready */ /* create the machine client token */ /* memorize the peer Machine */ /* share the parent pointer */ /* take the pointers to data to share */ /* create another VRDEServer object that will be mutable */ /* create another audio adapter object that will be mutable */ /* create a list of serial ports that will be mutable */ /* create a list of parallel ports that will be mutable */ /* create another USB device filters object that will be mutable */ /* create a list of network adapters that will be mutable */ /* create another bandwidth control object that will be mutable */ /* default is to delete saved state on Saved -> PoweredOff transition */ /* Confirm a successful initialization when it's the case */