VirtualBox

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

Last change on this file since 45961 was 45926, checked in by vboxsync, 12 years ago

IMachine::VideoCaptureFps

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