MediumAttachmentImpl.cpp revision 4a4d0b7611a832602800898d4ec5da6d588b535a
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-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 "MediumAttachmentImpl.h"
#include "MachineImpl.h"
#include "MediumImpl.h"
#include "Global.h"
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
////////////////////////////////////////////////////////////////////////////////
//
// private member data definition
//
////////////////////////////////////////////////////////////////////////////////
{
: lPort(0),
lDevice(0),
fPassthrough(false),
fTempEject(false),
fNonRotational(false),
fDiscard(false),
fImplicit(false),
fHotPluggable(false)
{ }
/* Since MediumAttachment is not a first class citizen when it
* comes to managing settings, having a reference to the storage
* controller will not work - when settings are changed it will point
* to the old, uninitialized instance. Changing this requires
* substantial changes to MediumImpl.cpp. */
const Bstr bstrControllerName;
/* Same counts for the assigned bandwidth group */
const DeviceType_T type;
bool fPassthrough;
bool fTempEject;
bool fNonRotational;
bool fDiscard;
bool fImplicit;
bool fHotPluggable;
};
struct MediumAttachment::Data
{
fIsEjected(false)
{ }
/** Reference to Machine object, for checking mutable state. */
/* later: const ComObjPtr<MediumAttachment> mPeer; */
bool fIsEjected;
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
LogFlowThisFunc(("\n"));
return BaseFinalConstruct();
}
void MediumAttachment::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the medium attachment object.
*
* @param aParent Machine object.
* @param aMedium Medium object.
* @param aController Controller the hard disk is attached to.
* @param aPort Port number.
* @param aDevice Device number on the port.
* @param aPassthrough Whether accesses are directly passed to the host drive.
* @param aBandwidthLimit Bandwidth limit in Mbps
*/
const Bstr &aControllerName,
bool aImplicit,
bool aPassthrough,
bool aTempEject,
bool aNonRotational,
bool aDiscard,
bool aHotPluggable,
const Utf8Str &strBandwidthGroup)
{
LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d aPassthrough=%d aTempEject=%d aNonRotational=%d aDiscard=%d aHotPluggable=%d strBandwithGroup=%s\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aImplicit, aPassthrough, aTempEject, aNonRotational, aDiscard, aHotPluggable, strBandwidthGroup.c_str()));
if (aType == DeviceType_HardDisk)
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
m = new Data();
/* Confirm a successful initialization when it's the case */
/* Construct a short log name for this attachment. */
this,
return S_OK;
}
/**
* Initializes the medium attachment 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.
* Called from FinalRelease().
*/
void MediumAttachment::uninit()
{
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
delete m;
m = NULL;
}
// IHardDiskAttachment properties
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
{
/* m->controller is constant during life time, no need to lock */
return S_OK;
}
{
/* m->bd->port is constant during life time, no need to lock */
return S_OK;
}
{
/* m->bd->device is constant during life time, no need to lock */
return S_OK;
}
{
/* m->bd->type is constant during life time, no need to lock */
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
*aEjected = m->fIsEjected;
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
{
Assert(SUCCEEDED(hrc)); /* This is not allowed to fail because the existence of the group was checked when it was attached. */
}
return hrc;
}
{
return S_OK;
}
/**
* @note Locks this object for writing.
*/
void MediumAttachment::i_rollback()
{
/* sanity */
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing.
*/
void MediumAttachment::i_commit()
{
/* sanity */
AutoCaller autoCaller(this);
if (m->bd.isBackedUp())
}
bool MediumAttachment::i_isImplicit() const
{
}
{
}
{
}
{
return m->bd->bstrControllerName;
}
{
}
{
}
{
}
bool MediumAttachment::i_getPassthrough() const
{
return m->bd->fPassthrough;
}
bool MediumAttachment::i_getTempEject() const
{
return m->bd->fTempEject;
}
bool MediumAttachment::i_getNonRotational() const
{
return m->bd->fNonRotational;
}
bool MediumAttachment::i_getDiscard() const
{
}
bool MediumAttachment::i_getHotPluggable() const
{
return m->bd->fHotPluggable;
}
{
return m->bd->strBandwidthGroup;
}
{
}
/**
* Sets the medium of this attachment and unsets the "implicit" flag.
* @param aMedium
*/
{
m->fIsEjected = false;
}
/** Must be called from under this object's write lock. */
{
}
/** Must be called from under this object's write lock. */
{
}
/** Must be called from under this object's write lock. */
void MediumAttachment::i_updateEjected()
{
m->fIsEjected = true;
}
/** Must be called from under this object's write lock. */
{
}
/** Must be called from under this object's write lock. */
{
}
/** Must be called from under this object's write lock. */
{
}
{
}
{
/* sanity */
AutoCaller autoCaller(this);
}