VirtualBox

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

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

Main: thumbnail PNG API, refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.5 KB
Line 
1/* $Id: MachineImpl.h 31958 2010-08-25 13:28:44Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "VRDPServerImpl.h"
24#include "MediumAttachmentImpl.h"
25#include "MediumLock.h"
26#include "NetworkAdapterImpl.h"
27#include "AudioAdapterImpl.h"
28#include "SerialPortImpl.h"
29#include "ParallelPortImpl.h"
30#include "BIOSSettingsImpl.h"
31#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
32#include "VBox/settings.h"
33#ifdef VBOX_WITH_RESOURCE_USAGE_API
34#include "Performance.h"
35#include "PerformanceImpl.h"
36#endif /* VBOX_WITH_RESOURCE_USAGE_API */
37
38// generated header
39#include "SchemaDefs.h"
40
41#include "VBox/com/ErrorInfo.h"
42
43#include <iprt/file.h>
44#include <iprt/thread.h>
45#include <iprt/time.h>
46
47#include <list>
48
49// defines
50////////////////////////////////////////////////////////////////////////////////
51
52// helper declarations
53////////////////////////////////////////////////////////////////////////////////
54
55class Progress;
56class ProgressProxy;
57class Keyboard;
58class Mouse;
59class Display;
60class MachineDebugger;
61class USBController;
62class Snapshot;
63class SharedFolder;
64class HostUSBDevice;
65class StorageController;
66
67class SessionMachine;
68
69namespace settings
70{
71 class MachineConfigFile;
72 struct Snapshot;
73 struct Hardware;
74 struct Storage;
75 struct StorageController;
76 struct MachineRegistryEntry;
77}
78
79// Machine class
80////////////////////////////////////////////////////////////////////////////////
81
82class ATL_NO_VTABLE Machine :
83 public VirtualBoxBaseWithChildrenNEXT,
84 VBOX_SCRIPTABLE_IMPL(IMachine)
85{
86 Q_OBJECT
87
88public:
89
90 enum StateDependency
91 {
92 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
93 };
94
95 /**
96 * Internal machine data.
97 *
98 * Only one instance of this data exists per every machine -- it is shared
99 * by the Machine, SessionMachine and all SnapshotMachine instances
100 * associated with the given machine using the util::Shareable template
101 * through the mData variable.
102 *
103 * @note |const| members are persistent during lifetime so can be
104 * accessed without locking.
105 *
106 * @note There is no need to lock anything inside init() or uninit()
107 * methods, because they are always serialized (see AutoCaller).
108 */
109 struct Data
110 {
111 /**
112 * Data structure to hold information about sessions opened for the
113 * given machine.
114 */
115 struct Session
116 {
117 /** Control of the direct session opened by lockMachine() */
118 ComPtr<IInternalSessionControl> mDirectControl;
119
120 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
121
122 /** list of controls of all opened remote sessions */
123 RemoteControlList mRemoteControls;
124
125 /** openRemoteSession() and OnSessionEnd() progress indicator */
126 ComObjPtr<ProgressProxy> mProgress;
127
128 /**
129 * PID of the session object that must be passed to openSession() to
130 * finalize the openRemoteSession() request (i.e., PID of the
131 * process created by openRemoteSession())
132 */
133 RTPROCESS mPid;
134
135 /** Current session state */
136 SessionState_T mState;
137
138 /** Session type string (for indirect sessions) */
139 Bstr mType;
140
141 /** Session machine object */
142 ComObjPtr<SessionMachine> mMachine;
143
144 /** Medium object lock collection. */
145 MediumLockListMap mLockedMedia;
146 };
147
148 Data();
149 ~Data();
150
151 const Guid mUuid;
152 BOOL mRegistered;
153
154 /** Flag indicating that the config file is read-only. */
155 Utf8Str m_strConfigFile;
156 Utf8Str m_strConfigFileFull;
157
158 // machine settings XML file
159 settings::MachineConfigFile *pMachineConfigFile;
160 uint32_t flModifications;
161
162 BOOL mAccessible;
163 com::ErrorInfo mAccessError;
164
165 MachineState_T mMachineState;
166 RTTIMESPEC mLastStateChange;
167
168 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
169 uint32_t mMachineStateDeps;
170 RTSEMEVENTMULTI mMachineStateDepsSem;
171 uint32_t mMachineStateChangePending;
172
173 BOOL mCurrentStateModified;
174 /** Guest properties have been modified and need saving since the
175 * machine was started, or there are transient properties which need
176 * deleting and the machine is being shut down. */
177 BOOL mGuestPropertiesModified;
178
179 Session mSession;
180
181 ComObjPtr<Snapshot> mFirstSnapshot;
182 ComObjPtr<Snapshot> mCurrentSnapshot;
183
184 // list of files to delete in Delete(); this list is filled by Unregister()
185 std::list<Utf8Str> llFilesToDelete;
186 };
187
188 /**
189 * Saved state data.
190 *
191 * It's actually only the state file path string, but it needs to be
192 * separate from Data, because Machine and SessionMachine instances
193 * share it, while SnapshotMachine does not.
194 *
195 * The data variable is |mSSData|.
196 */
197 struct SSData
198 {
199 Utf8Str mStateFilePath;
200 };
201
202 /**
203 * User changeable machine data.
204 *
205 * This data is common for all machine snapshots, i.e. it is shared
206 * by all SnapshotMachine instances associated with the given machine
207 * using the util::Backupable template through the |mUserData| variable.
208 *
209 * SessionMachine instances can alter this data and discard changes.
210 *
211 * @note There is no need to lock anything inside init() or uninit()
212 * methods, because they are always serialized (see AutoCaller).
213 */
214 struct UserData
215 {
216 settings::MachineUserData s;
217 Utf8Str m_strSnapshotFolderFull;
218 };
219
220 /**
221 * Hardware data.
222 *
223 * This data is unique for a machine and for every machine snapshot.
224 * Stored using the util::Backupable template in the |mHWData| variable.
225 *
226 * SessionMachine instances can alter this data and discard changes.
227 */
228 struct HWData
229 {
230 /**
231 * Data structure to hold information about a guest property.
232 */
233 struct GuestProperty {
234 /** Property name */
235 Utf8Str strName;
236 /** Property value */
237 Utf8Str strValue;
238 /** Property timestamp */
239 LONG64 mTimestamp;
240 /** Property flags */
241 ULONG mFlags;
242 };
243
244 HWData();
245 ~HWData();
246
247 Bstr mHWVersion;
248 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
249 ULONG mMemorySize;
250 ULONG mMemoryBalloonSize;
251 BOOL mPageFusionEnabled;
252 ULONG mVRAMSize;
253 ULONG mMonitorCount;
254 BOOL mHWVirtExEnabled;
255 BOOL mHWVirtExExclusive;
256 BOOL mHWVirtExNestedPagingEnabled;
257 BOOL mHWVirtExLargePagesEnabled;
258 BOOL mHWVirtExVPIDEnabled;
259 BOOL mHWVirtExForceEnabled;
260 BOOL mAccelerate2DVideoEnabled;
261 BOOL mPAEEnabled;
262 BOOL mSyntheticCpu;
263 ULONG mCPUCount;
264 BOOL mCPUHotPlugEnabled;
265 ULONG mCpuPriority;
266 BOOL mAccelerate3DEnabled;
267 BOOL mHpetEnabled;
268
269 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
270
271 settings::CpuIdLeaf mCpuIdStdLeafs[10];
272 settings::CpuIdLeaf mCpuIdExtLeafs[10];
273
274 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
275
276 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
277 SharedFolderList mSharedFolders;
278
279 ClipboardMode_T mClipboardMode;
280
281 typedef std::list<GuestProperty> GuestPropertyList;
282 GuestPropertyList mGuestProperties;
283 Utf8Str mGuestPropertyNotificationPatterns;
284
285 FirmwareType_T mFirmwareType;
286 KeyboardHidType_T mKeyboardHidType;
287 PointingHidType_T mPointingHidType;
288
289 BOOL mIoCacheEnabled;
290 ULONG mIoCacheSize;
291 };
292
293 /**
294 * Hard disk and other media data.
295 *
296 * The usage policy is the same as for HWData, but a separate structure
297 * is necessary because hard disk data requires different procedures when
298 * taking or deleting snapshots, etc.
299 *
300 * The data variable is |mMediaData|.
301 */
302 struct MediaData
303 {
304 MediaData();
305 ~MediaData();
306
307 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
308 AttachmentList mAttachments;
309 };
310
311 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
312
313 DECLARE_NOT_AGGREGATABLE(Machine)
314
315 DECLARE_PROTECT_FINAL_CONSTRUCT()
316
317 BEGIN_COM_MAP(Machine)
318 COM_INTERFACE_ENTRY(ISupportErrorInfo)
319 COM_INTERFACE_ENTRY(IMachine)
320 COM_INTERFACE_ENTRY(IDispatch)
321 END_COM_MAP()
322
323 DECLARE_EMPTY_CTOR_DTOR(Machine)
324
325 HRESULT FinalConstruct();
326 void FinalRelease();
327
328 // public initializer/uninitializer for internal purposes only:
329
330 // initializer for creating a new, empty machine
331 HRESULT init(VirtualBox *aParent,
332 const Utf8Str &strConfigFile,
333 const Utf8Str &strName,
334 const Guid &aId,
335 GuestOSType *aOsType = NULL,
336 BOOL aOverride = FALSE,
337 BOOL aNameSync = TRUE);
338
339 // initializer for loading existing machine XML (either registered or not)
340 HRESULT init(VirtualBox *aParent,
341 const Utf8Str &strConfigFile,
342 const Guid *aId);
343
344 // initializer for machine config in memory (OVF import)
345 HRESULT init(VirtualBox *aParent,
346 const Utf8Str &strName,
347 const settings::MachineConfigFile &config);
348
349 void uninit();
350
351#ifdef VBOX_WITH_RESOURCE_USAGE_API
352 // Needed from VirtualBox, for the delayed metrics cleanup.
353 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
354#endif /* VBOX_WITH_RESOURCE_USAGE_API */
355
356protected:
357 HRESULT initImpl(VirtualBox *aParent,
358 const Utf8Str &strConfigFile);
359 HRESULT initDataAndChildObjects();
360 HRESULT registeredInit();
361 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
362 void uninitDataAndChildObjects();
363
364public:
365 // IMachine properties
366 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
367 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
368 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
369 STDMETHOD(COMGETTER(Name))(BSTR *aName);
370 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
371 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
372 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
373 STDMETHOD(COMGETTER(Id))(BSTR *aId);
374 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
375 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
376 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
377 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
378 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
379 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
380 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
381 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
382 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
383 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
384 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
385 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
386 STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
387 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
388 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
389 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
390 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
391 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
392 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
393 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
394 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
395 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
396 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
397 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
398 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
399 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
400 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
401 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
402 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
403 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
404 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
405 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
406 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
407 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
408 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
409 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
410 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
411 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
412 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
413 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
414 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
415 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
416 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
417 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
418 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
419 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
420 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
421 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
422 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
423 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
424 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
425 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
426 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
427 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
428 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
429 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
430 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
431 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
432 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
433 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
434 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
435 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
436 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
437 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
438 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
439 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
440 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
441 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
442 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
443 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
444 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
445 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
446 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
447 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
448 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
449 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
450 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
451 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
452 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
453 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
454 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
455 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
456 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
457
458 // IMachine methods
459 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
460 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
461
462 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
463 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
464 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
465 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
466 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
467 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
468 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
469 LONG aDevice, IN_BSTR aId, BOOL aForce);
470 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
471 IMedium **aMedium);
472 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
473 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
474 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
475 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
476 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
477 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
478 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
479 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
480 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
481 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
482 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
483 STDMETHOD(RemoveAllCPUIDLeaves)();
484 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
485 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
486 STDMETHOD(SaveSettings)();
487 STDMETHOD(DiscardSettings)();
488 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
489 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
490 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
491 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
492 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
493 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
494 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
495 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
496 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
497 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
498 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
499 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
500 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
501 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
502 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
503 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
504 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
505 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
506 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
507 STDMETHOD(RemoveStorageController(IN_BSTR aName));
508 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
509 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
510 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
511 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
512 STDMETHOD(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_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 LONG64 *aTimestamp, BSTR *aFlags) const;
806 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
807 LONG64 *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(LONG64, aTimestamps),
816 ComSafeArrayOut(BSTR, aFlags));
817 HRESULT enumerateGuestPropertiesOnVM
818 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
819 ComSafeArrayOut(BSTR, aValues),
820 ComSafeArrayOut(LONG64, 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(SetRemoveSavedStateFile)(BOOL aRemove);
903 STDMETHOD(UpdateState)(MachineState_T machineState);
904 STDMETHOD(GetIPCId)(BSTR *id);
905 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
906 STDMETHOD(EndPowerUp)(LONG iResult);
907 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
908 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
909 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
910 STDMETHOD(AutoCaptureUSBDevices)();
911 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
912 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
913 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
914 STDMETHOD(EndSavingState)(BOOL aSuccess);
915 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
916 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
917 IN_BSTR aName,
918 IN_BSTR aDescription,
919 IProgress *aConsoleProgress,
920 BOOL fTakingSnapshotOnline,
921 BSTR *aStateFilePath);
922 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
923 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
924 MachineState_T *aMachineState, IProgress **aProgress);
925 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
926 IMedium *aSource, IMedium *aTarget,
927 BOOL fMergeForward,
928 IMedium *pParentForTarget,
929 ComSafeArrayIn(IMedium *, aChildrenToReparent));
930 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
931 ISnapshot *aSnapshot,
932 MachineState_T *aMachineState,
933 IProgress **aProgress);
934 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
935 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
936 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
937 LONG64 aTimestamp, IN_BSTR aFlags);
938 STDMETHOD(LockMedia)() { return lockMedia(); }
939 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
940
941 // public methods only for internal purposes
942
943 virtual bool isSessionMachine() const
944 {
945 return true;
946 }
947
948 bool checkForDeath();
949
950 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
951 HRESULT onStorageControllerChange();
952 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
953 HRESULT onSerialPortChange(ISerialPort *serialPort);
954 HRESULT onParallelPortChange(IParallelPort *parallelPort);
955 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
956 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
957 HRESULT onVRDPServerChange(BOOL aRestart);
958 HRESULT onUSBControllerChange();
959 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
960 IVirtualBoxErrorInfo *aError,
961 ULONG aMaskedIfs);
962 HRESULT onUSBDeviceDetach(IN_BSTR aId,
963 IVirtualBoxErrorInfo *aError);
964 HRESULT onSharedFolderChange();
965
966 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
967
968private:
969
970 struct SnapshotData
971 {
972 SnapshotData() : mLastState(MachineState_Null) {}
973
974 MachineState_T mLastState;
975
976 // used when taking snapshot
977 ComObjPtr<Snapshot> mSnapshot;
978
979 // used when saving state
980 Guid mProgressId;
981 Utf8Str mStateFilePath;
982 };
983
984 struct Uninit
985 {
986 enum Reason { Unexpected, Abnormal, Normal };
987 };
988
989 struct SnapshotTask;
990 struct DeleteSnapshotTask;
991 struct RestoreSnapshotTask;
992
993 friend struct DeleteSnapshotTask;
994 friend struct RestoreSnapshotTask;
995
996 void uninit(Uninit::Reason aReason);
997
998 HRESULT endSavingState(BOOL aSuccess);
999
1000 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
1001
1002 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1003 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1004
1005 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1006 const Guid &machineId,
1007 const Guid &snapshotId,
1008 bool fOnlineMergePossible,
1009 MediumLockList *aVMMALockList,
1010 ComObjPtr<Medium> &aSource,
1011 ComObjPtr<Medium> &aTarget,
1012 bool &fMergeForward,
1013 ComObjPtr<Medium> &pParentForTarget,
1014 MediaList &aChildrenToReparent,
1015 bool &fNeedOnlineMerge,
1016 MediumLockList * &aMediumLockList);
1017 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1018 const ComObjPtr<Medium> &aSource,
1019 const MediaList &aChildrenToReparent,
1020 bool fNeedsOnlineMerge,
1021 MediumLockList *aMediumLockList,
1022 const Guid &aMediumId,
1023 const Guid &aSnapshotId);
1024 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1025 const ComObjPtr<Medium> &aSource,
1026 const ComObjPtr<Medium> &aTarget,
1027 bool fMergeForward,
1028 const ComObjPtr<Medium> &pParentForTarget,
1029 const MediaList &aChildrenToReparent,
1030 MediumLockList *aMediumLockList,
1031 ComObjPtr<Progress> &aProgress,
1032 bool *pfNeedsMachineSaveSettings);
1033
1034 HRESULT lockMedia();
1035 void unlockMedia();
1036
1037 HRESULT setMachineState(MachineState_T aMachineState);
1038 HRESULT updateMachineStateOnClient();
1039
1040 HRESULT mRemoveSavedState;
1041
1042 SnapshotData mSnapshotData;
1043
1044 /** interprocess semaphore handle for this machine */
1045#if defined(RT_OS_WINDOWS)
1046 HANDLE mIPCSem;
1047 Bstr mIPCSemName;
1048 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1049 ComPtr<IInternalSessionControl> *aControl,
1050 HANDLE *aIPCSem, bool aAllowClosing);
1051#elif defined(RT_OS_OS2)
1052 HMTX mIPCSem;
1053 Bstr mIPCSemName;
1054 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1055 ComPtr<IInternalSessionControl> *aControl,
1056 HMTX *aIPCSem, bool aAllowClosing);
1057#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1058 int mIPCSem;
1059# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1060 Bstr mIPCKey;
1061# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1062#else
1063# error "Port me!"
1064#endif
1065
1066 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1067};
1068
1069// SnapshotMachine class
1070////////////////////////////////////////////////////////////////////////////////
1071
1072/**
1073 * @note Notes on locking objects of this class:
1074 * SnapshotMachine shares some data with the primary Machine instance (pointed
1075 * to by the |mPeer| member). In order to provide data consistency it also
1076 * shares its lock handle. This means that whenever you lock a SessionMachine
1077 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1078 * instance is also locked in the same lock mode. Keep it in mind.
1079 */
1080class ATL_NO_VTABLE SnapshotMachine :
1081 public Machine
1082{
1083public:
1084 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1085
1086 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1087
1088 DECLARE_PROTECT_FINAL_CONSTRUCT()
1089
1090 BEGIN_COM_MAP(SnapshotMachine)
1091 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1092 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1093 COM_INTERFACE_ENTRY(IMachine)
1094 END_COM_MAP()
1095
1096 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1097
1098 HRESULT FinalConstruct();
1099 void FinalRelease();
1100
1101 // public initializer/uninitializer for internal purposes only
1102 HRESULT init(SessionMachine *aSessionMachine,
1103 IN_GUID aSnapshotId,
1104 const Utf8Str &aStateFilePath);
1105 HRESULT init(Machine *aMachine,
1106 const settings::Hardware &hardware,
1107 const settings::Storage &storage,
1108 IN_GUID aSnapshotId,
1109 const Utf8Str &aStateFilePath);
1110 void uninit();
1111
1112 // util::Lockable interface
1113 RWLockHandle *lockHandle() const;
1114
1115 // public methods only for internal purposes
1116
1117 virtual bool isSnapshotMachine() const
1118 {
1119 return true;
1120 }
1121
1122 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1123
1124 // unsafe inline public methods for internal purposes only (ensure there is
1125 // a caller and a read lock before calling them!)
1126
1127 const Guid& getSnapshotId() const { return mSnapshotId; }
1128
1129private:
1130
1131 Guid mSnapshotId;
1132
1133 friend class Snapshot;
1134};
1135
1136// third party methods that depend on SnapshotMachine definiton
1137
1138inline const Guid &Machine::getSnapshotId() const
1139{
1140 return (isSnapshotMachine())
1141 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1142 : Guid::Empty;
1143}
1144
1145
1146#endif // ____H_MACHINEIMPL
1147/* 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