VirtualBox

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

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette