VirtualBox

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

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

Main and Devices, USB: use hal, DBus and sysfs on Linux if usbfs is not available. Currently disabled

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.3 KB
Line 
1/* $Id: HostHardwareLinux.h 15465 2008-12-14 14:31:14Z 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. */
35extern bool g_testHostHardwareLinux;
36
37/**
38 * Class for probing and returning information about host DVD and floppy drives
39 */
40class VBoxMainDriveInfo
41{
42public:
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 }
106private:
107 /** The list of currently available floppy drives */
108 DriveInfoList mFloppyList;
109 /** The list of currently available DVD drives */
110 DriveInfoList mDVDList;
111};
112
113typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
114typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
115
116/**
117 * Class for probing and returning information about host USB devices
118 */
119class VBoxMainUSBDeviceInfo
120{
121public:
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
162private:
163 /** The list of currently available USB devices */
164 DeviceInfoList mDeviceList;
165};
166
167typedef VBoxMainUSBDeviceInfo::DeviceInfoList USBDeviceInfoList;
168typedef VBoxMainUSBDeviceInfo::USBDeviceInfo USBDeviceInfo;
169typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList;
170
171class VBoxMainHotplugWaiter
172{
173 /** Opaque context struct. */
174 struct Context;
175
176 /** Opaque waiter context. */
177 Context *mContext;
178public:
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 * @param cMillies How long to wait for at most.
193 */
194 int Wait (unsigned cMillies);
195 /** Interrupts an active wait. */
196 void Interrupt (void);
197};
198
199#endif /* ____H_HOSTHARDWARELINUX */
200
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