VirtualBox

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

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

Main: Increased guest property lookup performance by using a map for internal data, leaving lock before posting change event.

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