FloppyImageImpl.cpp revision 1c94c0a63ba68be1a7b2c640e70d7a06464e4fca
/** @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 "FloppyImageImpl.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
mAccessible = FALSE;
return S_OK;
}
void FloppyImage::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the floppy image object.
*
* @param aParent
* parent object
* @param aFilePath
* local file system path to the image file
* (can be relative to the VirtualBox config dir)
* @param aRegistered
* whether this object is being initialized by the VirtualBox init code
* because it is present in the registry
* @param aId
* ID of the DVD image to assign
*
* @return COM result indicator
*/
{
LogFlowThisFunc (("aFilePath={%ls}, aId={%s}\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* share the parent weakly */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* get the full file name */
char filePathFull [RTPATH_MAX];
filePathFull, sizeof (filePathFull));
if (VBOX_FAILURE (vrc))
if (!aRegistered)
{
/* check whether the given file exists or not */
if (VBOX_FAILURE (vrc))
{
/* here we come when the image was just opened by
* IVirtualBox::OpenFloppyImage(). fail in this case */
tr ("Could not open the floppy image '%ls' (%Vrc)"),
}
else
RTFileClose (file);
}
/* Confirm a successful initialization when it's the case */
return rc;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void FloppyImage::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
mParent->removeDependentChild (this);
}
// IFloppyImage properties
/////////////////////////////////////////////////////////////////////////////
{
if (!aId)
return E_POINTER;
AutoCaller autoCaller (this);
/* mUuid is constant during life time, no need to lock */
return S_OK;
}
{
if (!aFilePath)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
if (!aAccessible)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* check whether the given image file exists or not */
if (VBOX_FAILURE (vrc))
{
Log (("FloppyImage::COMGETTER(Accessible): WARNING: '%ls' "
mAccessible = FALSE;
}
else
{
mAccessible = TRUE;
RTFileClose (file);
}
return rc;
}
{
if (!aSize)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
if (VBOX_FAILURE (vrc))
tr ("Failed to open floppy image '%ls' (%Vrc)\n"),
else
{
if (VBOX_SUCCESS (vrc))
else
tr ("Failed to determine size of floppy image '%ls' (%Vrc)\n"),
RTFileClose (file);
}
return rc;
}
// public methods for internal purposes only
////////////////////////////////////////////////////////////////////////////////
/**
* Changes the stored path values of this image to reflect the new location.
* Intended to be called only by VirtualBox::updateSettings() if a machine's
* name change causes directory renaming that affects this image.
*
* @param aNewFullPath new full path to this image file
* @param aNewPath new path to this image file relative to the VirtualBox
* settings directory (when possible)
*
* @note Locks this object for writing.
*/
{
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
}