[31891] | 1 | /* $Id: USBProxyService.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VirtualBox USB Proxy Service (base) class.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[96407] | 7 | * Copyright (C) 2005-2022 Oracle and/or its affiliates.
|
---|
[31891] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[31891] | 26 | */
|
---|
| 27 |
|
---|
[76562] | 28 | #ifndef MAIN_INCLUDED_USBProxyService_h
|
---|
| 29 | #define MAIN_INCLUDED_USBProxyService_h
|
---|
[76487] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[31891] | 33 |
|
---|
| 34 | #include <VBox/usb.h>
|
---|
| 35 | #include <VBox/usbfilter.h>
|
---|
| 36 |
|
---|
| 37 | #include "VirtualBoxBase.h"
|
---|
| 38 | #include "VirtualBoxImpl.h"
|
---|
| 39 | #include "HostUSBDeviceImpl.h"
|
---|
[59117] | 40 | #include "USBProxyBackend.h"
|
---|
[61009] | 41 |
|
---|
[31891] | 42 | class Host;
|
---|
| 43 |
|
---|
[61009] | 44 | namespace settings
|
---|
| 45 | {
|
---|
| 46 | struct USBDeviceSource;
|
---|
| 47 | typedef std::list<USBDeviceSource> USBDeviceSourcesList;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
[31891] | 51 | /**
|
---|
| 52 | * Base class for the USB Proxy service.
|
---|
| 53 | */
|
---|
| 54 | class USBProxyService
|
---|
[91312] | 55 | : public Lockable
|
---|
[31891] | 56 | {
|
---|
| 57 | public:
|
---|
[90828] | 58 | DECLARE_TRANSLATE_METHODS(USBProxyService)
|
---|
| 59 |
|
---|
[31891] | 60 | USBProxyService(Host *aHost);
|
---|
| 61 | virtual HRESULT init(void);
|
---|
| 62 | virtual ~USBProxyService();
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * Override of the default locking class to be used for validating lock
|
---|
| 66 | * order with the standard member lock handle.
|
---|
| 67 | */
|
---|
| 68 | virtual VBoxLockingClass getLockingClass() const
|
---|
| 69 | {
|
---|
| 70 | // the USB proxy service uses the Host object lock, so return the
|
---|
| 71 | // same locking class as the host
|
---|
| 72 | return LOCKCLASS_HOSTOBJECT;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[60089] | 75 | void uninit(void);
|
---|
| 76 |
|
---|
[31891] | 77 | bool isActive(void);
|
---|
| 78 | int getLastError(void);
|
---|
| 79 |
|
---|
| 80 | RWLockHandle *lockHandle() const;
|
---|
| 81 |
|
---|
[59117] | 82 | /** @name Interface for the USBController and the Host object.
|
---|
| 83 | * @{ */
|
---|
| 84 | void *insertFilter(PCUSBFILTER aFilter);
|
---|
| 85 | void removeFilter(void *aId);
|
---|
| 86 | /** @} */
|
---|
| 87 |
|
---|
[31891] | 88 | /** @name Host Interfaces
|
---|
| 89 | * @{ */
|
---|
[52934] | 90 | HRESULT getDeviceCollection(std::vector<ComPtr<IHostUSBDevice> > &aUSBDevices);
|
---|
[60089] | 91 | HRESULT addUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId, const com::Utf8Str &aAddress,
|
---|
| 92 | const std::vector<com::Utf8Str> &aPropertyNames, const std::vector<com::Utf8Str> &aPropertyValues);
|
---|
| 93 | HRESULT removeUSBDeviceSource(const com::Utf8Str &aId);
|
---|
[31891] | 94 | /** @} */
|
---|
| 95 |
|
---|
| 96 | /** @name SessionMachine Interfaces
|
---|
| 97 | * @{ */
|
---|
[53062] | 98 | HRESULT captureDeviceForVM(SessionMachine *aMachine, IN_GUID aId, const com::Utf8Str &aCaptureFilename);
|
---|
[31891] | 99 | HRESULT detachDeviceFromVM(SessionMachine *aMachine, IN_GUID aId, bool aDone);
|
---|
| 100 | HRESULT autoCaptureDevicesForVM(SessionMachine *aMachine);
|
---|
| 101 | HRESULT detachAllDevicesFromVM(SessionMachine *aMachine, bool aDone, bool aAbnormal);
|
---|
| 102 | /** @} */
|
---|
| 103 |
|
---|
[59117] | 104 | typedef std::list< ComObjPtr<HostUSBDeviceFilter> > USBDeviceFilterList;
|
---|
[31891] | 105 |
|
---|
[60107] | 106 | HRESULT i_loadSettings(const settings::USBDeviceSourcesList &llUSBDeviceSources);
|
---|
| 107 | HRESULT i_saveSettings(settings::USBDeviceSourcesList &llUSBDeviceSources);
|
---|
| 108 |
|
---|
[60742] | 109 | void i_deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, PUSBDEVICE aUSBDevice);
|
---|
| 110 | void i_deviceRemoved(ComObjPtr<HostUSBDevice> &aDevice);
|
---|
| 111 | void i_updateDeviceState(ComObjPtr<HostUSBDevice> &aDevice, PUSBDEVICE aUSBDevice, bool fFakeUpdate);
|
---|
| 112 |
|
---|
[31891] | 113 | protected:
|
---|
| 114 | ComObjPtr<HostUSBDevice> findDeviceById(IN_GUID aId);
|
---|
| 115 |
|
---|
| 116 | static HRESULT setError(HRESULT aResultCode, const char *aText, ...);
|
---|
| 117 |
|
---|
[60089] | 118 | USBProxyBackend *findUsbProxyBackendById(const com::Utf8Str &strId);
|
---|
| 119 |
|
---|
[60107] | 120 | HRESULT createUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId,
|
---|
| 121 | const com::Utf8Str &aAddress, const std::vector<com::Utf8Str> &aPropertyNames,
|
---|
[65854] | 122 | const std::vector<com::Utf8Str> &aPropertyValues, bool fLoadingSettings);
|
---|
[60107] | 123 |
|
---|
[31891] | 124 | private:
|
---|
| 125 |
|
---|
[60742] | 126 | HRESULT runAllFiltersOnDevice(ComObjPtr<HostUSBDevice> &aDevice,
|
---|
| 127 | SessionMachinesList &llOpenedMachines,
|
---|
| 128 | SessionMachine *aIgnoreMachine);
|
---|
| 129 | bool runMachineFilters(SessionMachine *aMachine, ComObjPtr<HostUSBDevice> &aDevice);
|
---|
| 130 |
|
---|
| 131 | void deviceChanged(ComObjPtr<HostUSBDevice> &aDevice, bool fRunFilters, SessionMachine *aIgnoreMachine);
|
---|
| 132 |
|
---|
[31891] | 133 | /** Pointer to the Host object. */
|
---|
| 134 | Host *mHost;
|
---|
| 135 | /** List of smart HostUSBDevice pointers. */
|
---|
| 136 | typedef std::list<ComObjPtr<HostUSBDevice> > HostUSBDeviceList;
|
---|
| 137 | /** List of the known USB devices. */
|
---|
| 138 | HostUSBDeviceList mDevices;
|
---|
[59117] | 139 | /** List of USBProxyBackend pointers. */
|
---|
[60089] | 140 | typedef std::list<ComObjPtr<USBProxyBackend> > USBProxyBackendList;
|
---|
[59117] | 141 | /** List of active USB backends. */
|
---|
| 142 | USBProxyBackendList mBackends;
|
---|
| 143 | int mLastError;
|
---|
[31891] | 144 | };
|
---|
| 145 |
|
---|
[76562] | 146 | #endif /* !MAIN_INCLUDED_USBProxyService_h */
|
---|
[31891] | 147 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|