VirtualBox

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

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

Main: change VirtualBox::createMachine() to accept arbitrary paths for the XML settings file; remove the override parameter

  • 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 33451 2010-10-26 09:34:19Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "VRDPServerImpl.h"
24#include "MediumAttachmentImpl.h"
25#include "MediumLock.h"
26#include "NetworkAdapterImpl.h"
27#include "AudioAdapterImpl.h"
28#include "SerialPortImpl.h"
29#include "ParallelPortImpl.h"
30#include "BIOSSettingsImpl.h"
31#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
32#include "VBox/settings.h"
33#ifdef VBOX_WITH_RESOURCE_USAGE_API
34#include "Performance.h"
35#include "PerformanceImpl.h"
36#endif /* VBOX_WITH_RESOURCE_USAGE_API */
37
38// generated header
39#include "SchemaDefs.h"
40
41#include "VBox/com/ErrorInfo.h"
42
43#include <iprt/file.h>
44#include <iprt/thread.h>
45#include <iprt/time.h>
46
47#include <list>
48
49// defines
50////////////////////////////////////////////////////////////////////////////////
51
52// helper declarations
53////////////////////////////////////////////////////////////////////////////////
54
55class Progress;
56class ProgressProxy;
57class Keyboard;
58class Mouse;
59class Display;
60class MachineDebugger;
61class USBController;
62class Snapshot;
63class SharedFolder;
64class HostUSBDevice;
65class StorageController;
66
67class SessionMachine;
68
69namespace settings
70{
71 class MachineConfigFile;
72 struct Snapshot;
73 struct Hardware;
74 struct Storage;
75 struct StorageController;
76 struct MachineRegistryEntry;
77}
78
79// Machine class
80////////////////////////////////////////////////////////////////////////////////
81
82class ATL_NO_VTABLE Machine :
83 public VirtualBoxBaseWithChildrenNEXT,
84 VBOX_SCRIPTABLE_IMPL(IMachine)
85{
86 Q_OBJECT
87
88public:
89
90 enum StateDependency
91 {
92 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
93 };
94
95 /**
96 * Internal machine data.
97 *
98 * Only one instance of this data exists per every machine -- it is shared
99 * by the Machine, SessionMachine and all SnapshotMachine instances
100 * associated with the given machine using the util::Shareable template
101 * through the mData variable.
102 *
103 * @note |const| members are persistent during lifetime so can be
104 * accessed without locking.
105 *
106 * @note There is no need to lock anything inside init() or uninit()
107 * methods, because they are always serialized (see AutoCaller).
108 */
109 struct Data
110 {
111 /**
112 * Data structure to hold information about sessions opened for the
113 * given machine.
114 */
115 struct Session
116 {
117 /** Control of the direct session opened by lockMachine() */
118 ComPtr<IInternalSessionControl> mDirectControl;
119
120 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
121
122 /** list of controls of all opened remote sessions */
123 RemoteControlList mRemoteControls;
124
125 /** openRemoteSession() and OnSessionEnd() progress indicator */
126 ComObjPtr<ProgressProxy> mProgress;
127
128 /**
129 * PID of the session object that must be passed to openSession() to
130 * finalize the openRemoteSession() request (i.e., PID of the
131 * process created by openRemoteSession())
132 */
133 RTPROCESS mPid;
134
135 /** Current session state */
136 SessionState_T mState;
137
138 /** Session type string (for indirect sessions) */
139 Bstr mType;
140
141 /** Session machine object */
142 ComObjPtr<SessionMachine> mMachine;
143
144 /** Medium object lock collection. */
145 MediumLockListMap mLockedMedia;
146 };
147
148 Data();
149 ~Data();
150
151 const Guid mUuid;
152 BOOL mRegistered;
153
154 Utf8Str m_strConfigFile;
155 Utf8Str m_strConfigFileFull;
156
157 // machine settings XML file
158 settings::MachineConfigFile *pMachineConfigFile;
159 uint32_t flModifications;
160
161 BOOL mAccessible;
162 com::ErrorInfo mAccessError;
163
164 MachineState_T mMachineState;
165 RTTIMESPEC mLastStateChange;
166
167 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
168 uint32_t mMachineStateDeps;
169 RTSEMEVENTMULTI mMachineStateDepsSem;
170 uint32_t mMachineStateChangePending;
171
172 BOOL mCurrentStateModified;
173 /** Guest properties have been modified and need saving since the
174 * machine was started, or there are transient properties which need
175 * deleting and the machine is being shut down. */
176 BOOL mGuestPropertiesModified;
177
178 Session mSession;
179
180 ComObjPtr<Snapshot> mFirstSnapshot;
181 ComObjPtr<Snapshot> mCurrentSnapshot;
182
183 // list of files to delete in Delete(); this list is filled by Unregister()
184 std::list<Utf8Str> llFilesToDelete;
185 };
186
187 /**
188 * Saved state data.
189 *
190 * It's actually only the state file path string, but it needs to be
191 * separate from Data, because Machine and SessionMachine instances
192 * share it, while SnapshotMachine does not.
193 *
194 * The data variable is |mSSData|.
195 */
196 struct SSData
197 {
198 Utf8Str mStateFilePath;
199 };
200
201 /**
202 * User changeable machine data.
203 *
204 * This data is common for all machine snapshots, i.e. it is shared
205 * by all SnapshotMachine instances associated with the given machine
206 * using the util::Backupable template through the |mUserData| variable.
207 *
208 * SessionMachine instances can alter this data and discard changes.
209 *
210 * @note There is no need to lock anything inside init() or uninit()
211 * methods, because they are always serialized (see AutoCaller).
212 */
213 struct UserData
214 {
215 settings::MachineUserData s;
216 Utf8Str m_strSnapshotFolderFull;
217 };
218
219 /**
220 * Hardware data.
221 *
222 * This data is unique for a machine and for every machine snapshot.
223 * Stored using the util::Backupable template in the |mHWData| variable.
224 *
225 * SessionMachine instances can alter this data and discard changes.
226 */
227 struct HWData
228 {
229 /**
230 * Data structure to hold information about a guest property.
231 */
232 struct GuestProperty {
233 /** Property name */
234 Utf8Str strName;
235 /** Property value */
236 Utf8Str strValue;
237 /** Property timestamp */
238 LONG64 mTimestamp;
239 /** Property flags */
240 ULONG mFlags;
241 };
242
243 HWData();
244 ~HWData();
245
246 Bstr mHWVersion;
247 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
248 ULONG mMemorySize;
249 ULONG mMemoryBalloonSize;
250 BOOL mPageFusionEnabled;
251 ULONG mVRAMSize;
252 ULONG mMonitorCount;
253 BOOL mHWVirtExEnabled;
254 BOOL mHWVirtExExclusive;
255 BOOL mHWVirtExNestedPagingEnabled;
256 BOOL mHWVirtExLargePagesEnabled;
257 BOOL mHWVirtExVPIDEnabled;
258 BOOL mHWVirtExForceEnabled;
259 BOOL mAccelerate2DVideoEnabled;
260 BOOL mPAEEnabled;
261 BOOL mSyntheticCpu;
262 ULONG mCPUCount;
263 BOOL mCPUHotPlugEnabled;
264 ULONG mCpuExecutionCap;
265 BOOL mAccelerate3DEnabled;
266 BOOL mHpetEnabled;
267
268 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
269
270 settings::CpuIdLeaf mCpuIdStdLeafs[10];
271 settings::CpuIdLeaf mCpuIdExtLeafs[10];
272
273 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
274
275 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
276 SharedFolderList mSharedFolders;
277
278 ClipboardMode_T mClipboardMode;
279
280 typedef std::list<GuestProperty> GuestPropertyList;
281 GuestPropertyList mGuestProperties;
282 Utf8Str mGuestPropertyNotificationPatterns;
283
284 FirmwareType_T mFirmwareType;
285 KeyboardHidType_T mKeyboardHidType;
286 PointingHidType_T mPointingHidType;
287 ChipsetType_T mChipsetType;
288
289 BOOL mIoCacheEnabled;
290 ULONG mIoCacheSize;
291 };
292
293 /**
294 * Hard disk and other media data.
295 *
296 * The usage policy is the same as for HWData, but a separate structure
297 * is necessary because hard disk data requires different procedures when
298 * taking or deleting snapshots, etc.
299 *
300 * The data variable is |mMediaData|.
301 */
302 struct MediaData
303 {
304 MediaData();
305 ~MediaData();
306
307 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
308 AttachmentList mAttachments;
309 };
310
311 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
312
313 DECLARE_NOT_AGGREGATABLE(Machine)
314
315 DECLARE_PROTECT_FINAL_CONSTRUCT()
316
317 BEGIN_COM_MAP(Machine)
318 COM_INTERFACE_ENTRY(ISupportErrorInfo)
319 COM_INTERFACE_ENTRY(IMachine)
320 COM_INTERFACE_ENTRY(IDispatch)
321 END_COM_MAP()
322
323 DECLARE_EMPTY_CTOR_DTOR(Machine)
324
325 HRESULT FinalConstruct();
326 void FinalRelease();
327
328 // public initializer/uninitializer for internal purposes only:
329
330 // initializer for creating a new, empty machine
331 HRESULT init(VirtualBox *aParent,
332 const Utf8Str &strConfigFile,
333 const Utf8Str &strName,
334 const Guid &aId,
335 GuestOSType *aOsType = NULL);
336
337 // initializer for loading existing machine XML (either registered or not)
338 HRESULT init(VirtualBox *aParent,
339 const Utf8Str &strConfigFile,
340 const Guid *aId);
341
342 // initializer for machine config in memory (OVF import)
343 HRESULT init(VirtualBox *aParent,
344 const Utf8Str &strName,
345 const settings::MachineConfigFile &config);
346
347 void uninit();
348
349#ifdef VBOX_WITH_RESOURCE_USAGE_API
350 // Needed from VirtualBox, for the delayed metrics cleanup.
351 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
352#endif /* VBOX_WITH_RESOURCE_USAGE_API */
353
354protected:
355 HRESULT initImpl(VirtualBox *aParent,
356 const Utf8Str &strConfigFile);
357 HRESULT initDataAndChildObjects();
358 HRESULT registeredInit();
359 HRESULT tryCreateMachineConfigFile();
360 void uninitDataAndChildObjects();
361
362public:
363 // IMachine properties
364 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
365 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
366 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
367 STDMETHOD(COMGETTER(Name))(BSTR *aName);
368 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
369 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
370 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
371 STDMETHOD(COMGETTER(Id))(BSTR *aId);
372 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
373 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
374 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
375 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
376 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
377 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
378 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
379 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
380 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
381 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
382 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
383 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
384 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
385 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
386 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
387 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
388 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
389 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
390 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
391 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
392 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
393 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
394 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
395 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
396 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
397 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
398 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
399 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
400 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
401 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
402 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
403 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
404 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
405 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
406 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
407 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
408 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
409 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
410 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
411 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
412 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
413 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
414 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
415 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
416 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
417 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
418 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
419 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
420 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
421 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
422 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
423 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
424 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
425 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
426 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
427 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
428 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
429 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
430 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
431 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
432 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
433 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
434 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
435 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
436 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
437 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
438 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
439 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
440 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
441 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
442 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
443 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
444 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
445 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
446 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
447 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
448 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
449 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
450 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
451 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
452 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
453 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
454 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
455 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
456 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
457
458 // IMachine methods
459 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
460 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
461
462 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
463 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
464 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
465 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
466 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
467 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
468 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
469 LONG aDevice, IMedium *aMedium, BOOL aForce);
470 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
471 IMedium **aMedium);
472 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
473 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
474 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
475 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
476 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
477 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
478 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
479 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
480 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
481 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
482 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
483 STDMETHOD(RemoveAllCPUIDLeaves)();
484 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
485 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
486 STDMETHOD(SaveSettings)();
487 STDMETHOD(DiscardSettings)();
488 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
489 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
490 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
491 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
492 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
493 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
494 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
495 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
496 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
497 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
498 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
499 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
500 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
501 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
502 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
503 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
504 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
505 STDMETHOD(RemoveStorageController(IN_BSTR aName));
506 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
507 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
508 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
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(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
512 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
513 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
514 STDMETHOD(HotPlugCPU(ULONG aCpu));
515 STDMETHOD(HotUnplugCPU(ULONG aCpu));
516 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
517 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
518 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
519
520 // public methods only for internal purposes
521
522 virtual bool isSnapshotMachine() const
523 {
524 return false;
525 }
526
527 virtual bool isSessionMachine() const
528 {
529 return false;
530 }
531
532 /**
533 * Override of the default locking class to be used for validating lock
534 * order with the standard member lock handle.
535 */
536 virtual VBoxLockingClass getLockingClass() const
537 {
538 return LOCKCLASS_MACHINEOBJECT;
539 }
540
541 /// @todo (dmik) add lock and make non-inlined after revising classes
542 // that use it. Note: they should enter Machine lock to keep the returned
543 // information valid!
544 bool isRegistered() { return !!mData->mRegistered; }
545
546 // unsafe inline public methods for internal purposes only (ensure there is
547 // a caller and a read lock before calling them!)
548
549 /**
550 * Returns the VirtualBox object this machine belongs to.
551 *
552 * @note This method doesn't check this object's readiness. Intended to be
553 * used by ready Machine children (whose readiness is bound to the parent's
554 * one) or after doing addCaller() manually.
555 */
556 VirtualBox* getVirtualBox() const { return mParent; }
557
558 /**
559 * Returns this machine ID.
560 *
561 * @note This method doesn't check this object's readiness. Intended to be
562 * used by ready Machine children (whose readiness is bound to the parent's
563 * one) or after adding a caller manually.
564 */
565 const Guid& getId() const { return mData->mUuid; }
566
567 /**
568 * Returns the snapshot ID this machine represents or an empty UUID if this
569 * instance is not SnapshotMachine.
570 *
571 * @note This method doesn't check this object's readiness. Intended to be
572 * used by ready Machine children (whose readiness is bound to the parent's
573 * one) or after adding a caller manually.
574 */
575 inline const Guid& getSnapshotId() const;
576
577 /**
578 * Returns this machine's full settings file path.
579 *
580 * @note This method doesn't lock this object or check its readiness.
581 * Intended to be used only after doing addCaller() manually and locking it
582 * for reading.
583 */
584 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
585
586 /**
587 * Returns this machine name.
588 *
589 * @note This method doesn't lock this object or check its readiness.
590 * Intended to be used only after doing addCaller() manually and locking it
591 * for reading.
592 */
593 const Utf8Str& getName() const { return mUserData->s.strName; }
594
595 enum
596 {
597 IsModified_MachineData = 0x0001,
598 IsModified_Storage = 0x0002,
599 IsModified_NetworkAdapters = 0x0008,
600 IsModified_SerialPorts = 0x0010,
601 IsModified_ParallelPorts = 0x0020,
602 IsModified_VRDEServer = 0x0040,
603 IsModified_AudioAdapter = 0x0080,
604 IsModified_USB = 0x0100,
605 IsModified_BIOS = 0x0200,
606 IsModified_SharedFolders = 0x0400,
607 IsModified_Snapshots = 0x0800
608 };
609
610 void setModified(uint32_t fl);
611
612 // callback handlers
613 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
614 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
615 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
616 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
617 virtual HRESULT onUSBControllerChange() { return S_OK; }
618 virtual HRESULT onStorageControllerChange() { return S_OK; }
619 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
620 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
621 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
622 virtual HRESULT onSharedFolderChange() { return S_OK; }
623
624 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
625
626 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
627 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
628
629 void getLogFolder(Utf8Str &aLogFolder);
630 Utf8Str queryLogFilename(ULONG idx);
631
632 HRESULT openRemoteSession(IInternalSessionControl *aControl,
633 IN_BSTR aType, IN_BSTR aEnvironment,
634 ProgressProxy *aProgress);
635
636 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
637 {
638 HRESULT rc;
639 *directControl = mData->mSession.mDirectControl;
640
641 if (!*directControl)
642 rc = E_ACCESSDENIED;
643 else
644 rc = S_OK;
645
646 return rc;
647 }
648
649#if defined(RT_OS_WINDOWS)
650
651 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
652 ComPtr<IInternalSessionControl> *aControl = NULL,
653 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
654 bool isSessionSpawning(RTPROCESS *aPID = NULL);
655
656 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
657 ComPtr<IInternalSessionControl> *aControl = NULL,
658 HANDLE *aIPCSem = NULL)
659 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
660
661#elif defined(RT_OS_OS2)
662
663 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
664 ComPtr<IInternalSessionControl> *aControl = NULL,
665 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
666
667 bool isSessionSpawning(RTPROCESS *aPID = NULL);
668
669 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
670 ComPtr<IInternalSessionControl> *aControl = NULL,
671 HMTX *aIPCSem = NULL)
672 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
673
674#else
675
676 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
677 ComPtr<IInternalSessionControl> *aControl = NULL,
678 bool aAllowClosing = false);
679 bool isSessionSpawning();
680
681 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
682 ComPtr<IInternalSessionControl> *aControl = NULL)
683 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
684
685#endif
686
687 bool checkForSpawnFailure();
688
689 HRESULT prepareRegister();
690
691 HRESULT getSharedFolder(CBSTR aName,
692 ComObjPtr<SharedFolder> &aSharedFolder,
693 bool aSetError = false)
694 {
695 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
696 return findSharedFolder(aName, aSharedFolder, aSetError);
697 }
698
699 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
700 MachineState_T *aState = NULL,
701 BOOL *aRegistered = NULL);
702 void releaseStateDependency();
703
704protected:
705
706 HRESULT checkStateDependency(StateDependency aDepType);
707
708 Machine *getMachine();
709
710 void ensureNoStateDependencies();
711
712 virtual HRESULT setMachineState(MachineState_T aMachineState);
713
714 HRESULT findSharedFolder(CBSTR aName,
715 ComObjPtr<SharedFolder> &aSharedFolder,
716 bool aSetError = false);
717
718 HRESULT loadSettings(bool aRegistered);
719 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
720 const Guid *puuidRegistry);
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 *puuidRegistry,
727 const Guid *puuidSnapshot);
728 HRESULT loadStorageDevices(StorageController *aStorageController,
729 const settings::StorageController &data,
730 const Guid *puuidRegistry,
731 const Guid *puuidSnapshot);
732
733 HRESULT findSnapshotById(const Guid &aId,
734 ComObjPtr<Snapshot> &aSnapshot,
735 bool aSetError = false);
736 HRESULT findSnapshotByName(const Utf8Str &strName,
737 ComObjPtr<Snapshot> &aSnapshot,
738 bool aSetError = false);
739
740 HRESULT getStorageControllerByName(const Utf8Str &aName,
741 ComObjPtr<StorageController> &aStorageController,
742 bool aSetError = false);
743
744 HRESULT getMediumAttachmentsOfController(CBSTR aName,
745 MediaData::AttachmentList &aAttachments);
746
747 enum
748 {
749 /* flags for #saveSettings() */
750 SaveS_ResetCurStateModified = 0x01,
751 SaveS_InformCallbacksAnyway = 0x02,
752 SaveS_Force = 0x04,
753 /* flags for #saveStateSettings() */
754 SaveSTS_CurStateModified = 0x20,
755 SaveSTS_StateFilePath = 0x40,
756 SaveSTS_StateTimeStamp = 0x80
757 };
758
759 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
760 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
761
762 void copyMachineDataToSettings(settings::MachineConfigFile &config);
763 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
764 HRESULT saveHardware(settings::Hardware &data);
765 HRESULT saveStorageControllers(settings::Storage &data);
766 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
767 settings::StorageController &data);
768 HRESULT saveStateSettings(int aFlags);
769
770 HRESULT createImplicitDiffs(IProgress *aProgress,
771 ULONG aWeight,
772 bool aOnline,
773 bool *pfNeedsSaveSettings);
774 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
775
776 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
777 IN_BSTR aControllerName,
778 LONG aControllerPort,
779 LONG aDevice);
780 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
781 ComObjPtr<Medium> pMedium);
782 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
783 Guid &id);
784
785 HRESULT detachDevice(MediumAttachment *pAttach,
786 AutoWriteLock &writeLock,
787 Snapshot *pSnapshot,
788 bool *pfNeedsSaveSettings);
789 HRESULT detachAllMedia(AutoWriteLock &writeLock,
790 Snapshot *pSnapshot,
791 CleanupMode_T cleanupMode,
792 MediaList &llMedia);
793
794 void commitMedia(bool aOnline = false);
795 void rollbackMedia();
796
797 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
798
799 void rollback(bool aNotify);
800 void commit();
801 void copyFrom(Machine *aThat);
802
803 struct DeleteTask;
804 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
805 HRESULT deleteTaskWorker(DeleteTask &task);
806
807#ifdef VBOX_WITH_GUEST_PROPS
808 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
809 LONG64 *aTimestamp, BSTR *aFlags) const;
810 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
811 LONG64 *aTimestamp, BSTR *aFlags) const;
812 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
813 IN_BSTR aFlags);
814 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
815 IN_BSTR aFlags);
816 HRESULT enumerateGuestPropertiesInService
817 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
818 ComSafeArrayOut(BSTR, aValues),
819 ComSafeArrayOut(LONG64, aTimestamps),
820 ComSafeArrayOut(BSTR, aFlags));
821 HRESULT enumerateGuestPropertiesOnVM
822 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
823 ComSafeArrayOut(BSTR, aValues),
824 ComSafeArrayOut(LONG64, aTimestamps),
825 ComSafeArrayOut(BSTR, aFlags));
826#endif /* VBOX_WITH_GUEST_PROPS */
827
828#ifdef VBOX_WITH_RESOURCE_USAGE_API
829 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
830
831 pm::CollectorGuestHAL *mGuestHAL;
832#endif /* VBOX_WITH_RESOURCE_USAGE_API */
833
834 Machine* const mPeer;
835
836 VirtualBox * const mParent;
837
838 Shareable<Data> mData;
839 Shareable<SSData> mSSData;
840
841 Backupable<UserData> mUserData;
842 Backupable<HWData> mHWData;
843 Backupable<MediaData> mMediaData;
844
845 // the following fields need special backup/rollback/commit handling,
846 // so they cannot be a part of HWData
847
848 const ComObjPtr<VRDEServer> mVRDEServer;
849 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
850 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
851 const ComObjPtr<AudioAdapter> mAudioAdapter;
852 const ComObjPtr<USBController> mUSBController;
853 const ComObjPtr<BIOSSettings> mBIOSSettings;
854 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
855
856 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
857 Backupable<StorageControllerList> mStorageControllers;
858
859 friend class SessionMachine;
860 friend class SnapshotMachine;
861 friend class Appliance;
862};
863
864// SessionMachine class
865////////////////////////////////////////////////////////////////////////////////
866
867/**
868 * @note Notes on locking objects of this class:
869 * SessionMachine shares some data with the primary Machine instance (pointed
870 * to by the |mPeer| member). In order to provide data consistency it also
871 * shares its lock handle. This means that whenever you lock a SessionMachine
872 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
873 * instance is also locked in the same lock mode. Keep it in mind.
874 */
875class ATL_NO_VTABLE SessionMachine :
876 public Machine,
877 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
878{
879public:
880 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
881
882 DECLARE_NOT_AGGREGATABLE(SessionMachine)
883
884 DECLARE_PROTECT_FINAL_CONSTRUCT()
885
886 BEGIN_COM_MAP(SessionMachine)
887 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
888 COM_INTERFACE_ENTRY(ISupportErrorInfo)
889 COM_INTERFACE_ENTRY(IMachine)
890 COM_INTERFACE_ENTRY(IInternalMachineControl)
891 END_COM_MAP()
892
893 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
894
895 HRESULT FinalConstruct();
896 void FinalRelease();
897
898 // public initializer/uninitializer for internal purposes only
899 HRESULT init(Machine *aMachine);
900 void uninit() { uninit(Uninit::Unexpected); }
901
902 // util::Lockable interface
903 RWLockHandle *lockHandle() const;
904
905 // IInternalMachineControl methods
906 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
907 STDMETHOD(UpdateState)(MachineState_T machineState);
908 STDMETHOD(GetIPCId)(BSTR *id);
909 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
910 STDMETHOD(EndPowerUp)(LONG iResult);
911 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
912 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
913 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
914 STDMETHOD(AutoCaptureUSBDevices)();
915 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
916 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
917 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
918 STDMETHOD(EndSavingState)(BOOL aSuccess);
919 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
920 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
921 IN_BSTR aName,
922 IN_BSTR aDescription,
923 IProgress *aConsoleProgress,
924 BOOL fTakingSnapshotOnline,
925 BSTR *aStateFilePath);
926 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
927 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
928 MachineState_T *aMachineState, IProgress **aProgress);
929 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
930 IMedium *aSource, IMedium *aTarget,
931 BOOL fMergeForward,
932 IMedium *pParentForTarget,
933 ComSafeArrayIn(IMedium *, aChildrenToReparent));
934 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
935 ISnapshot *aSnapshot,
936 MachineState_T *aMachineState,
937 IProgress **aProgress);
938 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
939 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
940 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
941 LONG64 aTimestamp, IN_BSTR aFlags);
942 STDMETHOD(LockMedia)() { return lockMedia(); }
943 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
944
945 // public methods only for internal purposes
946
947 virtual bool isSessionMachine() const
948 {
949 return true;
950 }
951
952 bool checkForDeath();
953
954 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
955 HRESULT onStorageControllerChange();
956 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
957 HRESULT onSerialPortChange(ISerialPort *serialPort);
958 HRESULT onParallelPortChange(IParallelPort *parallelPort);
959 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
960 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
961 HRESULT onVRDEServerChange(BOOL aRestart);
962 HRESULT onUSBControllerChange();
963 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
964 IVirtualBoxErrorInfo *aError,
965 ULONG aMaskedIfs);
966 HRESULT onUSBDeviceDetach(IN_BSTR aId,
967 IVirtualBoxErrorInfo *aError);
968 HRESULT onSharedFolderChange();
969
970 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
971
972private:
973
974 struct SnapshotData
975 {
976 SnapshotData() : mLastState(MachineState_Null) {}
977
978 MachineState_T mLastState;
979
980 // used when taking snapshot
981 ComObjPtr<Snapshot> mSnapshot;
982
983 // used when saving state
984 Guid mProgressId;
985 Utf8Str mStateFilePath;
986 };
987
988 struct Uninit
989 {
990 enum Reason { Unexpected, Abnormal, Normal };
991 };
992
993 struct SnapshotTask;
994 struct DeleteSnapshotTask;
995 struct RestoreSnapshotTask;
996
997 friend struct DeleteSnapshotTask;
998 friend struct RestoreSnapshotTask;
999
1000 void uninit(Uninit::Reason aReason);
1001
1002 HRESULT endSavingState(BOOL aSuccess);
1003
1004 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1005 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1006
1007 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1008 const Guid &machineId,
1009 const Guid &snapshotId,
1010 bool fOnlineMergePossible,
1011 MediumLockList *aVMMALockList,
1012 ComObjPtr<Medium> &aSource,
1013 ComObjPtr<Medium> &aTarget,
1014 bool &fMergeForward,
1015 ComObjPtr<Medium> &pParentForTarget,
1016 MediaList &aChildrenToReparent,
1017 bool &fNeedOnlineMerge,
1018 MediumLockList * &aMediumLockList);
1019 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1020 const ComObjPtr<Medium> &aSource,
1021 const MediaList &aChildrenToReparent,
1022 bool fNeedsOnlineMerge,
1023 MediumLockList *aMediumLockList,
1024 const Guid &aMediumId,
1025 const Guid &aSnapshotId);
1026 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1027 const ComObjPtr<Medium> &aSource,
1028 const ComObjPtr<Medium> &aTarget,
1029 bool fMergeForward,
1030 const ComObjPtr<Medium> &pParentForTarget,
1031 const MediaList &aChildrenToReparent,
1032 MediumLockList *aMediumLockList,
1033 ComObjPtr<Progress> &aProgress,
1034 bool *pfNeedsMachineSaveSettings);
1035
1036 HRESULT lockMedia();
1037 void unlockMedia();
1038
1039 HRESULT setMachineState(MachineState_T aMachineState);
1040 HRESULT updateMachineStateOnClient();
1041
1042 HRESULT mRemoveSavedState;
1043
1044 SnapshotData mSnapshotData;
1045
1046 /** interprocess semaphore handle for this machine */
1047#if defined(RT_OS_WINDOWS)
1048 HANDLE mIPCSem;
1049 Bstr mIPCSemName;
1050 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1051 ComPtr<IInternalSessionControl> *aControl,
1052 HANDLE *aIPCSem, bool aAllowClosing);
1053#elif defined(RT_OS_OS2)
1054 HMTX mIPCSem;
1055 Bstr mIPCSemName;
1056 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1057 ComPtr<IInternalSessionControl> *aControl,
1058 HMTX *aIPCSem, bool aAllowClosing);
1059#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1060 int mIPCSem;
1061# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1062 Bstr mIPCKey;
1063# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1064#else
1065# error "Port me!"
1066#endif
1067
1068 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1069};
1070
1071// SnapshotMachine class
1072////////////////////////////////////////////////////////////////////////////////
1073
1074/**
1075 * @note Notes on locking objects of this class:
1076 * SnapshotMachine shares some data with the primary Machine instance (pointed
1077 * to by the |mPeer| member). In order to provide data consistency it also
1078 * shares its lock handle. This means that whenever you lock a SessionMachine
1079 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1080 * instance is also locked in the same lock mode. Keep it in mind.
1081 */
1082class ATL_NO_VTABLE SnapshotMachine :
1083 public Machine
1084{
1085public:
1086 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1087
1088 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1089
1090 DECLARE_PROTECT_FINAL_CONSTRUCT()
1091
1092 BEGIN_COM_MAP(SnapshotMachine)
1093 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1094 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1095 COM_INTERFACE_ENTRY(IMachine)
1096 END_COM_MAP()
1097
1098 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1099
1100 HRESULT FinalConstruct();
1101 void FinalRelease();
1102
1103 // public initializer/uninitializer for internal purposes only
1104 HRESULT init(SessionMachine *aSessionMachine,
1105 IN_GUID aSnapshotId,
1106 const Utf8Str &aStateFilePath);
1107 HRESULT init(Machine *aMachine,
1108 const settings::Hardware &hardware,
1109 const settings::Storage &storage,
1110 IN_GUID aSnapshotId,
1111 const Utf8Str &aStateFilePath);
1112 void uninit();
1113
1114 // util::Lockable interface
1115 RWLockHandle *lockHandle() const;
1116
1117 // public methods only for internal purposes
1118
1119 virtual bool isSnapshotMachine() const
1120 {
1121 return true;
1122 }
1123
1124 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1125
1126 // unsafe inline public methods for internal purposes only (ensure there is
1127 // a caller and a read lock before calling them!)
1128
1129 const Guid& getSnapshotId() const { return mSnapshotId; }
1130
1131private:
1132
1133 Guid mSnapshotId;
1134
1135 friend class Snapshot;
1136};
1137
1138// third party methods that depend on SnapshotMachine definiton
1139
1140inline const Guid &Machine::getSnapshotId() const
1141{
1142 return (isSnapshotMachine())
1143 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1144 : Guid::Empty;
1145}
1146
1147
1148#endif // ____H_MACHINEIMPL
1149/* 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