VirtualBox

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

Last change on this file since 82797 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: HostHardwareLinux.h 76562 2019-01-01 03:22:50Z 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-2019 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 MAIN_INCLUDED_HostHardwareLinux_h
22#define MAIN_INCLUDED_HostHardwareLinux_h
23#ifndef RT_WITHOUT_PRAGMA_ONCE
24# pragma once
25#endif
26
27#include <iprt/err.h>
28#include <iprt/cpp/ministring.h>
29#include <vector>
30#include <vector.h>
31
32/**
33 * Class for probing and returning information about host DVD and floppy
34 * drives. To use this class, create an instance, call one of the update
35 * methods to do the actual probing and use the iterator methods to get the
36 * result of the probe.
37 */
38class VBoxMainDriveInfo
39{
40public:
41 /** Structure describing a host drive */
42 struct DriveInfo
43 {
44 /** The device node of the drive. */
45 RTCString mDevice;
46 /** A unique identifier for the device, if available. This should be
47 * kept consistent across different probing methods of a given
48 * platform if at all possible. */
49 RTCString mUdi;
50 /** A textual description of the drive. */
51 RTCString mDescription;
52
53 /** Constructors */
54 DriveInfo(const RTCString &aDevice,
55 const RTCString &aUdi = "",
56 const RTCString &aDescription = "")
57 : mDevice(aDevice),
58 mUdi(aUdi),
59 mDescription(aDescription)
60 { }
61 };
62
63 /** List (resp vector) holding drive information */
64 typedef std::vector<DriveInfo> DriveInfoList;
65
66 /**
67 * Search for host floppy drives and rebuild the list, which remains empty
68 * until the first time this method is called.
69 * @returns iprt status code
70 */
71 int updateFloppies();
72
73 /**
74 * Search for host DVD drives and rebuild the list, which remains empty
75 * until the first time this method is called.
76 * @returns iprt status code
77 */
78 int updateDVDs();
79
80 /** Get the first element in the list of floppy drives. */
81 DriveInfoList::const_iterator FloppyBegin()
82 {
83 return mFloppyList.begin();
84 }
85
86 /** Get the last element in the list of floppy drives. */
87 DriveInfoList::const_iterator FloppyEnd()
88 {
89 return mFloppyList.end();
90 }
91
92 /** Get the first element in the list of DVD drives. */
93 DriveInfoList::const_iterator DVDBegin()
94 {
95 return mDVDList.begin();
96 }
97
98 /** Get the last element in the list of DVD drives. */
99 DriveInfoList::const_iterator DVDEnd()
100 {
101 return mDVDList.end();
102 }
103private:
104 /** The list of currently available floppy drives */
105 DriveInfoList mFloppyList;
106 /** The list of currently available DVD drives */
107 DriveInfoList mDVDList;
108};
109
110/** Convenience typedef. */
111typedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
112/** Convenience typedef. */
113typedef VBoxMainDriveInfo::DriveInfo DriveInfo;
114
115/** Implementation of the hotplug waiter class below */
116class VBoxMainHotplugWaiterImpl
117{
118public:
119 VBoxMainHotplugWaiterImpl(void) {}
120 virtual ~VBoxMainHotplugWaiterImpl(void) {}
121 /** @copydoc VBoxMainHotplugWaiter::Wait */
122 virtual int Wait(RTMSINTERVAL cMillies) = 0;
123 /** @copydoc VBoxMainHotplugWaiter::Interrupt */
124 virtual void Interrupt(void) = 0;
125 /** @copydoc VBoxMainHotplugWaiter::getStatus */
126 virtual int getStatus(void) = 0;
127};
128
129/**
130 * Class for waiting for a hotplug event. To use this class, create an
131 * instance and call the @a Wait() method, which blocks until an event or a
132 * user-triggered interruption occurs. Call @a Interrupt() to interrupt the
133 * wait before an event occurs.
134 */
135class VBoxMainHotplugWaiter
136{
137 /** Class implementation. */
138 VBoxMainHotplugWaiterImpl *mImpl;
139public:
140 /** Constructor. Responsible for selecting the implementation. */
141 VBoxMainHotplugWaiter(const char *pcszDevicesRoot);
142 /** Destructor. */
143 ~VBoxMainHotplugWaiter (void)
144 {
145 delete mImpl;
146 }
147 /**
148 * Wait for a hotplug event.
149 *
150 * @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
151 * @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
152 * temporary failure.
153 * @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
154 * succeed if retried.
155 * @returns Possibly other iprt status codes otherwise.
156 * @param cMillies How long to wait for at most.
157 */
158 int Wait (RTMSINTERVAL cMillies)
159 {
160 return mImpl->Wait(cMillies);
161 }
162 /**
163 * Interrupts an active wait. In the current implementation, the wait
164 * may not return until up to two seconds after calling this method.
165 */
166 void Interrupt (void)
167 {
168 mImpl->Interrupt();
169 }
170
171 int getStatus(void)
172 {
173 return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
174 }
175};
176
177#endif /* !MAIN_INCLUDED_HostHardwareLinux_h */
178/* 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