VirtualBox

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

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

Main/Machine+BIOSSettings: simplify NVRAM handling, do everything in backwards c
ompatible way
Frontends/VBoxManage: adapt to API change

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette