BandwidthGroupImpl.cpp revision 376b3b9c4912d5602d0ad8394a429480b8f20e23
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2014 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"
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
//
{
return BaseFinalConstruct();
}
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 bandwidth group.
* @param aType Type of the bandwidth group (net, disk).
* @param aMaxBytesPerSec Maximum bandwidth for the bandwidth group.
*/
{
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 bandwidth group 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;
}
{
/* mName is constant during life time, no need to lock */
return S_OK;
}
{
/* type is constant during life time, no need to lock */
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
if (aMaxBytesPerSec < 0)
return setError(E_INVALIDARG,
tr("Bandwidth group limit cannot be negative"));
/* inform direct session if any. */
pMachine->onBandwidthGroupChange(this);
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/** @note Locks objects for writing! */
void BandwidthGroup::i_rollback()
{
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void BandwidthGroup::i_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::i_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())
}
}
void BandwidthGroup::i_reference()
{
m->bd->cReferences++;
}
void BandwidthGroup::i_release()
{
m->bd->cReferences--;
}