VirtualBox

source: vbox/trunk/src/VBox/Main/include/MachineImpl.h@ 32837

Last change on this file since 32837 was 32398, checked in by vboxsync, 14 years ago

Main: Save guest dimension in save state; add method for queering this info to IMachine.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.8 KB
Line 
1/* $Id: MachineImpl.h 32398 2010-09-10 12:46:23Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "VRDPServerImpl.h"
24#include "MediumAttachmentImpl.h"
25#include "MediumLock.h"
26#include "NetworkAdapterImpl.h"
27#include "AudioAdapterImpl.h"
28#include "SerialPortImpl.h"
29#include "ParallelPortImpl.h"
30#include "BIOSSettingsImpl.h"
31#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
32#include "VBox/settings.h"
33#ifdef VBOX_WITH_RESOURCE_USAGE_API
34#include "Performance.h"
35#include "PerformanceImpl.h"
36#endif /* VBOX_WITH_RESOURCE_USAGE_API */
37
38// generated header
39#include "SchemaDefs.h"
40
41#include "VBox/com/ErrorInfo.h"
42
43#include <iprt/file.h>
44#include <iprt/thread.h>
45#include <iprt/time.h>
46
47#include <list>
48
49// defines
50////////////////////////////////////////////////////////////////////////////////
51
52// helper declarations
53////////////////////////////////////////////////////////////////////////////////
54
55class Progress;
56class ProgressProxy;
57class Keyboard;
58class Mouse;
59class Display;
60class MachineDebugger;
61class USBController;
62class Snapshot;
63class SharedFolder;
64class HostUSBDevice;
65class StorageController;
66
67class SessionMachine;
68
69namespace settings
70{
71 class MachineConfigFile;
72 struct Snapshot;
73 struct Hardware;
74 struct Storage;
75 struct StorageController;
76 struct MachineRegistryEntry;
77}
78
79// Machine class
80////////////////////////////////////////////////////////////////////////////////
81
82class ATL_NO_VTABLE Machine :
83 public VirtualBoxBaseWithChildrenNEXT,
84 VBOX_SCRIPTABLE_IMPL(IMachine)
85{
86 Q_OBJECT
87
88public:
89
90 enum StateDependency
91 {
92 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
93 };
94
95 /**
96 * Internal machine data.
97 *
98 * Only one instance of this data exists per every machine -- it is shared
99 * by the Machine, SessionMachine and all SnapshotMachine instances
100 * associated with the given machine using the util::Shareable template
101 * through the mData variable.
102 *
103 * @note |const| members are persistent during lifetime so can be
104 * accessed without locking.
105 *
106 * @note There is no need to lock anything inside init() or uninit()
107 * methods, because they are always serialized (see AutoCaller).
108 */
109 struct Data
110 {
111 /**
112 * Data structure to hold information about sessions opened for the
113 * given machine.
114 */
115 struct Session
116 {
117 /** Control of the direct session opened by lockMachine() */
118 ComPtr<IInternalSessionControl> mDirectControl;
119
120 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
121
122 /** list of controls of all opened remote sessions */
123 RemoteControlList mRemoteControls;
124
125 /** openRemoteSession() and OnSessionEnd() progress indicator */
126 ComObjPtr<ProgressProxy> mProgress;
127
128 /**
129 * PID of the session object that must be passed to openSession() to
130 * finalize the openRemoteSession() request (i.e., PID of the
131 * process created by openRemoteSession())
132 */
133 RTPROCESS mPid;
134
135 /** Current session state */
136 SessionState_T mState;
137
138 /** Session type string (for indirect sessions) */
139 Bstr mType;
140
141 /** Session machine object */
142 ComObjPtr<SessionMachine> mMachine;
143
144 /** Medium object lock collection. */
145 MediumLockListMap mLockedMedia;
146 };
147
148 Data();
149 ~Data();
150
151 const Guid mUuid;
152 BOOL mRegistered;
153
154 /** Flag indicating that the config file is read-only. */
155 Utf8Str m_strConfigFile;
156 Utf8Str m_strConfigFileFull;
157
158 // machine settings XML file
159 settings::MachineConfigFile *pMachineConfigFile;
160 uint32_t flModifications;
161
162 BOOL mAccessible;
163 com::ErrorInfo mAccessError;
164
165 MachineState_T mMachineState;
166 RTTIMESPEC mLastStateChange;
167
168 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
169 uint32_t mMachineStateDeps;
170 RTSEMEVENTMULTI mMachineStateDepsSem;
171 uint32_t mMachineStateChangePending;
172
173 BOOL mCurrentStateModified;
174 /** Guest properties have been modified and need saving since the
175 * machine was started, or there are transient properties which need
176 * deleting and the machine is being shut down. */
177 BOOL mGuestPropertiesModified;
178
179 Session mSession;
180
181 ComObjPtr<Snapshot> mFirstSnapshot;
182 ComObjPtr<Snapshot> mCurrentSnapshot;
183
184 // list of files to delete in Delete(); this list is filled by Unregister()
185 std::list<Utf8Str> llFilesToDelete;
186 };
187
188 /**
189 * Saved state data.
190 *
191 * It's actually only the state file path string, but it needs to be
192 * separate from Data, because Machine and SessionMachine instances
193 * share it, while SnapshotMachine does not.
194 *
195 * The data variable is |mSSData|.
196 */
197 struct SSData
198 {
199 Utf8Str mStateFilePath;
200 };
201
202 /**
203 * User changeable machine data.
204 *
205 * This data is common for all machine snapshots, i.e. it is shared
206 * by all SnapshotMachine instances associated with the given machine
207 * using the util::Backupable template through the |mUserData| variable.
208 *
209 * SessionMachine instances can alter this data and discard changes.
210 *
211 * @note There is no need to lock anything inside init() or uninit()
212 * methods, because they are always serialized (see AutoCaller).
213 */
214 struct UserData
215 {
216 settings::MachineUserData s;
217 Utf8Str m_strSnapshotFolderFull;
218 };
219
220 /**
221 * Hardware data.
222 *
223 * This data is unique for a machine and for every machine snapshot.
224 * Stored using the util::Backupable template in the |mHWData| variable.
225 *
226 * SessionMachine instances can alter this data and discard changes.
227 */
228 struct HWData
229 {
230 /**
231 * Data structure to hold information about a guest property.
232 */
233 struct GuestProperty {
234 /** Property name */
235 Utf8Str strName;
236 /** Property value */
237 Utf8Str strValue;
238 /** Property timestamp */
239 LONG64 mTimestamp;
240 /** Property flags */
241 ULONG mFlags;
242 };
243
244 HWData();
245 ~HWData();
246
247 Bstr mHWVersion;
248 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
249 ULONG mMemorySize;
250 ULONG mMemoryBalloonSize;
251 BOOL mPageFusionEnabled;
252 ULONG mVRAMSize;
253 ULONG mMonitorCount;
254 BOOL mHWVirtExEnabled;
255 BOOL mHWVirtExExclusive;
256 BOOL mHWVirtExNestedPagingEnabled;
257 BOOL mHWVirtExLargePagesEnabled;
258 BOOL mHWVirtExVPIDEnabled;
259 BOOL mHWVirtExForceEnabled;
260 BOOL mAccelerate2DVideoEnabled;
261 BOOL mPAEEnabled;
262 BOOL mSyntheticCpu;
263 ULONG mCPUCount;
264 BOOL mCPUHotPlugEnabled;
265 ULONG mCpuPriority;
266 BOOL mAccelerate3DEnabled;
267 BOOL mHpetEnabled;
268
269 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
270
271 settings::CpuIdLeaf mCpuIdStdLeafs[10];
272 settings::CpuIdLeaf mCpuIdExtLeafs[10];
273
274 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
275
276 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
277 SharedFolderList mSharedFolders;
278
279 ClipboardMode_T mClipboardMode;
280
281 typedef std::list<GuestProperty> GuestPropertyList;
282 GuestPropertyList mGuestProperties;
283 Utf8Str mGuestPropertyNotificationPatterns;
284
285 FirmwareType_T mFirmwareType;
286 KeyboardHidType_T mKeyboardHidType;
287 PointingHidType_T mPointingHidType;
288 ChipsetType_T mChipsetType;
289
290 BOOL mIoCacheEnabled;
291 ULONG mIoCacheSize;
292 };
293
294 /**
295 * Hard disk and other media data.
296 *
297 * The usage policy is the same as for HWData, but a separate structure
298 * is necessary because hard disk data requires different procedures when
299 * taking or deleting snapshots, etc.
300 *
301 * The data variable is |mMediaData|.
302 */
303 struct MediaData
304 {
305 MediaData();
306 ~MediaData();
307
308 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
309 AttachmentList mAttachments;
310 };
311
312 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
313
314 DECLARE_NOT_AGGREGATABLE(Machine)
315
316 DECLARE_PROTECT_FINAL_CONSTRUCT()
317
318 BEGIN_COM_MAP(Machine)
319 COM_INTERFACE_ENTRY(ISupportErrorInfo)
320 COM_INTERFACE_ENTRY(IMachine)
321 COM_INTERFACE_ENTRY(IDispatch)
322 END_COM_MAP()
323
324 DECLARE_EMPTY_CTOR_DTOR(Machine)
325
326 HRESULT FinalConstruct();
327 void FinalRelease();
328
329 // public initializer/uninitializer for internal purposes only:
330
331 // initializer for creating a new, empty machine
332 HRESULT init(VirtualBox *aParent,
333 const Utf8Str &strConfigFile,
334 const Utf8Str &strName,
335 const Guid &aId,
336 GuestOSType *aOsType = NULL,
337 BOOL aOverride = FALSE,
338 BOOL aNameSync = TRUE);
339
340 // initializer for loading existing machine XML (either registered or not)
341 HRESULT init(VirtualBox *aParent,
342 const Utf8Str &strConfigFile,
343 const Guid *aId);
344
345 // initializer for machine config in memory (OVF import)
346 HRESULT init(VirtualBox *aParent,
347 const Utf8Str &strName,
348 const settings::MachineConfigFile &config);
349
350 void uninit();
351
352#ifdef VBOX_WITH_RESOURCE_USAGE_API
353 // Needed from VirtualBox, for the delayed metrics cleanup.
354 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
355#endif /* VBOX_WITH_RESOURCE_USAGE_API */
356
357protected:
358 HRESULT initImpl(VirtualBox *aParent,
359 const Utf8Str &strConfigFile);
360 HRESULT initDataAndChildObjects();
361 HRESULT registeredInit();
362 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
363 void uninitDataAndChildObjects();
364
365public:
366 // IMachine properties
367 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
368 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
369 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
370 STDMETHOD(COMGETTER(Name))(BSTR *aName);
371 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
372 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
373 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
374 STDMETHOD(COMGETTER(Id))(BSTR *aId);
375 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
376 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
377 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
378 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
379 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
380 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
381 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
382 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
383 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
384 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
385 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
386 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
387 STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
388 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
389 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
390 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
391 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
392 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
393 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
394 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
395 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
396 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
397 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
398 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
399 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
402 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
403 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
404 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
405 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
406 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
407 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
408 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
409 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
410 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
411 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
412 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
413 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
414 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
415 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
416 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
417 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
418 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
419 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
420 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
421 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
422 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
423 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
424 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
425 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
426 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
427 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
428 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
429 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
430 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
431 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
432 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
433 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
434 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
435 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
436 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
437 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
438 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
439 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
440 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
441 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
442 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
443 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
444 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
445 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
446 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
447 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
448 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
449 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
450 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
451 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
452 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
453 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
454 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
455 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
456 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
457 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
458 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
459 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
460
461 // IMachine methods
462 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
463 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
464
465 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
466 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
467 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
468 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
469 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
470 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
471 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
472 LONG aDevice, IN_BSTR aId, BOOL aForce);
473 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
474 IMedium **aMedium);
475 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
476 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
477 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
478 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
479 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
480 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
481 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
482 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
483 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
484 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
485 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
486 STDMETHOD(RemoveAllCPUIDLeaves)();
487 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
488 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
489 STDMETHOD(SaveSettings)();
490 STDMETHOD(DiscardSettings)();
491 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
492 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
493 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
494 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
495 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
496 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
497 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
498 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
499 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
500 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
501 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
502 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
503 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
504 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
505 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
506 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
507 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
508 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
509 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
510 STDMETHOD(RemoveStorageController(IN_BSTR aName));
511 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
512 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
513 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
514 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
515 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
516 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
517 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
518 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
519 STDMETHOD(HotPlugCPU(ULONG aCpu));
520 STDMETHOD(HotUnplugCPU(ULONG aCpu));
521 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
522 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
523 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
524
525 // public methods only for internal purposes
526
527 virtual bool isSnapshotMachine() const
528 {
529 return false;
530 }
531
532 virtual bool isSessionMachine() const
533 {
534 return false;
535 }
536
537 /**
538 * Override of the default locking class to be used for validating lock
539 * order with the standard member lock handle.
540 */
541 virtual VBoxLockingClass getLockingClass() const
542 {
543 return LOCKCLASS_MACHINEOBJECT;
544 }
545
546 /// @todo (dmik) add lock and make non-inlined after revising classes
547 // that use it. Note: they should enter Machine lock to keep the returned
548 // information valid!
549 bool isRegistered() { return !!mData->mRegistered; }
550
551 // unsafe inline public methods for internal purposes only (ensure there is
552 // a caller and a read lock before calling them!)
553
554 /**
555 * Returns the VirtualBox object this machine belongs to.
556 *
557 * @note This method doesn't check this object's readiness. Intended to be
558 * used by ready Machine children (whose readiness is bound to the parent's
559 * one) or after doing addCaller() manually.
560 */
561 VirtualBox* getVirtualBox() const { return mParent; }
562
563 /**
564 * Returns this machine ID.
565 *
566 * @note This method doesn't check this object's readiness. Intended to be
567 * used by ready Machine children (whose readiness is bound to the parent's
568 * one) or after adding a caller manually.
569 */
570 const Guid& getId() const { return mData->mUuid; }
571
572 /**
573 * Returns the snapshot ID this machine represents or an empty UUID if this
574 * instance is not SnapshotMachine.
575 *
576 * @note This method doesn't check this object's readiness. Intended to be
577 * used by ready Machine children (whose readiness is bound to the parent's
578 * one) or after adding a caller manually.
579 */
580 inline const Guid& getSnapshotId() const;
581
582 /**
583 * Returns this machine's full settings file path.
584 *
585 * @note This method doesn't lock this object or check its readiness.
586 * Intended to be used only after doing addCaller() manually and locking it
587 * for reading.
588 */
589 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
590
591 /**
592 * Returns this machine name.
593 *
594 * @note This method doesn't lock this object or check its readiness.
595 * Intended to be used only after doing addCaller() manually and locking it
596 * for reading.
597 */
598 const Utf8Str& getName() const { return mUserData->s.strName; }
599
600 enum
601 {
602 IsModified_MachineData = 0x0001,
603 IsModified_Storage = 0x0002,
604 IsModified_NetworkAdapters = 0x0008,
605 IsModified_SerialPorts = 0x0010,
606 IsModified_ParallelPorts = 0x0020,
607 IsModified_VRDPServer = 0x0040,
608 IsModified_AudioAdapter = 0x0080,
609 IsModified_USB = 0x0100,
610 IsModified_BIOS = 0x0200,
611 IsModified_SharedFolders = 0x0400,
612 IsModified_Snapshots = 0x0800
613 };
614
615 void setModified(uint32_t fl);
616
617 // callback handlers
618 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
619 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
620 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
621 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
622 virtual HRESULT onUSBControllerChange() { return S_OK; }
623 virtual HRESULT onStorageControllerChange() { return S_OK; }
624 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
625 virtual HRESULT onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
626 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
627 virtual HRESULT onSharedFolderChange() { return S_OK; }
628
629 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
630
631 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
632 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
633
634 void getLogFolder(Utf8Str &aLogFolder);
635 Utf8Str queryLogFilename(ULONG idx);
636
637 HRESULT openRemoteSession(IInternalSessionControl *aControl,
638 IN_BSTR aType, IN_BSTR aEnvironment,
639 ProgressProxy *aProgress);
640
641 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
642 {
643 HRESULT rc;
644 *directControl = mData->mSession.mDirectControl;
645
646 if (!*directControl)
647 rc = E_ACCESSDENIED;
648 else
649 rc = S_OK;
650
651 return rc;
652 }
653
654#if defined(RT_OS_WINDOWS)
655
656 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
657 ComPtr<IInternalSessionControl> *aControl = NULL,
658 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
659 bool isSessionSpawning(RTPROCESS *aPID = NULL);
660
661 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
662 ComPtr<IInternalSessionControl> *aControl = NULL,
663 HANDLE *aIPCSem = NULL)
664 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
665
666#elif defined(RT_OS_OS2)
667
668 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
669 ComPtr<IInternalSessionControl> *aControl = NULL,
670 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
671
672 bool isSessionSpawning(RTPROCESS *aPID = NULL);
673
674 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
675 ComPtr<IInternalSessionControl> *aControl = NULL,
676 HMTX *aIPCSem = NULL)
677 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
678
679#else
680
681 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
682 ComPtr<IInternalSessionControl> *aControl = NULL,
683 bool aAllowClosing = false);
684 bool isSessionSpawning();
685
686 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
687 ComPtr<IInternalSessionControl> *aControl = NULL)
688 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
689
690#endif
691
692 bool checkForSpawnFailure();
693
694 HRESULT prepareRegister();
695
696 HRESULT getSharedFolder(CBSTR aName,
697 ComObjPtr<SharedFolder> &aSharedFolder,
698 bool aSetError = false)
699 {
700 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
701 return findSharedFolder(aName, aSharedFolder, aSetError);
702 }
703
704 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
705 MachineState_T *aState = NULL,
706 BOOL *aRegistered = NULL);
707 void releaseStateDependency();
708
709protected:
710
711 HRESULT checkStateDependency(StateDependency aDepType);
712
713 Machine *getMachine();
714
715 void ensureNoStateDependencies();
716
717 virtual HRESULT setMachineState(MachineState_T aMachineState);
718
719 HRESULT findSharedFolder(CBSTR aName,
720 ComObjPtr<SharedFolder> &aSharedFolder,
721 bool aSetError = false);
722
723 HRESULT loadSettings(bool aRegistered);
724 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
725 HRESULT loadSnapshot(const settings::Snapshot &data,
726 const Guid &aCurSnapshotId,
727 Snapshot *aParentSnapshot);
728 HRESULT loadHardware(const settings::Hardware &data);
729 HRESULT loadStorageControllers(const settings::Storage &data,
730 const Guid *aSnapshotId = NULL);
731 HRESULT loadStorageDevices(StorageController *aStorageController,
732 const settings::StorageController &data,
733 const Guid *aSnapshotId = NULL);
734
735 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
736 bool aSetError = false);
737 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
738 bool aSetError = false);
739
740 HRESULT getStorageControllerByName(const Utf8Str &aName,
741 ComObjPtr<StorageController> &aStorageController,
742 bool aSetError = false);
743
744 HRESULT getMediumAttachmentsOfController(CBSTR aName,
745 MediaData::AttachmentList &aAttachments);
746
747 enum
748 {
749 /* flags for #saveSettings() */
750 SaveS_ResetCurStateModified = 0x01,
751 SaveS_InformCallbacksAnyway = 0x02,
752 SaveS_Force = 0x04,
753 /* flags for #saveStateSettings() */
754 SaveSTS_CurStateModified = 0x20,
755 SaveSTS_StateFilePath = 0x40,
756 SaveSTS_StateTimeStamp = 0x80
757 };
758
759 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
760 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
761
762 void copyMachineDataToSettings(settings::MachineConfigFile &config);
763 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
764 HRESULT saveHardware(settings::Hardware &data);
765 HRESULT saveStorageControllers(settings::Storage &data);
766 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
767 settings::StorageController &data);
768 HRESULT saveStateSettings(int aFlags);
769
770 HRESULT createImplicitDiffs(IProgress *aProgress,
771 ULONG aWeight,
772 bool aOnline,
773 bool *pfNeedsSaveSettings);
774 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
775
776 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
777 IN_BSTR aControllerName,
778 LONG aControllerPort,
779 LONG aDevice);
780 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
781 ComObjPtr<Medium> pMedium);
782 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
783 Guid &id);
784
785 HRESULT detachDevice(MediumAttachment *pAttach,
786 AutoWriteLock &writeLock,
787 Snapshot *pSnapshot,
788 bool *pfNeedsSaveSettings);
789 HRESULT detachAllMedia(AutoWriteLock &writeLock,
790 Snapshot *pSnapshot,
791 CleanupMode_T cleanupMode,
792 MediaList &llMedia);
793
794 void commitMedia(bool aOnline = false);
795 void rollbackMedia();
796
797 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
798
799 void rollback(bool aNotify);
800 void commit();
801 void copyFrom(Machine *aThat);
802
803 struct DeleteTask;
804 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
805 HRESULT deleteTaskWorker(DeleteTask &task);
806
807#ifdef VBOX_WITH_GUEST_PROPS
808 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
809 LONG64 *aTimestamp, BSTR *aFlags) const;
810 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
811 LONG64 *aTimestamp, BSTR *aFlags) const;
812 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
813 IN_BSTR aFlags);
814 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
815 IN_BSTR aFlags);
816 HRESULT enumerateGuestPropertiesInService
817 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
818 ComSafeArrayOut(BSTR, aValues),
819 ComSafeArrayOut(LONG64, aTimestamps),
820 ComSafeArrayOut(BSTR, aFlags));
821 HRESULT enumerateGuestPropertiesOnVM
822 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
823 ComSafeArrayOut(BSTR, aValues),
824 ComSafeArrayOut(LONG64, aTimestamps),
825 ComSafeArrayOut(BSTR, aFlags));
826#endif /* VBOX_WITH_GUEST_PROPS */
827
828#ifdef VBOX_WITH_RESOURCE_USAGE_API
829 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
830
831 pm::CollectorGuestHAL *mGuestHAL;
832#endif /* VBOX_WITH_RESOURCE_USAGE_API */
833
834 Machine* const mPeer;
835
836 VirtualBox * const mParent;
837
838 Shareable<Data> mData;
839 Shareable<SSData> mSSData;
840
841 Backupable<UserData> mUserData;
842 Backupable<HWData> mHWData;
843 Backupable<MediaData> mMediaData;
844
845 // the following fields need special backup/rollback/commit handling,
846 // so they cannot be a part of HWData
847
848 const ComObjPtr<VRDPServer> mVRDPServer;
849 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
850 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
851 const ComObjPtr<AudioAdapter> mAudioAdapter;
852 const ComObjPtr<USBController> mUSBController;
853 const ComObjPtr<BIOSSettings> mBIOSSettings;
854 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
855
856 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
857 Backupable<StorageControllerList> mStorageControllers;
858
859 friend class SessionMachine;
860 friend class SnapshotMachine;
861 friend class Appliance;
862};
863
864// SessionMachine class
865////////////////////////////////////////////////////////////////////////////////
866
867/**
868 * @note Notes on locking objects of this class:
869 * SessionMachine shares some data with the primary Machine instance (pointed
870 * to by the |mPeer| member). In order to provide data consistency it also
871 * shares its lock handle. This means that whenever you lock a SessionMachine
872 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
873 * instance is also locked in the same lock mode. Keep it in mind.
874 */
875class ATL_NO_VTABLE SessionMachine :
876 public Machine,
877 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
878{
879public:
880 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
881
882 DECLARE_NOT_AGGREGATABLE(SessionMachine)
883
884 DECLARE_PROTECT_FINAL_CONSTRUCT()
885
886 BEGIN_COM_MAP(SessionMachine)
887 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
888 COM_INTERFACE_ENTRY(ISupportErrorInfo)
889 COM_INTERFACE_ENTRY(IMachine)
890 COM_INTERFACE_ENTRY(IInternalMachineControl)
891 END_COM_MAP()
892
893 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
894
895 HRESULT FinalConstruct();
896 void FinalRelease();
897
898 // public initializer/uninitializer for internal purposes only
899 HRESULT init(Machine *aMachine);
900 void uninit() { uninit(Uninit::Unexpected); }
901
902 // util::Lockable interface
903 RWLockHandle *lockHandle() const;
904
905 // IInternalMachineControl methods
906 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
907 STDMETHOD(UpdateState)(MachineState_T machineState);
908 STDMETHOD(GetIPCId)(BSTR *id);
909 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
910 STDMETHOD(EndPowerUp)(LONG iResult);
911 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
912 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
913 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
914 STDMETHOD(AutoCaptureUSBDevices)();
915 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
916 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
917 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
918 STDMETHOD(EndSavingState)(BOOL aSuccess);
919 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
920 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
921 IN_BSTR aName,
922 IN_BSTR aDescription,
923 IProgress *aConsoleProgress,
924 BOOL fTakingSnapshotOnline,
925 BSTR *aStateFilePath);
926 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
927 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
928 MachineState_T *aMachineState, IProgress **aProgress);
929 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
930 IMedium *aSource, IMedium *aTarget,
931 BOOL fMergeForward,
932 IMedium *pParentForTarget,
933 ComSafeArrayIn(IMedium *, aChildrenToReparent));
934 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
935 ISnapshot *aSnapshot,
936 MachineState_T *aMachineState,
937 IProgress **aProgress);
938 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
939 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
940 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
941 LONG64 aTimestamp, IN_BSTR aFlags);
942 STDMETHOD(LockMedia)() { return lockMedia(); }
943 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
944
945 // public methods only for internal purposes
946
947 virtual bool isSessionMachine() const
948 {
949 return true;
950 }
951
952 bool checkForDeath();
953
954 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
955 HRESULT onStorageControllerChange();
956 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
957 HRESULT onSerialPortChange(ISerialPort *serialPort);
958 HRESULT onParallelPortChange(IParallelPort *parallelPort);
959 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
960 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
961 HRESULT onVRDPServerChange(BOOL aRestart);
962 HRESULT onUSBControllerChange();
963 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
964 IVirtualBoxErrorInfo *aError,
965 ULONG aMaskedIfs);
966 HRESULT onUSBDeviceDetach(IN_BSTR aId,
967 IVirtualBoxErrorInfo *aError);
968 HRESULT onSharedFolderChange();
969
970 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
971
972private:
973
974 struct SnapshotData
975 {
976 SnapshotData() : mLastState(MachineState_Null) {}
977
978 MachineState_T mLastState;
979
980 // used when taking snapshot
981 ComObjPtr<Snapshot> mSnapshot;
982
983 // used when saving state
984 Guid mProgressId;
985 Utf8Str mStateFilePath;
986 };
987
988 struct Uninit
989 {
990 enum Reason { Unexpected, Abnormal, Normal };
991 };
992
993 struct SnapshotTask;
994 struct DeleteSnapshotTask;
995 struct RestoreSnapshotTask;
996
997 friend struct DeleteSnapshotTask;
998 friend struct RestoreSnapshotTask;
999
1000 void uninit(Uninit::Reason aReason);
1001
1002 HRESULT endSavingState(BOOL aSuccess);
1003
1004 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
1005
1006 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1007 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1008
1009 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1010 const Guid &machineId,
1011 const Guid &snapshotId,
1012 bool fOnlineMergePossible,
1013 MediumLockList *aVMMALockList,
1014 ComObjPtr<Medium> &aSource,
1015 ComObjPtr<Medium> &aTarget,
1016 bool &fMergeForward,
1017 ComObjPtr<Medium> &pParentForTarget,
1018 MediaList &aChildrenToReparent,
1019 bool &fNeedOnlineMerge,
1020 MediumLockList * &aMediumLockList);
1021 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1022 const ComObjPtr<Medium> &aSource,
1023 const MediaList &aChildrenToReparent,
1024 bool fNeedsOnlineMerge,
1025 MediumLockList *aMediumLockList,
1026 const Guid &aMediumId,
1027 const Guid &aSnapshotId);
1028 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1029 const ComObjPtr<Medium> &aSource,
1030 const ComObjPtr<Medium> &aTarget,
1031 bool fMergeForward,
1032 const ComObjPtr<Medium> &pParentForTarget,
1033 const MediaList &aChildrenToReparent,
1034 MediumLockList *aMediumLockList,
1035 ComObjPtr<Progress> &aProgress,
1036 bool *pfNeedsMachineSaveSettings);
1037
1038 HRESULT lockMedia();
1039 void unlockMedia();
1040
1041 HRESULT setMachineState(MachineState_T aMachineState);
1042 HRESULT updateMachineStateOnClient();
1043
1044 HRESULT mRemoveSavedState;
1045
1046 SnapshotData mSnapshotData;
1047
1048 /** interprocess semaphore handle for this machine */
1049#if defined(RT_OS_WINDOWS)
1050 HANDLE mIPCSem;
1051 Bstr mIPCSemName;
1052 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1053 ComPtr<IInternalSessionControl> *aControl,
1054 HANDLE *aIPCSem, bool aAllowClosing);
1055#elif defined(RT_OS_OS2)
1056 HMTX mIPCSem;
1057 Bstr mIPCSemName;
1058 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1059 ComPtr<IInternalSessionControl> *aControl,
1060 HMTX *aIPCSem, bool aAllowClosing);
1061#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1062 int mIPCSem;
1063# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1064 Bstr mIPCKey;
1065# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1066#else
1067# error "Port me!"
1068#endif
1069
1070 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1071};
1072
1073// SnapshotMachine class
1074////////////////////////////////////////////////////////////////////////////////
1075
1076/**
1077 * @note Notes on locking objects of this class:
1078 * SnapshotMachine shares some data with the primary Machine instance (pointed
1079 * to by the |mPeer| member). In order to provide data consistency it also
1080 * shares its lock handle. This means that whenever you lock a SessionMachine
1081 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1082 * instance is also locked in the same lock mode. Keep it in mind.
1083 */
1084class ATL_NO_VTABLE SnapshotMachine :
1085 public Machine
1086{
1087public:
1088 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1089
1090 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1091
1092 DECLARE_PROTECT_FINAL_CONSTRUCT()
1093
1094 BEGIN_COM_MAP(SnapshotMachine)
1095 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1096 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1097 COM_INTERFACE_ENTRY(IMachine)
1098 END_COM_MAP()
1099
1100 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1101
1102 HRESULT FinalConstruct();
1103 void FinalRelease();
1104
1105 // public initializer/uninitializer for internal purposes only
1106 HRESULT init(SessionMachine *aSessionMachine,
1107 IN_GUID aSnapshotId,
1108 const Utf8Str &aStateFilePath);
1109 HRESULT init(Machine *aMachine,
1110 const settings::Hardware &hardware,
1111 const settings::Storage &storage,
1112 IN_GUID aSnapshotId,
1113 const Utf8Str &aStateFilePath);
1114 void uninit();
1115
1116 // util::Lockable interface
1117 RWLockHandle *lockHandle() const;
1118
1119 // public methods only for internal purposes
1120
1121 virtual bool isSnapshotMachine() const
1122 {
1123 return true;
1124 }
1125
1126 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1127
1128 // unsafe inline public methods for internal purposes only (ensure there is
1129 // a caller and a read lock before calling them!)
1130
1131 const Guid& getSnapshotId() const { return mSnapshotId; }
1132
1133private:
1134
1135 Guid mSnapshotId;
1136
1137 friend class Snapshot;
1138};
1139
1140// third party methods that depend on SnapshotMachine definiton
1141
1142inline const Guid &Machine::getSnapshotId() const
1143{
1144 return (isSnapshotMachine())
1145 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1146 : Guid::Empty;
1147}
1148
1149
1150#endif // ____H_MACHINEIMPL
1151/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette