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