VirtualBox

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

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

Main. QT/FE: fix long standing COM issue

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.4 KB
Line 
1/* $Id: MachineImpl.h 35638 2011-01-19 19:10:49Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2011 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
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 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
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(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
470 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
471 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
472 LONG aDevice, IMedium *aMedium, BOOL aForce);
473 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
474 IMedium **aMedium);
475 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
476 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
477 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
478 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
479 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
480 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
481 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
482 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
483 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
484 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
485 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
486 STDMETHOD(RemoveAllCPUIDLeaves)();
487 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
488 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
489 STDMETHOD(SaveSettings)();
490 STDMETHOD(DiscardSettings)();
491 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
492 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
493 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
494 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
495 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
496 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
497 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
498 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
499 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
500 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
501 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
502 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
503 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
504 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
505 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
506 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
507 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
508 STDMETHOD(RemoveStorageController(IN_BSTR aName));
509 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
510 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
511 STDMETHOD(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
512 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
513 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
514 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
515 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
516 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
517 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
518 STDMETHOD(HotPlugCPU(ULONG aCpu));
519 STDMETHOD(HotUnplugCPU(ULONG aCpu));
520 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
521 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
522 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
523 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, IEventContext *eventContext, BOOL tryToUnbind));
524 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
525 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
526 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
527 // public methods only for internal purposes
528
529 virtual bool isSnapshotMachine() const
530 {
531 return false;
532 }
533
534 virtual bool isSessionMachine() const
535 {
536 return false;
537 }
538
539 /**
540 * Override of the default locking class to be used for validating lock
541 * order with the standard member lock handle.
542 */
543 virtual VBoxLockingClass getLockingClass() const
544 {
545 return LOCKCLASS_MACHINEOBJECT;
546 }
547
548 /// @todo (dmik) add lock and make non-inlined after revising classes
549 // that use it. Note: they should enter Machine lock to keep the returned
550 // information valid!
551 bool isRegistered() { return !!mData->mRegistered; }
552
553 // unsafe inline public methods for internal purposes only (ensure there is
554 // a caller and a read lock before calling them!)
555
556 /**
557 * Returns the VirtualBox object this machine belongs to.
558 *
559 * @note This method doesn't check this object's readiness. Intended to be
560 * used by ready Machine children (whose readiness is bound to the parent's
561 * one) or after doing addCaller() manually.
562 */
563 VirtualBox* getVirtualBox() const { return mParent; }
564
565 /**
566 * Returns this machine ID.
567 *
568 * @note This method doesn't check this object's readiness. Intended to be
569 * used by ready Machine children (whose readiness is bound to the parent's
570 * one) or after adding a caller manually.
571 */
572 const Guid& getId() const { return mData->mUuid; }
573
574 /**
575 * Returns the snapshot ID this machine represents or an empty UUID if this
576 * instance is not SnapshotMachine.
577 *
578 * @note This method doesn't check this object's readiness. Intended to be
579 * used by ready Machine children (whose readiness is bound to the parent's
580 * one) or after adding a caller manually.
581 */
582 inline const Guid& getSnapshotId() const;
583
584 /**
585 * Returns this machine's full settings file path.
586 *
587 * @note This method doesn't lock this object or check its readiness.
588 * Intended to be used only after doing addCaller() manually and locking it
589 * for reading.
590 */
591 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
592
593 /**
594 * Returns this machine name.
595 *
596 * @note This method doesn't lock this object or check its readiness.
597 * Intended to be used only after doing addCaller() manually and locking it
598 * for reading.
599 */
600 const Utf8Str& getName() const { return mUserData->s.strName; }
601
602 enum
603 {
604 IsModified_MachineData = 0x0001,
605 IsModified_Storage = 0x0002,
606 IsModified_NetworkAdapters = 0x0008,
607 IsModified_SerialPorts = 0x0010,
608 IsModified_ParallelPorts = 0x0020,
609 IsModified_VRDEServer = 0x0040,
610 IsModified_AudioAdapter = 0x0080,
611 IsModified_USB = 0x0100,
612 IsModified_BIOS = 0x0200,
613 IsModified_SharedFolders = 0x0400,
614 IsModified_Snapshots = 0x0800,
615 IsModified_BandwidthControl = 0x1000
616 };
617
618 void setModified(uint32_t fl);
619
620 // callback handlers
621 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
622 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
623 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
624 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
625 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
626 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
627 virtual HRESULT onUSBControllerChange() { return S_OK; }
628 virtual HRESULT onStorageControllerChange() { return S_OK; }
629 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
630 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
631 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
632 virtual HRESULT onSharedFolderChange() { return S_OK; }
633 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
634
635 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
636
637 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
638 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
639
640 void getLogFolder(Utf8Str &aLogFolder);
641 Utf8Str queryLogFilename(ULONG idx);
642
643 HRESULT openRemoteSession(IInternalSessionControl *aControl,
644 IN_BSTR aType, IN_BSTR aEnvironment,
645 ProgressProxy *aProgress);
646
647 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
648 {
649 HRESULT rc;
650 *directControl = mData->mSession.mDirectControl;
651
652 if (!*directControl)
653 rc = E_ACCESSDENIED;
654 else
655 rc = S_OK;
656
657 return rc;
658 }
659
660#if defined(RT_OS_WINDOWS)
661
662 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
663 ComPtr<IInternalSessionControl> *aControl = NULL,
664 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
665 bool isSessionSpawning(RTPROCESS *aPID = NULL);
666
667 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
668 ComPtr<IInternalSessionControl> *aControl = NULL,
669 HANDLE *aIPCSem = NULL)
670 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
671
672#elif defined(RT_OS_OS2)
673
674 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
675 ComPtr<IInternalSessionControl> *aControl = NULL,
676 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
677
678 bool isSessionSpawning(RTPROCESS *aPID = NULL);
679
680 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
681 ComPtr<IInternalSessionControl> *aControl = NULL,
682 HMTX *aIPCSem = NULL)
683 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
684
685#else
686
687 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
688 ComPtr<IInternalSessionControl> *aControl = NULL,
689 bool aAllowClosing = false);
690 bool isSessionSpawning();
691
692 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
693 ComPtr<IInternalSessionControl> *aControl = NULL)
694 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
695
696#endif
697
698 bool checkForSpawnFailure();
699
700 HRESULT prepareRegister();
701
702 HRESULT getSharedFolder(CBSTR aName,
703 ComObjPtr<SharedFolder> &aSharedFolder,
704 bool aSetError = false)
705 {
706 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
707 return findSharedFolder(aName, aSharedFolder, aSetError);
708 }
709
710 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
711 MachineState_T *aState = NULL,
712 BOOL *aRegistered = NULL);
713 void releaseStateDependency();
714
715protected:
716
717 HRESULT checkStateDependency(StateDependency aDepType);
718
719 Machine *getMachine();
720
721 void ensureNoStateDependencies();
722
723 virtual HRESULT setMachineState(MachineState_T aMachineState);
724
725 HRESULT findSharedFolder(CBSTR aName,
726 ComObjPtr<SharedFolder> &aSharedFolder,
727 bool aSetError = false);
728
729 HRESULT loadSettings(bool aRegistered);
730 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
731 const Guid *puuidRegistry);
732 HRESULT loadSnapshot(const settings::Snapshot &data,
733 const Guid &aCurSnapshotId,
734 Snapshot *aParentSnapshot);
735 HRESULT loadHardware(const settings::Hardware &data);
736 HRESULT loadStorageControllers(const settings::Storage &data,
737 const Guid *puuidRegistry,
738 const Guid *puuidSnapshot);
739 HRESULT loadStorageDevices(StorageController *aStorageController,
740 const settings::StorageController &data,
741 const Guid *puuidRegistry,
742 const Guid *puuidSnapshot);
743
744 HRESULT findSnapshotById(const Guid &aId,
745 ComObjPtr<Snapshot> &aSnapshot,
746 bool aSetError = false);
747 HRESULT findSnapshotByName(const Utf8Str &strName,
748 ComObjPtr<Snapshot> &aSnapshot,
749 bool aSetError = false);
750
751 HRESULT getStorageControllerByName(const Utf8Str &aName,
752 ComObjPtr<StorageController> &aStorageController,
753 bool aSetError = false);
754
755 HRESULT getMediumAttachmentsOfController(CBSTR aName,
756 MediaData::AttachmentList &aAttachments);
757
758 enum
759 {
760 /* flags for #saveSettings() */
761 SaveS_ResetCurStateModified = 0x01,
762 SaveS_InformCallbacksAnyway = 0x02,
763 SaveS_Force = 0x04,
764 /* flags for #saveStateSettings() */
765 SaveSTS_CurStateModified = 0x20,
766 SaveSTS_StateFilePath = 0x40,
767 SaveSTS_StateTimeStamp = 0x80
768 };
769
770 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
771 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
772
773 void copyMachineDataToSettings(settings::MachineConfigFile &config);
774 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
775 HRESULT saveHardware(settings::Hardware &data);
776 HRESULT saveStorageControllers(settings::Storage &data);
777 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
778 settings::StorageController &data);
779 HRESULT saveStateSettings(int aFlags);
780
781 HRESULT createImplicitDiffs(IProgress *aProgress,
782 ULONG aWeight,
783 bool aOnline,
784 GuidList *pllRegistriesThatNeedSaving);
785 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
786
787 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
788 IN_BSTR aControllerName,
789 LONG aControllerPort,
790 LONG aDevice);
791 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
792 ComObjPtr<Medium> pMedium);
793 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
794 Guid &id);
795
796 HRESULT detachDevice(MediumAttachment *pAttach,
797 AutoWriteLock &writeLock,
798 Snapshot *pSnapshot,
799 GuidList *pllRegistriesThatNeedSaving);
800 HRESULT detachAllMedia(AutoWriteLock &writeLock,
801 Snapshot *pSnapshot,
802 CleanupMode_T cleanupMode,
803 MediaList &llMedia);
804
805 void commitMedia(bool aOnline = false);
806 void rollbackMedia();
807
808 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
809
810 void rollback(bool aNotify);
811 void commit();
812 void copyFrom(Machine *aThat);
813
814 struct DeleteTask;
815 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
816 HRESULT deleteTaskWorker(DeleteTask &task);
817
818#ifdef VBOX_WITH_GUEST_PROPS
819 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
820 LONG64 *aTimestamp, BSTR *aFlags) const;
821 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
822 LONG64 *aTimestamp, BSTR *aFlags) const;
823 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
824 IN_BSTR aFlags);
825 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
826 IN_BSTR aFlags);
827 HRESULT enumerateGuestPropertiesInService
828 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
829 ComSafeArrayOut(BSTR, aValues),
830 ComSafeArrayOut(LONG64, aTimestamps),
831 ComSafeArrayOut(BSTR, aFlags));
832 HRESULT enumerateGuestPropertiesOnVM
833 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
834 ComSafeArrayOut(BSTR, aValues),
835 ComSafeArrayOut(LONG64, aTimestamps),
836 ComSafeArrayOut(BSTR, aFlags));
837#endif /* VBOX_WITH_GUEST_PROPS */
838
839#ifdef VBOX_WITH_RESOURCE_USAGE_API
840 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
841
842 pm::CollectorGuestHAL *mGuestHAL;
843#endif /* VBOX_WITH_RESOURCE_USAGE_API */
844
845 Machine* const mPeer;
846
847 VirtualBox * const mParent;
848
849 Shareable<Data> mData;
850 Shareable<SSData> mSSData;
851
852 Backupable<UserData> mUserData;
853 Backupable<HWData> mHWData;
854 Backupable<MediaData> mMediaData;
855
856 // the following fields need special backup/rollback/commit handling,
857 // so they cannot be a part of HWData
858
859 const ComObjPtr<VRDEServer> mVRDEServer;
860 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
861 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
862 const ComObjPtr<AudioAdapter> mAudioAdapter;
863 const ComObjPtr<USBController> mUSBController;
864 const ComObjPtr<BIOSSettings> mBIOSSettings;
865 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
866 const ComObjPtr<BandwidthControl> mBandwidthControl;
867
868 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
869 Backupable<StorageControllerList> mStorageControllers;
870
871 typedef std::list< ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
872 PciDeviceAssignmentList mPciDeviceAssignments;
873
874 friend class SessionMachine;
875 friend class SnapshotMachine;
876 friend class Appliance;
877 friend class VirtualBox;
878};
879
880// SessionMachine class
881////////////////////////////////////////////////////////////////////////////////
882
883/**
884 * @note Notes on locking objects of this class:
885 * SessionMachine shares some data with the primary Machine instance (pointed
886 * to by the |mPeer| member). In order to provide data consistency it also
887 * shares its lock handle. This means that whenever you lock a SessionMachine
888 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
889 * instance is also locked in the same lock mode. Keep it in mind.
890 */
891class ATL_NO_VTABLE SessionMachine :
892 public Machine,
893 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
894{
895public:
896 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
897
898 DECLARE_NOT_AGGREGATABLE(SessionMachine)
899
900 DECLARE_PROTECT_FINAL_CONSTRUCT()
901
902 BEGIN_COM_MAP(SessionMachine)
903 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
904 COM_INTERFACE_ENTRY(IInternalMachineControl)
905 END_COM_MAP()
906
907 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
908
909 HRESULT FinalConstruct();
910 void FinalRelease();
911
912 // public initializer/uninitializer for internal purposes only
913 HRESULT init(Machine *aMachine);
914 void uninit() { uninit(Uninit::Unexpected); }
915
916 // util::Lockable interface
917 RWLockHandle *lockHandle() const;
918
919 // IInternalMachineControl methods
920 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
921 STDMETHOD(UpdateState)(MachineState_T machineState);
922 STDMETHOD(GetIPCId)(BSTR *id);
923 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
924 STDMETHOD(EndPowerUp)(LONG iResult);
925 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
926 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
927 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
928 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
929 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
930 STDMETHOD(AutoCaptureUSBDevices)();
931 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
932 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
933 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
934 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
935 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
936 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
937 IN_BSTR aName,
938 IN_BSTR aDescription,
939 IProgress *aConsoleProgress,
940 BOOL fTakingSnapshotOnline,
941 BSTR *aStateFilePath);
942 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
943 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
944 MachineState_T *aMachineState, IProgress **aProgress);
945 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
946 IMedium *aSource, IMedium *aTarget,
947 BOOL fMergeForward,
948 IMedium *pParentForTarget,
949 ComSafeArrayIn(IMedium *, aChildrenToReparent));
950 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
951 ISnapshot *aSnapshot,
952 MachineState_T *aMachineState,
953 IProgress **aProgress);
954 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
955 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
956 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
957 LONG64 aTimestamp, IN_BSTR aFlags);
958 STDMETHOD(LockMedia)() { return lockMedia(); }
959 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
960
961 // public methods only for internal purposes
962
963 virtual bool isSessionMachine() const
964 {
965 return true;
966 }
967
968 bool checkForDeath();
969
970 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
971 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
972 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
973 HRESULT onStorageControllerChange();
974 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
975 HRESULT onSerialPortChange(ISerialPort *serialPort);
976 HRESULT onParallelPortChange(IParallelPort *parallelPort);
977 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
978 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
979 HRESULT onVRDEServerChange(BOOL aRestart);
980 HRESULT onUSBControllerChange();
981 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
982 IVirtualBoxErrorInfo *aError,
983 ULONG aMaskedIfs);
984 HRESULT onUSBDeviceDetach(IN_BSTR aId,
985 IVirtualBoxErrorInfo *aError);
986 HRESULT onSharedFolderChange();
987 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
988
989 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
990
991private:
992
993 struct ConsoleTaskData
994 {
995 ConsoleTaskData() : mLastState(MachineState_Null) {}
996
997 MachineState_T mLastState;
998 ComObjPtr<Progress> mProgress;
999
1000 // used when taking snapshot
1001 ComObjPtr<Snapshot> mSnapshot;
1002
1003 // used when saving state (either as part of a snapshot or separate)
1004 Utf8Str mStateFilePath;
1005 };
1006
1007 struct Uninit
1008 {
1009 enum Reason { Unexpected, Abnormal, Normal };
1010 };
1011
1012 struct SnapshotTask;
1013 struct DeleteSnapshotTask;
1014 struct RestoreSnapshotTask;
1015
1016 friend struct DeleteSnapshotTask;
1017 friend struct RestoreSnapshotTask;
1018
1019 void uninit(Uninit::Reason aReason);
1020
1021 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1022
1023 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1024 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1025
1026 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1027 const Guid &machineId,
1028 const Guid &snapshotId,
1029 bool fOnlineMergePossible,
1030 MediumLockList *aVMMALockList,
1031 ComObjPtr<Medium> &aSource,
1032 ComObjPtr<Medium> &aTarget,
1033 bool &fMergeForward,
1034 ComObjPtr<Medium> &pParentForTarget,
1035 MediaList &aChildrenToReparent,
1036 bool &fNeedOnlineMerge,
1037 MediumLockList * &aMediumLockList);
1038 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1039 const ComObjPtr<Medium> &aSource,
1040 const MediaList &aChildrenToReparent,
1041 bool fNeedsOnlineMerge,
1042 MediumLockList *aMediumLockList,
1043 const Guid &aMediumId,
1044 const Guid &aSnapshotId);
1045 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1046 const ComObjPtr<Medium> &aSource,
1047 const ComObjPtr<Medium> &aTarget,
1048 bool fMergeForward,
1049 const ComObjPtr<Medium> &pParentForTarget,
1050 const MediaList &aChildrenToReparent,
1051 MediumLockList *aMediumLockList,
1052 ComObjPtr<Progress> &aProgress,
1053 bool *pfNeedsMachineSaveSettings);
1054
1055 HRESULT lockMedia();
1056 void unlockMedia();
1057
1058 HRESULT setMachineState(MachineState_T aMachineState);
1059 HRESULT updateMachineStateOnClient();
1060
1061 HRESULT mRemoveSavedState;
1062
1063 ConsoleTaskData mConsoleTaskData;
1064
1065 /** interprocess semaphore handle for this machine */
1066#if defined(RT_OS_WINDOWS)
1067 HANDLE mIPCSem;
1068 Bstr mIPCSemName;
1069 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1070 ComPtr<IInternalSessionControl> *aControl,
1071 HANDLE *aIPCSem, bool aAllowClosing);
1072#elif defined(RT_OS_OS2)
1073 HMTX mIPCSem;
1074 Bstr mIPCSemName;
1075 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1076 ComPtr<IInternalSessionControl> *aControl,
1077 HMTX *aIPCSem, bool aAllowClosing);
1078#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1079 int mIPCSem;
1080# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1081 Bstr mIPCKey;
1082# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1083#else
1084# error "Port me!"
1085#endif
1086
1087 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1088};
1089
1090// SnapshotMachine class
1091////////////////////////////////////////////////////////////////////////////////
1092
1093/**
1094 * @note Notes on locking objects of this class:
1095 * SnapshotMachine shares some data with the primary Machine instance (pointed
1096 * to by the |mPeer| member). In order to provide data consistency it also
1097 * shares its lock handle. This means that whenever you lock a SessionMachine
1098 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1099 * instance is also locked in the same lock mode. Keep it in mind.
1100 */
1101class ATL_NO_VTABLE SnapshotMachine :
1102 public Machine
1103{
1104public:
1105 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1106
1107 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1108
1109 DECLARE_PROTECT_FINAL_CONSTRUCT()
1110
1111 BEGIN_COM_MAP(SnapshotMachine)
1112 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1113 END_COM_MAP()
1114
1115 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1116
1117 HRESULT FinalConstruct();
1118 void FinalRelease();
1119
1120 // public initializer/uninitializer for internal purposes only
1121 HRESULT init(SessionMachine *aSessionMachine,
1122 IN_GUID aSnapshotId,
1123 const Utf8Str &aStateFilePath);
1124 HRESULT init(Machine *aMachine,
1125 const settings::Hardware &hardware,
1126 const settings::Storage &storage,
1127 IN_GUID aSnapshotId,
1128 const Utf8Str &aStateFilePath);
1129 void uninit();
1130
1131 // util::Lockable interface
1132 RWLockHandle *lockHandle() const;
1133
1134 // public methods only for internal purposes
1135
1136 virtual bool isSnapshotMachine() const
1137 {
1138 return true;
1139 }
1140
1141 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1142
1143 // unsafe inline public methods for internal purposes only (ensure there is
1144 // a caller and a read lock before calling them!)
1145
1146 const Guid& getSnapshotId() const { return mSnapshotId; }
1147
1148private:
1149
1150 Guid mSnapshotId;
1151
1152 friend class Snapshot;
1153};
1154
1155// third party methods that depend on SnapshotMachine definition
1156
1157inline const Guid &Machine::getSnapshotId() const
1158{
1159 return (isSnapshotMachine())
1160 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1161 : Guid::Empty;
1162}
1163
1164
1165#endif // ____H_MACHINEIMPL
1166/* 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