VirtualBox

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

Last change on this file since 72098 was 71108, checked in by vboxsync, 7 years ago

Added speculation control settings to API, refined implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.3 KB
Line 
1/* $Id: MachineImpl.h 71108 2018-02-22 15:38:35Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 "AuthLibrary.h"
22#include "VirtualBoxBase.h"
23#include "SnapshotImpl.h"
24#include "ProgressImpl.h"
25#include "VRDEServerImpl.h"
26#include "MediumAttachmentImpl.h"
27#include "PCIDeviceAttachmentImpl.h"
28#include "MediumLock.h"
29#include "NetworkAdapterImpl.h"
30#include "AudioAdapterImpl.h"
31#include "SerialPortImpl.h"
32#include "ParallelPortImpl.h"
33#include "BIOSSettingsImpl.h"
34#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
35#include "USBControllerImpl.h" // required for MachineImpl.h to compile on Windows
36#include "BandwidthControlImpl.h"
37#include "BandwidthGroupImpl.h"
38#ifdef VBOX_WITH_RESOURCE_USAGE_API
39# include "Performance.h"
40# include "PerformanceImpl.h"
41# include "ThreadTask.h"
42#endif
43
44// generated header
45#include "SchemaDefs.h"
46
47#include "VBox/com/ErrorInfo.h"
48
49#include <iprt/file.h>
50#include <iprt/thread.h>
51#include <iprt/time.h>
52
53#include <list>
54#include <vector>
55
56#include "MachineWrap.h"
57
58/** @todo r=klaus after moving the various Machine settings structs to
59 * MachineImpl.cpp it should be possible to eliminate this include. */
60#include <VBox/settings.h>
61
62// defines
63////////////////////////////////////////////////////////////////////////////////
64
65// helper declarations
66////////////////////////////////////////////////////////////////////////////////
67
68class Progress;
69class ProgressProxy;
70class Keyboard;
71class Mouse;
72class Display;
73class MachineDebugger;
74class USBController;
75class USBDeviceFilters;
76class Snapshot;
77class SharedFolder;
78class HostUSBDevice;
79class StorageController;
80class SessionMachine;
81#ifdef VBOX_WITH_UNATTENDED
82class Unattended;
83#endif
84
85// Machine class
86////////////////////////////////////////////////////////////////////////////////
87//
88class ATL_NO_VTABLE Machine :
89 public MachineWrap
90{
91
92public:
93
94 enum StateDependency
95 {
96 AnyStateDep = 0,
97 MutableStateDep,
98 MutableOrSavedStateDep,
99 MutableOrRunningStateDep,
100 MutableOrSavedOrRunningStateDep,
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 /** Type of lock which created this session */
126 LockType_T mLockType;
127
128 /** Control of the direct session opened by lockMachine() */
129 ComPtr<IInternalSessionControl> mDirectControl;
130
131 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
132
133 /** list of controls of all opened remote sessions */
134 RemoteControlList mRemoteControls;
135
136 /** launchVMProcess() and OnSessionEnd() progress indicator */
137 ComObjPtr<ProgressProxy> mProgress;
138
139 /**
140 * PID of the session object that must be passed to openSession()
141 * to finalize the launchVMProcess() request (i.e., PID of the
142 * process created by launchVMProcess())
143 */
144 RTPROCESS mPID;
145
146 /** Current session state */
147 SessionState_T mState;
148
149 /** Session name string (of the primary session) */
150 Utf8Str mName;
151
152 /** Session machine object */
153 ComObjPtr<SessionMachine> mMachine;
154
155 /** Medium object lock collection. */
156 MediumLockListMap mLockedMedia;
157 };
158
159 Data();
160 ~Data();
161
162 const Guid mUuid;
163 BOOL mRegistered;
164
165 Utf8Str m_strConfigFile;
166 Utf8Str m_strConfigFileFull;
167
168 // machine settings XML file
169 settings::MachineConfigFile *pMachineConfigFile;
170 uint32_t flModifications;
171 bool m_fAllowStateModification;
172
173 BOOL mAccessible;
174 com::ErrorInfo mAccessError;
175
176 MachineState_T mMachineState;
177 RTTIMESPEC mLastStateChange;
178
179 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
180 uint32_t mMachineStateDeps;
181 RTSEMEVENTMULTI mMachineStateDepsSem;
182 uint32_t mMachineStateChangePending;
183
184 BOOL mCurrentStateModified;
185 /** Guest properties have been modified and need saving since the
186 * machine was started, or there are transient properties which need
187 * deleting and the machine is being shut down. */
188 BOOL mGuestPropertiesModified;
189
190 Session mSession;
191
192 ComObjPtr<Snapshot> mFirstSnapshot;
193 ComObjPtr<Snapshot> mCurrentSnapshot;
194
195 // list of files to delete in Delete(); this list is filled by Unregister()
196 std::list<Utf8Str> llFilesToDelete;
197 };
198
199 /**
200 * Saved state data.
201 *
202 * It's actually only the state file path string, but it needs to be
203 * separate from Data, because Machine and SessionMachine instances
204 * share it, while SnapshotMachine does not.
205 *
206 * The data variable is |mSSData|.
207 */
208 struct SSData
209 {
210 Utf8Str strStateFilePath;
211 };
212
213 /**
214 * User changeable machine data.
215 *
216 * This data is common for all machine snapshots, i.e. it is shared
217 * by all SnapshotMachine instances associated with the given machine
218 * using the util::Backupable template through the |mUserData| variable.
219 *
220 * SessionMachine instances can alter this data and discard changes.
221 *
222 * @note There is no need to lock anything inside init() or uninit()
223 * methods, because they are always serialized (see AutoCaller).
224 */
225 struct UserData
226 {
227 settings::MachineUserData s;
228 };
229
230 /**
231 * Hardware data.
232 *
233 * This data is unique for a machine and for every machine snapshot.
234 * Stored using the util::Backupable template in the |mHWData| variable.
235 *
236 * SessionMachine instances can alter this data and discard changes.
237 *
238 * @todo r=klaus move all "pointer" objects out of this struct, as they
239 * need non-obvious handling when creating a new session or when taking
240 * a snapshot. Better do this right straight away, not relying on the
241 * template magic which doesn't work right in this case.
242 */
243 struct HWData
244 {
245 /**
246 * Data structure to hold information about a guest property.
247 */
248 struct GuestProperty {
249 /** Property value */
250 Utf8Str strValue;
251 /** Property timestamp */
252 LONG64 mTimestamp;
253 /** Property flags */
254 ULONG mFlags;
255 };
256
257 HWData();
258 ~HWData();
259
260 Bstr mHWVersion;
261 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
262 ULONG mMemorySize;
263 ULONG mMemoryBalloonSize;
264 BOOL mPageFusionEnabled;
265 GraphicsControllerType_T mGraphicsControllerType;
266 ULONG mVRAMSize;
267 ULONG mVideoCaptureWidth;
268 ULONG mVideoCaptureHeight;
269 ULONG mVideoCaptureRate;
270 ULONG mVideoCaptureFPS;
271 ULONG mVideoCaptureMaxTime;
272 ULONG mVideoCaptureMaxFileSize;
273 Utf8Str mVideoCaptureOptions;
274 Utf8Str mVideoCaptureFile;
275 BOOL mVideoCaptureEnabled;
276 BOOL maVideoCaptureScreens[SchemaDefs::MaxGuestMonitors];
277 ULONG mMonitorCount;
278 BOOL mHWVirtExEnabled;
279 BOOL mHWVirtExNestedPagingEnabled;
280 BOOL mHWVirtExLargePagesEnabled;
281 BOOL mHWVirtExVPIDEnabled;
282 BOOL mHWVirtExUXEnabled;
283 BOOL mHWVirtExForceEnabled;
284 BOOL mAccelerate2DVideoEnabled;
285 BOOL mPAEEnabled;
286 settings::Hardware::LongModeType mLongMode;
287 BOOL mTripleFaultReset;
288 BOOL mAPIC;
289 BOOL mX2APIC;
290 BOOL mIBPBOnVMExit;
291 BOOL mIBPBOnVMEntry;
292 BOOL mSpecCtrl;
293 BOOL mSpecCtrlByHost;
294 BOOL mNestedHWVirt;
295 ULONG mCPUCount;
296 BOOL mCPUHotPlugEnabled;
297 ULONG mCpuExecutionCap;
298 uint32_t mCpuIdPortabilityLevel;
299 Utf8Str mCpuProfile;
300 BOOL mAccelerate3DEnabled;
301 BOOL mHPETEnabled;
302
303 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
304
305 std::list<settings::CpuIdLeaf> mCpuIdLeafList;
306
307 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
308
309 typedef std::list<ComObjPtr<SharedFolder> > SharedFolderList;
310 SharedFolderList mSharedFolders;
311
312 ClipboardMode_T mClipboardMode;
313 DnDMode_T mDnDMode;
314
315 typedef std::map<Utf8Str, GuestProperty> GuestPropertyMap;
316 GuestPropertyMap mGuestProperties;
317
318 FirmwareType_T mFirmwareType;
319 KeyboardHIDType_T mKeyboardHIDType;
320 PointingHIDType_T mPointingHIDType;
321 ChipsetType_T mChipsetType;
322 ParavirtProvider_T mParavirtProvider;
323 Utf8Str mParavirtDebug;
324 BOOL mEmulatedUSBCardReaderEnabled;
325
326 BOOL mIOCacheEnabled;
327 ULONG mIOCacheSize;
328
329 typedef std::list<ComObjPtr<PCIDeviceAttachment> > PCIDeviceAssignmentList;
330 PCIDeviceAssignmentList mPCIDeviceAssignments;
331
332 settings::Debugging mDebugging;
333 settings::Autostart mAutostart;
334
335 Utf8Str mDefaultFrontend;
336 };
337
338 typedef std::list<ComObjPtr<MediumAttachment> > MediumAttachmentList;
339
340 DECLARE_EMPTY_CTOR_DTOR(Machine)
341
342 HRESULT FinalConstruct();
343 void FinalRelease();
344
345 // public initializer/uninitializer for internal purposes only:
346
347 // initializer for creating a new, empty machine
348 HRESULT init(VirtualBox *aParent,
349 const Utf8Str &strConfigFile,
350 const Utf8Str &strName,
351 const StringsList &llGroups,
352 GuestOSType *aOsType,
353 const Guid &aId,
354 bool fForceOverwrite,
355 bool fDirectoryIncludesUUID);
356
357 // initializer for loading existing machine XML (either registered or not)
358 HRESULT initFromSettings(VirtualBox *aParent,
359 const Utf8Str &strConfigFile,
360 const Guid *aId);
361
362 // initializer for machine config in memory (OVF import)
363 HRESULT init(VirtualBox *aParent,
364 const Utf8Str &strName,
365 const settings::MachineConfigFile &config);
366
367 void uninit();
368
369#ifdef VBOX_WITH_RESOURCE_USAGE_API
370 // Needed from VirtualBox, for the delayed metrics cleanup.
371 void i_unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
372#endif /* VBOX_WITH_RESOURCE_USAGE_API */
373
374protected:
375 HRESULT initImpl(VirtualBox *aParent,
376 const Utf8Str &strConfigFile);
377 HRESULT initDataAndChildObjects();
378 HRESULT i_registeredInit();
379 HRESULT i_tryCreateMachineConfigFile(bool fForceOverwrite);
380 void uninitDataAndChildObjects();
381
382public:
383
384
385 // public methods only for internal purposes
386
387 virtual bool i_isSnapshotMachine() const
388 {
389 return false;
390 }
391
392 virtual bool i_isSessionMachine() const
393 {
394 return false;
395 }
396
397 /**
398 * Override of the default locking class to be used for validating lock
399 * order with the standard member lock handle.
400 */
401 virtual VBoxLockingClass getLockingClass() const
402 {
403 return LOCKCLASS_MACHINEOBJECT;
404 }
405
406 /// @todo (dmik) add lock and make non-inlined after revising classes
407 // that use it. Note: they should enter Machine lock to keep the returned
408 // information valid!
409 bool i_isRegistered() { return !!mData->mRegistered; }
410
411 // unsafe inline public methods for internal purposes only (ensure there is
412 // a caller and a read lock before calling them!)
413
414 /**
415 * Returns the VirtualBox object this machine belongs to.
416 *
417 * @note This method doesn't check this object's readiness. Intended to be
418 * used by ready Machine children (whose readiness is bound to the parent's
419 * one) or after doing addCaller() manually.
420 */
421 VirtualBox* i_getVirtualBox() const { return mParent; }
422
423 /**
424 * Checks if this machine is accessible, without attempting to load the
425 * config file.
426 *
427 * @note This method doesn't check this object's readiness. Intended to be
428 * used by ready Machine children (whose readiness is bound to the parent's
429 * one) or after doing addCaller() manually.
430 */
431 bool i_isAccessible() const { return !!mData->mAccessible; }
432
433 /**
434 * Returns this machine ID.
435 *
436 * @note This method doesn't check this object's readiness. Intended to be
437 * used by ready Machine children (whose readiness is bound to the parent's
438 * one) or after adding a caller manually.
439 */
440 const Guid& i_getId() const { return mData->mUuid; }
441
442 /**
443 * Returns the snapshot ID this machine represents or an empty UUID if this
444 * instance is not SnapshotMachine.
445 *
446 * @note This method doesn't check this object's readiness. Intended to be
447 * used by ready Machine children (whose readiness is bound to the parent's
448 * one) or after adding a caller manually.
449 */
450 inline const Guid& i_getSnapshotId() const;
451
452 /**
453 * Returns this machine's full settings file path.
454 *
455 * @note This method doesn't lock this object or check its readiness.
456 * Intended to be used only after doing addCaller() manually and locking it
457 * for reading.
458 */
459 const Utf8Str& i_getSettingsFileFull() const { return mData->m_strConfigFileFull; }
460
461 /**
462 * Returns this machine name.
463 *
464 * @note This method doesn't lock this object or check its readiness.
465 * Intended to be used only after doing addCaller() manually and locking it
466 * for reading.
467 */
468 const Utf8Str& i_getName() const { return mUserData->s.strName; }
469
470 enum
471 {
472 IsModified_MachineData = 0x0001,
473 IsModified_Storage = 0x0002,
474 IsModified_NetworkAdapters = 0x0008,
475 IsModified_SerialPorts = 0x0010,
476 IsModified_ParallelPorts = 0x0020,
477 IsModified_VRDEServer = 0x0040,
478 IsModified_AudioAdapter = 0x0080,
479 IsModified_USB = 0x0100,
480 IsModified_BIOS = 0x0200,
481 IsModified_SharedFolders = 0x0400,
482 IsModified_Snapshots = 0x0800,
483 IsModified_BandwidthControl = 0x1000
484 };
485
486 /**
487 * Returns various information about this machine.
488 *
489 * @note This method doesn't lock this object or check its readiness.
490 * Intended to be used only after doing addCaller() manually and locking it
491 * for reading.
492 */
493 Utf8Str i_getOSTypeId() const { return mUserData->s.strOsType; }
494 ChipsetType_T i_getChipsetType() const { return mHWData->mChipsetType; }
495 ParavirtProvider_T i_getParavirtProvider() const { return mHWData->mParavirtProvider; }
496 Utf8Str i_getParavirtDebug() const { return mHWData->mParavirtDebug; }
497
498 void i_setModified(uint32_t fl, bool fAllowStateModification = true);
499 void i_setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
500
501 bool i_isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
502 void i_allowStateModification() { mData->m_fAllowStateModification = true; }
503 void i_disallowStateModification() { mData->m_fAllowStateModification = false; }
504
505 const StringsList &i_getGroups() const { return mUserData->s.llGroups; }
506
507 // callback handlers
508 virtual HRESULT i_onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
509 virtual HRESULT i_onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
510 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */,
511 IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
512 virtual HRESULT i_onAudioAdapterChange(IAudioAdapter * /* audioAdapter */) { return S_OK; }
513 virtual HRESULT i_onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
514 virtual HRESULT i_onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
515 virtual HRESULT i_onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
516 virtual HRESULT i_onUSBControllerChange() { return S_OK; }
517 virtual HRESULT i_onStorageControllerChange() { return S_OK; }
518 virtual HRESULT i_onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
519 virtual HRESULT i_onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
520 virtual HRESULT i_onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
521 virtual HRESULT i_onSharedFolderChange() { return S_OK; }
522 virtual HRESULT i_onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
523 virtual HRESULT i_onDnDModeChange(DnDMode_T /* aDnDMode */) { return S_OK; }
524 virtual HRESULT i_onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
525 virtual HRESULT i_onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */,
526 BOOL /* silent */) { return S_OK; }
527 virtual HRESULT i_onVideoCaptureChange() { return S_OK; }
528
529 HRESULT i_saveRegistryEntry(settings::MachineRegistryEntry &data);
530
531 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
532 void i_copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
533
534 void i_getLogFolder(Utf8Str &aLogFolder);
535 Utf8Str i_getLogFilename(ULONG idx);
536 Utf8Str i_getHardeningLogFilename(void);
537
538 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
539
540 void i_getDefaultVideoCaptureFile(Utf8Str &strFile);
541
542 bool i_isUSBControllerPresent();
543
544 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
545 const Utf8Str &strType,
546 const Utf8Str &strEnvironment,
547 ProgressProxy *aProgress);
548
549 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
550 {
551 HRESULT rc;
552 *directControl = mData->mSession.mDirectControl;
553
554 if (!*directControl)
555 rc = E_ACCESSDENIED;
556 else
557 rc = S_OK;
558
559 return rc;
560 }
561
562 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
563 ComPtr<IInternalSessionControl> *aControl = NULL,
564 bool aRequireVM = false,
565 bool aAllowClosing = false);
566 bool i_isSessionSpawning();
567
568 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
569 ComPtr<IInternalSessionControl> *aControl = NULL)
570 { return i_isSessionOpen(aMachine, aControl, false /* aRequireVM */, true /* aAllowClosing */); }
571
572 bool i_isSessionOpenVM(ComObjPtr<SessionMachine> &aMachine,
573 ComPtr<IInternalSessionControl> *aControl = NULL)
574 { return i_isSessionOpen(aMachine, aControl, true /* aRequireVM */, false /* aAllowClosing */); }
575
576 bool i_checkForSpawnFailure();
577
578 HRESULT i_prepareRegister();
579
580 HRESULT i_getSharedFolder(CBSTR aName,
581 ComObjPtr<SharedFolder> &aSharedFolder,
582 bool aSetError = false)
583 {
584 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
585 return i_findSharedFolder(aName, aSharedFolder, aSetError);
586 }
587
588 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
589 MachineState_T *aState = NULL,
590 BOOL *aRegistered = NULL);
591 void i_releaseStateDependency();
592
593 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
594 ComObjPtr<StorageController> &aStorageController,
595 bool aSetError = false);
596
597 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
598 MediumAttachmentList &aAttachments);
599
600 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
601 ComObjPtr<USBController> &aUSBController,
602 bool aSetError = false);
603
604 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
605 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
606 bool fSetError = false)
607 {
608 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
609 pBandwidthGroup,
610 fSetError);
611 }
612
613 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
614
615protected:
616
617 class ClientToken;
618
619 HRESULT i_checkStateDependency(StateDependency aDepType);
620
621 Machine *i_getMachine();
622
623 void i_ensureNoStateDependencies();
624
625 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
626
627 HRESULT i_findSharedFolder(const Utf8Str &aName,
628 ComObjPtr<SharedFolder> &aSharedFolder,
629 bool aSetError = false);
630
631 HRESULT i_loadSettings(bool aRegistered);
632 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
633 const Guid *puuidRegistry);
634 HRESULT i_loadSnapshot(const settings::Snapshot &data,
635 const Guid &aCurSnapshotId,
636 Snapshot *aParentSnapshot);
637 HRESULT i_loadHardware(const Guid *puuidRegistry,
638 const Guid *puuidSnapshot,
639 const settings::Hardware &data,
640 const settings::Debugging *pDbg,
641 const settings::Autostart *pAutostart);
642 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
643 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
644 HRESULT i_loadStorageControllers(const settings::Storage &data,
645 const Guid *puuidRegistry,
646 const Guid *puuidSnapshot);
647 HRESULT i_loadStorageDevices(StorageController *aStorageController,
648 const settings::StorageController &data,
649 const Guid *puuidRegistry,
650 const Guid *puuidSnapshot);
651
652 HRESULT i_findSnapshotById(const Guid &aId,
653 ComObjPtr<Snapshot> &aSnapshot,
654 bool aSetError = false);
655 HRESULT i_findSnapshotByName(const Utf8Str &strName,
656 ComObjPtr<Snapshot> &aSnapshot,
657 bool aSetError = false);
658
659 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
660
661 enum
662 {
663 /* flags for #saveSettings() */
664 SaveS_ResetCurStateModified = 0x01,
665 SaveS_Force = 0x04,
666 /* flags for #saveStateSettings() */
667 SaveSTS_CurStateModified = 0x20,
668 SaveSTS_StateFilePath = 0x40,
669 SaveSTS_StateTimeStamp = 0x80
670 };
671
672 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
673 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
674
675 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
676 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
677 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
678 settings::Autostart *pAutostart);
679 HRESULT i_saveStorageControllers(settings::Storage &data);
680 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
681 settings::StorageController &data);
682 HRESULT i_saveStateSettings(int aFlags);
683
684 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
685
686 HRESULT i_createImplicitDiffs(IProgress *aProgress,
687 ULONG aWeight,
688 bool aOnline);
689 HRESULT i_deleteImplicitDiffs(bool aOnline);
690
691 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
692 const Utf8Str &aControllerName,
693 LONG aControllerPort,
694 LONG aDevice);
695 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
696 ComObjPtr<Medium> pMedium);
697 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
698 Guid &id);
699
700 HRESULT i_detachDevice(MediumAttachment *pAttach,
701 AutoWriteLock &writeLock,
702 Snapshot *pSnapshot);
703
704 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
705 Snapshot *pSnapshot,
706 CleanupMode_T cleanupMode,
707 MediaList &llMedia);
708
709 void i_commitMedia(bool aOnline = false);
710 void i_rollbackMedia();
711
712 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
713
714 void i_rollback(bool aNotify);
715 void i_commit();
716 void i_copyFrom(Machine *aThat);
717 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
718
719 Utf8Str i_getExtraData(const Utf8Str &strKey);
720
721#ifdef VBOX_WITH_GUEST_PROPS
722 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
723 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
724 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
725 const com::Utf8Str &aFlags, bool fDelete);
726 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
727 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
728 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
729 const com::Utf8Str &aFlags, bool fDelete);
730 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
731 std::vector<com::Utf8Str> &aNames,
732 std::vector<com::Utf8Str> &aValues,
733 std::vector<LONG64> &aTimestamps,
734 std::vector<com::Utf8Str> &aFlags);
735 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
736 std::vector<com::Utf8Str> &aNames,
737 std::vector<com::Utf8Str> &aValues,
738 std::vector<LONG64> &aTimestamps,
739 std::vector<com::Utf8Str> &aFlags);
740
741#endif /* VBOX_WITH_GUEST_PROPS */
742
743#ifdef VBOX_WITH_RESOURCE_USAGE_API
744 void i_getDiskList(MediaList &list);
745 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
746
747 pm::CollectorGuest *mCollectorGuest;
748#endif /* VBOX_WITH_RESOURCE_USAGE_API */
749
750 Machine * const mPeer;
751
752 VirtualBox * const mParent;
753
754 Shareable<Data> mData;
755 Shareable<SSData> mSSData;
756
757 Backupable<UserData> mUserData;
758 Backupable<HWData> mHWData;
759
760 /**
761 * Hard disk and other media data.
762 *
763 * The usage policy is the same as for mHWData, but a separate field
764 * is necessary because hard disk data requires different procedures when
765 * taking or deleting snapshots, etc.
766 *
767 * @todo r=klaus change this to a regular list and use the normal way to
768 * handle the settings when creating a session or taking a snapshot.
769 * Same thing applies to mStorageControllers and mUSBControllers.
770 */
771 Backupable<MediumAttachmentList> mMediumAttachments;
772
773 // the following fields need special backup/rollback/commit handling,
774 // so they cannot be a part of HWData
775
776 const ComObjPtr<VRDEServer> mVRDEServer;
777 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
778 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
779 const ComObjPtr<AudioAdapter> mAudioAdapter;
780 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
781 const ComObjPtr<BIOSSettings> mBIOSSettings;
782 const ComObjPtr<BandwidthControl> mBandwidthControl;
783
784 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
785 NetworkAdapterVector mNetworkAdapters;
786
787 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
788 Backupable<StorageControllerList> mStorageControllers;
789
790 typedef std::list<ComObjPtr<USBController> > USBControllerList;
791 Backupable<USBControllerList> mUSBControllers;
792
793 uint64_t uRegistryNeedsSaving;
794
795 /**
796 * Abstract base class for all Machine or SessionMachine related
797 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
798 * a (non-static) method as its thread function, so instead we have it call
799 * the static Machine::taskHandler, which then calls the handler() method
800 * in here (implemented by the subclasses).
801 */
802 class Task : public ThreadTask
803 {
804 public:
805 Task(Machine *m, Progress *p, const Utf8Str &t)
806 : ThreadTask(t),
807 m_pMachine(m),
808 m_machineCaller(m),
809 m_pProgress(p),
810 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
811 {}
812 virtual ~Task(){}
813
814 void modifyBackedUpState(MachineState_T s)
815 {
816 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
817 }
818
819 ComObjPtr<Machine> m_pMachine;
820 AutoCaller m_machineCaller;
821 ComObjPtr<Progress> m_pProgress;
822 const MachineState_T m_machineStateBackup;
823 };
824
825 class DeleteConfigTask;
826 void i_deleteConfigHandler(DeleteConfigTask &task);
827
828 friend class SessionMachine;
829 friend class SnapshotMachine;
830 friend class Appliance;
831 friend class VirtualBox;
832
833 friend class MachineCloneVM;
834 friend class MachineMoveVM;
835private:
836 // wrapped IMachine properties
837 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
838 HRESULT getIcon(std::vector<BYTE> &aIcon);
839 HRESULT setIcon(const std::vector<BYTE> &aIcon);
840 HRESULT getAccessible(BOOL *aAccessible);
841 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
842 HRESULT getName(com::Utf8Str &aName);
843 HRESULT setName(const com::Utf8Str &aName);
844 HRESULT getDescription(com::Utf8Str &aDescription);
845 HRESULT setDescription(const com::Utf8Str &aDescription);
846 HRESULT getId(com::Guid &aId);
847 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
848 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
849 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
850 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
851 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
852 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
853 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
854 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
855 HRESULT getCPUCount(ULONG *aCPUCount);
856 HRESULT setCPUCount(ULONG aCPUCount);
857 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
858 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
859 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
860 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
861 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
862 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
863 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
864 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
865 HRESULT getMemorySize(ULONG *aMemorySize);
866 HRESULT setMemorySize(ULONG aMemorySize);
867 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
868 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
869 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
870 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
871 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
872 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
873 HRESULT getVRAMSize(ULONG *aVRAMSize);
874 HRESULT setVRAMSize(ULONG aVRAMSize);
875 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
876 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
877 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
878 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
879 HRESULT getMonitorCount(ULONG *aMonitorCount);
880 HRESULT setMonitorCount(ULONG aMonitorCount);
881 HRESULT getVideoCaptureEnabled(BOOL *aVideoCaptureEnabled);
882 HRESULT setVideoCaptureEnabled(BOOL aVideoCaptureEnabled);
883 HRESULT getVideoCaptureScreens(std::vector<BOOL> &aVideoCaptureScreens);
884 HRESULT setVideoCaptureScreens(const std::vector<BOOL> &aVideoCaptureScreens);
885 HRESULT getVideoCaptureFile(com::Utf8Str &aVideoCaptureFile);
886 HRESULT setVideoCaptureFile(const com::Utf8Str &aVideoCaptureFile);
887 HRESULT getVideoCaptureWidth(ULONG *aVideoCaptureWidth);
888 HRESULT setVideoCaptureWidth(ULONG aVideoCaptureWidth);
889 HRESULT getVideoCaptureHeight(ULONG *aVideoCaptureHeight);
890 HRESULT setVideoCaptureHeight(ULONG aVideoCaptureHeight);
891 HRESULT getVideoCaptureRate(ULONG *aVideoCaptureRate);
892 HRESULT setVideoCaptureRate(ULONG aVideoCaptureRate);
893 HRESULT getVideoCaptureFPS(ULONG *aVideoCaptureFPS);
894 HRESULT setVideoCaptureFPS(ULONG aVideoCaptureFPS);
895 HRESULT getVideoCaptureMaxTime(ULONG *aVideoCaptureMaxTime);
896 HRESULT setVideoCaptureMaxTime(ULONG aVideoCaptureMaxTime);
897 HRESULT getVideoCaptureMaxFileSize(ULONG *aVideoCaptureMaxFileSize);
898 HRESULT setVideoCaptureMaxFileSize(ULONG aVideoCaptureMaxFileSize);
899 HRESULT getVideoCaptureOptions(com::Utf8Str &aVideoCaptureOptions);
900 HRESULT setVideoCaptureOptions(const com::Utf8Str &aVideoCaptureOptions);
901 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
902 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
903 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
904 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
905 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
906 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
907 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
908 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
909 HRESULT setHPETEnabled(BOOL aHPETEnabled);
910 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
911 HRESULT setChipsetType(ChipsetType_T aChipsetType);
912 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
913 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
914 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
915 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
916 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
917 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
918 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
919 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
920 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
921 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
922 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
923 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
924 HRESULT getSettingsModified(BOOL *aSettingsModified);
925 HRESULT getSessionState(SessionState_T *aSessionState);
926 HRESULT getSessionType(SessionType_T *aSessionType);
927 HRESULT getSessionName(com::Utf8Str &aSessionType);
928 HRESULT getSessionPID(ULONG *aSessionPID);
929 HRESULT getState(MachineState_T *aState);
930 HRESULT getLastStateChange(LONG64 *aLastStateChange);
931 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
932 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
933 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
934 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
935 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
936 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
937 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
938 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
939 HRESULT getDnDMode(DnDMode_T *aDnDMode);
940 HRESULT setDnDMode(DnDMode_T aDnDMode);
941 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
942 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
943 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
944 HRESULT setTeleporterPort(ULONG aTeleporterPort);
945 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
946 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
947 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
948 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
949 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
950 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
951 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
952 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
953 HRESULT getFaultToleranceState(FaultToleranceState_T *aFaultToleranceState);
954 HRESULT setFaultToleranceState(FaultToleranceState_T aFaultToleranceState);
955 HRESULT getFaultTolerancePort(ULONG *aFaultTolerancePort);
956 HRESULT setFaultTolerancePort(ULONG aFaultTolerancePort);
957 HRESULT getFaultToleranceAddress(com::Utf8Str &aFaultToleranceAddress);
958 HRESULT setFaultToleranceAddress(const com::Utf8Str &aFaultToleranceAddress);
959 HRESULT getFaultTolerancePassword(com::Utf8Str &aFaultTolerancePassword);
960 HRESULT setFaultTolerancePassword(const com::Utf8Str &aFaultTolerancePassword);
961 HRESULT getFaultToleranceSyncInterval(ULONG *aFaultToleranceSyncInterval);
962 HRESULT setFaultToleranceSyncInterval(ULONG aFaultToleranceSyncInterval);
963 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
964 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
965 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
966 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
967 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
968 HRESULT setIOCacheSize(ULONG aIOCacheSize);
969 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
970 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
971 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
972 HRESULT setTracingEnabled(BOOL aTracingEnabled);
973 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
974 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
975 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
976 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
977 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
978 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
979 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
980 HRESULT setAutostartDelay(ULONG aAutostartDelay);
981 HRESULT getAutostopType(AutostopType_T *aAutostopType);
982 HRESULT setAutostopType(AutostopType_T aAutostopType);
983 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
984 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
985 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
986 HRESULT getVMProcessPriority(com::Utf8Str &aVMProcessPriority);
987 HRESULT setVMProcessPriority(const com::Utf8Str &aVMProcessPriority);
988
989 // wrapped IMachine methods
990 HRESULT lockMachine(const ComPtr<ISession> &aSession,
991 LockType_T aLockType);
992 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
993 const com::Utf8Str &aType,
994 const com::Utf8Str &aEnvironment,
995 ComPtr<IProgress> &aProgress);
996 HRESULT setBootOrder(ULONG aPosition,
997 DeviceType_T aDevice);
998 HRESULT getBootOrder(ULONG aPosition,
999 DeviceType_T *aDevice);
1000 HRESULT attachDevice(const com::Utf8Str &aName,
1001 LONG aControllerPort,
1002 LONG aDevice,
1003 DeviceType_T aType,
1004 const ComPtr<IMedium> &aMedium);
1005 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
1006 LONG aControllerPort,
1007 LONG aDevice,
1008 DeviceType_T aType);
1009 HRESULT detachDevice(const com::Utf8Str &aName,
1010 LONG aControllerPort,
1011 LONG aDevice);
1012 HRESULT passthroughDevice(const com::Utf8Str &aName,
1013 LONG aControllerPort,
1014 LONG aDevice,
1015 BOOL aPassthrough);
1016 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
1017 LONG aControllerPort,
1018 LONG aDevice,
1019 BOOL aTemporaryEject);
1020 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
1021 LONG aControllerPort,
1022 LONG aDevice,
1023 BOOL aNonRotational);
1024 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
1025 LONG aControllerPort,
1026 LONG aDevice,
1027 BOOL aDiscard);
1028 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
1029 LONG aControllerPort,
1030 LONG aDevice,
1031 BOOL aHotPluggable);
1032 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
1033 LONG aControllerPort,
1034 LONG aDevice,
1035 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
1036 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
1037 LONG aControllerPort,
1038 LONG aDevice);
1039 HRESULT unmountMedium(const com::Utf8Str &aName,
1040 LONG aControllerPort,
1041 LONG aDevice,
1042 BOOL aForce);
1043 HRESULT mountMedium(const com::Utf8Str &aName,
1044 LONG aControllerPort,
1045 LONG aDevice,
1046 const ComPtr<IMedium> &aMedium,
1047 BOOL aForce);
1048 HRESULT getMedium(const com::Utf8Str &aName,
1049 LONG aControllerPort,
1050 LONG aDevice,
1051 ComPtr<IMedium> &aMedium);
1052 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
1053 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
1054 HRESULT getMediumAttachment(const com::Utf8Str &aName,
1055 LONG aControllerPort,
1056 LONG aDevice,
1057 ComPtr<IMediumAttachment> &aAttachment);
1058 HRESULT attachHostPCIDevice(LONG aHostAddress,
1059 LONG aDesiredGuestAddress,
1060 BOOL aTryToUnbind);
1061 HRESULT detachHostPCIDevice(LONG aHostAddress);
1062 HRESULT getNetworkAdapter(ULONG aSlot,
1063 ComPtr<INetworkAdapter> &aAdapter);
1064 HRESULT addStorageController(const com::Utf8Str &aName,
1065 StorageBus_T aConnectionType,
1066 ComPtr<IStorageController> &aController);
1067 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1068 ComPtr<IStorageController> &aStorageController);
1069 HRESULT getStorageControllerByInstance(StorageBus_T aConnectionType,
1070 ULONG aInstance,
1071 ComPtr<IStorageController> &aStorageController);
1072 HRESULT removeStorageController(const com::Utf8Str &aName);
1073 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1074 BOOL aBootable);
1075 HRESULT addUSBController(const com::Utf8Str &aName,
1076 USBControllerType_T aType,
1077 ComPtr<IUSBController> &aController);
1078 HRESULT removeUSBController(const com::Utf8Str &aName);
1079 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1080 ComPtr<IUSBController> &aController);
1081 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1082 ULONG *aControllers);
1083 HRESULT getSerialPort(ULONG aSlot,
1084 ComPtr<ISerialPort> &aPort);
1085 HRESULT getParallelPort(ULONG aSlot,
1086 ComPtr<IParallelPort> &aPort);
1087 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1088 HRESULT getExtraData(const com::Utf8Str &aKey,
1089 com::Utf8Str &aValue);
1090 HRESULT setExtraData(const com::Utf8Str &aKey,
1091 const com::Utf8Str &aValue);
1092 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1093 BOOL *aValue);
1094 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1095 BOOL aValue);
1096 HRESULT getCPUIDLeafByOrdinal(ULONG aOrdinal,
1097 ULONG *aIdx,
1098 ULONG *aSubIdx,
1099 ULONG *aValEax,
1100 ULONG *aValEbx,
1101 ULONG *aValEcx,
1102 ULONG *aValEdx);
1103 HRESULT getCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1104 ULONG *aValEax,
1105 ULONG *aValEbx,
1106 ULONG *aValEcx,
1107 ULONG *aValEdx);
1108 HRESULT setCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1109 ULONG aValEax,
1110 ULONG aValEbx,
1111 ULONG aValEcx,
1112 ULONG aValEdx);
1113 HRESULT removeCPUIDLeaf(ULONG aIdx, ULONG aSubIdx);
1114 HRESULT removeAllCPUIDLeaves();
1115 HRESULT getHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1116 BOOL *aValue);
1117 HRESULT setHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1118 BOOL aValue);
1119 HRESULT setSettingsFilePath(const com::Utf8Str &aSettingsFilePath,
1120 ComPtr<IProgress> &aProgress);
1121 HRESULT saveSettings();
1122 HRESULT discardSettings();
1123 HRESULT unregister(AutoCaller &aAutoCaller,
1124 CleanupMode_T aCleanupMode,
1125 std::vector<ComPtr<IMedium> > &aMedia);
1126 HRESULT deleteConfig(const std::vector<ComPtr<IMedium> > &aMedia,
1127 ComPtr<IProgress> &aProgress);
1128 HRESULT exportTo(const ComPtr<IAppliance> &aAppliance,
1129 const com::Utf8Str &aLocation,
1130 ComPtr<IVirtualSystemDescription> &aDescription);
1131 HRESULT findSnapshot(const com::Utf8Str &aNameOrId,
1132 ComPtr<ISnapshot> &aSnapshot);
1133 HRESULT createSharedFolder(const com::Utf8Str &aName,
1134 const com::Utf8Str &aHostPath,
1135 BOOL aWritable,
1136 BOOL aAutomount);
1137 HRESULT removeSharedFolder(const com::Utf8Str &aName);
1138 HRESULT canShowConsoleWindow(BOOL *aCanShow);
1139 HRESULT showConsoleWindow(LONG64 *aWinId);
1140 HRESULT getGuestProperty(const com::Utf8Str &aName,
1141 com::Utf8Str &aValue,
1142 LONG64 *aTimestamp,
1143 com::Utf8Str &aFlags);
1144 HRESULT getGuestPropertyValue(const com::Utf8Str &aProperty,
1145 com::Utf8Str &aValue);
1146 HRESULT getGuestPropertyTimestamp(const com::Utf8Str &aProperty,
1147 LONG64 *aValue);
1148 HRESULT setGuestProperty(const com::Utf8Str &aProperty,
1149 const com::Utf8Str &aValue,
1150 const com::Utf8Str &aFlags);
1151 HRESULT setGuestPropertyValue(const com::Utf8Str &aProperty,
1152 const com::Utf8Str &aValue);
1153 HRESULT deleteGuestProperty(const com::Utf8Str &aName);
1154 HRESULT enumerateGuestProperties(const com::Utf8Str &aPatterns,
1155 std::vector<com::Utf8Str> &aNames,
1156 std::vector<com::Utf8Str> &aValues,
1157 std::vector<LONG64> &aTimestamps,
1158 std::vector<com::Utf8Str> &aFlags);
1159 HRESULT querySavedGuestScreenInfo(ULONG aScreenId,
1160 ULONG *aOriginX,
1161 ULONG *aOriginY,
1162 ULONG *aWidth,
1163 ULONG *aHeight,
1164 BOOL *aEnabled);
1165 HRESULT readSavedThumbnailToArray(ULONG aScreenId,
1166 BitmapFormat_T aBitmapFormat,
1167 ULONG *aWidth,
1168 ULONG *aHeight,
1169 std::vector<BYTE> &aData);
1170 HRESULT querySavedScreenshotInfo(ULONG aScreenId,
1171 ULONG *aWidth,
1172 ULONG *aHeight,
1173 std::vector<BitmapFormat_T> &aBitmapFormats);
1174 HRESULT readSavedScreenshotToArray(ULONG aScreenId,
1175 BitmapFormat_T aBitmapFormat,
1176 ULONG *aWidth,
1177 ULONG *aHeight,
1178 std::vector<BYTE> &aData);
1179
1180 HRESULT hotPlugCPU(ULONG aCpu);
1181 HRESULT hotUnplugCPU(ULONG aCpu);
1182 HRESULT getCPUStatus(ULONG aCpu,
1183 BOOL *aAttached);
1184 HRESULT getEffectiveParavirtProvider(ParavirtProvider_T *aParavirtProvider);
1185 HRESULT queryLogFilename(ULONG aIdx,
1186 com::Utf8Str &aFilename);
1187 HRESULT readLog(ULONG aIdx,
1188 LONG64 aOffset,
1189 LONG64 aSize,
1190 std::vector<BYTE> &aData);
1191 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1192 CloneMode_T aMode,
1193 const std::vector<CloneOptions_T> &aOptions,
1194 ComPtr<IProgress> &aProgress);
1195 HRESULT moveTo(const com::Utf8Str &aTargetPath,
1196 const com::Utf8Str &aType,
1197 ComPtr<IProgress> &aProgress);
1198 HRESULT saveState(ComPtr<IProgress> &aProgress);
1199 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1200 HRESULT discardSavedState(BOOL aFRemoveFile);
1201 HRESULT takeSnapshot(const com::Utf8Str &aName,
1202 const com::Utf8Str &aDescription,
1203 BOOL aPause,
1204 com::Guid &aId,
1205 ComPtr<IProgress> &aProgress);
1206 HRESULT deleteSnapshot(const com::Guid &aId,
1207 ComPtr<IProgress> &aProgress);
1208 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1209 ComPtr<IProgress> &aProgress);
1210 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1211 const com::Guid &aEndId,
1212 ComPtr<IProgress> &aProgress);
1213 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1214 ComPtr<IProgress> &aProgress);
1215 HRESULT applyDefaults(const com::Utf8Str &aFlags);
1216
1217 // wrapped IInternalMachineControl properties
1218
1219 // wrapped IInternalMachineControl methods
1220 HRESULT updateState(MachineState_T aState);
1221 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1222 HRESULT endPowerUp(LONG aResult);
1223 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1224 HRESULT endPoweringDown(LONG aResult,
1225 const com::Utf8Str &aErrMsg);
1226 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1227 BOOL *aMatched,
1228 ULONG *aMaskedInterfaces);
1229 HRESULT captureUSBDevice(const com::Guid &aId,
1230 const com::Utf8Str &aCaptureFilename);
1231 HRESULT detachUSBDevice(const com::Guid &aId,
1232 BOOL aDone);
1233 HRESULT autoCaptureUSBDevices();
1234 HRESULT detachAllUSBDevices(BOOL aDone);
1235 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1236 ComPtr<IProgress> &aProgress);
1237 HRESULT finishOnlineMergeMedium();
1238 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1239 std::vector<com::Utf8Str> &aValues,
1240 std::vector<LONG64> &aTimestamps,
1241 std::vector<com::Utf8Str> &aFlags);
1242 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1243 const com::Utf8Str &aValue,
1244 LONG64 aTimestamp,
1245 const com::Utf8Str &aFlags);
1246 HRESULT lockMedia();
1247 HRESULT unlockMedia();
1248 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1249 ComPtr<IMediumAttachment> &aNewAttachment);
1250 HRESULT reportVmStatistics(ULONG aValidStats,
1251 ULONG aCpuUser,
1252 ULONG aCpuKernel,
1253 ULONG aCpuIdle,
1254 ULONG aMemTotal,
1255 ULONG aMemFree,
1256 ULONG aMemBalloon,
1257 ULONG aMemShared,
1258 ULONG aMemCache,
1259 ULONG aPagedTotal,
1260 ULONG aMemAllocTotal,
1261 ULONG aMemFreeTotal,
1262 ULONG aMemBalloonTotal,
1263 ULONG aMemSharedTotal,
1264 ULONG aVmNetRx,
1265 ULONG aVmNetTx);
1266 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1267 com::Utf8Str &aResult);
1268};
1269
1270// SessionMachine class
1271////////////////////////////////////////////////////////////////////////////////
1272
1273/**
1274 * @note Notes on locking objects of this class:
1275 * SessionMachine shares some data with the primary Machine instance (pointed
1276 * to by the |mPeer| member). In order to provide data consistency it also
1277 * shares its lock handle. This means that whenever you lock a SessionMachine
1278 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1279 * instance is also locked in the same lock mode. Keep it in mind.
1280 */
1281class ATL_NO_VTABLE SessionMachine :
1282 public Machine
1283{
1284public:
1285 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1286
1287 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1288
1289 DECLARE_PROTECT_FINAL_CONSTRUCT()
1290
1291 BEGIN_COM_MAP(SessionMachine)
1292 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1293 COM_INTERFACE_ENTRY(IMachine)
1294 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1295 COM_INTERFACE_ENTRY(IInternalMachineControl)
1296 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1297 END_COM_MAP()
1298
1299 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1300
1301 HRESULT FinalConstruct();
1302 void FinalRelease();
1303
1304 struct Uninit
1305 {
1306 enum Reason { Unexpected, Abnormal, Normal };
1307 };
1308
1309 // public initializer/uninitializer for internal purposes only
1310 HRESULT init(Machine *aMachine);
1311 void uninit() { uninit(Uninit::Unexpected); }
1312 void uninit(Uninit::Reason aReason);
1313
1314
1315 // util::Lockable interface
1316 RWLockHandle *lockHandle() const;
1317
1318 // public methods only for internal purposes
1319
1320 virtual bool i_isSessionMachine() const
1321 {
1322 return true;
1323 }
1324
1325#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1326 bool i_checkForDeath();
1327
1328 void i_getTokenId(Utf8Str &strTokenId);
1329#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1330 IToken *i_getToken();
1331#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1332 // getClientToken must be only used by callers who can guarantee that
1333 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1334 ClientToken *i_getClientToken();
1335
1336 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1337 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1338 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1339 IN_BSTR aGuestIp, LONG aGuestPort);
1340 HRESULT i_onStorageControllerChange();
1341 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1342 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1343 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1344 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1345 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1346 HRESULT i_onVRDEServerChange(BOOL aRestart);
1347 HRESULT i_onVideoCaptureChange();
1348 HRESULT i_onUSBControllerChange();
1349 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1350 IVirtualBoxErrorInfo *aError,
1351 ULONG aMaskedIfs,
1352 const com::Utf8Str &aCaptureFilename);
1353 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1354 IVirtualBoxErrorInfo *aError);
1355 HRESULT i_onSharedFolderChange();
1356 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1357 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1358 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1359 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1360 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1361
1362 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1363
1364 HRESULT i_lockMedia();
1365 HRESULT i_unlockMedia();
1366
1367 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1368
1369private:
1370
1371 // wrapped IInternalMachineControl properties
1372
1373 // wrapped IInternalMachineControl methods
1374 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1375 HRESULT updateState(MachineState_T aState);
1376 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1377 HRESULT endPowerUp(LONG aResult);
1378 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1379 HRESULT endPoweringDown(LONG aResult,
1380 const com::Utf8Str &aErrMsg);
1381 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1382 BOOL *aMatched,
1383 ULONG *aMaskedInterfaces);
1384 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1385 HRESULT detachUSBDevice(const com::Guid &aId,
1386 BOOL aDone);
1387 HRESULT autoCaptureUSBDevices();
1388 HRESULT detachAllUSBDevices(BOOL aDone);
1389 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1390 ComPtr<IProgress> &aProgress);
1391 HRESULT finishOnlineMergeMedium();
1392 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1393 std::vector<com::Utf8Str> &aValues,
1394 std::vector<LONG64> &aTimestamps,
1395 std::vector<com::Utf8Str> &aFlags);
1396 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1397 const com::Utf8Str &aValue,
1398 LONG64 aTimestamp,
1399 const com::Utf8Str &aFlags);
1400 HRESULT lockMedia();
1401 HRESULT unlockMedia();
1402 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1403 ComPtr<IMediumAttachment> &aNewAttachment);
1404 HRESULT reportVmStatistics(ULONG aValidStats,
1405 ULONG aCpuUser,
1406 ULONG aCpuKernel,
1407 ULONG aCpuIdle,
1408 ULONG aMemTotal,
1409 ULONG aMemFree,
1410 ULONG aMemBalloon,
1411 ULONG aMemShared,
1412 ULONG aMemCache,
1413 ULONG aPagedTotal,
1414 ULONG aMemAllocTotal,
1415 ULONG aMemFreeTotal,
1416 ULONG aMemBalloonTotal,
1417 ULONG aMemSharedTotal,
1418 ULONG aVmNetRx,
1419 ULONG aVmNetTx);
1420 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1421 com::Utf8Str &aResult);
1422
1423
1424 struct ConsoleTaskData
1425 {
1426 ConsoleTaskData()
1427 : mLastState(MachineState_Null),
1428 mDeleteSnapshotInfo(NULL)
1429 { }
1430
1431 MachineState_T mLastState;
1432 ComObjPtr<Progress> mProgress;
1433
1434 // used when deleting online snaphshot
1435 void *mDeleteSnapshotInfo;
1436 };
1437
1438 class SaveStateTask;
1439 class SnapshotTask;
1440 class TakeSnapshotTask;
1441 class DeleteSnapshotTask;
1442 class RestoreSnapshotTask;
1443
1444 void i_saveStateHandler(SaveStateTask &aTask);
1445
1446 // Override some functionality for SessionMachine, this is where the
1447 // real action happens (the Machine methods are just dummies).
1448 HRESULT saveState(ComPtr<IProgress> &aProgress);
1449 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1450 HRESULT discardSavedState(BOOL aFRemoveFile);
1451 HRESULT takeSnapshot(const com::Utf8Str &aName,
1452 const com::Utf8Str &aDescription,
1453 BOOL aPause,
1454 com::Guid &aId,
1455 ComPtr<IProgress> &aProgress);
1456 HRESULT deleteSnapshot(const com::Guid &aId,
1457 ComPtr<IProgress> &aProgress);
1458 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1459 ComPtr<IProgress> &aProgress);
1460 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1461 const com::Guid &aEndId,
1462 ComPtr<IProgress> &aProgress);
1463 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1464 ComPtr<IProgress> &aProgress);
1465
1466 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1467
1468 void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
1469 static void i_takeSnapshotProgressCancelCallback(void *pvUser);
1470 HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
1471 HRESULT i_deleteSnapshot(const com::Guid &aStartId,
1472 const com::Guid &aEndId,
1473 BOOL aDeleteAllChildren,
1474 ComPtr<IProgress> &aProgress);
1475 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1476 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1477
1478 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1479 const Guid &machineId,
1480 const Guid &snapshotId,
1481 bool fOnlineMergePossible,
1482 MediumLockList *aVMMALockList,
1483 ComObjPtr<Medium> &aSource,
1484 ComObjPtr<Medium> &aTarget,
1485 bool &fMergeForward,
1486 ComObjPtr<Medium> &pParentForTarget,
1487 MediumLockList * &aChildrenToReparent,
1488 bool &fNeedOnlineMerge,
1489 MediumLockList * &aMediumLockList,
1490 ComPtr<IToken> &aHDLockToken);
1491 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1492 const ComObjPtr<Medium> &aSource,
1493 MediumLockList *aChildrenToReparent,
1494 bool fNeedsOnlineMerge,
1495 MediumLockList *aMediumLockList,
1496 const ComPtr<IToken> &aHDLockToken,
1497 const Guid &aMediumId,
1498 const Guid &aSnapshotId);
1499 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1500 const ComObjPtr<Medium> &aSource,
1501 const ComObjPtr<Medium> &aTarget,
1502 bool fMergeForward,
1503 const ComObjPtr<Medium> &pParentForTarget,
1504 MediumLockList *aChildrenToReparent,
1505 MediumLockList *aMediumLockList,
1506 ComObjPtr<Progress> &aProgress,
1507 bool *pfNeedsMachineSaveSettings);
1508
1509 HRESULT i_setMachineState(MachineState_T aMachineState);
1510 HRESULT i_updateMachineStateOnClient();
1511
1512 bool mRemoveSavedState;
1513
1514 ConsoleTaskData mConsoleTaskData;
1515
1516 /** client token for this machine */
1517 ClientToken *mClientToken;
1518
1519 int miNATNetworksStarted;
1520
1521 AUTHLIBRARYCONTEXT mAuthLibCtx;
1522};
1523
1524// SnapshotMachine class
1525////////////////////////////////////////////////////////////////////////////////
1526
1527/**
1528 * @note Notes on locking objects of this class:
1529 * SnapshotMachine shares some data with the primary Machine instance (pointed
1530 * to by the |mPeer| member). In order to provide data consistency it also
1531 * shares its lock handle. This means that whenever you lock a SessionMachine
1532 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1533 * instance is also locked in the same lock mode. Keep it in mind.
1534 */
1535class ATL_NO_VTABLE SnapshotMachine :
1536 public Machine
1537{
1538public:
1539 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1540
1541 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1542
1543 DECLARE_PROTECT_FINAL_CONSTRUCT()
1544
1545 BEGIN_COM_MAP(SnapshotMachine)
1546 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1547 COM_INTERFACE_ENTRY(IMachine)
1548 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1549 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1550 END_COM_MAP()
1551
1552 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1553
1554 HRESULT FinalConstruct();
1555 void FinalRelease();
1556
1557 // public initializer/uninitializer for internal purposes only
1558 HRESULT init(SessionMachine *aSessionMachine,
1559 IN_GUID aSnapshotId,
1560 const Utf8Str &aStateFilePath);
1561 HRESULT initFromSettings(Machine *aMachine,
1562 const settings::Hardware &hardware,
1563 const settings::Debugging *pDbg,
1564 const settings::Autostart *pAutostart,
1565 IN_GUID aSnapshotId,
1566 const Utf8Str &aStateFilePath);
1567 void uninit();
1568
1569 // util::Lockable interface
1570 RWLockHandle *lockHandle() const;
1571
1572 // public methods only for internal purposes
1573
1574 virtual bool i_isSnapshotMachine() const
1575 {
1576 return true;
1577 }
1578
1579 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1580
1581 // unsafe inline public methods for internal purposes only (ensure there is
1582 // a caller and a read lock before calling them!)
1583
1584 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1585
1586private:
1587
1588 Guid mSnapshotId;
1589 /** This field replaces mPeer for SessionMachine instances, as having
1590 * a peer reference is plain meaningless and causes many subtle problems
1591 * with saving settings and the like. */
1592 Machine * const mMachine;
1593
1594 friend class Snapshot;
1595};
1596
1597// third party methods that depend on SnapshotMachine definition
1598
1599inline const Guid &Machine::i_getSnapshotId() const
1600{
1601 return (i_isSnapshotMachine())
1602 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1603 : Guid::Empty;
1604}
1605
1606
1607#endif // ____H_MACHINEIMPL
1608/* 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