VirtualBox

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

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

Main/Machine+Console+Settings: add graphics controller type setting, preparing for the fututure, plus some whitespace cleanup

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette