VirtualBox

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

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

Main: Added HWVirtExPropertyType::UseNativeApi for use with IMachine::getHWVirtExProperty and IMachine::setHWVirtExProperty. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.3 KB
Line 
1/* $Id: MachineImpl.h 72332 2018-05-24 20:51:23Z 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 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 Utf8Str i_getOSTypeId() const { return mUserData->s.strOsType; }
495 ChipsetType_T i_getChipsetType() const { return mHWData->mChipsetType; }
496 ParavirtProvider_T i_getParavirtProvider() const { return mHWData->mParavirtProvider; }
497 Utf8Str i_getParavirtDebug() const { return mHWData->mParavirtDebug; }
498
499 void i_setModified(uint32_t fl, bool fAllowStateModification = true);
500 void i_setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
501
502 bool i_isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
503 void i_allowStateModification() { mData->m_fAllowStateModification = true; }
504 void i_disallowStateModification() { mData->m_fAllowStateModification = false; }
505
506 const StringsList &i_getGroups() const { return mUserData->s.llGroups; }
507
508 // callback handlers
509 virtual HRESULT i_onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
510 virtual HRESULT i_onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
511 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */,
512 IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
513 virtual HRESULT i_onAudioAdapterChange(IAudioAdapter * /* audioAdapter */) { return S_OK; }
514 virtual HRESULT i_onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
515 virtual HRESULT i_onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
516 virtual HRESULT i_onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
517 virtual HRESULT i_onUSBControllerChange() { return S_OK; }
518 virtual HRESULT i_onStorageControllerChange() { return S_OK; }
519 virtual HRESULT i_onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
520 virtual HRESULT i_onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
521 virtual HRESULT i_onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
522 virtual HRESULT i_onSharedFolderChange() { return S_OK; }
523 virtual HRESULT i_onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
524 virtual HRESULT i_onDnDModeChange(DnDMode_T /* aDnDMode */) { return S_OK; }
525 virtual HRESULT i_onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
526 virtual HRESULT i_onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */,
527 BOOL /* silent */) { return S_OK; }
528 virtual HRESULT i_onVideoCaptureChange() { return S_OK; }
529
530 HRESULT i_saveRegistryEntry(settings::MachineRegistryEntry &data);
531
532 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
533 void i_copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
534
535 void i_getLogFolder(Utf8Str &aLogFolder);
536 Utf8Str i_getLogFilename(ULONG idx);
537 Utf8Str i_getHardeningLogFilename(void);
538
539 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
540
541 void i_getDefaultVideoCaptureFile(Utf8Str &strFile);
542
543 bool i_isUSBControllerPresent();
544
545 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
546 const Utf8Str &strType,
547 const Utf8Str &strEnvironment,
548 ProgressProxy *aProgress);
549
550 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
551 {
552 HRESULT rc;
553 *directControl = mData->mSession.mDirectControl;
554
555 if (!*directControl)
556 rc = E_ACCESSDENIED;
557 else
558 rc = S_OK;
559
560 return rc;
561 }
562
563 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
564 ComPtr<IInternalSessionControl> *aControl = NULL,
565 bool aRequireVM = false,
566 bool aAllowClosing = false);
567 bool i_isSessionSpawning();
568
569 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
570 ComPtr<IInternalSessionControl> *aControl = NULL)
571 { return i_isSessionOpen(aMachine, aControl, false /* aRequireVM */, true /* aAllowClosing */); }
572
573 bool i_isSessionOpenVM(ComObjPtr<SessionMachine> &aMachine,
574 ComPtr<IInternalSessionControl> *aControl = NULL)
575 { return i_isSessionOpen(aMachine, aControl, true /* aRequireVM */, false /* aAllowClosing */); }
576
577 bool i_checkForSpawnFailure();
578
579 HRESULT i_prepareRegister();
580
581 HRESULT i_getSharedFolder(CBSTR aName,
582 ComObjPtr<SharedFolder> &aSharedFolder,
583 bool aSetError = false)
584 {
585 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
586 return i_findSharedFolder(aName, aSharedFolder, aSetError);
587 }
588
589 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
590 MachineState_T *aState = NULL,
591 BOOL *aRegistered = NULL);
592 void i_releaseStateDependency();
593
594 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
595 ComObjPtr<StorageController> &aStorageController,
596 bool aSetError = false);
597
598 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
599 MediumAttachmentList &aAttachments);
600
601 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
602 ComObjPtr<USBController> &aUSBController,
603 bool aSetError = false);
604
605 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
606 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
607 bool fSetError = false)
608 {
609 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
610 pBandwidthGroup,
611 fSetError);
612 }
613
614 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
615
616protected:
617
618 class ClientToken;
619
620 HRESULT i_checkStateDependency(StateDependency aDepType);
621
622 Machine *i_getMachine();
623
624 void i_ensureNoStateDependencies();
625
626 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
627
628 HRESULT i_findSharedFolder(const Utf8Str &aName,
629 ComObjPtr<SharedFolder> &aSharedFolder,
630 bool aSetError = false);
631
632 HRESULT i_loadSettings(bool aRegistered);
633 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
634 const Guid *puuidRegistry);
635 HRESULT i_loadSnapshot(const settings::Snapshot &data,
636 const Guid &aCurSnapshotId,
637 Snapshot *aParentSnapshot);
638 HRESULT i_loadHardware(const Guid *puuidRegistry,
639 const Guid *puuidSnapshot,
640 const settings::Hardware &data,
641 const settings::Debugging *pDbg,
642 const settings::Autostart *pAutostart);
643 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
644 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
645 HRESULT i_loadStorageControllers(const settings::Storage &data,
646 const Guid *puuidRegistry,
647 const Guid *puuidSnapshot);
648 HRESULT i_loadStorageDevices(StorageController *aStorageController,
649 const settings::StorageController &data,
650 const Guid *puuidRegistry,
651 const Guid *puuidSnapshot);
652
653 HRESULT i_findSnapshotById(const Guid &aId,
654 ComObjPtr<Snapshot> &aSnapshot,
655 bool aSetError = false);
656 HRESULT i_findSnapshotByName(const Utf8Str &strName,
657 ComObjPtr<Snapshot> &aSnapshot,
658 bool aSetError = false);
659
660 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
661
662 enum
663 {
664 /* flags for #saveSettings() */
665 SaveS_ResetCurStateModified = 0x01,
666 SaveS_Force = 0x04,
667 /* flags for #saveStateSettings() */
668 SaveSTS_CurStateModified = 0x20,
669 SaveSTS_StateFilePath = 0x40,
670 SaveSTS_StateTimeStamp = 0x80
671 };
672
673 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
674 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
675
676 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
677 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
678 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
679 settings::Autostart *pAutostart);
680 HRESULT i_saveStorageControllers(settings::Storage &data);
681 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
682 settings::StorageController &data);
683 HRESULT i_saveStateSettings(int aFlags);
684
685 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
686
687 HRESULT i_createImplicitDiffs(IProgress *aProgress,
688 ULONG aWeight,
689 bool aOnline);
690 HRESULT i_deleteImplicitDiffs(bool aOnline);
691
692 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
693 const Utf8Str &aControllerName,
694 LONG aControllerPort,
695 LONG aDevice);
696 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
697 ComObjPtr<Medium> pMedium);
698 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
699 Guid &id);
700
701 HRESULT i_detachDevice(MediumAttachment *pAttach,
702 AutoWriteLock &writeLock,
703 Snapshot *pSnapshot);
704
705 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
706 Snapshot *pSnapshot,
707 CleanupMode_T cleanupMode,
708 MediaList &llMedia);
709
710 void i_commitMedia(bool aOnline = false);
711 void i_rollbackMedia();
712
713 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
714
715 void i_rollback(bool aNotify);
716 void i_commit();
717 void i_copyFrom(Machine *aThat);
718 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
719
720 Utf8Str i_getExtraData(const Utf8Str &strKey);
721
722#ifdef VBOX_WITH_GUEST_PROPS
723 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
724 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
725 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
726 const com::Utf8Str &aFlags, bool fDelete);
727 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
728 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
729 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
730 const com::Utf8Str &aFlags, bool fDelete);
731 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
732 std::vector<com::Utf8Str> &aNames,
733 std::vector<com::Utf8Str> &aValues,
734 std::vector<LONG64> &aTimestamps,
735 std::vector<com::Utf8Str> &aFlags);
736 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
737 std::vector<com::Utf8Str> &aNames,
738 std::vector<com::Utf8Str> &aValues,
739 std::vector<LONG64> &aTimestamps,
740 std::vector<com::Utf8Str> &aFlags);
741
742#endif /* VBOX_WITH_GUEST_PROPS */
743
744#ifdef VBOX_WITH_RESOURCE_USAGE_API
745 void i_getDiskList(MediaList &list);
746 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
747
748 pm::CollectorGuest *mCollectorGuest;
749#endif /* VBOX_WITH_RESOURCE_USAGE_API */
750
751 Machine * const mPeer;
752
753 VirtualBox * const mParent;
754
755 Shareable<Data> mData;
756 Shareable<SSData> mSSData;
757
758 Backupable<UserData> mUserData;
759 Backupable<HWData> mHWData;
760
761 /**
762 * Hard disk and other media data.
763 *
764 * The usage policy is the same as for mHWData, but a separate field
765 * is necessary because hard disk data requires different procedures when
766 * taking or deleting snapshots, etc.
767 *
768 * @todo r=klaus change this to a regular list and use the normal way to
769 * handle the settings when creating a session or taking a snapshot.
770 * Same thing applies to mStorageControllers and mUSBControllers.
771 */
772 Backupable<MediumAttachmentList> mMediumAttachments;
773
774 // the following fields need special backup/rollback/commit handling,
775 // so they cannot be a part of HWData
776
777 const ComObjPtr<VRDEServer> mVRDEServer;
778 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
779 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
780 const ComObjPtr<AudioAdapter> mAudioAdapter;
781 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
782 const ComObjPtr<BIOSSettings> mBIOSSettings;
783 const ComObjPtr<BandwidthControl> mBandwidthControl;
784
785 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
786 NetworkAdapterVector mNetworkAdapters;
787
788 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
789 Backupable<StorageControllerList> mStorageControllers;
790
791 typedef std::list<ComObjPtr<USBController> > USBControllerList;
792 Backupable<USBControllerList> mUSBControllers;
793
794 uint64_t uRegistryNeedsSaving;
795
796 /**
797 * Abstract base class for all Machine or SessionMachine related
798 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
799 * a (non-static) method as its thread function, so instead we have it call
800 * the static Machine::taskHandler, which then calls the handler() method
801 * in here (implemented by the subclasses).
802 */
803 class Task : public ThreadTask
804 {
805 public:
806 Task(Machine *m, Progress *p, const Utf8Str &t)
807 : ThreadTask(t),
808 m_pMachine(m),
809 m_machineCaller(m),
810 m_pProgress(p),
811 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
812 {}
813 virtual ~Task(){}
814
815 void modifyBackedUpState(MachineState_T s)
816 {
817 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
818 }
819
820 ComObjPtr<Machine> m_pMachine;
821 AutoCaller m_machineCaller;
822 ComObjPtr<Progress> m_pProgress;
823 const MachineState_T m_machineStateBackup;
824 };
825
826 class DeleteConfigTask;
827 void i_deleteConfigHandler(DeleteConfigTask &task);
828
829 friend class SessionMachine;
830 friend class SnapshotMachine;
831 friend class Appliance;
832 friend class VirtualBox;
833
834 friend class MachineCloneVM;
835 friend class MachineMoveVM;
836private:
837 // wrapped IMachine properties
838 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
839 HRESULT getIcon(std::vector<BYTE> &aIcon);
840 HRESULT setIcon(const std::vector<BYTE> &aIcon);
841 HRESULT getAccessible(BOOL *aAccessible);
842 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
843 HRESULT getName(com::Utf8Str &aName);
844 HRESULT setName(const com::Utf8Str &aName);
845 HRESULT getDescription(com::Utf8Str &aDescription);
846 HRESULT setDescription(const com::Utf8Str &aDescription);
847 HRESULT getId(com::Guid &aId);
848 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
849 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
850 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
851 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
852 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
853 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
854 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
855 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
856 HRESULT getCPUCount(ULONG *aCPUCount);
857 HRESULT setCPUCount(ULONG aCPUCount);
858 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
859 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
860 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
861 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
862 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
863 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
864 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
865 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
866 HRESULT getMemorySize(ULONG *aMemorySize);
867 HRESULT setMemorySize(ULONG aMemorySize);
868 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
869 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
870 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
871 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
872 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
873 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
874 HRESULT getVRAMSize(ULONG *aVRAMSize);
875 HRESULT setVRAMSize(ULONG aVRAMSize);
876 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
877 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
878 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
879 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
880 HRESULT getMonitorCount(ULONG *aMonitorCount);
881 HRESULT setMonitorCount(ULONG aMonitorCount);
882 HRESULT getVideoCaptureEnabled(BOOL *aVideoCaptureEnabled);
883 HRESULT setVideoCaptureEnabled(BOOL aVideoCaptureEnabled);
884 HRESULT getVideoCaptureScreens(std::vector<BOOL> &aVideoCaptureScreens);
885 HRESULT setVideoCaptureScreens(const std::vector<BOOL> &aVideoCaptureScreens);
886 HRESULT getVideoCaptureFile(com::Utf8Str &aVideoCaptureFile);
887 HRESULT setVideoCaptureFile(const com::Utf8Str &aVideoCaptureFile);
888 HRESULT getVideoCaptureWidth(ULONG *aVideoCaptureWidth);
889 HRESULT setVideoCaptureWidth(ULONG aVideoCaptureWidth);
890 HRESULT getVideoCaptureHeight(ULONG *aVideoCaptureHeight);
891 HRESULT setVideoCaptureHeight(ULONG aVideoCaptureHeight);
892 HRESULT getVideoCaptureRate(ULONG *aVideoCaptureRate);
893 HRESULT setVideoCaptureRate(ULONG aVideoCaptureRate);
894 HRESULT getVideoCaptureFPS(ULONG *aVideoCaptureFPS);
895 HRESULT setVideoCaptureFPS(ULONG aVideoCaptureFPS);
896 HRESULT getVideoCaptureMaxTime(ULONG *aVideoCaptureMaxTime);
897 HRESULT setVideoCaptureMaxTime(ULONG aVideoCaptureMaxTime);
898 HRESULT getVideoCaptureMaxFileSize(ULONG *aVideoCaptureMaxFileSize);
899 HRESULT setVideoCaptureMaxFileSize(ULONG aVideoCaptureMaxFileSize);
900 HRESULT getVideoCaptureOptions(com::Utf8Str &aVideoCaptureOptions);
901 HRESULT setVideoCaptureOptions(const com::Utf8Str &aVideoCaptureOptions);
902 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
903 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
904 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
905 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
906 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
907 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
908 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
909 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
910 HRESULT setHPETEnabled(BOOL aHPETEnabled);
911 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
912 HRESULT setChipsetType(ChipsetType_T aChipsetType);
913 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
914 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
915 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
916 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
917 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
918 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
919 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
920 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
921 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
922 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
923 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
924 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
925 HRESULT getSettingsModified(BOOL *aSettingsModified);
926 HRESULT getSessionState(SessionState_T *aSessionState);
927 HRESULT getSessionType(SessionType_T *aSessionType);
928 HRESULT getSessionName(com::Utf8Str &aSessionType);
929 HRESULT getSessionPID(ULONG *aSessionPID);
930 HRESULT getState(MachineState_T *aState);
931 HRESULT getLastStateChange(LONG64 *aLastStateChange);
932 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
933 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
934 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
935 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
936 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
937 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
938 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
939 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
940 HRESULT getDnDMode(DnDMode_T *aDnDMode);
941 HRESULT setDnDMode(DnDMode_T aDnDMode);
942 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
943 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
944 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
945 HRESULT setTeleporterPort(ULONG aTeleporterPort);
946 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
947 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
948 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
949 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
950 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
951 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
952 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
953 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
954 HRESULT getFaultToleranceState(FaultToleranceState_T *aFaultToleranceState);
955 HRESULT setFaultToleranceState(FaultToleranceState_T aFaultToleranceState);
956 HRESULT getFaultTolerancePort(ULONG *aFaultTolerancePort);
957 HRESULT setFaultTolerancePort(ULONG aFaultTolerancePort);
958 HRESULT getFaultToleranceAddress(com::Utf8Str &aFaultToleranceAddress);
959 HRESULT setFaultToleranceAddress(const com::Utf8Str &aFaultToleranceAddress);
960 HRESULT getFaultTolerancePassword(com::Utf8Str &aFaultTolerancePassword);
961 HRESULT setFaultTolerancePassword(const com::Utf8Str &aFaultTolerancePassword);
962 HRESULT getFaultToleranceSyncInterval(ULONG *aFaultToleranceSyncInterval);
963 HRESULT setFaultToleranceSyncInterval(ULONG aFaultToleranceSyncInterval);
964 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
965 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
966 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
967 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
968 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
969 HRESULT setIOCacheSize(ULONG aIOCacheSize);
970 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
971 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
972 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
973 HRESULT setTracingEnabled(BOOL aTracingEnabled);
974 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
975 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
976 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
977 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
978 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
979 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
980 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
981 HRESULT setAutostartDelay(ULONG aAutostartDelay);
982 HRESULT getAutostopType(AutostopType_T *aAutostopType);
983 HRESULT setAutostopType(AutostopType_T aAutostopType);
984 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
985 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
986 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
987 HRESULT getVMProcessPriority(com::Utf8Str &aVMProcessPriority);
988 HRESULT setVMProcessPriority(const com::Utf8Str &aVMProcessPriority);
989
990 // wrapped IMachine methods
991 HRESULT lockMachine(const ComPtr<ISession> &aSession,
992 LockType_T aLockType);
993 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
994 const com::Utf8Str &aType,
995 const com::Utf8Str &aEnvironment,
996 ComPtr<IProgress> &aProgress);
997 HRESULT setBootOrder(ULONG aPosition,
998 DeviceType_T aDevice);
999 HRESULT getBootOrder(ULONG aPosition,
1000 DeviceType_T *aDevice);
1001 HRESULT attachDevice(const com::Utf8Str &aName,
1002 LONG aControllerPort,
1003 LONG aDevice,
1004 DeviceType_T aType,
1005 const ComPtr<IMedium> &aMedium);
1006 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
1007 LONG aControllerPort,
1008 LONG aDevice,
1009 DeviceType_T aType);
1010 HRESULT detachDevice(const com::Utf8Str &aName,
1011 LONG aControllerPort,
1012 LONG aDevice);
1013 HRESULT passthroughDevice(const com::Utf8Str &aName,
1014 LONG aControllerPort,
1015 LONG aDevice,
1016 BOOL aPassthrough);
1017 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
1018 LONG aControllerPort,
1019 LONG aDevice,
1020 BOOL aTemporaryEject);
1021 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
1022 LONG aControllerPort,
1023 LONG aDevice,
1024 BOOL aNonRotational);
1025 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
1026 LONG aControllerPort,
1027 LONG aDevice,
1028 BOOL aDiscard);
1029 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
1030 LONG aControllerPort,
1031 LONG aDevice,
1032 BOOL aHotPluggable);
1033 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
1034 LONG aControllerPort,
1035 LONG aDevice,
1036 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
1037 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
1038 LONG aControllerPort,
1039 LONG aDevice);
1040 HRESULT unmountMedium(const com::Utf8Str &aName,
1041 LONG aControllerPort,
1042 LONG aDevice,
1043 BOOL aForce);
1044 HRESULT mountMedium(const com::Utf8Str &aName,
1045 LONG aControllerPort,
1046 LONG aDevice,
1047 const ComPtr<IMedium> &aMedium,
1048 BOOL aForce);
1049 HRESULT getMedium(const com::Utf8Str &aName,
1050 LONG aControllerPort,
1051 LONG aDevice,
1052 ComPtr<IMedium> &aMedium);
1053 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
1054 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
1055 HRESULT getMediumAttachment(const com::Utf8Str &aName,
1056 LONG aControllerPort,
1057 LONG aDevice,
1058 ComPtr<IMediumAttachment> &aAttachment);
1059 HRESULT attachHostPCIDevice(LONG aHostAddress,
1060 LONG aDesiredGuestAddress,
1061 BOOL aTryToUnbind);
1062 HRESULT detachHostPCIDevice(LONG aHostAddress);
1063 HRESULT getNetworkAdapter(ULONG aSlot,
1064 ComPtr<INetworkAdapter> &aAdapter);
1065 HRESULT addStorageController(const com::Utf8Str &aName,
1066 StorageBus_T aConnectionType,
1067 ComPtr<IStorageController> &aController);
1068 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1069 ComPtr<IStorageController> &aStorageController);
1070 HRESULT getStorageControllerByInstance(StorageBus_T aConnectionType,
1071 ULONG aInstance,
1072 ComPtr<IStorageController> &aStorageController);
1073 HRESULT removeStorageController(const com::Utf8Str &aName);
1074 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1075 BOOL aBootable);
1076 HRESULT addUSBController(const com::Utf8Str &aName,
1077 USBControllerType_T aType,
1078 ComPtr<IUSBController> &aController);
1079 HRESULT removeUSBController(const com::Utf8Str &aName);
1080 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1081 ComPtr<IUSBController> &aController);
1082 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1083 ULONG *aControllers);
1084 HRESULT getSerialPort(ULONG aSlot,
1085 ComPtr<ISerialPort> &aPort);
1086 HRESULT getParallelPort(ULONG aSlot,
1087 ComPtr<IParallelPort> &aPort);
1088 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1089 HRESULT getExtraData(const com::Utf8Str &aKey,
1090 com::Utf8Str &aValue);
1091 HRESULT setExtraData(const com::Utf8Str &aKey,
1092 const com::Utf8Str &aValue);
1093 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1094 BOOL *aValue);
1095 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1096 BOOL aValue);
1097 HRESULT getCPUIDLeafByOrdinal(ULONG aOrdinal,
1098 ULONG *aIdx,
1099 ULONG *aSubIdx,
1100 ULONG *aValEax,
1101 ULONG *aValEbx,
1102 ULONG *aValEcx,
1103 ULONG *aValEdx);
1104 HRESULT getCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1105 ULONG *aValEax,
1106 ULONG *aValEbx,
1107 ULONG *aValEcx,
1108 ULONG *aValEdx);
1109 HRESULT setCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1110 ULONG aValEax,
1111 ULONG aValEbx,
1112 ULONG aValEcx,
1113 ULONG aValEdx);
1114 HRESULT removeCPUIDLeaf(ULONG aIdx, ULONG aSubIdx);
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 moveTo(const com::Utf8Str &aTargetPath,
1197 const com::Utf8Str &aType,
1198 ComPtr<IProgress> &aProgress);
1199 HRESULT saveState(ComPtr<IProgress> &aProgress);
1200 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1201 HRESULT discardSavedState(BOOL aFRemoveFile);
1202 HRESULT takeSnapshot(const com::Utf8Str &aName,
1203 const com::Utf8Str &aDescription,
1204 BOOL aPause,
1205 com::Guid &aId,
1206 ComPtr<IProgress> &aProgress);
1207 HRESULT deleteSnapshot(const com::Guid &aId,
1208 ComPtr<IProgress> &aProgress);
1209 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1210 ComPtr<IProgress> &aProgress);
1211 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1212 const com::Guid &aEndId,
1213 ComPtr<IProgress> &aProgress);
1214 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1215 ComPtr<IProgress> &aProgress);
1216 HRESULT applyDefaults(const com::Utf8Str &aFlags);
1217
1218 // wrapped IInternalMachineControl properties
1219
1220 // wrapped IInternalMachineControl methods
1221 HRESULT updateState(MachineState_T aState);
1222 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1223 HRESULT endPowerUp(LONG aResult);
1224 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1225 HRESULT endPoweringDown(LONG aResult,
1226 const com::Utf8Str &aErrMsg);
1227 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1228 BOOL *aMatched,
1229 ULONG *aMaskedInterfaces);
1230 HRESULT captureUSBDevice(const com::Guid &aId,
1231 const com::Utf8Str &aCaptureFilename);
1232 HRESULT detachUSBDevice(const com::Guid &aId,
1233 BOOL aDone);
1234 HRESULT autoCaptureUSBDevices();
1235 HRESULT detachAllUSBDevices(BOOL aDone);
1236 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1237 ComPtr<IProgress> &aProgress);
1238 HRESULT finishOnlineMergeMedium();
1239 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1240 std::vector<com::Utf8Str> &aValues,
1241 std::vector<LONG64> &aTimestamps,
1242 std::vector<com::Utf8Str> &aFlags);
1243 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1244 const com::Utf8Str &aValue,
1245 LONG64 aTimestamp,
1246 const com::Utf8Str &aFlags);
1247 HRESULT lockMedia();
1248 HRESULT unlockMedia();
1249 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1250 ComPtr<IMediumAttachment> &aNewAttachment);
1251 HRESULT reportVmStatistics(ULONG aValidStats,
1252 ULONG aCpuUser,
1253 ULONG aCpuKernel,
1254 ULONG aCpuIdle,
1255 ULONG aMemTotal,
1256 ULONG aMemFree,
1257 ULONG aMemBalloon,
1258 ULONG aMemShared,
1259 ULONG aMemCache,
1260 ULONG aPagedTotal,
1261 ULONG aMemAllocTotal,
1262 ULONG aMemFreeTotal,
1263 ULONG aMemBalloonTotal,
1264 ULONG aMemSharedTotal,
1265 ULONG aVmNetRx,
1266 ULONG aVmNetTx);
1267 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1268 com::Utf8Str &aResult);
1269};
1270
1271// SessionMachine class
1272////////////////////////////////////////////////////////////////////////////////
1273
1274/**
1275 * @note Notes on locking objects of this class:
1276 * SessionMachine shares some data with the primary Machine instance (pointed
1277 * to by the |mPeer| member). In order to provide data consistency it also
1278 * shares its lock handle. This means that whenever you lock a SessionMachine
1279 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1280 * instance is also locked in the same lock mode. Keep it in mind.
1281 */
1282class ATL_NO_VTABLE SessionMachine :
1283 public Machine
1284{
1285public:
1286 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1287
1288 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1289
1290 DECLARE_PROTECT_FINAL_CONSTRUCT()
1291
1292 BEGIN_COM_MAP(SessionMachine)
1293 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1294 COM_INTERFACE_ENTRY(IMachine)
1295 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1296 COM_INTERFACE_ENTRY(IInternalMachineControl)
1297 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1298 END_COM_MAP()
1299
1300 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1301
1302 HRESULT FinalConstruct();
1303 void FinalRelease();
1304
1305 struct Uninit
1306 {
1307 enum Reason { Unexpected, Abnormal, Normal };
1308 };
1309
1310 // public initializer/uninitializer for internal purposes only
1311 HRESULT init(Machine *aMachine);
1312 void uninit() { uninit(Uninit::Unexpected); }
1313 void uninit(Uninit::Reason aReason);
1314
1315
1316 // util::Lockable interface
1317 RWLockHandle *lockHandle() const;
1318
1319 // public methods only for internal purposes
1320
1321 virtual bool i_isSessionMachine() const
1322 {
1323 return true;
1324 }
1325
1326#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1327 bool i_checkForDeath();
1328
1329 void i_getTokenId(Utf8Str &strTokenId);
1330#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1331 IToken *i_getToken();
1332#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1333 // getClientToken must be only used by callers who can guarantee that
1334 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1335 ClientToken *i_getClientToken();
1336
1337 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1338 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1339 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1340 IN_BSTR aGuestIp, LONG aGuestPort);
1341 HRESULT i_onStorageControllerChange();
1342 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1343 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1344 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1345 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1346 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1347 HRESULT i_onVRDEServerChange(BOOL aRestart);
1348 HRESULT i_onVideoCaptureChange();
1349 HRESULT i_onUSBControllerChange();
1350 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1351 IVirtualBoxErrorInfo *aError,
1352 ULONG aMaskedIfs,
1353 const com::Utf8Str &aCaptureFilename);
1354 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1355 IVirtualBoxErrorInfo *aError);
1356 HRESULT i_onSharedFolderChange();
1357 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1358 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1359 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1360 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1361 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1362
1363 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1364
1365 HRESULT i_lockMedia();
1366 HRESULT i_unlockMedia();
1367
1368 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1369
1370private:
1371
1372 // wrapped IInternalMachineControl properties
1373
1374 // wrapped IInternalMachineControl methods
1375 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1376 HRESULT updateState(MachineState_T aState);
1377 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1378 HRESULT endPowerUp(LONG aResult);
1379 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1380 HRESULT endPoweringDown(LONG aResult,
1381 const com::Utf8Str &aErrMsg);
1382 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1383 BOOL *aMatched,
1384 ULONG *aMaskedInterfaces);
1385 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1386 HRESULT detachUSBDevice(const com::Guid &aId,
1387 BOOL aDone);
1388 HRESULT autoCaptureUSBDevices();
1389 HRESULT detachAllUSBDevices(BOOL aDone);
1390 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1391 ComPtr<IProgress> &aProgress);
1392 HRESULT finishOnlineMergeMedium();
1393 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1394 std::vector<com::Utf8Str> &aValues,
1395 std::vector<LONG64> &aTimestamps,
1396 std::vector<com::Utf8Str> &aFlags);
1397 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1398 const com::Utf8Str &aValue,
1399 LONG64 aTimestamp,
1400 const com::Utf8Str &aFlags);
1401 HRESULT lockMedia();
1402 HRESULT unlockMedia();
1403 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1404 ComPtr<IMediumAttachment> &aNewAttachment);
1405 HRESULT reportVmStatistics(ULONG aValidStats,
1406 ULONG aCpuUser,
1407 ULONG aCpuKernel,
1408 ULONG aCpuIdle,
1409 ULONG aMemTotal,
1410 ULONG aMemFree,
1411 ULONG aMemBalloon,
1412 ULONG aMemShared,
1413 ULONG aMemCache,
1414 ULONG aPagedTotal,
1415 ULONG aMemAllocTotal,
1416 ULONG aMemFreeTotal,
1417 ULONG aMemBalloonTotal,
1418 ULONG aMemSharedTotal,
1419 ULONG aVmNetRx,
1420 ULONG aVmNetTx);
1421 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1422 com::Utf8Str &aResult);
1423
1424
1425 struct ConsoleTaskData
1426 {
1427 ConsoleTaskData()
1428 : mLastState(MachineState_Null),
1429 mDeleteSnapshotInfo(NULL)
1430 { }
1431
1432 MachineState_T mLastState;
1433 ComObjPtr<Progress> mProgress;
1434
1435 // used when deleting online snaphshot
1436 void *mDeleteSnapshotInfo;
1437 };
1438
1439 class SaveStateTask;
1440 class SnapshotTask;
1441 class TakeSnapshotTask;
1442 class DeleteSnapshotTask;
1443 class 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