VirtualBox

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

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

Main/VPX, VBoxManage: added IMachine::VideoCaptureScreens and IDisplay::{enableVideoCapture,disableVideoCapture}

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

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