VirtualBox

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

Last change on this file since 41549 was 41371, checked in by vboxsync, 13 years ago

Main,include,VBoxManage: smartcard support: IMachine::EmulatedUSBCardReaderEnabled.

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