VirtualBox

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

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

Main: fix setting the current state modification flag in some circumstances

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