VirtualBox

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

Last change on this file since 47148 was 46667, checked in by vboxsync, 12 years ago

Main/idl: clarify IMachine.videoCaptureFile to be an absolute path, and many naming convention cleanups for method/attribute names starting with an uppercase letter or containing an acronym
Main/xml/Settings.cpp: clean up default video capture file handling and related path conversions, version handling of the new functionality
Main/Machine: handle default value for video capture file better, store relative path in settings if possible, cleanups
Main/src-client/VideoRec.cpp: do not overwrite a file ever
Main/Display: generate a unique name if there is a collision, matching cleanups for name changes
Frontends/VirtualBox: matching name changes
Frontends/VBoxManage: matching name changes, fixing the machine readable output

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.2 KB
Line 
1/* $Id: MachineImpl.h 46667 2013-06-19 15:30:23Z 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 Utf8Str 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 void getDefaultVideoCaptureFile(Utf8Str &strFile);
756
757 HRESULT launchVMProcess(IInternalSessionControl *aControl,
758 const Utf8Str &strType,
759 const Utf8Str &strEnvironment,
760 ProgressProxy *aProgress);
761
762 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
763 {
764 HRESULT rc;
765 *directControl = mData->mSession.mDirectControl;
766
767 if (!*directControl)
768 rc = E_ACCESSDENIED;
769 else
770 rc = S_OK;
771
772 return rc;
773 }
774
775#if defined(RT_OS_WINDOWS)
776
777 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
778 ComPtr<IInternalSessionControl> *aControl = NULL,
779 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
780 bool isSessionSpawning(RTPROCESS *aPID = NULL);
781
782 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
783 ComPtr<IInternalSessionControl> *aControl = NULL,
784 HANDLE *aIPCSem = NULL)
785 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
786
787#elif defined(RT_OS_OS2)
788
789 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
790 ComPtr<IInternalSessionControl> *aControl = NULL,
791 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
792
793 bool isSessionSpawning(RTPROCESS *aPID = NULL);
794
795 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
796 ComPtr<IInternalSessionControl> *aControl = NULL,
797 HMTX *aIPCSem = NULL)
798 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
799
800#else
801
802 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
803 ComPtr<IInternalSessionControl> *aControl = NULL,
804 bool aAllowClosing = false);
805 bool isSessionSpawning();
806
807 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
808 ComPtr<IInternalSessionControl> *aControl = NULL)
809 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
810
811#endif
812
813 bool checkForSpawnFailure();
814
815 HRESULT prepareRegister();
816
817 HRESULT getSharedFolder(CBSTR aName,
818 ComObjPtr<SharedFolder> &aSharedFolder,
819 bool aSetError = false)
820 {
821 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
822 return findSharedFolder(aName, aSharedFolder, aSetError);
823 }
824
825 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
826 MachineState_T *aState = NULL,
827 BOOL *aRegistered = NULL);
828 void releaseStateDependency();
829
830 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
831 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
832 bool fSetError = false)
833 {
834 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
835 pBandwidthGroup,
836 fSetError);
837 }
838
839protected:
840
841 HRESULT checkStateDependency(StateDependency aDepType);
842
843 Machine *getMachine();
844
845 void ensureNoStateDependencies();
846
847 virtual HRESULT setMachineState(MachineState_T aMachineState);
848
849 HRESULT findSharedFolder(const Utf8Str &aName,
850 ComObjPtr<SharedFolder> &aSharedFolder,
851 bool aSetError = false);
852
853 HRESULT loadSettings(bool aRegistered);
854 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
855 const Guid *puuidRegistry);
856 HRESULT loadSnapshot(const settings::Snapshot &data,
857 const Guid &aCurSnapshotId,
858 Snapshot *aParentSnapshot);
859 HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
860 const settings::Autostart *pAutostart);
861 HRESULT loadDebugging(const settings::Debugging *pDbg);
862 HRESULT loadAutostart(const settings::Autostart *pAutostart);
863 HRESULT loadStorageControllers(const settings::Storage &data,
864 const Guid *puuidRegistry,
865 const Guid *puuidSnapshot);
866 HRESULT loadStorageDevices(StorageController *aStorageController,
867 const settings::StorageController &data,
868 const Guid *puuidRegistry,
869 const Guid *puuidSnapshot);
870
871 HRESULT findSnapshotById(const Guid &aId,
872 ComObjPtr<Snapshot> &aSnapshot,
873 bool aSetError = false);
874 HRESULT findSnapshotByName(const Utf8Str &strName,
875 ComObjPtr<Snapshot> &aSnapshot,
876 bool aSetError = false);
877
878 HRESULT getStorageControllerByName(const Utf8Str &aName,
879 ComObjPtr<StorageController> &aStorageController,
880 bool aSetError = false);
881
882 HRESULT getMediumAttachmentsOfController(CBSTR aName,
883 MediaData::AttachmentList &aAttachments);
884
885 enum
886 {
887 /* flags for #saveSettings() */
888 SaveS_ResetCurStateModified = 0x01,
889 SaveS_InformCallbacksAnyway = 0x02,
890 SaveS_Force = 0x04,
891 /* flags for #saveStateSettings() */
892 SaveSTS_CurStateModified = 0x20,
893 SaveSTS_StateFilePath = 0x40,
894 SaveSTS_StateTimeStamp = 0x80
895 };
896
897 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
898 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
899
900 void copyMachineDataToSettings(settings::MachineConfigFile &config);
901 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
902 HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
903 settings::Autostart *pAutostart);
904 HRESULT saveStorageControllers(settings::Storage &data);
905 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
906 settings::StorageController &data);
907 HRESULT saveStateSettings(int aFlags);
908
909 void addMediumToRegistry(ComObjPtr<Medium> &pMedium);
910
911 HRESULT createImplicitDiffs(IProgress *aProgress,
912 ULONG aWeight,
913 bool aOnline);
914 HRESULT deleteImplicitDiffs(bool aOnline);
915
916 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
917 IN_BSTR aControllerName,
918 LONG aControllerPort,
919 LONG aDevice);
920 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
921 ComObjPtr<Medium> pMedium);
922 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
923 Guid &id);
924
925 HRESULT detachDevice(MediumAttachment *pAttach,
926 AutoWriteLock &writeLock,
927 Snapshot *pSnapshot);
928
929 HRESULT detachAllMedia(AutoWriteLock &writeLock,
930 Snapshot *pSnapshot,
931 CleanupMode_T cleanupMode,
932 MediaList &llMedia);
933
934 void commitMedia(bool aOnline = false);
935 void rollbackMedia();
936
937 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
938
939 void rollback(bool aNotify);
940 void commit();
941 void copyFrom(Machine *aThat);
942 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
943
944 struct DeleteTask;
945 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
946 HRESULT deleteTaskWorker(DeleteTask &task);
947
948 Utf8Str getExtraData(const Utf8Str &strKey);
949
950#ifdef VBOX_WITH_GUEST_PROPS
951 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
952 LONG64 *aTimestamp, BSTR *aFlags) const;
953 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
954 LONG64 *aTimestamp, BSTR *aFlags) const;
955 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
956 IN_BSTR aFlags);
957 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
958 IN_BSTR aFlags);
959 HRESULT enumerateGuestPropertiesInService
960 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
961 ComSafeArrayOut(BSTR, aValues),
962 ComSafeArrayOut(LONG64, aTimestamps),
963 ComSafeArrayOut(BSTR, aFlags));
964 HRESULT enumerateGuestPropertiesOnVM
965 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
966 ComSafeArrayOut(BSTR, aValues),
967 ComSafeArrayOut(LONG64, aTimestamps),
968 ComSafeArrayOut(BSTR, aFlags));
969#endif /* VBOX_WITH_GUEST_PROPS */
970
971#ifdef VBOX_WITH_RESOURCE_USAGE_API
972 void getDiskList(MediaList &list);
973 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
974
975 pm::CollectorGuest *mCollectorGuest;
976#endif /* VBOX_WITH_RESOURCE_USAGE_API */
977
978 Machine * const mPeer;
979
980 VirtualBox * const mParent;
981
982 Shareable<Data> mData;
983 Shareable<SSData> mSSData;
984
985 Backupable<UserData> mUserData;
986 Backupable<HWData> mHWData;
987 Backupable<MediaData> mMediaData;
988
989 // the following fields need special backup/rollback/commit handling,
990 // so they cannot be a part of HWData
991
992 const ComObjPtr<VRDEServer> mVRDEServer;
993 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
994 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
995 const ComObjPtr<AudioAdapter> mAudioAdapter;
996 const ComObjPtr<USBController> mUSBController;
997 const ComObjPtr<BIOSSettings> mBIOSSettings;
998 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
999 NetworkAdapterVector mNetworkAdapters;
1000 const ComObjPtr<BandwidthControl> mBandwidthControl;
1001
1002 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
1003 Backupable<StorageControllerList> mStorageControllers;
1004
1005 uint64_t uRegistryNeedsSaving;
1006
1007 friend class SessionMachine;
1008 friend class SnapshotMachine;
1009 friend class Appliance;
1010 friend class VirtualBox;
1011
1012 friend class MachineCloneVM;
1013};
1014
1015// SessionMachine class
1016////////////////////////////////////////////////////////////////////////////////
1017
1018/**
1019 * @note Notes on locking objects of this class:
1020 * SessionMachine shares some data with the primary Machine instance (pointed
1021 * to by the |mPeer| member). In order to provide data consistency it also
1022 * shares its lock handle. This means that whenever you lock a SessionMachine
1023 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1024 * instance is also locked in the same lock mode. Keep it in mind.
1025 */
1026class ATL_NO_VTABLE SessionMachine :
1027 public Machine,
1028 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
1029{
1030public:
1031 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1032
1033 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1034
1035 DECLARE_PROTECT_FINAL_CONSTRUCT()
1036
1037 BEGIN_COM_MAP(SessionMachine)
1038 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1039 COM_INTERFACE_ENTRY(IInternalMachineControl)
1040 END_COM_MAP()
1041
1042 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1043
1044 HRESULT FinalConstruct();
1045 void FinalRelease();
1046
1047 // public initializer/uninitializer for internal purposes only
1048 HRESULT init(Machine *aMachine);
1049 void uninit() { uninit(Uninit::Unexpected); }
1050
1051 // util::Lockable interface
1052 RWLockHandle *lockHandle() const;
1053
1054 // IInternalMachineControl methods
1055 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
1056 STDMETHOD(UpdateState)(MachineState_T machineState);
1057 STDMETHOD(GetIPCId)(BSTR *id);
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)(IMediumAttachment *aMediumAttachment,
1082 IMedium *aSource, IMedium *aTarget,
1083 BOOL fMergeForward,
1084 IMedium *pParentForTarget,
1085 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1086 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1087 ISnapshot *aSnapshot,
1088 MachineState_T *aMachineState,
1089 IProgress **aProgress);
1090 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1091 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1092 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1093 LONG64 aTimestamp, IN_BSTR aFlags);
1094 STDMETHOD(LockMedia)();
1095 STDMETHOD(UnlockMedia)();
1096 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1097 IMediumAttachment **aNewAttachment);
1098 STDMETHOD(ReportVmStatistics)(ULONG aValidStats, ULONG aCpuUser,
1099 ULONG aCpuKernel, ULONG aCpuIdle,
1100 ULONG aMemTotal, ULONG aMemFree,
1101 ULONG aMemBalloon, ULONG aMemShared,
1102 ULONG aMemCache, ULONG aPageTotal,
1103 ULONG aAllocVMM, ULONG aFreeVMM,
1104 ULONG aBalloonedVMM, ULONG aSharedVMM,
1105 ULONG aVmNetRx, ULONG aVmNetTx);
1106
1107 // public methods only for internal purposes
1108
1109 virtual bool isSessionMachine() const
1110 {
1111 return true;
1112 }
1113
1114 bool checkForDeath();
1115
1116 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1117 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1118 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1119 HRESULT onStorageControllerChange();
1120 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1121 HRESULT onSerialPortChange(ISerialPort *serialPort);
1122 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1123 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1124 HRESULT onVRDEServerChange(BOOL aRestart);
1125 HRESULT onVideoCaptureChange();
1126 HRESULT onUSBControllerChange();
1127 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1128 IVirtualBoxErrorInfo *aError,
1129 ULONG aMaskedIfs);
1130 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1131 IVirtualBoxErrorInfo *aError);
1132 HRESULT onSharedFolderChange();
1133 HRESULT onClipboardModeChange(ClipboardMode_T aClipboardMode);
1134 HRESULT onDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode);
1135 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1136 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1137 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1138
1139 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1140
1141 HRESULT lockMedia();
1142 void unlockMedia();
1143
1144private:
1145
1146 struct ConsoleTaskData
1147 {
1148 ConsoleTaskData()
1149 : mLastState(MachineState_Null)
1150 { }
1151
1152 MachineState_T mLastState;
1153 ComObjPtr<Progress> mProgress;
1154
1155 // used when taking snapshot
1156 ComObjPtr<Snapshot> mSnapshot;
1157
1158 // used when saving state (either as part of a snapshot or separate)
1159 Utf8Str strStateFilePath;
1160 };
1161
1162 struct Uninit
1163 {
1164 enum Reason { Unexpected, Abnormal, Normal };
1165 };
1166
1167 struct SnapshotTask;
1168 struct DeleteSnapshotTask;
1169 struct RestoreSnapshotTask;
1170
1171 friend struct DeleteSnapshotTask;
1172 friend struct RestoreSnapshotTask;
1173
1174 void uninit(Uninit::Reason aReason);
1175
1176 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1177 void releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1178
1179 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1180 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1181
1182 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1183 const Guid &machineId,
1184 const Guid &snapshotId,
1185 bool fOnlineMergePossible,
1186 MediumLockList *aVMMALockList,
1187 ComObjPtr<Medium> &aSource,
1188 ComObjPtr<Medium> &aTarget,
1189 bool &fMergeForward,
1190 ComObjPtr<Medium> &pParentForTarget,
1191 MediaList &aChildrenToReparent,
1192 bool &fNeedOnlineMerge,
1193 MediumLockList * &aMediumLockList);
1194 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1195 const ComObjPtr<Medium> &aSource,
1196 const MediaList &aChildrenToReparent,
1197 bool fNeedsOnlineMerge,
1198 MediumLockList *aMediumLockList,
1199 const Guid &aMediumId,
1200 const Guid &aSnapshotId);
1201 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1202 const ComObjPtr<Medium> &aSource,
1203 const ComObjPtr<Medium> &aTarget,
1204 bool fMergeForward,
1205 const ComObjPtr<Medium> &pParentForTarget,
1206 const MediaList &aChildrenToReparent,
1207 MediumLockList *aMediumLockList,
1208 ComObjPtr<Progress> &aProgress,
1209 bool *pfNeedsMachineSaveSettings);
1210
1211 HRESULT setMachineState(MachineState_T aMachineState);
1212 HRESULT updateMachineStateOnClient();
1213
1214 HRESULT mRemoveSavedState;
1215
1216 ConsoleTaskData mConsoleTaskData;
1217
1218 /** interprocess semaphore handle for this machine */
1219#if defined(RT_OS_WINDOWS)
1220 HANDLE mIPCSem;
1221 Bstr mIPCSemName;
1222 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1223 ComPtr<IInternalSessionControl> *aControl,
1224 HANDLE *aIPCSem, bool aAllowClosing);
1225#elif defined(RT_OS_OS2)
1226 HMTX mIPCSem;
1227 Bstr mIPCSemName;
1228 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1229 ComPtr<IInternalSessionControl> *aControl,
1230 HMTX *aIPCSem, bool aAllowClosing);
1231#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1232 int mIPCSem;
1233# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1234 Bstr mIPCKey;
1235# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1236#else
1237# error "Port me!"
1238#endif
1239
1240 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1241};
1242
1243// SnapshotMachine class
1244////////////////////////////////////////////////////////////////////////////////
1245
1246/**
1247 * @note Notes on locking objects of this class:
1248 * SnapshotMachine shares some data with the primary Machine instance (pointed
1249 * to by the |mPeer| member). In order to provide data consistency it also
1250 * shares its lock handle. This means that whenever you lock a SessionMachine
1251 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1252 * instance is also locked in the same lock mode. Keep it in mind.
1253 */
1254class ATL_NO_VTABLE SnapshotMachine :
1255 public Machine
1256{
1257public:
1258 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1259
1260 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1261
1262 DECLARE_PROTECT_FINAL_CONSTRUCT()
1263
1264 BEGIN_COM_MAP(SnapshotMachine)
1265 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1266 END_COM_MAP()
1267
1268 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1269
1270 HRESULT FinalConstruct();
1271 void FinalRelease();
1272
1273 // public initializer/uninitializer for internal purposes only
1274 HRESULT init(SessionMachine *aSessionMachine,
1275 IN_GUID aSnapshotId,
1276 const Utf8Str &aStateFilePath);
1277 HRESULT initFromSettings(Machine *aMachine,
1278 const settings::Hardware &hardware,
1279 const settings::Debugging *pDbg,
1280 const settings::Autostart *pAutostart,
1281 const settings::Storage &storage,
1282 IN_GUID aSnapshotId,
1283 const Utf8Str &aStateFilePath);
1284 void uninit();
1285
1286 // util::Lockable interface
1287 RWLockHandle *lockHandle() const;
1288
1289 // public methods only for internal purposes
1290
1291 virtual bool isSnapshotMachine() const
1292 {
1293 return true;
1294 }
1295
1296 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1297
1298 // unsafe inline public methods for internal purposes only (ensure there is
1299 // a caller and a read lock before calling them!)
1300
1301 const Guid& getSnapshotId() const { return mSnapshotId; }
1302
1303private:
1304
1305 Guid mSnapshotId;
1306 /** This field replaces mPeer for SessionMachine instances, as having
1307 * a peer reference is plain meaningless and causes many subtle problems
1308 * with saving settings and the like. */
1309 Machine * const mMachine;
1310
1311 friend class Snapshot;
1312};
1313
1314// third party methods that depend on SnapshotMachine definition
1315
1316inline const Guid &Machine::getSnapshotId() const
1317{
1318 return (isSnapshotMachine())
1319 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1320 : Guid::Empty;
1321}
1322
1323
1324#endif // ____H_MACHINEIMPL
1325/* 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