VirtualBox

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

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

Main/SystemProperties+Machine: new config setting for default VM frontend.
Frontend/VirtualBox+VBoxManage: changes to use the default VM frontend when starting a VM, other minor cleanups
Main/xml/*.xsd: attempt to bring the XML schema close to reality
doc/manual: document the new possibilities, and fix a few long standing inaccuracies

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