- Timestamp:
- Aug 15, 2012 1:59:01 PM (12 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/NetworkAdapterImpl.h
r42551 r42825 90 90 // public initializer/uninitializer for internal purposes only 91 91 HRESULT init(Machine *aParent, ULONG aSlot); 92 HRESULT init(Machine *aParent, NetworkAdapter *aThat );92 HRESULT init(Machine *aParent, NetworkAdapter *aThat, bool aReshare = false); 93 93 HRESULT initCopy(Machine *aParent, NetworkAdapter *aThat); 94 94 void uninit(); … … 148 148 void applyDefaults(GuestOSType *aOsType); 149 149 150 ComObjPtr<NetworkAdapter> getPeer(); 151 150 152 private: 151 153 -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r42823 r42825 9101 9101 Utf8Str newConfigBaseDir(newConfigDir); 9102 9102 newConfigDir.append(newGroupPlusName); 9103 /* consistency: use \ if appropriate on the platform */ 9104 RTPathChangeToDosSlashes(newConfigDir.mutableRaw(), false); 9103 9105 /* new dir and old dir cannot be equal here because of 'if' 9104 9106 * above and because name != newName */ … … 11017 11019 mBandwidthControl->commit(); 11018 11020 11019 /* Keep the original network adapter count until this point, so that 11020 * discarding a chipset type change will not lose settings. */ 11021 mNetworkAdapters.resize(Global::getMaxNetworkAdapters(mHWData->mChipsetType)); 11022 for (ULONG slot = 0; slot < mNetworkAdapters.size(); slot++) 11023 mNetworkAdapters[slot]->commit(); 11021 /* Since mNetworkAdapters is a list which might have been changed (resized) 11022 * without using the Backupable<> template we need to handle the copying 11023 * of the list entries manually, including the creation of peers for the 11024 * new objects. */ 11025 bool commitNetworkAdapters = false; 11026 size_t newSize = Global::getMaxNetworkAdapters(mHWData->mChipsetType); 11027 if (mPeer) 11028 { 11029 /* commit everything, even the ones which will go away */ 11030 for (size_t slot = 0; slot < mNetworkAdapters.size(); slot++) 11031 mNetworkAdapters[slot]->commit(); 11032 /* copy over the new entries, creating a peer and uninit the original */ 11033 mPeer->mNetworkAdapters.resize(RT_MAX(newSize, mPeer->mNetworkAdapters.size())); 11034 for (size_t slot = 0; slot < newSize; slot++) 11035 { 11036 /* look if this adapter has a peer device */ 11037 ComObjPtr<NetworkAdapter> peer = mNetworkAdapters[slot]->getPeer(); 11038 if (!peer) 11039 { 11040 /* no peer means the adapter is a newly created one; 11041 * create a peer owning data this data share it with */ 11042 peer.createObject(); 11043 peer->init(mPeer, mNetworkAdapters[slot], true /* aReshare */); 11044 } 11045 mPeer->mNetworkAdapters[slot] = peer; 11046 } 11047 /* uninit any no longer needed network adapters */ 11048 for (size_t slot = newSize; slot < mNetworkAdapters.size(); slot++) 11049 mNetworkAdapters[slot]->uninit(); 11050 for (size_t slot = newSize; slot < mPeer->mNetworkAdapters.size(); slot++) 11051 { 11052 if (mPeer->mNetworkAdapters[slot]) 11053 mPeer->mNetworkAdapters[slot]->uninit(); 11054 } 11055 /* Keep the original network adapter count until this point, so that 11056 * discarding a chipset type change will not lose settings. */ 11057 mNetworkAdapters.resize(newSize); 11058 mPeer->mNetworkAdapters.resize(newSize); 11059 } 11060 else 11061 { 11062 /* we have no peer (our parent is the newly created machine); 11063 * just commit changes to the network adapters */ 11064 commitNetworkAdapters = true; 11065 } 11066 if (commitNetworkAdapters) 11067 { 11068 for (size_t slot = 0; slot < mNetworkAdapters.size(); slot++) 11069 mNetworkAdapters[slot]->commit(); 11070 } 11071 11024 11072 for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); slot++) 11025 11073 mSerialPorts[slot]->commit(); … … 11035 11083 if (mPeer) 11036 11084 { 11037 AutoWriteLock peerlock(mPeer COMMA_LOCKVAL_SRC_POS);11038 11039 11085 /* Commit all changes to new controllers (this will reshare data with 11040 11086 * peers for those who have peers) */ -
trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp
r42551 r42825 108 108 * the object passed as an argument. 109 109 * 110 * @param aReshare 111 * When false, the original object will remain a data owner. 112 * Otherwise, data ownership will be transferred from the original 113 * object to this one. 114 * 110 115 * @note This object must be destroyed before the original object 111 116 * it shares data with is destroyed. … … 113 118 * @note Locks @a aThat object for reading. 114 119 */ 115 HRESULT NetworkAdapter::init(Machine *aParent, NetworkAdapter *aThat )116 { 117 LogFlowThisFunc(("aParent=%p, aThat=%p \n", aParent, aThat));120 HRESULT NetworkAdapter::init(Machine *aParent, NetworkAdapter *aThat, bool aReshare /* = false */) 121 { 122 LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n", aParent, aThat, aReshare)); 118 123 119 124 ComAssertRet(aParent && aThat, E_INVALIDARG); … … 124 129 125 130 unconst(mParent) = aParent; 126 unconst(mPeer) = aThat;127 131 unconst(mNATEngine).createObject(); 128 132 mNATEngine->init(aParent, this, aThat->mNATEngine); 129 133 134 /* sanity */ 130 135 AutoCaller thatCaller(aThat); 131 136 AssertComRCReturnRC(thatCaller.rc()); 132 137 133 AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); 134 mData.share(aThat->mData); 138 if (aReshare) 139 { 140 AutoWriteLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); 141 142 unconst(aThat->mPeer) = this; 143 mData.attach(aThat->mData); 144 } 145 else 146 { 147 unconst(mPeer) = aThat; 148 149 AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); 150 mData.share(aThat->mData); 151 } 135 152 136 153 /* Confirm a successful initialization */ … … 1372 1389 } 1373 1390 1391 ComObjPtr<NetworkAdapter> NetworkAdapter::getPeer() 1392 { 1393 return mPeer; 1394 } 1395 1396 1374 1397 // private methods 1375 1398 ////////////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.