/** * Loads settings from the given adapter node. * May be called once right after this object creation. * * @param aAdapterNode <Adapter> node. * * @note Locks this object for writing. */ HRESULT NetworkAdapter::loadSettings(BandwidthControl *bwctl, const settings::NetworkAdapter &data) { AutoCaller autoCaller(this); AssertComRCReturnRC(autoCaller.rc()); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Note: we assume that the default values for attributes of optional * nodes are assigned in the Data::Data() constructor and don't do it * here. It implies that this method may only be called after constructing * a new BIOSSettings object while all its data fields are in the default * values. Exceptions are fields whose creation time defaults don't match * values that should be applied when these fields are not explicitly set * in the settings file (for backwards compatibility reasons). This takes * place when a setting of a newly created object must default to A while * the same setting of an object loaded from the old settings file must * default to B. */ HRESULT rc = S_OK; mData->mAdapterType = data.type; mData->mEnabled = data.fEnabled; /* MAC address (can be null) */ rc = updateMacAddress(data.strMACAddress); if (FAILED(rc)) return rc; /* cable (required) */ mData->mCableConnected = data.fCableConnected; /* line speed (defaults to 100 Mbps) */ mData->mLineSpeed = data.ulLineSpeed; mData->mPromiscModePolicy = data.enmPromiscModePolicy; /* tracing (defaults to false) */ mData->mTraceEnabled = data.fTraceEnabled; mData->mTraceFile = data.strTraceFile; /* boot priority (defaults to 0, i.e. lowest) */ mData->mBootPriority = data.ulBootPriority; /* bandwidth group */ mData->mBandwidthGroup = data.strBandwidthGroup; if (mData->mBandwidthGroup.isNotEmpty()) { ComObjPtr<BandwidthGroup> group; rc = bwctl->getBandwidthGroupByName(data.strBandwidthGroup, group, true); if (FAILED(rc)) return rc; group->reference(); } mNATEngine->loadSettings(data.nat); mData->mBridgedInterface = data.strBridgedName; mData->mInternalNetwork = data.strInternalNetworkName; mData->mHostOnlyInterface = data.strHostOnlyName; mData->mGenericDriver = data.strGenericDriver; mData->mGenericProperties = data.genericProperties; // leave the lock before setting attachment type alock.release(); rc = COMSETTER(AttachmentType)(data.mode); if (FAILED(rc)) return rc; // after loading settings, we are no longer different from the XML on disk m_fModified = false; return S_OK; }