VirtualBox

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

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

include,ExtPacks\Puel\UsbWebcam,Main,VRDP,VBoxManage: emulated USB webcam.

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