VirtualBox

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

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

Main,Frontends: Second step of USB controller rework. There is one controller instance for every USB controller now. Adapt frontends and testsuite to work with the changed API

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