VirtualBox

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

Last change on this file since 49059 was 49059, checked in by vboxsync, 11 years ago

Forgot part of r89856.

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