SATAControllerImpl.cpp revision 16ab6cda9bc53bc791284d26da448bbccb11b7ff
/* $Id$ */
/** @file
*
* Implementation of ISATAController.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "SATAControllerImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
#include <algorithm>
// defines
/////////////////////////////////////////////////////////////////////////////
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void SATAController::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the SATA 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 SATA controller object given another SATA 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 SATA 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 SATAController::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
/* uninit all filters (including those still referenced by clients) */
}
// ISATAController properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
/* leave the lock for safety */
}
return S_OK;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
/* We support a maximum of 30 channels. */
return setError (E_INVALIDARG,
tr ("Invalid port count: %lu (must be in range [%lu, %lu])"),
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
/* leave the lock for safety */
}
return S_OK;
}
// ISATAController methods
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller (this);
switch (DevicePosition)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
return E_INVALIDARG;
}
return S_OK;
}
{
return setError (E_INVALIDARG,
tr ("Invalid port number: %l (must be in range [%lu, %lu])"),
aPortNumber, 0, 29);
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
switch (DevicePosition)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
return E_INVALIDARG;
}
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 Locks this object for writing.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* SATA Controller node (required) */
/* enabled (required) */
/* number of useable ports */
/* ide emulation settings (optional, default to 0,1,2,3 respectively) */
return S_OK;
}
/**
* Saves settings to the given machine node.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for reading.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
/* first, delete the entry */
if (!controller.isNull())
controller.zap();
/* then, recreate it */
/* enabled */
/* number of useable ports */
/* ide emulation settings */
return S_OK;
}
/** @note Locks objects for reading! */
bool SATAController::isModified()
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
if (mData.isBackedUp())
return true;
return false;
}
/** @note Locks objects for reading! */
bool SATAController::isReallyModified()
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
if (mData.hasActualChanges())
return true;
return false;
}
/** @note Locks objects for writing! */
bool SATAController::rollback()
{
AutoCaller autoCaller (this);
/* we need the machine state */
AutoWriteLock alock (this);
bool dataChanged = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
}
return dataChanged;
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void SATAController::commit()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* lock both for writing since we modify both (mPeer is "master" so locked
* first) */
if (mData.isBackedUp())
{
if (mPeer)
{
// 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 */
/* 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: */