BandwidthControlImpl.cpp revision d7a2c5e4cc83588b277fd8f28a288773173c3638
/** @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 "BandwidthControlImpl.h"
#include "BandwidthGroupImpl.h"
#include "MachineImpl.h"
#include "Global.h"
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
#include <algorithm>
// defines
/////////////////////////////////////////////////////////////////////////////
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return BaseFinalConstruct();
}
void BandwidthControl::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.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* m->pPeer is left null */
m->llBandwidthGroups.allocate();
/* 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.
*
* @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.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* sanity */
/* create copies of all groups */
m->llBandwidthGroups.allocate();
++it)
{
}
/* Confirm successful initialization */
return S_OK;
}
/**
* Initializes the bandwidth control 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 */
/* create copies of all groups */
m->llBandwidthGroups.allocate();
++it)
{
}
/* Confirm a successful initialization */
return S_OK;
}
/**
* @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) */
/* create private copies of all bandwidth groups */
m->llBandwidthGroups.backup();
m->llBandwidthGroups->clear();
++it)
{
}
}
/** @note Locks objects for writing! */
void BandwidthControl::i_rollback()
{
AutoCaller autoCaller(this);
/* we need the machine state */
if (!m->llBandwidthGroups.isNull())
{
if (m->llBandwidthGroups.isBackedUp())
{
/* unitialize all new groups (absent in the backed up list). */
++it)
{
== backedList->end())
}
/* restore the list */
m->llBandwidthGroups.rollback();
}
/* rollback any changes to groups after restoring the list */
++it)
(*it)->i_rollback();
}
}
void BandwidthControl::i_commit()
{
bool commitBandwidthGroups = false;
if (m->llBandwidthGroups.isBackedUp())
{
m->llBandwidthGroups.commit();
if (m->pPeer)
{
/* Commit all changes to new groups (this will reshare data with
* peers for those who have peers) */
++it)
{
/* look if this group has a peer group */
if (!peer)
{
/* no peer means the device is a newly created one;
* create a peer owning data this device share it with */
peer.createObject();
}
else
{
/* remove peer from the old list */
}
/* and add it to the new list */
}
/* uninit old peer's groups that are left */
++it)
/* attach new list of groups to our peer */
}
else
{
/* we have no peer (our parent is the newly created machine);
* just commit changes to devices */
commitBandwidthGroups = true;
}
}
else
{
/* the list of groups itself is not changed,
* just commit changes to groups themselves */
commitBandwidthGroups = true;
}
{
++it)
}
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void BandwidthControl::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
// uninit all groups on the list (it's a standard std::list not an ObjectsList
// so we must uninit() manually)
++it)
m->llBandwidthGroups.free();
delete m;
m = NULL;
}
/**
* Returns a bandwidth group object with the given name.
*
* @param aName bandwidth group name to find
* @param aBandwidthGroup where to return the found bandwidth group
* @param aSetError true to set extended error info on failure
*/
bool aSetError /* = false */)
{
++it)
{
{
aBandwidthGroup = (*it);
return S_OK;
}
}
if (aSetError)
return setError(VBOX_E_OBJECT_NOT_FOUND,
tr("Could not find a bandwidth group named '%s'"),
return VBOX_E_OBJECT_NOT_FOUND;
}
// To do
{
if (aMaxBytesPerSec < 0)
return setError(E_INVALIDARG,
tr("Bandwidth group limit cannot be negative"));
/* the machine needs to be mutable */
/* try to find one with the name first. */
return setError(VBOX_E_OBJECT_IN_USE,
tr("Bandwidth group named '%s' already exists"),
m->llBandwidthGroups.backup();
return S_OK;
}
{
/* the machine needs to be mutable */
if (group->i_getReferences() != 0)
return setError(VBOX_E_OBJECT_IN_USE,
/* We can remove it now. */
m->llBandwidthGroups.backup();
/* inform the direct session if any */
//onStorageControllerChange(); @todo
return S_OK;
}
{
return S_OK;
}
HRESULT BandwidthControl::getBandwidthGroup(const com::Utf8Str &aName, ComPtr<IBandwidthGroup> &aBandwidthGroup)
{
return rc;
}
HRESULT BandwidthControl::getAllBandwidthGroups(std::vector<ComPtr<IBandwidthGroup> > &aBandwidthGroups)
{
++it)
return S_OK;
}
{
AutoCaller autoCaller(this);
++it)
{
}
return rc;
}
{
AutoCaller autoCaller(this);
++it)
{
}
return S_OK;
}
{
return m->pParent;
}