1 | /* $Id: HostHardwareLinux.h 28882 2010-04-28 23:17:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Classes for handling hardware detection under Linux.
|
---|
4 | *
|
---|
5 | * Please feel free to expand these to work for other systems (Solaris!) or to
|
---|
6 | * add new ones for other systems.
|
---|
7 | */
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Copyright (C) 2008-2009 Oracle Corporation
|
---|
11 | *
|
---|
12 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | * available from http://www.virtualbox.org. This file is free software;
|
---|
14 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | * General Public License (GPL) as published by the Free Software
|
---|
16 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef ____H_HOSTHARDWARELINUX
|
---|
22 | # define ____H_HOSTHARDWARELINUX
|
---|
23 |
|
---|
24 | #include <iprt/err.h>
|
---|
25 | #include <iprt/cpp/ministring.h>
|
---|
26 | #include <vector>
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Class for probing and returning information about host DVD and floppy
|
---|
30 | * drives. To use this class, create an instance, call one of the update
|
---|
31 | * methods to do the actual probing and use the iterator methods to get the
|
---|
32 | * result of the probe.
|
---|
33 | */
|
---|
34 | class VBoxMainDriveInfo
|
---|
35 | {
|
---|
36 | public:
|
---|
37 | /** Structure describing a host drive */
|
---|
38 | struct DriveInfo
|
---|
39 | {
|
---|
40 | /** The device node of the drive. */
|
---|
41 | iprt::MiniString mDevice;
|
---|
42 | /** A unique identifier for the device, if available. This should be
|
---|
43 | * kept consistant accross different probing methods of a given
|
---|
44 | * platform if at all possible. */
|
---|
45 | iprt::MiniString mUdi;
|
---|
46 | /** A textual description of the drive. */
|
---|
47 | iprt::MiniString mDescription;
|
---|
48 |
|
---|
49 | /** Constructors */
|
---|
50 | DriveInfo(const iprt::MiniString &aDevice,
|
---|
51 | const iprt::MiniString &aUdi = "",
|
---|
52 | const iprt::MiniString &aDescription = "")
|
---|
53 | : mDevice(aDevice),
|
---|
54 | mUdi(aUdi),
|
---|
55 | mDescription(aDescription)
|
---|
56 | { }
|
---|
57 | };
|
---|
58 |
|
---|
59 | /** List (resp vector) holding drive information */
|
---|
60 | typedef std::vector<DriveInfo> DriveInfoList;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Search for host floppy drives and rebuild the list, which remains empty
|
---|
64 | * until the first time this method is called.
|
---|
65 | * @returns iprt status code
|
---|
66 | */
|
---|
67 | int updateFloppies();
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Search for host DVD drives and rebuild the list, which remains empty
|
---|
71 | * until the first time this method is called.
|
---|
72 | * @returns iprt status code
|
---|
73 | */
|
---|
74 | int updateDVDs();
|
---|
75 |
|
---|
76 | /** Get the first element in the list of floppy drives. */
|
---|
77 | DriveInfoList::const_iterator FloppyBegin()
|
---|
78 | {
|
---|
79 | return mFloppyList.begin();
|
---|
80 | }
|
---|
81 |
|
---|
82 | /** Get the last element in the list of floppy drives. */
|
---|
83 | DriveInfoList::const_iterator FloppyEnd()
|
---|
84 | {
|
---|
85 | return mFloppyList.end();
|
---|
86 | }
|
---|
87 |
|
---|
88 | /** Get the first element in the list of DVD drives. */
|
---|
89 | DriveInfoList::const_iterator DVDBegin()
|
---|
90 | {
|
---|
91 | return mDVDList.begin();
|
---|
92 | }
|
---|
93 |
|
---|
94 | /** Get the last element in the list of DVD drives. */
|
---|
95 | DriveInfoList::const_iterator DVDEnd()
|
---|
96 | {
|
---|
97 | return mDVDList.end();
|
---|
98 | }
|
---|
99 | private:
|
---|
100 | /** The list of currently available floppy drives */
|
---|
101 | DriveInfoList mFloppyList;
|
---|
102 | /** The list of currently available DVD drives */
|
---|
103 | DriveInfoList mDVDList;
|
---|
104 | };
|
---|
105 |
|
---|
106 | /** Convenience typedef. */
|
---|
107 | typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
|
---|
108 | /** Convenience typedef. */
|
---|
109 | typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Class for probing and returning information about host USB devices.
|
---|
113 | * To use this class, create an instance, call the update methods to do the
|
---|
114 | * actual probing and use the iterator methods to get the result of the probe.
|
---|
115 | */
|
---|
116 | class VBoxMainUSBDeviceInfo
|
---|
117 | {
|
---|
118 | public:
|
---|
119 | /** Structure describing a host USB device */
|
---|
120 | struct USBDeviceInfo
|
---|
121 | {
|
---|
122 | /** The device node of the device. */
|
---|
123 | iprt::MiniString mDevice;
|
---|
124 | /** The system identifier of the device. Specific to the probing
|
---|
125 | * method. */
|
---|
126 | iprt::MiniString mSysfsPath;
|
---|
127 | /** Type for the list of interfaces. */
|
---|
128 | typedef std::vector<iprt::MiniString> InterfaceList;
|
---|
129 | /** The system IDs of the device's interfaces. */
|
---|
130 | InterfaceList mInterfaces;
|
---|
131 |
|
---|
132 | /** Constructors */
|
---|
133 | USBDeviceInfo(const iprt::MiniString &aDevice,
|
---|
134 | const iprt::MiniString &aSystemID)
|
---|
135 | : mDevice(aDevice),
|
---|
136 | mSysfsPath(aSystemID)
|
---|
137 | { }
|
---|
138 | };
|
---|
139 |
|
---|
140 | /** List (resp vector) holding drive information */
|
---|
141 | typedef std::vector<USBDeviceInfo> DeviceInfoList;
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Search for host USB devices and rebuild the list, which remains empty
|
---|
145 | * until the first time this method is called.
|
---|
146 | * @returns iprt status code
|
---|
147 | */
|
---|
148 | int UpdateDevices ();
|
---|
149 |
|
---|
150 | /** Get the first element in the list of USB devices. */
|
---|
151 | DeviceInfoList::const_iterator DevicesBegin()
|
---|
152 | {
|
---|
153 | return mDeviceList.begin();
|
---|
154 | }
|
---|
155 |
|
---|
156 | /** Get the last element in the list of USB devices. */
|
---|
157 | DeviceInfoList::const_iterator DevicesEnd()
|
---|
158 | {
|
---|
159 | return mDeviceList.end();
|
---|
160 | }
|
---|
161 |
|
---|
162 | private:
|
---|
163 | /** The list of currently available USB devices */
|
---|
164 | DeviceInfoList mDeviceList;
|
---|
165 | };
|
---|
166 |
|
---|
167 | /** Convenience typedef. */
|
---|
168 | typedef VBoxMainUSBDeviceInfo::DeviceInfoList USBDeviceInfoList;
|
---|
169 | /** Convenience typedef. */
|
---|
170 | typedef VBoxMainUSBDeviceInfo::USBDeviceInfo USBDeviceInfo;
|
---|
171 | /** Convenience typedef. */
|
---|
172 | typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList;
|
---|
173 |
|
---|
174 | /** Implementation of the hotplug waiter class below */
|
---|
175 | class VBoxMainHotplugWaiterImpl
|
---|
176 | {
|
---|
177 | public:
|
---|
178 | VBoxMainHotplugWaiterImpl(void) {}
|
---|
179 | virtual ~VBoxMainHotplugWaiterImpl(void) {}
|
---|
180 | /** @copydoc VBoxMainHotplugWaiter::Wait */
|
---|
181 | virtual int Wait(RTMSINTERVAL cMillies) = 0;
|
---|
182 | /** @copydoc VBoxMainHotplugWaiter::Interrupt */
|
---|
183 | virtual void Interrupt(void) = 0;
|
---|
184 | /** @copydoc VBoxMainHotplugWaiter::getStatus */
|
---|
185 | virtual int getStatus(void) = 0;
|
---|
186 | };
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Class for waiting for a hotplug event. To use this class, create an
|
---|
190 | * instance and call the @a Wait() method, which blocks until an event or a
|
---|
191 | * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
|
---|
192 | * wait before an event occurs.
|
---|
193 | */
|
---|
194 | class VBoxMainHotplugWaiter
|
---|
195 | {
|
---|
196 | /** Class implementation. */
|
---|
197 | VBoxMainHotplugWaiterImpl *mImpl;
|
---|
198 | public:
|
---|
199 | /** Constructor. Responsible for selecting the implementation. */
|
---|
200 | VBoxMainHotplugWaiter (void);
|
---|
201 | /** Destructor. */
|
---|
202 | ~VBoxMainHotplugWaiter (void)
|
---|
203 | {
|
---|
204 | delete mImpl;
|
---|
205 | }
|
---|
206 | /**
|
---|
207 | * Wait for a hotplug event.
|
---|
208 | *
|
---|
209 | * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
|
---|
210 | * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
|
---|
211 | * temporary failure.
|
---|
212 | * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
|
---|
213 | * succeed if retried.
|
---|
214 | * @returns Possibly other iprt status codes otherwise.
|
---|
215 | * @param cMillies How long to wait for at most.
|
---|
216 | */
|
---|
217 | int Wait (RTMSINTERVAL cMillies)
|
---|
218 | {
|
---|
219 | return mImpl->Wait(cMillies);
|
---|
220 | }
|
---|
221 | /**
|
---|
222 | * Interrupts an active wait. In the current implementation, the wait
|
---|
223 | * may not return until up to two seconds after calling this method.
|
---|
224 | */
|
---|
225 | void Interrupt (void)
|
---|
226 | {
|
---|
227 | mImpl->Interrupt();
|
---|
228 | }
|
---|
229 |
|
---|
230 | int getStatus(void)
|
---|
231 | {
|
---|
232 | return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
|
---|
233 | }
|
---|
234 | };
|
---|
235 |
|
---|
236 | #endif /* ____H_HOSTHARDWARELINUX */
|
---|
237 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|