third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 * Commits all the changes to machine settings.
 *
 * Note that this operation is supposed to never fail.
 *
 * @note Locks this object and children for writing.
 */
Commits all the changes to machine settings.
Note that this operation is supposed to never fail.

@note Locks this object and children for writing.
Commits all the changes to machine settings . Note that this operation is supposed to never fail . @note Locks this object and children for writing .
void Machine::i_commit()
{
    AutoCaller autoCaller(this);
    AssertComRCReturnVoid(autoCaller.rc());
    AutoCaller peerCaller(mPeer);
    AssertComRCReturnVoid(peerCaller.rc());
    AutoMultiWriteLock2 alock(mPeer, this COMMA_LOCKVAL_SRC_POS);
    mUserData.commitCopy();
    mHWData.commit();
    if (mMediumAttachments.isBackedUp())
        i_commitMedia(Global::IsOnline(mData->mMachineState));
    mBIOSSettings->i_commit();
    mVRDEServer->i_commit();
    mAudioAdapter->i_commit();
    mUSBDeviceFilters->i_commit();
    mBandwidthControl->i_commit();
    bool commitNetworkAdapters = false;
    size_t newSize = Global::getMaxNetworkAdapters(mHWData->mChipsetType);
    if (mPeer)
    {
        for (size_t slot = 0; slot < mNetworkAdapters.size(); slot++)
            mNetworkAdapters[slot]->i_commit();
        mPeer->mNetworkAdapters.resize(RT_MAX(newSize, mPeer->mNetworkAdapters.size()));
        for (size_t slot = 0; slot < newSize; slot++)
        {
            ComObjPtr<NetworkAdapter> peer = mNetworkAdapters[slot]->i_getPeer();
            if (!peer)
            {
                peer.createObject();
                peer->init(mPeer, mNetworkAdapters[slot], true );
            }
            mPeer->mNetworkAdapters[slot] = peer;
        }
        for (size_t slot = newSize; slot < mNetworkAdapters.size(); ++slot)
            mNetworkAdapters[slot]->uninit();
        for (size_t slot = newSize; slot < mPeer->mNetworkAdapters.size(); ++slot)
        {
            if (mPeer->mNetworkAdapters[slot])
                mPeer->mNetworkAdapters[slot]->uninit();
        }
        mNetworkAdapters.resize(newSize);
        mPeer->mNetworkAdapters.resize(newSize);
    }
    else
    {
        commitNetworkAdapters = true;
    }
    if (commitNetworkAdapters)
        for (size_t slot = 0; slot < mNetworkAdapters.size(); ++slot)
            mNetworkAdapters[slot]->i_commit();
    for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); ++slot)
        mSerialPorts[slot]->i_commit();
    for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); ++slot)
        mParallelPorts[slot]->i_commit();
    bool commitStorageControllers = false;
    if (mStorageControllers.isBackedUp())
    {
        mStorageControllers.commit();
        if (mPeer)
        {
            StorageControllerList *newList = new StorageControllerList();
            for (StorageControllerList::const_iterator
                 it = mStorageControllers->begin();
                 it != mStorageControllers->end();
                 ++it)
            {
                (*it)->i_commit();
                ComObjPtr<StorageController> peer = (*it)->i_getPeer();
                if (!peer)
                {
                    peer.createObject();
                    peer->init(mPeer, *it, true );
                }
                else
                {
                    mPeer->mStorageControllers->remove(peer);
                }
                newList->push_back(peer);
            }
            for (StorageControllerList::const_iterator
                 it = mPeer->mStorageControllers->begin();
                 it != mPeer->mStorageControllers->end();
                 ++it)
            {
                (*it)->uninit();
            }
            mPeer->mStorageControllers.attach(newList);
        }
        else
        {
            commitStorageControllers = true;
        }
    }
    else
    {
        commitStorageControllers = true;
    }
    if (commitStorageControllers)
    {
        for (StorageControllerList::const_iterator
             it = mStorageControllers->begin();
             it != mStorageControllers->end();
             ++it)
        {
            (*it)->i_commit();
        }
    }
    bool commitUSBControllers = false;
    if (mUSBControllers.isBackedUp())
    {
        mUSBControllers.commit();
        if (mPeer)
        {
            USBControllerList *newList = new USBControllerList();
            for (USBControllerList::const_iterator
                 it = mUSBControllers->begin();
                 it != mUSBControllers->end();
                 ++it)
            {
                (*it)->i_commit();
                ComObjPtr<USBController> peer = (*it)->i_getPeer();
                if (!peer)
                {
                    peer.createObject();
                    peer->init(mPeer, *it, true );
                }
                else
                {
                    mPeer->mUSBControllers->remove(peer);
                }
                newList->push_back(peer);
            }
            for (USBControllerList::const_iterator
                 it = mPeer->mUSBControllers->begin();
                 it != mPeer->mUSBControllers->end();
                 ++it)
            {
                (*it)->uninit();
            }
            mPeer->mUSBControllers.attach(newList);
        }
        else
        {
            commitUSBControllers = true;
        }
    }
    else
    {
        commitUSBControllers = true;
    }
    if (commitUSBControllers)
    {
        for (USBControllerList::const_iterator
             it = mUSBControllers->begin();
             it != mUSBControllers->end();
             ++it)
        {
            (*it)->i_commit();
        }
    }
    if (i_isSessionMachine())
    {
        mPeer->mUserData.attach(mUserData);
        mPeer->mHWData.attach(mHWData);
        Assert(mPeer->mMediumAttachments.data() == mMediumAttachments.data());
    }
}
void Machine :: i_commit ( ) { AutoCaller autoCaller ( this ) ; AssertComRCReturnVoid ( autoCaller . rc ( ) ) ; AutoCaller peerCaller ( mPeer ) ; AssertComRCReturnVoid ( peerCaller . rc ( ) ) ; AutoMultiWriteLock2 alock ( mPeer , this COMMA_LOCKVAL_SRC_POS ) ; mUserData . commitCopy ( ) ; mHWData . commit ( ) ; if ( mMediumAttachments . isBackedUp ( ) ) i_commitMedia ( Global :: IsOnline ( mData -> mMachineState ) ) ; mBIOSSettings -> i_commit ( ) ; mVRDEServer -> i_commit ( ) ; mAudioAdapter -> i_commit ( ) ; mUSBDeviceFilters -> i_commit ( ) ; mBandwidthControl -> i_commit ( ) ; bool commitNetworkAdapters = false ; size_t newSize = Global :: getMaxNetworkAdapters ( mHWData -> mChipsetType ) ; if ( mPeer ) { for ( size_t slot = 0 ; slot < mNetworkAdapters . size ( ) ; slot ++ ) mNetworkAdapters [ slot ] -> i_commit ( ) ; mPeer -> mNetworkAdapters . resize ( RT_MAX ( newSize , mPeer -> mNetworkAdapters . size ( ) ) ) ; for ( size_t slot = 0 ; slot < newSize ; slot ++ ) { ComObjPtr < NetworkAdapter > peer = mNetworkAdapters [ slot ] -> i_getPeer ( ) ; if ( ! peer ) { peer . createObject ( ) ; peer -> init ( mPeer , mNetworkAdapters [ slot ] , true ) ; } mPeer -> mNetworkAdapters [ slot ] = peer ; } for ( size_t slot = newSize ; slot < mNetworkAdapters . size ( ) ; ++ slot ) mNetworkAdapters [ slot ] -> uninit ( ) ; for ( size_t slot = newSize ; slot < mPeer -> mNetworkAdapters . size ( ) ; ++ slot ) { if ( mPeer -> mNetworkAdapters [ slot ] ) mPeer -> mNetworkAdapters [ slot ] -> uninit ( ) ; } mNetworkAdapters . resize ( newSize ) ; mPeer -> mNetworkAdapters . resize ( newSize ) ; } else { commitNetworkAdapters = true ; } if ( commitNetworkAdapters ) for ( size_t slot = 0 ; slot < mNetworkAdapters . size ( ) ; ++ slot ) mNetworkAdapters [ slot ] -> i_commit ( ) ; for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mSerialPorts ) ; ++ slot ) mSerialPorts [ slot ] -> i_commit ( ) ; for ( ULONG slot = 0 ; slot < RT_ELEMENTS ( mParallelPorts ) ; ++ slot ) mParallelPorts [ slot ] -> i_commit ( ) ; bool commitStorageControllers = false ; if ( mStorageControllers . isBackedUp ( ) ) { mStorageControllers . commit ( ) ; if ( mPeer ) { StorageControllerList * newList = new StorageControllerList ( ) ; for ( StorageControllerList :: const_iterator it = mStorageControllers -> begin ( ) ; it != mStorageControllers -> end ( ) ; ++ it ) { ( * it ) -> i_commit ( ) ; ComObjPtr < StorageController > peer = ( * it ) -> i_getPeer ( ) ; if ( ! peer ) { peer . createObject ( ) ; peer -> init ( mPeer , * it , true ) ; } else { mPeer -> mStorageControllers -> remove ( peer ) ; } newList -> push_back ( peer ) ; } for ( StorageControllerList :: const_iterator it = mPeer -> mStorageControllers -> begin ( ) ; it != mPeer -> mStorageControllers -> end ( ) ; ++ it ) { ( * it ) -> uninit ( ) ; } mPeer -> mStorageControllers . attach ( newList ) ; } else { commitStorageControllers = true ; } } else { commitStorageControllers = true ; } if ( commitStorageControllers ) { for ( StorageControllerList :: const_iterator it = mStorageControllers -> begin ( ) ; it != mStorageControllers -> end ( ) ; ++ it ) { ( * it ) -> i_commit ( ) ; } } bool commitUSBControllers = false ; if ( mUSBControllers . isBackedUp ( ) ) { mUSBControllers . commit ( ) ; if ( mPeer ) { USBControllerList * newList = new USBControllerList ( ) ; for ( USBControllerList :: const_iterator it = mUSBControllers -> begin ( ) ; it != mUSBControllers -> end ( ) ; ++ it ) { ( * it ) -> i_commit ( ) ; ComObjPtr < USBController > peer = ( * it ) -> i_getPeer ( ) ; if ( ! peer ) { peer . createObject ( ) ; peer -> init ( mPeer , * it , true ) ; } else { mPeer -> mUSBControllers -> remove ( peer ) ; } newList -> push_back ( peer ) ; } for ( USBControllerList :: const_iterator it = mPeer -> mUSBControllers -> begin ( ) ; it != mPeer -> mUSBControllers -> end ( ) ; ++ it ) { ( * it ) -> uninit ( ) ; } mPeer -> mUSBControllers . attach ( newList ) ; } else { commitUSBControllers = true ; } } else { commitUSBControllers = true ; } if ( commitUSBControllers ) { for ( USBControllerList :: const_iterator it = mUSBControllers -> begin ( ) ; it != mUSBControllers -> end ( ) ; ++ it ) { ( * it ) -> i_commit ( ) ; } } if ( i_isSessionMachine ( ) ) { mPeer -> mUserData . attach ( mUserData ) ; mPeer -> mHWData . attach ( mHWData ) ; Assert ( mPeer -> mMediumAttachments . data ( ) == mMediumAttachments . data ( ) ) ; } }
Commits all the changes to machine settings.
Commits all the changes to machine settings .
/*
     *  use safe commit to ensure Snapshot machines (that share mUserData)
     *  will still refer to a valid memory location
     */ /* Since mNetworkAdapters is a list which might have been changed (resized)
     * without using the Backupable<> template we need to handle the copying
     * of the list entries manually, including the creation of peers for the
     * new objects. */ /* commit everything, even the ones which will go away */ /* copy over the new entries, creating a peer and uninit the original */ /* look if this adapter has a peer device */ /* no peer means the adapter is a newly created one;
                 * create a peer owning data this data share it with */ /* aReshare */ /* uninit any no longer needed network adapters */ /* Keep the original network adapter count until this point, so that
         * discarding a chipset type change will not lose settings. */ /* we have no peer (our parent is the newly created machine);
         * just commit changes to the network adapters */ /* Commit all changes to new controllers (this will reshare data with
             * peers for those who have peers) */ /* look if this controller has a peer device */ /* no peer means the device is a newly created one;
                     * create a peer owning data this device share it with */ /* aReshare */ /* remove peer from the old list */ /* and add it to the new list */ /* uninit old peer's controllers that are left */ /* attach new list of controllers to our peer */ /* we have no peer (our parent is the newly created machine);
             * just commit changes to devices */ /* the list of controllers itself is not changed,
         * just commit changes to controllers themselves */ /* Commit all changes to new controllers (this will reshare data with
             * peers for those who have peers) */ /* look if this controller has a peer device */ /* no peer means the device is a newly created one;
                     * create a peer owning data this device share it with */ /* aReshare */ /* remove peer from the old list */ /* and add it to the new list */ /* uninit old peer's controllers that are left */ /* attach new list of controllers to our peer */ /* we have no peer (our parent is the newly created machine);
             * just commit changes to devices */ /* the list of controllers itself is not changed,
         * just commit changes to controllers themselves */ /* attach new data to the primary machine and reshare it */ /* mmMediumAttachments is reshared by fixupMedia */ // mPeer->mMediumAttachments.attach(mMediumAttachments);