VirtualBox

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

Last change on this file since 107044 was 106516, checked in by vboxsync, 5 weeks ago

Main,settings.h: Workarounds for a handful warnings about default copy constructors & default copy assignment operators due to user defined destructors. jiraref:VBP-1171

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