VirtualBox

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

Last change on this file since 101505 was 101035, checked in by vboxsync, 15 months ago

Initial commit (based draft v2 / on patch v5) for implementing platform architecture support for x86 and ARM. bugref:10384

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