VirtualBox

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

Last change on this file since 46497 was 46465, checked in by vboxsync, 12 years ago

Main/VPX: introduced onVideoCaptureChange event

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.1 KB
Line 
1/* $Id: MachineImpl.h 46465 2013-06-10 14:11:26Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "ProgressImpl.h"
24#include "VRDEServerImpl.h"
25#include "MediumAttachmentImpl.h"
26#include "PCIDeviceAttachmentImpl.h"
27#include "MediumLock.h"
28#include "NetworkAdapterImpl.h"
29#include "AudioAdapterImpl.h"
30#include "SerialPortImpl.h"
31#include "ParallelPortImpl.h"
32#include "BIOSSettingsImpl.h"
33#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
34#include "BandwidthControlImpl.h"
35#include "BandwidthGroupImpl.h"
36#include "VBox/settings.h"
37#ifdef VBOX_WITH_RESOURCE_USAGE_API
38#include "Performance.h"
39#include "PerformanceImpl.h"
40#endif /* VBOX_WITH_RESOURCE_USAGE_API */
41
42// generated header
43#include "SchemaDefs.h"
44
45#include "VBox/com/ErrorInfo.h"
46
47#include <iprt/file.h>
48#include <iprt/thread.h>
49#include <iprt/time.h>
50
51#include <list>
52#include <vector>
53
54// defines
55////////////////////////////////////////////////////////////////////////////////
56
57// helper declarations
58////////////////////////////////////////////////////////////////////////////////
59
60class Progress;
61class ProgressProxy;
62class Keyboard;
63class Mouse;
64class Display;
65class MachineDebugger;
66class USBController;
67class Snapshot;
68class SharedFolder;
69class HostUSBDevice;
70class StorageController;
71
72class SessionMachine;
73
74namespace settings
75{
76 class MachineConfigFile;
77 struct Snapshot;
78 struct Hardware;
79 struct Storage;
80 struct StorageController;
81 struct MachineRegistryEntry;
82}
83
84// Machine class
85////////////////////////////////////////////////////////////////////////////////
86
87class ATL_NO_VTABLE Machine :
88 public VirtualBoxBase,
89 VBOX_SCRIPTABLE_IMPL(IMachine)
90{
91 Q_OBJECT
92
93public:
94
95 enum StateDependency
96 {
97 AnyStateDep = 0,
98 MutableStateDep,
99 MutableOrSavedStateDep,
100 OfflineStateDep
101 };
102
103 /**
104 * Internal machine data.
105 *
106 * Only one instance of this data exists per every machine -- it is shared
107 * by the Machine, SessionMachine and all SnapshotMachine instances
108 * associated with the given machine using the util::Shareable template
109 * through the mData variable.
110 *
111 * @note |const| members are persistent during lifetime so can be
112 * accessed without locking.
113 *
114 * @note There is no need to lock anything inside init() or uninit()
115 * methods, because they are always serialized (see AutoCaller).
116 */
117 struct Data
118 {
119 /**
120 * Data structure to hold information about sessions opened for the
121 * given machine.
122 */
123 struct Session
124 {
125 /** Control of the direct session opened by lockMachine() */
126 ComPtr<IInternalSessionControl> mDirectControl;
127
128 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
129
130 /** list of controls of all opened remote sessions */
131 RemoteControlList mRemoteControls;
132
133 /** launchVMProcess() and OnSessionEnd() progress indicator */
134 ComObjPtr<ProgressProxy> mProgress;
135
136 /**
137 * PID of the session object that must be passed to openSession()
138 * to finalize the launchVMProcess() request (i.e., PID of the
139 * process created by launchVMProcess())
140 */
141 RTPROCESS mPID;
142
143 /** Current session state */
144 SessionState_T mState;
145
146 /** Session type string (for indirect sessions) */
147 Bstr mType;
148
149 /** Session machine object */
150 ComObjPtr<SessionMachine> mMachine;
151
152 /** Medium object lock collection. */
153 MediumLockListMap mLockedMedia;
154 };
155
156 Data();
157 ~Data();
158
159 const Guid mUuid;
160 BOOL mRegistered;
161
162 Utf8Str m_strConfigFile;
163 Utf8Str m_strConfigFileFull;
164
165 // machine settings XML file
166 settings::MachineConfigFile *pMachineConfigFile;
167 uint32_t flModifications;
168 bool m_fAllowStateModification;
169
170 BOOL mAccessible;
171 com::ErrorInfo mAccessError;
172
173 MachineState_T mMachineState;
174 RTTIMESPEC mLastStateChange;
175
176 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
177 uint32_t mMachineStateDeps;
178 RTSEMEVENTMULTI mMachineStateDepsSem;
179 uint32_t mMachineStateChangePending;
180
181 BOOL mCurrentStateModified;
182 /** Guest properties have been modified and need saving since the
183 * machine was started, or there are transient properties which need
184 * deleting and the machine is being shut down. */
185 BOOL mGuestPropertiesModified;
186
187 Session mSession;
188
189 ComObjPtr<Snapshot> mFirstSnapshot;
190 ComObjPtr<Snapshot> mCurrentSnapshot;
191
192 // list of files to delete in Delete(); this list is filled by Unregister()
193 std::list<Utf8Str> llFilesToDelete;
194 };
195
196 /**
197 * Saved state data.
198 *
199 * It's actually only the state file path string, but it needs to be
200 * separate from Data, because Machine and SessionMachine instances
201 * share it, while SnapshotMachine does not.
202 *
203 * The data variable is |mSSData|.
204 */
205 struct SSData
206 {
207 Utf8Str strStateFilePath;
208 };
209
210 /**
211 * User changeable machine data.
212 *
213 * This data is common for all machine snapshots, i.e. it is shared
214 * by all SnapshotMachine instances associated with the given machine
215 * using the util::Backupable template through the |mUserData| variable.
216 *
217 * SessionMachine instances can alter this data and discard changes.
218 *
219 * @note There is no need to lock anything inside init() or uninit()
220 * methods, because they are always serialized (see AutoCaller).
221 */
222 struct UserData
223 {
224 settings::MachineUserData s;
225 typedef std::vector<uint8_t> IconBlob;
226 IconBlob mIcon;
227 };
228
229 /**
230 * Hardware data.
231 *
232 * This data is unique for a machine and for every machine snapshot.
233 * Stored using the util::Backupable template in the |mHWData| variable.
234 *
235 * SessionMachine instances can alter this data and discard changes.
236 */
237 struct HWData
238 {
239 /**
240 * Data structure to hold information about a guest property.
241 */
242 struct GuestProperty {
243 /** Property value */
244 Utf8Str strValue;
245 /** Property timestamp */
246 LONG64 mTimestamp;
247 /** Property flags */
248 ULONG mFlags;
249 };
250
251 HWData();
252 ~HWData();
253
254 Bstr mHWVersion;
255 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
256 ULONG mMemorySize;
257 ULONG mMemoryBalloonSize;
258 BOOL mPageFusionEnabled;
259 GraphicsControllerType_T mGraphicsControllerType;
260 ULONG mVRAMSize;
261 ULONG mVideoCaptureWidth;
262 ULONG mVideoCaptureHeight;
263 ULONG mVideoCaptureRate;
264 ULONG mVideoCaptureFps;
265 Bstr mVideoCaptureFile;
266 BOOL mVideoCaptureEnabled;
267 BOOL maVideoCaptureScreens[SchemaDefs::MaxGuestMonitors];
268 ULONG mMonitorCount;
269 BOOL mHWVirtExEnabled;
270 BOOL mHWVirtExExclusive;
271 BOOL mHWVirtExNestedPagingEnabled;
272 BOOL mHWVirtExLargePagesEnabled;
273 BOOL mHWVirtExVPIDEnabled;
274 BOOL mHWVirtExUXEnabled;
275 BOOL mHWVirtExForceEnabled;
276 BOOL mAccelerate2DVideoEnabled;
277 BOOL mPAEEnabled;
278 settings::Hardware::LongModeType mLongMode;
279 BOOL mSyntheticCpu;
280 ULONG mCPUCount;
281 BOOL mCPUHotPlugEnabled;
282 ULONG mCpuExecutionCap;
283 BOOL mAccelerate3DEnabled;
284 BOOL mHPETEnabled;
285
286 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
287
288 settings::CpuIdLeaf mCpuIdStdLeafs[11];
289 settings::CpuIdLeaf mCpuIdExtLeafs[11];
290
291 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
292
293 typedef std::list<ComObjPtr<SharedFolder> > SharedFolderList;
294 SharedFolderList mSharedFolders;
295
296 ClipboardMode_T mClipboardMode;
297 DragAndDropMode_T mDragAndDropMode;
298
299 typedef std::map<Utf8Str, GuestProperty> GuestPropertyMap;
300 GuestPropertyMap mGuestProperties;
301 Utf8Str mGuestPropertyNotificationPatterns;
302
303 FirmwareType_T mFirmwareType;
304 KeyboardHIDType_T mKeyboardHIDType;
305 PointingHIDType_T mPointingHIDType;
306 ChipsetType_T mChipsetType;
307 BOOL mEmulatedUSBWebcamEnabled;
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(EmulatedUSBWebcameraEnabled))(BOOL *aEnabled);
421 STDMETHOD(COMSETTER(EmulatedUSBWebcameraEnabled))(BOOL aEnabled);
422 STDMETHOD(COMGETTER(HPETEnabled))(BOOL *enabled);
423 STDMETHOD(COMSETTER(HPETEnabled))(BOOL enabled);
424 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
425 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
426 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
427 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
428 STDMETHOD(COMGETTER(GraphicsControllerType))(GraphicsControllerType_T *aGraphicsController);
429 STDMETHOD(COMSETTER(GraphicsControllerType))(GraphicsControllerType_T aGraphicsController);
430 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
431 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
432 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *aEnabled);
433 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL aEnabled);
434 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *aEnabled);
435 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL aEnabled);
436 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
437 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
438 STDMETHOD(COMGETTER(VideoCaptureEnabled))(BOOL *u8VideoRecEnabled);
439 STDMETHOD(COMSETTER(VideoCaptureEnabled))(BOOL u8VideoRecEnabled);
440 STDMETHOD(COMGETTER(VideoCaptureScreens))(ComSafeArrayOut(BOOL, aScreens));
441 STDMETHOD(COMSETTER(VideoCaptureScreens))(ComSafeArrayIn(BOOL, aScreens));
442 STDMETHOD(COMGETTER(VideoCaptureFile))(BSTR * ppChVideoRecFilename);
443 STDMETHOD(COMSETTER(VideoCaptureFile))(IN_BSTR pChVideoRecFilename);
444 STDMETHOD(COMGETTER(VideoCaptureWidth))(ULONG *aHorzRes);
445 STDMETHOD(COMSETTER(VideoCaptureWidth))(ULONG aorzRes);
446 STDMETHOD(COMGETTER(VideoCaptureHeight))(ULONG *aVertRes);
447 STDMETHOD(COMSETTER(VideoCaptureHeight))(ULONG aVertRes);
448 STDMETHOD(COMGETTER(VideoCaptureRate))(ULONG *aRate);
449 STDMETHOD(COMSETTER(VideoCaptureRate))(ULONG aRate);
450 STDMETHOD(COMGETTER(VideoCaptureFps))(ULONG *aFps);
451 STDMETHOD(COMSETTER(VideoCaptureFps))(ULONG aFps);
452 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
453 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
454 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
455 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
456 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
457 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
458 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
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
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(QuerySavedGuestScreenInfo)(ULONG uScreenId, ULONG *puOriginX, ULONG *puOriginY, ULONG *puWidth, ULONG *puHeight, BOOL *pfEnabled);
594 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
595 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
596 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
597 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
598 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
599 STDMETHOD(HotPlugCPU(ULONG aCpu));
600 STDMETHOD(HotUnplugCPU(ULONG aCpu));
601 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
602 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
603 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
604 STDMETHOD(AttachHostPCIDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL tryToUnbind));
605 STDMETHOD(DetachHostPCIDevice(LONG hostAddress));
606 STDMETHOD(CloneTo(IMachine *pTarget, CloneMode_T mode, ComSafeArrayIn(CloneOptions_T, options), IProgress **pProgress));
607 // public methods only for internal purposes
608
609 virtual bool isSnapshotMachine() const
610 {
611 return false;
612 }
613
614 virtual bool isSessionMachine() const
615 {
616 return false;
617 }
618
619 /**
620 * Override of the default locking class to be used for validating lock
621 * order with the standard member lock handle.
622 */
623 virtual VBoxLockingClass getLockingClass() const
624 {
625 return LOCKCLASS_MACHINEOBJECT;
626 }
627
628 /// @todo (dmik) add lock and make non-inlined after revising classes
629 // that use it. Note: they should enter Machine lock to keep the returned
630 // information valid!
631 bool isRegistered() { return !!mData->mRegistered; }
632
633 // unsafe inline public methods for internal purposes only (ensure there is
634 // a caller and a read lock before calling them!)
635
636 /**
637 * Returns the VirtualBox object this machine belongs to.
638 *
639 * @note This method doesn't check this object's readiness. Intended to be
640 * used by ready Machine children (whose readiness is bound to the parent's
641 * one) or after doing addCaller() manually.
642 */
643 VirtualBox* getVirtualBox() const { return mParent; }
644
645 /**
646 * Checks if this machine is accessible, without attempting to load the
647 * config file.
648 *
649 * @note This method doesn't check this object's readiness. Intended to be
650 * used by ready Machine children (whose readiness is bound to the parent's
651 * one) or after doing addCaller() manually.
652 */
653 bool isAccessible() const { return !!mData->mAccessible; }
654
655 /**
656 * Returns this machine ID.
657 *
658 * @note This method doesn't check this object's readiness. Intended to be
659 * used by ready Machine children (whose readiness is bound to the parent's
660 * one) or after adding a caller manually.
661 */
662 const Guid& getId() const { return mData->mUuid; }
663
664 /**
665 * Returns the snapshot ID this machine represents or an empty UUID if this
666 * instance is not SnapshotMachine.
667 *
668 * @note This method doesn't check this object's readiness. Intended to be
669 * used by ready Machine children (whose readiness is bound to the parent's
670 * one) or after adding a caller manually.
671 */
672 inline const Guid& getSnapshotId() const;
673
674 /**
675 * Returns this machine's full settings file path.
676 *
677 * @note This method doesn't lock this object or check its readiness.
678 * Intended to be used only after doing addCaller() manually and locking it
679 * for reading.
680 */
681 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
682
683 /**
684 * Returns this machine name.
685 *
686 * @note This method doesn't lock this object or check its readiness.
687 * Intended to be used only after doing addCaller() manually and locking it
688 * for reading.
689 */
690 const Utf8Str& getName() const { return mUserData->s.strName; }
691
692 enum
693 {
694 IsModified_MachineData = 0x0001,
695 IsModified_Storage = 0x0002,
696 IsModified_NetworkAdapters = 0x0008,
697 IsModified_SerialPorts = 0x0010,
698 IsModified_ParallelPorts = 0x0020,
699 IsModified_VRDEServer = 0x0040,
700 IsModified_AudioAdapter = 0x0080,
701 IsModified_USB = 0x0100,
702 IsModified_BIOS = 0x0200,
703 IsModified_SharedFolders = 0x0400,
704 IsModified_Snapshots = 0x0800,
705 IsModified_BandwidthControl = 0x1000
706 };
707
708 /**
709 * Returns various information about this machine.
710 *
711 * @note This method doesn't lock this object or check its readiness.
712 * Intended to be used only after doing addCaller() manually and locking it
713 * for reading.
714 */
715 ChipsetType_T getChipsetType() const { return mHWData->mChipsetType; }
716
717 void setModified(uint32_t fl, bool fAllowStateModification = true);
718 void setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
719
720 bool isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
721 void allowStateModification() { mData->m_fAllowStateModification = true; }
722 void disallowStateModification() { mData->m_fAllowStateModification = false; }
723
724 const StringsList &getGroups() const { return mUserData->s.llGroups; }
725
726 // callback handlers
727 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
728 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
729 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
730 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
731 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
732 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
733 virtual HRESULT onUSBControllerChange() { return S_OK; }
734 virtual HRESULT onStorageControllerChange() { return S_OK; }
735 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
736 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
737 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
738 virtual HRESULT onSharedFolderChange() { return S_OK; }
739 virtual HRESULT onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
740 virtual HRESULT onDragAndDropModeChange(DragAndDropMode_T /* aDragAndDropMode */) { return S_OK; }
741 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
742 virtual HRESULT onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */, BOOL /* silent */) { return S_OK; }
743 virtual HRESULT onVideoCaptureChange() { return S_OK; }
744
745 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
746
747 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
748 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
749
750 void getLogFolder(Utf8Str &aLogFolder);
751 Utf8Str queryLogFilename(ULONG idx);
752
753 void composeSavedStateFilename(Utf8Str &strStateFilePath);
754
755 HRESULT launchVMProcess(IInternalSessionControl *aControl,
756 const Utf8Str &strType,
757 const Utf8Str &strEnvironment,
758 ProgressProxy *aProgress);
759
760 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
761 {
762 HRESULT rc;
763 *directControl = mData->mSession.mDirectControl;
764
765 if (!*directControl)
766 rc = E_ACCESSDENIED;
767 else
768 rc = S_OK;
769
770 return rc;
771 }
772
773#if defined(RT_OS_WINDOWS)
774
775 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
776 ComPtr<IInternalSessionControl> *aControl = NULL,
777 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
778 bool isSessionSpawning(RTPROCESS *aPID = NULL);
779
780 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
781 ComPtr<IInternalSessionControl> *aControl = NULL,
782 HANDLE *aIPCSem = NULL)
783 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
784
785#elif defined(RT_OS_OS2)
786
787 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
788 ComPtr<IInternalSessionControl> *aControl = NULL,
789 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
790
791 bool isSessionSpawning(RTPROCESS *aPID = NULL);
792
793 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
794 ComPtr<IInternalSessionControl> *aControl = NULL,
795 HMTX *aIPCSem = NULL)
796 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
797
798#else
799
800 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
801 ComPtr<IInternalSessionControl> *aControl = NULL,
802 bool aAllowClosing = false);
803 bool isSessionSpawning();
804
805 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
806 ComPtr<IInternalSessionControl> *aControl = NULL)
807 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
808
809#endif
810
811 bool checkForSpawnFailure();
812
813 HRESULT prepareRegister();
814
815 HRESULT getSharedFolder(CBSTR aName,
816 ComObjPtr<SharedFolder> &aSharedFolder,
817 bool aSetError = false)
818 {
819 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
820 return findSharedFolder(aName, aSharedFolder, aSetError);
821 }
822
823 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
824 MachineState_T *aState = NULL,
825 BOOL *aRegistered = NULL);
826 void releaseStateDependency();
827
828 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
829 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
830 bool fSetError = false)
831 {
832 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
833 pBandwidthGroup,
834 fSetError);
835 }
836
837protected:
838
839 HRESULT checkStateDependency(StateDependency aDepType);
840
841 Machine *getMachine();
842
843 void ensureNoStateDependencies();
844
845 virtual HRESULT setMachineState(MachineState_T aMachineState);
846
847 HRESULT findSharedFolder(const Utf8Str &aName,
848 ComObjPtr<SharedFolder> &aSharedFolder,
849 bool aSetError = false);
850
851 HRESULT loadSettings(bool aRegistered);
852 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
853 const Guid *puuidRegistry);
854 HRESULT loadSnapshot(const settings::Snapshot &data,
855 const Guid &aCurSnapshotId,
856 Snapshot *aParentSnapshot);
857 HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
858 const settings::Autostart *pAutostart);
859 HRESULT loadDebugging(const settings::Debugging *pDbg);
860 HRESULT loadAutostart(const settings::Autostart *pAutostart);
861 HRESULT loadStorageControllers(const settings::Storage &data,
862 const Guid *puuidRegistry,
863 const Guid *puuidSnapshot);
864 HRESULT loadStorageDevices(StorageController *aStorageController,
865 const settings::StorageController &data,
866 const Guid *puuidRegistry,
867 const Guid *puuidSnapshot);
868
869 HRESULT findSnapshotById(const Guid &aId,
870 ComObjPtr<Snapshot> &aSnapshot,
871 bool aSetError = false);
872 HRESULT findSnapshotByName(const Utf8Str &strName,
873 ComObjPtr<Snapshot> &aSnapshot,
874 bool aSetError = false);
875
876 HRESULT getStorageControllerByName(const Utf8Str &aName,
877 ComObjPtr<StorageController> &aStorageController,
878 bool aSetError = false);
879
880 HRESULT getMediumAttachmentsOfController(CBSTR aName,
881 MediaData::AttachmentList &aAttachments);
882
883 enum
884 {
885 /* flags for #saveSettings() */
886 SaveS_ResetCurStateModified = 0x01,
887 SaveS_InformCallbacksAnyway = 0x02,
888 SaveS_Force = 0x04,
889 /* flags for #saveStateSettings() */
890 SaveSTS_CurStateModified = 0x20,
891 SaveSTS_StateFilePath = 0x40,
892 SaveSTS_StateTimeStamp = 0x80
893 };
894
895 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
896 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
897
898 void copyMachineDataToSettings(settings::MachineConfigFile &config);
899 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
900 HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
901 settings::Autostart *pAutostart);
902 HRESULT saveStorageControllers(settings::Storage &data);
903 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
904 settings::StorageController &data);
905 HRESULT saveStateSettings(int aFlags);
906
907 void addMediumToRegistry(ComObjPtr<Medium> &pMedium);
908
909 HRESULT createImplicitDiffs(IProgress *aProgress,
910 ULONG aWeight,
911 bool aOnline);
912 HRESULT deleteImplicitDiffs(bool aOnline);
913
914 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
915 IN_BSTR aControllerName,
916 LONG aControllerPort,
917 LONG aDevice);
918 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
919 ComObjPtr<Medium> pMedium);
920 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
921 Guid &id);
922
923 HRESULT detachDevice(MediumAttachment *pAttach,
924 AutoWriteLock &writeLock,
925 Snapshot *pSnapshot);
926
927 HRESULT detachAllMedia(AutoWriteLock &writeLock,
928 Snapshot *pSnapshot,
929 CleanupMode_T cleanupMode,
930 MediaList &llMedia);
931
932 void commitMedia(bool aOnline = false);
933 void rollbackMedia();
934
935 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
936
937 void rollback(bool aNotify);
938 void commit();
939 void copyFrom(Machine *aThat);
940 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
941
942 struct DeleteTask;
943 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
944 HRESULT deleteTaskWorker(DeleteTask &task);
945
946 Utf8Str getExtraData(const Utf8Str &strKey);
947
948#ifdef VBOX_WITH_GUEST_PROPS
949 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
950 LONG64 *aTimestamp, BSTR *aFlags) const;
951 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
952 LONG64 *aTimestamp, BSTR *aFlags) const;
953 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
954 IN_BSTR aFlags);
955 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
956 IN_BSTR aFlags);
957 HRESULT enumerateGuestPropertiesInService
958 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
959 ComSafeArrayOut(BSTR, aValues),
960 ComSafeArrayOut(LONG64, aTimestamps),
961 ComSafeArrayOut(BSTR, aFlags));
962 HRESULT enumerateGuestPropertiesOnVM
963 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
964 ComSafeArrayOut(BSTR, aValues),
965 ComSafeArrayOut(LONG64, aTimestamps),
966 ComSafeArrayOut(BSTR, aFlags));
967#endif /* VBOX_WITH_GUEST_PROPS */
968
969#ifdef VBOX_WITH_RESOURCE_USAGE_API
970 void getDiskList(MediaList &list);
971 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
972
973 pm::CollectorGuest *mCollectorGuest;
974#endif /* VBOX_WITH_RESOURCE_USAGE_API */
975
976 Machine * const mPeer;
977
978 VirtualBox * const mParent;
979
980 Shareable<Data> mData;
981 Shareable<SSData> mSSData;
982
983 Backupable<UserData> mUserData;
984 Backupable<HWData> mHWData;
985 Backupable<MediaData> mMediaData;
986
987 // the following fields need special backup/rollback/commit handling,
988 // so they cannot be a part of HWData
989
990 const ComObjPtr<VRDEServer> mVRDEServer;
991 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
992 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
993 const ComObjPtr<AudioAdapter> mAudioAdapter;
994 const ComObjPtr<USBController> mUSBController;
995 const ComObjPtr<BIOSSettings> mBIOSSettings;
996 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
997 NetworkAdapterVector mNetworkAdapters;
998 const ComObjPtr<BandwidthControl> mBandwidthControl;
999
1000 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
1001 Backupable<StorageControllerList> mStorageControllers;
1002
1003 uint64_t uRegistryNeedsSaving;
1004
1005 friend class SessionMachine;
1006 friend class SnapshotMachine;
1007 friend class Appliance;
1008 friend class VirtualBox;
1009
1010 friend class MachineCloneVM;
1011};
1012
1013// SessionMachine class
1014////////////////////////////////////////////////////////////////////////////////
1015
1016/**
1017 * @note Notes on locking objects of this class:
1018 * SessionMachine shares some data with the primary Machine instance (pointed
1019 * to by the |mPeer| member). In order to provide data consistency it also
1020 * shares its lock handle. This means that whenever you lock a SessionMachine
1021 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1022 * instance is also locked in the same lock mode. Keep it in mind.
1023 */
1024class ATL_NO_VTABLE SessionMachine :
1025 public Machine,
1026 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
1027{
1028public:
1029 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1030
1031 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1032
1033 DECLARE_PROTECT_FINAL_CONSTRUCT()
1034
1035 BEGIN_COM_MAP(SessionMachine)
1036 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1037 COM_INTERFACE_ENTRY(IInternalMachineControl)
1038 END_COM_MAP()
1039
1040 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1041
1042 HRESULT FinalConstruct();
1043 void FinalRelease();
1044
1045 // public initializer/uninitializer for internal purposes only
1046 HRESULT init(Machine *aMachine);
1047 void uninit() { uninit(Uninit::Unexpected); }
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(GetIPCId)(BSTR *id);
1056 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
1057 STDMETHOD(EndPowerUp)(LONG iResult);
1058 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
1059 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
1060 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
1061 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
1062 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
1063 STDMETHOD(AutoCaptureUSBDevices)();
1064 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
1065 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
1066 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
1067 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
1068 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
1069 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
1070 IN_BSTR aName,
1071 IN_BSTR aDescription,
1072 IProgress *aConsoleProgress,
1073 BOOL fTakingSnapshotOnline,
1074 BSTR *aStateFilePath);
1075 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
1076 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
1077 IN_BSTR aEndID, BOOL fDeleteAllChildren,
1078 MachineState_T *aMachineState, IProgress **aProgress);
1079 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
1080 IMedium *aSource, IMedium *aTarget,
1081 BOOL fMergeForward,
1082 IMedium *pParentForTarget,
1083 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1084 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1085 ISnapshot *aSnapshot,
1086 MachineState_T *aMachineState,
1087 IProgress **aProgress);
1088 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1089 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1090 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1091 LONG64 aTimestamp, IN_BSTR aFlags);
1092 STDMETHOD(LockMedia)();
1093 STDMETHOD(UnlockMedia)();
1094 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1095 IMediumAttachment **aNewAttachment);
1096 STDMETHOD(ReportVmStatistics)(ULONG aValidStats, ULONG aCpuUser,
1097 ULONG aCpuKernel, ULONG aCpuIdle,
1098 ULONG aMemTotal, ULONG aMemFree,
1099 ULONG aMemBalloon, ULONG aMemShared,
1100 ULONG aMemCache, ULONG aPageTotal,
1101 ULONG aAllocVMM, ULONG aFreeVMM,
1102 ULONG aBalloonedVMM, ULONG aSharedVMM,
1103 ULONG aVmNetRx, ULONG aVmNetTx);
1104
1105 // public methods only for internal purposes
1106
1107 virtual bool isSessionMachine() const
1108 {
1109 return true;
1110 }
1111
1112 bool checkForDeath();
1113
1114 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1115 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1116 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1117 HRESULT onStorageControllerChange();
1118 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1119 HRESULT onSerialPortChange(ISerialPort *serialPort);
1120 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1121 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1122 HRESULT onVRDEServerChange(BOOL aRestart);
1123 HRESULT onVideoCaptureChange();
1124 HRESULT onUSBControllerChange();
1125 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1126 IVirtualBoxErrorInfo *aError,
1127 ULONG aMaskedIfs);
1128 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1129 IVirtualBoxErrorInfo *aError);
1130 HRESULT onSharedFolderChange();
1131 HRESULT onClipboardModeChange(ClipboardMode_T aClipboardMode);
1132 HRESULT onDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode);
1133 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1134 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1135 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1136
1137 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1138
1139 HRESULT lockMedia();
1140 void unlockMedia();
1141
1142private:
1143
1144 struct ConsoleTaskData
1145 {
1146 ConsoleTaskData()
1147 : mLastState(MachineState_Null)
1148 { }
1149
1150 MachineState_T mLastState;
1151 ComObjPtr<Progress> mProgress;
1152
1153 // used when taking snapshot
1154 ComObjPtr<Snapshot> mSnapshot;
1155
1156 // used when saving state (either as part of a snapshot or separate)
1157 Utf8Str strStateFilePath;
1158 };
1159
1160 struct Uninit
1161 {
1162 enum Reason { Unexpected, Abnormal, Normal };
1163 };
1164
1165 struct SnapshotTask;
1166 struct DeleteSnapshotTask;
1167 struct RestoreSnapshotTask;
1168
1169 friend struct DeleteSnapshotTask;
1170 friend struct RestoreSnapshotTask;
1171
1172 void uninit(Uninit::Reason aReason);
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 MediaList &aChildrenToReparent,
1190 bool &fNeedOnlineMerge,
1191 MediumLockList * &aMediumLockList);
1192 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1193 const ComObjPtr<Medium> &aSource,
1194 const MediaList &aChildrenToReparent,
1195 bool fNeedsOnlineMerge,
1196 MediumLockList *aMediumLockList,
1197 const Guid &aMediumId,
1198 const Guid &aSnapshotId);
1199 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1200 const ComObjPtr<Medium> &aSource,
1201 const ComObjPtr<Medium> &aTarget,
1202 bool fMergeForward,
1203 const ComObjPtr<Medium> &pParentForTarget,
1204 const MediaList &aChildrenToReparent,
1205 MediumLockList *aMediumLockList,
1206 ComObjPtr<Progress> &aProgress,
1207 bool *pfNeedsMachineSaveSettings);
1208
1209 HRESULT setMachineState(MachineState_T aMachineState);
1210 HRESULT updateMachineStateOnClient();
1211
1212 HRESULT mRemoveSavedState;
1213
1214 ConsoleTaskData mConsoleTaskData;
1215
1216 /** interprocess semaphore handle for this machine */
1217#if defined(RT_OS_WINDOWS)
1218 HANDLE mIPCSem;
1219 Bstr mIPCSemName;
1220 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1221 ComPtr<IInternalSessionControl> *aControl,
1222 HANDLE *aIPCSem, bool aAllowClosing);
1223#elif defined(RT_OS_OS2)
1224 HMTX mIPCSem;
1225 Bstr mIPCSemName;
1226 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1227 ComPtr<IInternalSessionControl> *aControl,
1228 HMTX *aIPCSem, bool aAllowClosing);
1229#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1230 int mIPCSem;
1231# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1232 Bstr mIPCKey;
1233# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1234#else
1235# error "Port me!"
1236#endif
1237
1238 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1239};
1240
1241// SnapshotMachine class
1242////////////////////////////////////////////////////////////////////////////////
1243
1244/**
1245 * @note Notes on locking objects of this class:
1246 * SnapshotMachine shares some data with the primary Machine instance (pointed
1247 * to by the |mPeer| member). In order to provide data consistency it also
1248 * shares its lock handle. This means that whenever you lock a SessionMachine
1249 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1250 * instance is also locked in the same lock mode. Keep it in mind.
1251 */
1252class ATL_NO_VTABLE SnapshotMachine :
1253 public Machine
1254{
1255public:
1256 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1257
1258 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1259
1260 DECLARE_PROTECT_FINAL_CONSTRUCT()
1261
1262 BEGIN_COM_MAP(SnapshotMachine)
1263 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1264 END_COM_MAP()
1265
1266 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1267
1268 HRESULT FinalConstruct();
1269 void FinalRelease();
1270
1271 // public initializer/uninitializer for internal purposes only
1272 HRESULT init(SessionMachine *aSessionMachine,
1273 IN_GUID aSnapshotId,
1274 const Utf8Str &aStateFilePath);
1275 HRESULT initFromSettings(Machine *aMachine,
1276 const settings::Hardware &hardware,
1277 const settings::Debugging *pDbg,
1278 const settings::Autostart *pAutostart,
1279 const settings::Storage &storage,
1280 IN_GUID aSnapshotId,
1281 const Utf8Str &aStateFilePath);
1282 void uninit();
1283
1284 // util::Lockable interface
1285 RWLockHandle *lockHandle() const;
1286
1287 // public methods only for internal purposes
1288
1289 virtual bool isSnapshotMachine() const
1290 {
1291 return true;
1292 }
1293
1294 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1295
1296 // unsafe inline public methods for internal purposes only (ensure there is
1297 // a caller and a read lock before calling them!)
1298
1299 const Guid& getSnapshotId() const { return mSnapshotId; }
1300
1301private:
1302
1303 Guid mSnapshotId;
1304 /** This field replaces mPeer for SessionMachine instances, as having
1305 * a peer reference is plain meaningless and causes many subtle problems
1306 * with saving settings and the like. */
1307 Machine * const mMachine;
1308
1309 friend class Snapshot;
1310};
1311
1312// third party methods that depend on SnapshotMachine definition
1313
1314inline const Guid &Machine::getSnapshotId() const
1315{
1316 return (isSnapshotMachine())
1317 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1318 : Guid::Empty;
1319}
1320
1321
1322#endif // ____H_MACHINEIMPL
1323/* 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