VirtualBox

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

Last change on this file since 46034 was 45971, checked in by vboxsync, 12 years ago

Main, VMM: Added an API seting to disable VT-x unrestricted execution.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette