VirtualBox

source: vbox/trunk/src/VBox/Main/include/HostHardwareLinux.h@ 18622

Last change on this file since 18622 was 17688, checked in by vboxsync, 16 years ago

Main API: cosmetics only; no code changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.2 KB
Line 
1/* $Id: HostHardwareLinux.h 17688 2009-03-11 12:38:18Z 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 <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. */
35extern bool g_testHostHardwareLinux;
36
37/**
38 * Class for probing and returning information about host DVD and floppy
39 * drives. To use this class, create an instance, call one of the update
40 * methods to do the actual probing and use the iterator methods to get the
41 * result of the probe.
42 */
43class VBoxMainDriveInfo
44{
45public:
46 /** Structure describing a host drive */
47 struct DriveInfo
48 {
49 /** The device node of the drive. */
50 std::string mDevice;
51 /** The hal unique device identifier, if available. */
52 std::string mUdi;
53 /** A textual description of the drive. */
54 std::string mDescription;
55
56 /** Constructors */
57 DriveInfo (std::string aDevice, std::string aUdi, std::string aDescription)
58 : mDevice (aDevice), mUdi (aUdi), mDescription (aDescription) {}
59 DriveInfo (std::string aDevice, std::string aUdi,
60 const char *aDescription = NULL)
61 : mDevice (aDevice), mUdi (aUdi),
62 mDescription (aDescription != NULL ? aDescription : std::string ()) {}
63 DriveInfo (std::string aDevice, const char *aUdi = NULL,
64 const char *aDescription = NULL)
65 : mDevice (aDevice), mUdi (aUdi != NULL ? aUdi : std::string ()),
66 mDescription (aDescription != NULL ? aDescription : std::string ()) {}
67 };
68
69 /** List (resp vector) holding drive information */
70 typedef std::vector <DriveInfo> DriveInfoList;
71
72 /**
73 * Search for host floppy drives and rebuild the list, which remains empty
74 * until the first time this method is called.
75 * @returns iprt status code
76 */
77 int updateFloppies ();
78
79 /**
80 * Search for host DVD drives and rebuild the list, which remains empty
81 * until the first time this method is called.
82 * @returns iprt status code
83 */
84 int updateDVDs ();
85
86 /** Get the first element in the list of floppy drives. */
87 DriveInfoList::const_iterator FloppyBegin()
88 {
89 return mFloppyList.begin();
90 }
91
92 /** Get the last element in the list of floppy drives. */
93 DriveInfoList::const_iterator FloppyEnd()
94 {
95 return mFloppyList.end();
96 }
97
98 /** Get the first element in the list of DVD drives. */
99 DriveInfoList::const_iterator DVDBegin()
100 {
101 return mDVDList.begin();
102 }
103
104 /** Get the last element in the list of DVD drives. */
105 DriveInfoList::const_iterator DVDEnd()
106 {
107 return mDVDList.end();
108 }
109private:
110 /** The list of currently available floppy drives */
111 DriveInfoList mFloppyList;
112 /** The list of currently available DVD drives */
113 DriveInfoList mDVDList;
114};
115
116/** Convenience typedef. */
117typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
118/** Convenience typedef. */
119typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
120
121/**
122 * Class for probing and returning information about host USB devices.
123 * To use this class, create an instance, call the update methods to do the
124 * actual probing and use the iterator methods to get the result of the probe.
125 */
126class VBoxMainUSBDeviceInfo
127{
128public:
129 /** Structure describing a host USB device */
130 struct USBDeviceInfo
131 {
132 /** The device node of the device. */
133 std::string mDevice;
134 /** The sysfs path of the device. */
135 std::string mSysfsPath;
136 /** Type for the list of interfaces. */
137 typedef std::vector <std::string> InterfaceList;
138 /** The sysfs paths of the device's interfaces. */
139 InterfaceList mInterfaces;
140
141 /** Constructors */
142 USBDeviceInfo (std::string aDevice, std::string aSysfsPath)
143 : mDevice (aDevice), mSysfsPath (aSysfsPath) {}
144 USBDeviceInfo () {}
145 };
146
147 /** List (resp vector) holding drive information */
148 typedef std::vector <USBDeviceInfo> DeviceInfoList;
149
150 /**
151 * Search for host USB devices and rebuild the list, which remains empty
152 * until the first time this method is called.
153 * @returns iprt status code
154 */
155 int UpdateDevices ();
156
157 /** Get the first element in the list of USB devices. */
158 DeviceInfoList::const_iterator DevicesBegin()
159 {
160 return mDeviceList.begin();
161 }
162
163 /** Get the last element in the list of USB devices. */
164 DeviceInfoList::const_iterator DevicesEnd()
165 {
166 return mDeviceList.end();
167 }
168
169private:
170 /** The list of currently available USB devices */
171 DeviceInfoList mDeviceList;
172};
173
174/** Convenience typedef. */
175typedef VBoxMainUSBDeviceInfo::DeviceInfoList USBDeviceInfoList;
176/** Convenience typedef. */
177typedef VBoxMainUSBDeviceInfo::USBDeviceInfo USBDeviceInfo;
178/** Convenience typedef. */
179typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList;
180
181/**
182 * Class for waiting for a hotplug event. To use this class, create an
183 * instance and call the @a Wait() method, which blocks until an event or a
184 * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
185 * wait before an event occurs.
186 */
187class VBoxMainHotplugWaiter
188{
189 /** Opaque context struct. */
190 struct Context;
191
192 /** Opaque waiter context. */
193 Context *mContext;
194public:
195 /** Constructor */
196 VBoxMainHotplugWaiter (void);
197 /** Destructor. */
198 ~VBoxMainHotplugWaiter (void);
199 /**
200 * Wait for a hotplug event.
201 *
202 * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
203 * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
204 * temporary failure.
205 * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
206 * succeed if retried.
207 * @returns Possibly other iprt status codes otherwise.
208 * @param cMillies How long to wait for at most.
209 */
210 int Wait (unsigned cMillies);
211 /**
212 * Interrupts an active wait. In the current implementation, the wait
213 * may not return until up to two seconds after calling this method.
214 */
215 void Interrupt (void);
216};
217
218#endif /* ____H_HOSTHARDWARELINUX */
219/* 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