VirtualBox

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

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

Recording: Settings handling fixes / overhaul. This adds the ability to handle per-screen settings, which can be different from the first screen (screen 0). Also fixed a couple of bugs regarding snapshot handling and persistence (committing, rolling back, ++) in that area. FE/VBoxManage now can also list the per-screen settings. Added some further @todos. bugref:9286

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.6 KB
Line 
1/* $Id: MachineImpl.h 95639 2022-07-14 08:30:45Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_MachineImpl_h
19#define MAIN_INCLUDED_MachineImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "AuthLibrary.h"
25#include "VirtualBoxBase.h"
26#include "ProgressImpl.h"
27#include "VRDEServerImpl.h"
28#include "MediumAttachmentImpl.h"
29#include "PCIDeviceAttachmentImpl.h"
30#include "MediumLock.h"
31#include "NetworkAdapterImpl.h"
32#include "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 const settings::RecordingSettings &recording);
683 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
684 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
685 HRESULT i_loadStorageControllers(const settings::Storage &data,
686 const Guid *puuidRegistry,
687 const Guid *puuidSnapshot);
688 HRESULT i_loadStorageDevices(StorageController *aStorageController,
689 const settings::StorageController &data,
690 const Guid *puuidRegistry,
691 const Guid *puuidSnapshot);
692
693 HRESULT i_findSnapshotById(const Guid &aId,
694 ComObjPtr<Snapshot> &aSnapshot,
695 bool aSetError = false);
696 HRESULT i_findSnapshotByName(const Utf8Str &strName,
697 ComObjPtr<Snapshot> &aSnapshot,
698 bool aSetError = false);
699
700 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
701
702 enum
703 {
704 /* flags for #saveSettings() */
705 SaveS_ResetCurStateModified = 0x01,
706 SaveS_Force = 0x04,
707 SaveS_RemoveBackup = 0x08,
708 /* flags for #saveStateSettings() */
709 SaveSTS_CurStateModified = 0x20,
710 SaveSTS_StateFilePath = 0x40,
711 SaveSTS_StateTimeStamp = 0x80
712 };
713
714 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings,
715 bool *pfSettingsFileIsNew);
716 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, AutoWriteLock &alock, int aFlags = 0);
717
718 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
719 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
720 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
721 settings::Autostart *pAutostart, settings::RecordingSettings &recording);
722 HRESULT i_saveStorageControllers(settings::Storage &data);
723 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
724 settings::StorageController &data);
725 HRESULT i_saveStateSettings(int aFlags);
726
727 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
728
729 HRESULT i_deleteFile(const Utf8Str &strFile, bool fIgnoreFailures = false, const Utf8Str &strWhat = "", int *prc = NULL);
730
731 HRESULT i_createImplicitDiffs(IProgress *aProgress,
732 ULONG aWeight,
733 bool aOnline);
734 HRESULT i_deleteImplicitDiffs(bool aOnline);
735
736 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
737 const Utf8Str &aControllerName,
738 LONG aControllerPort,
739 LONG aDevice);
740 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
741 ComObjPtr<Medium> pMedium);
742 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
743 Guid &id);
744
745 HRESULT i_detachDevice(MediumAttachment *pAttach,
746 AutoWriteLock &writeLock,
747 Snapshot *pSnapshot);
748
749 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
750 Snapshot *pSnapshot,
751 CleanupMode_T cleanupMode,
752 MediaList &llMedia);
753
754 void i_commitMedia(bool aOnline = false);
755 void i_rollbackMedia();
756
757 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
758
759 void i_rollback(bool aNotify);
760 void i_commit();
761 void i_copyFrom(Machine *aThat);
762 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
763
764 Utf8Str i_getExtraData(const Utf8Str &strKey);
765
766 com::Utf8Str i_controllerNameFromBusType(StorageBus_T aBusType);
767
768#ifdef VBOX_WITH_GUEST_PROPS
769 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
770 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
771 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
772 const com::Utf8Str &aFlags, bool fDelete);
773 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
774 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
775 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
776 const com::Utf8Str &aFlags, bool fDelete);
777 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
778 std::vector<com::Utf8Str> &aNames,
779 std::vector<com::Utf8Str> &aValues,
780 std::vector<LONG64> &aTimestamps,
781 std::vector<com::Utf8Str> &aFlags);
782 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
783 std::vector<com::Utf8Str> &aNames,
784 std::vector<com::Utf8Str> &aValues,
785 std::vector<LONG64> &aTimestamps,
786 std::vector<com::Utf8Str> &aFlags);
787
788#endif /* VBOX_WITH_GUEST_PROPS */
789
790#ifdef VBOX_WITH_RESOURCE_USAGE_API
791 void i_getDiskList(MediaList &list);
792 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
793
794 pm::CollectorGuest *mCollectorGuest;
795#endif /* VBOX_WITH_RESOURCE_USAGE_API */
796
797 Machine * const mPeer;
798
799 VirtualBox * const mParent;
800
801 Shareable<Data> mData;
802 Shareable<SSData> mSSData;
803
804 Backupable<UserData> mUserData;
805 Backupable<HWData> mHWData;
806
807 /**
808 * Hard disk and other media data.
809 *
810 * The usage policy is the same as for mHWData, but a separate field
811 * is necessary because hard disk data requires different procedures when
812 * taking or deleting snapshots, etc.
813 *
814 * @todo r=klaus change this to a regular list and use the normal way to
815 * handle the settings when creating a session or taking a snapshot.
816 * Same thing applies to mStorageControllers and mUSBControllers.
817 */
818 Backupable<MediumAttachmentList> mMediumAttachments;
819
820 // the following fields need special backup/rollback/commit handling,
821 // so they cannot be a part of HWData
822
823 const ComObjPtr<VRDEServer> mVRDEServer;
824 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
825 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
826 const ComObjPtr<AudioSettings> mAudioSettings;
827 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
828 const ComObjPtr<BIOSSettings> mBIOSSettings;
829 const ComObjPtr<RecordingSettings> mRecordingSettings;
830 const ComObjPtr<GraphicsAdapter> mGraphicsAdapter;
831 const ComObjPtr<BandwidthControl> mBandwidthControl;
832
833 const ComObjPtr<TrustedPlatformModule> mTrustedPlatformModule;
834 const ComObjPtr<NvramStore> mNvramStore;
835
836 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
837 NetworkAdapterVector mNetworkAdapters;
838
839 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
840 Backupable<StorageControllerList> mStorageControllers;
841
842 typedef std::list<ComObjPtr<USBController> > USBControllerList;
843 Backupable<USBControllerList> mUSBControllers;
844
845 uint64_t uRegistryNeedsSaving;
846
847 /**
848 * Abstract base class for all Machine or SessionMachine related
849 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
850 * a (non-static) method as its thread function, so instead we have it call
851 * the static Machine::taskHandler, which then calls the handler() method
852 * in here (implemented by the subclasses).
853 */
854 class Task : public ThreadTask
855 {
856 public:
857 Task(Machine *m, Progress *p, const Utf8Str &t)
858 : ThreadTask(t),
859 m_pMachine(m),
860 m_machineCaller(m),
861 m_pProgress(p),
862 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
863 {}
864 virtual ~Task(){}
865
866 void modifyBackedUpState(MachineState_T s)
867 {
868 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
869 }
870
871 ComObjPtr<Machine> m_pMachine;
872 AutoCaller m_machineCaller;
873 ComObjPtr<Progress> m_pProgress;
874 const MachineState_T m_machineStateBackup;
875 };
876
877 class DeleteConfigTask;
878 void i_deleteConfigHandler(DeleteConfigTask &task);
879
880#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
881 class ChangeEncryptionTask;
882 void i_changeEncryptionHandler(ChangeEncryptionTask &task);
883 HRESULT i_changeEncryptionForComponent(ChangeEncryptionTask &task, const com::Utf8Str strDirectory,
884 const com::Utf8Str strFilePattern, com::Utf8Str &strKeyStore,
885 com::Utf8Str &strKeyId, int iCipherMode);
886 int i_findFiles(std::list<com::Utf8Str> &lstFiles, const com::Utf8Str &strDir,
887 const com::Utf8Str &strPattern);
888 int i_createIoStreamForFile(const char *pszFilename, PCVBOXCRYPTOIF pCryptoIf,
889 const char *pszKeyStore, const char *pszPassword,
890 uint64_t fOpen, PRTVFSIOSTREAM phVfsIos);
891#endif
892
893 friend class Appliance;
894 friend class RecordingSettings;
895 friend class RecordingScreenSettings;
896 friend class SessionMachine;
897 friend class SnapshotMachine;
898 friend class VirtualBox;
899
900 friend class MachineCloneVM;
901 friend class MachineMoveVM;
902private:
903 // wrapped IMachine properties
904 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
905 HRESULT getIcon(std::vector<BYTE> &aIcon);
906 HRESULT setIcon(const std::vector<BYTE> &aIcon);
907 HRESULT getAccessible(BOOL *aAccessible);
908 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
909 HRESULT getName(com::Utf8Str &aName);
910 HRESULT setName(const com::Utf8Str &aName);
911 HRESULT getDescription(com::Utf8Str &aDescription);
912 HRESULT setDescription(const com::Utf8Str &aDescription);
913 HRESULT getId(com::Guid &aId);
914 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
915 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
916 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
917 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
918 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
919 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
920 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
921 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
922 HRESULT getCPUCount(ULONG *aCPUCount);
923 HRESULT setCPUCount(ULONG aCPUCount);
924 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
925 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
926 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
927 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
928 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
929 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
930 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
931 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
932 HRESULT getMemorySize(ULONG *aMemorySize);
933 HRESULT setMemorySize(ULONG aMemorySize);
934 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
935 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
936 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
937 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
938 HRESULT getGraphicsAdapter(ComPtr<IGraphicsAdapter> &aGraphicsAdapter);
939 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
940 HRESULT getTrustedPlatformModule(ComPtr<ITrustedPlatformModule> &aTrustedPlatformModule);
941 HRESULT getNonVolatileStore(ComPtr<INvramStore> &aNvramStore);
942 HRESULT getRecordingSettings(ComPtr<IRecordingSettings> &aRecordingSettings);
943 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
944 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
945 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
946 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
947 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
948 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
949 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
950 HRESULT setHPETEnabled(BOOL aHPETEnabled);
951 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
952 HRESULT setChipsetType(ChipsetType_T aChipsetType);
953 HRESULT getIommuType(IommuType_T *aIommuType);
954 HRESULT setIommuType(IommuType_T aIommuType);
955 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
956 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
957 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
958 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
959 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
960 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
961 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
962 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
963 HRESULT getAudioSettings(ComPtr<IAudioSettings> &aAudioSettings);
964 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
965 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
966 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
967 HRESULT getSettingsModified(BOOL *aSettingsModified);
968 HRESULT getSessionState(SessionState_T *aSessionState);
969 HRESULT getSessionType(SessionType_T *aSessionType);
970 HRESULT getSessionName(com::Utf8Str &aSessionType);
971 HRESULT getSessionPID(ULONG *aSessionPID);
972 HRESULT getState(MachineState_T *aState);
973 HRESULT getLastStateChange(LONG64 *aLastStateChange);
974 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
975 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
976 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
977 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
978 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
979 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
980 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
981 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
982 HRESULT getClipboardFileTransfersEnabled(BOOL *aEnabled);
983 HRESULT setClipboardFileTransfersEnabled(BOOL aEnabled);
984 HRESULT getDnDMode(DnDMode_T *aDnDMode);
985 HRESULT setDnDMode(DnDMode_T aDnDMode);
986 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
987 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
988 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
989 HRESULT setTeleporterPort(ULONG aTeleporterPort);
990 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
991 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
992 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
993 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
994 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
995 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
996 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
997 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
998 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
999 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
1000 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
1001 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
1002 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
1003 HRESULT setIOCacheSize(ULONG aIOCacheSize);
1004 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
1005 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
1006 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
1007 HRESULT setTracingEnabled(BOOL aTracingEnabled);
1008 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
1009 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
1010 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
1011 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
1012 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
1013 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
1014 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
1015 HRESULT setAutostartDelay(ULONG aAutostartDelay);
1016 HRESULT getAutostopType(AutostopType_T *aAutostopType);
1017 HRESULT setAutostopType(AutostopType_T aAutostopType);
1018 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
1019 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
1020 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
1021 HRESULT getVMProcessPriority(VMProcPriority_T *aVMProcessPriority);
1022 HRESULT setVMProcessPriority(VMProcPriority_T aVMProcessPriority);
1023 HRESULT getStateKeyId(com::Utf8Str &aKeyId);
1024 HRESULT getStateKeyStore(com::Utf8Str &aKeyStore);
1025 HRESULT getLogKeyId(com::Utf8Str &aKeyId);
1026 HRESULT getLogKeyStore(com::Utf8Str &aKeyStore);
1027
1028 // wrapped IMachine methods
1029 HRESULT lockMachine(const ComPtr<ISession> &aSession,
1030 LockType_T aLockType);
1031 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
1032 const com::Utf8Str &aType,
1033 const std::vector<com::Utf8Str> &aEnvironmentChanges,
1034 ComPtr<IProgress> &aProgress);
1035 HRESULT setBootOrder(ULONG aPosition,
1036 DeviceType_T aDevice);
1037 HRESULT getBootOrder(ULONG aPosition,
1038 DeviceType_T *aDevice);
1039 HRESULT attachDevice(const com::Utf8Str &aName,
1040 LONG aControllerPort,
1041 LONG aDevice,
1042 DeviceType_T aType,
1043 const ComPtr<IMedium> &aMedium);
1044 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
1045 LONG aControllerPort,
1046 LONG aDevice,
1047 DeviceType_T aType);
1048 HRESULT detachDevice(const com::Utf8Str &aName,
1049 LONG aControllerPort,
1050 LONG aDevice);
1051 HRESULT passthroughDevice(const com::Utf8Str &aName,
1052 LONG aControllerPort,
1053 LONG aDevice,
1054 BOOL aPassthrough);
1055 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
1056 LONG aControllerPort,
1057 LONG aDevice,
1058 BOOL aTemporaryEject);
1059 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
1060 LONG aControllerPort,
1061 LONG aDevice,
1062 BOOL aNonRotational);
1063 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
1064 LONG aControllerPort,
1065 LONG aDevice,
1066 BOOL aDiscard);
1067 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
1068 LONG aControllerPort,
1069 LONG aDevice,
1070 BOOL aHotPluggable);
1071 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
1072 LONG aControllerPort,
1073 LONG aDevice,
1074 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
1075 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
1076 LONG aControllerPort,
1077 LONG aDevice);
1078 HRESULT unmountMedium(const com::Utf8Str &aName,
1079 LONG aControllerPort,
1080 LONG aDevice,
1081 BOOL aForce);
1082 HRESULT mountMedium(const com::Utf8Str &aName,
1083 LONG aControllerPort,
1084 LONG aDevice,
1085 const ComPtr<IMedium> &aMedium,
1086 BOOL aForce);
1087 HRESULT getMedium(const com::Utf8Str &aName,
1088 LONG aControllerPort,
1089 LONG aDevice,
1090 ComPtr<IMedium> &aMedium);
1091 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
1092 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
1093 HRESULT getMediumAttachment(const com::Utf8Str &aName,
1094 LONG aControllerPort,
1095 LONG aDevice,
1096 ComPtr<IMediumAttachment> &aAttachment);
1097 HRESULT attachHostPCIDevice(LONG aHostAddress,
1098 LONG aDesiredGuestAddress,
1099 BOOL aTryToUnbind);
1100 HRESULT detachHostPCIDevice(LONG aHostAddress);
1101 HRESULT getNetworkAdapter(ULONG aSlot,
1102 ComPtr<INetworkAdapter> &aAdapter);
1103 HRESULT addStorageController(const com::Utf8Str &aName,
1104 StorageBus_T aConnectionType,
1105 ComPtr<IStorageController> &aController);
1106 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1107 ComPtr<IStorageController> &aStorageController);
1108 HRESULT getStorageControllerByInstance(StorageBus_T aConnectionType,
1109 ULONG aInstance,
1110 ComPtr<IStorageController> &aStorageController);
1111 HRESULT removeStorageController(const com::Utf8Str &aName);
1112 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1113 BOOL aBootable);
1114 HRESULT addUSBController(const com::Utf8Str &aName,
1115 USBControllerType_T aType,
1116 ComPtr<IUSBController> &aController);
1117 HRESULT removeUSBController(const com::Utf8Str &aName);
1118 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1119 ComPtr<IUSBController> &aController);
1120 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1121 ULONG *aControllers);
1122 HRESULT getSerialPort(ULONG aSlot,
1123 ComPtr<ISerialPort> &aPort);
1124 HRESULT getParallelPort(ULONG aSlot,
1125 ComPtr<IParallelPort> &aPort);
1126 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1127 HRESULT getExtraData(const com::Utf8Str &aKey,
1128 com::Utf8Str &aValue);
1129 HRESULT setExtraData(const com::Utf8Str &aKey,
1130 const com::Utf8Str &aValue);
1131 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1132 BOOL *aValue);
1133 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1134 BOOL aValue);
1135 HRESULT getCPUIDLeafByOrdinal(ULONG aOrdinal,
1136 ULONG *aIdx,
1137 ULONG *aSubIdx,
1138 ULONG *aValEax,
1139 ULONG *aValEbx,
1140 ULONG *aValEcx,
1141 ULONG *aValEdx);
1142 HRESULT getCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1143 ULONG *aValEax,
1144 ULONG *aValEbx,
1145 ULONG *aValEcx,
1146 ULONG *aValEdx);
1147 HRESULT setCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1148 ULONG aValEax,
1149 ULONG aValEbx,
1150 ULONG aValEcx,
1151 ULONG aValEdx);
1152 HRESULT removeCPUIDLeaf(ULONG aIdx, ULONG aSubIdx);
1153 HRESULT removeAllCPUIDLeaves();
1154 HRESULT getHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1155 BOOL *aValue);
1156 HRESULT setHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1157 BOOL aValue);
1158 HRESULT setSettingsFilePath(const com::Utf8Str &aSettingsFilePath,
1159 ComPtr<IProgress> &aProgress);
1160 HRESULT saveSettings();
1161 HRESULT discardSettings();
1162 HRESULT unregister(AutoCaller &aAutoCaller,
1163 CleanupMode_T aCleanupMode,
1164 std::vector<ComPtr<IMedium> > &aMedia);
1165 HRESULT deleteConfig(const std::vector<ComPtr<IMedium> > &aMedia,
1166 ComPtr<IProgress> &aProgress);
1167 HRESULT exportTo(const ComPtr<IAppliance> &aAppliance,
1168 const com::Utf8Str &aLocation,
1169 ComPtr<IVirtualSystemDescription> &aDescription);
1170 HRESULT findSnapshot(const com::Utf8Str &aNameOrId,
1171 ComPtr<ISnapshot> &aSnapshot);
1172 HRESULT createSharedFolder(const com::Utf8Str &aName,
1173 const com::Utf8Str &aHostPath,
1174 BOOL aWritable,
1175 BOOL aAutomount,
1176 const com::Utf8Str &aAutoMountPoint);
1177 HRESULT removeSharedFolder(const com::Utf8Str &aName);
1178 HRESULT canShowConsoleWindow(BOOL *aCanShow);
1179 HRESULT showConsoleWindow(LONG64 *aWinId);
1180 HRESULT getGuestProperty(const com::Utf8Str &aName,
1181 com::Utf8Str &aValue,
1182 LONG64 *aTimestamp,
1183 com::Utf8Str &aFlags);
1184 HRESULT getGuestPropertyValue(const com::Utf8Str &aProperty,
1185 com::Utf8Str &aValue);
1186 HRESULT getGuestPropertyTimestamp(const com::Utf8Str &aProperty,
1187 LONG64 *aValue);
1188 HRESULT setGuestProperty(const com::Utf8Str &aProperty,
1189 const com::Utf8Str &aValue,
1190 const com::Utf8Str &aFlags);
1191 HRESULT setGuestPropertyValue(const com::Utf8Str &aProperty,
1192 const com::Utf8Str &aValue);
1193 HRESULT deleteGuestProperty(const com::Utf8Str &aName);
1194 HRESULT enumerateGuestProperties(const com::Utf8Str &aPatterns,
1195 std::vector<com::Utf8Str> &aNames,
1196 std::vector<com::Utf8Str> &aValues,
1197 std::vector<LONG64> &aTimestamps,
1198 std::vector<com::Utf8Str> &aFlags);
1199 HRESULT querySavedGuestScreenInfo(ULONG aScreenId,
1200 ULONG *aOriginX,
1201 ULONG *aOriginY,
1202 ULONG *aWidth,
1203 ULONG *aHeight,
1204 BOOL *aEnabled);
1205 HRESULT readSavedThumbnailToArray(ULONG aScreenId,
1206 BitmapFormat_T aBitmapFormat,
1207 ULONG *aWidth,
1208 ULONG *aHeight,
1209 std::vector<BYTE> &aData);
1210 HRESULT querySavedScreenshotInfo(ULONG aScreenId,
1211 ULONG *aWidth,
1212 ULONG *aHeight,
1213 std::vector<BitmapFormat_T> &aBitmapFormats);
1214 HRESULT readSavedScreenshotToArray(ULONG aScreenId,
1215 BitmapFormat_T aBitmapFormat,
1216 ULONG *aWidth,
1217 ULONG *aHeight,
1218 std::vector<BYTE> &aData);
1219
1220 HRESULT hotPlugCPU(ULONG aCpu);
1221 HRESULT hotUnplugCPU(ULONG aCpu);
1222 HRESULT getCPUStatus(ULONG aCpu,
1223 BOOL *aAttached);
1224 HRESULT getEffectiveParavirtProvider(ParavirtProvider_T *aParavirtProvider);
1225 HRESULT queryLogFilename(ULONG aIdx,
1226 com::Utf8Str &aFilename);
1227 HRESULT readLog(ULONG aIdx,
1228 LONG64 aOffset,
1229 LONG64 aSize,
1230 std::vector<BYTE> &aData);
1231 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1232 CloneMode_T aMode,
1233 const std::vector<CloneOptions_T> &aOptions,
1234 ComPtr<IProgress> &aProgress);
1235 HRESULT moveTo(const com::Utf8Str &aTargetPath,
1236 const com::Utf8Str &aType,
1237 ComPtr<IProgress> &aProgress);
1238 HRESULT saveState(ComPtr<IProgress> &aProgress);
1239 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1240 HRESULT discardSavedState(BOOL aFRemoveFile);
1241 HRESULT takeSnapshot(const com::Utf8Str &aName,
1242 const com::Utf8Str &aDescription,
1243 BOOL aPause,
1244 com::Guid &aId,
1245 ComPtr<IProgress> &aProgress);
1246 HRESULT deleteSnapshot(const com::Guid &aId,
1247 ComPtr<IProgress> &aProgress);
1248 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1249 ComPtr<IProgress> &aProgress);
1250 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1251 const com::Guid &aEndId,
1252 ComPtr<IProgress> &aProgress);
1253 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1254 ComPtr<IProgress> &aProgress);
1255 HRESULT applyDefaults(const com::Utf8Str &aFlags);
1256 HRESULT changeEncryption(const com::Utf8Str &aCurrentPassword,
1257 const com::Utf8Str &aCipher,
1258 const com::Utf8Str &aNewPassword,
1259 const com::Utf8Str &aNewPasswordId,
1260 BOOL aForce,
1261 ComPtr<IProgress> &aProgress);
1262 HRESULT getEncryptionSettings(com::Utf8Str &aCipher,
1263 com::Utf8Str &aPasswordId);
1264 HRESULT checkEncryptionPassword(const com::Utf8Str &aPassword);
1265 HRESULT addEncryptionPassword(const com::Utf8Str &aId,
1266 const com::Utf8Str &aPassword);
1267 HRESULT addEncryptionPasswords(const std::vector<com::Utf8Str> &aIds,
1268 const std::vector<com::Utf8Str> &aPasswords);
1269 HRESULT removeEncryptionPassword(AutoCaller &autoCaller,
1270 const com::Utf8Str &aId);
1271 HRESULT clearAllEncryptionPasswords(AutoCaller &autoCaller);
1272
1273 // wrapped IInternalMachineControl properties
1274
1275 // wrapped IInternalMachineControl methods
1276 HRESULT updateState(MachineState_T aState);
1277 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1278 HRESULT endPowerUp(LONG aResult);
1279 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1280 HRESULT endPoweringDown(LONG aResult,
1281 const com::Utf8Str &aErrMsg);
1282 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1283 BOOL *aMatched,
1284 ULONG *aMaskedInterfaces);
1285 HRESULT captureUSBDevice(const com::Guid &aId,
1286 const com::Utf8Str &aCaptureFilename);
1287 HRESULT detachUSBDevice(const com::Guid &aId,
1288 BOOL aDone);
1289 HRESULT autoCaptureUSBDevices();
1290 HRESULT detachAllUSBDevices(BOOL aDone);
1291 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1292 ComPtr<IProgress> &aProgress);
1293 HRESULT finishOnlineMergeMedium();
1294 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1295 std::vector<com::Utf8Str> &aValues,
1296 std::vector<LONG64> &aTimestamps,
1297 std::vector<com::Utf8Str> &aFlags);
1298 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1299 const com::Utf8Str &aValue,
1300 LONG64 aTimestamp,
1301 const com::Utf8Str &aFlags,
1302 BOOL fWasDeleted);
1303 HRESULT lockMedia();
1304 HRESULT unlockMedia();
1305 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1306 ComPtr<IMediumAttachment> &aNewAttachment);
1307 HRESULT reportVmStatistics(ULONG aValidStats,
1308 ULONG aCpuUser,
1309 ULONG aCpuKernel,
1310 ULONG aCpuIdle,
1311 ULONG aMemTotal,
1312 ULONG aMemFree,
1313 ULONG aMemBalloon,
1314 ULONG aMemShared,
1315 ULONG aMemCache,
1316 ULONG aPagedTotal,
1317 ULONG aMemAllocTotal,
1318 ULONG aMemFreeTotal,
1319 ULONG aMemBalloonTotal,
1320 ULONG aMemSharedTotal,
1321 ULONG aVmNetRx,
1322 ULONG aVmNetTx);
1323 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1324 com::Utf8Str &aResult);
1325
1326#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1327 HRESULT i_setInaccessible(void);
1328#endif
1329};
1330
1331// SessionMachine class
1332////////////////////////////////////////////////////////////////////////////////
1333
1334/**
1335 * @note Notes on locking objects of this class:
1336 * SessionMachine shares some data with the primary Machine instance (pointed
1337 * to by the |mPeer| member). In order to provide data consistency it also
1338 * shares its lock handle. This means that whenever you lock a SessionMachine
1339 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1340 * instance is also locked in the same lock mode. Keep it in mind.
1341 */
1342class ATL_NO_VTABLE SessionMachine :
1343 public Machine
1344{
1345public:
1346 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1347
1348 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1349
1350 DECLARE_PROTECT_FINAL_CONSTRUCT()
1351
1352 BEGIN_COM_MAP(SessionMachine)
1353 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1354 COM_INTERFACE_ENTRY(IMachine)
1355 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1356 COM_INTERFACE_ENTRY(IInternalMachineControl)
1357 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1358 END_COM_MAP()
1359
1360 DECLARE_COMMON_CLASS_METHODS(SessionMachine)
1361
1362 HRESULT FinalConstruct();
1363 void FinalRelease();
1364
1365 struct Uninit
1366 {
1367 enum Reason { Unexpected, Abnormal, Normal };
1368 };
1369
1370 // public initializer/uninitializer for internal purposes only
1371 HRESULT init(Machine *aMachine);
1372 void uninit() { uninit(Uninit::Unexpected); }
1373 void uninit(Uninit::Reason aReason);
1374
1375
1376 // util::Lockable interface
1377 RWLockHandle *lockHandle() const;
1378
1379 // public methods only for internal purposes
1380
1381 virtual bool i_isSessionMachine() const
1382 {
1383 return true;
1384 }
1385
1386#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1387 bool i_checkForDeath();
1388
1389 void i_getTokenId(Utf8Str &strTokenId);
1390#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1391 IToken *i_getToken();
1392#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1393 // getClientToken must be only used by callers who can guarantee that
1394 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1395 ClientToken *i_getClientToken();
1396
1397 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1398 HRESULT i_onNATRedirectRuleChanged(ULONG ulSlot, BOOL aNatRuleRemove, const Utf8Str &aRuleName,
1399 NATProtocol_T aProto, const Utf8Str &aHostIp, LONG aHostPort,
1400 const Utf8Str &aGuestIp, LONG aGuestPort) RT_OVERRIDE;
1401 HRESULT i_onStorageControllerChange(const com::Guid &aMachineId, const com::Utf8Str &aControllerName);
1402 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1403 HRESULT i_onVMProcessPriorityChange(VMProcPriority_T aPriority);
1404 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1405 HRESULT i_onHostAudioDeviceChange(IHostAudioDevice *aDevice, BOOL aNew, AudioDeviceState_T aState, IVirtualBoxErrorInfo *aErrInfo);
1406 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1407 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1408 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1409 HRESULT i_onVRDEServerChange(BOOL aRestart);
1410 HRESULT i_onRecordingChange(BOOL aEnable);
1411 HRESULT i_onUSBControllerChange();
1412 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1413 IVirtualBoxErrorInfo *aError,
1414 ULONG aMaskedIfs,
1415 const com::Utf8Str &aCaptureFilename);
1416 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1417 IVirtualBoxErrorInfo *aError);
1418 HRESULT i_onSharedFolderChange();
1419 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1420 HRESULT i_onClipboardFileTransferModeChange(BOOL aEnable);
1421 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1422 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1423 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1424 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1425
1426 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1427
1428 HRESULT i_lockMedia();
1429 HRESULT i_unlockMedia();
1430
1431 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1432
1433private:
1434
1435 // wrapped IInternalMachineControl properties
1436
1437 // wrapped IInternalMachineControl methods
1438 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1439 HRESULT updateState(MachineState_T aState);
1440 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1441 HRESULT endPowerUp(LONG aResult);
1442 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1443 HRESULT endPoweringDown(LONG aResult,
1444 const com::Utf8Str &aErrMsg);
1445 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1446 BOOL *aMatched,
1447 ULONG *aMaskedInterfaces);
1448 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1449 HRESULT detachUSBDevice(const com::Guid &aId,
1450 BOOL aDone);
1451 HRESULT autoCaptureUSBDevices();
1452 HRESULT detachAllUSBDevices(BOOL aDone);
1453 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1454 ComPtr<IProgress> &aProgress);
1455 HRESULT finishOnlineMergeMedium();
1456 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1457 std::vector<com::Utf8Str> &aValues,
1458 std::vector<LONG64> &aTimestamps,
1459 std::vector<com::Utf8Str> &aFlags);
1460 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1461 const com::Utf8Str &aValue,
1462 LONG64 aTimestamp,
1463 const com::Utf8Str &aFlags,
1464 BOOL fWasDeleted);
1465 HRESULT lockMedia();
1466 HRESULT unlockMedia();
1467 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1468 ComPtr<IMediumAttachment> &aNewAttachment);
1469 HRESULT reportVmStatistics(ULONG aValidStats,
1470 ULONG aCpuUser,
1471 ULONG aCpuKernel,
1472 ULONG aCpuIdle,
1473 ULONG aMemTotal,
1474 ULONG aMemFree,
1475 ULONG aMemBalloon,
1476 ULONG aMemShared,
1477 ULONG aMemCache,
1478 ULONG aPagedTotal,
1479 ULONG aMemAllocTotal,
1480 ULONG aMemFreeTotal,
1481 ULONG aMemBalloonTotal,
1482 ULONG aMemSharedTotal,
1483 ULONG aVmNetRx,
1484 ULONG aVmNetTx);
1485 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1486 com::Utf8Str &aResult);
1487
1488
1489 struct ConsoleTaskData
1490 {
1491 ConsoleTaskData()
1492 : mLastState(MachineState_Null),
1493 mDeleteSnapshotInfo(NULL)
1494 { }
1495
1496 MachineState_T mLastState;
1497 ComObjPtr<Progress> mProgress;
1498
1499 // used when deleting online snaphshot
1500 void *mDeleteSnapshotInfo;
1501 };
1502
1503 class SaveStateTask;
1504 class SnapshotTask;
1505 class TakeSnapshotTask;
1506 class DeleteSnapshotTask;
1507 class RestoreSnapshotTask;
1508
1509 void i_saveStateHandler(SaveStateTask &aTask);
1510
1511 // Override some functionality for SessionMachine, this is where the
1512 // real action happens (the Machine methods are just dummies).
1513 HRESULT saveState(ComPtr<IProgress> &aProgress);
1514 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1515 HRESULT discardSavedState(BOOL aFRemoveFile);
1516 HRESULT takeSnapshot(const com::Utf8Str &aName,
1517 const com::Utf8Str &aDescription,
1518 BOOL aPause,
1519 com::Guid &aId,
1520 ComPtr<IProgress> &aProgress);
1521 HRESULT deleteSnapshot(const com::Guid &aId,
1522 ComPtr<IProgress> &aProgress);
1523 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1524 ComPtr<IProgress> &aProgress);
1525 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1526 const com::Guid &aEndId,
1527 ComPtr<IProgress> &aProgress);
1528 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1529 ComPtr<IProgress> &aProgress);
1530
1531 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1532
1533 void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
1534 static void i_takeSnapshotProgressCancelCallback(void *pvUser);
1535 HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
1536 HRESULT i_deleteSnapshot(const com::Guid &aStartId,
1537 const com::Guid &aEndId,
1538 BOOL aDeleteAllChildren,
1539 ComPtr<IProgress> &aProgress);
1540 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1541 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1542
1543 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1544 const Guid &machineId,
1545 const Guid &snapshotId,
1546 bool fOnlineMergePossible,
1547 MediumLockList *aVMMALockList,
1548 ComObjPtr<Medium> &aSource,
1549 ComObjPtr<Medium> &aTarget,
1550 bool &fMergeForward,
1551 ComObjPtr<Medium> &pParentForTarget,
1552 MediumLockList * &aChildrenToReparent,
1553 bool &fNeedOnlineMerge,
1554 MediumLockList * &aMediumLockList,
1555 ComPtr<IToken> &aHDLockToken);
1556 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1557 const ComObjPtr<Medium> &aSource,
1558 MediumLockList *aChildrenToReparent,
1559 bool fNeedsOnlineMerge,
1560 MediumLockList *aMediumLockList,
1561 const ComPtr<IToken> &aHDLockToken,
1562 const Guid &aMediumId,
1563 const Guid &aSnapshotId);
1564 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1565 const ComObjPtr<Medium> &aSource,
1566 const ComObjPtr<Medium> &aTarget,
1567 bool fMergeForward,
1568 const ComObjPtr<Medium> &pParentForTarget,
1569 MediumLockList *aChildrenToReparent,
1570 MediumLockList *aMediumLockList,
1571 ComObjPtr<Progress> &aProgress,
1572 bool *pfNeedsMachineSaveSettings);
1573
1574 HRESULT i_setMachineState(MachineState_T aMachineState);
1575 HRESULT i_updateMachineStateOnClient();
1576
1577 bool mRemoveSavedState;
1578
1579 ConsoleTaskData mConsoleTaskData;
1580
1581 /** client token for this machine */
1582 ClientToken *mClientToken;
1583
1584 int miNATNetworksStarted;
1585
1586 AUTHLIBRARYCONTEXT mAuthLibCtx;
1587};
1588
1589// SnapshotMachine class
1590////////////////////////////////////////////////////////////////////////////////
1591
1592/**
1593 * @note Notes on locking objects of this class:
1594 * SnapshotMachine shares some data with the primary Machine instance (pointed
1595 * to by the |mPeer| member). In order to provide data consistency it also
1596 * shares its lock handle. This means that whenever you lock a SessionMachine
1597 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1598 * instance is also locked in the same lock mode. Keep it in mind.
1599 */
1600class ATL_NO_VTABLE SnapshotMachine :
1601 public Machine
1602{
1603public:
1604 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1605
1606 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1607
1608 DECLARE_PROTECT_FINAL_CONSTRUCT()
1609
1610 BEGIN_COM_MAP(SnapshotMachine)
1611 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1612 COM_INTERFACE_ENTRY(IMachine)
1613 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1614 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1615 END_COM_MAP()
1616
1617 DECLARE_COMMON_CLASS_METHODS(SnapshotMachine)
1618
1619 HRESULT FinalConstruct();
1620 void FinalRelease();
1621
1622 // public initializer/uninitializer for internal purposes only
1623 HRESULT init(SessionMachine *aSessionMachine,
1624 IN_GUID aSnapshotId,
1625 const Utf8Str &aStateFilePath);
1626 HRESULT initFromSettings(Machine *aMachine,
1627 const settings::Hardware &hardware,
1628 const settings::Debugging *pDbg,
1629 const settings::Autostart *pAutostart,
1630 const settings::RecordingSettings &recording,
1631 IN_GUID aSnapshotId,
1632 const Utf8Str &aStateFilePath);
1633 void uninit();
1634
1635 // util::Lockable interface
1636 RWLockHandle *lockHandle() const;
1637
1638 // public methods only for internal purposes
1639
1640 virtual bool i_isSnapshotMachine() const
1641 {
1642 return true;
1643 }
1644
1645 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1646
1647 // unsafe inline public methods for internal purposes only (ensure there is
1648 // a caller and a read lock before calling them!)
1649
1650 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1651
1652private:
1653
1654 Guid mSnapshotId;
1655 /** This field replaces mPeer for SessionMachine instances, as having
1656 * a peer reference is plain meaningless and causes many subtle problems
1657 * with saving settings and the like. */
1658 Machine * const mMachine;
1659
1660 friend class Snapshot;
1661};
1662
1663// third party methods that depend on SnapshotMachine definition
1664
1665inline const Guid &Machine::i_getSnapshotId() const
1666{
1667 return (i_isSnapshotMachine())
1668 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1669 : Guid::Empty;
1670}
1671
1672
1673#endif /* !MAIN_INCLUDED_MachineImpl_h */
1674/* 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