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