USBControllerImpl.cpp revision 8d2c7dec46677bbd72336d406d2644e578045dd9
/* $Id$ */
/** @file
* Implementation of IUSBController.
*/
/*
* Copyright (C) 2005-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "USBControllerImpl.h"
#include "Global.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "HostImpl.h"
#include <VBox/settings.h>
#include <algorithm>
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
// defines
/////////////////////////////////////////////////////////////////////////////
struct BackupableUSBData
{
: fEnabled(false),
fEnabledEHCI(false)
{ }
};
struct USBController::Data
{
{ }
~Data()
{};
// peer machine's USB controller
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return BaseFinalConstruct();
}
void USBController::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the USB controller object.
*
* @returns COM result indicator.
* @param aParent Pointer to our parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the USB controller object given another USB controller object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @returns COM result indicator.
* @param aParent Pointer to our parent object.
* @param aPeer The object to share.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the USB controller object given another guest object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void USBController::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
delete m;
m = NULL;
}
// IUSBController properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
// leave the lock for safety
m->pParent->onUSBControllerChange();
}
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
// leave the lock for safety
m->pParent->onUSBControllerChange();
}
return S_OK;
}
{
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_USB
*aEnabled = true;
#else
*aEnabled = false;
#endif
return S_OK;
}
{
AutoCaller autoCaller(this);
/* not accessing data -- no need to lock */
/** @todo This is no longer correct */
*aUSBStandard = 0x0101;
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Loads settings from the given machine node.
* May be called once right after this object creation.
*
* @param aMachineNode <Machine> node.
*
* @note Does not lock "this" as Machine::loadHardware, which calls this, does not lock either.
*/
{
AutoCaller autoCaller(this);
/* Note: we assume that the default values for attributes of optional
* nodes are assigned in the Data::Data() constructor and don't do it
* here. It implies that this method may only be called after constructing
* a new BIOSSettings object while all its data fields are in the default
* values. Exceptions are fields whose creation time defaults don't match
* values that should be applied when these fields are not explicitly set
* in the settings file (for backwards compatibility reasons). This takes
* place when a setting of a newly created object must default to A while
* the same setting of an object loaded from the old settings file must
* default to B. */
return S_OK;
}
/**
* Saves settings to the given machine node.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for reading.
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/** @note Locks objects for writing! */
void USBController::rollback()
{
AutoCaller autoCaller(this);
/* we need the machine state */
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void USBController::commit()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* lock both for writing since we modify both (mPeer is "master" so locked
* first) */
if (m->bd.isBackedUp())
{
if (m->pPeer)
{
/* attach new data to the peer and reshare it */
}
}
}
/**
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* even more sanity */
/* Machine::copyFrom() may not be called when the VM is running */
/* peer is not modified, lock it for reading (aThat is "master" so locked
* first) */
/* this will back up current data */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/* vi: set tabstop=4 shiftwidth=4 expandtab: */