/** * Initializes the guest object given another guest object * (a kind of copy constructor). This object makes a private copy of data * of the original object passed as an argument. * * @note Locks @a aThat object for reading. */ HRESULT USBDeviceFilter::initCopy(USBDeviceFilters *aParent, USBDeviceFilter *aThat) { LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); unconst(mParent) = aParent; /* mPeer is left null */ m_fModified = false; /* sanity */ AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); bd.attachCopy(aThat->bd); /* reset the arbitrary ID field * (this field is something unique that two distinct objects, even if they * are deep copies of each other, should not share) */ bd->mId = NULL; mInList = aThat->mInList; /* Confirm successful initialization */ autoInitSpan.setSucceeded(); return S_OK; }
/** * Initializes the guest object given another guest object * (a kind of copy constructor). This object makes a private copy of data * of the original object passed as an argument. * * @note Locks @a aThat object for reading. */ HRESULT NetworkAdapter::initCopy(Machine *aParent, NetworkAdapter *aThat) { LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); unconst(mParent) = aParent; /* mPeer is left null */ unconst(mNATEngine).createObject(); mNATEngine->initCopy(aParent, this, aThat->mNATEngine); AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); mData.attachCopy(aThat->mData); /* Confirm a successful initialization */ autoInitSpan.setSucceeded(); return S_OK; }
/** * Initializes the guest object given another guest object * (a kind of copy constructor). This object makes a private copy of data * of the original object passed as an argument. * * @note Locks @a aThat object for reading. */ HRESULT ParallelPort::initCopy(Machine *aParent, ParallelPort *aThat) { LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); m = new Data; unconst(m->pMachine) = aParent; /* m->pPeer is left null */ AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); m->bd.attachCopy(aThat->m->bd); /* Confirm a successful initialization */ autoInitSpan.setSucceeded(); return S_OK; }
/** * @note Locks this object for writing, together with the peer object * represented by @a aThat (locked for reading). */ void USBController::i_copyFrom(USBController *aThat) { AssertReturnVoid(aThat != NULL); /* sanity */ AutoCaller autoCaller(this); AssertComRCReturnVoid(autoCaller.rc()); /* sanity too */ AutoCaller thatCaller(aThat); AssertComRCReturnVoid(thatCaller.rc()); /* even more sanity */ AutoAnyStateDependency adep(m->pParent); AssertComRCReturnVoid(adep.rc()); /* Machine::copyFrom() may not be called when the VM is running */ AssertReturnVoid(!Global::IsOnline(adep.machineState())); /* peer is not modified, lock it for reading (aThat is "master" so locked * first) */ AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS); AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS); /* this will back up current data */ m->bd.assignCopy(aThat->m->bd); }
/** * Initializes the medium attachment object given another guest object * (a kind of copy constructor). This object makes a private copy of data * of the original object passed as an argument. */ HRESULT MediumAttachment::initCopy(Machine *aParent, MediumAttachment *aThat) { LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); m = new Data(aParent); /* m->pPeer is left null */ AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); AutoReadLock thatlock(aThat COMMA_LOCKVAL_SRC_POS); m->bd.attachCopy(aThat->m->bd); /* Confirm a successful initialization */ autoInitSpan.setSucceeded(); /* Construct a short log name for this attachment. */ i_updateLogName(); LogFlowThisFunc(("LEAVE - %s\n", i_getLogName())); return S_OK; }
/** * Initializes the object given another object * (a kind of copy constructor). This object shares data with * the object passed as an argument. * * @param aReshare * When false, the original object will remain a data owner. * Otherwise, data ownership will be transferred from the original * object to this one. * * @note This object must be destroyed before the original object * it shares data with is destroyed. * * @note Locks @a aThat object for writing if @a aReshare is @c true, or for * reading if @a aReshare is false. */ HRESULT USBDeviceFilter::init(USBDeviceFilters *aParent, USBDeviceFilter *aThat, bool aReshare /* = false */) { LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n", aParent, aThat, aReshare)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); unconst(mParent) = aParent; m_fModified = false; /* sanity */ AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); if (aReshare) { AutoWriteLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); unconst(aThat->mPeer) = this; bd.attach(aThat->bd); } else { unconst(mPeer) = aThat; AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); bd.share(aThat->bd); } /* the arbitrary ID field is not reset because * the copy is a shadow of the original */ mInList = aThat->mInList; /* Confirm successful initialization */ autoInitSpan.setSucceeded(); return S_OK; }
/** * @note Locks this object for writing, together with the peer object * represented by @a aThat (locked for reading). */ void USBDeviceFilters::i_copyFrom(USBDeviceFilters *aThat) { AssertReturnVoid(aThat != NULL); /* sanity */ AutoCaller autoCaller(this); AssertComRCReturnVoid(autoCaller.rc()); /* sanity too */ AutoCaller thatCaller(aThat); AssertComRCReturnVoid(thatCaller.rc()); /* even more sanity */ AutoAnyStateDependency adep(m->pParent); AssertComRCReturnVoid(adep.rc()); /* Machine::copyFrom() may not be called when the VM is running */ AssertReturnVoid(!Global::IsOnline(adep.machineState())); /* peer is not modified, lock it for reading (aThat is "master" so locked * first) */ AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS); AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS); #ifdef VBOX_WITH_USB /* Note that we won't inform the USB proxy about new filters since the VM is * not running when we are here and therefore no need to do so */ /* create private copies of all filters */ m->llDeviceFilters.backup(); m->llDeviceFilters->clear(); for (DeviceFilterList::const_iterator it = aThat->m->llDeviceFilters->begin(); it != aThat->m->llDeviceFilters->end(); ++it) { ComObjPtr<USBDeviceFilter> pFilter; pFilter.createObject(); pFilter->initCopy(this, *it); m->llDeviceFilters->push_back(pFilter); } #endif /* VBOX_WITH_USB */ }
/** * @note Locks this object for writing, together with the peer object * represented by @a aThat (locked for reading). */ void NetworkAdapter::copyFrom(NetworkAdapter *aThat) { AssertReturnVoid(aThat != NULL); /* sanity */ AutoCaller autoCaller(this); AssertComRCReturnVoid(autoCaller.rc()); /* sanity too */ AutoCaller thatCaller(aThat); AssertComRCReturnVoid(thatCaller.rc()); /* peer is not modified, lock it for reading (aThat is "master" so locked * first) */ AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS); AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS); /* this will back up current data */ mData.assignCopy(aThat->mData); }
/** * Initializes the object given another object * (a kind of copy constructor). This object shares data with * the object passed as an argument. * * @param aReshare * When false, the original object will remain a data owner. * Otherwise, data ownership will be transferred from the original * object to this one. * * @note This object must be destroyed before the original object * it shares data with is destroyed. * * @note Locks @a aThat object for writing if @a aReshare is @c true, or for * reading if @a aReshare is false. */ HRESULT BandwidthGroup::init(BandwidthControl *aParent, BandwidthGroup *aThat, bool aReshare /* = false */) { LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n", aParent, aThat, aReshare)); ComAssertRet(aParent && aThat, E_INVALIDARG); /* Enclose the state transition NotReady->InInit->Ready */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); m = new Data(aParent); /* sanity */ AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); if (aReshare) { AutoWriteLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); unconst(aThat->m->pPeer) = this; m->bd.attach(aThat->m->bd); } else { unconst(m->pPeer) = aThat; AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); m->bd.share(aThat->m->bd); } /* Confirm successful initialization */ autoInitSpan.setSucceeded(); return S_OK; }
HRESULT NATEngine::initCopy(Machine *aParent, INetworkAdapter *aAdapter, NATEngine *aThat) { AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); Log(("initCopy that:%p this:%p\n", aThat, this)); AutoCaller thatCaller(aThat); AssertComRCReturnRC(thatCaller.rc()); AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS); mData.attachCopy(aThat->mData); NATRuleMap::iterator it; mNATRules.clear(); for (it = aThat->mNATRules.begin(); it != aThat->mNATRules.end(); ++it) { mNATRules.insert(std::make_pair(it->first, it->second)); } unconst(mAdapter) = aAdapter; unconst(mParent) = aParent; autoInitSpan.setSucceeded(); return BaseFinalConstruct(); }