VirtualBox

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

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

Main/Machine+Snapshot+Medium: fix cancelling snapshots, used to trigger both backref inconsistency and incorrect lock list/map updates which could cause runtime misbehavior, the config file was already made consistent with the previous changes

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

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