int destroyClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr) { if (listener) { ComPtr<IEventSource> esVBox; HRESULT hrc = vboxclientptr->COMGETTER(EventSource)(esVBox.asOutParam()); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); if (!esVBox.isNull()) { hrc = esVBox->UnregisterListener(listener); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); } listener.setNull(); } return VINF_SUCCESS; }
int VBoxNetBaseService::init() { if (isMainNeeded()) { HRESULT hrc = com::Initialize(); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); hrc = virtualboxClient.createInprocObject(CLSID_VirtualBoxClient); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); hrc = virtualboxClient->COMGETTER(VirtualBox)(virtualbox.asOutParam()); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); } return VINF_SUCCESS; }
bool ParallelPort::i_hasDefaults() { /* sanity */ AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), true); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); if (!m->bd->fEnabled) { /* Could be default, check the IO base and IRQ. */ switch (m->bd->ulSlot) { case 0: if (m->bd->ulIOBase == 0x378 && m->bd->ulIRQ == 7) return true; break; case 1: if (m->bd->ulIOBase == 0x278 && m->bd->ulIRQ == 5) return true; break; default: AssertMsgFailed(("Parallel port slot %u exceeds limit\n", m->bd->ulSlot)); break; } /* Detect old-style defaults (0x378, irq 4) in any slot, they are still * in place for many VMs created by old VirtualBox versions. */ if (m->bd->ulIOBase == 0x378 && m->bd->ulIRQ == 4) return true; } return false; }
/** * Returns a medium format object corresponding to the given file extension or * null if no such format. * * @param aExt File extension. * * @return ComObjPtr<MediumFormat> */ ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt) { ComObjPtr<MediumFormat> format; AutoCaller autoCaller(this); AssertComRCReturn (autoCaller.rc(), format); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); bool fFound = false; for (MediumFormatList::const_iterator it = m_llMediumFormats.begin(); it != m_llMediumFormats.end() && !fFound; ++it) { /* MediumFormat is all const, no need to lock */ MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions(); for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin(); it1 != aFileList.end(); ++it1) { if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0) { format = *it; fFound = true; break; } } } return format; }
/* static */ int NativeEventQueue::init() { Assert(sMainQueue == NULL); Assert(RTThreadIsMain(RTThreadSelf())); try { sMainQueue = new NativeEventQueue(); AssertPtr(sMainQueue); #ifdef VBOX_WITH_XPCOM /* Check that it actually is the main event queue, i.e. that we're called on the right thread. */ nsCOMPtr<nsIEventQueue> q; nsresult rv = NS_GetMainEventQ(getter_AddRefs(q)); AssertComRCReturn(rv, VERR_INVALID_POINTER); Assert(q == sMainQueue->mEventQ); /* Check that it's a native queue. */ PRBool fIsNative = PR_FALSE; rv = sMainQueue->mEventQ->IsQueueNative(&fIsNative); Assert(NS_SUCCEEDED(rv) && fIsNative); #endif // VBOX_WITH_XPCOM } catch (std::bad_alloc &ba) { NOREF(ba); return VERR_NO_MEMORY; } return VINF_SUCCESS; }
STDMETHODIMP Session::OnShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); #ifndef VBOX_COM_INPROC_API_CLIENT AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); #endif if (mState != SessionState_Locked) { /* the call from Machine issued when the session is open can arrive * after the session starts closing or gets closed. Note that when * aCheck is false, we return E_FAIL to indicate that aWinId we return * is not valid */ *aCanShow = FALSE; *aWinId = 0; return aCheck ? S_OK : E_FAIL; } #ifndef VBOX_COM_INPROC_API_CLIENT return mConsole->onShowWindow(aCheck, aCanShow, aWinId); #else return S_OK; #endif }
/** * Returns true if the given USB device matches to at least one of * this controller's USB device filters. * * A HostUSBDevice specific version. * * @note Locks this object for reading. */ bool USBDeviceFilters::i_hasMatchingFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), false); /* It is not possible to work with USB device if there is no USB controller present. */ if (!m->pParent->i_isUSBControllerPresent()) return false; AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); /* apply self filters */ for (DeviceFilterList::const_iterator it = m->llDeviceFilters->begin(); it != m->llDeviceFilters->end(); ++it) { AutoWriteLock filterLock(*it COMMA_LOCKVAL_SRC_POS); if (aDevice->i_isMatch((*it)->i_getData())) { *aMaskedIfs = (*it)->i_getData().mMaskedIfs; return true; } } return false; }
STDMETHODIMP Session::GetRemoteConsole(IConsole **aConsole) { LogFlowThisFuncEnter(); AssertReturn(aConsole, E_POINTER); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState != SessionState_Unlocked, VBOX_E_INVALID_VM_STATE); #ifndef VBOX_COM_INPROC_API_CLIENT AssertMsgReturn(mType == SessionType_WriteLock && !!mConsole, ("This is not a direct session!\n"), VBOX_E_INVALID_OBJECT_STATE); /* return a failure if the session already transitioned to Closing * but the server hasn't processed Machine::OnSessionEnd() yet. */ if (mState != SessionState_Locked) return VBOX_E_INVALID_VM_STATE; mConsole.queryInterfaceTo(aConsole); LogFlowThisFuncLeave(); return S_OK; #else /* VBOX_COM_INPROC_API_CLIENT */ AssertFailed(); return VBOX_E_INVALID_OBJECT_STATE; #endif /* VBOX_COM_INPROC_API_CLIENT */ }
bool USBDeviceFilter::i_isModified() { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), false); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); return m_fModified; }
STDMETHODIMP Session::EnableVMMStatistics(BOOL aEnable) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); mConsole->enableVMMStatistics(aEnable); return S_OK; }
DECLCALLBACK(int) VBoxNetBaseService::Data::recvLoop(RTTHREAD, void *pvUser) { VBoxNetBaseService *pThis = static_cast<VBoxNetBaseService *>(pvUser); HRESULT hrc = com::Initialize(); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); pThis->doReceiveLoop(); return VINF_SUCCESS; }
STDMETHODIMP Session::SaveStateWithReason(Reason_T aReason, IProgress **aProgress) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); return mConsole->saveState(aReason, aProgress); }
int createClientListener(ComNatListenerPtr& listener, const ComVirtualBoxClientPtr& vboxclientptr, NATNetworkEventAdapter *adapter, /* const */ ComEventTypeArray& events) { ComObjPtr<NATNetworkListenerImpl> obj; HRESULT hrc = obj.createObject(); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); hrc = obj->init(new NATNetworkListener(), adapter); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); ComPtr<IEventSource> esVBox; hrc = vboxclientptr->COMGETTER(EventSource)(esVBox.asOutParam()); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); listener = obj; hrc = esVBox->RegisterListener(listener, ComSafeArrayAsInParam(events), true); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); return VINF_SUCCESS; }
STDMETHODIMP Session::OnStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onStorageDeviceChange(aMediumAttachment, aRemove); }
STDMETHODIMP Session::OnBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onBandwidthGroupChange(aBandwidthGroup); }
STDMETHODIMP Session::OnSharedFolderChange(BOOL aGlobal) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onSharedFolderChange(aGlobal); }
STDMETHODIMP Session::OnNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onNetworkAdapterChange(networkAdapter, changeAdapter); }
STDMETHODIMP Session::OnDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onDragAndDropModeChange(aDragAndDropMode); }
static inline int configGetBoundryAddress(const ComDhcpServerPtr& dhcp, bool fUpperBoundry, RTNETADDRIPV4& boundryAddress) { boundryAddress.u = INADDR_ANY; HRESULT hrc; com::Bstr strAddress; if (fUpperBoundry) hrc = dhcp->COMGETTER(UpperIP)(strAddress.asOutParam()); else hrc = dhcp->COMGETTER(LowerIP)(strAddress.asOutParam()); AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); return RTNetStrToIPv4Addr(com::Utf8Str(strAddress).c_str(), &boundryAddress); }
STDMETHODIMP Session::OnUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onUSBDeviceDetach(aId, aError); }
STDMETHODIMP Session::EnableVMMStatistics(BOOL aEnable) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); mConsole->enableVMMStatistics(aEnable); return S_OK; }
STDMETHODIMP Session::OnCPUChange(ULONG aCPU, BOOL aRemove) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onCPUChange(aCPU, aRemove); }
STDMETHODIMP Session::GetPID(ULONG *aPid) { AssertReturn(aPid, E_POINTER); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aPid = (ULONG)RTProcSelf(); AssertCompile(sizeof(*aPid) == sizeof(RTPROCESS)); return S_OK; }
HRESULT VBoxNetDhcp::HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent) { switch (aEventType) { case VBoxEventType_OnHostNameResolutionConfigurationChange: fetchAndUpdateDnsInfo(); break; case VBoxEventType_OnNATNetworkStartStop: { ComPtr <INATNetworkStartStopEvent> pStartStopEvent = pEvent; com::Bstr networkName; HRESULT hrc = pStartStopEvent->COMGETTER(NetworkName)(networkName.asOutParam()); AssertComRCReturn(hrc, hrc); if (networkName.compare(getNetworkName().c_str())) break; /* change not for our network */ BOOL fStart = TRUE; hrc = pStartStopEvent->COMGETTER(StartEvent)(&fStart); AssertComRCReturn(hrc, hrc); if (!fStart) shutdown(); break; } case VBoxEventType_OnVBoxSVCAvailabilityChanged: { shutdown(); break; } default: break; /* Shut up MSC. */ } return S_OK; }
/** * Sets the cancelation callback, checking for cancelation first. * * @returns Success indicator. * @retval true on success. * @retval false if the progress object has already been canceled or is in an * invalid state * * @param pfnCallback The function to be called upon cancelation. * @param pvUser The callback argument. */ bool Progress::i_setCancelCallback(void (*pfnCallback)(void *), void *pvUser) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), false); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); i_checkForAutomaticTimeout(); if (mCanceled) return false; m_pvCancelUserArg = pvUser; m_pfnCancelCallback = pfnCallback; return true; }
STDMETHODIMP Session::AccessGuestProperty(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags, BOOL aIsSetter, BSTR *aRetValue, LONG64 *aRetTimestamp, BSTR *aRetFlags) { #ifdef VBOX_WITH_GUEST_PROPS # ifndef VBOX_COM_INPROC_API_CLIENT AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); if (mState != SessionState_Locked) return setError(VBOX_E_INVALID_VM_STATE, tr("Machine is not locked by session (session state: %s)."), Global::stringifySessionState(mState)); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); CheckComArgStrNotEmptyOrNull(aName); if (!aIsSetter && !VALID_PTR(aRetValue)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetTimestamp)) return E_POINTER; if (!aIsSetter && !VALID_PTR(aRetFlags)) return E_POINTER; /* aValue can be NULL for a setter call if the property is to be deleted. */ if (aIsSetter && (aValue != NULL) && !VALID_PTR(aValue)) return setError(E_INVALIDARG, tr("Invalid value pointer")); /* aFlags can be null if it is to be left as is */ if (aIsSetter && (aFlags != NULL) && !VALID_PTR(aFlags)) return setError(E_INVALIDARG, tr("Invalid flags pointer")); /* If this session is not in a VM process fend off the call. The caller * handles this correctly, by doing the operation in VBoxSVC. */ if (!mConsole) return E_ACCESSDENIED; if (!aIsSetter) return mConsole->getGuestProperty(aName, aRetValue, aRetTimestamp, aRetFlags); else return mConsole->setGuestProperty(aName, aValue, aFlags); # else /* VBOX_COM_INPROC_API_CLIENT */ /** @todo This is nonsense, non-VM API users shouldn't need to deal with this * method call, VBoxSVC should be clever enough to see that the * session doesn't have a console! */ return E_ACCESSDENIED; # endif /* VBOX_COM_INPROC_API_CLIENT */ #else /* VBOX_WITH_GUEST_PROPS */ ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_PROPS */ }
STDMETHODIMP Session::SaveStateWithReason(Reason_T aReason, IProgress **aProgress) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); #ifndef VBOX_COM_INPROC_API_CLIENT AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); return mConsole->saveState(aReason, aProgress); #else AssertFailed(); return E_NOTIMPL; #endif }
bool NATEngine::rollback() { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), false); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); bool fChanged = m_fModified; if (m_fModified) { /* we need to check all data to see whether anything will be changed * after rollback */ mData.rollback(); } m_fModified = false; return fChanged; }
/** * Notify the progress object that we're almost at the point of no return. * * This atomically checks for and disables cancelation. Calls to * IProgress::Cancel() made after a successful call to this method will fail * and the user can be told. While this isn't entirely clean behavior, it * prevents issues with an irreversible actually operation succeeding while the * user believe it was rolled back. * * @returns Success indicator. * @retval true on success. * @retval false if the progress object has already been canceled or is in an * invalid state */ bool Progress::i_notifyPointOfNoReturn(void) { AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), false); AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); if (mCanceled) { LogThisFunc(("returns false\n")); return false; } mCancelable = FALSE; LogThisFunc(("returns true\n")); return true; }
STDMETHODIMP Session::OnClipboardModeChange(ClipboardMode_T aClipboardMode) { LogFlowThisFunc(("\n")); AutoCaller autoCaller(this); AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE); AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE); #ifndef VBOX_COM_INPROC_API_CLIENT AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE); return mConsole->onClipboardModeChange(aClipboardMode); #else return S_OK; #endif }