1 | /* $Id: HostHardwareLinux.h 23522 2009-10-02 23:27:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Classes for handling hardware detection under Linux. Please feel free to
|
---|
4 | * expand these to work for other systems (Solaris!) or to add new ones for
|
---|
5 | * other systems.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2009 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef ____H_HOSTHARDWARELINUX
|
---|
25 | # define ____H_HOSTHARDWARELINUX
|
---|
26 |
|
---|
27 | #include <iprt/err.h>
|
---|
28 | #include <iprt/ministring_cpp.h>
|
---|
29 | #include <vector>
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Class for probing and returning information about host DVD and floppy
|
---|
33 | * drives. To use this class, create an instance, call one of the update
|
---|
34 | * methods to do the actual probing and use the iterator methods to get the
|
---|
35 | * result of the probe.
|
---|
36 | */
|
---|
37 | class VBoxMainDriveInfo
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /** Structure describing a host drive */
|
---|
41 | struct DriveInfo
|
---|
42 | {
|
---|
43 | /** The device node of the drive. */
|
---|
44 | iprt::MiniString mDevice;
|
---|
45 | /** The hal unique device identifier, if available. */
|
---|
46 | iprt::MiniString mUdi;
|
---|
47 | /** A textual description of the drive. */
|
---|
48 | iprt::MiniString mDescription;
|
---|
49 |
|
---|
50 | /** Constructors */
|
---|
51 | DriveInfo(const iprt::MiniString &aDevice,
|
---|
52 | const iprt::MiniString &aUdi = "",
|
---|
53 | const iprt::MiniString &aDescription = "")
|
---|
54 | : mDevice(aDevice),
|
---|
55 | mUdi(aUdi),
|
---|
56 | mDescription(aDescription)
|
---|
57 | { }
|
---|
58 | };
|
---|
59 |
|
---|
60 | /** List (resp vector) holding drive information */
|
---|
61 | typedef std::vector<DriveInfo> DriveInfoList;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Search for host floppy drives and rebuild the list, which remains empty
|
---|
65 | * until the first time this method is called.
|
---|
66 | * @returns iprt status code
|
---|
67 | */
|
---|
68 | int updateFloppies();
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Search for host DVD drives and rebuild the list, which remains empty
|
---|
72 | * until the first time this method is called.
|
---|
73 | * @returns iprt status code
|
---|
74 | */
|
---|
75 | int updateDVDs();
|
---|
76 |
|
---|
77 | /** Get the first element in the list of floppy drives. */
|
---|
78 | DriveInfoList::const_iterator FloppyBegin()
|
---|
79 | {
|
---|
80 | return mFloppyList.begin();
|
---|
81 | }
|
---|
82 |
|
---|
83 | /** Get the last element in the list of floppy drives. */
|
---|
84 | DriveInfoList::const_iterator FloppyEnd()
|
---|
85 | {
|
---|
86 | return mFloppyList.end();
|
---|
87 | }
|
---|
88 |
|
---|
89 | /** Get the first element in the list of DVD drives. */
|
---|
90 | DriveInfoList::const_iterator DVDBegin()
|
---|
91 | {
|
---|
92 | return mDVDList.begin();
|
---|
93 | }
|
---|
94 |
|
---|
95 | /** Get the last element in the list of DVD drives. */
|
---|
96 | DriveInfoList::const_iterator DVDEnd()
|
---|
97 | {
|
---|
98 | return mDVDList.end();
|
---|
99 | }
|
---|
100 | private:
|
---|
101 | /** The list of currently available floppy drives */
|
---|
102 | DriveInfoList mFloppyList;
|
---|
103 | /** The list of currently available DVD drives */
|
---|
104 | DriveInfoList mDVDList;
|
---|
105 | };
|
---|
106 |
|
---|
107 | /** Convenience typedef. */
|
---|
108 | typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
|
---|
109 | /** Convenience typedef. */
|
---|
110 | typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Class for probing and returning information about host USB devices.
|
---|
114 | * To use this class, create an instance, call the update methods to do the
|
---|
115 | * actual probing and use the iterator methods to get the result of the probe.
|
---|
116 | */
|
---|
117 | class VBoxMainUSBDeviceInfo
|
---|
118 | {
|
---|
119 | public:
|
---|
120 | /** Structure describing a host USB device */
|
---|
121 | struct USBDeviceInfo
|
---|
122 | {
|
---|
123 | /** The device node of the device. */
|
---|
124 | iprt::MiniString mDevice;
|
---|
125 | /** The sysfs path of the device. */
|
---|
126 | iprt::MiniString mSysfsPath;
|
---|
127 | /** Type for the list of interfaces. */
|
---|
128 | typedef std::vector<iprt::MiniString> InterfaceList;
|
---|
129 | /** The sysfs paths of the device's interfaces. */
|
---|
130 | InterfaceList mInterfaces;
|
---|
131 |
|
---|
132 | /** Constructors */
|
---|
133 | USBDeviceInfo(const iprt::MiniString &aDevice,
|
---|
134 | const iprt::MiniString &aSysfsPath)
|
---|
135 | : mDevice(aDevice),
|
---|
136 | mSysfsPath(aSysfsPath)
|
---|
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 | /**
|
---|
175 | * Class for waiting for a hotplug event. To use this class, create an
|
---|
176 | * instance and call the @a Wait() method, which blocks until an event or a
|
---|
177 | * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
|
---|
178 | * wait before an event occurs.
|
---|
179 | */
|
---|
180 | class VBoxMainHotplugWaiter
|
---|
181 | {
|
---|
182 | /** Opaque context struct. */
|
---|
183 | struct Context;
|
---|
184 |
|
---|
185 | /** Opaque waiter context. */
|
---|
186 | Context *mContext;
|
---|
187 | public:
|
---|
188 | /** Constructor */
|
---|
189 | VBoxMainHotplugWaiter (void);
|
---|
190 | /** Destructor. */
|
---|
191 | ~VBoxMainHotplugWaiter (void);
|
---|
192 | /**
|
---|
193 | * Wait for a hotplug event.
|
---|
194 | *
|
---|
195 | * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
|
---|
196 | * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
|
---|
197 | * temporary failure.
|
---|
198 | * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
|
---|
199 | * succeed if retried.
|
---|
200 | * @returns Possibly other iprt status codes otherwise.
|
---|
201 | * @param cMillies How long to wait for at most.
|
---|
202 | */
|
---|
203 | int Wait (unsigned cMillies);
|
---|
204 | /**
|
---|
205 | * Interrupts an active wait. In the current implementation, the wait
|
---|
206 | * may not return until up to two seconds after calling this method.
|
---|
207 | */
|
---|
208 | void Interrupt (void);
|
---|
209 | };
|
---|
210 |
|
---|
211 | #endif /* ____H_HOSTHARDWARELINUX */
|
---|
212 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|