VirtualBox

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

Last change on this file since 48446 was 48431, checked in by vboxsync, 12 years ago

Main/Machine+Session: New generic client session watcher implementation based on token objects, works on all platforms and is used for now on XPCOM. Additionally a better error message when several API clients are racing for a lock, previously it could be quite confusing.

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