VirtualBox

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

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

Main, VMM: PCI passthrough work

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