VirtualBox

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

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

FT password

  • 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 31742 2010-08-18 07:52:22Z 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 mAccelerate2DVideoEnabled;
260 BOOL mPAEEnabled;
261 BOOL mSyntheticCpu;
262 ULONG mCPUCount;
263 BOOL mCPUHotPlugEnabled;
264 ULONG mCpuPriority;
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
288 BOOL mIoCacheEnabled;
289 ULONG mIoCacheSize;
290 };
291
292 /**
293 * Hard disk and other media data.
294 *
295 * The usage policy is the same as for HWData, but a separate structure
296 * is necessary because hard disk data requires different procedures when
297 * taking or deleting snapshots, etc.
298 *
299 * The data variable is |mMediaData|.
300 */
301 struct MediaData
302 {
303 MediaData();
304 ~MediaData();
305
306 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
307 AttachmentList mAttachments;
308 };
309
310 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
311
312 DECLARE_NOT_AGGREGATABLE(Machine)
313
314 DECLARE_PROTECT_FINAL_CONSTRUCT()
315
316 BEGIN_COM_MAP(Machine)
317 COM_INTERFACE_ENTRY(ISupportErrorInfo)
318 COM_INTERFACE_ENTRY(IMachine)
319 COM_INTERFACE_ENTRY(IDispatch)
320 END_COM_MAP()
321
322 DECLARE_EMPTY_CTOR_DTOR(Machine)
323
324 HRESULT FinalConstruct();
325 void FinalRelease();
326
327 // public initializer/uninitializer for internal purposes only:
328
329 // initializer for creating a new, empty machine
330 HRESULT init(VirtualBox *aParent,
331 const Utf8Str &strConfigFile,
332 const Utf8Str &strName,
333 const Guid &aId,
334 GuestOSType *aOsType = NULL,
335 BOOL aOverride = FALSE,
336 BOOL aNameSync = TRUE);
337
338 // initializer for loading existing machine XML (either registered or not)
339 HRESULT init(VirtualBox *aParent,
340 const Utf8Str &strConfigFile,
341 const Guid *aId);
342
343 // initializer for machine config in memory (OVF import)
344 HRESULT init(VirtualBox *aParent,
345 const Utf8Str &strName,
346 const settings::MachineConfigFile &config);
347
348 void uninit();
349
350#ifdef VBOX_WITH_RESOURCE_USAGE_API
351 // Needed from VirtualBox, for the delayed metrics cleanup.
352 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
353#endif /* VBOX_WITH_RESOURCE_USAGE_API */
354
355protected:
356 HRESULT initImpl(VirtualBox *aParent,
357 const Utf8Str &strConfigFile);
358 HRESULT initDataAndChildObjects();
359 HRESULT registeredInit();
360 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
361 void uninitDataAndChildObjects();
362
363public:
364 // IMachine properties
365 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
366 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
367 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
368 STDMETHOD(COMGETTER(Name))(BSTR *aName);
369 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
370 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
371 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
372 STDMETHOD(COMGETTER(Id))(BSTR *aId);
373 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
374 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
375 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
376 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
377 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
378 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
379 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
380 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
381 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
382 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
383 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
384 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
385 STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
386 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
387 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
388 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
389 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
390 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
391 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
392 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
393 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
394 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
395 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
396 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
397 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
398 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
399 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
402 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
403 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
404 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
405 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
406 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
407 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
408 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
409 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
410 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
411 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
412 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
413 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
414 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
415 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
416 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
417 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
418 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
419 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
420 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
421 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
422 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
423 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
424 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
425 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
426 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
427 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
428 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
429 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
430 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
431 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
432 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
433 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
434 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
435 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
436 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
437 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
438 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
439 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
440 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
441 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
442 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
443 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
444 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
445 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
446 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
447 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
448 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
449 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
450 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
451 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
452 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
453 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
454 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
455 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
456
457 // IMachine methods
458 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
459 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
460
461 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
462 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
463 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
464 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
465 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
466 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
467 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
468 LONG aDevice, IN_BSTR aId, BOOL aForce);
469 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
470 IMedium **aMedium);
471 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
472 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
473 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
474 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
475 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
476 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
477 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
478 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
479 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
480 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
481 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
482 STDMETHOD(RemoveAllCPUIDLeaves)();
483 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
484 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
485 STDMETHOD(SaveSettings)();
486 STDMETHOD(DiscardSettings)();
487 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
488 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
489 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
490 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
491 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
492 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
493 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
494 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
495 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
496 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
497 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
498 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
499 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
500 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
501 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
502 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
503 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
504 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
505 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
506 STDMETHOD(RemoveStorageController(IN_BSTR aName));
507 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
508 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
509 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
510 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
511 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
512 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
513 STDMETHOD(HotPlugCPU(ULONG aCpu));
514 STDMETHOD(HotUnplugCPU(ULONG aCpu));
515 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
516 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
517 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
518
519 // public methods only for internal purposes
520
521 virtual bool isSnapshotMachine() const
522 {
523 return false;
524 }
525
526 virtual bool isSessionMachine() const
527 {
528 return false;
529 }
530
531 /**
532 * Override of the default locking class to be used for validating lock
533 * order with the standard member lock handle.
534 */
535 virtual VBoxLockingClass getLockingClass() const
536 {
537 return LOCKCLASS_MACHINEOBJECT;
538 }
539
540 /// @todo (dmik) add lock and make non-inlined after revising classes
541 // that use it. Note: they should enter Machine lock to keep the returned
542 // information valid!
543 bool isRegistered() { return !!mData->mRegistered; }
544
545 // unsafe inline public methods for internal purposes only (ensure there is
546 // a caller and a read lock before calling them!)
547
548 /**
549 * Returns the VirtualBox object this machine belongs to.
550 *
551 * @note This method doesn't check this object's readiness. Intended to be
552 * used by ready Machine children (whose readiness is bound to the parent's
553 * one) or after doing addCaller() manually.
554 */
555 VirtualBox* getVirtualBox() const { return mParent; }
556
557 /**
558 * Returns this machine ID.
559 *
560 * @note This method doesn't check this object's readiness. Intended to be
561 * used by ready Machine children (whose readiness is bound to the parent's
562 * one) or after adding a caller manually.
563 */
564 const Guid& getId() const { return mData->mUuid; }
565
566 /**
567 * Returns the snapshot ID this machine represents or an empty UUID if this
568 * instance is not SnapshotMachine.
569 *
570 * @note This method doesn't check this object's readiness. Intended to be
571 * used by ready Machine children (whose readiness is bound to the parent's
572 * one) or after adding a caller manually.
573 */
574 inline const Guid& getSnapshotId() const;
575
576 /**
577 * Returns this machine's full settings file path.
578 *
579 * @note This method doesn't lock this object or check its readiness.
580 * Intended to be used only after doing addCaller() manually and locking it
581 * for reading.
582 */
583 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
584
585 /**
586 * Returns this machine name.
587 *
588 * @note This method doesn't lock this object or check its readiness.
589 * Intended to be used only after doing addCaller() manually and locking it
590 * for reading.
591 */
592 const Utf8Str& getName() const { return mUserData->s.strName; }
593
594 enum
595 {
596 IsModified_MachineData = 0x0001,
597 IsModified_Storage = 0x0002,
598 IsModified_NetworkAdapters = 0x0008,
599 IsModified_SerialPorts = 0x0010,
600 IsModified_ParallelPorts = 0x0020,
601 IsModified_VRDPServer = 0x0040,
602 IsModified_AudioAdapter = 0x0080,
603 IsModified_USB = 0x0100,
604 IsModified_BIOS = 0x0200,
605 IsModified_SharedFolders = 0x0400,
606 IsModified_Snapshots = 0x0800
607 };
608
609 void setModified(uint32_t fl);
610
611 // callback handlers
612 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
613 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
614 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
615 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
616 virtual HRESULT onUSBControllerChange() { return S_OK; }
617 virtual HRESULT onStorageControllerChange() { return S_OK; }
618 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
619 virtual HRESULT onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
620 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
621 virtual HRESULT onSharedFolderChange() { return S_OK; }
622
623 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
624
625 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
626 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
627
628 void getLogFolder(Utf8Str &aLogFolder);
629 Utf8Str queryLogFilename(ULONG idx);
630
631 HRESULT openRemoteSession(IInternalSessionControl *aControl,
632 IN_BSTR aType, IN_BSTR aEnvironment,
633 ProgressProxy *aProgress);
634
635 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
636 {
637 HRESULT rc;
638 *directControl = mData->mSession.mDirectControl;
639
640 if (!*directControl)
641 rc = E_ACCESSDENIED;
642 else
643 rc = S_OK;
644
645 return rc;
646 }
647
648#if defined(RT_OS_WINDOWS)
649
650 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
651 ComPtr<IInternalSessionControl> *aControl = NULL,
652 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
653 bool isSessionSpawning(RTPROCESS *aPID = NULL);
654
655 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
656 ComPtr<IInternalSessionControl> *aControl = NULL,
657 HANDLE *aIPCSem = NULL)
658 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
659
660#elif defined(RT_OS_OS2)
661
662 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
663 ComPtr<IInternalSessionControl> *aControl = NULL,
664 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
665
666 bool isSessionSpawning(RTPROCESS *aPID = NULL);
667
668 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
669 ComPtr<IInternalSessionControl> *aControl = NULL,
670 HMTX *aIPCSem = NULL)
671 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
672
673#else
674
675 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
676 ComPtr<IInternalSessionControl> *aControl = NULL,
677 bool aAllowClosing = false);
678 bool isSessionSpawning();
679
680 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
681 ComPtr<IInternalSessionControl> *aControl = NULL)
682 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
683
684#endif
685
686 bool checkForSpawnFailure();
687
688 HRESULT prepareRegister();
689
690 HRESULT getSharedFolder(CBSTR aName,
691 ComObjPtr<SharedFolder> &aSharedFolder,
692 bool aSetError = false)
693 {
694 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
695 return findSharedFolder(aName, aSharedFolder, aSetError);
696 }
697
698 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
699 MachineState_T *aState = NULL,
700 BOOL *aRegistered = NULL);
701 void releaseStateDependency();
702
703protected:
704
705 HRESULT checkStateDependency(StateDependency aDepType);
706
707 Machine *getMachine();
708
709 void ensureNoStateDependencies();
710
711 virtual HRESULT setMachineState(MachineState_T aMachineState);
712
713 HRESULT findSharedFolder(CBSTR aName,
714 ComObjPtr<SharedFolder> &aSharedFolder,
715 bool aSetError = false);
716
717 HRESULT loadSettings(bool aRegistered);
718 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
719 HRESULT loadSnapshot(const settings::Snapshot &data,
720 const Guid &aCurSnapshotId,
721 Snapshot *aParentSnapshot);
722 HRESULT loadHardware(const settings::Hardware &data);
723 HRESULT loadStorageControllers(const settings::Storage &data,
724 const Guid *aSnapshotId = NULL);
725 HRESULT loadStorageDevices(StorageController *aStorageController,
726 const settings::StorageController &data,
727 const Guid *aSnapshotId = NULL);
728
729 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
730 bool aSetError = false);
731 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
732 bool aSetError = false);
733
734 HRESULT getStorageControllerByName(const Utf8Str &aName,
735 ComObjPtr<StorageController> &aStorageController,
736 bool aSetError = false);
737
738 HRESULT getMediumAttachmentsOfController(CBSTR aName,
739 MediaData::AttachmentList &aAttachments);
740
741 enum
742 {
743 /* flags for #saveSettings() */
744 SaveS_ResetCurStateModified = 0x01,
745 SaveS_InformCallbacksAnyway = 0x02,
746 SaveS_Force = 0x04,
747 /* flags for #saveStateSettings() */
748 SaveSTS_CurStateModified = 0x20,
749 SaveSTS_StateFilePath = 0x40,
750 SaveSTS_StateTimeStamp = 0x80
751 };
752
753 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
754 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
755
756 void copyMachineDataToSettings(settings::MachineConfigFile &config);
757 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
758 HRESULT saveHardware(settings::Hardware &data);
759 HRESULT saveStorageControllers(settings::Storage &data);
760 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
761 settings::StorageController &data);
762 HRESULT saveStateSettings(int aFlags);
763
764 HRESULT createImplicitDiffs(IProgress *aProgress,
765 ULONG aWeight,
766 bool aOnline,
767 bool *pfNeedsSaveSettings);
768 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
769
770 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
771 IN_BSTR aControllerName,
772 LONG aControllerPort,
773 LONG aDevice);
774 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
775 ComObjPtr<Medium> pMedium);
776 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
777 Guid &id);
778
779 HRESULT detachDevice(MediumAttachment *pAttach,
780 AutoWriteLock &writeLock,
781 Snapshot *pSnapshot,
782 bool *pfNeedsSaveSettings);
783 HRESULT detachAllMedia(AutoWriteLock &writeLock,
784 Snapshot *pSnapshot,
785 CleanupMode_T cleanupMode,
786 MediaList &llMedia);
787
788 void commitMedia(bool aOnline = false);
789 void rollbackMedia();
790
791 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
792
793 void rollback(bool aNotify);
794 void commit();
795 void copyFrom(Machine *aThat);
796
797 struct DeleteTask;
798 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
799 HRESULT deleteTaskWorker(DeleteTask &task);
800
801#ifdef VBOX_WITH_GUEST_PROPS
802 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
803 LONG64 *aTimestamp, BSTR *aFlags) const;
804 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
805 LONG64 *aTimestamp, BSTR *aFlags) const;
806 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
807 IN_BSTR aFlags);
808 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
809 IN_BSTR aFlags);
810 HRESULT enumerateGuestPropertiesInService
811 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
812 ComSafeArrayOut(BSTR, aValues),
813 ComSafeArrayOut(LONG64, aTimestamps),
814 ComSafeArrayOut(BSTR, aFlags));
815 HRESULT enumerateGuestPropertiesOnVM
816 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
817 ComSafeArrayOut(BSTR, aValues),
818 ComSafeArrayOut(LONG64, aTimestamps),
819 ComSafeArrayOut(BSTR, aFlags));
820#endif /* VBOX_WITH_GUEST_PROPS */
821
822#ifdef VBOX_WITH_RESOURCE_USAGE_API
823 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
824
825 pm::CollectorGuestHAL *mGuestHAL;
826#endif /* VBOX_WITH_RESOURCE_USAGE_API */
827
828 Machine* const mPeer;
829
830 VirtualBox * const mParent;
831
832 Shareable<Data> mData;
833 Shareable<SSData> mSSData;
834
835 Backupable<UserData> mUserData;
836 Backupable<HWData> mHWData;
837 Backupable<MediaData> mMediaData;
838
839 // the following fields need special backup/rollback/commit handling,
840 // so they cannot be a part of HWData
841
842 const ComObjPtr<VRDPServer> mVRDPServer;
843 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
844 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
845 const ComObjPtr<AudioAdapter> mAudioAdapter;
846 const ComObjPtr<USBController> mUSBController;
847 const ComObjPtr<BIOSSettings> mBIOSSettings;
848 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
849
850 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
851 Backupable<StorageControllerList> mStorageControllers;
852
853 friend class SessionMachine;
854 friend class SnapshotMachine;
855 friend class Appliance;
856};
857
858// SessionMachine class
859////////////////////////////////////////////////////////////////////////////////
860
861/**
862 * @note Notes on locking objects of this class:
863 * SessionMachine shares some data with the primary Machine instance (pointed
864 * to by the |mPeer| member). In order to provide data consistency it also
865 * shares its lock handle. This means that whenever you lock a SessionMachine
866 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
867 * instance is also locked in the same lock mode. Keep it in mind.
868 */
869class ATL_NO_VTABLE SessionMachine :
870 public Machine,
871 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
872{
873public:
874 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
875
876 DECLARE_NOT_AGGREGATABLE(SessionMachine)
877
878 DECLARE_PROTECT_FINAL_CONSTRUCT()
879
880 BEGIN_COM_MAP(SessionMachine)
881 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
882 COM_INTERFACE_ENTRY(ISupportErrorInfo)
883 COM_INTERFACE_ENTRY(IMachine)
884 COM_INTERFACE_ENTRY(IInternalMachineControl)
885 END_COM_MAP()
886
887 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
888
889 HRESULT FinalConstruct();
890 void FinalRelease();
891
892 // public initializer/uninitializer for internal purposes only
893 HRESULT init(Machine *aMachine);
894 void uninit() { uninit(Uninit::Unexpected); }
895
896 // util::Lockable interface
897 RWLockHandle *lockHandle() const;
898
899 // IInternalMachineControl methods
900 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
901 STDMETHOD(UpdateState)(MachineState_T machineState);
902 STDMETHOD(GetIPCId)(BSTR *id);
903 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
904 STDMETHOD(EndPowerUp)(LONG iResult);
905 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
906 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
907 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
908 STDMETHOD(AutoCaptureUSBDevices)();
909 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
910 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
911 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
912 STDMETHOD(EndSavingState)(BOOL aSuccess);
913 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
914 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
915 IN_BSTR aName,
916 IN_BSTR aDescription,
917 IProgress *aConsoleProgress,
918 BOOL fTakingSnapshotOnline,
919 BSTR *aStateFilePath);
920 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
921 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
922 MachineState_T *aMachineState, IProgress **aProgress);
923 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
924 IMedium *aSource, IMedium *aTarget,
925 BOOL fMergeForward,
926 IMedium *pParentForTarget,
927 ComSafeArrayIn(IMedium *, aChildrenToReparent));
928 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
929 ISnapshot *aSnapshot,
930 MachineState_T *aMachineState,
931 IProgress **aProgress);
932 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
933 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
934 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
935 LONG64 aTimestamp, IN_BSTR aFlags);
936 STDMETHOD(LockMedia)() { return lockMedia(); }
937 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
938
939 // public methods only for internal purposes
940
941 virtual bool isSessionMachine() const
942 {
943 return true;
944 }
945
946 bool checkForDeath();
947
948 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
949 HRESULT onStorageControllerChange();
950 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
951 HRESULT onSerialPortChange(ISerialPort *serialPort);
952 HRESULT onParallelPortChange(IParallelPort *parallelPort);
953 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
954 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
955 HRESULT onVRDPServerChange(BOOL aRestart);
956 HRESULT onUSBControllerChange();
957 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
958 IVirtualBoxErrorInfo *aError,
959 ULONG aMaskedIfs);
960 HRESULT onUSBDeviceDetach(IN_BSTR aId,
961 IVirtualBoxErrorInfo *aError);
962 HRESULT onSharedFolderChange();
963
964 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
965
966private:
967
968 struct SnapshotData
969 {
970 SnapshotData() : mLastState(MachineState_Null) {}
971
972 MachineState_T mLastState;
973
974 // used when taking snapshot
975 ComObjPtr<Snapshot> mSnapshot;
976
977 // used when saving state
978 Guid mProgressId;
979 Utf8Str mStateFilePath;
980 };
981
982 struct Uninit
983 {
984 enum Reason { Unexpected, Abnormal, Normal };
985 };
986
987 struct SnapshotTask;
988 struct DeleteSnapshotTask;
989 struct RestoreSnapshotTask;
990
991 friend struct DeleteSnapshotTask;
992 friend struct RestoreSnapshotTask;
993
994 void uninit(Uninit::Reason aReason);
995
996 HRESULT endSavingState(BOOL aSuccess);
997
998 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
999
1000 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1001 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1002
1003 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1004 const Guid &machineId,
1005 const Guid &snapshotId,
1006 bool fOnlineMergePossible,
1007 MediumLockList *aVMMALockList,
1008 ComObjPtr<Medium> &aSource,
1009 ComObjPtr<Medium> &aTarget,
1010 bool &fMergeForward,
1011 ComObjPtr<Medium> &pParentForTarget,
1012 MediaList &aChildrenToReparent,
1013 bool &fNeedOnlineMerge,
1014 MediumLockList * &aMediumLockList);
1015 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1016 const ComObjPtr<Medium> &aSource,
1017 const MediaList &aChildrenToReparent,
1018 bool fNeedsOnlineMerge,
1019 MediumLockList *aMediumLockList,
1020 const Guid &aMediumId,
1021 const Guid &aSnapshotId);
1022 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1023 const ComObjPtr<Medium> &aSource,
1024 const ComObjPtr<Medium> &aTarget,
1025 bool fMergeForward,
1026 const ComObjPtr<Medium> &pParentForTarget,
1027 const MediaList &aChildrenToReparent,
1028 MediumLockList *aMediumLockList,
1029 ComObjPtr<Progress> &aProgress,
1030 bool *pfNeedsMachineSaveSettings);
1031
1032 HRESULT lockMedia();
1033 void unlockMedia();
1034
1035 HRESULT setMachineState(MachineState_T aMachineState);
1036 HRESULT updateMachineStateOnClient();
1037
1038 HRESULT mRemoveSavedState;
1039
1040 SnapshotData mSnapshotData;
1041
1042 /** interprocess semaphore handle for this machine */
1043#if defined(RT_OS_WINDOWS)
1044 HANDLE mIPCSem;
1045 Bstr mIPCSemName;
1046 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1047 ComPtr<IInternalSessionControl> *aControl,
1048 HANDLE *aIPCSem, bool aAllowClosing);
1049#elif defined(RT_OS_OS2)
1050 HMTX mIPCSem;
1051 Bstr mIPCSemName;
1052 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1053 ComPtr<IInternalSessionControl> *aControl,
1054 HMTX *aIPCSem, bool aAllowClosing);
1055#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1056 int mIPCSem;
1057# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1058 Bstr mIPCKey;
1059# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1060#else
1061# error "Port me!"
1062#endif
1063
1064 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1065};
1066
1067// SnapshotMachine class
1068////////////////////////////////////////////////////////////////////////////////
1069
1070/**
1071 * @note Notes on locking objects of this class:
1072 * SnapshotMachine shares some data with the primary Machine instance (pointed
1073 * to by the |mPeer| member). In order to provide data consistency it also
1074 * shares its lock handle. This means that whenever you lock a SessionMachine
1075 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1076 * instance is also locked in the same lock mode. Keep it in mind.
1077 */
1078class ATL_NO_VTABLE SnapshotMachine :
1079 public Machine
1080{
1081public:
1082 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1083
1084 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1085
1086 DECLARE_PROTECT_FINAL_CONSTRUCT()
1087
1088 BEGIN_COM_MAP(SnapshotMachine)
1089 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1090 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1091 COM_INTERFACE_ENTRY(IMachine)
1092 END_COM_MAP()
1093
1094 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1095
1096 HRESULT FinalConstruct();
1097 void FinalRelease();
1098
1099 // public initializer/uninitializer for internal purposes only
1100 HRESULT init(SessionMachine *aSessionMachine,
1101 IN_GUID aSnapshotId,
1102 const Utf8Str &aStateFilePath);
1103 HRESULT init(Machine *aMachine,
1104 const settings::Hardware &hardware,
1105 const settings::Storage &storage,
1106 IN_GUID aSnapshotId,
1107 const Utf8Str &aStateFilePath);
1108 void uninit();
1109
1110 // util::Lockable interface
1111 RWLockHandle *lockHandle() const;
1112
1113 // public methods only for internal purposes
1114
1115 virtual bool isSnapshotMachine() const
1116 {
1117 return true;
1118 }
1119
1120 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1121
1122 // unsafe inline public methods for internal purposes only (ensure there is
1123 // a caller and a read lock before calling them!)
1124
1125 const Guid& getSnapshotId() const { return mSnapshotId; }
1126
1127private:
1128
1129 Guid mSnapshotId;
1130
1131 friend class Snapshot;
1132};
1133
1134// third party methods that depend on SnapshotMachine definiton
1135
1136inline const Guid &Machine::getSnapshotId() const
1137{
1138 return (isSnapshotMachine())
1139 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1140 : Guid::Empty;
1141}
1142
1143
1144#endif // ____H_MACHINEIMPL
1145/* 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