VirtualBox

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

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

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.8 KB
Line 
1/* $Id: MachineImpl.h 33540 2010-10-28 09:27:05Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "VRDPServerImpl.h"
24#include "MediumAttachmentImpl.h"
25#include "MediumLock.h"
26#include "NetworkAdapterImpl.h"
27#include "AudioAdapterImpl.h"
28#include "SerialPortImpl.h"
29#include "ParallelPortImpl.h"
30#include "BIOSSettingsImpl.h"
31#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
32#include "VBox/settings.h"
33#ifdef VBOX_WITH_RESOURCE_USAGE_API
34#include "Performance.h"
35#include "PerformanceImpl.h"
36#endif /* VBOX_WITH_RESOURCE_USAGE_API */
37
38// generated header
39#include "SchemaDefs.h"
40
41#include "VBox/com/ErrorInfo.h"
42
43#include <iprt/file.h>
44#include <iprt/thread.h>
45#include <iprt/time.h>
46
47#include <list>
48
49// defines
50////////////////////////////////////////////////////////////////////////////////
51
52// helper declarations
53////////////////////////////////////////////////////////////////////////////////
54
55class Progress;
56class ProgressProxy;
57class Keyboard;
58class Mouse;
59class Display;
60class MachineDebugger;
61class USBController;
62class Snapshot;
63class SharedFolder;
64class HostUSBDevice;
65class StorageController;
66
67class SessionMachine;
68
69namespace settings
70{
71 class MachineConfigFile;
72 struct Snapshot;
73 struct Hardware;
74 struct Storage;
75 struct StorageController;
76 struct MachineRegistryEntry;
77}
78
79// Machine class
80////////////////////////////////////////////////////////////////////////////////
81
82class ATL_NO_VTABLE Machine :
83 public VirtualBoxBaseWithChildrenNEXT,
84 VBOX_SCRIPTABLE_IMPL(IMachine)
85{
86 Q_OBJECT
87
88public:
89
90 enum StateDependency
91 {
92 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
93 };
94
95 /**
96 * Internal machine data.
97 *
98 * Only one instance of this data exists per every machine -- it is shared
99 * by the Machine, SessionMachine and all SnapshotMachine instances
100 * associated with the given machine using the util::Shareable template
101 * through the mData variable.
102 *
103 * @note |const| members are persistent during lifetime so can be
104 * accessed without locking.
105 *
106 * @note There is no need to lock anything inside init() or uninit()
107 * methods, because they are always serialized (see AutoCaller).
108 */
109 struct Data
110 {
111 /**
112 * Data structure to hold information about sessions opened for the
113 * given machine.
114 */
115 struct Session
116 {
117 /** Control of the direct session opened by lockMachine() */
118 ComPtr<IInternalSessionControl> mDirectControl;
119
120 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
121
122 /** list of controls of all opened remote sessions */
123 RemoteControlList mRemoteControls;
124
125 /** openRemoteSession() and OnSessionEnd() progress indicator */
126 ComObjPtr<ProgressProxy> mProgress;
127
128 /**
129 * PID of the session object that must be passed to openSession() to
130 * finalize the openRemoteSession() request (i.e., PID of the
131 * process created by openRemoteSession())
132 */
133 RTPROCESS mPid;
134
135 /** Current session state */
136 SessionState_T mState;
137
138 /** Session type string (for indirect sessions) */
139 Bstr mType;
140
141 /** Session machine object */
142 ComObjPtr<SessionMachine> mMachine;
143
144 /** Medium object lock collection. */
145 MediumLockListMap mLockedMedia;
146 };
147
148 Data();
149 ~Data();
150
151 const Guid mUuid;
152 BOOL mRegistered;
153
154 Utf8Str m_strConfigFile;
155 Utf8Str m_strConfigFileFull;
156
157 // machine settings XML file
158 settings::MachineConfigFile *pMachineConfigFile;
159 uint32_t flModifications;
160
161 BOOL mAccessible;
162 com::ErrorInfo mAccessError;
163
164 MachineState_T mMachineState;
165 RTTIMESPEC mLastStateChange;
166
167 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
168 uint32_t mMachineStateDeps;
169 RTSEMEVENTMULTI mMachineStateDepsSem;
170 uint32_t mMachineStateChangePending;
171
172 BOOL mCurrentStateModified;
173 /** Guest properties have been modified and need saving since the
174 * machine was started, or there are transient properties which need
175 * deleting and the machine is being shut down. */
176 BOOL mGuestPropertiesModified;
177
178 Session mSession;
179
180 ComObjPtr<Snapshot> mFirstSnapshot;
181 ComObjPtr<Snapshot> mCurrentSnapshot;
182
183 // list of files to delete in Delete(); this list is filled by Unregister()
184 std::list<Utf8Str> llFilesToDelete;
185 };
186
187 /**
188 * Saved state data.
189 *
190 * It's actually only the state file path string, but it needs to be
191 * separate from Data, because Machine and SessionMachine instances
192 * share it, while SnapshotMachine does not.
193 *
194 * The data variable is |mSSData|.
195 */
196 struct SSData
197 {
198 Utf8Str mStateFilePath;
199 };
200
201 /**
202 * User changeable machine data.
203 *
204 * This data is common for all machine snapshots, i.e. it is shared
205 * by all SnapshotMachine instances associated with the given machine
206 * using the util::Backupable template through the |mUserData| variable.
207 *
208 * SessionMachine instances can alter this data and discard changes.
209 *
210 * @note There is no need to lock anything inside init() or uninit()
211 * methods, because they are always serialized (see AutoCaller).
212 */
213 struct UserData
214 {
215 settings::MachineUserData s;
216 Utf8Str m_strSnapshotFolderFull;
217 };
218
219 /**
220 * Hardware data.
221 *
222 * This data is unique for a machine and for every machine snapshot.
223 * Stored using the util::Backupable template in the |mHWData| variable.
224 *
225 * SessionMachine instances can alter this data and discard changes.
226 */
227 struct HWData
228 {
229 /**
230 * Data structure to hold information about a guest property.
231 */
232 struct GuestProperty {
233 /** Property name */
234 Utf8Str strName;
235 /** Property value */
236 Utf8Str strValue;
237 /** Property timestamp */
238 LONG64 mTimestamp;
239 /** Property flags */
240 ULONG mFlags;
241 };
242
243 HWData();
244 ~HWData();
245
246 Bstr mHWVersion;
247 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
248 ULONG mMemorySize;
249 ULONG mMemoryBalloonSize;
250 BOOL mPageFusionEnabled;
251 ULONG mVRAMSize;
252 ULONG mMonitorCount;
253 BOOL mHWVirtExEnabled;
254 BOOL mHWVirtExExclusive;
255 BOOL mHWVirtExNestedPagingEnabled;
256 BOOL mHWVirtExLargePagesEnabled;
257 BOOL mHWVirtExVPIDEnabled;
258 BOOL mHWVirtExForceEnabled;
259 BOOL mAccelerate2DVideoEnabled;
260 BOOL mPAEEnabled;
261 BOOL mSyntheticCpu;
262 ULONG mCPUCount;
263 BOOL mCPUHotPlugEnabled;
264 ULONG mCpuExecutionCap;
265 BOOL mAccelerate3DEnabled;
266 BOOL mHpetEnabled;
267
268 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
269
270 settings::CpuIdLeaf mCpuIdStdLeafs[10];
271 settings::CpuIdLeaf mCpuIdExtLeafs[10];
272
273 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
274
275 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
276 SharedFolderList mSharedFolders;
277
278 ClipboardMode_T mClipboardMode;
279
280 typedef std::list<GuestProperty> GuestPropertyList;
281 GuestPropertyList mGuestProperties;
282 Utf8Str mGuestPropertyNotificationPatterns;
283
284 FirmwareType_T mFirmwareType;
285 KeyboardHidType_T mKeyboardHidType;
286 PointingHidType_T mPointingHidType;
287 ChipsetType_T mChipsetType;
288
289 BOOL mIoCacheEnabled;
290 ULONG mIoCacheSize;
291 };
292
293 /**
294 * Hard disk and other media data.
295 *
296 * The usage policy is the same as for HWData, but a separate structure
297 * is necessary because hard disk data requires different procedures when
298 * taking or deleting snapshots, etc.
299 *
300 * The data variable is |mMediaData|.
301 */
302 struct MediaData
303 {
304 MediaData();
305 ~MediaData();
306
307 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
308 AttachmentList mAttachments;
309 };
310
311 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
312
313 DECLARE_NOT_AGGREGATABLE(Machine)
314
315 DECLARE_PROTECT_FINAL_CONSTRUCT()
316
317 BEGIN_COM_MAP(Machine)
318 COM_INTERFACE_ENTRY(ISupportErrorInfo)
319 COM_INTERFACE_ENTRY(IMachine)
320 COM_INTERFACE_ENTRY(IDispatch)
321 END_COM_MAP()
322
323 DECLARE_EMPTY_CTOR_DTOR(Machine)
324
325 HRESULT FinalConstruct();
326 void FinalRelease();
327
328 // public initializer/uninitializer for internal purposes only:
329
330 // initializer for creating a new, empty machine
331 HRESULT init(VirtualBox *aParent,
332 const Utf8Str &strConfigFile,
333 const Utf8Str &strName,
334 GuestOSType *aOsType,
335 const Guid &aId,
336 bool fForceOverwrite);
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 fForceOverwrite);
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(CPUExecutionCap))(ULONG *aExecutionCap);
386 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
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(VRDEServer))(IVRDEServer **vrdeServer);
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(ChipsetType)) (ChipsetType_T *aChipsetType);
453 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
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, IMedium *aMedium);
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, IMedium *aMedium, 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, IN_BSTR location, IVirtualSystemDescription **aDescription);
492 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
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(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
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(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, 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, LONG64 aOffset, LONG64 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 Utf8Str& getName() const { return mUserData->s.strName; }
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_VRDEServer = 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 onVRDEServerChange(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 onCPUExecutionCapChange(ULONG /* aExecutionCap */) { 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 const Guid *puuidRegistry);
722 HRESULT loadSnapshot(const settings::Snapshot &data,
723 const Guid &aCurSnapshotId,
724 Snapshot *aParentSnapshot);
725 HRESULT loadHardware(const settings::Hardware &data);
726 HRESULT loadStorageControllers(const settings::Storage &data,
727 const Guid *puuidRegistry,
728 const Guid *puuidSnapshot);
729 HRESULT loadStorageDevices(StorageController *aStorageController,
730 const settings::StorageController &data,
731 const Guid *puuidRegistry,
732 const Guid *puuidSnapshot);
733
734 HRESULT findSnapshotById(const Guid &aId,
735 ComObjPtr<Snapshot> &aSnapshot,
736 bool aSetError = false);
737 HRESULT findSnapshotByName(const Utf8Str &strName,
738 ComObjPtr<Snapshot> &aSnapshot,
739 bool aSetError = false);
740
741 HRESULT getStorageControllerByName(const Utf8Str &aName,
742 ComObjPtr<StorageController> &aStorageController,
743 bool aSetError = false);
744
745 HRESULT getMediumAttachmentsOfController(CBSTR aName,
746 MediaData::AttachmentList &aAttachments);
747
748 enum
749 {
750 /* flags for #saveSettings() */
751 SaveS_ResetCurStateModified = 0x01,
752 SaveS_InformCallbacksAnyway = 0x02,
753 SaveS_Force = 0x04,
754 /* flags for #saveStateSettings() */
755 SaveSTS_CurStateModified = 0x20,
756 SaveSTS_StateFilePath = 0x40,
757 SaveSTS_StateTimeStamp = 0x80
758 };
759
760 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
761 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
762
763 void copyMachineDataToSettings(settings::MachineConfigFile &config);
764 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
765 HRESULT saveHardware(settings::Hardware &data);
766 HRESULT saveStorageControllers(settings::Storage &data);
767 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
768 settings::StorageController &data);
769 HRESULT saveStateSettings(int aFlags);
770
771 HRESULT createImplicitDiffs(IProgress *aProgress,
772 ULONG aWeight,
773 bool aOnline,
774 bool *pfNeedsSaveSettings);
775 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
776
777 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
778 IN_BSTR aControllerName,
779 LONG aControllerPort,
780 LONG aDevice);
781 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
782 ComObjPtr<Medium> pMedium);
783 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
784 Guid &id);
785
786 HRESULT detachDevice(MediumAttachment *pAttach,
787 AutoWriteLock &writeLock,
788 Snapshot *pSnapshot,
789 bool *pfNeedsSaveSettings);
790 HRESULT detachAllMedia(AutoWriteLock &writeLock,
791 Snapshot *pSnapshot,
792 CleanupMode_T cleanupMode,
793 MediaList &llMedia);
794
795 void commitMedia(bool aOnline = false);
796 void rollbackMedia();
797
798 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
799
800 void rollback(bool aNotify);
801 void commit();
802 void copyFrom(Machine *aThat);
803
804 struct DeleteTask;
805 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
806 HRESULT deleteTaskWorker(DeleteTask &task);
807
808#ifdef VBOX_WITH_GUEST_PROPS
809 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
810 LONG64 *aTimestamp, BSTR *aFlags) const;
811 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
812 LONG64 *aTimestamp, BSTR *aFlags) const;
813 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
814 IN_BSTR aFlags);
815 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
816 IN_BSTR aFlags);
817 HRESULT enumerateGuestPropertiesInService
818 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
819 ComSafeArrayOut(BSTR, aValues),
820 ComSafeArrayOut(LONG64, aTimestamps),
821 ComSafeArrayOut(BSTR, aFlags));
822 HRESULT enumerateGuestPropertiesOnVM
823 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
824 ComSafeArrayOut(BSTR, aValues),
825 ComSafeArrayOut(LONG64, aTimestamps),
826 ComSafeArrayOut(BSTR, aFlags));
827#endif /* VBOX_WITH_GUEST_PROPS */
828
829#ifdef VBOX_WITH_RESOURCE_USAGE_API
830 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
831
832 pm::CollectorGuestHAL *mGuestHAL;
833#endif /* VBOX_WITH_RESOURCE_USAGE_API */
834
835 Machine* const mPeer;
836
837 VirtualBox * const mParent;
838
839 Shareable<Data> mData;
840 Shareable<SSData> mSSData;
841
842 Backupable<UserData> mUserData;
843 Backupable<HWData> mHWData;
844 Backupable<MediaData> mMediaData;
845
846 // the following fields need special backup/rollback/commit handling,
847 // so they cannot be a part of HWData
848
849 const ComObjPtr<VRDEServer> mVRDEServer;
850 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
851 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
852 const ComObjPtr<AudioAdapter> mAudioAdapter;
853 const ComObjPtr<USBController> mUSBController;
854 const ComObjPtr<BIOSSettings> mBIOSSettings;
855 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
856
857 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
858 Backupable<StorageControllerList> mStorageControllers;
859
860 friend class SessionMachine;
861 friend class SnapshotMachine;
862 friend class Appliance;
863};
864
865// SessionMachine class
866////////////////////////////////////////////////////////////////////////////////
867
868/**
869 * @note Notes on locking objects of this class:
870 * SessionMachine shares some data with the primary Machine instance (pointed
871 * to by the |mPeer| member). In order to provide data consistency it also
872 * shares its lock handle. This means that whenever you lock a SessionMachine
873 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
874 * instance is also locked in the same lock mode. Keep it in mind.
875 */
876class ATL_NO_VTABLE SessionMachine :
877 public Machine,
878 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
879{
880public:
881 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
882
883 DECLARE_NOT_AGGREGATABLE(SessionMachine)
884
885 DECLARE_PROTECT_FINAL_CONSTRUCT()
886
887 BEGIN_COM_MAP(SessionMachine)
888 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
889 COM_INTERFACE_ENTRY(ISupportErrorInfo)
890 COM_INTERFACE_ENTRY(IMachine)
891 COM_INTERFACE_ENTRY(IInternalMachineControl)
892 END_COM_MAP()
893
894 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
895
896 HRESULT FinalConstruct();
897 void FinalRelease();
898
899 // public initializer/uninitializer for internal purposes only
900 HRESULT init(Machine *aMachine);
901 void uninit() { uninit(Uninit::Unexpected); }
902
903 // util::Lockable interface
904 RWLockHandle *lockHandle() const;
905
906 // IInternalMachineControl methods
907 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
908 STDMETHOD(UpdateState)(MachineState_T machineState);
909 STDMETHOD(GetIPCId)(BSTR *id);
910 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
911 STDMETHOD(EndPowerUp)(LONG iResult);
912 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
913 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
914 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
915 STDMETHOD(AutoCaptureUSBDevices)();
916 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
917 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
918 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
919 STDMETHOD(EndSavingState)(BOOL aSuccess);
920 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
921 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
922 IN_BSTR aName,
923 IN_BSTR aDescription,
924 IProgress *aConsoleProgress,
925 BOOL fTakingSnapshotOnline,
926 BSTR *aStateFilePath);
927 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
928 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
929 MachineState_T *aMachineState, IProgress **aProgress);
930 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
931 IMedium *aSource, IMedium *aTarget,
932 BOOL fMergeForward,
933 IMedium *pParentForTarget,
934 ComSafeArrayIn(IMedium *, aChildrenToReparent));
935 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
936 ISnapshot *aSnapshot,
937 MachineState_T *aMachineState,
938 IProgress **aProgress);
939 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
940 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
941 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
942 LONG64 aTimestamp, IN_BSTR aFlags);
943 STDMETHOD(LockMedia)() { return lockMedia(); }
944 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
945
946 // public methods only for internal purposes
947
948 virtual bool isSessionMachine() const
949 {
950 return true;
951 }
952
953 bool checkForDeath();
954
955 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
956 HRESULT onStorageControllerChange();
957 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
958 HRESULT onSerialPortChange(ISerialPort *serialPort);
959 HRESULT onParallelPortChange(IParallelPort *parallelPort);
960 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
961 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
962 HRESULT onVRDEServerChange(BOOL aRestart);
963 HRESULT onUSBControllerChange();
964 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
965 IVirtualBoxErrorInfo *aError,
966 ULONG aMaskedIfs);
967 HRESULT onUSBDeviceDetach(IN_BSTR aId,
968 IVirtualBoxErrorInfo *aError);
969 HRESULT onSharedFolderChange();
970
971 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
972
973private:
974
975 struct SnapshotData
976 {
977 SnapshotData() : mLastState(MachineState_Null) {}
978
979 MachineState_T mLastState;
980
981 // used when taking snapshot
982 ComObjPtr<Snapshot> mSnapshot;
983
984 // used when saving state
985 Guid mProgressId;
986 Utf8Str mStateFilePath;
987 };
988
989 struct Uninit
990 {
991 enum Reason { Unexpected, Abnormal, Normal };
992 };
993
994 struct SnapshotTask;
995 struct DeleteSnapshotTask;
996 struct RestoreSnapshotTask;
997
998 friend struct DeleteSnapshotTask;
999 friend struct RestoreSnapshotTask;
1000
1001 void uninit(Uninit::Reason aReason);
1002
1003 HRESULT endSavingState(BOOL aSuccess);
1004
1005 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1006 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1007
1008 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1009 const Guid &machineId,
1010 const Guid &snapshotId,
1011 bool fOnlineMergePossible,
1012 MediumLockList *aVMMALockList,
1013 ComObjPtr<Medium> &aSource,
1014 ComObjPtr<Medium> &aTarget,
1015 bool &fMergeForward,
1016 ComObjPtr<Medium> &pParentForTarget,
1017 MediaList &aChildrenToReparent,
1018 bool &fNeedOnlineMerge,
1019 MediumLockList * &aMediumLockList);
1020 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1021 const ComObjPtr<Medium> &aSource,
1022 const MediaList &aChildrenToReparent,
1023 bool fNeedsOnlineMerge,
1024 MediumLockList *aMediumLockList,
1025 const Guid &aMediumId,
1026 const Guid &aSnapshotId);
1027 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1028 const ComObjPtr<Medium> &aSource,
1029 const ComObjPtr<Medium> &aTarget,
1030 bool fMergeForward,
1031 const ComObjPtr<Medium> &pParentForTarget,
1032 const MediaList &aChildrenToReparent,
1033 MediumLockList *aMediumLockList,
1034 ComObjPtr<Progress> &aProgress,
1035 bool *pfNeedsMachineSaveSettings);
1036
1037 HRESULT lockMedia();
1038 void unlockMedia();
1039
1040 HRESULT setMachineState(MachineState_T aMachineState);
1041 HRESULT updateMachineStateOnClient();
1042
1043 HRESULT mRemoveSavedState;
1044
1045 SnapshotData mSnapshotData;
1046
1047 /** interprocess semaphore handle for this machine */
1048#if defined(RT_OS_WINDOWS)
1049 HANDLE mIPCSem;
1050 Bstr mIPCSemName;
1051 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1052 ComPtr<IInternalSessionControl> *aControl,
1053 HANDLE *aIPCSem, bool aAllowClosing);
1054#elif defined(RT_OS_OS2)
1055 HMTX mIPCSem;
1056 Bstr mIPCSemName;
1057 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1058 ComPtr<IInternalSessionControl> *aControl,
1059 HMTX *aIPCSem, bool aAllowClosing);
1060#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1061 int mIPCSem;
1062# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1063 Bstr mIPCKey;
1064# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1065#else
1066# error "Port me!"
1067#endif
1068
1069 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1070};
1071
1072// SnapshotMachine class
1073////////////////////////////////////////////////////////////////////////////////
1074
1075/**
1076 * @note Notes on locking objects of this class:
1077 * SnapshotMachine shares some data with the primary Machine instance (pointed
1078 * to by the |mPeer| member). In order to provide data consistency it also
1079 * shares its lock handle. This means that whenever you lock a SessionMachine
1080 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1081 * instance is also locked in the same lock mode. Keep it in mind.
1082 */
1083class ATL_NO_VTABLE SnapshotMachine :
1084 public Machine
1085{
1086public:
1087 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1088
1089 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1090
1091 DECLARE_PROTECT_FINAL_CONSTRUCT()
1092
1093 BEGIN_COM_MAP(SnapshotMachine)
1094 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1095 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1096 COM_INTERFACE_ENTRY(IMachine)
1097 END_COM_MAP()
1098
1099 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1100
1101 HRESULT FinalConstruct();
1102 void FinalRelease();
1103
1104 // public initializer/uninitializer for internal purposes only
1105 HRESULT init(SessionMachine *aSessionMachine,
1106 IN_GUID aSnapshotId,
1107 const Utf8Str &aStateFilePath);
1108 HRESULT init(Machine *aMachine,
1109 const settings::Hardware &hardware,
1110 const settings::Storage &storage,
1111 IN_GUID aSnapshotId,
1112 const Utf8Str &aStateFilePath);
1113 void uninit();
1114
1115 // util::Lockable interface
1116 RWLockHandle *lockHandle() const;
1117
1118 // public methods only for internal purposes
1119
1120 virtual bool isSnapshotMachine() const
1121 {
1122 return true;
1123 }
1124
1125 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1126
1127 // unsafe inline public methods for internal purposes only (ensure there is
1128 // a caller and a read lock before calling them!)
1129
1130 const Guid& getSnapshotId() const { return mSnapshotId; }
1131
1132private:
1133
1134 Guid mSnapshotId;
1135
1136 friend class Snapshot;
1137};
1138
1139// third party methods that depend on SnapshotMachine definition
1140
1141inline const Guid &Machine::getSnapshotId() const
1142{
1143 return (isSnapshotMachine())
1144 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1145 : Guid::Empty;
1146}
1147
1148
1149#endif // ____H_MACHINEIMPL
1150/* 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