1 | /* $Id: USBProxyService.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox USB Proxy Service (base) class.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2005-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
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
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_USBProxyService_h
|
---|
29 | #define MAIN_INCLUDED_USBProxyService_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/usb.h>
|
---|
35 | #include <VBox/usbfilter.h>
|
---|
36 |
|
---|
37 | #include "VirtualBoxBase.h"
|
---|
38 | #include "VirtualBoxImpl.h"
|
---|
39 | #include "HostUSBDeviceImpl.h"
|
---|
40 | #include "USBProxyBackend.h"
|
---|
41 |
|
---|
42 | class Host;
|
---|
43 |
|
---|
44 | namespace settings
|
---|
45 | {
|
---|
46 | struct USBDeviceSource;
|
---|
47 | typedef std::list<USBDeviceSource> USBDeviceSourcesList;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Base class for the USB Proxy service.
|
---|
53 | */
|
---|
54 | class USBProxyService
|
---|
55 | : public Lockable
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | DECLARE_TRANSLATE_METHODS(USBProxyService)
|
---|
59 |
|
---|
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 |
|
---|
75 | void uninit(void);
|
---|
76 |
|
---|
77 | bool isActive(void);
|
---|
78 | int getLastError(void);
|
---|
79 |
|
---|
80 | RWLockHandle *lockHandle() const;
|
---|
81 |
|
---|
82 | /** @name Interface for the USBController and the Host object.
|
---|
83 | * @{ */
|
---|
84 | void *insertFilter(PCUSBFILTER aFilter);
|
---|
85 | void removeFilter(void *aId);
|
---|
86 | /** @} */
|
---|
87 |
|
---|
88 | /** @name Host Interfaces
|
---|
89 | * @{ */
|
---|
90 | HRESULT getDeviceCollection(std::vector<ComPtr<IHostUSBDevice> > &aUSBDevices);
|
---|
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);
|
---|
94 | /** @} */
|
---|
95 |
|
---|
96 | /** @name SessionMachine Interfaces
|
---|
97 | * @{ */
|
---|
98 | HRESULT captureDeviceForVM(SessionMachine *aMachine, IN_GUID aId, const com::Utf8Str &aCaptureFilename);
|
---|
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 |
|
---|
104 | typedef std::list< ComObjPtr<HostUSBDeviceFilter> > USBDeviceFilterList;
|
---|
105 |
|
---|
106 | HRESULT i_loadSettings(const settings::USBDeviceSourcesList &llUSBDeviceSources);
|
---|
107 | HRESULT i_saveSettings(settings::USBDeviceSourcesList &llUSBDeviceSources);
|
---|
108 |
|
---|
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 |
|
---|
113 | protected:
|
---|
114 | ComObjPtr<HostUSBDevice> findDeviceById(IN_GUID aId);
|
---|
115 |
|
---|
116 | static HRESULT setError(HRESULT aResultCode, const char *aText, ...);
|
---|
117 |
|
---|
118 | USBProxyBackend *findUsbProxyBackendById(const com::Utf8Str &strId);
|
---|
119 |
|
---|
120 | HRESULT createUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId,
|
---|
121 | const com::Utf8Str &aAddress, const std::vector<com::Utf8Str> &aPropertyNames,
|
---|
122 | const std::vector<com::Utf8Str> &aPropertyValues, bool fLoadingSettings);
|
---|
123 |
|
---|
124 | private:
|
---|
125 |
|
---|
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 |
|
---|
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;
|
---|
139 | /** List of USBProxyBackend pointers. */
|
---|
140 | typedef std::list<ComObjPtr<USBProxyBackend> > USBProxyBackendList;
|
---|
141 | /** List of active USB backends. */
|
---|
142 | USBProxyBackendList mBackends;
|
---|
143 | int mLastError;
|
---|
144 | };
|
---|
145 |
|
---|
146 | #endif /* !MAIN_INCLUDED_USBProxyService_h */
|
---|
147 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|