VirtualBox

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

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

Audio/Main: Bigger revamp of the audio interface(s) to later also support host audio device enumeration and selection for individual VMs. The audio settings now live in a dedicated (per-VM) IAudioSettings interface (audio adapter + audio host device stuff), to further tidy up the IMachine interface. Also added stubs for IAudioDevice + IHostAudioDevice, plus enmuerations, left for further implementation. Added a new IHostAudioDeviceChangedEvent that can also be used later by API clients. bugref:10050

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