VirtualBox

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

Last change on this file since 32262 was 32262, checked in by vboxsync, 14 years ago

Main/linux/vector container: simplification

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: HostHardwareLinux.h 32262 2010-09-06 23:37:00Z 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#include <vector.h>
28
29/**
30 * Class for probing and returning information about host DVD and floppy
31 * drives. To use this class, create an instance, call one of the update
32 * methods to do the actual probing and use the iterator methods to get the
33 * result of the probe.
34 */
35class VBoxMainDriveInfo
36{
37public:
38 /** Structure describing a host drive */
39 struct DriveInfo
40 {
41 /** The device node of the drive. */
42 iprt::MiniString mDevice;
43 /** A unique identifier for the device, if available. This should be
44 * kept consistant accross different probing methods of a given
45 * platform if at all possible. */
46 iprt::MiniString mUdi;
47 /** A textual description of the drive. */
48 iprt::MiniString mDescription;
49
50 /** Constructors */
51 DriveInfo(const iprt::MiniString &aDevice,
52 const iprt::MiniString &aUdi = "",
53 const iprt::MiniString &aDescription = "")
54 : mDevice(aDevice),
55 mUdi(aUdi),
56 mDescription(aDescription)
57 { }
58 };
59
60 /** List (resp vector) holding drive information */
61 typedef std::vector<DriveInfo> DriveInfoList;
62
63 /**
64 * Search for host floppy drives and rebuild the list, which remains empty
65 * until the first time this method is called.
66 * @returns iprt status code
67 */
68 int updateFloppies();
69
70 /**
71 * Search for host DVD drives and rebuild the list, which remains empty
72 * until the first time this method is called.
73 * @returns iprt status code
74 */
75 int updateDVDs();
76
77 /** Get the first element in the list of floppy drives. */
78 DriveInfoList::const_iterator FloppyBegin()
79 {
80 return mFloppyList.begin();
81 }
82
83 /** Get the last element in the list of floppy drives. */
84 DriveInfoList::const_iterator FloppyEnd()
85 {
86 return mFloppyList.end();
87 }
88
89 /** Get the first element in the list of DVD drives. */
90 DriveInfoList::const_iterator DVDBegin()
91 {
92 return mDVDList.begin();
93 }
94
95 /** Get the last element in the list of DVD drives. */
96 DriveInfoList::const_iterator DVDEnd()
97 {
98 return mDVDList.end();
99 }
100private:
101 /** The list of currently available floppy drives */
102 DriveInfoList mFloppyList;
103 /** The list of currently available DVD drives */
104 DriveInfoList mDVDList;
105};
106
107/** Convenience typedef. */
108typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
109/** Convenience typedef. */
110typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
111
112
113/** Structure describing a host USB device */
114typedef struct USBDeviceInfo
115{
116 /** The device node of the device. */
117 char *mDevice;
118 /** The system identifier of the device. Specific to the probing
119 * method. */
120 char *mSysfsPath;
121 /** List of interfaces as sysfs paths */
122 VECTOR_PTR(char *) mvecpszInterfaces;
123} USBDeviceInfo;
124
125/** Destructor. */
126void USBDevInfoCleanup(USBDeviceInfo *pSelf);
127
128/** Constructor - the strings will be duplicated. */
129int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
130 const char *aSystemID);
131
132/**
133 * Class for probing and returning information about host USB devices.
134 * To use this class, create an instance, call the update methods to do the
135 * actual probing and use the iterator methods to get the result of the probe.
136 */
137typedef struct VBoxMainUSBDeviceInfo
138{
139 /** The list of currently available USB devices */
140 VECTOR_OBJ(USBDeviceInfo) mvecDevInfo;
141} VBoxMainUSBDeviceInfo;
142
143/** Constructor */
144static inline void VBoxMainUSBDevInfoInit(VBoxMainUSBDeviceInfo *pSelf)
145{
146 VEC_INIT_OBJ(&pSelf->mvecDevInfo, USBDeviceInfo, USBDevInfoCleanup);
147}
148
149/** Destructor */
150static inline void VBoxMainUSBDevInfoCleanup(VBoxMainUSBDeviceInfo *pSelf)
151{
152 VEC_CLEANUP_OBJ(&pSelf->mvecDevInfo);
153}
154
155/**
156 * Search for host USB devices and rebuild the list, which remains empty
157 * until the first time this method is called.
158 * @returns iprt status code
159 */
160int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf);
161
162
163/** Implementation of the hotplug waiter class below */
164class VBoxMainHotplugWaiterImpl
165{
166public:
167 VBoxMainHotplugWaiterImpl(void) {}
168 virtual ~VBoxMainHotplugWaiterImpl(void) {}
169 /** @copydoc VBoxMainHotplugWaiter::Wait */
170 virtual int Wait(RTMSINTERVAL cMillies) = 0;
171 /** @copydoc VBoxMainHotplugWaiter::Interrupt */
172 virtual void Interrupt(void) = 0;
173 /** @copydoc VBoxMainHotplugWaiter::getStatus */
174 virtual int getStatus(void) = 0;
175};
176
177/**
178 * Class for waiting for a hotplug event. To use this class, create an
179 * instance and call the @a Wait() method, which blocks until an event or a
180 * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
181 * wait before an event occurs.
182 */
183class VBoxMainHotplugWaiter
184{
185 /** Class implementation. */
186 VBoxMainHotplugWaiterImpl *mImpl;
187public:
188 /** Constructor. Responsible for selecting the implementation. */
189 VBoxMainHotplugWaiter (void);
190 /** Destructor. */
191 ~VBoxMainHotplugWaiter (void)
192 {
193 delete mImpl;
194 }
195 /**
196 * Wait for a hotplug event.
197 *
198 * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
199 * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
200 * temporary failure.
201 * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
202 * succeed if retried.
203 * @returns Possibly other iprt status codes otherwise.
204 * @param cMillies How long to wait for at most.
205 */
206 int Wait (RTMSINTERVAL cMillies)
207 {
208 return mImpl->Wait(cMillies);
209 }
210 /**
211 * Interrupts an active wait. In the current implementation, the wait
212 * may not return until up to two seconds after calling this method.
213 */
214 void Interrupt (void)
215 {
216 mImpl->Interrupt();
217 }
218
219 int getStatus(void)
220 {
221 return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
222 }
223};
224
225#endif /* ____H_HOSTHARDWARELINUX */
226/* 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