MediumAttachmentImpl.cpp revision dc09cb937d0a66e030b4d7bef88dec429f41e060
/** @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 "MediumAttachmentImpl.h"
#include "MachineImpl.h"
#include "MediumImpl.h"
#include "Global.h"
#include "AutoCaller.h"
#include "Logging.h"
////////////////////////////////////////////////////////////////////////////////
//
// private member data definition
//
////////////////////////////////////////////////////////////////////////////////
{
: lPort(0),
lDevice(0),
fPassthrough(false),
fImplicit(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;
const DeviceType_T type;
bool fPassthrough : 1;
bool fImplicit : 1;
};
struct MediumAttachment::Data
{
Data()
{ }
/** Reference to Machine object, for checking mutable state. */
/* later: const ComObjPtr<MediumAttachment> mPeer; */
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
LogFlowThisFunc(("\n"));
return S_OK;
}
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 Wether accesses are directly passed to the host drive.
*/
const Bstr &aControllerName,
bool aPassthrough)
{
LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aPassthrough=%d\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aPassthrough));
if (aType == DeviceType_HardDisk)
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
m = new Data();
/* Newly created attachments never have an implicitly created medium
* associated with them. Implicit diff image creation happens later. */
/* Confirm a successful initialization when it's the case */
/* Construct a short log name for this attachment. */
this,
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
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->controller is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->bd->port is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->bd->device is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->bd->type is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* @note Locks this object for writing.
*/
void MediumAttachment::rollback()
{
/* sanity */
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing.
*/
void MediumAttachment::commit()
{
/* sanity */
AutoCaller autoCaller(this);
if (m->bd.isBackedUp())
}
bool MediumAttachment::isImplicit() const
{
}
{
}
{
}
{
return m->bd->bstrControllerName;
}
{
}
{
}
{
}
bool MediumAttachment::getPassthrough() const
{
return m->bd->fPassthrough;
}
{
}
/** Must be called from under this object's write lock. */
{
}
/** Must be called from under this object's write lock. */
{
}