VirtualBox

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

Last change on this file since 61009 was 61009, checked in by vboxsync, 9 years ago

Main: big settings cleanup and writing optimization. Moved constructors/equality/default checks into the .cpp file, and write only settings which aren't at the default value. Greatly reduces the effort needed to write everything out, especially when a lot of snapshots have to be dealt with. Move the storage controllers to the hardware settings, where they always belonged. No change to the XML file (yet). Lots of settings related cleanups in the API code.

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