HostHardwareLinux.h revision a0c1e203edd9781c6d0f7560e37dbc729fef5991
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/* $Id$ */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** @file
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Classes for handling hardware detection under Linux.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync *
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Please feel free to expand these to work for other systems (Solaris!) or to
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * add new ones for other systems.
c0b6af690ad705bddfa87c643b89770a7a0aaf5avboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/*
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Copyright (C) 2008-2009 Oracle Corporation
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync *
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * available from http://www.virtualbox.org. This file is free software;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * you can redistribute it and/or modify it under the terms of the GNU
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * General Public License (GPL) as published by the Free Software
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync#ifndef ____H_HOSTHARDWARELINUX
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync# define ____H_HOSTHARDWARELINUX
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync#include <iprt/err.h>
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync#include <iprt/cpp/ministring.h>
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync#include <vector>
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/**
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Class for probing and returning information about host DVD and floppy
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * drives. To use this class, create an instance, call one of the update
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * methods to do the actual probing and use the iterator methods to get the
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * result of the probe.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncclass VBoxMainDriveInfo
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync{
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncpublic:
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Structure describing a host drive */
2b3dc93fedb4e72ac5b3cbaa89a9fc2f559be550vboxsync struct DriveInfo
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync {
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** The device node of the drive. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync iprt::MiniString mDevice;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** A unique identifier for the device, if available. This should be
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * kept consistant accross different probing methods of a given
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * platform if at all possible. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync iprt::MiniString mUdi;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** A textual description of the drive. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync iprt::MiniString mDescription;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Constructors */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfo(const iprt::MiniString &aDevice,
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync const iprt::MiniString &aUdi = "",
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync const iprt::MiniString &aDescription = "")
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync : mDevice(aDevice),
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync mUdi(aUdi),
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync mDescription(aDescription)
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync { }
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync };
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** List (resp vector) holding drive information */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync typedef std::vector<DriveInfo> DriveInfoList;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /**
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Search for host floppy drives and rebuild the list, which remains empty
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * until the first time this method is called.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * @returns iprt status code
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync int updateFloppies();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /**
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Search for host DVD drives and rebuild the list, which remains empty
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * until the first time this method is called.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * @returns iprt status code
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync int updateDVDs();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Get the first element in the list of floppy drives. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList::const_iterator FloppyBegin()
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync {
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync return mFloppyList.begin();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync }
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Get the last element in the list of floppy drives. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList::const_iterator FloppyEnd()
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync {
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync return mFloppyList.end();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync }
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Get the first element in the list of DVD drives. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList::const_iterator DVDBegin()
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync {
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync return mDVDList.begin();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync }
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** Get the last element in the list of DVD drives. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList::const_iterator DVDEnd()
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync {
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync return mDVDList.end();
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync }
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncprivate:
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** The list of currently available floppy drives */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList mFloppyList;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** The list of currently available DVD drives */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync DriveInfoList mDVDList;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync};
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** Convenience typedef. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsynctypedef VBoxMainDriveInfo::DriveInfoList DriveInfoList;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** Convenience typedef. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsynctypedef VBoxMainDriveInfo::DriveInfo DriveInfo;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** Structure describing a host USB device */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsynctypedef struct USBDeviceInfo
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync{
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** The device node of the device. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync char *mDevice;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** The system identifier of the device. Specific to the probing
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * method. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync char *mSysfsPath;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync /** List of interfaces. Only one simulaneous traversal is possible. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync struct USBInterfaceList *mInterfaces;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync} USBDeviceInfo;
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** Destructor. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncvoid USBDevInfoCleanup(USBDeviceInfo *pSelf);
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/** Constructor - the strings will be duplicated. */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncint USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync const char *aSystemID);
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/**
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Return the first in a list of USB device interfaces (that is, its sysfs
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * path), or NULL if there are none.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync */
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsyncchar *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces);
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync/**
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Return the next in a list of USB device interfaces (that is, its sysfs
* path), or NULL if there are none.
*/
char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces);
/** Vector type holding device information */
#define VECTOR_TYPE USBDeviceInfo
#define VECTOR_TYPENAME USBDeviceInfoList
#define VECTOR_DESTRUCTOR USBDevInfoCleanup
#include "vector.h"
/**
* Class for probing and returning information about host USB devices.
* To use this class, create an instance, call the update methods to do the
* actual probing and use the iterator methods to get the result of the probe.
*/
typedef struct VBoxMainUSBDeviceInfo
{
/** The list of currently available USB devices */
USBDeviceInfoList mDeviceList;
} VBoxMainUSBDeviceInfo;
/** Constructor */
static inline int VBoxMainUSBDevInfoInit(VBoxMainUSBDeviceInfo *pSelf)
{
return USBDeviceInfoList_init(&pSelf->mDeviceList);
}
/** Destructor */
static inline void VBoxMainUSBDevInfoCleanup(VBoxMainUSBDeviceInfo *pSelf)
{
USBDeviceInfoList_cleanup(&pSelf->mDeviceList);
}
/**
* Search for host USB devices and rebuild the list, which remains empty
* until the first time this method is called.
* @returns iprt status code
*/
int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf);
/** Get the first element in the list of USB devices. */
static inline const USBDeviceInfoList_iterator *USBDevInfoBegin
(VBoxMainUSBDeviceInfo *pSelf)
{
return USBDeviceInfoList_begin(&pSelf->mDeviceList);
}
/** Get the last element in the list of USB devices. */
static inline const USBDeviceInfoList_iterator *USBDevInfoEnd
(VBoxMainUSBDeviceInfo *pSelf)
{
return USBDeviceInfoList_end(&pSelf->mDeviceList);
}
/** Implementation of the hotplug waiter class below */
class VBoxMainHotplugWaiterImpl
{
public:
VBoxMainHotplugWaiterImpl(void) {}
virtual ~VBoxMainHotplugWaiterImpl(void) {}
/** @copydoc VBoxMainHotplugWaiter::Wait */
virtual int Wait(RTMSINTERVAL cMillies) = 0;
/** @copydoc VBoxMainHotplugWaiter::Interrupt */
virtual void Interrupt(void) = 0;
/** @copydoc VBoxMainHotplugWaiter::getStatus */
virtual int getStatus(void) = 0;
};
/**
* Class for waiting for a hotplug event. To use this class, create an
* instance and call the @a Wait() method, which blocks until an event or a
* user-triggered interruption occurs. Call @a Interrupt() to interrupt the
* wait before an event occurs.
*/
class VBoxMainHotplugWaiter
{
/** Class implementation. */
VBoxMainHotplugWaiterImpl *mImpl;
public:
/** Constructor. Responsible for selecting the implementation. */
VBoxMainHotplugWaiter (void);
/** Destructor. */
~VBoxMainHotplugWaiter (void)
{
delete mImpl;
}
/**
* Wait for a hotplug event.
*
* @returns VINF_SUCCESS if an event occurred or if Interrupt() was called.
* @returns VERR_TRY_AGAIN if the wait failed but this might (!) be a
* temporary failure.
* @returns VERR_NOT_SUPPORTED if the wait failed and will definitely not
* succeed if retried.
* @returns Possibly other iprt status codes otherwise.
* @param cMillies How long to wait for at most.
*/
int Wait (RTMSINTERVAL cMillies)
{
return mImpl->Wait(cMillies);
}
/**
* Interrupts an active wait. In the current implementation, the wait
* may not return until up to two seconds after calling this method.
*/
void Interrupt (void)
{
mImpl->Interrupt();
}
int getStatus(void)
{
return mImpl ? mImpl->getStatus() : VERR_NO_MEMORY;
}
};
#endif /* ____H_HOSTHARDWARELINUX */
/* vi: set tabstop=4 shiftwidth=4 expandtab: */