VirtualBox

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

Last change on this file since 94601 was 94598, checked in by vboxsync, 3 years ago

Main/Machine+Medium+Snapshot+VirtualBox: Recursion elimination to save stack space. Caused trouble with the current settings limits already in ASAN builds, now much higher limits would be possible, but that's not urgent. Also fix the behavior of forgetting medium objects when unregistering VMs (was previously not doing what the API documentation said in the CleanupMode_UnregisterOnly case). bugref:7717

Settings.cpp: Recursion elimination and make the handling of settings reading and writing more similar.

ValidationKit/tests/api/tdTreeDepth1.py: Improve testcase. Make sure that VM unregistering does the right thing with the associated medium objects.

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