SnapshotImpl.cpp revision 9abd802d84a98ae8602297346ec3b3290423bbab
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 "SnapshotImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
#include <algorithm>
// constructor / destructor
////////////////////////////////////////////////////////////////////////////////
{
RTTimeSpecSetMilli (&mTimeStamp, 0);
};
{
};
{
LogFlowMember (("Snapshot::FinalConstruct()\n"));
return S_OK;
}
void Snapshot::FinalRelease()
{
LogFlowMember (("Snapshot::FinalRelease()\n"));
uninit();
}
/**
* Initializes the instance
*
* @param aId id of the snapshot
* @param aName name of the snapshot
* @param aDescription name of the snapshot (NULL if no description)
* @param aTimeStamp timestamp of the snapshot, in ms since 1970-01-01 UTC
* @param aMachine machine associated with this snapshot
* @param aParent parent snapshot (NULL if no parent)
*/
{
AutoWriteLock alock (this);
if (aParent)
aParent->addDependentChild (this);
setReady (true);
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease(), by the parent when it gets destroyed,
* or by a third party when it decides this object is no more valid.
*/
{
LogFlowMember (("Snapshot::uninit()\n"));
AutoWriteLock alock (this);
if (!isReady())
return;
// uninit all children
setReady (false);
if (mParent)
{
mParent->removeDependentChild (this);
}
{
}
}
/**
* Discards the current snapshot by removing it from the tree of snapshots
* and reparenting its children.
* This method also calls #uninit() in case of success.
*/
{
LogFlowMember (("Snapshot::discard()\n"));
AutoWriteLock alock (this);
AssertReturn (isReady(), (void) 0);
{
{
// reparent the child
if (mParent)
}
}
// detach all our children to avoid their uninit in #uninit()
// finalize uninitialization
uninit();
}
// ISnapshot methods
////////////////////////////////////////////////////////////////////////////////
{
if (!aId)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aName)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
/**
* @note Locks this object for writing, then calls Machine::onSnapshotChange()
* (see its lock requirements).
*/
{
if (!aName)
return E_INVALIDARG;
AutoWriteLock alock (this);
CHECK_READY();
{
}
return S_OK;
}
{
if (!aDescription)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aDescription)
return E_INVALIDARG;
AutoWriteLock alock (this);
CHECK_READY();
{
}
return S_OK;
}
{
if (!aTimeStamp)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aOnline)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aMachine)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aParent)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
{
if (!aChildren)
return E_POINTER;
AutoWriteLock alock (this);
CHECK_READY();
return S_OK;
}
// public methods only for internal purposes
////////////////////////////////////////////////////////////////////////////////
/**
* @note
* Must be called from under the object's lock!
*/
{
}
/**
* Returns the number of children of this snapshot, including grand-children,
* etc.
*/
{
AutoWriteLock alock(this);
AssertReturn (isReady(), 0);
{
}
return count;
}
/**
* Searches for a snapshot with the given ID among children, grand-children,
* etc. of this snapshot. This snapshot itself is also included in the search.
*/
{
AutoWriteLock alock (this);
child = this;
else
{
{
}
}
return child;
}
/**
* Searches for a first snapshot with the given name among children,
* grand-children, etc. of this snapshot. This snapshot itself is also included
* in the search.
*/
{
AutoWriteLock alock (this);
child = this;
else
{
{
}
}
return child;
}
/**
* Returns @c true if the given DVD image is attached to this snapshot or any
* of its children, recursively.
*
* @param aId Image ID to check.
*
* @note Locks this object for reading.
*/
{
AutoReadLock alock (this);
AssertReturn (isReady(), false);
if (d &&
{
AssertComRC (rc);
return true;
}
{
return true;
}
return false;
}
/**
* Returns @c true if the given Floppy image is attached to this snapshot or any
* of its children, recursively.
*
* @param aId Image ID to check.
*
* @note Locks this object for reading.
*/
{
AutoReadLock alock (this);
AssertReturn (isReady(), false);
if (d &&
{
AssertComRC (rc);
return true;
}
{
return true;
}
return false;
}
/**
* Checks if the specified path change affects the saved state file path of
* this snapshot or any of its (grand-)children and updates it accordingly.
*
* Intended to be called by Machine::openConfigLoader() only.
*
* @param aOldPath old path (full)
* @param aNewPath new path (full)
*
* @note Locks this object + children for writing.
*/
{
AutoWriteLock alock (this);
AssertReturnVoid (isReady());
/* state file may be NULL (for offline snapshots) */
{
}
{
}
}