VirtualBox

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

Last change on this file since 62141 was 62141, checked in by vboxsync, 8 years ago

Main: fixed a few small memory leaks

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