MachineImpl.h revision 0a90c7a0df11e88ee3ac85afb235d7acedbb0af7
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * VirtualBox COM class declaration
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * available from http://www.virtualbox.org. This file is free software;
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * General Public License (GPL) as published by the Free Software
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * additional information or have any questions.
2f827df539da232220444c27f2b207a707a045b0vboxsync#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
2f827df539da232220444c27f2b207a707a045b0vboxsync#endif /* VBOX_WITH_RESOURCE_USAGE_API */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync// generated header
7cca5a9aeb06913531b982bf772508d09b4c2f0bvboxsync////////////////////////////////////////////////////////////////////////////////
2f827df539da232220444c27f2b207a707a045b0vboxsync// helper declarations
2f827df539da232220444c27f2b207a707a045b0vboxsync////////////////////////////////////////////////////////////////////////////////
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync// Machine class
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync////////////////////////////////////////////////////////////////////////////////
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync public VirtualBoxSupportErrorInfoImpl<Machine, IMachine>,
2f827df539da232220444c27f2b207a707a045b0vboxsync enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync enum InitMode { Init_New, Init_Import, Init_Registered };
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Internal machine data.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Only one instance of this data exists per every machine -- it is shared
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * by the Machine, SessionMachine and all SnapshotMachine instances
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * associated with the given machine using the util::Shareable template
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * through the mData variable.
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * @note |const| members are persistent during lifetime so can be
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * accessed without locking.
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * @note There is no need to lock anything inside init() or uninit()
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * methods, because they are always serialized (see AutoCaller).
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * Data structure to hold information about sessions opened for the
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * given machine.
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync /** Control of the direct session opened by openSession() */
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** list of controls of all opened remote sessions */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** openRemoteSession() and OnSessionEnd() progress indicator */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * PID of the session object that must be passed to openSession() to
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * finalize the openRemoteSession() request (i.e., PID of the
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * process created by openRemoteSession())
2f827df539da232220444c27f2b207a707a045b0vboxsync /** Current session state */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Session type string (for indirect sessions) */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Session machine object */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Successfully locked media list. The 2nd value in the pair is true
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * if the medium is locked for writing and false if locked for
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync typedef std::list<std::pair<ComPtr<IMedium>, bool > > LockedMedia;
2f827df539da232220444c27f2b207a707a045b0vboxsync /** Flag indicating that the config file is read-only. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync // machine settings XML file
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync // protectes the snapshots tree of this machine
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Saved state data.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * It's actually only the state file path string, but it needs to be
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * separate from Data, because Machine and SessionMachine instances
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * share it, while SnapshotMachine does not.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * The data variable is |mSSData|.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * User changeable machine data.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * This data is common for all machine snapshots, i.e. it is shared
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * by all SnapshotMachine instances associated with the given machine
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * using the util::Backupable template through the |mUserData| variable.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * SessionMachine instances can alter this data and discard changes.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * @note There is no need to lock anything inside init() or uninit()
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * methods, because they are always serialized (see AutoCaller).
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync && mTeleporterPassword == that.mTeleporterPassword);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Hardware data.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * This data is unique for a machine and for every machine snapshot.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Stored using the util::Backupable template in the |mHWData| variable.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * SessionMachine instances can alter this data and discard changes.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Data structure to hold information about a guest property.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** Property name */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** Property value */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /** Property timestamp */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /** Property flags */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync typedef std::list<GuestProperty> GuestPropertyList;
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Hard disk and other media data.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * The usage policy is the same as for HWData, but a separate structure
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * is necessary because hard disk data requires different procedures when
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * taking or discarding snapshots, etc.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * The data variable is |mMediaData|.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Helper class that safely manages the machine state dependency by
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * calling Machine::addStateDependency() on construction and
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Machine::releaseStateDependency() on destruction. Intended for Machine
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * children. The usage pattern is:
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * AutoCaller autoCaller(this);
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * CheckComRCReturnRC(autoCaller.rc());
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Machine::AutoStateDependency<MutableStateDep> adep(mParent);
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * CheckComRCReturnRC(stateDep.rc());
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * // code that depends on the particular machine state
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Note that it is more convenient to use the following individual
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * shortcut classes instead of using this template directly:
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * AutoAnyStateDependency, AutoMutableStateDependency and
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * AutoMutableOrSavedStateDependency. The usage pattern is exactly the
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * same as above except that there is no need to specify the template
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * argument because it is already done by the shortcut class.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * @param taDepType Dependecy type to manage.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync mRC = aThat->addStateDependency(taDepType, &mMachineState,
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /** Decreases the number of dependencies before the instance is
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * destroyed. Note that will reset #rc() to E_FAIL. */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync /** Restores the number of callers after by #release(). #rc() will be
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * reset to the result of calling addStateDependency() and must be
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * rechecked to ensure the operation succeeded. */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync mRC = mThat->addStateDependency(taDepType, &mMachineState,
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync /** Returns the result of Machine::addStateDependency(). */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /** Shortcut to SUCCEEDED(rc()). */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync /** Returns the machine state value as returned by
7cca5a9aeb06913531b982bf772508d09b4c2f0bvboxsync * Machine::addStateDependency(). */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync MachineState_T machineState() const { return mMachineState; }
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync /** Returns the machine state value as returned by
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Machine::addStateDependency(). */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync BOOL machineRegistered() const { return mRegistered; }
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoStateDependency)
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Shortcut to AutoStateDependency<AnyStateDep>.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * See AutoStateDependency to get the usage pattern.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Accepts any machine state and guarantees the state won't change before
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * this object is destroyed. If the machine state cannot be protected (as
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * a result of the state change currently in progress), this instance's
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * #rc() method will indicate a failure, and the caller is not allowed to
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * rely on any particular machine state and should return the failed
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * result code to the upper level.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync typedef AutoStateDependency<AnyStateDep> AutoAnyStateDependency;
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Shortcut to AutoStateDependency<MutableStateDep>.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * See AutoStateDependency to get the usage pattern.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Succeeds only if the machine state is in one of the mutable states, and
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * guarantees the given mutable state won't change before this object is
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * destroyed. If the machine is not mutable, this instance's #rc() method
7cca5a9aeb06913531b982bf772508d09b4c2f0bvboxsync * will indicate a failure, and the caller is not allowed to rely on any
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * particular machine state and should return the failed result code to
7cca5a9aeb06913531b982bf772508d09b4c2f0bvboxsync * the upper level.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Intended to be used within all setter methods of IMachine
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * children objects (DVDDrive, NetworkAdapter, AudioAdapter, etc.) to
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * provide data protection and consistency.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync typedef AutoStateDependency<MutableStateDep> AutoMutableStateDependency;
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Shortcut to AutoStateDependency<MutableOrSavedStateDep>.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * See AutoStateDependency to get the usage pattern.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Succeeds only if the machine state is in one of the mutable states, or
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * if the machine is in the Saved state, and guarantees the given mutable
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * state won't change before this object is destroyed. If the machine is
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * not mutable, this instance's #rc() method will indicate a failure, and
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * the caller is not allowed to rely on any particular machine state and
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * should return the failed result code to the upper level.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Intended to be used within setter methods of IMachine
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * children objects that may also operate on Saved machines.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync typedef AutoStateDependency<MutableOrSavedStateDep> AutoMutableOrSavedStateDependency;
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync // public initializer/uninitializer for internal purposes only
STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
#if defined(RT_OS_WINDOWS)
bool aAllowClosing = false);
bool isSessionSpawning();
bool checkForSpawnFailure();
bool aSetError = false)
void releaseStateDependency();
void ensureNoStateDependencies();
bool aSetError = false);
bool aRegistered,
bool aRegistered,
bool aSetError = false);
bool aSetError = false);
bool aSetError = false);
bool aOnline);
bool isModified();
void commit();
#ifdef VBOX_WITH_RESOURCE_USAGE_API
void FinalRelease();
// public initializer/uninitializer for internal purposes only
bool checkForDeath();
struct SnapshotData
struct Uninit
struct Task;
struct DeleteSnapshotTask;
struct RestoreSnapshotTask;
void unlockMedia();
#if defined(RT_OS_WINDOWS)
int mIPCSem;
# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
void FinalRelease();
// public initializer/uninitializer for internal purposes only
void uninit();
return mPeer;
return this;