VirtualBox

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

Last change on this file since 94747 was 94747, checked in by vboxsync, 3 years ago

Main/MachineImpl: Implement a few more APIs for full VM encryption, bugref:9955

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