VirtualBox

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

Last change on this file since 31447 was 31333, checked in by vboxsync, 15 years ago

Main: rework new implementation of Machine::Unregister() and Machine::Delete() to be more flexible and still easy to use

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