VirtualBox

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

Last change on this file since 69785 was 68938, checked in by vboxsync, 7 years ago

Main,VBoxManage: Changed the CPUID override methods on IMachine to take sub-leaves into account. Currently we do not support non-zero sub-leaves due to VMM, but that can be fixed later.

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