1 | /* $Id: HostHardwareLinux.h 15401 2008-12-12 22:05:34Z 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 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 <string>
|
---|
29 | #include <vector>
|
---|
30 |
|
---|
31 | /** This should only be enabled when testing. It causes all methods to be used
|
---|
32 | * when probing for drives instead of stopping as soon as one method is
|
---|
33 | * successful. This is a global instead of a define in order to keep the test
|
---|
34 | * code closer to the real code. */
|
---|
35 | extern bool g_testHostHardwareLinux;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Class for probing and returning information about host DVD and floppy drives
|
---|
39 | */
|
---|
40 | class VBoxMainDriveInfo
|
---|
41 | {
|
---|
42 | public:
|
---|
43 | /** Structure describing a host drive */
|
---|
44 | struct DriveInfo
|
---|
45 | {
|
---|
46 | /** The device node of the drive. */
|
---|
47 | std::string mDevice;
|
---|
48 | /** The hal unique device identifier, if available. */
|
---|
49 | std::string mUdi;
|
---|
50 | /** A textual description of the drive. */
|
---|
51 | std::string mDescription;
|
---|
52 |
|
---|
53 | /** Constructors */
|
---|
54 | DriveInfo (std::string aDevice, std::string aUdi, std::string aDescription)
|
---|
55 | : mDevice (aDevice), mUdi (aUdi), mDescription (aDescription) {}
|
---|
56 | DriveInfo (std::string aDevice, std::string aUdi,
|
---|
57 | const char *aDescription = NULL)
|
---|
58 | : mDevice (aDevice), mUdi (aUdi),
|
---|
59 | mDescription (aDescription != NULL ? aDescription : std::string ()) {}
|
---|
60 | DriveInfo (std::string aDevice, const char *aUdi = NULL,
|
---|
61 | const char *aDescription = NULL)
|
---|
62 | : mDevice (aDevice), mUdi (aUdi != NULL ? aUdi : std::string ()),
|
---|
63 | mDescription (aDescription != NULL ? aDescription : std::string ()) {}
|
---|
64 | };
|
---|
65 |
|
---|
66 | /** List (resp vector) holding drive information */
|
---|
67 | typedef std::vector <DriveInfo> DriveInfoList;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Search for host floppy drives and rebuild the list, which remains empty
|
---|
71 | * until the first time it is called.
|
---|
72 | * @returns iprt status code
|
---|
73 | */
|
---|
74 | int updateFloppies ();
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Search for host DVD drives and rebuild the list, which remains empty
|
---|
78 | * until the first time it is called.
|
---|
79 | * @returns iprt status code
|
---|
80 | */
|
---|
81 | int updateDVDs ();
|
---|
82 |
|
---|
83 | /** Get the first element in the list of floppy drives. */
|
---|
84 | DriveInfoList::const_iterator FloppyBegin()
|
---|
85 | {
|
---|
86 | return mFloppyList.begin();
|
---|
87 | }
|
---|
88 |
|
---|
89 | /** Get the last element in the list of floppy drives. */
|
---|
90 | DriveInfoList::const_iterator FloppyEnd()
|
---|
91 | {
|
---|
92 | return mFloppyList.end();
|
---|
93 | }
|
---|
94 |
|
---|
95 | /** Get the first element in the list of DVD drives. */
|
---|
96 | DriveInfoList::const_iterator DVDBegin()
|
---|
97 | {
|
---|
98 | return mDVDList.begin();
|
---|
99 | }
|
---|
100 |
|
---|
101 | /** Get the last element in the list of DVD drives. */
|
---|
102 | DriveInfoList::const_iterator DVDEnd()
|
---|
103 | {
|
---|
104 | return mDVDList.end();
|
---|
105 | }
|
---|
106 | private:
|
---|
107 | /** The list of currently available floppy drives */
|
---|
108 | DriveInfoList mFloppyList;
|
---|
109 | /** The list of currently available DVD drives */
|
---|
110 | DriveInfoList mDVDList;
|
---|
111 | };
|
---|
112 |
|
---|
113 | typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
|
---|
114 | typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Class for probing and returning information about host USB devices
|
---|
118 | */
|
---|
119 | class VBoxMainUSBDeviceInfo
|
---|
120 | {
|
---|
121 | public:
|
---|
122 | /** Structure describing a host USB device */
|
---|
123 | struct USBDeviceInfo
|
---|
124 | {
|
---|
125 | /** The device node of the device. */
|
---|
126 | std::string mDevice;
|
---|
127 | /** The sysfs path of the device. */
|
---|
128 | std::string mSysfsPath;
|
---|
129 | /** Type for the list of interfaces. */
|
---|
130 | typedef std::vector <std::string> InterfaceList;
|
---|
131 | /** The sysfs paths of the device's interfaces. */
|
---|
132 | InterfaceList mInterfaces;
|
---|
133 |
|
---|
134 | /** Constructors */
|
---|
135 | USBDeviceInfo (std::string aDevice, std::string aSysfsPath)
|
---|
136 | : mDevice (aDevice), mSysfsPath (aSysfsPath) {}
|
---|
137 | USBDeviceInfo () {}
|
---|
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 it 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 | typedef VBoxMainUSBDeviceInfo::DeviceInfoList USBDeviceInfoList;
|
---|
168 | typedef VBoxMainUSBDeviceInfo::USBDeviceInfo USBDeviceInfo;
|
---|
169 | typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList;
|
---|
170 |
|
---|
171 | class VBoxMainHotplugWaiter
|
---|
172 | {
|
---|
173 | /** Opaque context struct. */
|
---|
174 | struct Context;
|
---|
175 |
|
---|
176 | /** Opaque waiter context. */
|
---|
177 | Context *mContext;
|
---|
178 | public:
|
---|
179 | /** Constructor */
|
---|
180 | VBoxMainHotplugWaiter (void);
|
---|
181 | /** Destructor. */
|
---|
182 | ~VBoxMainHotplugWaiter (void);
|
---|
183 | /**
|
---|
184 | * Wait for a hotplug event.
|
---|
185 | *
|
---|
186 | * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
|
---|
187 | * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
|
---|
188 | * temporary failure.
|
---|
189 | * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
|
---|
190 | * succeed if retried.
|
---|
191 | * @returns Possibly other iprt status codes otherwise.
|
---|
192 | */
|
---|
193 | int Wait (void);
|
---|
194 | /** Interrupts an active wait. */
|
---|
195 | void Interrupt (void);
|
---|
196 | };
|
---|
197 |
|
---|
198 | #endif /* ____H_HOSTHARDWARELINUX */
|
---|
199 |
|
---|