BandwidthGroupImpl.cpp revision 63b785c3291332a86a9bc473e68f08121368898b
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2009 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 "BandwidthGroupImpl.h"
#include "MachineImpl.h"
#include "Global.h"
#include "AutoCaller.h"
#include "Logging.h"
////////////////////////////////////////////////////////////////////////////////
//
// private member data definition
//
////////////////////////////////////////////////////////////////////////////////
struct BackupableBandwidthGroupData
{
aMaxMbPerSec(0),
cReferences(0)
{ }
};
struct BandwidthGroup::Data
{
{ }
BandwidthControl * const pParent;
// use the XML settings structure in the members for simplicity
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void BandwidthGroup::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the bandwidth group object.
*
* @returns COM result indicator.
* @param aParent Pointer to our parent object.
* @param aName Name of the storage controller.
* @param aInstance Instance number of the storage controller.
*/
{
LogFlowThisFunc(("aParent=%p aName=\"%s\"\n",
if ( (aType <= BandwidthGroupType_Null)
|| (aType > BandwidthGroupType_Network))
return setError(E_INVALIDARG,
tr("Invalid bandwidth group type type"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* m->pPeer is left null */
m->bd->cReferences = 0;
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the object given another object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @param aReshare
* When false, the original object will remain a data owner.
* Otherwise, data ownership will be transferred from the original
* object to this one.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*
* @note Locks @a aThat object for writing if @a aReshare is @c true, or for
* reading if @a aReshare is false.
*/
bool aReshare /* = false */)
{
LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* sanity */
if (aReshare)
{
}
else
{
}
/* Confirm successful initialization */
return S_OK;
}
/**
* Initializes the storage 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);
/* m->pPeer 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 BandwidthGroup::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
delete m;
m = NULL;
}
{
AutoCaller autoCaller(this);
/* mName is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* type is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* inform direct session if any. */
pMachine->onBandwidthGroupChange(this);
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/** @note Locks objects for writing! */
void BandwidthGroup::rollback()
{
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void BandwidthGroup::commit()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* lock both for writing since we modify both (m->pPeer is "master" so locked
* first) */
if (m->bd.isBackedUp())
{
if (m->pPeer)
{
// attach new data to the peer and reshare it
}
}
}
/**
* Cancels sharing (if any) by making an independent copy of data.
* This operation also resets this object's peer to NULL.
*
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
void BandwidthGroup::unshare()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* peer is not modified, lock it for reading (m->pPeer is "master" so locked
* first) */
{
if (!m->bd.isBackedUp())
}
}
{
return m->pPeer;
}
{
}
{
}
{
return m->bd->aMaxMbPerSec;
}
{
return m->bd->cReferences;
}
void BandwidthGroup::reference()
{
m->bd->cReferences++;
}
void BandwidthGroup::release()
{
m->bd->cReferences--;
}