VirtualBox

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

Last change on this file since 70644 was 70606, checked in by vboxsync, 7 years ago

updates (bugref:9087)

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