VirtualBox

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

最後變更 在這個檔案從34772是 34770,由 vboxsync 提交於 14 年 前

Warning.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 47.5 KB
 
1/* $Id: MachineImpl.h 34770 2010-12-07 09:45:08Z 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.alldomusa.eu.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 "PciDeviceAttachmentImpl.h"
27#include "MediumLock.h"
28#include "NetworkAdapterImpl.h"
29#include "AudioAdapterImpl.h"
30#include "SerialPortImpl.h"
31#include "ParallelPortImpl.h"
32#include "BIOSSettingsImpl.h"
33#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
34#include "BandwidthControlImpl.h"
35#include "VBox/settings.h"
36#ifdef VBOX_WITH_RESOURCE_USAGE_API
37#include "Performance.h"
38#include "PerformanceImpl.h"
39#endif /* VBOX_WITH_RESOURCE_USAGE_API */
40
41// generated header
42#include "SchemaDefs.h"
43
44#include "VBox/com/ErrorInfo.h"
45
46#include <iprt/file.h>
47#include <iprt/thread.h>
48#include <iprt/time.h>
49
50#include <list>
51
52// defines
53////////////////////////////////////////////////////////////////////////////////
54
55// helper declarations
56////////////////////////////////////////////////////////////////////////////////
57
58class Progress;
59class ProgressProxy;
60class Keyboard;
61class Mouse;
62class Display;
63class MachineDebugger;
64class USBController;
65class Snapshot;
66class SharedFolder;
67class HostUSBDevice;
68class StorageController;
69
70class SessionMachine;
71
72namespace settings
73{
74 class MachineConfigFile;
75 struct Snapshot;
76 struct Hardware;
77 struct Storage;
78 struct StorageController;
79 struct MachineRegistryEntry;
80}
81
82// Machine class
83////////////////////////////////////////////////////////////////////////////////
84
85class ATL_NO_VTABLE Machine :
86 public VirtualBoxBase,
87 VBOX_SCRIPTABLE_IMPL(IMachine)
88{
89 Q_OBJECT
90
91public:
92
93 enum StateDependency
94 {
95 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
96 };
97
98 /**
99 * Internal machine data.
100 *
101 * Only one instance of this data exists per every machine -- it is shared
102 * by the Machine, SessionMachine and all SnapshotMachine instances
103 * associated with the given machine using the util::Shareable template
104 * through the mData variable.
105 *
106 * @note |const| members are persistent during lifetime so can be
107 * accessed without locking.
108 *
109 * @note There is no need to lock anything inside init() or uninit()
110 * methods, because they are always serialized (see AutoCaller).
111 */
112 struct Data
113 {
114 /**
115 * Data structure to hold information about sessions opened for the
116 * given machine.
117 */
118 struct Session
119 {
120 /** Control of the direct session opened by lockMachine() */
121 ComPtr<IInternalSessionControl> mDirectControl;
122
123 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
124
125 /** list of controls of all opened remote sessions */
126 RemoteControlList mRemoteControls;
127
128 /** openRemoteSession() and OnSessionEnd() progress indicator */
129 ComObjPtr<ProgressProxy> mProgress;
130
131 /**
132 * PID of the session object that must be passed to openSession() to
133 * finalize the openRemoteSession() request (i.e., PID of the
134 * process created by openRemoteSession())
135 */
136 RTPROCESS mPid;
137
138 /** Current session state */
139 SessionState_T mState;
140
141 /** Session type string (for indirect sessions) */
142 Bstr mType;
143
144 /** Session machine object */
145 ComObjPtr<SessionMachine> mMachine;
146
147 /** Medium object lock collection. */
148 MediumLockListMap mLockedMedia;
149 };
150
151 Data();
152 ~Data();
153
154 const Guid mUuid;
155 BOOL mRegistered;
156
157 Utf8Str m_strConfigFile;
158 Utf8Str m_strConfigFileFull;
159
160 // machine settings XML file
161 settings::MachineConfigFile *pMachineConfigFile;
162 uint32_t flModifications;
163
164 BOOL mAccessible;
165 com::ErrorInfo mAccessError;
166
167 MachineState_T mMachineState;
168 RTTIMESPEC mLastStateChange;
169
170 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
171 uint32_t mMachineStateDeps;
172 RTSEMEVENTMULTI mMachineStateDepsSem;
173 uint32_t mMachineStateChangePending;
174
175 BOOL mCurrentStateModified;
176 /** Guest properties have been modified and need saving since the
177 * machine was started, or there are transient properties which need
178 * deleting and the machine is being shut down. */
179 BOOL mGuestPropertiesModified;
180
181 Session mSession;
182
183 ComObjPtr<Snapshot> mFirstSnapshot;
184 ComObjPtr<Snapshot> mCurrentSnapshot;
185
186 // list of files to delete in Delete(); this list is filled by Unregister()
187 std::list<Utf8Str> llFilesToDelete;
188 };
189
190 /**
191 * Saved state data.
192 *
193 * It's actually only the state file path string, but it needs to be
194 * separate from Data, because Machine and SessionMachine instances
195 * share it, while SnapshotMachine does not.
196 *
197 * The data variable is |mSSData|.
198 */
199 struct SSData
200 {
201 Utf8Str mStateFilePath;
202 };
203
204 /**
205 * User changeable machine data.
206 *
207 * This data is common for all machine snapshots, i.e. it is shared
208 * by all SnapshotMachine instances associated with the given machine
209 * using the util::Backupable template through the |mUserData| variable.
210 *
211 * SessionMachine instances can alter this data and discard changes.
212 *
213 * @note There is no need to lock anything inside init() or uninit()
214 * methods, because they are always serialized (see AutoCaller).
215 */
216 struct UserData
217 {
218 settings::MachineUserData s;
219 };
220
221 /**
222 * Hardware data.
223 *
224 * This data is unique for a machine and for every machine snapshot.
225 * Stored using the util::Backupable template in the |mHWData| variable.
226 *
227 * SessionMachine instances can alter this data and discard changes.
228 */
229 struct HWData
230 {
231 /**
232 * Data structure to hold information about a guest property.
233 */
234 struct GuestProperty {
235 /** Property name */
236 Utf8Str strName;
237 /** Property value */
238 Utf8Str strValue;
239 /** Property timestamp */
240 LONG64 mTimestamp;
241 /** Property flags */
242 ULONG mFlags;
243 };
244
245 HWData();
246 ~HWData();
247
248 Bstr mHWVersion;
249 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
250 ULONG mMemorySize;
251 ULONG mMemoryBalloonSize;
252 BOOL mPageFusionEnabled;
253 ULONG mVRAMSize;
254 ULONG mMonitorCount;
255 BOOL mHWVirtExEnabled;
256 BOOL mHWVirtExExclusive;
257 BOOL mHWVirtExNestedPagingEnabled;
258 BOOL mHWVirtExLargePagesEnabled;
259 BOOL mHWVirtExVPIDEnabled;
260 BOOL mHWVirtExForceEnabled;
261 BOOL mAccelerate2DVideoEnabled;
262 BOOL mPAEEnabled;
263 BOOL mSyntheticCpu;
264 ULONG mCPUCount;
265 BOOL mCPUHotPlugEnabled;
266 ULONG mCpuExecutionCap;
267 BOOL mAccelerate3DEnabled;
268 BOOL mHpetEnabled;
269
270 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
271
272 settings::CpuIdLeaf mCpuIdStdLeafs[10];
273 settings::CpuIdLeaf mCpuIdExtLeafs[10];
274
275 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
276
277 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
278 SharedFolderList mSharedFolders;
279
280 ClipboardMode_T mClipboardMode;
281
282 typedef std::list<GuestProperty> GuestPropertyList;
283 GuestPropertyList mGuestProperties;
284 Utf8Str mGuestPropertyNotificationPatterns;
285
286 FirmwareType_T mFirmwareType;
287 KeyboardHidType_T mKeyboardHidType;
288 PointingHidType_T mPointingHidType;
289 ChipsetType_T mChipsetType;
290
291 BOOL mIoCacheEnabled;
292 ULONG mIoCacheSize;
293 };
294
295 /**
296 * Hard disk and other media data.
297 *
298 * The usage policy is the same as for HWData, but a separate structure
299 * is necessary because hard disk data requires different procedures when
300 * taking or deleting snapshots, etc.
301 *
302 * The data variable is |mMediaData|.
303 */
304 struct MediaData
305 {
306 MediaData();
307 ~MediaData();
308
309 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
310 AttachmentList mAttachments;
311 };
312
313 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
314
315 DECLARE_NOT_AGGREGATABLE(Machine)
316
317 DECLARE_PROTECT_FINAL_CONSTRUCT()
318
319 BEGIN_COM_MAP(Machine)
320 COM_INTERFACE_ENTRY(ISupportErrorInfo)
321 COM_INTERFACE_ENTRY(IMachine)
322 COM_INTERFACE_ENTRY(IDispatch)
323 END_COM_MAP()
324
325 DECLARE_EMPTY_CTOR_DTOR(Machine)
326
327 HRESULT FinalConstruct();
328 void FinalRelease();
329
330 // public initializer/uninitializer for internal purposes only:
331
332 // initializer for creating a new, empty machine
333 HRESULT init(VirtualBox *aParent,
334 const Utf8Str &strConfigFile,
335 const Utf8Str &strName,
336 GuestOSType *aOsType,
337 const Guid &aId,
338 bool fForceOverwrite);
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 fForceOverwrite);
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(CPUExecutionCap))(ULONG *aExecutionCap);
388 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
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(VRDEServer))(IVRDEServer **vrdeServer);
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(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
472 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
473 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
474 LONG aDevice, IMedium *aMedium, BOOL aForce);
475 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
476 IMedium **aMedium);
477 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
478 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
479 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
480 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
481 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
482 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
483 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
484 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
485 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
486 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
487 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
488 STDMETHOD(RemoveAllCPUIDLeaves)();
489 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
490 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
491 STDMETHOD(SaveSettings)();
492 STDMETHOD(DiscardSettings)();
493 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
494 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
495 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
496 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
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(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
514 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
515 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
516 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
517 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
518 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
519 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
520 STDMETHOD(HotPlugCPU(ULONG aCpu));
521 STDMETHOD(HotUnplugCPU(ULONG aCpu));
522 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
523 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
524 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
525 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, IEventContext *eventContext, BOOL tryToUnbind));
526 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
527 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
528 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
529 // public methods only for internal purposes
530
531 virtual bool isSnapshotMachine() const
532 {
533 return false;
534 }
535
536 virtual bool isSessionMachine() const
537 {
538 return false;
539 }
540
541 /**
542 * Override of the default locking class to be used for validating lock
543 * order with the standard member lock handle.
544 */
545 virtual VBoxLockingClass getLockingClass() const
546 {
547 return LOCKCLASS_MACHINEOBJECT;
548 }
549
550 /// @todo (dmik) add lock and make non-inlined after revising classes
551 // that use it. Note: they should enter Machine lock to keep the returned
552 // information valid!
553 bool isRegistered() { return !!mData->mRegistered; }
554
555 // unsafe inline public methods for internal purposes only (ensure there is
556 // a caller and a read lock before calling them!)
557
558 /**
559 * Returns the VirtualBox object this machine belongs to.
560 *
561 * @note This method doesn't check this object's readiness. Intended to be
562 * used by ready Machine children (whose readiness is bound to the parent's
563 * one) or after doing addCaller() manually.
564 */
565 VirtualBox* getVirtualBox() const { return mParent; }
566
567 /**
568 * Returns this machine ID.
569 *
570 * @note This method doesn't check this object's readiness. Intended to be
571 * used by ready Machine children (whose readiness is bound to the parent's
572 * one) or after adding a caller manually.
573 */
574 const Guid& getId() const { return mData->mUuid; }
575
576 /**
577 * Returns the snapshot ID this machine represents or an empty UUID if this
578 * instance is not SnapshotMachine.
579 *
580 * @note This method doesn't check this object's readiness. Intended to be
581 * used by ready Machine children (whose readiness is bound to the parent's
582 * one) or after adding a caller manually.
583 */
584 inline const Guid& getSnapshotId() const;
585
586 /**
587 * Returns this machine's full settings file path.
588 *
589 * @note This method doesn't lock this object or check its readiness.
590 * Intended to be used only after doing addCaller() manually and locking it
591 * for reading.
592 */
593 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
594
595 /**
596 * Returns this machine name.
597 *
598 * @note This method doesn't lock this object or check its readiness.
599 * Intended to be used only after doing addCaller() manually and locking it
600 * for reading.
601 */
602 const Utf8Str& getName() const { return mUserData->s.strName; }
603
604 enum
605 {
606 IsModified_MachineData = 0x0001,
607 IsModified_Storage = 0x0002,
608 IsModified_NetworkAdapters = 0x0008,
609 IsModified_SerialPorts = 0x0010,
610 IsModified_ParallelPorts = 0x0020,
611 IsModified_VRDEServer = 0x0040,
612 IsModified_AudioAdapter = 0x0080,
613 IsModified_USB = 0x0100,
614 IsModified_BIOS = 0x0200,
615 IsModified_SharedFolders = 0x0400,
616 IsModified_Snapshots = 0x0800,
617 IsModified_BandwidthControl = 0x1000
618 };
619
620 void setModified(uint32_t fl);
621
622 // callback handlers
623 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
624 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
625 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
626 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
627 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
628 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
629 virtual HRESULT onUSBControllerChange() { return S_OK; }
630 virtual HRESULT onStorageControllerChange() { return S_OK; }
631 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
632 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
633 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
634 virtual HRESULT onSharedFolderChange() { return S_OK; }
635 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
636
637 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
638
639 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
640 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
641
642 void getLogFolder(Utf8Str &aLogFolder);
643 Utf8Str queryLogFilename(ULONG idx);
644
645 HRESULT openRemoteSession(IInternalSessionControl *aControl,
646 IN_BSTR aType, IN_BSTR aEnvironment,
647 ProgressProxy *aProgress);
648
649 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
650 {
651 HRESULT rc;
652 *directControl = mData->mSession.mDirectControl;
653
654 if (!*directControl)
655 rc = E_ACCESSDENIED;
656 else
657 rc = S_OK;
658
659 return rc;
660 }
661
662#if defined(RT_OS_WINDOWS)
663
664 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
665 ComPtr<IInternalSessionControl> *aControl = NULL,
666 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
667 bool isSessionSpawning(RTPROCESS *aPID = NULL);
668
669 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
670 ComPtr<IInternalSessionControl> *aControl = NULL,
671 HANDLE *aIPCSem = NULL)
672 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
673
674#elif defined(RT_OS_OS2)
675
676 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
677 ComPtr<IInternalSessionControl> *aControl = NULL,
678 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
679
680 bool isSessionSpawning(RTPROCESS *aPID = NULL);
681
682 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
683 ComPtr<IInternalSessionControl> *aControl = NULL,
684 HMTX *aIPCSem = NULL)
685 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
686
687#else
688
689 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
690 ComPtr<IInternalSessionControl> *aControl = NULL,
691 bool aAllowClosing = false);
692 bool isSessionSpawning();
693
694 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
695 ComPtr<IInternalSessionControl> *aControl = NULL)
696 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
697
698#endif
699
700 bool checkForSpawnFailure();
701
702 HRESULT prepareRegister();
703
704 HRESULT getSharedFolder(CBSTR aName,
705 ComObjPtr<SharedFolder> &aSharedFolder,
706 bool aSetError = false)
707 {
708 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
709 return findSharedFolder(aName, aSharedFolder, aSetError);
710 }
711
712 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
713 MachineState_T *aState = NULL,
714 BOOL *aRegistered = NULL);
715 void releaseStateDependency();
716
717protected:
718
719 HRESULT checkStateDependency(StateDependency aDepType);
720
721 Machine *getMachine();
722
723 void ensureNoStateDependencies();
724
725 virtual HRESULT setMachineState(MachineState_T aMachineState);
726
727 HRESULT findSharedFolder(CBSTR aName,
728 ComObjPtr<SharedFolder> &aSharedFolder,
729 bool aSetError = false);
730
731 HRESULT loadSettings(bool aRegistered);
732 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
733 const Guid *puuidRegistry);
734 HRESULT loadSnapshot(const settings::Snapshot &data,
735 const Guid &aCurSnapshotId,
736 Snapshot *aParentSnapshot);
737 HRESULT loadHardware(const settings::Hardware &data);
738 HRESULT loadStorageControllers(const settings::Storage &data,
739 const Guid *puuidRegistry,
740 const Guid *puuidSnapshot);
741 HRESULT loadStorageDevices(StorageController *aStorageController,
742 const settings::StorageController &data,
743 const Guid *puuidRegistry,
744 const Guid *puuidSnapshot);
745
746 HRESULT findSnapshotById(const Guid &aId,
747 ComObjPtr<Snapshot> &aSnapshot,
748 bool aSetError = false);
749 HRESULT findSnapshotByName(const Utf8Str &strName,
750 ComObjPtr<Snapshot> &aSnapshot,
751 bool aSetError = false);
752
753 HRESULT getStorageControllerByName(const Utf8Str &aName,
754 ComObjPtr<StorageController> &aStorageController,
755 bool aSetError = false);
756
757 HRESULT getMediumAttachmentsOfController(CBSTR aName,
758 MediaData::AttachmentList &aAttachments);
759
760 enum
761 {
762 /* flags for #saveSettings() */
763 SaveS_ResetCurStateModified = 0x01,
764 SaveS_InformCallbacksAnyway = 0x02,
765 SaveS_Force = 0x04,
766 /* flags for #saveStateSettings() */
767 SaveSTS_CurStateModified = 0x20,
768 SaveSTS_StateFilePath = 0x40,
769 SaveSTS_StateTimeStamp = 0x80
770 };
771
772 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
773 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
774
775 void copyMachineDataToSettings(settings::MachineConfigFile &config);
776 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
777 HRESULT saveHardware(settings::Hardware &data);
778 HRESULT saveStorageControllers(settings::Storage &data);
779 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
780 settings::StorageController &data);
781 HRESULT saveStateSettings(int aFlags);
782
783 HRESULT createImplicitDiffs(IProgress *aProgress,
784 ULONG aWeight,
785 bool aOnline,
786 GuidList *pllRegistriesThatNeedSaving);
787 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
788
789 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
790 IN_BSTR aControllerName,
791 LONG aControllerPort,
792 LONG aDevice);
793 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
794 ComObjPtr<Medium> pMedium);
795 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
796 Guid &id);
797
798 HRESULT detachDevice(MediumAttachment *pAttach,
799 AutoWriteLock &writeLock,
800 Snapshot *pSnapshot,
801 GuidList *pllRegistriesThatNeedSaving);
802 HRESULT detachAllMedia(AutoWriteLock &writeLock,
803 Snapshot *pSnapshot,
804 CleanupMode_T cleanupMode,
805 MediaList &llMedia);
806
807 void commitMedia(bool aOnline = false);
808 void rollbackMedia();
809
810 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
811
812 void rollback(bool aNotify);
813 void commit();
814 void copyFrom(Machine *aThat);
815
816 struct DeleteTask;
817 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
818 HRESULT deleteTaskWorker(DeleteTask &task);
819
820#ifdef VBOX_WITH_GUEST_PROPS
821 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
822 LONG64 *aTimestamp, BSTR *aFlags) const;
823 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
824 LONG64 *aTimestamp, BSTR *aFlags) const;
825 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
826 IN_BSTR aFlags);
827 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
828 IN_BSTR aFlags);
829 HRESULT enumerateGuestPropertiesInService
830 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
831 ComSafeArrayOut(BSTR, aValues),
832 ComSafeArrayOut(LONG64, aTimestamps),
833 ComSafeArrayOut(BSTR, aFlags));
834 HRESULT enumerateGuestPropertiesOnVM
835 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
836 ComSafeArrayOut(BSTR, aValues),
837 ComSafeArrayOut(LONG64, aTimestamps),
838 ComSafeArrayOut(BSTR, aFlags));
839#endif /* VBOX_WITH_GUEST_PROPS */
840
841#ifdef VBOX_WITH_RESOURCE_USAGE_API
842 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
843
844 pm::CollectorGuestHAL *mGuestHAL;
845#endif /* VBOX_WITH_RESOURCE_USAGE_API */
846
847 Machine* const mPeer;
848
849 VirtualBox * const mParent;
850
851 Shareable<Data> mData;
852 Shareable<SSData> mSSData;
853
854 Backupable<UserData> mUserData;
855 Backupable<HWData> mHWData;
856 Backupable<MediaData> mMediaData;
857
858 // the following fields need special backup/rollback/commit handling,
859 // so they cannot be a part of HWData
860
861 const ComObjPtr<VRDEServer> mVRDEServer;
862 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
863 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
864 const ComObjPtr<AudioAdapter> mAudioAdapter;
865 const ComObjPtr<USBController> mUSBController;
866 const ComObjPtr<BIOSSettings> mBIOSSettings;
867 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
868 const ComObjPtr<BandwidthControl> mBandwidthControl;
869
870 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
871 Backupable<StorageControllerList> mStorageControllers;
872
873 typedef std::list< ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
874 PciDeviceAssignmentList mPciDeviceAssignments;
875
876 friend class SessionMachine;
877 friend class SnapshotMachine;
878 friend class Appliance;
879 friend class VirtualBox;
880};
881
882// SessionMachine class
883////////////////////////////////////////////////////////////////////////////////
884
885/**
886 * @note Notes on locking objects of this class:
887 * SessionMachine shares some data with the primary Machine instance (pointed
888 * to by the |mPeer| member). In order to provide data consistency it also
889 * shares its lock handle. This means that whenever you lock a SessionMachine
890 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
891 * instance is also locked in the same lock mode. Keep it in mind.
892 */
893class ATL_NO_VTABLE SessionMachine :
894 public Machine,
895 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
896{
897public:
898 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
899
900 DECLARE_NOT_AGGREGATABLE(SessionMachine)
901
902 DECLARE_PROTECT_FINAL_CONSTRUCT()
903
904 BEGIN_COM_MAP(SessionMachine)
905 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
906 COM_INTERFACE_ENTRY(ISupportErrorInfo)
907 COM_INTERFACE_ENTRY(IMachine)
908 COM_INTERFACE_ENTRY(IInternalMachineControl)
909 END_COM_MAP()
910
911 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
912
913 HRESULT FinalConstruct();
914 void FinalRelease();
915
916 // public initializer/uninitializer for internal purposes only
917 HRESULT init(Machine *aMachine);
918 void uninit() { uninit(Uninit::Unexpected); }
919
920 // util::Lockable interface
921 RWLockHandle *lockHandle() const;
922
923 // IInternalMachineControl methods
924 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
925 STDMETHOD(UpdateState)(MachineState_T machineState);
926 STDMETHOD(GetIPCId)(BSTR *id);
927 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
928 STDMETHOD(EndPowerUp)(LONG iResult);
929 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
930 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
931 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
932 STDMETHOD(AutoCaptureUSBDevices)();
933 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
934 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
935 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
936 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
937 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
938 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
939 IN_BSTR aName,
940 IN_BSTR aDescription,
941 IProgress *aConsoleProgress,
942 BOOL fTakingSnapshotOnline,
943 BSTR *aStateFilePath);
944 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
945 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
946 MachineState_T *aMachineState, IProgress **aProgress);
947 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
948 IMedium *aSource, IMedium *aTarget,
949 BOOL fMergeForward,
950 IMedium *pParentForTarget,
951 ComSafeArrayIn(IMedium *, aChildrenToReparent));
952 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
953 ISnapshot *aSnapshot,
954 MachineState_T *aMachineState,
955 IProgress **aProgress);
956 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
957 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
958 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
959 LONG64 aTimestamp, IN_BSTR aFlags);
960 STDMETHOD(LockMedia)() { return lockMedia(); }
961 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
962
963 // public methods only for internal purposes
964
965 virtual bool isSessionMachine() const
966 {
967 return true;
968 }
969
970 bool checkForDeath();
971
972 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
973 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
974 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
975 HRESULT onStorageControllerChange();
976 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
977 HRESULT onSerialPortChange(ISerialPort *serialPort);
978 HRESULT onParallelPortChange(IParallelPort *parallelPort);
979 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
980 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
981 HRESULT onVRDEServerChange(BOOL aRestart);
982 HRESULT onUSBControllerChange();
983 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
984 IVirtualBoxErrorInfo *aError,
985 ULONG aMaskedIfs);
986 HRESULT onUSBDeviceDetach(IN_BSTR aId,
987 IVirtualBoxErrorInfo *aError);
988 HRESULT onSharedFolderChange();
989 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
990
991 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
992
993private:
994
995 struct SnapshotData
996 {
997 SnapshotData() : mLastState(MachineState_Null) {}
998
999 MachineState_T mLastState;
1000
1001 // used when taking snapshot
1002 ComObjPtr<Snapshot> mSnapshot;
1003
1004 // used when saving state
1005 Utf8Str mStateFilePath;
1006 ComObjPtr<Progress> mProgress;
1007 };
1008
1009 struct Uninit
1010 {
1011 enum Reason { Unexpected, Abnormal, Normal };
1012 };
1013
1014 struct SnapshotTask;
1015 struct DeleteSnapshotTask;
1016 struct RestoreSnapshotTask;
1017
1018 friend struct DeleteSnapshotTask;
1019 friend struct RestoreSnapshotTask;
1020
1021 void uninit(Uninit::Reason aReason);
1022
1023 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1024
1025 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1026 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1027
1028 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1029 const Guid &machineId,
1030 const Guid &snapshotId,
1031 bool fOnlineMergePossible,
1032 MediumLockList *aVMMALockList,
1033 ComObjPtr<Medium> &aSource,
1034 ComObjPtr<Medium> &aTarget,
1035 bool &fMergeForward,
1036 ComObjPtr<Medium> &pParentForTarget,
1037 MediaList &aChildrenToReparent,
1038 bool &fNeedOnlineMerge,
1039 MediumLockList * &aMediumLockList);
1040 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1041 const ComObjPtr<Medium> &aSource,
1042 const MediaList &aChildrenToReparent,
1043 bool fNeedsOnlineMerge,
1044 MediumLockList *aMediumLockList,
1045 const Guid &aMediumId,
1046 const Guid &aSnapshotId);
1047 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1048 const ComObjPtr<Medium> &aSource,
1049 const ComObjPtr<Medium> &aTarget,
1050 bool fMergeForward,
1051 const ComObjPtr<Medium> &pParentForTarget,
1052 const MediaList &aChildrenToReparent,
1053 MediumLockList *aMediumLockList,
1054 ComObjPtr<Progress> &aProgress,
1055 bool *pfNeedsMachineSaveSettings);
1056
1057 HRESULT lockMedia();
1058 void unlockMedia();
1059
1060 HRESULT setMachineState(MachineState_T aMachineState);
1061 HRESULT updateMachineStateOnClient();
1062
1063 HRESULT mRemoveSavedState;
1064
1065 SnapshotData mSnapshotData;
1066
1067 /** interprocess semaphore handle for this machine */
1068#if defined(RT_OS_WINDOWS)
1069 HANDLE mIPCSem;
1070 Bstr mIPCSemName;
1071 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1072 ComPtr<IInternalSessionControl> *aControl,
1073 HANDLE *aIPCSem, bool aAllowClosing);
1074#elif defined(RT_OS_OS2)
1075 HMTX mIPCSem;
1076 Bstr mIPCSemName;
1077 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1078 ComPtr<IInternalSessionControl> *aControl,
1079 HMTX *aIPCSem, bool aAllowClosing);
1080#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1081 int mIPCSem;
1082# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1083 Bstr mIPCKey;
1084# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1085#else
1086# error "Port me!"
1087#endif
1088
1089 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1090};
1091
1092// SnapshotMachine class
1093////////////////////////////////////////////////////////////////////////////////
1094
1095/**
1096 * @note Notes on locking objects of this class:
1097 * SnapshotMachine shares some data with the primary Machine instance (pointed
1098 * to by the |mPeer| member). In order to provide data consistency it also
1099 * shares its lock handle. This means that whenever you lock a SessionMachine
1100 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1101 * instance is also locked in the same lock mode. Keep it in mind.
1102 */
1103class ATL_NO_VTABLE SnapshotMachine :
1104 public Machine
1105{
1106public:
1107 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1108
1109 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1110
1111 DECLARE_PROTECT_FINAL_CONSTRUCT()
1112
1113 BEGIN_COM_MAP(SnapshotMachine)
1114 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1115 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1116 COM_INTERFACE_ENTRY(IMachine)
1117 END_COM_MAP()
1118
1119 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1120
1121 HRESULT FinalConstruct();
1122 void FinalRelease();
1123
1124 // public initializer/uninitializer for internal purposes only
1125 HRESULT init(SessionMachine *aSessionMachine,
1126 IN_GUID aSnapshotId,
1127 const Utf8Str &aStateFilePath);
1128 HRESULT init(Machine *aMachine,
1129 const settings::Hardware &hardware,
1130 const settings::Storage &storage,
1131 IN_GUID aSnapshotId,
1132 const Utf8Str &aStateFilePath);
1133 void uninit();
1134
1135 // util::Lockable interface
1136 RWLockHandle *lockHandle() const;
1137
1138 // public methods only for internal purposes
1139
1140 virtual bool isSnapshotMachine() const
1141 {
1142 return true;
1143 }
1144
1145 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1146
1147 // unsafe inline public methods for internal purposes only (ensure there is
1148 // a caller and a read lock before calling them!)
1149
1150 const Guid& getSnapshotId() const { return mSnapshotId; }
1151
1152private:
1153
1154 Guid mSnapshotId;
1155
1156 friend class Snapshot;
1157};
1158
1159// third party methods that depend on SnapshotMachine definition
1160
1161inline const Guid &Machine::getSnapshotId() const
1162{
1163 return (isSnapshotMachine())
1164 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1165 : Guid::Empty;
1166}
1167
1168
1169#endif // ____H_MACHINEIMPL
1170/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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