VirtualBox

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

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

src/VBox/Main/include/MachineImpl[.h|.cpp]: Fixed warnings found by Parfait (uninitialized attributes). Left a @todo. jiraref:VBP-1424

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