VirtualBox

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

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

Main, devices: support for chipset selection in the public API

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.7 KB
Line 
1/* $Id: MachineImpl.h 32120 2010-08-31 09:58:36Z 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.215389.xyz. 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 ChipsetType_T mChipsetType;
289
290 BOOL mIoCacheEnabled;
291 ULONG mIoCacheSize;
292 };
293
294 /**
295 * Hard disk and other media data.
296 *
297 * The usage policy is the same as for HWData, but a separate structure
298 * is necessary because hard disk data requires different procedures when
299 * taking or deleting snapshots, etc.
300 *
301 * The data variable is |mMediaData|.
302 */
303 struct MediaData
304 {
305 MediaData();
306 ~MediaData();
307
308 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
309 AttachmentList mAttachments;
310 };
311
312 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
313
314 DECLARE_NOT_AGGREGATABLE(Machine)
315
316 DECLARE_PROTECT_FINAL_CONSTRUCT()
317
318 BEGIN_COM_MAP(Machine)
319 COM_INTERFACE_ENTRY(ISupportErrorInfo)
320 COM_INTERFACE_ENTRY(IMachine)
321 COM_INTERFACE_ENTRY(IDispatch)
322 END_COM_MAP()
323
324 DECLARE_EMPTY_CTOR_DTOR(Machine)
325
326 HRESULT FinalConstruct();
327 void FinalRelease();
328
329 // public initializer/uninitializer for internal purposes only:
330
331 // initializer for creating a new, empty machine
332 HRESULT init(VirtualBox *aParent,
333 const Utf8Str &strConfigFile,
334 const Utf8Str &strName,
335 const Guid &aId,
336 GuestOSType *aOsType = NULL,
337 BOOL aOverride = FALSE,
338 BOOL aNameSync = TRUE);
339
340 // initializer for loading existing machine XML (either registered or not)
341 HRESULT init(VirtualBox *aParent,
342 const Utf8Str &strConfigFile,
343 const Guid *aId);
344
345 // initializer for machine config in memory (OVF import)
346 HRESULT init(VirtualBox *aParent,
347 const Utf8Str &strName,
348 const settings::MachineConfigFile &config);
349
350 void uninit();
351
352#ifdef VBOX_WITH_RESOURCE_USAGE_API
353 // Needed from VirtualBox, for the delayed metrics cleanup.
354 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
355#endif /* VBOX_WITH_RESOURCE_USAGE_API */
356
357protected:
358 HRESULT initImpl(VirtualBox *aParent,
359 const Utf8Str &strConfigFile);
360 HRESULT initDataAndChildObjects();
361 HRESULT registeredInit();
362 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
363 void uninitDataAndChildObjects();
364
365public:
366 // IMachine properties
367 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
368 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
369 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
370 STDMETHOD(COMGETTER(Name))(BSTR *aName);
371 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
372 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
373 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
374 STDMETHOD(COMGETTER(Id))(BSTR *aId);
375 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
376 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
377 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
378 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
379 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
380 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
381 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
382 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
383 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
384 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
385 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
386 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
387 STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
388 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
389 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
390 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
391 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
392 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
393 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
394 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
395 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
396 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
397 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
398 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
399 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
402 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
403 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
404 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
405 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
406 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
407 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
408 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
409 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
410 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
411 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
412 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
413 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
414 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
415 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
416 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
417 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
418 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
419 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
420 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
421 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
422 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
423 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
424 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
425 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
426 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
427 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
428 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
429 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
430 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
431 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
432 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
433 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
434 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
435 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
436 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
437 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
438 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
439 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
440 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
441 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
442 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
443 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
444 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
445 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
446 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
447 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
448 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
449 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
450 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
451 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
452 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
453 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
454 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
455 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
456 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
457 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
458 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
459 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
460
461 // IMachine methods
462 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
463 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
464
465 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
466 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
467 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
468 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
469 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
470 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
471 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
472 LONG aDevice, IN_BSTR aId, BOOL aForce);
473 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
474 IMedium **aMedium);
475 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
476 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
477 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
478 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
479 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
480 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
481 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
482 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
483 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
484 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
485 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
486 STDMETHOD(RemoveAllCPUIDLeaves)();
487 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
488 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
489 STDMETHOD(SaveSettings)();
490 STDMETHOD(DiscardSettings)();
491 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
492 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
493 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
494 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
495 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
496 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
497 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
498 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
499 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
500 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
501 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
502 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
503 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
504 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
505 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
506 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
507 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
508 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
509 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
510 STDMETHOD(RemoveStorageController(IN_BSTR aName));
511 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
512 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
513 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
514 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
515 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
516 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
517 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
518 STDMETHOD(HotPlugCPU(ULONG aCpu));
519 STDMETHOD(HotUnplugCPU(ULONG aCpu));
520 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
521 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
522 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
523
524 // public methods only for internal purposes
525
526 virtual bool isSnapshotMachine() const
527 {
528 return false;
529 }
530
531 virtual bool isSessionMachine() const
532 {
533 return false;
534 }
535
536 /**
537 * Override of the default locking class to be used for validating lock
538 * order with the standard member lock handle.
539 */
540 virtual VBoxLockingClass getLockingClass() const
541 {
542 return LOCKCLASS_MACHINEOBJECT;
543 }
544
545 /// @todo (dmik) add lock and make non-inlined after revising classes
546 // that use it. Note: they should enter Machine lock to keep the returned
547 // information valid!
548 bool isRegistered() { return !!mData->mRegistered; }
549
550 // unsafe inline public methods for internal purposes only (ensure there is
551 // a caller and a read lock before calling them!)
552
553 /**
554 * Returns the VirtualBox object this machine belongs to.
555 *
556 * @note This method doesn't check this object's readiness. Intended to be
557 * used by ready Machine children (whose readiness is bound to the parent's
558 * one) or after doing addCaller() manually.
559 */
560 VirtualBox* getVirtualBox() const { return mParent; }
561
562 /**
563 * Returns this machine ID.
564 *
565 * @note This method doesn't check this object's readiness. Intended to be
566 * used by ready Machine children (whose readiness is bound to the parent's
567 * one) or after adding a caller manually.
568 */
569 const Guid& getId() const { return mData->mUuid; }
570
571 /**
572 * Returns the snapshot ID this machine represents or an empty UUID if this
573 * instance is not SnapshotMachine.
574 *
575 * @note This method doesn't check this object's readiness. Intended to be
576 * used by ready Machine children (whose readiness is bound to the parent's
577 * one) or after adding a caller manually.
578 */
579 inline const Guid& getSnapshotId() const;
580
581 /**
582 * Returns this machine's full settings file path.
583 *
584 * @note This method doesn't lock this object or check its readiness.
585 * Intended to be used only after doing addCaller() manually and locking it
586 * for reading.
587 */
588 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
589
590 /**
591 * Returns this machine name.
592 *
593 * @note This method doesn't lock this object or check its readiness.
594 * Intended to be used only after doing addCaller() manually and locking it
595 * for reading.
596 */
597 const Utf8Str& getName() const { return mUserData->s.strName; }
598
599 enum
600 {
601 IsModified_MachineData = 0x0001,
602 IsModified_Storage = 0x0002,
603 IsModified_NetworkAdapters = 0x0008,
604 IsModified_SerialPorts = 0x0010,
605 IsModified_ParallelPorts = 0x0020,
606 IsModified_VRDPServer = 0x0040,
607 IsModified_AudioAdapter = 0x0080,
608 IsModified_USB = 0x0100,
609 IsModified_BIOS = 0x0200,
610 IsModified_SharedFolders = 0x0400,
611 IsModified_Snapshots = 0x0800
612 };
613
614 void setModified(uint32_t fl);
615
616 // callback handlers
617 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
618 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
619 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
620 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
621 virtual HRESULT onUSBControllerChange() { return S_OK; }
622 virtual HRESULT onStorageControllerChange() { return S_OK; }
623 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
624 virtual HRESULT onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
625 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
626 virtual HRESULT onSharedFolderChange() { return S_OK; }
627
628 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
629
630 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
631 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
632
633 void getLogFolder(Utf8Str &aLogFolder);
634 Utf8Str queryLogFilename(ULONG idx);
635
636 HRESULT openRemoteSession(IInternalSessionControl *aControl,
637 IN_BSTR aType, IN_BSTR aEnvironment,
638 ProgressProxy *aProgress);
639
640 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
641 {
642 HRESULT rc;
643 *directControl = mData->mSession.mDirectControl;
644
645 if (!*directControl)
646 rc = E_ACCESSDENIED;
647 else
648 rc = S_OK;
649
650 return rc;
651 }
652
653#if defined(RT_OS_WINDOWS)
654
655 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
656 ComPtr<IInternalSessionControl> *aControl = NULL,
657 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
658 bool isSessionSpawning(RTPROCESS *aPID = NULL);
659
660 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
661 ComPtr<IInternalSessionControl> *aControl = NULL,
662 HANDLE *aIPCSem = NULL)
663 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
664
665#elif defined(RT_OS_OS2)
666
667 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
668 ComPtr<IInternalSessionControl> *aControl = NULL,
669 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
670
671 bool isSessionSpawning(RTPROCESS *aPID = NULL);
672
673 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
674 ComPtr<IInternalSessionControl> *aControl = NULL,
675 HMTX *aIPCSem = NULL)
676 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
677
678#else
679
680 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
681 ComPtr<IInternalSessionControl> *aControl = NULL,
682 bool aAllowClosing = false);
683 bool isSessionSpawning();
684
685 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
686 ComPtr<IInternalSessionControl> *aControl = NULL)
687 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
688
689#endif
690
691 bool checkForSpawnFailure();
692
693 HRESULT prepareRegister();
694
695 HRESULT getSharedFolder(CBSTR aName,
696 ComObjPtr<SharedFolder> &aSharedFolder,
697 bool aSetError = false)
698 {
699 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
700 return findSharedFolder(aName, aSharedFolder, aSetError);
701 }
702
703 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
704 MachineState_T *aState = NULL,
705 BOOL *aRegistered = NULL);
706 void releaseStateDependency();
707
708protected:
709
710 HRESULT checkStateDependency(StateDependency aDepType);
711
712 Machine *getMachine();
713
714 void ensureNoStateDependencies();
715
716 virtual HRESULT setMachineState(MachineState_T aMachineState);
717
718 HRESULT findSharedFolder(CBSTR aName,
719 ComObjPtr<SharedFolder> &aSharedFolder,
720 bool aSetError = false);
721
722 HRESULT loadSettings(bool aRegistered);
723 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
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 *aSnapshotId = NULL);
730 HRESULT loadStorageDevices(StorageController *aStorageController,
731 const settings::StorageController &data,
732 const Guid *aSnapshotId = NULL);
733
734 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
735 bool aSetError = false);
736 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
737 bool aSetError = false);
738
739 HRESULT getStorageControllerByName(const Utf8Str &aName,
740 ComObjPtr<StorageController> &aStorageController,
741 bool aSetError = false);
742
743 HRESULT getMediumAttachmentsOfController(CBSTR aName,
744 MediaData::AttachmentList &aAttachments);
745
746 enum
747 {
748 /* flags for #saveSettings() */
749 SaveS_ResetCurStateModified = 0x01,
750 SaveS_InformCallbacksAnyway = 0x02,
751 SaveS_Force = 0x04,
752 /* flags for #saveStateSettings() */
753 SaveSTS_CurStateModified = 0x20,
754 SaveSTS_StateFilePath = 0x40,
755 SaveSTS_StateTimeStamp = 0x80
756 };
757
758 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
759 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
760
761 void copyMachineDataToSettings(settings::MachineConfigFile &config);
762 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
763 HRESULT saveHardware(settings::Hardware &data);
764 HRESULT saveStorageControllers(settings::Storage &data);
765 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
766 settings::StorageController &data);
767 HRESULT saveStateSettings(int aFlags);
768
769 HRESULT createImplicitDiffs(IProgress *aProgress,
770 ULONG aWeight,
771 bool aOnline,
772 bool *pfNeedsSaveSettings);
773 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
774
775 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
776 IN_BSTR aControllerName,
777 LONG aControllerPort,
778 LONG aDevice);
779 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
780 ComObjPtr<Medium> pMedium);
781 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
782 Guid &id);
783
784 HRESULT detachDevice(MediumAttachment *pAttach,
785 AutoWriteLock &writeLock,
786 Snapshot *pSnapshot,
787 bool *pfNeedsSaveSettings);
788 HRESULT detachAllMedia(AutoWriteLock &writeLock,
789 Snapshot *pSnapshot,
790 CleanupMode_T cleanupMode,
791 MediaList &llMedia);
792
793 void commitMedia(bool aOnline = false);
794 void rollbackMedia();
795
796 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
797
798 void rollback(bool aNotify);
799 void commit();
800 void copyFrom(Machine *aThat);
801
802 struct DeleteTask;
803 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
804 HRESULT deleteTaskWorker(DeleteTask &task);
805
806#ifdef VBOX_WITH_GUEST_PROPS
807 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
808 LONG64 *aTimestamp, BSTR *aFlags) const;
809 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
810 LONG64 *aTimestamp, BSTR *aFlags) const;
811 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
812 IN_BSTR aFlags);
813 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
814 IN_BSTR aFlags);
815 HRESULT enumerateGuestPropertiesInService
816 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
817 ComSafeArrayOut(BSTR, aValues),
818 ComSafeArrayOut(LONG64, aTimestamps),
819 ComSafeArrayOut(BSTR, aFlags));
820 HRESULT enumerateGuestPropertiesOnVM
821 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
822 ComSafeArrayOut(BSTR, aValues),
823 ComSafeArrayOut(LONG64, aTimestamps),
824 ComSafeArrayOut(BSTR, aFlags));
825#endif /* VBOX_WITH_GUEST_PROPS */
826
827#ifdef VBOX_WITH_RESOURCE_USAGE_API
828 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
829
830 pm::CollectorGuestHAL *mGuestHAL;
831#endif /* VBOX_WITH_RESOURCE_USAGE_API */
832
833 Machine* const mPeer;
834
835 VirtualBox * const mParent;
836
837 Shareable<Data> mData;
838 Shareable<SSData> mSSData;
839
840 Backupable<UserData> mUserData;
841 Backupable<HWData> mHWData;
842 Backupable<MediaData> mMediaData;
843
844 // the following fields need special backup/rollback/commit handling,
845 // so they cannot be a part of HWData
846
847 const ComObjPtr<VRDPServer> mVRDPServer;
848 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
849 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
850 const ComObjPtr<AudioAdapter> mAudioAdapter;
851 const ComObjPtr<USBController> mUSBController;
852 const ComObjPtr<BIOSSettings> mBIOSSettings;
853 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
854
855 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
856 Backupable<StorageControllerList> mStorageControllers;
857
858 friend class SessionMachine;
859 friend class SnapshotMachine;
860 friend class Appliance;
861};
862
863// SessionMachine class
864////////////////////////////////////////////////////////////////////////////////
865
866/**
867 * @note Notes on locking objects of this class:
868 * SessionMachine shares some data with the primary Machine instance (pointed
869 * to by the |mPeer| member). In order to provide data consistency it also
870 * shares its lock handle. This means that whenever you lock a SessionMachine
871 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
872 * instance is also locked in the same lock mode. Keep it in mind.
873 */
874class ATL_NO_VTABLE SessionMachine :
875 public Machine,
876 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
877{
878public:
879 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
880
881 DECLARE_NOT_AGGREGATABLE(SessionMachine)
882
883 DECLARE_PROTECT_FINAL_CONSTRUCT()
884
885 BEGIN_COM_MAP(SessionMachine)
886 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
887 COM_INTERFACE_ENTRY(ISupportErrorInfo)
888 COM_INTERFACE_ENTRY(IMachine)
889 COM_INTERFACE_ENTRY(IInternalMachineControl)
890 END_COM_MAP()
891
892 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
893
894 HRESULT FinalConstruct();
895 void FinalRelease();
896
897 // public initializer/uninitializer for internal purposes only
898 HRESULT init(Machine *aMachine);
899 void uninit() { uninit(Uninit::Unexpected); }
900
901 // util::Lockable interface
902 RWLockHandle *lockHandle() const;
903
904 // IInternalMachineControl methods
905 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
906 STDMETHOD(UpdateState)(MachineState_T machineState);
907 STDMETHOD(GetIPCId)(BSTR *id);
908 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
909 STDMETHOD(EndPowerUp)(LONG iResult);
910 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
911 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
912 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
913 STDMETHOD(AutoCaptureUSBDevices)();
914 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
915 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
916 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
917 STDMETHOD(EndSavingState)(BOOL aSuccess);
918 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
919 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
920 IN_BSTR aName,
921 IN_BSTR aDescription,
922 IProgress *aConsoleProgress,
923 BOOL fTakingSnapshotOnline,
924 BSTR *aStateFilePath);
925 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
926 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
927 MachineState_T *aMachineState, IProgress **aProgress);
928 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
929 IMedium *aSource, IMedium *aTarget,
930 BOOL fMergeForward,
931 IMedium *pParentForTarget,
932 ComSafeArrayIn(IMedium *, aChildrenToReparent));
933 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
934 ISnapshot *aSnapshot,
935 MachineState_T *aMachineState,
936 IProgress **aProgress);
937 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
938 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
939 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
940 LONG64 aTimestamp, IN_BSTR aFlags);
941 STDMETHOD(LockMedia)() { return lockMedia(); }
942 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
943
944 // public methods only for internal purposes
945
946 virtual bool isSessionMachine() const
947 {
948 return true;
949 }
950
951 bool checkForDeath();
952
953 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
954 HRESULT onStorageControllerChange();
955 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
956 HRESULT onSerialPortChange(ISerialPort *serialPort);
957 HRESULT onParallelPortChange(IParallelPort *parallelPort);
958 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
959 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
960 HRESULT onVRDPServerChange(BOOL aRestart);
961 HRESULT onUSBControllerChange();
962 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
963 IVirtualBoxErrorInfo *aError,
964 ULONG aMaskedIfs);
965 HRESULT onUSBDeviceDetach(IN_BSTR aId,
966 IVirtualBoxErrorInfo *aError);
967 HRESULT onSharedFolderChange();
968
969 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
970
971private:
972
973 struct SnapshotData
974 {
975 SnapshotData() : mLastState(MachineState_Null) {}
976
977 MachineState_T mLastState;
978
979 // used when taking snapshot
980 ComObjPtr<Snapshot> mSnapshot;
981
982 // used when saving state
983 Guid mProgressId;
984 Utf8Str mStateFilePath;
985 };
986
987 struct Uninit
988 {
989 enum Reason { Unexpected, Abnormal, Normal };
990 };
991
992 struct SnapshotTask;
993 struct DeleteSnapshotTask;
994 struct RestoreSnapshotTask;
995
996 friend struct DeleteSnapshotTask;
997 friend struct RestoreSnapshotTask;
998
999 void uninit(Uninit::Reason aReason);
1000
1001 HRESULT endSavingState(BOOL aSuccess);
1002
1003 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
1004
1005 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1006 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1007
1008 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1009 const Guid &machineId,
1010 const Guid &snapshotId,
1011 bool fOnlineMergePossible,
1012 MediumLockList *aVMMALockList,
1013 ComObjPtr<Medium> &aSource,
1014 ComObjPtr<Medium> &aTarget,
1015 bool &fMergeForward,
1016 ComObjPtr<Medium> &pParentForTarget,
1017 MediaList &aChildrenToReparent,
1018 bool &fNeedOnlineMerge,
1019 MediumLockList * &aMediumLockList);
1020 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1021 const ComObjPtr<Medium> &aSource,
1022 const MediaList &aChildrenToReparent,
1023 bool fNeedsOnlineMerge,
1024 MediumLockList *aMediumLockList,
1025 const Guid &aMediumId,
1026 const Guid &aSnapshotId);
1027 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1028 const ComObjPtr<Medium> &aSource,
1029 const ComObjPtr<Medium> &aTarget,
1030 bool fMergeForward,
1031 const ComObjPtr<Medium> &pParentForTarget,
1032 const MediaList &aChildrenToReparent,
1033 MediumLockList *aMediumLockList,
1034 ComObjPtr<Progress> &aProgress,
1035 bool *pfNeedsMachineSaveSettings);
1036
1037 HRESULT lockMedia();
1038 void unlockMedia();
1039
1040 HRESULT setMachineState(MachineState_T aMachineState);
1041 HRESULT updateMachineStateOnClient();
1042
1043 HRESULT mRemoveSavedState;
1044
1045 SnapshotData mSnapshotData;
1046
1047 /** interprocess semaphore handle for this machine */
1048#if defined(RT_OS_WINDOWS)
1049 HANDLE mIPCSem;
1050 Bstr mIPCSemName;
1051 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1052 ComPtr<IInternalSessionControl> *aControl,
1053 HANDLE *aIPCSem, bool aAllowClosing);
1054#elif defined(RT_OS_OS2)
1055 HMTX mIPCSem;
1056 Bstr mIPCSemName;
1057 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1058 ComPtr<IInternalSessionControl> *aControl,
1059 HMTX *aIPCSem, bool aAllowClosing);
1060#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1061 int mIPCSem;
1062# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1063 Bstr mIPCKey;
1064# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1065#else
1066# error "Port me!"
1067#endif
1068
1069 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1070};
1071
1072// SnapshotMachine class
1073////////////////////////////////////////////////////////////////////////////////
1074
1075/**
1076 * @note Notes on locking objects of this class:
1077 * SnapshotMachine shares some data with the primary Machine instance (pointed
1078 * to by the |mPeer| member). In order to provide data consistency it also
1079 * shares its lock handle. This means that whenever you lock a SessionMachine
1080 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1081 * instance is also locked in the same lock mode. Keep it in mind.
1082 */
1083class ATL_NO_VTABLE SnapshotMachine :
1084 public Machine
1085{
1086public:
1087 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1088
1089 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1090
1091 DECLARE_PROTECT_FINAL_CONSTRUCT()
1092
1093 BEGIN_COM_MAP(SnapshotMachine)
1094 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1095 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1096 COM_INTERFACE_ENTRY(IMachine)
1097 END_COM_MAP()
1098
1099 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1100
1101 HRESULT FinalConstruct();
1102 void FinalRelease();
1103
1104 // public initializer/uninitializer for internal purposes only
1105 HRESULT init(SessionMachine *aSessionMachine,
1106 IN_GUID aSnapshotId,
1107 const Utf8Str &aStateFilePath);
1108 HRESULT init(Machine *aMachine,
1109 const settings::Hardware &hardware,
1110 const settings::Storage &storage,
1111 IN_GUID aSnapshotId,
1112 const Utf8Str &aStateFilePath);
1113 void uninit();
1114
1115 // util::Lockable interface
1116 RWLockHandle *lockHandle() const;
1117
1118 // public methods only for internal purposes
1119
1120 virtual bool isSnapshotMachine() const
1121 {
1122 return true;
1123 }
1124
1125 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1126
1127 // unsafe inline public methods for internal purposes only (ensure there is
1128 // a caller and a read lock before calling them!)
1129
1130 const Guid& getSnapshotId() const { return mSnapshotId; }
1131
1132private:
1133
1134 Guid mSnapshotId;
1135
1136 friend class Snapshot;
1137};
1138
1139// third party methods that depend on SnapshotMachine definiton
1140
1141inline const Guid &Machine::getSnapshotId() const
1142{
1143 return (isSnapshotMachine())
1144 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1145 : Guid::Empty;
1146}
1147
1148
1149#endif // ____H_MACHINEIMPL
1150/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette