VirtualBox

source: vbox/trunk/src/VBox/Main/include/USBProxyService.h@ 87093

Last change on this file since 87093 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: USBProxyService.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VirtualBox USB Proxy Service (base) class.
4 */
5
6/*
7 * Copyright (C) 2005-2020 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
32class Host;
33
34namespace settings
35{
36 struct USBDeviceSource;
37 typedef std::list<USBDeviceSource> USBDeviceSourcesList;
38}
39
40
41/**
42 * Base class for the USB Proxy service.
43 */
44class USBProxyService
45 : public VirtualBoxTranslatable
46{
47public:
48 USBProxyService(Host *aHost);
49 virtual HRESULT init(void);
50 virtual ~USBProxyService();
51
52 /**
53 * Override of the default locking class to be used for validating lock
54 * order with the standard member lock handle.
55 */
56 virtual VBoxLockingClass getLockingClass() const
57 {
58 // the USB proxy service uses the Host object lock, so return the
59 // same locking class as the host
60 return LOCKCLASS_HOSTOBJECT;
61 }
62
63 void uninit(void);
64
65 bool isActive(void);
66 int getLastError(void);
67
68 RWLockHandle *lockHandle() const;
69
70 /** @name Interface for the USBController and the Host object.
71 * @{ */
72 void *insertFilter(PCUSBFILTER aFilter);
73 void removeFilter(void *aId);
74 /** @} */
75
76 /** @name Host Interfaces
77 * @{ */
78 HRESULT getDeviceCollection(std::vector<ComPtr<IHostUSBDevice> > &aUSBDevices);
79 HRESULT addUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId, const com::Utf8Str &aAddress,
80 const std::vector<com::Utf8Str> &aPropertyNames, const std::vector<com::Utf8Str> &aPropertyValues);
81 HRESULT removeUSBDeviceSource(const com::Utf8Str &aId);
82 /** @} */
83
84 /** @name SessionMachine Interfaces
85 * @{ */
86 HRESULT captureDeviceForVM(SessionMachine *aMachine, IN_GUID aId, const com::Utf8Str &aCaptureFilename);
87 HRESULT detachDeviceFromVM(SessionMachine *aMachine, IN_GUID aId, bool aDone);
88 HRESULT autoCaptureDevicesForVM(SessionMachine *aMachine);
89 HRESULT detachAllDevicesFromVM(SessionMachine *aMachine, bool aDone, bool aAbnormal);
90 /** @} */
91
92 typedef std::list< ComObjPtr<HostUSBDeviceFilter> > USBDeviceFilterList;
93
94 HRESULT i_loadSettings(const settings::USBDeviceSourcesList &llUSBDeviceSources);
95 HRESULT i_saveSettings(settings::USBDeviceSourcesList &llUSBDeviceSources);
96
97 void i_deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, PUSBDEVICE aUSBDevice);
98 void i_deviceRemoved(ComObjPtr<HostUSBDevice> &aDevice);
99 void i_updateDeviceState(ComObjPtr<HostUSBDevice> &aDevice, PUSBDEVICE aUSBDevice, bool fFakeUpdate);
100
101protected:
102 ComObjPtr<HostUSBDevice> findDeviceById(IN_GUID aId);
103
104 static HRESULT setError(HRESULT aResultCode, const char *aText, ...);
105
106 USBProxyBackend *findUsbProxyBackendById(const com::Utf8Str &strId);
107
108 HRESULT createUSBDeviceSource(const com::Utf8Str &aBackend, const com::Utf8Str &aId,
109 const com::Utf8Str &aAddress, const std::vector<com::Utf8Str> &aPropertyNames,
110 const std::vector<com::Utf8Str> &aPropertyValues, bool fLoadingSettings);
111
112private:
113
114 HRESULT runAllFiltersOnDevice(ComObjPtr<HostUSBDevice> &aDevice,
115 SessionMachinesList &llOpenedMachines,
116 SessionMachine *aIgnoreMachine);
117 bool runMachineFilters(SessionMachine *aMachine, ComObjPtr<HostUSBDevice> &aDevice);
118
119 void deviceChanged(ComObjPtr<HostUSBDevice> &aDevice, bool fRunFilters, SessionMachine *aIgnoreMachine);
120
121 /** Pointer to the Host object. */
122 Host *mHost;
123 /** List of smart HostUSBDevice pointers. */
124 typedef std::list<ComObjPtr<HostUSBDevice> > HostUSBDeviceList;
125 /** List of the known USB devices. */
126 HostUSBDeviceList mDevices;
127 /** List of USBProxyBackend pointers. */
128 typedef std::list<ComObjPtr<USBProxyBackend> > USBProxyBackendList;
129 /** List of active USB backends. */
130 USBProxyBackendList mBackends;
131 int mLastError;
132};
133
134#endif /* !MAIN_INCLUDED_USBProxyService_h */
135/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette