VirtualBox

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

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

Change DiscardDevice to SetAutoDiscardForDevice

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.3 KB
Line 
1/* $Id: MachineImpl.h 38887 2011-09-27 12:08:50Z 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 "BandwidthGroupImpl.h"
36#include "VBox/settings.h"
37#ifdef VBOX_WITH_RESOURCE_USAGE_API
38#include "Performance.h"
39#include "PerformanceImpl.h"
40#endif /* VBOX_WITH_RESOURCE_USAGE_API */
41
42// generated header
43#include "SchemaDefs.h"
44
45#include "VBox/com/ErrorInfo.h"
46
47#include <iprt/file.h>
48#include <iprt/thread.h>
49#include <iprt/time.h>
50
51#include <list>
52
53// defines
54////////////////////////////////////////////////////////////////////////////////
55
56// helper declarations
57////////////////////////////////////////////////////////////////////////////////
58
59class Progress;
60class ProgressProxy;
61class Keyboard;
62class Mouse;
63class Display;
64class MachineDebugger;
65class USBController;
66class Snapshot;
67class SharedFolder;
68class HostUSBDevice;
69class StorageController;
70
71class SessionMachine;
72
73namespace settings
74{
75 class MachineConfigFile;
76 struct Snapshot;
77 struct Hardware;
78 struct Storage;
79 struct StorageController;
80 struct MachineRegistryEntry;
81}
82
83// Machine class
84////////////////////////////////////////////////////////////////////////////////
85
86class ATL_NO_VTABLE Machine :
87 public VirtualBoxBase,
88 VBOX_SCRIPTABLE_IMPL(IMachine)
89{
90 Q_OBJECT
91
92public:
93
94 enum StateDependency
95 {
96 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
97 };
98
99 /**
100 * Internal machine data.
101 *
102 * Only one instance of this data exists per every machine -- it is shared
103 * by the Machine, SessionMachine and all SnapshotMachine instances
104 * associated with the given machine using the util::Shareable template
105 * through the mData variable.
106 *
107 * @note |const| members are persistent during lifetime so can be
108 * accessed without locking.
109 *
110 * @note There is no need to lock anything inside init() or uninit()
111 * methods, because they are always serialized (see AutoCaller).
112 */
113 struct Data
114 {
115 /**
116 * Data structure to hold information about sessions opened for the
117 * given machine.
118 */
119 struct Session
120 {
121 /** Control of the direct session opened by lockMachine() */
122 ComPtr<IInternalSessionControl> mDirectControl;
123
124 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
125
126 /** list of controls of all opened remote sessions */
127 RemoteControlList mRemoteControls;
128
129 /** launchVMProcess() and OnSessionEnd() progress indicator */
130 ComObjPtr<ProgressProxy> mProgress;
131
132 /**
133 * PID of the session object that must be passed to openSession()
134 * to finalize the launchVMProcess() request (i.e., PID of the
135 * process created by launchVMProcess())
136 */
137 RTPROCESS mPid;
138
139 /** Current session state */
140 SessionState_T mState;
141
142 /** Session type string (for indirect sessions) */
143 Bstr mType;
144
145 /** Session machine object */
146 ComObjPtr<SessionMachine> mMachine;
147
148 /** Medium object lock collection. */
149 MediumLockListMap mLockedMedia;
150 };
151
152 Data();
153 ~Data();
154
155 const Guid mUuid;
156 BOOL mRegistered;
157
158 Utf8Str m_strConfigFile;
159 Utf8Str m_strConfigFileFull;
160
161 // machine settings XML file
162 settings::MachineConfigFile *pMachineConfigFile;
163 uint32_t flModifications;
164
165 BOOL mAccessible;
166 com::ErrorInfo mAccessError;
167
168 MachineState_T mMachineState;
169 RTTIMESPEC mLastStateChange;
170
171 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
172 uint32_t mMachineStateDeps;
173 RTSEMEVENTMULTI mMachineStateDepsSem;
174 uint32_t mMachineStateChangePending;
175
176 BOOL mCurrentStateModified;
177 /** Guest properties have been modified and need saving since the
178 * machine was started, or there are transient properties which need
179 * deleting and the machine is being shut down. */
180 BOOL mGuestPropertiesModified;
181
182 Session mSession;
183
184 ComObjPtr<Snapshot> mFirstSnapshot;
185 ComObjPtr<Snapshot> mCurrentSnapshot;
186
187 // list of files to delete in Delete(); this list is filled by Unregister()
188 std::list<Utf8Str> llFilesToDelete;
189 };
190
191 /**
192 * Saved state data.
193 *
194 * It's actually only the state file path string, but it needs to be
195 * separate from Data, because Machine and SessionMachine instances
196 * share it, while SnapshotMachine does not.
197 *
198 * The data variable is |mSSData|.
199 */
200 struct SSData
201 {
202 Utf8Str strStateFilePath;
203 };
204
205 /**
206 * User changeable machine data.
207 *
208 * This data is common for all machine snapshots, i.e. it is shared
209 * by all SnapshotMachine instances associated with the given machine
210 * using the util::Backupable template through the |mUserData| variable.
211 *
212 * SessionMachine instances can alter this data and discard changes.
213 *
214 * @note There is no need to lock anything inside init() or uninit()
215 * methods, because they are always serialized (see AutoCaller).
216 */
217 struct UserData
218 {
219 settings::MachineUserData s;
220 };
221
222 /**
223 * Hardware data.
224 *
225 * This data is unique for a machine and for every machine snapshot.
226 * Stored using the util::Backupable template in the |mHWData| variable.
227 *
228 * SessionMachine instances can alter this data and discard changes.
229 */
230 struct HWData
231 {
232 /**
233 * Data structure to hold information about a guest property.
234 */
235 struct GuestProperty {
236 /** Property name */
237 Utf8Str strName;
238 /** Property value */
239 Utf8Str strValue;
240 /** Property timestamp */
241 LONG64 mTimestamp;
242 /** Property flags */
243 ULONG mFlags;
244 };
245
246 HWData();
247 ~HWData();
248
249 Bstr mHWVersion;
250 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
251 ULONG mMemorySize;
252 ULONG mMemoryBalloonSize;
253 BOOL mPageFusionEnabled;
254 ULONG mVRAMSize;
255 ULONG mMonitorCount;
256 BOOL mHWVirtExEnabled;
257 BOOL mHWVirtExExclusive;
258 BOOL mHWVirtExNestedPagingEnabled;
259 BOOL mHWVirtExLargePagesEnabled;
260 BOOL mHWVirtExVPIDEnabled;
261 BOOL mHWVirtExForceEnabled;
262 BOOL mAccelerate2DVideoEnabled;
263 BOOL mPAEEnabled;
264 BOOL mSyntheticCpu;
265 ULONG mCPUCount;
266 BOOL mCPUHotPlugEnabled;
267 ULONG mCpuExecutionCap;
268 BOOL mAccelerate3DEnabled;
269 BOOL mHpetEnabled;
270
271 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
272
273 settings::CpuIdLeaf mCpuIdStdLeafs[11];
274 settings::CpuIdLeaf mCpuIdExtLeafs[11];
275
276 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
277
278 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
279 SharedFolderList mSharedFolders;
280
281 ClipboardMode_T mClipboardMode;
282
283 typedef std::list<GuestProperty> GuestPropertyList;
284 GuestPropertyList mGuestProperties;
285 Utf8Str mGuestPropertyNotificationPatterns;
286
287 FirmwareType_T mFirmwareType;
288 KeyboardHidType_T mKeyboardHidType;
289 PointingHidType_T mPointingHidType;
290 ChipsetType_T mChipsetType;
291
292 BOOL mIoCacheEnabled;
293 ULONG mIoCacheSize;
294
295 typedef std::list< ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
296 PciDeviceAssignmentList mPciDeviceAssignments;
297 };
298
299 /**
300 * Hard disk and other media data.
301 *
302 * The usage policy is the same as for HWData, but a separate structure
303 * is necessary because hard disk data requires different procedures when
304 * taking or deleting snapshots, etc.
305 *
306 * The data variable is |mMediaData|.
307 */
308 struct MediaData
309 {
310 MediaData();
311 ~MediaData();
312
313 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
314 AttachmentList mAttachments;
315 };
316
317 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
318
319 DECLARE_NOT_AGGREGATABLE(Machine)
320
321 DECLARE_PROTECT_FINAL_CONSTRUCT()
322
323 BEGIN_COM_MAP(Machine)
324 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
325 END_COM_MAP()
326
327 DECLARE_EMPTY_CTOR_DTOR(Machine)
328
329 HRESULT FinalConstruct();
330 void FinalRelease();
331
332 // public initializer/uninitializer for internal purposes only:
333
334 // initializer for creating a new, empty machine
335 HRESULT init(VirtualBox *aParent,
336 const Utf8Str &strConfigFile,
337 const Utf8Str &strName,
338 GuestOSType *aOsType,
339 const Guid &aId,
340 bool fForceOverwrite);
341
342 // initializer for loading existing machine XML (either registered or not)
343 HRESULT init(VirtualBox *aParent,
344 const Utf8Str &strConfigFile,
345 const Guid *aId);
346
347 // initializer for machine config in memory (OVF import)
348 HRESULT init(VirtualBox *aParent,
349 const Utf8Str &strName,
350 const settings::MachineConfigFile &config);
351
352 void uninit();
353
354#ifdef VBOX_WITH_RESOURCE_USAGE_API
355 // Needed from VirtualBox, for the delayed metrics cleanup.
356 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
357#endif /* VBOX_WITH_RESOURCE_USAGE_API */
358
359protected:
360 HRESULT initImpl(VirtualBox *aParent,
361 const Utf8Str &strConfigFile);
362 HRESULT initDataAndChildObjects();
363 HRESULT registeredInit();
364 HRESULT tryCreateMachineConfigFile(bool fForceOverwrite);
365 void uninitDataAndChildObjects();
366
367public:
368 // IMachine properties
369 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
370 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
371 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
372 STDMETHOD(COMGETTER(Name))(BSTR *aName);
373 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
374 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
375 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
376 STDMETHOD(COMGETTER(Id))(BSTR *aId);
377 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
378 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
379 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
380 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
381 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
382 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
383 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
384 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
385 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
386 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
387 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
388 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
389 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
390 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
391 STDMETHOD(COMGETTER(EmulatedUSBCardReaderEnabled))(BOOL *enabled);
392 STDMETHOD(COMSETTER(EmulatedUSBCardReaderEnabled))(BOOL enabled);
393 STDMETHOD(COMGETTER(EmulatedUSBWebcameraEnabled))(BOOL *enabled);
394 STDMETHOD(COMSETTER(EmulatedUSBWebcameraEnabled))(BOOL enabled);
395 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
396 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
397 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
398 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
399 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
402 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
403 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
404 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
405 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
406 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
407 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
408 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
409 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
410 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
411 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
412 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
413 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
414 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
415 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
416 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
417 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
418 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
419 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
420 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
421 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
422 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
423 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
424 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
425 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
426 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
427 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
428 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
429 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
430 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
431 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
432 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
433 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
434 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
435 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
436 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
437 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
438 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
439 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
440 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
441 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
442 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
443 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
444 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
445 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
446 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
447 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
448 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
449 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
450 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
451 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
452 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
453 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
454 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
455 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
456 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
457 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
458 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
459 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
460 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
461 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
462 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
463 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
464 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
465 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
466 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
467 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
468
469 // IMachine methods
470 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
471 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
472
473 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
474 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
475 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
476 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
477 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
478 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
479 STDMETHOD(TemporaryEjectDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aTempEject);
480 STDMETHOD(NonRotationalDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aNonRotational);
481 STDMETHOD(SetAutoDiscardForDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aDiscard);
482 STDMETHOD(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
483 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
484 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
485 LONG aDevice, IMedium *aMedium, BOOL aForce);
486 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
487 IMedium **aMedium);
488 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
489 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
490 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
491 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
492 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
493 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
494 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
495 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
496 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
497 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
498 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
499 STDMETHOD(RemoveAllCPUIDLeaves)();
500 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
501 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
502 STDMETHOD(SaveSettings)();
503 STDMETHOD(DiscardSettings)();
504 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
505 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
506 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
507 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
508 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
509 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
510 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
511 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
512 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
513 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
514 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
515 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
516 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
517 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
518 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
519 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
520 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
521 STDMETHOD(RemoveStorageController(IN_BSTR aName));
522 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
523 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
524 STDMETHOD(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
525 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
526 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
527 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
528 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
529 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
530 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
531 STDMETHOD(HotPlugCPU(ULONG aCpu));
532 STDMETHOD(HotUnplugCPU(ULONG aCpu));
533 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
534 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
535 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
536 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL tryToUnbind));
537 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
538 STDMETHOD(CloneTo(IMachine *pTarget, CloneMode_T mode, ComSafeArrayIn(CloneOptions_T, options), IProgress **pProgress));
539 // public methods only for internal purposes
540
541 virtual bool isSnapshotMachine() const
542 {
543 return false;
544 }
545
546 virtual bool isSessionMachine() const
547 {
548 return false;
549 }
550
551 /**
552 * Override of the default locking class to be used for validating lock
553 * order with the standard member lock handle.
554 */
555 virtual VBoxLockingClass getLockingClass() const
556 {
557 return LOCKCLASS_MACHINEOBJECT;
558 }
559
560 /// @todo (dmik) add lock and make non-inlined after revising classes
561 // that use it. Note: they should enter Machine lock to keep the returned
562 // information valid!
563 bool isRegistered() { return !!mData->mRegistered; }
564
565 // unsafe inline public methods for internal purposes only (ensure there is
566 // a caller and a read lock before calling them!)
567
568 /**
569 * Returns the VirtualBox object this machine belongs to.
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 doing addCaller() manually.
574 */
575 VirtualBox* getVirtualBox() const { return mParent; }
576
577 /**
578 * Checks if this machine is accessible, without attempting to load the
579 * config file.
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 doing addCaller() manually.
584 */
585 bool isAccessible() const { return mData->mAccessible; }
586
587 /**
588 * Returns this machine ID.
589 *
590 * @note This method doesn't check this object's readiness. Intended to be
591 * used by ready Machine children (whose readiness is bound to the parent's
592 * one) or after adding a caller manually.
593 */
594 const Guid& getId() const { return mData->mUuid; }
595
596 /**
597 * Returns the snapshot ID this machine represents or an empty UUID if this
598 * instance is not SnapshotMachine.
599 *
600 * @note This method doesn't check this object's readiness. Intended to be
601 * used by ready Machine children (whose readiness is bound to the parent's
602 * one) or after adding a caller manually.
603 */
604 inline const Guid& getSnapshotId() const;
605
606 /**
607 * Returns this machine's full settings file path.
608 *
609 * @note This method doesn't lock this object or check its readiness.
610 * Intended to be used only after doing addCaller() manually and locking it
611 * for reading.
612 */
613 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
614
615 /**
616 * Returns this machine name.
617 *
618 * @note This method doesn't lock this object or check its readiness.
619 * Intended to be used only after doing addCaller() manually and locking it
620 * for reading.
621 */
622 const Utf8Str& getName() const { return mUserData->s.strName; }
623
624 enum
625 {
626 IsModified_MachineData = 0x0001,
627 IsModified_Storage = 0x0002,
628 IsModified_NetworkAdapters = 0x0008,
629 IsModified_SerialPorts = 0x0010,
630 IsModified_ParallelPorts = 0x0020,
631 IsModified_VRDEServer = 0x0040,
632 IsModified_AudioAdapter = 0x0080,
633 IsModified_USB = 0x0100,
634 IsModified_BIOS = 0x0200,
635 IsModified_SharedFolders = 0x0400,
636 IsModified_Snapshots = 0x0800,
637 IsModified_BandwidthControl = 0x1000
638 };
639
640 /**
641 * Checks if this machine is accessible, without attempting to load the
642 * config file.
643 *
644 * @note This method doesn't check this object's readiness. Intended to be
645 * used by ready Machine children (whose readiness is bound to the parent's
646 * one) or after doing addCaller() manually.
647 */
648 ChipsetType_T getChipsetType() const { return mHWData->mChipsetType; }
649
650 void setModified(uint32_t fl);
651 void setModifiedLock(uint32_t fl);
652
653 // callback handlers
654 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
655 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
656 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
657 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
658 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
659 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
660 virtual HRESULT onUSBControllerChange() { return S_OK; }
661 virtual HRESULT onStorageControllerChange() { return S_OK; }
662 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
663 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
664 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
665 virtual HRESULT onSharedFolderChange() { return S_OK; }
666 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
667 virtual HRESULT onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */) { return S_OK; }
668
669 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
670
671 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
672 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
673
674 void getLogFolder(Utf8Str &aLogFolder);
675 Utf8Str queryLogFilename(ULONG idx);
676
677 void composeSavedStateFilename(Utf8Str &strStateFilePath);
678
679 HRESULT launchVMProcess(IInternalSessionControl *aControl,
680 const Utf8Str &strType,
681 const Utf8Str &strEnvironment,
682 ProgressProxy *aProgress);
683
684 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
685 {
686 HRESULT rc;
687 *directControl = mData->mSession.mDirectControl;
688
689 if (!*directControl)
690 rc = E_ACCESSDENIED;
691 else
692 rc = S_OK;
693
694 return rc;
695 }
696
697#if defined(RT_OS_WINDOWS)
698
699 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
700 ComPtr<IInternalSessionControl> *aControl = NULL,
701 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
702 bool isSessionSpawning(RTPROCESS *aPID = NULL);
703
704 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
705 ComPtr<IInternalSessionControl> *aControl = NULL,
706 HANDLE *aIPCSem = NULL)
707 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
708
709#elif defined(RT_OS_OS2)
710
711 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
712 ComPtr<IInternalSessionControl> *aControl = NULL,
713 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
714
715 bool isSessionSpawning(RTPROCESS *aPID = NULL);
716
717 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
718 ComPtr<IInternalSessionControl> *aControl = NULL,
719 HMTX *aIPCSem = NULL)
720 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
721
722#else
723
724 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
725 ComPtr<IInternalSessionControl> *aControl = NULL,
726 bool aAllowClosing = false);
727 bool isSessionSpawning();
728
729 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
730 ComPtr<IInternalSessionControl> *aControl = NULL)
731 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
732
733#endif
734
735 bool checkForSpawnFailure();
736
737 HRESULT prepareRegister();
738
739 HRESULT getSharedFolder(CBSTR aName,
740 ComObjPtr<SharedFolder> &aSharedFolder,
741 bool aSetError = false)
742 {
743 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
744 return findSharedFolder(aName, aSharedFolder, aSetError);
745 }
746
747 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
748 MachineState_T *aState = NULL,
749 BOOL *aRegistered = NULL);
750 void releaseStateDependency();
751
752 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
753 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
754 bool fSetError = false)
755 {
756 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
757 pBandwidthGroup,
758 fSetError);
759 }
760
761protected:
762
763 HRESULT checkStateDependency(StateDependency aDepType);
764
765 Machine *getMachine();
766
767 void ensureNoStateDependencies();
768
769 virtual HRESULT setMachineState(MachineState_T aMachineState);
770
771 HRESULT findSharedFolder(const Utf8Str &aName,
772 ComObjPtr<SharedFolder> &aSharedFolder,
773 bool aSetError = false);
774
775 HRESULT loadSettings(bool aRegistered);
776 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
777 const Guid *puuidRegistry);
778 HRESULT loadSnapshot(const settings::Snapshot &data,
779 const Guid &aCurSnapshotId,
780 Snapshot *aParentSnapshot);
781 HRESULT loadHardware(const settings::Hardware &data);
782 HRESULT loadStorageControllers(const settings::Storage &data,
783 const Guid *puuidRegistry,
784 const Guid *puuidSnapshot);
785 HRESULT loadStorageDevices(StorageController *aStorageController,
786 const settings::StorageController &data,
787 const Guid *puuidRegistry,
788 const Guid *puuidSnapshot);
789
790 HRESULT findSnapshotById(const Guid &aId,
791 ComObjPtr<Snapshot> &aSnapshot,
792 bool aSetError = false);
793 HRESULT findSnapshotByName(const Utf8Str &strName,
794 ComObjPtr<Snapshot> &aSnapshot,
795 bool aSetError = false);
796
797 HRESULT getStorageControllerByName(const Utf8Str &aName,
798 ComObjPtr<StorageController> &aStorageController,
799 bool aSetError = false);
800
801 HRESULT getMediumAttachmentsOfController(CBSTR aName,
802 MediaData::AttachmentList &aAttachments);
803
804 enum
805 {
806 /* flags for #saveSettings() */
807 SaveS_ResetCurStateModified = 0x01,
808 SaveS_InformCallbacksAnyway = 0x02,
809 SaveS_Force = 0x04,
810 /* flags for #saveStateSettings() */
811 SaveSTS_CurStateModified = 0x20,
812 SaveSTS_StateFilePath = 0x40,
813 SaveSTS_StateTimeStamp = 0x80
814 };
815
816 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
817 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
818
819 void copyMachineDataToSettings(settings::MachineConfigFile &config);
820 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
821 HRESULT saveHardware(settings::Hardware &data);
822 HRESULT saveStorageControllers(settings::Storage &data);
823 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
824 settings::StorageController &data);
825 HRESULT saveStateSettings(int aFlags);
826
827 void addMediumToRegistry(ComObjPtr<Medium> &pMedium,
828 GuidList &llRegistriesThatNeedSaving,
829 Guid *puuid);
830
831 HRESULT createImplicitDiffs(IProgress *aProgress,
832 ULONG aWeight,
833 bool aOnline,
834 GuidList *pllRegistriesThatNeedSaving);
835 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
836
837 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
838 IN_BSTR aControllerName,
839 LONG aControllerPort,
840 LONG aDevice);
841 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
842 ComObjPtr<Medium> pMedium);
843 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
844 Guid &id);
845
846 HRESULT detachDevice(MediumAttachment *pAttach,
847 AutoWriteLock &writeLock,
848 Snapshot *pSnapshot,
849 GuidList *pllRegistriesThatNeedSaving);
850
851 HRESULT detachAllMedia(AutoWriteLock &writeLock,
852 Snapshot *pSnapshot,
853 CleanupMode_T cleanupMode,
854 MediaList &llMedia);
855
856 void commitMedia(bool aOnline = false);
857 void rollbackMedia();
858
859 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
860
861 void rollback(bool aNotify);
862 void commit();
863 void copyFrom(Machine *aThat);
864 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
865
866 struct DeleteTask;
867 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
868 HRESULT deleteTaskWorker(DeleteTask &task);
869
870#ifdef VBOX_WITH_GUEST_PROPS
871 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
872 LONG64 *aTimestamp, BSTR *aFlags) const;
873 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
874 LONG64 *aTimestamp, BSTR *aFlags) const;
875 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
876 IN_BSTR aFlags);
877 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
878 IN_BSTR aFlags);
879 HRESULT enumerateGuestPropertiesInService
880 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
881 ComSafeArrayOut(BSTR, aValues),
882 ComSafeArrayOut(LONG64, aTimestamps),
883 ComSafeArrayOut(BSTR, aFlags));
884 HRESULT enumerateGuestPropertiesOnVM
885 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
886 ComSafeArrayOut(BSTR, aValues),
887 ComSafeArrayOut(LONG64, aTimestamps),
888 ComSafeArrayOut(BSTR, aFlags));
889#endif /* VBOX_WITH_GUEST_PROPS */
890
891#ifdef VBOX_WITH_RESOURCE_USAGE_API
892 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
893
894 pm::CollectorGuest *mCollectorGuest;
895#endif /* VBOX_WITH_RESOURCE_USAGE_API */
896
897 Machine* const mPeer;
898
899 VirtualBox * const mParent;
900
901 Shareable<Data> mData;
902 Shareable<SSData> mSSData;
903
904 Backupable<UserData> mUserData;
905 Backupable<HWData> mHWData;
906 Backupable<MediaData> mMediaData;
907
908 // the following fields need special backup/rollback/commit handling,
909 // so they cannot be a part of HWData
910
911 const ComObjPtr<VRDEServer> mVRDEServer;
912 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
913 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
914 const ComObjPtr<AudioAdapter> mAudioAdapter;
915 const ComObjPtr<USBController> mUSBController;
916 const ComObjPtr<BIOSSettings> mBIOSSettings;
917 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
918 const ComObjPtr<BandwidthControl> mBandwidthControl;
919
920 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
921 Backupable<StorageControllerList> mStorageControllers;
922
923 friend class SessionMachine;
924 friend class SnapshotMachine;
925 friend class Appliance;
926 friend class VirtualBox;
927
928 friend class MachineCloneVM;
929};
930
931// SessionMachine class
932////////////////////////////////////////////////////////////////////////////////
933
934/**
935 * @note Notes on locking objects of this class:
936 * SessionMachine shares some data with the primary Machine instance (pointed
937 * to by the |mPeer| member). In order to provide data consistency it also
938 * shares its lock handle. This means that whenever you lock a SessionMachine
939 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
940 * instance is also locked in the same lock mode. Keep it in mind.
941 */
942class ATL_NO_VTABLE SessionMachine :
943 public Machine,
944 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
945{
946public:
947 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
948
949 DECLARE_NOT_AGGREGATABLE(SessionMachine)
950
951 DECLARE_PROTECT_FINAL_CONSTRUCT()
952
953 BEGIN_COM_MAP(SessionMachine)
954 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
955 COM_INTERFACE_ENTRY(IInternalMachineControl)
956 END_COM_MAP()
957
958 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
959
960 HRESULT FinalConstruct();
961 void FinalRelease();
962
963 // public initializer/uninitializer for internal purposes only
964 HRESULT init(Machine *aMachine);
965 void uninit() { uninit(Uninit::Unexpected); }
966
967 // util::Lockable interface
968 RWLockHandle *lockHandle() const;
969
970 // IInternalMachineControl methods
971 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
972 STDMETHOD(UpdateState)(MachineState_T machineState);
973 STDMETHOD(GetIPCId)(BSTR *id);
974 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
975 STDMETHOD(EndPowerUp)(LONG iResult);
976 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
977 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
978 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
979 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
980 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
981 STDMETHOD(AutoCaptureUSBDevices)();
982 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
983 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
984 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
985 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
986 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
987 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
988 IN_BSTR aName,
989 IN_BSTR aDescription,
990 IProgress *aConsoleProgress,
991 BOOL fTakingSnapshotOnline,
992 BSTR *aStateFilePath);
993 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
994 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
995 IN_BSTR aEndID, BOOL fDeleteAllChildren,
996 MachineState_T *aMachineState, IProgress **aProgress);
997 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
998 IMedium *aSource, IMedium *aTarget,
999 BOOL fMergeForward,
1000 IMedium *pParentForTarget,
1001 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1002 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1003 ISnapshot *aSnapshot,
1004 MachineState_T *aMachineState,
1005 IProgress **aProgress);
1006 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1007 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1008 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1009 LONG64 aTimestamp, IN_BSTR aFlags);
1010 STDMETHOD(LockMedia)() { return lockMedia(); }
1011 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
1012 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1013 IMediumAttachment **aNewAttachment);
1014
1015 // public methods only for internal purposes
1016
1017 virtual bool isSessionMachine() const
1018 {
1019 return true;
1020 }
1021
1022 bool checkForDeath();
1023
1024 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1025 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1026 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1027 HRESULT onStorageControllerChange();
1028 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1029 HRESULT onSerialPortChange(ISerialPort *serialPort);
1030 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1031 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1032 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1033 HRESULT onVRDEServerChange(BOOL aRestart);
1034 HRESULT onUSBControllerChange();
1035 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1036 IVirtualBoxErrorInfo *aError,
1037 ULONG aMaskedIfs);
1038 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1039 IVirtualBoxErrorInfo *aError);
1040 HRESULT onSharedFolderChange();
1041 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1042 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove);
1043
1044 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1045
1046private:
1047
1048 struct ConsoleTaskData
1049 {
1050 ConsoleTaskData()
1051 : mLastState(MachineState_Null)
1052 { }
1053
1054 MachineState_T mLastState;
1055 ComObjPtr<Progress> mProgress;
1056
1057 // used when taking snapshot
1058 ComObjPtr<Snapshot> mSnapshot;
1059
1060 // used when saving state (either as part of a snapshot or separate)
1061 Utf8Str strStateFilePath;
1062 };
1063
1064 struct Uninit
1065 {
1066 enum Reason { Unexpected, Abnormal, Normal };
1067 };
1068
1069 struct SnapshotTask;
1070 struct DeleteSnapshotTask;
1071 struct RestoreSnapshotTask;
1072
1073 friend struct DeleteSnapshotTask;
1074 friend struct RestoreSnapshotTask;
1075
1076 void uninit(Uninit::Reason aReason);
1077
1078 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1079 void releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1080
1081 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1082 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1083
1084 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1085 const Guid &machineId,
1086 const Guid &snapshotId,
1087 bool fOnlineMergePossible,
1088 MediumLockList *aVMMALockList,
1089 ComObjPtr<Medium> &aSource,
1090 ComObjPtr<Medium> &aTarget,
1091 bool &fMergeForward,
1092 ComObjPtr<Medium> &pParentForTarget,
1093 MediaList &aChildrenToReparent,
1094 bool &fNeedOnlineMerge,
1095 MediumLockList * &aMediumLockList);
1096 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1097 const ComObjPtr<Medium> &aSource,
1098 const MediaList &aChildrenToReparent,
1099 bool fNeedsOnlineMerge,
1100 MediumLockList *aMediumLockList,
1101 const Guid &aMediumId,
1102 const Guid &aSnapshotId);
1103 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1104 const ComObjPtr<Medium> &aSource,
1105 const ComObjPtr<Medium> &aTarget,
1106 bool fMergeForward,
1107 const ComObjPtr<Medium> &pParentForTarget,
1108 const MediaList &aChildrenToReparent,
1109 MediumLockList *aMediumLockList,
1110 ComObjPtr<Progress> &aProgress,
1111 bool *pfNeedsMachineSaveSettings);
1112
1113 HRESULT lockMedia();
1114 void unlockMedia();
1115
1116 HRESULT setMachineState(MachineState_T aMachineState);
1117 HRESULT updateMachineStateOnClient();
1118
1119 HRESULT mRemoveSavedState;
1120
1121 ConsoleTaskData mConsoleTaskData;
1122
1123 /** interprocess semaphore handle for this machine */
1124#if defined(RT_OS_WINDOWS)
1125 HANDLE mIPCSem;
1126 Bstr mIPCSemName;
1127 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1128 ComPtr<IInternalSessionControl> *aControl,
1129 HANDLE *aIPCSem, bool aAllowClosing);
1130#elif defined(RT_OS_OS2)
1131 HMTX mIPCSem;
1132 Bstr mIPCSemName;
1133 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1134 ComPtr<IInternalSessionControl> *aControl,
1135 HMTX *aIPCSem, bool aAllowClosing);
1136#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1137 int mIPCSem;
1138# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1139 Bstr mIPCKey;
1140# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1141#else
1142# error "Port me!"
1143#endif
1144
1145 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1146};
1147
1148// SnapshotMachine class
1149////////////////////////////////////////////////////////////////////////////////
1150
1151/**
1152 * @note Notes on locking objects of this class:
1153 * SnapshotMachine shares some data with the primary Machine instance (pointed
1154 * to by the |mPeer| member). In order to provide data consistency it also
1155 * shares its lock handle. This means that whenever you lock a SessionMachine
1156 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1157 * instance is also locked in the same lock mode. Keep it in mind.
1158 */
1159class ATL_NO_VTABLE SnapshotMachine :
1160 public Machine
1161{
1162public:
1163 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1164
1165 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1166
1167 DECLARE_PROTECT_FINAL_CONSTRUCT()
1168
1169 BEGIN_COM_MAP(SnapshotMachine)
1170 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1171 END_COM_MAP()
1172
1173 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1174
1175 HRESULT FinalConstruct();
1176 void FinalRelease();
1177
1178 // public initializer/uninitializer for internal purposes only
1179 HRESULT init(SessionMachine *aSessionMachine,
1180 IN_GUID aSnapshotId,
1181 const Utf8Str &aStateFilePath);
1182 HRESULT init(Machine *aMachine,
1183 const settings::Hardware &hardware,
1184 const settings::Storage &storage,
1185 IN_GUID aSnapshotId,
1186 const Utf8Str &aStateFilePath);
1187 void uninit();
1188
1189 // util::Lockable interface
1190 RWLockHandle *lockHandle() const;
1191
1192 // public methods only for internal purposes
1193
1194 virtual bool isSnapshotMachine() const
1195 {
1196 return true;
1197 }
1198
1199 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1200
1201 // unsafe inline public methods for internal purposes only (ensure there is
1202 // a caller and a read lock before calling them!)
1203
1204 const Guid& getSnapshotId() const { return mSnapshotId; }
1205
1206private:
1207
1208 Guid mSnapshotId;
1209
1210 friend class Snapshot;
1211};
1212
1213// third party methods that depend on SnapshotMachine definition
1214
1215inline const Guid &Machine::getSnapshotId() const
1216{
1217 return (isSnapshotMachine())
1218 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1219 : Guid::Empty;
1220}
1221
1222
1223#endif // ____H_MACHINEIMPL
1224/* 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