VirtualBox

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

Last change on this file since 42546 was 42538, checked in by vboxsync, 13 years ago

added 3 extra methods for 6124

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