VirtualBox

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

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

Main, FE/VBoxManage: Make it possible to mark specific controllers as bootable which means that the BIOS can access devices attached to the controller to boot from it

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.5 KB
Line 
1/* $Id: MachineImpl.h 34010 2010-11-11 20:17:47Z 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(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
510 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
511 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
512 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
513 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
514 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
515 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
516 STDMETHOD(HotPlugCPU(ULONG aCpu));
517 STDMETHOD(HotUnplugCPU(ULONG aCpu));
518 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
519 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
520 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
521
522 // public methods only for internal purposes
523
524 virtual bool isSnapshotMachine() const
525 {
526 return false;
527 }
528
529 virtual bool isSessionMachine() const
530 {
531 return false;
532 }
533
534 /**
535 * Override of the default locking class to be used for validating lock
536 * order with the standard member lock handle.
537 */
538 virtual VBoxLockingClass getLockingClass() const
539 {
540 return LOCKCLASS_MACHINEOBJECT;
541 }
542
543 /// @todo (dmik) add lock and make non-inlined after revising classes
544 // that use it. Note: they should enter Machine lock to keep the returned
545 // information valid!
546 bool isRegistered() { return !!mData->mRegistered; }
547
548 // unsafe inline public methods for internal purposes only (ensure there is
549 // a caller and a read lock before calling them!)
550
551 /**
552 * Returns the VirtualBox object this machine belongs to.
553 *
554 * @note This method doesn't check this object's readiness. Intended to be
555 * used by ready Machine children (whose readiness is bound to the parent's
556 * one) or after doing addCaller() manually.
557 */
558 VirtualBox* getVirtualBox() const { return mParent; }
559
560 /**
561 * Returns this machine ID.
562 *
563 * @note This method doesn't check this object's readiness. Intended to be
564 * used by ready Machine children (whose readiness is bound to the parent's
565 * one) or after adding a caller manually.
566 */
567 const Guid& getId() const { return mData->mUuid; }
568
569 /**
570 * Returns the snapshot ID this machine represents or an empty UUID if this
571 * instance is not SnapshotMachine.
572 *
573 * @note This method doesn't check this object's readiness. Intended to be
574 * used by ready Machine children (whose readiness is bound to the parent's
575 * one) or after adding a caller manually.
576 */
577 inline const Guid& getSnapshotId() const;
578
579 /**
580 * Returns this machine's full settings file path.
581 *
582 * @note This method doesn't lock this object or check its readiness.
583 * Intended to be used only after doing addCaller() manually and locking it
584 * for reading.
585 */
586 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
587
588 /**
589 * Returns this machine name.
590 *
591 * @note This method doesn't lock this object or check its readiness.
592 * Intended to be used only after doing addCaller() manually and locking it
593 * for reading.
594 */
595 const Utf8Str& getName() const { return mUserData->s.strName; }
596
597 enum
598 {
599 IsModified_MachineData = 0x0001,
600 IsModified_Storage = 0x0002,
601 IsModified_NetworkAdapters = 0x0008,
602 IsModified_SerialPorts = 0x0010,
603 IsModified_ParallelPorts = 0x0020,
604 IsModified_VRDEServer = 0x0040,
605 IsModified_AudioAdapter = 0x0080,
606 IsModified_USB = 0x0100,
607 IsModified_BIOS = 0x0200,
608 IsModified_SharedFolders = 0x0400,
609 IsModified_Snapshots = 0x0800
610 };
611
612 void setModified(uint32_t fl);
613
614 // callback handlers
615 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
616 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
617 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
618 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
619 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
620 virtual HRESULT onVRDEServerChange(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 onCPUExecutionCapChange(ULONG /* aExecutionCap */) { 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 const Guid *puuidRegistry);
725 HRESULT loadSnapshot(const settings::Snapshot &data,
726 const Guid &aCurSnapshotId,
727 Snapshot *aParentSnapshot);
728 HRESULT loadHardware(const settings::Hardware &data);
729 HRESULT loadStorageControllers(const settings::Storage &data,
730 const Guid *puuidRegistry,
731 const Guid *puuidSnapshot);
732 HRESULT loadStorageDevices(StorageController *aStorageController,
733 const settings::StorageController &data,
734 const Guid *puuidRegistry,
735 const Guid *puuidSnapshot);
736
737 HRESULT findSnapshotById(const Guid &aId,
738 ComObjPtr<Snapshot> &aSnapshot,
739 bool aSetError = false);
740 HRESULT findSnapshotByName(const Utf8Str &strName,
741 ComObjPtr<Snapshot> &aSnapshot,
742 bool aSetError = false);
743
744 HRESULT getStorageControllerByName(const Utf8Str &aName,
745 ComObjPtr<StorageController> &aStorageController,
746 bool aSetError = false);
747
748 HRESULT getMediumAttachmentsOfController(CBSTR aName,
749 MediaData::AttachmentList &aAttachments);
750
751 enum
752 {
753 /* flags for #saveSettings() */
754 SaveS_ResetCurStateModified = 0x01,
755 SaveS_InformCallbacksAnyway = 0x02,
756 SaveS_Force = 0x04,
757 /* flags for #saveStateSettings() */
758 SaveSTS_CurStateModified = 0x20,
759 SaveSTS_StateFilePath = 0x40,
760 SaveSTS_StateTimeStamp = 0x80
761 };
762
763 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
764 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
765
766 void copyMachineDataToSettings(settings::MachineConfigFile &config);
767 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
768 HRESULT saveHardware(settings::Hardware &data);
769 HRESULT saveStorageControllers(settings::Storage &data);
770 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
771 settings::StorageController &data);
772 HRESULT saveStateSettings(int aFlags);
773
774 HRESULT createImplicitDiffs(IProgress *aProgress,
775 ULONG aWeight,
776 bool aOnline,
777 GuidList *pllRegistriesThatNeedSaving);
778 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
779
780 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
781 IN_BSTR aControllerName,
782 LONG aControllerPort,
783 LONG aDevice);
784 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
785 ComObjPtr<Medium> pMedium);
786 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
787 Guid &id);
788
789 HRESULT detachDevice(MediumAttachment *pAttach,
790 AutoWriteLock &writeLock,
791 Snapshot *pSnapshot,
792 GuidList *pllRegistriesThatNeedSaving);
793 HRESULT detachAllMedia(AutoWriteLock &writeLock,
794 Snapshot *pSnapshot,
795 CleanupMode_T cleanupMode,
796 MediaList &llMedia);
797
798 void commitMedia(bool aOnline = false);
799 void rollbackMedia();
800
801 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
802
803 void rollback(bool aNotify);
804 void commit();
805 void copyFrom(Machine *aThat);
806
807 struct DeleteTask;
808 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
809 HRESULT deleteTaskWorker(DeleteTask &task);
810
811#ifdef VBOX_WITH_GUEST_PROPS
812 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
813 LONG64 *aTimestamp, BSTR *aFlags) const;
814 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
815 LONG64 *aTimestamp, BSTR *aFlags) const;
816 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
817 IN_BSTR aFlags);
818 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
819 IN_BSTR aFlags);
820 HRESULT enumerateGuestPropertiesInService
821 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
822 ComSafeArrayOut(BSTR, aValues),
823 ComSafeArrayOut(LONG64, aTimestamps),
824 ComSafeArrayOut(BSTR, aFlags));
825 HRESULT enumerateGuestPropertiesOnVM
826 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
827 ComSafeArrayOut(BSTR, aValues),
828 ComSafeArrayOut(LONG64, aTimestamps),
829 ComSafeArrayOut(BSTR, aFlags));
830#endif /* VBOX_WITH_GUEST_PROPS */
831
832#ifdef VBOX_WITH_RESOURCE_USAGE_API
833 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
834
835 pm::CollectorGuestHAL *mGuestHAL;
836#endif /* VBOX_WITH_RESOURCE_USAGE_API */
837
838 Machine* const mPeer;
839
840 VirtualBox * const mParent;
841
842 Shareable<Data> mData;
843 Shareable<SSData> mSSData;
844
845 Backupable<UserData> mUserData;
846 Backupable<HWData> mHWData;
847 Backupable<MediaData> mMediaData;
848
849 // the following fields need special backup/rollback/commit handling,
850 // so they cannot be a part of HWData
851
852 const ComObjPtr<VRDEServer> mVRDEServer;
853 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
854 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
855 const ComObjPtr<AudioAdapter> mAudioAdapter;
856 const ComObjPtr<USBController> mUSBController;
857 const ComObjPtr<BIOSSettings> mBIOSSettings;
858 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
859
860 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
861 Backupable<StorageControllerList> mStorageControllers;
862
863 friend class SessionMachine;
864 friend class SnapshotMachine;
865 friend class Appliance;
866 friend class VirtualBox;
867};
868
869// SessionMachine class
870////////////////////////////////////////////////////////////////////////////////
871
872/**
873 * @note Notes on locking objects of this class:
874 * SessionMachine shares some data with the primary Machine instance (pointed
875 * to by the |mPeer| member). In order to provide data consistency it also
876 * shares its lock handle. This means that whenever you lock a SessionMachine
877 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
878 * instance is also locked in the same lock mode. Keep it in mind.
879 */
880class ATL_NO_VTABLE SessionMachine :
881 public Machine,
882 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
883{
884public:
885 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
886
887 DECLARE_NOT_AGGREGATABLE(SessionMachine)
888
889 DECLARE_PROTECT_FINAL_CONSTRUCT()
890
891 BEGIN_COM_MAP(SessionMachine)
892 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
893 COM_INTERFACE_ENTRY(ISupportErrorInfo)
894 COM_INTERFACE_ENTRY(IMachine)
895 COM_INTERFACE_ENTRY(IInternalMachineControl)
896 END_COM_MAP()
897
898 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
899
900 HRESULT FinalConstruct();
901 void FinalRelease();
902
903 // public initializer/uninitializer for internal purposes only
904 HRESULT init(Machine *aMachine);
905 void uninit() { uninit(Uninit::Unexpected); }
906
907 // util::Lockable interface
908 RWLockHandle *lockHandle() const;
909
910 // IInternalMachineControl methods
911 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
912 STDMETHOD(UpdateState)(MachineState_T machineState);
913 STDMETHOD(GetIPCId)(BSTR *id);
914 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
915 STDMETHOD(EndPowerUp)(LONG iResult);
916 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
917 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
918 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
919 STDMETHOD(AutoCaptureUSBDevices)();
920 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
921 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
922 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
923 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
924 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
925 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
926 IN_BSTR aName,
927 IN_BSTR aDescription,
928 IProgress *aConsoleProgress,
929 BOOL fTakingSnapshotOnline,
930 BSTR *aStateFilePath);
931 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
932 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
933 MachineState_T *aMachineState, IProgress **aProgress);
934 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
935 IMedium *aSource, IMedium *aTarget,
936 BOOL fMergeForward,
937 IMedium *pParentForTarget,
938 ComSafeArrayIn(IMedium *, aChildrenToReparent));
939 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
940 ISnapshot *aSnapshot,
941 MachineState_T *aMachineState,
942 IProgress **aProgress);
943 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
944 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
945 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
946 LONG64 aTimestamp, IN_BSTR aFlags);
947 STDMETHOD(LockMedia)() { return lockMedia(); }
948 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
949
950 // public methods only for internal purposes
951
952 virtual bool isSessionMachine() const
953 {
954 return true;
955 }
956
957 bool checkForDeath();
958
959 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
960 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
961 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
962 HRESULT onStorageControllerChange();
963 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
964 HRESULT onSerialPortChange(ISerialPort *serialPort);
965 HRESULT onParallelPortChange(IParallelPort *parallelPort);
966 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
967 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
968 HRESULT onVRDEServerChange(BOOL aRestart);
969 HRESULT onUSBControllerChange();
970 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
971 IVirtualBoxErrorInfo *aError,
972 ULONG aMaskedIfs);
973 HRESULT onUSBDeviceDetach(IN_BSTR aId,
974 IVirtualBoxErrorInfo *aError);
975 HRESULT onSharedFolderChange();
976
977 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
978
979private:
980
981 struct SnapshotData
982 {
983 SnapshotData() : mLastState(MachineState_Null) {}
984
985 MachineState_T mLastState;
986
987 // used when taking snapshot
988 ComObjPtr<Snapshot> mSnapshot;
989
990 // used when saving state
991 Utf8Str mStateFilePath;
992 ComObjPtr<Progress> mProgress;
993 };
994
995 struct Uninit
996 {
997 enum Reason { Unexpected, Abnormal, Normal };
998 };
999
1000 struct SnapshotTask;
1001 struct DeleteSnapshotTask;
1002 struct RestoreSnapshotTask;
1003
1004 friend struct DeleteSnapshotTask;
1005 friend struct RestoreSnapshotTask;
1006
1007 void uninit(Uninit::Reason aReason);
1008
1009 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1010
1011 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1012 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1013
1014 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1015 const Guid &machineId,
1016 const Guid &snapshotId,
1017 bool fOnlineMergePossible,
1018 MediumLockList *aVMMALockList,
1019 ComObjPtr<Medium> &aSource,
1020 ComObjPtr<Medium> &aTarget,
1021 bool &fMergeForward,
1022 ComObjPtr<Medium> &pParentForTarget,
1023 MediaList &aChildrenToReparent,
1024 bool &fNeedOnlineMerge,
1025 MediumLockList * &aMediumLockList);
1026 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1027 const ComObjPtr<Medium> &aSource,
1028 const MediaList &aChildrenToReparent,
1029 bool fNeedsOnlineMerge,
1030 MediumLockList *aMediumLockList,
1031 const Guid &aMediumId,
1032 const Guid &aSnapshotId);
1033 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1034 const ComObjPtr<Medium> &aSource,
1035 const ComObjPtr<Medium> &aTarget,
1036 bool fMergeForward,
1037 const ComObjPtr<Medium> &pParentForTarget,
1038 const MediaList &aChildrenToReparent,
1039 MediumLockList *aMediumLockList,
1040 ComObjPtr<Progress> &aProgress,
1041 bool *pfNeedsMachineSaveSettings);
1042
1043 HRESULT lockMedia();
1044 void unlockMedia();
1045
1046 HRESULT setMachineState(MachineState_T aMachineState);
1047 HRESULT updateMachineStateOnClient();
1048
1049 HRESULT mRemoveSavedState;
1050
1051 SnapshotData mSnapshotData;
1052
1053 /** interprocess semaphore handle for this machine */
1054#if defined(RT_OS_WINDOWS)
1055 HANDLE mIPCSem;
1056 Bstr mIPCSemName;
1057 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1058 ComPtr<IInternalSessionControl> *aControl,
1059 HANDLE *aIPCSem, bool aAllowClosing);
1060#elif defined(RT_OS_OS2)
1061 HMTX mIPCSem;
1062 Bstr mIPCSemName;
1063 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1064 ComPtr<IInternalSessionControl> *aControl,
1065 HMTX *aIPCSem, bool aAllowClosing);
1066#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1067 int mIPCSem;
1068# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1069 Bstr mIPCKey;
1070# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1071#else
1072# error "Port me!"
1073#endif
1074
1075 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1076};
1077
1078// SnapshotMachine class
1079////////////////////////////////////////////////////////////////////////////////
1080
1081/**
1082 * @note Notes on locking objects of this class:
1083 * SnapshotMachine shares some data with the primary Machine instance (pointed
1084 * to by the |mPeer| member). In order to provide data consistency it also
1085 * shares its lock handle. This means that whenever you lock a SessionMachine
1086 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1087 * instance is also locked in the same lock mode. Keep it in mind.
1088 */
1089class ATL_NO_VTABLE SnapshotMachine :
1090 public Machine
1091{
1092public:
1093 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1094
1095 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1096
1097 DECLARE_PROTECT_FINAL_CONSTRUCT()
1098
1099 BEGIN_COM_MAP(SnapshotMachine)
1100 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1101 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1102 COM_INTERFACE_ENTRY(IMachine)
1103 END_COM_MAP()
1104
1105 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1106
1107 HRESULT FinalConstruct();
1108 void FinalRelease();
1109
1110 // public initializer/uninitializer for internal purposes only
1111 HRESULT init(SessionMachine *aSessionMachine,
1112 IN_GUID aSnapshotId,
1113 const Utf8Str &aStateFilePath);
1114 HRESULT init(Machine *aMachine,
1115 const settings::Hardware &hardware,
1116 const settings::Storage &storage,
1117 IN_GUID aSnapshotId,
1118 const Utf8Str &aStateFilePath);
1119 void uninit();
1120
1121 // util::Lockable interface
1122 RWLockHandle *lockHandle() const;
1123
1124 // public methods only for internal purposes
1125
1126 virtual bool isSnapshotMachine() const
1127 {
1128 return true;
1129 }
1130
1131 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1132
1133 // unsafe inline public methods for internal purposes only (ensure there is
1134 // a caller and a read lock before calling them!)
1135
1136 const Guid& getSnapshotId() const { return mSnapshotId; }
1137
1138private:
1139
1140 Guid mSnapshotId;
1141
1142 friend class Snapshot;
1143};
1144
1145// third party methods that depend on SnapshotMachine definition
1146
1147inline const Guid &Machine::getSnapshotId() const
1148{
1149 return (isSnapshotMachine())
1150 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1151 : Guid::Empty;
1152}
1153
1154
1155#endif // ____H_MACHINEIMPL
1156/* 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