VirtualBox

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

Last change on this file since 67954 was 62485, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: HostHardwareLinux.h 62485 2016-07-22 18:36:43Z vboxsync $ */
2/** @file
3 * VirtualBox Main - 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-2016 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 RTCString mDevice;
43 /** A unique identifier for the device, if available. This should be
44 * kept consistent across different probing methods of a given
45 * platform if at all possible. */
46 RTCString mUdi;
47 /** A textual description of the drive. */
48 RTCString mDescription;
49
50 /** Constructors */
51 DriveInfo(const RTCString &aDevice,
52 const RTCString &aUdi = "",
53 const RTCString &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/** Implementation of the hotplug waiter class below */
113class VBoxMainHotplugWaiterImpl
114{
115public:
116 VBoxMainHotplugWaiterImpl(void) {}
117 virtual ~VBoxMainHotplugWaiterImpl(void) {}
118 /** @copydoc VBoxMainHotplugWaiter::Wait */
119 virtual int Wait(RTMSINTERVAL cMillies) = 0;
120 /** @copydoc VBoxMainHotplugWaiter::Interrupt */
121 virtual void Interrupt(void) = 0;
122 /** @copydoc VBoxMainHotplugWaiter::getStatus */
123 virtual int getStatus(void) = 0;
124};
125
126/**
127 * Class for waiting for a hotplug event. To use this class, create an
128 * instance and call the @a Wait() method, which blocks until an event or a
129 * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
130 * wait before an event occurs.
131 */
132class VBoxMainHotplugWaiter
133{
134 /** Class implementation. */
135 VBoxMainHotplugWaiterImpl *mImpl;
136public:
137 /** Constructor. Responsible for selecting the implementation. */
138 VBoxMainHotplugWaiter(const char *pcszDevicesRoot);
139 /** Destructor. */
140 ~VBoxMainHotplugWaiter (void)
141 {
142 delete mImpl;
143 }
144 /**
145 * Wait for a hotplug event.
146 *
147 * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
148 * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
149 * temporary failure.
150 * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
151 * succeed if retried.
152 * @returns Possibly other iprt status codes otherwise.
153 * @param cMillies How long to wait for at most.
154 */
155 int Wait (RTMSINTERVAL cMillies)
156 {
157 return mImpl->Wait(cMillies);
158 }
159 /**
160 * Interrupts an active wait. In the current implementation, the wait
161 * may not return until up to two seconds after calling this method.
162 */
163 void Interrupt (void)
164 {
165 mImpl->Interrupt();
166 }
167
168 int getStatus(void)
169 {
170 return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
171 }
172};
173
174#endif /* ____H_HOSTHARDWARELINUX */
175/* 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