VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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