USBProxyService.h revision b52c24239bed9dc9f284d829b6059073afcb1894
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * VirtualBox USB Proxy Service (base) class.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright (C) 2006-2007 Oracle Corporation
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This file is part of VirtualBox Open Source Edition (OSE), as
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * available from http://www.virtualbox.org. This file is free software;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * you can redistribute it and/or modify it under the terms of the GNU
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * General Public License (GPL) as published by the Free Software
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Foundation, in version 2 as it comes in the "COPYING" file of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Base class for the USB Proxy service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Override of the default locking class to be used for validating lock
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * order with the standard member lock handle.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual VBoxLockingClass getLockingClass() const
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // the USB proxy service uses the Host object lock, so return the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // same locking class as the host
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** @name Host Interfaces
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT getDeviceCollection(ComSafeArrayOut(IHostUSBDevice *, aUSBDevices));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** @name SessionMachine Interfaces
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT captureDeviceForVM(SessionMachine *aMachine, IN_GUID aId);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT detachDeviceFromVM(SessionMachine *aMachine, IN_GUID aId, bool aDone);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT autoCaptureDevicesForVM(SessionMachine *aMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT detachAllDevicesFromVM(SessionMachine *aMachine, bool aDone, bool aAbnormal);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** @name Interface for the USBController and the Host object.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void *insertFilter(PCUSBFILTER aFilter);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** @name Interfaces for the HostUSBDevice
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void detachingDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void releaseDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void deviceRemoved(ComObjPtr<HostUSBDevice> &aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void deviceChanged(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList *pllOpenedMachines, SessionMachine *aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bool updateDeviceStateFake(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ComObjPtr<HostUSBDevice> findDeviceById(IN_GUID aId);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static HRESULT setError(HRESULT aResultCode, const char *aText, ...);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static void initFilterFromDevice(PUSBFILTER aFilter, HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static void freeDeviceMembers(PUSBDEVICE pDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe HRESULT runAllFiltersOnDevice(ComObjPtr<HostUSBDevice> &aDevice,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bool runMachineFilters(SessionMachine *aMachine, ComObjPtr<HostUSBDevice> &aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static DECLCALLBACK(int) serviceThread(RTTHREAD Thread, void *pvUser);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Pointer to the Host object. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Thread handle of the service thread. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Flag which stop() sets to cause serviceThread to return. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bool volatile mTerminate;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** VBox status code of the last failure.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (Only used by start(), stop() and the child constructors.) */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Optional error message to complement mLastError. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** List of smart HostUSBDevice pointers. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe typedef std::list<ComObjPtr<HostUSBDevice> > HostUSBDeviceList;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** List of the known USB devices. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The Darwin hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweclass USBProxyServiceDarwin : public USBProxyService
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void *insertFilter(PCUSBFILTER aFilter);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void detachingDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void releaseDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState (HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Reference to the runloop of the service thread.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This is NULL if the service thread isn't running. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** The opaque value returned by DarwinSubscribeUSBNotifications. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** A hack to work around the problem with the usb device enumeration
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * not including newly attached devices. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Whether we've got a fake async event and should return without entering the runloop. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bool volatile mFakeAsync;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Whether we've successfully initialized the USBLib and should call USBLibTerm in the destructor. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe# endif /* RT_OS_DARWIN */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The Linux hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, int rc);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** File handle to the '/proc/bus/usb/devices' file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Stream for mFile. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Pipe used to interrupt wait(), the read end. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Pipe used to interrupt wait(), the write end. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** The root of usbfs. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Whether we're using <mUsbfsRoot>/devices or /sys/whatever. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Number of 500ms polls left to do. See usbDeterminState for details. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Object used for querying device information from hal. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Object used for polling for hotplug events from hal. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe# endif /* RT_OS_LINUX */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The Linux hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweclass USBProxyServiceOs2 : public USBProxyService
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /// @todo virtual HRESULT init(void);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, int rc);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** The notification event semaphore */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** The notification id. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** The usbcalls.dll handle. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** UsbRegisterChangeNotification */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APIRET (APIENTRY *mpfnUsbRegisterChangeNotification)(PUSBNOTIFY, HEV, HEV);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** UsbDeregisterNotification */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APIRET (APIENTRY *mpfnUsbDeregisterNotification)(USBNOTIFY);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** UsbQueryNumberDevices */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APIRET (APIENTRY *mpfnUsbQueryNumberDevices)(PULONG);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** UsbQueryDeviceReport */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APIRET (APIENTRY *mpfnUsbQueryDeviceReport)(ULONG, PULONG, PVOID);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe# endif /* RT_OS_LINUX */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The Solaris hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweclass USBProxyServiceSolaris : public USBProxyService
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void *insertFilter (PCUSBFILTER aFilter);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void captureDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void releaseDeviceCompleted(HostUSBDevice *aDevice, bool aSuccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /** Whether we've successfully initialized the USBLib and should call USBLibTerm in the destructor. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* RT_OS_SOLARIS */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The Windows hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweclass USBProxyServiceWindows : public USBProxyService
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void *insertFilter (PCUSBFILTER aFilter);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice (HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe# endif /* RT_OS_WINDOWS */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The FreeBSD hosted USB Proxy Service.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweclass USBProxyServiceFreeBSD : public USBProxyService
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int captureDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual int releaseDevice(HostUSBDevice *aDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, int rc);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual void deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe# endif /* RT_OS_FREEBSD */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* !____H_USBPROXYSERVICE */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* vi: set tabstop=4 shiftwidth=4 expandtab: */