VirtualBox

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

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

Main/linux/USB: moved a vector container-based implementation detail out of the interface

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: HostHardwareLinux.h 32142 2010-08-31 13:00:46Z 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.virtualbox.org. 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/** Structure describing a host USB device */
113typedef struct USBDeviceInfo
114{
115 /** The device node of the device. */
116 char *mDevice;
117 /** The system identifier of the device. Specific to the probing
118 * method. */
119 char *mSysfsPath;
120 /** List of interfaces. Only one simulaneous traversal is possible. */
121 struct USBInterfaceList *mInterfaces;
122} USBDeviceInfo;
123
124/** Destructor. */
125void USBDevInfoCleanup(USBDeviceInfo *pSelf);
126
127/** Constructor - the strings will be duplicated. */
128int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
129 const char *aSystemID);
130
131/**
132 * Return the first in a list of USB device interfaces (that is, its sysfs
133 * path), or NULL if there are none.
134 */
135char *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces);
136
137/**
138 * Return the next in a list of USB device interfaces (that is, its sysfs
139 * path), or NULL if there are none.
140 */
141char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces);
142
143
144/** Vector type holding device information */
145#define VECTOR_TYPE USBDeviceInfo
146#define VECTOR_TYPENAME USBDeviceInfoList
147#define VECTOR_DESTRUCTOR USBDevInfoCleanup
148#include "vector.h"
149
150
151/**
152 * Class for probing and returning information about host USB devices.
153 * To use this class, create an instance, call the update methods to do the
154 * actual probing and use the iterator methods to get the result of the probe.
155 */
156typedef struct VBoxMainUSBDeviceInfo
157{
158 /** The list of currently available USB devices */
159 USBDeviceInfoList mDeviceList;
160} VBoxMainUSBDeviceInfo;
161
162/** Constructor */
163static inline int VBoxMainUSBDevInfoInit(VBoxMainUSBDeviceInfo *pSelf)
164{
165 return USBDeviceInfoList_init(&pSelf->mDeviceList);
166}
167
168/** Destructor */
169static inline void VBoxMainUSBDevInfoCleanup(VBoxMainUSBDeviceInfo *pSelf)
170{
171 USBDeviceInfoList_cleanup(&pSelf->mDeviceList);
172}
173
174/**
175 * Search for host USB devices and rebuild the list, which remains empty
176 * until the first time this method is called.
177 * @returns iprt status code
178 */
179int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf);
180
181/** Get the first element in the list of USB devices. */
182static inline const USBDeviceInfoList_iterator *USBDevInfoBegin
183 (VBoxMainUSBDeviceInfo *pSelf)
184{
185 return USBDeviceInfoList_begin(&pSelf->mDeviceList);
186}
187
188
189/** Get the last element in the list of USB devices. */
190static inline const USBDeviceInfoList_iterator *USBDevInfoEnd
191 (VBoxMainUSBDeviceInfo *pSelf)
192{
193 return USBDeviceInfoList_end(&pSelf->mDeviceList);
194}
195
196
197/** Implementation of the hotplug waiter class below */
198class VBoxMainHotplugWaiterImpl
199{
200public:
201 VBoxMainHotplugWaiterImpl(void) {}
202 virtual ~VBoxMainHotplugWaiterImpl(void) {}
203 /** @copydoc VBoxMainHotplugWaiter::Wait */
204 virtual int Wait(RTMSINTERVAL cMillies) = 0;
205 /** @copydoc VBoxMainHotplugWaiter::Interrupt */
206 virtual void Interrupt(void) = 0;
207 /** @copydoc VBoxMainHotplugWaiter::getStatus */
208 virtual int getStatus(void) = 0;
209};
210
211/**
212 * Class for waiting for a hotplug event. To use this class, create an
213 * instance and call the @a Wait() method, which blocks until an event or a
214 * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
215 * wait before an event occurs.
216 */
217class VBoxMainHotplugWaiter
218{
219 /** Class implementation. */
220 VBoxMainHotplugWaiterImpl *mImpl;
221public:
222 /** Constructor. Responsible for selecting the implementation. */
223 VBoxMainHotplugWaiter (void);
224 /** Destructor. */
225 ~VBoxMainHotplugWaiter (void)
226 {
227 delete mImpl;
228 }
229 /**
230 * Wait for a hotplug event.
231 *
232 * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
233 * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
234 * temporary failure.
235 * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
236 * succeed if retried.
237 * @returns Possibly other iprt status codes otherwise.
238 * @param cMillies How long to wait for at most.
239 */
240 int Wait (RTMSINTERVAL cMillies)
241 {
242 return mImpl->Wait(cMillies);
243 }
244 /**
245 * Interrupts an active wait. In the current implementation, the wait
246 * may not return until up to two seconds after calling this method.
247 */
248 void Interrupt (void)
249 {
250 mImpl->Interrupt();
251 }
252
253 int getStatus(void)
254 {
255 return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
256 }
257};
258
259#endif /* ____H_HOSTHARDWARELINUX */
260/* 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