VirtualBox

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

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

Main: replaces callback mechanism of NAT redirect change event notification with event-driven model.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.4 KB
Line 
1/* $Id: MachineImpl.h 33952 2010-11-11 03:49:28Z 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 "ProgressImpl.h"
24#include "VRDEServerImpl.h"
25#include "MediumAttachmentImpl.h"
26#include "MediumLock.h"
27#include "NetworkAdapterImpl.h"
28#include "AudioAdapterImpl.h"
29#include "SerialPortImpl.h"
30#include "ParallelPortImpl.h"
31#include "BIOSSettingsImpl.h"
32#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
33#include "VBox/settings.h"
34#ifdef VBOX_WITH_RESOURCE_USAGE_API
35#include "Performance.h"
36#include "PerformanceImpl.h"
37#endif /* VBOX_WITH_RESOURCE_USAGE_API */
38
39// generated header
40#include "SchemaDefs.h"
41
42#include "VBox/com/ErrorInfo.h"
43
44#include <iprt/file.h>
45#include <iprt/thread.h>
46#include <iprt/time.h>
47
48#include <list>
49
50// defines
51////////////////////////////////////////////////////////////////////////////////
52
53// helper declarations
54////////////////////////////////////////////////////////////////////////////////
55
56class Progress;
57class ProgressProxy;
58class Keyboard;
59class Mouse;
60class Display;
61class MachineDebugger;
62class USBController;
63class Snapshot;
64class SharedFolder;
65class HostUSBDevice;
66class StorageController;
67
68class SessionMachine;
69
70namespace settings
71{
72 class MachineConfigFile;
73 struct Snapshot;
74 struct Hardware;
75 struct Storage;
76 struct StorageController;
77 struct MachineRegistryEntry;
78}
79
80// Machine class
81////////////////////////////////////////////////////////////////////////////////
82
83class ATL_NO_VTABLE Machine :
84 public VirtualBoxBase,
85 VBOX_SCRIPTABLE_IMPL(IMachine)
86{
87 Q_OBJECT
88
89public:
90
91 enum StateDependency
92 {
93 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
94 };
95
96 /**
97 * Internal machine data.
98 *
99 * Only one instance of this data exists per every machine -- it is shared
100 * by the Machine, SessionMachine and all SnapshotMachine instances
101 * associated with the given machine using the util::Shareable template
102 * through the mData variable.
103 *
104 * @note |const| members are persistent during lifetime so can be
105 * accessed without locking.
106 *
107 * @note There is no need to lock anything inside init() or uninit()
108 * methods, because they are always serialized (see AutoCaller).
109 */
110 struct Data
111 {
112 /**
113 * Data structure to hold information about sessions opened for the
114 * given machine.
115 */
116 struct Session
117 {
118 /** Control of the direct session opened by lockMachine() */
119 ComPtr<IInternalSessionControl> mDirectControl;
120
121 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
122
123 /** list of controls of all opened remote sessions */
124 RemoteControlList mRemoteControls;
125
126 /** openRemoteSession() and OnSessionEnd() progress indicator */
127 ComObjPtr<ProgressProxy> mProgress;
128
129 /**
130 * PID of the session object that must be passed to openSession() to
131 * finalize the openRemoteSession() request (i.e., PID of the
132 * process created by openRemoteSession())
133 */
134 RTPROCESS mPid;
135
136 /** Current session state */
137 SessionState_T mState;
138
139 /** Session type string (for indirect sessions) */
140 Bstr mType;
141
142 /** Session machine object */
143 ComObjPtr<SessionMachine> mMachine;
144
145 /** Medium object lock collection. */
146 MediumLockListMap mLockedMedia;
147 };
148
149 Data();
150 ~Data();
151
152 const Guid mUuid;
153 BOOL mRegistered;
154
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 };
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 onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
616 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
617 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
618 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
619 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
620 virtual HRESULT onUSBControllerChange() { return S_OK; }
621 virtual HRESULT onStorageControllerChange() { return S_OK; }
622 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
623 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
624 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
625 virtual HRESULT onSharedFolderChange() { return S_OK; }
626
627 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
628
629 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
630 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
631
632 void getLogFolder(Utf8Str &aLogFolder);
633 Utf8Str queryLogFilename(ULONG idx);
634
635 HRESULT openRemoteSession(IInternalSessionControl *aControl,
636 IN_BSTR aType, IN_BSTR aEnvironment,
637 ProgressProxy *aProgress);
638
639 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
640 {
641 HRESULT rc;
642 *directControl = mData->mSession.mDirectControl;
643
644 if (!*directControl)
645 rc = E_ACCESSDENIED;
646 else
647 rc = S_OK;
648
649 return rc;
650 }
651
652#if defined(RT_OS_WINDOWS)
653
654 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
655 ComPtr<IInternalSessionControl> *aControl = NULL,
656 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
657 bool isSessionSpawning(RTPROCESS *aPID = NULL);
658
659 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
660 ComPtr<IInternalSessionControl> *aControl = NULL,
661 HANDLE *aIPCSem = NULL)
662 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
663
664#elif defined(RT_OS_OS2)
665
666 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
667 ComPtr<IInternalSessionControl> *aControl = NULL,
668 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
669
670 bool isSessionSpawning(RTPROCESS *aPID = NULL);
671
672 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
673 ComPtr<IInternalSessionControl> *aControl = NULL,
674 HMTX *aIPCSem = NULL)
675 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
676
677#else
678
679 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
680 ComPtr<IInternalSessionControl> *aControl = NULL,
681 bool aAllowClosing = false);
682 bool isSessionSpawning();
683
684 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
685 ComPtr<IInternalSessionControl> *aControl = NULL)
686 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
687
688#endif
689
690 bool checkForSpawnFailure();
691
692 HRESULT prepareRegister();
693
694 HRESULT getSharedFolder(CBSTR aName,
695 ComObjPtr<SharedFolder> &aSharedFolder,
696 bool aSetError = false)
697 {
698 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
699 return findSharedFolder(aName, aSharedFolder, aSetError);
700 }
701
702 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
703 MachineState_T *aState = NULL,
704 BOOL *aRegistered = NULL);
705 void releaseStateDependency();
706
707protected:
708
709 HRESULT checkStateDependency(StateDependency aDepType);
710
711 Machine *getMachine();
712
713 void ensureNoStateDependencies();
714
715 virtual HRESULT setMachineState(MachineState_T aMachineState);
716
717 HRESULT findSharedFolder(CBSTR aName,
718 ComObjPtr<SharedFolder> &aSharedFolder,
719 bool aSetError = false);
720
721 HRESULT loadSettings(bool aRegistered);
722 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
723 const Guid *puuidRegistry);
724 HRESULT loadSnapshot(const settings::Snapshot &data,
725 const Guid &aCurSnapshotId,
726 Snapshot *aParentSnapshot);
727 HRESULT loadHardware(const settings::Hardware &data);
728 HRESULT loadStorageControllers(const settings::Storage &data,
729 const Guid *puuidRegistry,
730 const Guid *puuidSnapshot);
731 HRESULT loadStorageDevices(StorageController *aStorageController,
732 const settings::StorageController &data,
733 const Guid *puuidRegistry,
734 const Guid *puuidSnapshot);
735
736 HRESULT findSnapshotById(const Guid &aId,
737 ComObjPtr<Snapshot> &aSnapshot,
738 bool aSetError = false);
739 HRESULT findSnapshotByName(const Utf8Str &strName,
740 ComObjPtr<Snapshot> &aSnapshot,
741 bool aSetError = false);
742
743 HRESULT getStorageControllerByName(const Utf8Str &aName,
744 ComObjPtr<StorageController> &aStorageController,
745 bool aSetError = false);
746
747 HRESULT getMediumAttachmentsOfController(CBSTR aName,
748 MediaData::AttachmentList &aAttachments);
749
750 enum
751 {
752 /* flags for #saveSettings() */
753 SaveS_ResetCurStateModified = 0x01,
754 SaveS_InformCallbacksAnyway = 0x02,
755 SaveS_Force = 0x04,
756 /* flags for #saveStateSettings() */
757 SaveSTS_CurStateModified = 0x20,
758 SaveSTS_StateFilePath = 0x40,
759 SaveSTS_StateTimeStamp = 0x80
760 };
761
762 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
763 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
764
765 void copyMachineDataToSettings(settings::MachineConfigFile &config);
766 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
767 HRESULT saveHardware(settings::Hardware &data);
768 HRESULT saveStorageControllers(settings::Storage &data);
769 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
770 settings::StorageController &data);
771 HRESULT saveStateSettings(int aFlags);
772
773 HRESULT createImplicitDiffs(IProgress *aProgress,
774 ULONG aWeight,
775 bool aOnline,
776 GuidList *pllRegistriesThatNeedSaving);
777 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
778
779 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
780 IN_BSTR aControllerName,
781 LONG aControllerPort,
782 LONG aDevice);
783 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
784 ComObjPtr<Medium> pMedium);
785 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
786 Guid &id);
787
788 HRESULT detachDevice(MediumAttachment *pAttach,
789 AutoWriteLock &writeLock,
790 Snapshot *pSnapshot,
791 GuidList *pllRegistriesThatNeedSaving);
792 HRESULT detachAllMedia(AutoWriteLock &writeLock,
793 Snapshot *pSnapshot,
794 CleanupMode_T cleanupMode,
795 MediaList &llMedia);
796
797 void commitMedia(bool aOnline = false);
798 void rollbackMedia();
799
800 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
801
802 void rollback(bool aNotify);
803 void commit();
804 void copyFrom(Machine *aThat);
805
806 struct DeleteTask;
807 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
808 HRESULT deleteTaskWorker(DeleteTask &task);
809
810#ifdef VBOX_WITH_GUEST_PROPS
811 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
812 LONG64 *aTimestamp, BSTR *aFlags) const;
813 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
814 LONG64 *aTimestamp, BSTR *aFlags) const;
815 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
816 IN_BSTR aFlags);
817 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
818 IN_BSTR aFlags);
819 HRESULT enumerateGuestPropertiesInService
820 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
821 ComSafeArrayOut(BSTR, aValues),
822 ComSafeArrayOut(LONG64, aTimestamps),
823 ComSafeArrayOut(BSTR, aFlags));
824 HRESULT enumerateGuestPropertiesOnVM
825 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
826 ComSafeArrayOut(BSTR, aValues),
827 ComSafeArrayOut(LONG64, aTimestamps),
828 ComSafeArrayOut(BSTR, aFlags));
829#endif /* VBOX_WITH_GUEST_PROPS */
830
831#ifdef VBOX_WITH_RESOURCE_USAGE_API
832 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
833
834 pm::CollectorGuestHAL *mGuestHAL;
835#endif /* VBOX_WITH_RESOURCE_USAGE_API */
836
837 Machine* const mPeer;
838
839 VirtualBox * const mParent;
840
841 Shareable<Data> mData;
842 Shareable<SSData> mSSData;
843
844 Backupable<UserData> mUserData;
845 Backupable<HWData> mHWData;
846 Backupable<MediaData> mMediaData;
847
848 // the following fields need special backup/rollback/commit handling,
849 // so they cannot be a part of HWData
850
851 const ComObjPtr<VRDEServer> mVRDEServer;
852 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
853 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
854 const ComObjPtr<AudioAdapter> mAudioAdapter;
855 const ComObjPtr<USBController> mUSBController;
856 const ComObjPtr<BIOSSettings> mBIOSSettings;
857 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
858
859 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
860 Backupable<StorageControllerList> mStorageControllers;
861
862 friend class SessionMachine;
863 friend class SnapshotMachine;
864 friend class Appliance;
865 friend class VirtualBox;
866};
867
868// SessionMachine class
869////////////////////////////////////////////////////////////////////////////////
870
871/**
872 * @note Notes on locking objects of this class:
873 * SessionMachine shares some data with the primary Machine instance (pointed
874 * to by the |mPeer| member). In order to provide data consistency it also
875 * shares its lock handle. This means that whenever you lock a SessionMachine
876 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
877 * instance is also locked in the same lock mode. Keep it in mind.
878 */
879class ATL_NO_VTABLE SessionMachine :
880 public Machine,
881 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
882{
883public:
884 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
885
886 DECLARE_NOT_AGGREGATABLE(SessionMachine)
887
888 DECLARE_PROTECT_FINAL_CONSTRUCT()
889
890 BEGIN_COM_MAP(SessionMachine)
891 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
892 COM_INTERFACE_ENTRY(ISupportErrorInfo)
893 COM_INTERFACE_ENTRY(IMachine)
894 COM_INTERFACE_ENTRY(IInternalMachineControl)
895 END_COM_MAP()
896
897 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
898
899 HRESULT FinalConstruct();
900 void FinalRelease();
901
902 // public initializer/uninitializer for internal purposes only
903 HRESULT init(Machine *aMachine);
904 void uninit() { uninit(Uninit::Unexpected); }
905
906 // util::Lockable interface
907 RWLockHandle *lockHandle() const;
908
909 // IInternalMachineControl methods
910 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
911 STDMETHOD(UpdateState)(MachineState_T machineState);
912 STDMETHOD(GetIPCId)(BSTR *id);
913 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
914 STDMETHOD(EndPowerUp)(LONG iResult);
915 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
916 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
917 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
918 STDMETHOD(AutoCaptureUSBDevices)();
919 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
920 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
921 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
922 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
923 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
924 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
925 IN_BSTR aName,
926 IN_BSTR aDescription,
927 IProgress *aConsoleProgress,
928 BOOL fTakingSnapshotOnline,
929 BSTR *aStateFilePath);
930 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
931 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
932 MachineState_T *aMachineState, IProgress **aProgress);
933 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
934 IMedium *aSource, IMedium *aTarget,
935 BOOL fMergeForward,
936 IMedium *pParentForTarget,
937 ComSafeArrayIn(IMedium *, aChildrenToReparent));
938 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
939 ISnapshot *aSnapshot,
940 MachineState_T *aMachineState,
941 IProgress **aProgress);
942 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
943 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
944 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
945 LONG64 aTimestamp, IN_BSTR aFlags);
946 STDMETHOD(LockMedia)() { return lockMedia(); }
947 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
948
949 // public methods only for internal purposes
950
951 virtual bool isSessionMachine() const
952 {
953 return true;
954 }
955
956 bool checkForDeath();
957
958 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
959 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
960 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
961 HRESULT onStorageControllerChange();
962 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
963 HRESULT onSerialPortChange(ISerialPort *serialPort);
964 HRESULT onParallelPortChange(IParallelPort *parallelPort);
965 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
966 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
967 HRESULT onVRDEServerChange(BOOL aRestart);
968 HRESULT onUSBControllerChange();
969 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
970 IVirtualBoxErrorInfo *aError,
971 ULONG aMaskedIfs);
972 HRESULT onUSBDeviceDetach(IN_BSTR aId,
973 IVirtualBoxErrorInfo *aError);
974 HRESULT onSharedFolderChange();
975
976 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
977
978private:
979
980 struct SnapshotData
981 {
982 SnapshotData() : mLastState(MachineState_Null) {}
983
984 MachineState_T mLastState;
985
986 // used when taking snapshot
987 ComObjPtr<Snapshot> mSnapshot;
988
989 // used when saving state
990 Utf8Str mStateFilePath;
991 ComObjPtr<Progress> mProgress;
992 };
993
994 struct Uninit
995 {
996 enum Reason { Unexpected, Abnormal, Normal };
997 };
998
999 struct SnapshotTask;
1000 struct DeleteSnapshotTask;
1001 struct RestoreSnapshotTask;
1002
1003 friend struct DeleteSnapshotTask;
1004 friend struct RestoreSnapshotTask;
1005
1006 void uninit(Uninit::Reason aReason);
1007
1008 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1009
1010 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1011 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1012
1013 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1014 const Guid &machineId,
1015 const Guid &snapshotId,
1016 bool fOnlineMergePossible,
1017 MediumLockList *aVMMALockList,
1018 ComObjPtr<Medium> &aSource,
1019 ComObjPtr<Medium> &aTarget,
1020 bool &fMergeForward,
1021 ComObjPtr<Medium> &pParentForTarget,
1022 MediaList &aChildrenToReparent,
1023 bool &fNeedOnlineMerge,
1024 MediumLockList * &aMediumLockList);
1025 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1026 const ComObjPtr<Medium> &aSource,
1027 const MediaList &aChildrenToReparent,
1028 bool fNeedsOnlineMerge,
1029 MediumLockList *aMediumLockList,
1030 const Guid &aMediumId,
1031 const Guid &aSnapshotId);
1032 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1033 const ComObjPtr<Medium> &aSource,
1034 const ComObjPtr<Medium> &aTarget,
1035 bool fMergeForward,
1036 const ComObjPtr<Medium> &pParentForTarget,
1037 const MediaList &aChildrenToReparent,
1038 MediumLockList *aMediumLockList,
1039 ComObjPtr<Progress> &aProgress,
1040 bool *pfNeedsMachineSaveSettings);
1041
1042 HRESULT lockMedia();
1043 void unlockMedia();
1044
1045 HRESULT setMachineState(MachineState_T aMachineState);
1046 HRESULT updateMachineStateOnClient();
1047
1048 HRESULT mRemoveSavedState;
1049
1050 SnapshotData mSnapshotData;
1051
1052 /** interprocess semaphore handle for this machine */
1053#if defined(RT_OS_WINDOWS)
1054 HANDLE mIPCSem;
1055 Bstr mIPCSemName;
1056 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1057 ComPtr<IInternalSessionControl> *aControl,
1058 HANDLE *aIPCSem, bool aAllowClosing);
1059#elif defined(RT_OS_OS2)
1060 HMTX mIPCSem;
1061 Bstr mIPCSemName;
1062 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1063 ComPtr<IInternalSessionControl> *aControl,
1064 HMTX *aIPCSem, bool aAllowClosing);
1065#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1066 int mIPCSem;
1067# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1068 Bstr mIPCKey;
1069# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1070#else
1071# error "Port me!"
1072#endif
1073
1074 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1075};
1076
1077// SnapshotMachine class
1078////////////////////////////////////////////////////////////////////////////////
1079
1080/**
1081 * @note Notes on locking objects of this class:
1082 * SnapshotMachine shares some data with the primary Machine instance (pointed
1083 * to by the |mPeer| member). In order to provide data consistency it also
1084 * shares its lock handle. This means that whenever you lock a SessionMachine
1085 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1086 * instance is also locked in the same lock mode. Keep it in mind.
1087 */
1088class ATL_NO_VTABLE SnapshotMachine :
1089 public Machine
1090{
1091public:
1092 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1093
1094 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1095
1096 DECLARE_PROTECT_FINAL_CONSTRUCT()
1097
1098 BEGIN_COM_MAP(SnapshotMachine)
1099 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1100 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1101 COM_INTERFACE_ENTRY(IMachine)
1102 END_COM_MAP()
1103
1104 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1105
1106 HRESULT FinalConstruct();
1107 void FinalRelease();
1108
1109 // public initializer/uninitializer for internal purposes only
1110 HRESULT init(SessionMachine *aSessionMachine,
1111 IN_GUID aSnapshotId,
1112 const Utf8Str &aStateFilePath);
1113 HRESULT init(Machine *aMachine,
1114 const settings::Hardware &hardware,
1115 const settings::Storage &storage,
1116 IN_GUID aSnapshotId,
1117 const Utf8Str &aStateFilePath);
1118 void uninit();
1119
1120 // util::Lockable interface
1121 RWLockHandle *lockHandle() const;
1122
1123 // public methods only for internal purposes
1124
1125 virtual bool isSnapshotMachine() const
1126 {
1127 return true;
1128 }
1129
1130 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1131
1132 // unsafe inline public methods for internal purposes only (ensure there is
1133 // a caller and a read lock before calling them!)
1134
1135 const Guid& getSnapshotId() const { return mSnapshotId; }
1136
1137private:
1138
1139 Guid mSnapshotId;
1140
1141 friend class Snapshot;
1142};
1143
1144// third party methods that depend on SnapshotMachine definition
1145
1146inline const Guid &Machine::getSnapshotId() const
1147{
1148 return (isSnapshotMachine())
1149 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1150 : Guid::Empty;
1151}
1152
1153
1154#endif // ____H_MACHINEIMPL
1155/* 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