FloppyDriveImpl.cpp revision 26d2a42f095ded346df2e41cc4837cb426b4753a
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2007 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 "FloppyDriveImpl.h"
#include "MachineImpl.h"
#include "HostImpl.h"
#include "HostFloppyDriveImpl.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void FloppyDrive::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the Floppy drive object.
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the Floppy drive object given another Floppy drive 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 reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the guest 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.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* at present, this must be a snapshot machine */
{
/* associate the DVD image media with the snapshot */
aParent->snapshotId());
AssertComRC (rc);
}
/* 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 FloppyDrive::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
{
/* Deassociate the DVD image (only when mParent is a real Machine or a
* SnapshotMachine instance; SessionMachine instances
* refer to real Machine hard disks). This is necessary for a clean
* re-initialization of the VM after successfully re-checking the
* accessibility state. */
mParent->snapshotId());
AssertComRC (rc);
}
}
// IFloppyDrive properties
/////////////////////////////////////////////////////////////////////////////
{
if (!aEnabled)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
/* leave the lock before informing callbacks */
}
return S_OK;
}
{
if (!aState)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
// IFloppyDrive methods
/////////////////////////////////////////////////////////////////////////////
{
return E_INVALIDARG;
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
/* Our lifetime is bound to mParent's lifetime, so we don't add caller.
* We also don't lock mParent since its mParent field is const. */
true /* aSetError */, &image);
{
{
{
unmount();
/* leave the lock before informing callbacks */
}
}
}
return rc;
}
{
if (!aHostFloppyDrive)
return E_INVALIDARG;
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
unmount();
/* leave the lock before informing callbacks */
}
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
unmount();
/* leave the lock before informing callbacks */
}
return S_OK;
}
{
if (!aFloppyImage)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
if (!aHostDrive)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Loads settings from the given machine node.
* May be called once right after this object creation.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for writing.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* Note: we assume that the default values for attributes of optional
* nodes are assigned in the Data::Data() constructor and don't do it
* here. It implies that this method may only be called after constructing
* a new BIOSSettings object while all its data fields are in the default
* values. Exceptions are fields whose creation time defaults don't match
* values that should be applied when these fields are not explicitly set
* in the settings file (for backwards compatibility reasons). This takes
* place when a setting of a newly created object must default to A while
* the same setting of an object loaded from the old settings file must
* default to B. */
/* Floppy drive (required, contains either Image or HostDrive or nothing) */
/* optional, defaults to true */
{
}
{
/* find the correspoding object */
AssertComRC (rc);
{
}
else if (rc == E_INVALIDARG)
{
/* the host DVD drive is not currently available. we
* assume it will be available later and create an
* extra object now */
AssertComRC (rc);
}
else
AssertComRC (rc);
}
return S_OK;
}
/**
* Saves settings to the given machine node.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for reading.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
{
case DriveState_ImageMounted:
{
AssertComRC (rc);
break;
}
{
AssertComRC (rc);
break;
}
case DriveState_NotMounted:
/* do nothing, i.e.leave the drive node empty */
break;
default:
E_FAIL);
}
return S_OK;
}
/**
* @note Locks this object for writing.
*/
bool FloppyDrive::rollback()
{
/* sanity */
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
bool changed = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
if (changed)
{
{
/* detach the current image that will go away after rollback */
}
}
}
return changed;
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void FloppyDrive::commit()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* lock both for writing since we modify both (mPeer is "master" so locked
* first) */
if (mData.isBackedUp())
{
{
/* detach the old image that will go away after commit */
}
if (mPeer)
{
/* attach new data to the peer and reshare it */
}
}
}
/**
* @note Locks this object for writing, together with the peer object (locked
* for reading) if there is one.
*/
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* peer is not modified, lock it for reading (aThat is "master" so locked
* first) */
/* this will back up current data */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/**
* Helper to unmount a drive.
*
* @return COM status code
*/
{
if (mData->mHostDrive)
return S_OK;
}