VirtualBox

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

Last change on this file since 74910 was 72919, checked in by vboxsync, 6 years ago

Main/*: From now on any valid UTF8 string is considered a valid guest OS type. Of course not all of them are known, so the API clients must be prepared to deal with not having a matching IGuestOSType object.
Frontends/VBoxManage+VBoxShell: adjust to deal with the change

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