VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

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