MachineImpl.h revision a5d293b897a78df8a9bfb091399b8df2b47bea48
/** @file
*
* VirtualBox COM class declaration
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifndef ____H_MACHINEIMPL
#define ____H_MACHINEIMPL
#include "VirtualBoxBase.h"
#include "VirtualBoxXMLUtil.h"
#include "ProgressImpl.h"
#include "SnapshotImpl.h"
#include "VRDPServerImpl.h"
#include "DVDDriveImpl.h"
#include "FloppyDriveImpl.h"
#include "HardDiskAttachmentImpl.h"
#include "Collection.h"
#include "NetworkAdapterImpl.h"
#include "AudioAdapterImpl.h"
#include "BIOSSettingsImpl.h"
// generated header
#include "SchemaDefs.h"
#include <list>
// defines
////////////////////////////////////////////////////////////////////////////////
/**
* Checks whether the given Machine object is mutable (allows for calling setters)
* or not. When the machine is not mutable, sets error info and returns E_ACCESSDENIED.
* The translatable error message is defined in null context.
*
* This macro <b>must</b> be used within setters of all Machine children
* (DVDDrive, NetworkAdapter, AudioAdapter, etc.).
*
* @param machine the machine object (must cast to Machine *)
*/
#define CHECK_MACHINE_MUTABILITY(machine) \
do { \
} while (0)
/** like CHECK_MACHINE_MUTABILITY but a saved state is ok, too */
#define CHECK_MACHINE_MUTABILITY_IGNORING_SAVED(machine) \
do { \
if (!machine->isMutableIgnoringSavedState()) \
} while (0)
// helper declarations
////////////////////////////////////////////////////////////////////////////////
// Machine class
////////////////////////////////////////////////////////////////////////////////
{
/**
* Internal machine data.
*
* Only one instance of this data exists per every machine --
* it is shared by the Machine, SessionMachine and all SnapshotMachine
* instances associated with the given machine using the util::Shareable
* template through the mData variable.
*
* @note |const| members are persistent during lifetime so can be
* accessed without locking.
*
* @note There is no need to lock anything inside init() or uninit()
* methods, because they are always serialized (see AutoCaller).
*/
struct Data
{
/**
* Data structure to hold information about sessions opened for the
* given machine.
*/
struct Session
{
/** Control of the direct session opened by openSession() */
/** list of controls of all opened remote sessions */
/** openRemoteSession() and OnSessionEnd() progress indicator */
/**
* PID of the session object that must be passed to openSession()
* to finalize the openRemoteSession() request
* (i.e., PID of the process created by openRemoteSession())
*/
/** Current session state */
/** Session type string (for indirect sessions) */
/** Sesison machine object */
};
Data();
~Data();
};
/**
* Saved state data.
*
* It's actually only the state file path string, but it needs to be
* separate from Data, because Machine and SessionMachine instances
* share it, while SnapshotMachine does not.
*
* The data variable is |mSSData|.
*/
struct SSData
{
};
/**
* User changeable machine data.
*
* This data is common for all machine snapshots, i.e. it is shared
* by all SnapshotMachine instances associated with the given machine
* using the util::Backupable template through the |mUserData| variable.
*
* SessionMachine instances can alter this data and discard changes.
*
* @note There is no need to lock anything inside init() or uninit()
* methods, because they are always serialized (see AutoCaller).
*/
struct UserData
{
UserData();
~UserData();
{
}
};
/**
* Hardware data.
*
* This data is unique for a machine and for every machine snapshot.
* Stored using the util::Backupable template in the |mHWData| variable.
*
* SessionMachine instances can alter this data and discard changes.
*/
struct HWData
{
HWData();
~HWData();
};
/**
* Hard disk data.
*
* The usage policy is the same as for HWData, but a separate structure
* is necessarym because hard disk data requires different procedures when
* taking or discarding snapshots, etc.
*
* The data variable is |mHWData|.
*/
struct HDData
{
HDData();
~HDData();
/**
* Right after Machine::fixupHardDisks(true): |true| if hard disks
* were actually changed, |false| otherwise
*/
bool mHDAttachmentsChanged;
};
void FinalRelease();
// public initializer/uninitializer for internal purposes only
void uninit();
// IMachine properties
// IMachine methods
// public methods only for internal purposes
/// @todo (dmik) add lock and make non-inlined after revising classes
// that use it (actually, the CHECK_MACHINE_MUTABILITY macro).
// Note: these classes should enter Machine lock to keep the returned
// information valid!
bool isMutable()
{
return ((!mData->mRegistered) ||
(mType == IsSessionMachine &&
}
/// @todo (dmik) add lock and make non-inlined after revising classes
// that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).
// Note: these classes should enter Machine lock to keep the returned
// information valid!
bool isMutableIgnoringSavedState()
{
return ((!mData->mRegistered) ||
(mType == IsSessionMachine &&
}
/// @todo (dmik) add lock and make non-inlined after revising classes
// that use it. Note: they should enter Machine lock to keep the returned
// information valid!
// Note: the below methods are intended to be called only after adding
// a caller to the Machine instance and, when necessary, from under
// the Machine lock in appropriate mode
/// @todo (dmik) revise code using these methods: improving incapsulation
// should make them not necessary
bool aSetError = false)
{
}
// for VirtualBoxSupportErrorInfoImpl
void uninitDataAndChildObjects();
bool aSetError = false);
bool aSetError = false);
bool aSetError = false);
bool aInformCallbacksAnyway = false);
enum
{
// ops for #saveSnapshotSettings()
SaveSS_OpMask = 0xF,
// flags for #saveSnapshotSettings()
SaveSS_UpdateCurStateModified = 0x40,
SaveSS_UpdateCurrentId = 0x80,
// flags for #saveStateSettings()
SaveSTS_CurStateModified = 0x20,
SaveSTS_StateFilePath = 0x40,
SaveSTS_StateTimeStamp = 0x80,
};
bool aOnline);
/** @note This method is not thread safe */
{
}
bool isModified();
bool isReallyModified (bool aIgnoreUserData = false);
const InstanceType mType;
// so they cannot be a part of HWData
const ComObjPtr <NetworkAdapter>
};
// SessionMachine class
////////////////////////////////////////////////////////////////////////////////
/**
* @note Notes on locking objects of this class:
* SessionMachine shares some data with the primary Machine instance (pointed
* to by the |mPeer| member). In order to provide data consistency it also
* shares its lock handle. This means that whenever you lock a SessionMachine
* instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
* instance is also locked in the same lock mode. Keep it in mind.
*/
{
void FinalRelease();
// public initializer/uninitializer for internal purposes only
// AutoLock::Lockable interface
// IInternalMachineControl methods
// public methods only for internal purposes
bool checkForDeath();
#ifdef __WIN__
#endif
struct SnapshotData
{
// used when taking snapshot
// used when saving state
};
struct Uninit {
};
struct Task;
struct TakeSnapshotTask;
struct DiscardSnapshotTask;
struct DiscardCurrentStateTask;
friend struct TakeSnapshotTask;
friend struct DiscardSnapshotTask;
friend struct DiscardCurrentStateTask;
/** interprocess semaphore handle (id) for this machine */
#if defined(__WIN__)
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
int mIPCSem;
#endif
};
// SnapshotMachine class
////////////////////////////////////////////////////////////////////////////////
/**
* @note Notes on locking objects of this class:
* SnapshotMachine shares some data with the primary Machine instance (pointed
* to by the |mPeer| member). In order to provide data consistency it also
* shares its lock handle. This means that whenever you lock a SessionMachine
* instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
* instance is also locked in the same lock mode. Keep it in mind.
*/
{
void FinalRelease();
// public initializer/uninitializer for internal purposes only
void uninit();
// AutoLock::Lockable interface
// public methods only for internal purposes
};
////////////////////////////////////////////////////////////////////////////////
/**
* Returns a pointer to the Machine object for this machine that acts like a
* parent for complex machine data objects such as shared folders, etc.
*
* For primary Machine objects and for SnapshotMachine objects, returns this
* object's pointer itself. For SessoinMachine objects, returns the peer
* (primary) machine pointer.
*/
{
if (mType == IsSessionMachine)
return mPeer;
return this;
}
#endif // ____H_MACHINEIMPL