MediumAttachmentImpl.cpp revision 2c4460e3cb462e743aa08229a17e49aa4f061eff
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "MediumAttachmentImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void MediumAttachment::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the medium attachment object.
*
* @param aMachine 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 aImplicit Wether the attachment contains an implicitly created diff.
*/
bool aImplicit /*= false*/)
{
if (aType == DeviceType_HardDisk)
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
m.allocate();
unconst(m->passthrough) = false;
/* Confirm a successful initialization when it's the case */
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;
}
/**
* @note Locks this object for writing.
*/
bool MediumAttachment::rollback()
{
/* sanity */
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
bool changed = false;
if (m.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
changed = m.hasActualChanges();
m.rollback();
}
return changed;
}
/**
* @note Locks this object for writing.
*/
void MediumAttachment::commit()
{
/* sanity */
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
if (m.isBackedUp())
m.commit();
}
// IHardDiskAttachment properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
AutoReadLock alock(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->port is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->device is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* m->type is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine need to be mutable */
AutoWriteLock lock(this);
if (m->passthrough != !!aPassthrough)
{
m.backup();
m->passthrough = !!aPassthrough;
}
return S_OK;
}
{
AutoCaller autoCaller(this);
AutoReadLock lock(this);
*aPassthrough = m->passthrough;
return S_OK;
}