VirtualBox

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

Last change on this file since 31930 was 31818, checked in by vboxsync, 15 years ago

added HWVirtEx force property to API

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.4 KB
Line 
1/* $Id: MachineImpl.h 31818 2010-08-20 13:06:33Z 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
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(CPUPriority))(ULONG *aPriority);
387 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
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(IoCacheEnabled)) (BOOL *aEnabled);
454 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
455 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
456 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
457
458 // IMachine methods
459 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
460 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
461
462 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
463 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
464 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
465 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
466 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
467 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
468 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
469 LONG aDevice, IN_BSTR aId, BOOL aForce);
470 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
471 IMedium **aMedium);
472 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
473 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
474 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
475 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
476 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
477 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
478 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
479 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
480 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
481 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
482 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
483 STDMETHOD(RemoveAllCPUIDLeaves)();
484 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
485 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
486 STDMETHOD(SaveSettings)();
487 STDMETHOD(DiscardSettings)();
488 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
489 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
490 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
491 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
492 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
493 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
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(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
511 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
512 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
513 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
514 STDMETHOD(HotPlugCPU(ULONG aCpu));
515 STDMETHOD(HotUnplugCPU(ULONG aCpu));
516 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
517 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
518 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
519
520 // public methods only for internal purposes
521
522 virtual bool isSnapshotMachine() const
523 {
524 return false;
525 }
526
527 virtual bool isSessionMachine() const
528 {
529 return false;
530 }
531
532 /**
533 * Override of the default locking class to be used for validating lock
534 * order with the standard member lock handle.
535 */
536 virtual VBoxLockingClass getLockingClass() const
537 {
538 return LOCKCLASS_MACHINEOBJECT;
539 }
540
541 /// @todo (dmik) add lock and make non-inlined after revising classes
542 // that use it. Note: they should enter Machine lock to keep the returned
543 // information valid!
544 bool isRegistered() { return !!mData->mRegistered; }
545
546 // unsafe inline public methods for internal purposes only (ensure there is
547 // a caller and a read lock before calling them!)
548
549 /**
550 * Returns the VirtualBox object this machine belongs to.
551 *
552 * @note This method doesn't check this object's readiness. Intended to be
553 * used by ready Machine children (whose readiness is bound to the parent's
554 * one) or after doing addCaller() manually.
555 */
556 VirtualBox* getVirtualBox() const { return mParent; }
557
558 /**
559 * Returns this machine ID.
560 *
561 * @note This method doesn't check this object's readiness. Intended to be
562 * used by ready Machine children (whose readiness is bound to the parent's
563 * one) or after adding a caller manually.
564 */
565 const Guid& getId() const { return mData->mUuid; }
566
567 /**
568 * Returns the snapshot ID this machine represents or an empty UUID if this
569 * instance is not SnapshotMachine.
570 *
571 * @note This method doesn't check this object's readiness. Intended to be
572 * used by ready Machine children (whose readiness is bound to the parent's
573 * one) or after adding a caller manually.
574 */
575 inline const Guid& getSnapshotId() const;
576
577 /**
578 * Returns this machine's full settings file path.
579 *
580 * @note This method doesn't lock this object or check its readiness.
581 * Intended to be used only after doing addCaller() manually and locking it
582 * for reading.
583 */
584 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
585
586 /**
587 * Returns this machine name.
588 *
589 * @note This method doesn't lock this object or check its readiness.
590 * Intended to be used only after doing addCaller() manually and locking it
591 * for reading.
592 */
593 const Utf8Str& getName() const { return mUserData->s.strName; }
594
595 enum
596 {
597 IsModified_MachineData = 0x0001,
598 IsModified_Storage = 0x0002,
599 IsModified_NetworkAdapters = 0x0008,
600 IsModified_SerialPorts = 0x0010,
601 IsModified_ParallelPorts = 0x0020,
602 IsModified_VRDPServer = 0x0040,
603 IsModified_AudioAdapter = 0x0080,
604 IsModified_USB = 0x0100,
605 IsModified_BIOS = 0x0200,
606 IsModified_SharedFolders = 0x0400,
607 IsModified_Snapshots = 0x0800
608 };
609
610 void setModified(uint32_t fl);
611
612 // callback handlers
613 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
614 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
615 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
616 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
617 virtual HRESULT onUSBControllerChange() { return S_OK; }
618 virtual HRESULT onStorageControllerChange() { return S_OK; }
619 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
620 virtual HRESULT onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
621 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
622 virtual HRESULT onSharedFolderChange() { return S_OK; }
623
624 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
625
626 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
627 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
628
629 void getLogFolder(Utf8Str &aLogFolder);
630 Utf8Str queryLogFilename(ULONG idx);
631
632 HRESULT openRemoteSession(IInternalSessionControl *aControl,
633 IN_BSTR aType, IN_BSTR aEnvironment,
634 ProgressProxy *aProgress);
635
636 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
637 {
638 HRESULT rc;
639 *directControl = mData->mSession.mDirectControl;
640
641 if (!*directControl)
642 rc = E_ACCESSDENIED;
643 else
644 rc = S_OK;
645
646 return rc;
647 }
648
649#if defined(RT_OS_WINDOWS)
650
651 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
652 ComPtr<IInternalSessionControl> *aControl = NULL,
653 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
654 bool isSessionSpawning(RTPROCESS *aPID = NULL);
655
656 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
657 ComPtr<IInternalSessionControl> *aControl = NULL,
658 HANDLE *aIPCSem = NULL)
659 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
660
661#elif defined(RT_OS_OS2)
662
663 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
664 ComPtr<IInternalSessionControl> *aControl = NULL,
665 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
666
667 bool isSessionSpawning(RTPROCESS *aPID = NULL);
668
669 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
670 ComPtr<IInternalSessionControl> *aControl = NULL,
671 HMTX *aIPCSem = NULL)
672 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
673
674#else
675
676 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
677 ComPtr<IInternalSessionControl> *aControl = NULL,
678 bool aAllowClosing = false);
679 bool isSessionSpawning();
680
681 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
682 ComPtr<IInternalSessionControl> *aControl = NULL)
683 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
684
685#endif
686
687 bool checkForSpawnFailure();
688
689 HRESULT prepareRegister();
690
691 HRESULT getSharedFolder(CBSTR aName,
692 ComObjPtr<SharedFolder> &aSharedFolder,
693 bool aSetError = false)
694 {
695 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
696 return findSharedFolder(aName, aSharedFolder, aSetError);
697 }
698
699 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
700 MachineState_T *aState = NULL,
701 BOOL *aRegistered = NULL);
702 void releaseStateDependency();
703
704protected:
705
706 HRESULT checkStateDependency(StateDependency aDepType);
707
708 Machine *getMachine();
709
710 void ensureNoStateDependencies();
711
712 virtual HRESULT setMachineState(MachineState_T aMachineState);
713
714 HRESULT findSharedFolder(CBSTR aName,
715 ComObjPtr<SharedFolder> &aSharedFolder,
716 bool aSetError = false);
717
718 HRESULT loadSettings(bool aRegistered);
719 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
720 HRESULT loadSnapshot(const settings::Snapshot &data,
721 const Guid &aCurSnapshotId,
722 Snapshot *aParentSnapshot);
723 HRESULT loadHardware(const settings::Hardware &data);
724 HRESULT loadStorageControllers(const settings::Storage &data,
725 const Guid *aSnapshotId = NULL);
726 HRESULT loadStorageDevices(StorageController *aStorageController,
727 const settings::StorageController &data,
728 const Guid *aSnapshotId = NULL);
729
730 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
731 bool aSetError = false);
732 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
733 bool aSetError = false);
734
735 HRESULT getStorageControllerByName(const Utf8Str &aName,
736 ComObjPtr<StorageController> &aStorageController,
737 bool aSetError = false);
738
739 HRESULT getMediumAttachmentsOfController(CBSTR aName,
740 MediaData::AttachmentList &aAttachments);
741
742 enum
743 {
744 /* flags for #saveSettings() */
745 SaveS_ResetCurStateModified = 0x01,
746 SaveS_InformCallbacksAnyway = 0x02,
747 SaveS_Force = 0x04,
748 /* flags for #saveStateSettings() */
749 SaveSTS_CurStateModified = 0x20,
750 SaveSTS_StateFilePath = 0x40,
751 SaveSTS_StateTimeStamp = 0x80
752 };
753
754 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
755 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
756
757 void copyMachineDataToSettings(settings::MachineConfigFile &config);
758 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
759 HRESULT saveHardware(settings::Hardware &data);
760 HRESULT saveStorageControllers(settings::Storage &data);
761 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
762 settings::StorageController &data);
763 HRESULT saveStateSettings(int aFlags);
764
765 HRESULT createImplicitDiffs(IProgress *aProgress,
766 ULONG aWeight,
767 bool aOnline,
768 bool *pfNeedsSaveSettings);
769 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
770
771 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
772 IN_BSTR aControllerName,
773 LONG aControllerPort,
774 LONG aDevice);
775 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
776 ComObjPtr<Medium> pMedium);
777 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
778 Guid &id);
779
780 HRESULT detachDevice(MediumAttachment *pAttach,
781 AutoWriteLock &writeLock,
782 Snapshot *pSnapshot,
783 bool *pfNeedsSaveSettings);
784 HRESULT detachAllMedia(AutoWriteLock &writeLock,
785 Snapshot *pSnapshot,
786 CleanupMode_T cleanupMode,
787 MediaList &llMedia);
788
789 void commitMedia(bool aOnline = false);
790 void rollbackMedia();
791
792 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
793
794 void rollback(bool aNotify);
795 void commit();
796 void copyFrom(Machine *aThat);
797
798 struct DeleteTask;
799 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
800 HRESULT deleteTaskWorker(DeleteTask &task);
801
802#ifdef VBOX_WITH_GUEST_PROPS
803 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
804 LONG64 *aTimestamp, BSTR *aFlags) const;
805 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
806 LONG64 *aTimestamp, BSTR *aFlags) const;
807 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
808 IN_BSTR aFlags);
809 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
810 IN_BSTR aFlags);
811 HRESULT enumerateGuestPropertiesInService
812 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
813 ComSafeArrayOut(BSTR, aValues),
814 ComSafeArrayOut(LONG64, aTimestamps),
815 ComSafeArrayOut(BSTR, aFlags));
816 HRESULT enumerateGuestPropertiesOnVM
817 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
818 ComSafeArrayOut(BSTR, aValues),
819 ComSafeArrayOut(LONG64, aTimestamps),
820 ComSafeArrayOut(BSTR, aFlags));
821#endif /* VBOX_WITH_GUEST_PROPS */
822
823#ifdef VBOX_WITH_RESOURCE_USAGE_API
824 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
825
826 pm::CollectorGuestHAL *mGuestHAL;
827#endif /* VBOX_WITH_RESOURCE_USAGE_API */
828
829 Machine* const mPeer;
830
831 VirtualBox * const mParent;
832
833 Shareable<Data> mData;
834 Shareable<SSData> mSSData;
835
836 Backupable<UserData> mUserData;
837 Backupable<HWData> mHWData;
838 Backupable<MediaData> mMediaData;
839
840 // the following fields need special backup/rollback/commit handling,
841 // so they cannot be a part of HWData
842
843 const ComObjPtr<VRDPServer> mVRDPServer;
844 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
845 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
846 const ComObjPtr<AudioAdapter> mAudioAdapter;
847 const ComObjPtr<USBController> mUSBController;
848 const ComObjPtr<BIOSSettings> mBIOSSettings;
849 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
850
851 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
852 Backupable<StorageControllerList> mStorageControllers;
853
854 friend class SessionMachine;
855 friend class SnapshotMachine;
856 friend class Appliance;
857};
858
859// SessionMachine class
860////////////////////////////////////////////////////////////////////////////////
861
862/**
863 * @note Notes on locking objects of this class:
864 * SessionMachine shares some data with the primary Machine instance (pointed
865 * to by the |mPeer| member). In order to provide data consistency it also
866 * shares its lock handle. This means that whenever you lock a SessionMachine
867 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
868 * instance is also locked in the same lock mode. Keep it in mind.
869 */
870class ATL_NO_VTABLE SessionMachine :
871 public Machine,
872 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
873{
874public:
875 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
876
877 DECLARE_NOT_AGGREGATABLE(SessionMachine)
878
879 DECLARE_PROTECT_FINAL_CONSTRUCT()
880
881 BEGIN_COM_MAP(SessionMachine)
882 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
883 COM_INTERFACE_ENTRY(ISupportErrorInfo)
884 COM_INTERFACE_ENTRY(IMachine)
885 COM_INTERFACE_ENTRY(IInternalMachineControl)
886 END_COM_MAP()
887
888 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
889
890 HRESULT FinalConstruct();
891 void FinalRelease();
892
893 // public initializer/uninitializer for internal purposes only
894 HRESULT init(Machine *aMachine);
895 void uninit() { uninit(Uninit::Unexpected); }
896
897 // util::Lockable interface
898 RWLockHandle *lockHandle() const;
899
900 // IInternalMachineControl methods
901 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
902 STDMETHOD(UpdateState)(MachineState_T machineState);
903 STDMETHOD(GetIPCId)(BSTR *id);
904 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
905 STDMETHOD(EndPowerUp)(LONG iResult);
906 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
907 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
908 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
909 STDMETHOD(AutoCaptureUSBDevices)();
910 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
911 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
912 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
913 STDMETHOD(EndSavingState)(BOOL aSuccess);
914 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
915 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
916 IN_BSTR aName,
917 IN_BSTR aDescription,
918 IProgress *aConsoleProgress,
919 BOOL fTakingSnapshotOnline,
920 BSTR *aStateFilePath);
921 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
922 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
923 MachineState_T *aMachineState, IProgress **aProgress);
924 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
925 IMedium *aSource, IMedium *aTarget,
926 BOOL fMergeForward,
927 IMedium *pParentForTarget,
928 ComSafeArrayIn(IMedium *, aChildrenToReparent));
929 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
930 ISnapshot *aSnapshot,
931 MachineState_T *aMachineState,
932 IProgress **aProgress);
933 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
934 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
935 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
936 LONG64 aTimestamp, IN_BSTR aFlags);
937 STDMETHOD(LockMedia)() { return lockMedia(); }
938 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
939
940 // public methods only for internal purposes
941
942 virtual bool isSessionMachine() const
943 {
944 return true;
945 }
946
947 bool checkForDeath();
948
949 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
950 HRESULT onStorageControllerChange();
951 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
952 HRESULT onSerialPortChange(ISerialPort *serialPort);
953 HRESULT onParallelPortChange(IParallelPort *parallelPort);
954 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
955 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
956 HRESULT onVRDPServerChange(BOOL aRestart);
957 HRESULT onUSBControllerChange();
958 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
959 IVirtualBoxErrorInfo *aError,
960 ULONG aMaskedIfs);
961 HRESULT onUSBDeviceDetach(IN_BSTR aId,
962 IVirtualBoxErrorInfo *aError);
963 HRESULT onSharedFolderChange();
964
965 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
966
967private:
968
969 struct SnapshotData
970 {
971 SnapshotData() : mLastState(MachineState_Null) {}
972
973 MachineState_T mLastState;
974
975 // used when taking snapshot
976 ComObjPtr<Snapshot> mSnapshot;
977
978 // used when saving state
979 Guid mProgressId;
980 Utf8Str mStateFilePath;
981 };
982
983 struct Uninit
984 {
985 enum Reason { Unexpected, Abnormal, Normal };
986 };
987
988 struct SnapshotTask;
989 struct DeleteSnapshotTask;
990 struct RestoreSnapshotTask;
991
992 friend struct DeleteSnapshotTask;
993 friend struct RestoreSnapshotTask;
994
995 void uninit(Uninit::Reason aReason);
996
997 HRESULT endSavingState(BOOL aSuccess);
998
999 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
1000
1001 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1002 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1003
1004 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1005 const Guid &machineId,
1006 const Guid &snapshotId,
1007 bool fOnlineMergePossible,
1008 MediumLockList *aVMMALockList,
1009 ComObjPtr<Medium> &aSource,
1010 ComObjPtr<Medium> &aTarget,
1011 bool &fMergeForward,
1012 ComObjPtr<Medium> &pParentForTarget,
1013 MediaList &aChildrenToReparent,
1014 bool &fNeedOnlineMerge,
1015 MediumLockList * &aMediumLockList);
1016 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1017 const ComObjPtr<Medium> &aSource,
1018 const MediaList &aChildrenToReparent,
1019 bool fNeedsOnlineMerge,
1020 MediumLockList *aMediumLockList,
1021 const Guid &aMediumId,
1022 const Guid &aSnapshotId);
1023 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1024 const ComObjPtr<Medium> &aSource,
1025 const ComObjPtr<Medium> &aTarget,
1026 bool fMergeForward,
1027 const ComObjPtr<Medium> &pParentForTarget,
1028 const MediaList &aChildrenToReparent,
1029 MediumLockList *aMediumLockList,
1030 ComObjPtr<Progress> &aProgress,
1031 bool *pfNeedsMachineSaveSettings);
1032
1033 HRESULT lockMedia();
1034 void unlockMedia();
1035
1036 HRESULT setMachineState(MachineState_T aMachineState);
1037 HRESULT updateMachineStateOnClient();
1038
1039 HRESULT mRemoveSavedState;
1040
1041 SnapshotData mSnapshotData;
1042
1043 /** interprocess semaphore handle for this machine */
1044#if defined(RT_OS_WINDOWS)
1045 HANDLE mIPCSem;
1046 Bstr mIPCSemName;
1047 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1048 ComPtr<IInternalSessionControl> *aControl,
1049 HANDLE *aIPCSem, bool aAllowClosing);
1050#elif defined(RT_OS_OS2)
1051 HMTX mIPCSem;
1052 Bstr mIPCSemName;
1053 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1054 ComPtr<IInternalSessionControl> *aControl,
1055 HMTX *aIPCSem, bool aAllowClosing);
1056#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1057 int mIPCSem;
1058# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1059 Bstr mIPCKey;
1060# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1061#else
1062# error "Port me!"
1063#endif
1064
1065 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1066};
1067
1068// SnapshotMachine class
1069////////////////////////////////////////////////////////////////////////////////
1070
1071/**
1072 * @note Notes on locking objects of this class:
1073 * SnapshotMachine shares some data with the primary Machine instance (pointed
1074 * to by the |mPeer| member). In order to provide data consistency it also
1075 * shares its lock handle. This means that whenever you lock a SessionMachine
1076 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1077 * instance is also locked in the same lock mode. Keep it in mind.
1078 */
1079class ATL_NO_VTABLE SnapshotMachine :
1080 public Machine
1081{
1082public:
1083 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1084
1085 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1086
1087 DECLARE_PROTECT_FINAL_CONSTRUCT()
1088
1089 BEGIN_COM_MAP(SnapshotMachine)
1090 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1091 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1092 COM_INTERFACE_ENTRY(IMachine)
1093 END_COM_MAP()
1094
1095 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1096
1097 HRESULT FinalConstruct();
1098 void FinalRelease();
1099
1100 // public initializer/uninitializer for internal purposes only
1101 HRESULT init(SessionMachine *aSessionMachine,
1102 IN_GUID aSnapshotId,
1103 const Utf8Str &aStateFilePath);
1104 HRESULT init(Machine *aMachine,
1105 const settings::Hardware &hardware,
1106 const settings::Storage &storage,
1107 IN_GUID aSnapshotId,
1108 const Utf8Str &aStateFilePath);
1109 void uninit();
1110
1111 // util::Lockable interface
1112 RWLockHandle *lockHandle() const;
1113
1114 // public methods only for internal purposes
1115
1116 virtual bool isSnapshotMachine() const
1117 {
1118 return true;
1119 }
1120
1121 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1122
1123 // unsafe inline public methods for internal purposes only (ensure there is
1124 // a caller and a read lock before calling them!)
1125
1126 const Guid& getSnapshotId() const { return mSnapshotId; }
1127
1128private:
1129
1130 Guid mSnapshotId;
1131
1132 friend class Snapshot;
1133};
1134
1135// third party methods that depend on SnapshotMachine definiton
1136
1137inline const Guid &Machine::getSnapshotId() const
1138{
1139 return (isSnapshotMachine())
1140 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1141 : Guid::Empty;
1142}
1143
1144
1145#endif // ____H_MACHINEIMPL
1146/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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