HRESULT SerialPort::setServer(BOOL aServer) { /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->fServer != !!aServer) { m->bd.backup(); m->bd->fServer = !!aServer; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_SerialPorts); mlock.release(); m->pMachine->i_onSerialPortChange(this); } return S_OK; }
HRESULT SerialPort::setIRQ(ULONG aIRQ) { /* check IRQ limits * (when changing this, make sure it corresponds to XML schema */ if (aIRQ > 255) return setError(E_INVALIDARG, tr("Invalid IRQ number of the serial port %d: %lu (must be in range [0, %lu])"), m->bd->ulSlot, aIRQ, 255); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->ulIRQ != aIRQ) { m->bd.backup(); m->bd->ulIRQ = aIRQ; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_SerialPorts); mlock.release(); m->pMachine->i_onSerialPortChange(this); } return S_OK; }
HRESULT SerialPort::setPath(const com::Utf8Str &aPath) { /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (aPath != m->bd->strPath) { HRESULT rc = i_checkSetPath(aPath); if (FAILED(rc)) return rc; m->bd.backup(); m->bd->strPath = aPath; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_SerialPorts); mlock.release(); m->pMachine->i_onSerialPortChange(this); } return S_OK; }
HRESULT USBDeviceFilter::setName(const com::Utf8Str &aName) { /* the machine needs to be mutable */ AutoMutableOrSavedOrRunningStateDependency adep(mParent->i_getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mName != aName) { m_fModified = true; ComObjPtr<Machine> pMachine = mParent->i_getMachine(); mData.backup(); mData->mName = aName; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->i_setModified(Machine::IsModified_USB); mlock.release(); return mParent->i_onDeviceFilterChange(this); } return S_OK; }
HRESULT SerialPort::setEnabled(BOOL aEnabled) { LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled)); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->fEnabled != !!aEnabled) { m->bd.backup(); m->bd->fEnabled = !!aEnabled; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_SerialPorts); mlock.release(); m->pMachine->i_onSerialPortChange(this); } return S_OK; }
HRESULT ParallelPort::setIOBase(ULONG aIOBase) { /* check IOBase limits * (when changing this, make sure it corresponds to XML schema */ if (aIOBase > 0xFFFF) return setError(E_INVALIDARG, tr("Invalid I/O port base address of the parallel port %d: %lu (must be in range [0, 0x%X])"), m->bd->ulSlot, aIOBase, 0, 0xFFFF); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->ulIOBase != aIOBase) { m->bd.backup(); m->bd->ulIOBase = aIOBase; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_ParallelPorts); mlock.release(); m->pMachine->i_onParallelPortChange(this); } return S_OK; }
HRESULT SerialPort::setHostMode(PortMode_T aHostMode) { /* the machine needs to be mutable */ AutoMutableOrSavedStateDependency adep(m->pMachine); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->portMode != aHostMode) { switch (aHostMode) { case PortMode_RawFile: if (m->bd->strPath.isEmpty()) return setError(E_INVALIDARG, tr("Cannot set the raw file mode of the serial port %d " "because the file path is empty or null"), m->bd->ulSlot); break; case PortMode_HostPipe: if (m->bd->strPath.isEmpty()) return setError(E_INVALIDARG, tr("Cannot set the host pipe mode of the serial port %d " "because the pipe path is empty or null"), m->bd->ulSlot); break; case PortMode_HostDevice: if (m->bd->strPath.isEmpty()) return setError(E_INVALIDARG, tr("Cannot set the host device mode of the serial port %d " "because the device path is empty or null"), m->bd->ulSlot); break; case PortMode_TCP: if (m->bd->strPath.isEmpty()) return setError(E_INVALIDARG, tr("Cannot set the host device mode of the serial port %d " "because the server address or TCP port is invalid"), m->bd->ulSlot); break; case PortMode_Disconnected: break; } m->bd.backup(); m->bd->portMode = aHostMode; m->fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); m->pMachine->i_setModified(Machine::IsModified_SerialPorts); mlock.release(); m->pMachine->i_onSerialPortChange(this); } return S_OK; }
STDMETHODIMP AudioAdapter::COMSETTER(AudioDriver)(AudioDriverType_T aAudioDriver) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); HRESULT rc = S_OK; if (mData->mAudioDriver != aAudioDriver) { if (settings::MachineConfigFile::isAudioDriverAllowedOnThisHost(aAudioDriver)) { mData.backup(); mData->mAudioDriver = aAudioDriver; alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking mParent->setModified(Machine::IsModified_AudioAdapter); } else { AssertMsgFailed(("Wrong audio driver type %d\n", aAudioDriver)); rc = E_FAIL; } } return rc; }
STDMETHODIMP StorageController::COMSETTER(UseHostIOCache) (BOOL fUseHostIOCache) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->fUseHostIOCache != !!fUseHostIOCache) { m->bd.backup(); m->bd->fUseHostIOCache = !!fUseHostIOCache; alock.release(); AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); // m->pParent is const, needs no locking m->pParent->setModified(Machine::IsModified_Storage); mlock.release(); m->pParent->onStorageControllerChange(); } return S_OK; }
STDMETHODIMP USBDeviceFilter::COMSETTER(MaskedInterfaces) (ULONG aMaskedIfs) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent->getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mMaskedIfs != aMaskedIfs) { m_fModified = true; ComObjPtr<Machine> pMachine = mParent->getMachine(); mData.backup(); mData->mMaskedIfs = aMaskedIfs; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->setModified(Machine::IsModified_USB); mlock.release(); return mParent->onDeviceFilterChange(this); } return S_OK; }
STDMETHODIMP USBDeviceFilter::COMSETTER(Name) (IN_BSTR aName) { CheckComArgStrNotEmptyOrNull(aName); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent->getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mName != aName) { m_fModified = true; ComObjPtr<Machine> pMachine = mParent->getMachine(); mData.backup(); mData->mName = aName; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->setModified(Machine::IsModified_USB); mlock.release(); return mParent->onDeviceFilterChange(this); } 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); }
HRESULT USBDeviceFilters::createDeviceFilter(const com::Utf8Str &aName, ComPtr<IUSBDeviceFilter> &aFilter) { #ifdef VBOX_WITH_USB /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); ComObjPtr<USBDeviceFilter> pFilter; pFilter.createObject(); HRESULT rc = pFilter->init(this, Bstr(aName).raw()); ComAssertComRCRetRC(rc); rc = pFilter.queryInterfaceTo(aFilter.asOutParam()); AssertComRCReturnRC(rc); return S_OK; #else NOREF(aName); NOREF(aFilter); ReturnComNotImplemented(); #endif }
HRESULT USBDeviceFilters::insertDeviceFilter(ULONG aPosition, const ComPtr<IUSBDeviceFilter> &aFilter) { #ifdef VBOX_WITH_USB /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); IUSBDeviceFilter *iFilter = aFilter; ComObjPtr<USBDeviceFilter> pFilter = static_cast<USBDeviceFilter*>(iFilter); if (pFilter->mInList) return setError(VBOX_E_INVALID_OBJECT_STATE, tr("The given USB device pFilter is already in the list")); /* backup the list before modification */ m->llDeviceFilters.backup(); /* iterate to the position... */ DeviceFilterList::iterator it; if (aPosition < m->llDeviceFilters->size()) { it = m->llDeviceFilters->begin(); std::advance(it, aPosition); } else it = m->llDeviceFilters->end(); /* ...and insert */ m->llDeviceFilters->insert(it, pFilter); pFilter->mInList = true; /* notify the proxy (only when it makes sense) */ if (pFilter->i_getData().mActive && Global::IsOnline(adep.machineState()) && pFilter->i_getData().mRemote.isMatch(false)) { USBProxyService *pProxySvc = m->pHost->i_usbProxyService(); ComAssertRet(pProxySvc, E_FAIL); ComAssertRet(pFilter->i_getId() == NULL, E_FAIL); pFilter->i_getId() = pProxySvc->insertFilter(&pFilter->i_getData().mUSBFilter); } alock.release(); AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); m->pParent->i_setModified(Machine::IsModified_USB); mlock.release(); return S_OK; #else /* VBOX_WITH_USB */ NOREF(aPosition); NOREF(aFilter); ReturnComNotImplemented(); #endif /* VBOX_WITH_USB */ }
HRESULT USBDeviceFilter::setMaskedInterfaces(ULONG aMaskedIfs) { /* the machine needs to be mutable */ AutoMutableOrSavedOrRunningStateDependency adep(mParent->i_getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (bd->mData.ulMaskedInterfaces != aMaskedIfs) { m_fModified = true; ComObjPtr<Machine> pMachine = mParent->i_getMachine(); bd.backup(); bd->mData.ulMaskedInterfaces = aMaskedIfs; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->i_setModified(Machine::IsModified_USB); mlock.release(); return mParent->i_onDeviceFilterChange(this); } return S_OK; }
HRESULT USBDeviceFilter::setRemote(const com::Utf8Str &aRemote) { /* the machine needs to be mutable */ AutoMutableOrSavedOrRunningStateDependency adep(mParent->i_getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); Bstr bRemote = Bstr(aRemote).raw(); if (bd->mRemote.string() != bRemote) { BackupableUSBDeviceFilterData::BOOLFilter flt = bRemote; ComAssertRet(!flt.isNull(), E_FAIL); if (!flt.isValid()) return setError(E_INVALIDARG, tr("Remote state filter string '%s' is not valid (error at position %d)"), aRemote.c_str(), flt.errorPosition() + 1); m_fModified = true; ComObjPtr<Machine> pMachine = mParent->i_getMachine(); bd.backup(); bd->mRemote = flt; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->i_setModified(Machine::IsModified_USB); mlock.release(); return mParent->i_onDeviceFilterChange(this); } return S_OK; }
HRESULT USBController::setName(const com::Utf8Str &aName) { /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoMultiWriteLock2 alock(m->pParent, this COMMA_LOCKVAL_SRC_POS); if (m->bd->strName != aName) { ComObjPtr<USBController> ctrl; HRESULT rc = m->pParent->i_getUSBControllerByName(aName, ctrl, false /* aSetError */); if (SUCCEEDED(rc)) return setError(VBOX_E_OBJECT_IN_USE, tr("USB controller named '%s' already exists"), aName.c_str()); m->bd.backup(); m->bd->strName = aName; m->pParent->i_setModified(Machine::IsModified_USB); alock.release(); m->pParent->i_onUSBControllerChange(); } return S_OK; }
STDMETHODIMP USBController::COMSETTER(EnabledEhci) (BOOL aEnabled) { LogFlowThisFunc(("aEnabled=%RTbool\n", aEnabled)); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (m->bd->fEnabledEHCI != aEnabled) { m->bd.backup(); m->bd->fEnabledEHCI = aEnabled; // leave the lock for safety alock.release(); AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); m->pParent->setModified(Machine::IsModified_USB); mlock.release(); m->pParent->onUSBControllerChange(); } return S_OK; }
HRESULT USBDeviceFilter::setActive(const BOOL aActive) { /* the machine needs to be mutable */ AutoMutableOrSavedOrRunningStateDependency adep(mParent->i_getMachine()); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (bd->mData.fActive != RT_BOOL(aActive)) { m_fModified = true; ComObjPtr<Machine> pMachine = mParent->i_getMachine(); bd.backup(); bd->mData.fActive = RT_BOOL(aActive); // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(pMachine COMMA_LOCKVAL_SRC_POS); pMachine->i_setModified(Machine::IsModified_USB); mlock.release(); return mParent->i_onDeviceFilterChange(this, TRUE /* aActiveChanged */); } return S_OK; }
STDMETHODIMP USBController::CreateDeviceFilter (IN_BSTR aName, IUSBDeviceFilter **aFilter) { #ifdef VBOX_WITH_USB CheckComArgOutPointerValid(aFilter); CheckComArgStrNotEmptyOrNull(aName); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(m->pParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); ComObjPtr<USBDeviceFilter> filter; filter.createObject(); HRESULT rc = filter->init (this, aName); ComAssertComRCRetRC (rc); rc = filter.queryInterfaceTo(aFilter); AssertComRCReturnRC(rc); return S_OK; #else NOREF(aName); NOREF(aFilter); ReturnComNotImplemented(); #endif }
STDMETHODIMP NetworkAdapter::COMSETTER(TraceEnabled)(BOOL aEnabled) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (aEnabled != mData->mTraceEnabled) { mData.backup(); mData->mTraceEnabled = aEnabled; m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Adapt the CFGM logic changeAdapter=TRUE */ mParent->onNetworkAdapterChange(this, TRUE); } return S_OK; }
STDMETHODIMP NetworkAdapter::COMSETTER(BootPriority)(ULONG aBootPriority) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (aBootPriority != mData->mBootPriority) { mData.backup(); mData->mBootPriority = aBootPriority; m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* No change in CFGM logic => changeAdapter=FALSE. */ mParent->onNetworkAdapterChange(this, FALSE); } return S_OK; }
STDMETHODIMP NetworkAdapter::COMSETTER(NATNetwork)(IN_BSTR aNATNetwork) { Bstr bstrEmpty(""); if (!aNATNetwork) aNATNetwork = bstrEmpty.raw(); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mNATNetwork != aNATNetwork) { mData.backup(); mData->mNATNetwork = aNATNetwork; m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Changing the NAT network isn't allowed during runtime, therefore * no immediate replug in CFGM logic => changeAdapter=FALSE */ mParent->onNetworkAdapterChange(this, FALSE); } return S_OK; }
STDMETHODIMP NetworkAdapter::COMSETTER(GenericDriver)(IN_BSTR aGenericDriver) { Bstr bstrEmpty(""); if (!aGenericDriver) aGenericDriver = bstrEmpty.raw(); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mGenericDriver != aGenericDriver) { mData.backup(); mData->mGenericDriver = aGenericDriver; /* leave the lock before informing callbacks */ alock.release(); mParent->onNetworkAdapterChange(this, FALSE); } return S_OK; }
STDMETHODIMP NetworkAdapter::COMSETTER(MACAddress)(IN_BSTR aMACAddress) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); mData.backup(); HRESULT rc = updateMacAddress(aMACAddress); if (SUCCEEDED(rc)) { m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Changing the MAC via the Main API during runtime is not allowed, * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */ mParent->onNetworkAdapterChange(this, FALSE); } return rc; }
STDMETHODIMP NetworkAdapter::COMSETTER(Enabled)(BOOL aEnabled) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mData->mEnabled != aEnabled) { mData.backup(); mData->mEnabled = aEnabled; m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Disabling the network adapter during runtime is not allowed * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */ mParent->onNetworkAdapterChange(this, FALSE); } return S_OK; }
/** * Called by setter methods of all USB device filters. * * @note Locks nothing. */ HRESULT USBController::onDeviceFilterChange (USBDeviceFilter *aFilter, BOOL aActiveChanged /* = FALSE */) { AutoCaller autoCaller(this); AssertComRCReturnRC(autoCaller.rc()); /* we need the machine state */ AutoAnyStateDependency adep(m->pParent); AssertComRCReturnRC(adep.rc()); /* nothing to do if the machine isn't running */ if (!Global::IsOnline (adep.machineState())) return S_OK; /* we don't modify our data fields -- no need to lock */ if ( aFilter->mInList && m->pParent->isRegistered()) { USBProxyService *service = m->pHost->usbProxyService(); ComAssertRet(service, E_FAIL); if (aActiveChanged) { if (aFilter->getData().mRemote.isMatch (false)) { /* insert/remove the filter from the proxy */ if (aFilter->getData().mActive) { ComAssertRet(aFilter->getId() == NULL, E_FAIL); aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter); } else { ComAssertRet(aFilter->getId() != NULL, E_FAIL); service->removeFilter(aFilter->getId()); aFilter->getId() = NULL; } } } else { if (aFilter->getData().mActive) { /* update the filter in the proxy */ ComAssertRet(aFilter->getId() != NULL, E_FAIL); service->removeFilter(aFilter->getId()); if (aFilter->getData().mRemote.isMatch (false)) { aFilter->getId() = service->insertFilter(&aFilter->getData().mUSBFilter); } } } } return S_OK; }
/** @note Locks objects for writing! */ void USBController::i_rollback() { AutoCaller autoCaller(this); AssertComRCReturnVoid(autoCaller.rc()); /* we need the machine state */ AutoAnyStateDependency adep(m->pParent); AssertComRCReturnVoid(adep.rc()); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); m->bd.rollback(); }
STDMETHODIMP NetworkAdapter::COMSETTER(AdapterType)(NetworkAdapterType_T aAdapterType) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* the machine needs to be mutable */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* make sure the value is allowed */ switch (aAdapterType) { case NetworkAdapterType_Am79C970A: case NetworkAdapterType_Am79C973: #ifdef VBOX_WITH_E1000 case NetworkAdapterType_I82540EM: case NetworkAdapterType_I82543GC: case NetworkAdapterType_I82545EM: #endif #ifdef VBOX_WITH_VIRTIO case NetworkAdapterType_Virtio: #endif /* VBOX_WITH_VIRTIO */ break; default: return setError(E_FAIL, tr("Invalid network adapter type '%d'"), aAdapterType); } if (mData->mAdapterType != aAdapterType) { mData.backup(); mData->mAdapterType = aAdapterType; m_fModified = true; // leave the lock before informing callbacks alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); // mParent is const, no need to lock mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Changing the network adapter type during runtime is not allowed, * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */ mParent->onNetworkAdapterChange(this, FALSE); } return S_OK; }
STDMETHODIMP NetworkAdapter::SetProperty(IN_BSTR aKey, IN_BSTR aValue) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); /* The machine needs to be mutable. */ AutoMutableStateDependency adep(mParent); if (FAILED(adep.rc())) return adep.rc(); Bstr key = aKey; AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); bool fGenericChange = (mData->mAttachmentType == NetworkAttachmentType_Generic); /* Generic properties processing. * Look up the old value first; if nothing's changed then do nothing. */ Utf8Str strValue(aValue); Utf8Str strKey(aKey); Utf8Str strOldValue; settings::StringsMap::const_iterator it = mData->mGenericProperties.find(strKey); if (it != mData->mGenericProperties.end()) strOldValue = it->second; if (strOldValue != strValue) { if (strValue.isEmpty()) mData->mGenericProperties.erase(strKey); else mData->mGenericProperties[strKey] = strValue; /* leave the lock before informing callbacks */ alock.release(); AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS); mParent->setModified(Machine::IsModified_NetworkAdapters); mlock.release(); /* Avoid deadlock when the event triggers a call to a method of this * interface. */ adep.release(); mParent->onNetworkAdapterChange(this, fGenericChange); } return S_OK; }