VirtualBox

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

Last change on this file since 45912 was 45838, checked in by vboxsync, 12 years ago

VPX: plugged memory leak; introduced rate parameter; clear artefacts from previous frames after resize; cleanup

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