VirtualBox

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

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

Main: API change, merge IMachine::getSnapshot() with findSnapshot()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.9 KB
Line 
1/* $Id: MachineImpl.h 33300 2010-10-21 11:28:06Z 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 Utf8Str m_strConfigFile;
155 Utf8Str m_strConfigFileFull;
156
157 // machine settings XML file
158 settings::MachineConfigFile *pMachineConfigFile;
159 uint32_t flModifications;
160
161 BOOL mAccessible;
162 com::ErrorInfo mAccessError;
163
164 MachineState_T mMachineState;
165 RTTIMESPEC mLastStateChange;
166
167 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
168 uint32_t mMachineStateDeps;
169 RTSEMEVENTMULTI mMachineStateDepsSem;
170 uint32_t mMachineStateChangePending;
171
172 BOOL mCurrentStateModified;
173 /** Guest properties have been modified and need saving since the
174 * machine was started, or there are transient properties which need
175 * deleting and the machine is being shut down. */
176 BOOL mGuestPropertiesModified;
177
178 Session mSession;
179
180 ComObjPtr<Snapshot> mFirstSnapshot;
181 ComObjPtr<Snapshot> mCurrentSnapshot;
182
183 // list of files to delete in Delete(); this list is filled by Unregister()
184 std::list<Utf8Str> llFilesToDelete;
185 };
186
187 /**
188 * Saved state data.
189 *
190 * It's actually only the state file path string, but it needs to be
191 * separate from Data, because Machine and SessionMachine instances
192 * share it, while SnapshotMachine does not.
193 *
194 * The data variable is |mSSData|.
195 */
196 struct SSData
197 {
198 Utf8Str mStateFilePath;
199 };
200
201 /**
202 * User changeable machine data.
203 *
204 * This data is common for all machine snapshots, i.e. it is shared
205 * by all SnapshotMachine instances associated with the given machine
206 * using the util::Backupable template through the |mUserData| variable.
207 *
208 * SessionMachine instances can alter this data and discard changes.
209 *
210 * @note There is no need to lock anything inside init() or uninit()
211 * methods, because they are always serialized (see AutoCaller).
212 */
213 struct UserData
214 {
215 settings::MachineUserData s;
216 Utf8Str m_strSnapshotFolderFull;
217 };
218
219 /**
220 * Hardware data.
221 *
222 * This data is unique for a machine and for every machine snapshot.
223 * Stored using the util::Backupable template in the |mHWData| variable.
224 *
225 * SessionMachine instances can alter this data and discard changes.
226 */
227 struct HWData
228 {
229 /**
230 * Data structure to hold information about a guest property.
231 */
232 struct GuestProperty {
233 /** Property name */
234 Utf8Str strName;
235 /** Property value */
236 Utf8Str strValue;
237 /** Property timestamp */
238 LONG64 mTimestamp;
239 /** Property flags */
240 ULONG mFlags;
241 };
242
243 HWData();
244 ~HWData();
245
246 Bstr mHWVersion;
247 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
248 ULONG mMemorySize;
249 ULONG mMemoryBalloonSize;
250 BOOL mPageFusionEnabled;
251 ULONG mVRAMSize;
252 ULONG mMonitorCount;
253 BOOL mHWVirtExEnabled;
254 BOOL mHWVirtExExclusive;
255 BOOL mHWVirtExNestedPagingEnabled;
256 BOOL mHWVirtExLargePagesEnabled;
257 BOOL mHWVirtExVPIDEnabled;
258 BOOL mHWVirtExForceEnabled;
259 BOOL mAccelerate2DVideoEnabled;
260 BOOL mPAEEnabled;
261 BOOL mSyntheticCpu;
262 ULONG mCPUCount;
263 BOOL mCPUHotPlugEnabled;
264 ULONG mCpuExecutionCap;
265 BOOL mAccelerate3DEnabled;
266 BOOL mHpetEnabled;
267
268 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
269
270 settings::CpuIdLeaf mCpuIdStdLeafs[10];
271 settings::CpuIdLeaf mCpuIdExtLeafs[10];
272
273 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
274
275 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
276 SharedFolderList mSharedFolders;
277
278 ClipboardMode_T mClipboardMode;
279
280 typedef std::list<GuestProperty> GuestPropertyList;
281 GuestPropertyList mGuestProperties;
282 Utf8Str mGuestPropertyNotificationPatterns;
283
284 FirmwareType_T mFirmwareType;
285 KeyboardHidType_T mKeyboardHidType;
286 PointingHidType_T mPointingHidType;
287 ChipsetType_T mChipsetType;
288
289 BOOL mIoCacheEnabled;
290 ULONG mIoCacheSize;
291 };
292
293 /**
294 * Hard disk and other media data.
295 *
296 * The usage policy is the same as for HWData, but a separate structure
297 * is necessary because hard disk data requires different procedures when
298 * taking or deleting snapshots, etc.
299 *
300 * The data variable is |mMediaData|.
301 */
302 struct MediaData
303 {
304 MediaData();
305 ~MediaData();
306
307 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
308 AttachmentList mAttachments;
309 };
310
311 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
312
313 DECLARE_NOT_AGGREGATABLE(Machine)
314
315 DECLARE_PROTECT_FINAL_CONSTRUCT()
316
317 BEGIN_COM_MAP(Machine)
318 COM_INTERFACE_ENTRY(ISupportErrorInfo)
319 COM_INTERFACE_ENTRY(IMachine)
320 COM_INTERFACE_ENTRY(IDispatch)
321 END_COM_MAP()
322
323 DECLARE_EMPTY_CTOR_DTOR(Machine)
324
325 HRESULT FinalConstruct();
326 void FinalRelease();
327
328 // public initializer/uninitializer for internal purposes only:
329
330 // initializer for creating a new, empty machine
331 HRESULT init(VirtualBox *aParent,
332 const Utf8Str &strConfigFile,
333 const Utf8Str &strName,
334 const Guid &aId,
335 GuestOSType *aOsType = NULL,
336 BOOL aOverride = FALSE,
337 BOOL aNameSync = TRUE);
338
339 // initializer for loading existing machine XML (either registered or not)
340 HRESULT init(VirtualBox *aParent,
341 const Utf8Str &strConfigFile,
342 const Guid *aId);
343
344 // initializer for machine config in memory (OVF import)
345 HRESULT init(VirtualBox *aParent,
346 const Utf8Str &strName,
347 const settings::MachineConfigFile &config);
348
349 void uninit();
350
351#ifdef VBOX_WITH_RESOURCE_USAGE_API
352 // Needed from VirtualBox, for the delayed metrics cleanup.
353 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
354#endif /* VBOX_WITH_RESOURCE_USAGE_API */
355
356protected:
357 HRESULT initImpl(VirtualBox *aParent,
358 const Utf8Str &strConfigFile);
359 HRESULT initDataAndChildObjects();
360 HRESULT registeredInit();
361 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
362 void uninitDataAndChildObjects();
363
364public:
365 // IMachine properties
366 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
367 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
368 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
369 STDMETHOD(COMGETTER(Name))(BSTR *aName);
370 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
371 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
372 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
373 STDMETHOD(COMGETTER(Id))(BSTR *aId);
374 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
375 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
376 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
377 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
378 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
379 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
380 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
381 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
382 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
383 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
384 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
385 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
386 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
387 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
388 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
389 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
390 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
391 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
392 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
393 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
394 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
395 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
396 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
397 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
398 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
399 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
400 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
401 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
402 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
403 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
404 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
405 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
406 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
407 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
408 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
409 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
410 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
411 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
412 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
413 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
414 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
415 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
416 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
417 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
418 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
419 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
420 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
421 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
422 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
423 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
424 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
425 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
426 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
427 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
428 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
429 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
430 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
431 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
432 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
433 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
434 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
435 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
436 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
437 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
438 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
439 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
440 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
441 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
442 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
443 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
444 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
445 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
446 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
447 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
448 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
449 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
450 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
451 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
452 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
453 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
454 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
455 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
456 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
457 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
458 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
459
460 // IMachine methods
461 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
462 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
463
464 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
465 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
466 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
467 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
468 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
469 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
470 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
471 LONG aDevice, IMedium *aMedium, BOOL aForce);
472 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
473 IMedium **aMedium);
474 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
475 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
476 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
477 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
478 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
479 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
480 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
481 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
482 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
483 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
484 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
485 STDMETHOD(RemoveAllCPUIDLeaves)();
486 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
487 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
488 STDMETHOD(SaveSettings)();
489 STDMETHOD(DiscardSettings)();
490 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
491 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
492 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
493 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
494 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
495 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
496 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
497 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
498 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
499 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
500 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
501 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
502 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
503 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
504 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
505 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
506 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
507 STDMETHOD(RemoveStorageController(IN_BSTR aName));
508 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
509 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
510 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
511 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
512 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
513 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
514 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
515 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
516 STDMETHOD(HotPlugCPU(ULONG aCpu));
517 STDMETHOD(HotUnplugCPU(ULONG aCpu));
518 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
519 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
520 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
521
522 // public methods only for internal purposes
523
524 virtual bool isSnapshotMachine() const
525 {
526 return false;
527 }
528
529 virtual bool isSessionMachine() const
530 {
531 return false;
532 }
533
534 /**
535 * Override of the default locking class to be used for validating lock
536 * order with the standard member lock handle.
537 */
538 virtual VBoxLockingClass getLockingClass() const
539 {
540 return LOCKCLASS_MACHINEOBJECT;
541 }
542
543 /// @todo (dmik) add lock and make non-inlined after revising classes
544 // that use it. Note: they should enter Machine lock to keep the returned
545 // information valid!
546 bool isRegistered() { return !!mData->mRegistered; }
547
548 // unsafe inline public methods for internal purposes only (ensure there is
549 // a caller and a read lock before calling them!)
550
551 /**
552 * Returns the VirtualBox object this machine belongs to.
553 *
554 * @note This method doesn't check this object's readiness. Intended to be
555 * used by ready Machine children (whose readiness is bound to the parent's
556 * one) or after doing addCaller() manually.
557 */
558 VirtualBox* getVirtualBox() const { return mParent; }
559
560 /**
561 * Returns this machine ID.
562 *
563 * @note This method doesn't check this object's readiness. Intended to be
564 * used by ready Machine children (whose readiness is bound to the parent's
565 * one) or after adding a caller manually.
566 */
567 const Guid& getId() const { return mData->mUuid; }
568
569 /**
570 * Returns the snapshot ID this machine represents or an empty UUID if this
571 * instance is not SnapshotMachine.
572 *
573 * @note This method doesn't check this object's readiness. Intended to be
574 * used by ready Machine children (whose readiness is bound to the parent's
575 * one) or after adding a caller manually.
576 */
577 inline const Guid& getSnapshotId() const;
578
579 /**
580 * Returns this machine's full settings file path.
581 *
582 * @note This method doesn't lock this object or check its readiness.
583 * Intended to be used only after doing addCaller() manually and locking it
584 * for reading.
585 */
586 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
587
588 /**
589 * Returns this machine name.
590 *
591 * @note This method doesn't lock this object or check its readiness.
592 * Intended to be used only after doing addCaller() manually and locking it
593 * for reading.
594 */
595 const Utf8Str& getName() const { return mUserData->s.strName; }
596
597 enum
598 {
599 IsModified_MachineData = 0x0001,
600 IsModified_Storage = 0x0002,
601 IsModified_NetworkAdapters = 0x0008,
602 IsModified_SerialPorts = 0x0010,
603 IsModified_ParallelPorts = 0x0020,
604 IsModified_VRDPServer = 0x0040,
605 IsModified_AudioAdapter = 0x0080,
606 IsModified_USB = 0x0100,
607 IsModified_BIOS = 0x0200,
608 IsModified_SharedFolders = 0x0400,
609 IsModified_Snapshots = 0x0800
610 };
611
612 void setModified(uint32_t fl);
613
614 // callback handlers
615 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
616 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
617 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
618 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
619 virtual HRESULT onUSBControllerChange() { return S_OK; }
620 virtual HRESULT onStorageControllerChange() { return S_OK; }
621 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
622 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
623 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
624 virtual HRESULT onSharedFolderChange() { return S_OK; }
625
626 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
627
628 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
629 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
630
631 void getLogFolder(Utf8Str &aLogFolder);
632 Utf8Str queryLogFilename(ULONG idx);
633
634 HRESULT openRemoteSession(IInternalSessionControl *aControl,
635 IN_BSTR aType, IN_BSTR aEnvironment,
636 ProgressProxy *aProgress);
637
638 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
639 {
640 HRESULT rc;
641 *directControl = mData->mSession.mDirectControl;
642
643 if (!*directControl)
644 rc = E_ACCESSDENIED;
645 else
646 rc = S_OK;
647
648 return rc;
649 }
650
651#if defined(RT_OS_WINDOWS)
652
653 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
654 ComPtr<IInternalSessionControl> *aControl = NULL,
655 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
656 bool isSessionSpawning(RTPROCESS *aPID = NULL);
657
658 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
659 ComPtr<IInternalSessionControl> *aControl = NULL,
660 HANDLE *aIPCSem = NULL)
661 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
662
663#elif defined(RT_OS_OS2)
664
665 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
666 ComPtr<IInternalSessionControl> *aControl = NULL,
667 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
668
669 bool isSessionSpawning(RTPROCESS *aPID = NULL);
670
671 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
672 ComPtr<IInternalSessionControl> *aControl = NULL,
673 HMTX *aIPCSem = NULL)
674 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
675
676#else
677
678 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
679 ComPtr<IInternalSessionControl> *aControl = NULL,
680 bool aAllowClosing = false);
681 bool isSessionSpawning();
682
683 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
684 ComPtr<IInternalSessionControl> *aControl = NULL)
685 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
686
687#endif
688
689 bool checkForSpawnFailure();
690
691 HRESULT prepareRegister();
692
693 HRESULT getSharedFolder(CBSTR aName,
694 ComObjPtr<SharedFolder> &aSharedFolder,
695 bool aSetError = false)
696 {
697 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
698 return findSharedFolder(aName, aSharedFolder, aSetError);
699 }
700
701 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
702 MachineState_T *aState = NULL,
703 BOOL *aRegistered = NULL);
704 void releaseStateDependency();
705
706protected:
707
708 HRESULT checkStateDependency(StateDependency aDepType);
709
710 Machine *getMachine();
711
712 void ensureNoStateDependencies();
713
714 virtual HRESULT setMachineState(MachineState_T aMachineState);
715
716 HRESULT findSharedFolder(CBSTR aName,
717 ComObjPtr<SharedFolder> &aSharedFolder,
718 bool aSetError = false);
719
720 HRESULT loadSettings(bool aRegistered);
721 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
722 const Guid *puuidRegistry);
723 HRESULT loadSnapshot(const settings::Snapshot &data,
724 const Guid &aCurSnapshotId,
725 Snapshot *aParentSnapshot);
726 HRESULT loadHardware(const settings::Hardware &data);
727 HRESULT loadStorageControllers(const settings::Storage &data,
728 const Guid *puuidRegistry,
729 const Guid *puuidSnapshot);
730 HRESULT loadStorageDevices(StorageController *aStorageController,
731 const settings::StorageController &data,
732 const Guid *puuidRegistry,
733 const Guid *puuidSnapshot);
734
735 HRESULT findSnapshotById(const Guid &aId,
736 ComObjPtr<Snapshot> &aSnapshot,
737 bool aSetError = false);
738 HRESULT findSnapshotByName(const Utf8Str &strName,
739 ComObjPtr<Snapshot> &aSnapshot,
740 bool aSetError = false);
741
742 HRESULT getStorageControllerByName(const Utf8Str &aName,
743 ComObjPtr<StorageController> &aStorageController,
744 bool aSetError = false);
745
746 HRESULT getMediumAttachmentsOfController(CBSTR aName,
747 MediaData::AttachmentList &aAttachments);
748
749 enum
750 {
751 /* flags for #saveSettings() */
752 SaveS_ResetCurStateModified = 0x01,
753 SaveS_InformCallbacksAnyway = 0x02,
754 SaveS_Force = 0x04,
755 /* flags for #saveStateSettings() */
756 SaveSTS_CurStateModified = 0x20,
757 SaveSTS_StateFilePath = 0x40,
758 SaveSTS_StateTimeStamp = 0x80
759 };
760
761 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
762 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
763
764 void copyMachineDataToSettings(settings::MachineConfigFile &config);
765 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
766 HRESULT saveHardware(settings::Hardware &data);
767 HRESULT saveStorageControllers(settings::Storage &data);
768 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
769 settings::StorageController &data);
770 HRESULT saveStateSettings(int aFlags);
771
772 HRESULT createImplicitDiffs(IProgress *aProgress,
773 ULONG aWeight,
774 bool aOnline,
775 bool *pfNeedsSaveSettings);
776 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
777
778 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
779 IN_BSTR aControllerName,
780 LONG aControllerPort,
781 LONG aDevice);
782 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
783 ComObjPtr<Medium> pMedium);
784 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
785 Guid &id);
786
787 HRESULT detachDevice(MediumAttachment *pAttach,
788 AutoWriteLock &writeLock,
789 Snapshot *pSnapshot,
790 bool *pfNeedsSaveSettings);
791 HRESULT detachAllMedia(AutoWriteLock &writeLock,
792 Snapshot *pSnapshot,
793 CleanupMode_T cleanupMode,
794 MediaList &llMedia);
795
796 void commitMedia(bool aOnline = false);
797 void rollbackMedia();
798
799 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
800
801 void rollback(bool aNotify);
802 void commit();
803 void copyFrom(Machine *aThat);
804
805 struct DeleteTask;
806 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
807 HRESULT deleteTaskWorker(DeleteTask &task);
808
809#ifdef VBOX_WITH_GUEST_PROPS
810 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
811 LONG64 *aTimestamp, BSTR *aFlags) const;
812 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
813 LONG64 *aTimestamp, BSTR *aFlags) const;
814 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
815 IN_BSTR aFlags);
816 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
817 IN_BSTR aFlags);
818 HRESULT enumerateGuestPropertiesInService
819 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
820 ComSafeArrayOut(BSTR, aValues),
821 ComSafeArrayOut(LONG64, aTimestamps),
822 ComSafeArrayOut(BSTR, aFlags));
823 HRESULT enumerateGuestPropertiesOnVM
824 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
825 ComSafeArrayOut(BSTR, aValues),
826 ComSafeArrayOut(LONG64, aTimestamps),
827 ComSafeArrayOut(BSTR, aFlags));
828#endif /* VBOX_WITH_GUEST_PROPS */
829
830#ifdef VBOX_WITH_RESOURCE_USAGE_API
831 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
832
833 pm::CollectorGuestHAL *mGuestHAL;
834#endif /* VBOX_WITH_RESOURCE_USAGE_API */
835
836 Machine* const mPeer;
837
838 VirtualBox * const mParent;
839
840 Shareable<Data> mData;
841 Shareable<SSData> mSSData;
842
843 Backupable<UserData> mUserData;
844 Backupable<HWData> mHWData;
845 Backupable<MediaData> mMediaData;
846
847 // the following fields need special backup/rollback/commit handling,
848 // so they cannot be a part of HWData
849
850 const ComObjPtr<VRDPServer> mVRDPServer;
851 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
852 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
853 const ComObjPtr<AudioAdapter> mAudioAdapter;
854 const ComObjPtr<USBController> mUSBController;
855 const ComObjPtr<BIOSSettings> mBIOSSettings;
856 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
857
858 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
859 Backupable<StorageControllerList> mStorageControllers;
860
861 friend class SessionMachine;
862 friend class SnapshotMachine;
863 friend class Appliance;
864};
865
866// SessionMachine class
867////////////////////////////////////////////////////////////////////////////////
868
869/**
870 * @note Notes on locking objects of this class:
871 * SessionMachine shares some data with the primary Machine instance (pointed
872 * to by the |mPeer| member). In order to provide data consistency it also
873 * shares its lock handle. This means that whenever you lock a SessionMachine
874 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
875 * instance is also locked in the same lock mode. Keep it in mind.
876 */
877class ATL_NO_VTABLE SessionMachine :
878 public Machine,
879 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
880{
881public:
882 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
883
884 DECLARE_NOT_AGGREGATABLE(SessionMachine)
885
886 DECLARE_PROTECT_FINAL_CONSTRUCT()
887
888 BEGIN_COM_MAP(SessionMachine)
889 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
890 COM_INTERFACE_ENTRY(ISupportErrorInfo)
891 COM_INTERFACE_ENTRY(IMachine)
892 COM_INTERFACE_ENTRY(IInternalMachineControl)
893 END_COM_MAP()
894
895 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
896
897 HRESULT FinalConstruct();
898 void FinalRelease();
899
900 // public initializer/uninitializer for internal purposes only
901 HRESULT init(Machine *aMachine);
902 void uninit() { uninit(Uninit::Unexpected); }
903
904 // util::Lockable interface
905 RWLockHandle *lockHandle() const;
906
907 // IInternalMachineControl methods
908 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
909 STDMETHOD(UpdateState)(MachineState_T machineState);
910 STDMETHOD(GetIPCId)(BSTR *id);
911 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
912 STDMETHOD(EndPowerUp)(LONG iResult);
913 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
914 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
915 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
916 STDMETHOD(AutoCaptureUSBDevices)();
917 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
918 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
919 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
920 STDMETHOD(EndSavingState)(BOOL aSuccess);
921 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
922 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
923 IN_BSTR aName,
924 IN_BSTR aDescription,
925 IProgress *aConsoleProgress,
926 BOOL fTakingSnapshotOnline,
927 BSTR *aStateFilePath);
928 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
929 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
930 MachineState_T *aMachineState, IProgress **aProgress);
931 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
932 IMedium *aSource, IMedium *aTarget,
933 BOOL fMergeForward,
934 IMedium *pParentForTarget,
935 ComSafeArrayIn(IMedium *, aChildrenToReparent));
936 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
937 ISnapshot *aSnapshot,
938 MachineState_T *aMachineState,
939 IProgress **aProgress);
940 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
941 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
942 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
943 LONG64 aTimestamp, IN_BSTR aFlags);
944 STDMETHOD(LockMedia)() { return lockMedia(); }
945 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
946
947 // public methods only for internal purposes
948
949 virtual bool isSessionMachine() const
950 {
951 return true;
952 }
953
954 bool checkForDeath();
955
956 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
957 HRESULT onStorageControllerChange();
958 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
959 HRESULT onSerialPortChange(ISerialPort *serialPort);
960 HRESULT onParallelPortChange(IParallelPort *parallelPort);
961 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
962 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
963 HRESULT onVRDPServerChange(BOOL aRestart);
964 HRESULT onUSBControllerChange();
965 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
966 IVirtualBoxErrorInfo *aError,
967 ULONG aMaskedIfs);
968 HRESULT onUSBDeviceDetach(IN_BSTR aId,
969 IVirtualBoxErrorInfo *aError);
970 HRESULT onSharedFolderChange();
971
972 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
973
974private:
975
976 struct SnapshotData
977 {
978 SnapshotData() : mLastState(MachineState_Null) {}
979
980 MachineState_T mLastState;
981
982 // used when taking snapshot
983 ComObjPtr<Snapshot> mSnapshot;
984
985 // used when saving state
986 Guid mProgressId;
987 Utf8Str mStateFilePath;
988 };
989
990 struct Uninit
991 {
992 enum Reason { Unexpected, Abnormal, Normal };
993 };
994
995 struct SnapshotTask;
996 struct DeleteSnapshotTask;
997 struct RestoreSnapshotTask;
998
999 friend struct DeleteSnapshotTask;
1000 friend struct RestoreSnapshotTask;
1001
1002 void uninit(Uninit::Reason aReason);
1003
1004 HRESULT endSavingState(BOOL aSuccess);
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