VirtualBox

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

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

VMM, Main: PCI passthrough work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.5 KB
Line 
1/* $Id: MachineImpl.h 35357 2010-12-27 22:38:34Z 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 "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 typedef std::list< ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
295 PciDeviceAssignmentList mPciDeviceAssignments;
296 };
297
298 /**
299 * Hard disk and other media data.
300 *
301 * The usage policy is the same as for HWData, but a separate structure
302 * is necessary because hard disk data requires different procedures when
303 * taking or deleting snapshots, etc.
304 *
305 * The data variable is |mMediaData|.
306 */
307 struct MediaData
308 {
309 MediaData();
310 ~MediaData();
311
312 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
313 AttachmentList mAttachments;
314 };
315
316 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
317
318 DECLARE_NOT_AGGREGATABLE(Machine)
319
320 DECLARE_PROTECT_FINAL_CONSTRUCT()
321
322 BEGIN_COM_MAP(Machine)
323 COM_INTERFACE_ENTRY(ISupportErrorInfo)
324 COM_INTERFACE_ENTRY(IMachine)
325 COM_INTERFACE_ENTRY(IDispatch)
326 END_COM_MAP()
327
328 DECLARE_EMPTY_CTOR_DTOR(Machine)
329
330 HRESULT FinalConstruct();
331 void FinalRelease();
332
333 // public initializer/uninitializer for internal purposes only:
334
335 // initializer for creating a new, empty machine
336 HRESULT init(VirtualBox *aParent,
337 const Utf8Str &strConfigFile,
338 const Utf8Str &strName,
339 GuestOSType *aOsType,
340 const Guid &aId,
341 bool fForceOverwrite);
342
343 // initializer for loading existing machine XML (either registered or not)
344 HRESULT init(VirtualBox *aParent,
345 const Utf8Str &strConfigFile,
346 const Guid *aId);
347
348 // initializer for machine config in memory (OVF import)
349 HRESULT init(VirtualBox *aParent,
350 const Utf8Str &strName,
351 const settings::MachineConfigFile &config);
352
353 void uninit();
354
355#ifdef VBOX_WITH_RESOURCE_USAGE_API
356 // Needed from VirtualBox, for the delayed metrics cleanup.
357 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
358#endif /* VBOX_WITH_RESOURCE_USAGE_API */
359
360protected:
361 HRESULT initImpl(VirtualBox *aParent,
362 const Utf8Str &strConfigFile);
363 HRESULT initDataAndChildObjects();
364 HRESULT registeredInit();
365 HRESULT tryCreateMachineConfigFile(bool fForceOverwrite);
366 void uninitDataAndChildObjects();
367
368public:
369 // IMachine properties
370 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
371 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
372 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
373 STDMETHOD(COMGETTER(Name))(BSTR *aName);
374 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
375 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
376 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
377 STDMETHOD(COMGETTER(Id))(BSTR *aId);
378 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
379 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
380 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
381 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
382 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
383 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
384 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
385 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
386 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
387 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
388 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
389 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
390 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
391 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
392 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
393 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
394 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
395 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
396 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
397 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
398 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
399 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
400 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
401 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
402 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
403 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
404 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
405 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
406 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
407 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
408 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
409 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
410 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
411 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
412 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
413 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
414 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
415 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
416 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
417 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
418 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
419 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
420 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
421 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
422 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
423 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
424 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
425 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
426 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
427 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
428 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
429 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
430 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
431 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
432 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
433 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
434 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
435 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
436 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
437 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
438 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
439 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
440 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
441 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
442 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
443 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
444 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
445 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
446 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
447 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
448 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
449 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
450 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
451 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
452 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
453 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
454 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
455 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
456 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
457 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
458 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
459 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
460 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
461 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
462 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
463
464 // IMachine methods
465 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
466 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
467
468 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
469 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
470 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
471 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
472 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
473 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
474 STDMETHOD(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
475 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
476 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
477 LONG aDevice, IMedium *aMedium, BOOL aForce);
478 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
479 IMedium **aMedium);
480 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
481 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
482 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
483 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
484 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
485 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
486 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
487 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
488 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
489 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
490 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
491 STDMETHOD(RemoveAllCPUIDLeaves)();
492 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
493 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
494 STDMETHOD(SaveSettings)();
495 STDMETHOD(DiscardSettings)();
496 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
497 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
498 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
499 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
500 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
501 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
502 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
503 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
504 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
505 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
506 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
507 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
508 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
509 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
510 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
511 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
512 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
513 STDMETHOD(RemoveStorageController(IN_BSTR aName));
514 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
515 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
516 STDMETHOD(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
517 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
518 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
519 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
520 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
521 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
522 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
523 STDMETHOD(HotPlugCPU(ULONG aCpu));
524 STDMETHOD(HotUnplugCPU(ULONG aCpu));
525 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
526 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
527 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
528 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL tryToUnbind));
529 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
530 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
531 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
532 // public methods only for internal purposes
533
534 virtual bool isSnapshotMachine() const
535 {
536 return false;
537 }
538
539 virtual bool isSessionMachine() const
540 {
541 return false;
542 }
543
544 /**
545 * Override of the default locking class to be used for validating lock
546 * order with the standard member lock handle.
547 */
548 virtual VBoxLockingClass getLockingClass() const
549 {
550 return LOCKCLASS_MACHINEOBJECT;
551 }
552
553 /// @todo (dmik) add lock and make non-inlined after revising classes
554 // that use it. Note: they should enter Machine lock to keep the returned
555 // information valid!
556 bool isRegistered() { return !!mData->mRegistered; }
557
558 // unsafe inline public methods for internal purposes only (ensure there is
559 // a caller and a read lock before calling them!)
560
561 /**
562 * Returns the VirtualBox object this machine belongs to.
563 *
564 * @note This method doesn't check this object's readiness. Intended to be
565 * used by ready Machine children (whose readiness is bound to the parent's
566 * one) or after doing addCaller() manually.
567 */
568 VirtualBox* getVirtualBox() const { return mParent; }
569
570 /**
571 * Returns this machine ID.
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 const Guid& getId() const { return mData->mUuid; }
578
579 /**
580 * Returns the snapshot ID this machine represents or an empty UUID if this
581 * instance is not SnapshotMachine.
582 *
583 * @note This method doesn't check this object's readiness. Intended to be
584 * used by ready Machine children (whose readiness is bound to the parent's
585 * one) or after adding a caller manually.
586 */
587 inline const Guid& getSnapshotId() const;
588
589 /**
590 * Returns this machine's full settings file path.
591 *
592 * @note This method doesn't lock this object or check its readiness.
593 * Intended to be used only after doing addCaller() manually and locking it
594 * for reading.
595 */
596 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
597
598 /**
599 * Returns this machine name.
600 *
601 * @note This method doesn't lock this object or check its readiness.
602 * Intended to be used only after doing addCaller() manually and locking it
603 * for reading.
604 */
605 const Utf8Str& getName() const { return mUserData->s.strName; }
606
607 enum
608 {
609 IsModified_MachineData = 0x0001,
610 IsModified_Storage = 0x0002,
611 IsModified_NetworkAdapters = 0x0008,
612 IsModified_SerialPorts = 0x0010,
613 IsModified_ParallelPorts = 0x0020,
614 IsModified_VRDEServer = 0x0040,
615 IsModified_AudioAdapter = 0x0080,
616 IsModified_USB = 0x0100,
617 IsModified_BIOS = 0x0200,
618 IsModified_SharedFolders = 0x0400,
619 IsModified_Snapshots = 0x0800,
620 IsModified_BandwidthControl = 0x1000
621 };
622
623 void setModified(uint32_t fl);
624
625 // callback handlers
626 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
627 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
628 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
629 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
630 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
631 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
632 virtual HRESULT onUSBControllerChange() { return S_OK; }
633 virtual HRESULT onStorageControllerChange() { return S_OK; }
634 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
635 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
636 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
637 virtual HRESULT onSharedFolderChange() { return S_OK; }
638 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
639
640 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
641
642 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
643 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
644
645 void getLogFolder(Utf8Str &aLogFolder);
646 Utf8Str queryLogFilename(ULONG idx);
647
648 HRESULT openRemoteSession(IInternalSessionControl *aControl,
649 IN_BSTR aType, IN_BSTR aEnvironment,
650 ProgressProxy *aProgress);
651
652 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
653 {
654 HRESULT rc;
655 *directControl = mData->mSession.mDirectControl;
656
657 if (!*directControl)
658 rc = E_ACCESSDENIED;
659 else
660 rc = S_OK;
661
662 return rc;
663 }
664
665#if defined(RT_OS_WINDOWS)
666
667 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
668 ComPtr<IInternalSessionControl> *aControl = NULL,
669 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
670 bool isSessionSpawning(RTPROCESS *aPID = NULL);
671
672 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
673 ComPtr<IInternalSessionControl> *aControl = NULL,
674 HANDLE *aIPCSem = NULL)
675 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
676
677#elif defined(RT_OS_OS2)
678
679 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
680 ComPtr<IInternalSessionControl> *aControl = NULL,
681 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
682
683 bool isSessionSpawning(RTPROCESS *aPID = NULL);
684
685 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
686 ComPtr<IInternalSessionControl> *aControl = NULL,
687 HMTX *aIPCSem = NULL)
688 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
689
690#else
691
692 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
693 ComPtr<IInternalSessionControl> *aControl = NULL,
694 bool aAllowClosing = false);
695 bool isSessionSpawning();
696
697 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
698 ComPtr<IInternalSessionControl> *aControl = NULL)
699 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
700
701#endif
702
703 bool checkForSpawnFailure();
704
705 HRESULT prepareRegister();
706
707 HRESULT getSharedFolder(CBSTR aName,
708 ComObjPtr<SharedFolder> &aSharedFolder,
709 bool aSetError = false)
710 {
711 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
712 return findSharedFolder(aName, aSharedFolder, aSetError);
713 }
714
715 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
716 MachineState_T *aState = NULL,
717 BOOL *aRegistered = NULL);
718 void releaseStateDependency();
719
720protected:
721
722 HRESULT checkStateDependency(StateDependency aDepType);
723
724 Machine *getMachine();
725
726 void ensureNoStateDependencies();
727
728 virtual HRESULT setMachineState(MachineState_T aMachineState);
729
730 HRESULT findSharedFolder(CBSTR aName,
731 ComObjPtr<SharedFolder> &aSharedFolder,
732 bool aSetError = false);
733
734 HRESULT loadSettings(bool aRegistered);
735 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
736 const Guid *puuidRegistry);
737 HRESULT loadSnapshot(const settings::Snapshot &data,
738 const Guid &aCurSnapshotId,
739 Snapshot *aParentSnapshot);
740 HRESULT loadHardware(const settings::Hardware &data);
741 HRESULT loadStorageControllers(const settings::Storage &data,
742 const Guid *puuidRegistry,
743 const Guid *puuidSnapshot);
744 HRESULT loadStorageDevices(StorageController *aStorageController,
745 const settings::StorageController &data,
746 const Guid *puuidRegistry,
747 const Guid *puuidSnapshot);
748
749 HRESULT findSnapshotById(const Guid &aId,
750 ComObjPtr<Snapshot> &aSnapshot,
751 bool aSetError = false);
752 HRESULT findSnapshotByName(const Utf8Str &strName,
753 ComObjPtr<Snapshot> &aSnapshot,
754 bool aSetError = false);
755
756 HRESULT getStorageControllerByName(const Utf8Str &aName,
757 ComObjPtr<StorageController> &aStorageController,
758 bool aSetError = false);
759
760 HRESULT getMediumAttachmentsOfController(CBSTR aName,
761 MediaData::AttachmentList &aAttachments);
762
763 enum
764 {
765 /* flags for #saveSettings() */
766 SaveS_ResetCurStateModified = 0x01,
767 SaveS_InformCallbacksAnyway = 0x02,
768 SaveS_Force = 0x04,
769 /* flags for #saveStateSettings() */
770 SaveSTS_CurStateModified = 0x20,
771 SaveSTS_StateFilePath = 0x40,
772 SaveSTS_StateTimeStamp = 0x80
773 };
774
775 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
776 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
777
778 void copyMachineDataToSettings(settings::MachineConfigFile &config);
779 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
780 HRESULT saveHardware(settings::Hardware &data);
781 HRESULT saveStorageControllers(settings::Storage &data);
782 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
783 settings::StorageController &data);
784 HRESULT saveStateSettings(int aFlags);
785
786 HRESULT createImplicitDiffs(IProgress *aProgress,
787 ULONG aWeight,
788 bool aOnline,
789 GuidList *pllRegistriesThatNeedSaving);
790 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
791
792 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
793 IN_BSTR aControllerName,
794 LONG aControllerPort,
795 LONG aDevice);
796 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
797 ComObjPtr<Medium> pMedium);
798 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
799 Guid &id);
800
801 HRESULT detachDevice(MediumAttachment *pAttach,
802 AutoWriteLock &writeLock,
803 Snapshot *pSnapshot,
804 GuidList *pllRegistriesThatNeedSaving);
805 HRESULT detachAllMedia(AutoWriteLock &writeLock,
806 Snapshot *pSnapshot,
807 CleanupMode_T cleanupMode,
808 MediaList &llMedia);
809
810 void commitMedia(bool aOnline = false);
811 void rollbackMedia();
812
813 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
814
815 void rollback(bool aNotify);
816 void commit();
817 void copyFrom(Machine *aThat);
818
819 struct DeleteTask;
820 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
821 HRESULT deleteTaskWorker(DeleteTask &task);
822
823#ifdef VBOX_WITH_GUEST_PROPS
824 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
825 LONG64 *aTimestamp, BSTR *aFlags) const;
826 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
827 LONG64 *aTimestamp, BSTR *aFlags) const;
828 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
829 IN_BSTR aFlags);
830 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
831 IN_BSTR aFlags);
832 HRESULT enumerateGuestPropertiesInService
833 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
834 ComSafeArrayOut(BSTR, aValues),
835 ComSafeArrayOut(LONG64, aTimestamps),
836 ComSafeArrayOut(BSTR, aFlags));
837 HRESULT enumerateGuestPropertiesOnVM
838 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
839 ComSafeArrayOut(BSTR, aValues),
840 ComSafeArrayOut(LONG64, aTimestamps),
841 ComSafeArrayOut(BSTR, aFlags));
842#endif /* VBOX_WITH_GUEST_PROPS */
843
844#ifdef VBOX_WITH_RESOURCE_USAGE_API
845 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
846
847 pm::CollectorGuestHAL *mGuestHAL;
848#endif /* VBOX_WITH_RESOURCE_USAGE_API */
849
850 Machine* const mPeer;
851
852 VirtualBox * const mParent;
853
854 Shareable<Data> mData;
855 Shareable<SSData> mSSData;
856
857 Backupable<UserData> mUserData;
858 Backupable<HWData> mHWData;
859 Backupable<MediaData> mMediaData;
860
861 // the following fields need special backup/rollback/commit handling,
862 // so they cannot be a part of HWData
863
864 const ComObjPtr<VRDEServer> mVRDEServer;
865 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
866 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
867 const ComObjPtr<AudioAdapter> mAudioAdapter;
868 const ComObjPtr<USBController> mUSBController;
869 const ComObjPtr<BIOSSettings> mBIOSSettings;
870 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
871 const ComObjPtr<BandwidthControl> mBandwidthControl;
872
873 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
874 Backupable<StorageControllerList> mStorageControllers;
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 ConsoleTaskData
996 {
997 ConsoleTaskData() : mLastState(MachineState_Null) {}
998
999 MachineState_T mLastState;
1000 ComObjPtr<Progress> mProgress;
1001
1002 // used when taking snapshot
1003 ComObjPtr<Snapshot> mSnapshot;
1004
1005 // used when saving state (either as part of a snapshot or separate)
1006 Utf8Str mStateFilePath;
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 ConsoleTaskData mConsoleTaskData;
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: */
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