VirtualBox

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

最後變更 在這個檔案從81425是 81425,由 vboxsync 提交於 5 年 前

Main/Machine+BIOSSettings+Console: Full implementation of NVRAM handling (part of VM delete, rename, clone and move code in combination with taking, deleting and restoring snapshots). Corresponding console update (ripping out old, never really used NVRAM handling).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 69.6 KB
 
1/* $Id: MachineImpl.h 81425 2019-10-21 18:19:39Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_MachineImpl_h
19#define MAIN_INCLUDED_MachineImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "AuthLibrary.h"
25#include "VirtualBoxBase.h"
26#include "SnapshotImpl.h"
27#include "ProgressImpl.h"
28#include "VRDEServerImpl.h"
29#include "MediumAttachmentImpl.h"
30#include "PCIDeviceAttachmentImpl.h"
31#include "MediumLock.h"
32#include "NetworkAdapterImpl.h"
33#include "AudioAdapterImpl.h"
34#include "SerialPortImpl.h"
35#include "ParallelPortImpl.h"
36#include "BIOSSettingsImpl.h"
37#include "RecordingSettingsImpl.h"
38#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
39#include "USBControllerImpl.h" // required for MachineImpl.h to compile on Windows
40#include "BandwidthControlImpl.h"
41#include "BandwidthGroupImpl.h"
42#ifdef VBOX_WITH_RESOURCE_USAGE_API
43# include "Performance.h"
44# include "PerformanceImpl.h"
45# include "ThreadTask.h"
46#endif
47#ifdef VBOX_WITH_CLOUD_NET
48# include "CloudNetworkImpl.h"
49# include "CloudGateway.h"
50#endif /* VBOX_WITH_CLOUD_NET */
51
52// generated header
53#include "SchemaDefs.h"
54
55#include "VBox/com/ErrorInfo.h"
56
57#include <iprt/file.h>
58#include <iprt/thread.h>
59#include <iprt/time.h>
60
61#include <list>
62#include <vector>
63
64#include "MachineWrap.h"
65
66/** @todo r=klaus after moving the various Machine settings structs to
67 * MachineImpl.cpp it should be possible to eliminate this include. */
68#include <VBox/settings.h>
69
70// defines
71////////////////////////////////////////////////////////////////////////////////
72
73// helper declarations
74////////////////////////////////////////////////////////////////////////////////
75
76class Progress;
77class ProgressProxy;
78class Keyboard;
79class Mouse;
80class Display;
81class MachineDebugger;
82class USBController;
83class USBDeviceFilters;
84class Snapshot;
85class SharedFolder;
86class HostUSBDevice;
87class StorageController;
88class SessionMachine;
89#ifdef VBOX_WITH_UNATTENDED
90class Unattended;
91#endif
92
93// Machine class
94////////////////////////////////////////////////////////////////////////////////
95//
96class ATL_NO_VTABLE Machine :
97 public MachineWrap
98{
99
100public:
101
102 enum StateDependency
103 {
104 AnyStateDep = 0,
105 MutableStateDep,
106 MutableOrSavedStateDep,
107 MutableOrRunningStateDep,
108 MutableOrSavedOrRunningStateDep,
109 };
110
111 /**
112 * Internal machine data.
113 *
114 * Only one instance of this data exists per every machine -- it is shared
115 * by the Machine, SessionMachine and all SnapshotMachine instances
116 * associated with the given machine using the util::Shareable template
117 * through the mData variable.
118 *
119 * @note |const| members are persistent during lifetime so can be
120 * accessed without locking.
121 *
122 * @note There is no need to lock anything inside init() or uninit()
123 * methods, because they are always serialized (see AutoCaller).
124 */
125 struct Data
126 {
127 /**
128 * Data structure to hold information about sessions opened for the
129 * given machine.
130 */
131 struct Session
132 {
133 /** Type of lock which created this session */
134 LockType_T mLockType;
135
136 /** Control of the direct session opened by lockMachine() */
137 ComPtr<IInternalSessionControl> mDirectControl;
138
139 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
140
141 /** list of controls of all opened remote sessions */
142 RemoteControlList mRemoteControls;
143
144 /** launchVMProcess() and OnSessionEnd() progress indicator */
145 ComObjPtr<ProgressProxy> mProgress;
146
147 /**
148 * PID of the session object that must be passed to openSession()
149 * to finalize the launchVMProcess() request (i.e., PID of the
150 * process created by launchVMProcess())
151 */
152 RTPROCESS mPID;
153
154 /** Current session state */
155 SessionState_T mState;
156
157 /** Session name string (of the primary session) */
158 Utf8Str mName;
159
160 /** Session machine object */
161 ComObjPtr<SessionMachine> mMachine;
162
163 /** Medium object lock collection. */
164 MediumLockListMap mLockedMedia;
165 };
166
167 Data();
168 ~Data();
169
170 const Guid mUuid;
171 BOOL mRegistered;
172
173 Utf8Str m_strConfigFile;
174 Utf8Str m_strConfigFileFull;
175
176 // machine settings XML file
177 settings::MachineConfigFile *pMachineConfigFile;
178 uint32_t flModifications;
179 bool m_fAllowStateModification;
180
181 BOOL mAccessible;
182 com::ErrorInfo mAccessError;
183
184 MachineState_T mMachineState;
185 RTTIMESPEC mLastStateChange;
186
187 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
188 uint32_t mMachineStateDeps;
189 RTSEMEVENTMULTI mMachineStateDepsSem;
190 uint32_t mMachineStateChangePending;
191
192 BOOL mCurrentStateModified;
193 /** Guest properties have been modified and need saving since the
194 * machine was started, or there are transient properties which need
195 * deleting and the machine is being shut down. */
196 BOOL mGuestPropertiesModified;
197
198 Session mSession;
199
200 ComObjPtr<Snapshot> mFirstSnapshot;
201 ComObjPtr<Snapshot> mCurrentSnapshot;
202
203 // list of files to delete in Delete(); this list is filled by Unregister()
204 std::list<Utf8Str> llFilesToDelete;
205
206#ifdef VBOX_WITH_CLOUD_NET
207 GatewayInfo mGatewayInfo;
208#endif /* VBOX_WITH_CLOUD_NET */
209};
210
211 /**
212 * Saved state data.
213 *
214 * It's actually only the state file path string, but it needs to be
215 * separate from Data, because Machine and SessionMachine instances
216 * share it, while SnapshotMachine does not.
217 *
218 * The data variable is |mSSData|.
219 */
220 struct SSData
221 {
222 Utf8Str strStateFilePath;
223 };
224
225 /**
226 * User changeable machine data.
227 *
228 * This data is common for all machine snapshots, i.e. it is shared
229 * by all SnapshotMachine instances associated with the given machine
230 * using the util::Backupable template through the |mUserData| variable.
231 *
232 * SessionMachine instances can alter this data and discard changes.
233 *
234 * @note There is no need to lock anything inside init() or uninit()
235 * methods, because they are always serialized (see AutoCaller).
236 */
237 struct UserData
238 {
239 settings::MachineUserData s;
240 };
241
242 /**
243 * Hardware data.
244 *
245 * This data is unique for a machine and for every machine snapshot.
246 * Stored using the util::Backupable template in the |mHWData| variable.
247 *
248 * SessionMachine instances can alter this data and discard changes.
249 *
250 * @todo r=klaus move all "pointer" objects out of this struct, as they
251 * need non-obvious handling when creating a new session or when taking
252 * a snapshot. Better do this right straight away, not relying on the
253 * template magic which doesn't work right in this case.
254 */
255 struct HWData
256 {
257 /**
258 * Data structure to hold information about a guest property.
259 */
260 struct GuestProperty {
261 /** Property value */
262 Utf8Str strValue;
263 /** Property timestamp */
264 LONG64 mTimestamp;
265 /** Property flags */
266 ULONG mFlags;
267 };
268
269 HWData();
270 ~HWData();
271
272 Bstr mHWVersion;
273 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
274 ULONG mMemorySize;
275 ULONG mMemoryBalloonSize;
276 BOOL mPageFusionEnabled;
277 GraphicsControllerType_T mGraphicsControllerType;
278 ULONG mVRAMSize;
279 settings::RecordingSettings mRecordSettings;
280 ULONG mMonitorCount;
281 BOOL mHWVirtExEnabled;
282 BOOL mHWVirtExNestedPagingEnabled;
283 BOOL mHWVirtExLargePagesEnabled;
284 BOOL mHWVirtExVPIDEnabled;
285 BOOL mHWVirtExUXEnabled;
286 BOOL mHWVirtExForceEnabled;
287 BOOL mHWVirtExUseNativeApi;
288 BOOL mAccelerate2DVideoEnabled;
289 BOOL mPAEEnabled;
290 settings::Hardware::LongModeType mLongMode;
291 BOOL mTripleFaultReset;
292 BOOL mAPIC;
293 BOOL mX2APIC;
294 BOOL mIBPBOnVMExit;
295 BOOL mIBPBOnVMEntry;
296 BOOL mSpecCtrl;
297 BOOL mSpecCtrlByHost;
298 BOOL mL1DFlushOnSched;
299 BOOL mL1DFlushOnVMEntry;
300 BOOL mMDSClearOnSched;
301 BOOL mMDSClearOnVMEntry;
302 BOOL mNestedHWVirt;
303 ULONG mCPUCount;
304 BOOL mCPUHotPlugEnabled;
305 ULONG mCpuExecutionCap;
306 uint32_t mCpuIdPortabilityLevel;
307 Utf8Str mCpuProfile;
308 BOOL mAccelerate3DEnabled;
309 BOOL mHPETEnabled;
310
311 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
312
313 std::list<settings::CpuIdLeaf> mCpuIdLeafList;
314
315 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
316
317 typedef std::list<ComObjPtr<SharedFolder> > SharedFolderList;
318 SharedFolderList mSharedFolders;
319
320 ClipboardMode_T mClipboardMode;
321 BOOL mClipboardFileTransfersEnabled;
322
323 DnDMode_T mDnDMode;
324
325 typedef std::map<Utf8Str, GuestProperty> GuestPropertyMap;
326 GuestPropertyMap mGuestProperties;
327
328 FirmwareType_T mFirmwareType;
329 KeyboardHIDType_T mKeyboardHIDType;
330 PointingHIDType_T mPointingHIDType;
331 ChipsetType_T mChipsetType;
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_EMPTY_CTOR_DTOR(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 const StringsList &llGroups,
362 const Utf8Str &strOsTypeId,
363 GuestOSType *aOsType,
364 const Guid &aId,
365 bool fForceOverwrite,
366 bool fDirectoryIncludesUUID);
367
368 // initializer for loading existing machine XML (either registered or not)
369 HRESULT initFromSettings(VirtualBox *aParent,
370 const Utf8Str &strConfigFile,
371 const Guid *aId);
372
373 // initializer for machine config in memory (OVF import)
374 HRESULT init(VirtualBox *aParent,
375 const Utf8Str &strName,
376 const Utf8Str &strSettingsFilename,
377 const settings::MachineConfigFile &config);
378
379 void uninit();
380
381#ifdef VBOX_WITH_RESOURCE_USAGE_API
382 // Needed from VirtualBox, for the delayed metrics cleanup.
383 void i_unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
384#endif /* VBOX_WITH_RESOURCE_USAGE_API */
385
386protected:
387 HRESULT initImpl(VirtualBox *aParent,
388 const Utf8Str &strConfigFile);
389 HRESULT initDataAndChildObjects();
390 HRESULT i_registeredInit();
391 HRESULT i_tryCreateMachineConfigFile(bool fForceOverwrite);
392 void uninitDataAndChildObjects();
393
394public:
395
396
397 // public methods only for internal purposes
398
399 virtual bool i_isSnapshotMachine() const
400 {
401 return false;
402 }
403
404 virtual bool i_isSessionMachine() const
405 {
406 return false;
407 }
408
409 /**
410 * Override of the default locking class to be used for validating lock
411 * order with the standard member lock handle.
412 */
413 virtual VBoxLockingClass getLockingClass() const
414 {
415 return LOCKCLASS_MACHINEOBJECT;
416 }
417
418 /// @todo (dmik) add lock and make non-inlined after revising classes
419 // that use it. Note: they should enter Machine lock to keep the returned
420 // information valid!
421 bool i_isRegistered() { return !!mData->mRegistered; }
422
423 // unsafe inline public methods for internal purposes only (ensure there is
424 // a caller and a read lock before calling them!)
425
426 /**
427 * Returns the VirtualBox object this machine belongs to.
428 *
429 * @note This method doesn't check this object's readiness. Intended to be
430 * used by ready Machine children (whose readiness is bound to the parent's
431 * one) or after doing addCaller() manually.
432 */
433 VirtualBox* i_getVirtualBox() const { return mParent; }
434
435 /**
436 * Checks if this machine is accessible, without attempting to load the
437 * config file.
438 *
439 * @note This method doesn't check this object's readiness. Intended to be
440 * used by ready Machine children (whose readiness is bound to the parent's
441 * one) or after doing addCaller() manually.
442 */
443 bool i_isAccessible() const { return !!mData->mAccessible; }
444
445 /**
446 * Returns this machine ID.
447 *
448 * @note This method doesn't check this object's readiness. Intended to be
449 * used by ready Machine children (whose readiness is bound to the parent's
450 * one) or after adding a caller manually.
451 */
452 const Guid& i_getId() const { return mData->mUuid; }
453
454 /**
455 * Returns the snapshot ID this machine represents or an empty UUID if this
456 * instance is not SnapshotMachine.
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 adding a caller manually.
461 */
462 inline const Guid& i_getSnapshotId() const;
463
464 /**
465 * Returns this machine's full settings file path.
466 *
467 * @note This method doesn't lock this object or check its readiness.
468 * Intended to be used only after doing addCaller() manually and locking it
469 * for reading.
470 */
471 const Utf8Str& i_getSettingsFileFull() const { return mData->m_strConfigFileFull; }
472
473 /**
474 * Returns this machine name.
475 *
476 * @note This method doesn't lock this object or check its readiness.
477 * Intended to be used only after doing addCaller() manually and locking it
478 * for reading.
479 */
480 const Utf8Str& i_getName() const { return mUserData->s.strName; }
481
482 enum
483 {
484 IsModified_MachineData = 0x0001,
485 IsModified_Storage = 0x0002,
486 IsModified_NetworkAdapters = 0x0008,
487 IsModified_SerialPorts = 0x0010,
488 IsModified_ParallelPorts = 0x0020,
489 IsModified_VRDEServer = 0x0040,
490 IsModified_AudioAdapter = 0x0080,
491 IsModified_USB = 0x0100,
492 IsModified_BIOS = 0x0200,
493 IsModified_SharedFolders = 0x0400,
494 IsModified_Snapshots = 0x0800,
495 IsModified_BandwidthControl = 0x1000,
496 IsModified_Recording = 0x2000
497 };
498
499 /**
500 * Returns various information about this machine.
501 *
502 * @note This method doesn't lock this object or check its readiness.
503 * Intended to be used only after doing addCaller() manually and locking it
504 * for reading.
505 */
506 Utf8Str i_getOSTypeId() const { return mUserData->s.strOsType; }
507 ChipsetType_T i_getChipsetType() const { return mHWData->mChipsetType; }
508 FirmwareType_T i_getFirmwareType() const { return mHWData->mFirmwareType; }
509 ULONG i_getMonitorCount() const { return mHWData->mMonitorCount; }
510 ParavirtProvider_T i_getParavirtProvider() const { return mHWData->mParavirtProvider; }
511 Utf8Str i_getParavirtDebug() const { return mHWData->mParavirtDebug; }
512
513 void i_setModified(uint32_t fl, bool fAllowStateModification = true);
514 void i_setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
515
516 MachineState_T i_getMachineState() const { return mData->mMachineState; }
517
518 bool i_isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
519 void i_allowStateModification() { mData->m_fAllowStateModification = true; }
520 void i_disallowStateModification() { mData->m_fAllowStateModification = false; }
521
522 const StringsList &i_getGroups() const { return mUserData->s.llGroups; }
523
524 // callback handlers
525 virtual HRESULT i_onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
526 virtual HRESULT i_onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
527 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */,
528 IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
529 virtual HRESULT i_onAudioAdapterChange(IAudioAdapter * /* audioAdapter */) { return S_OK; }
530 virtual HRESULT i_onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
531 virtual HRESULT i_onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
532 virtual HRESULT i_onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
533 virtual HRESULT i_onUSBControllerChange() { return S_OK; }
534 virtual HRESULT i_onStorageControllerChange(const com::Guid & /* aMachineId */, const com::Utf8Str & /* aControllerName */) { return S_OK; }
535 virtual HRESULT i_onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
536 virtual HRESULT i_onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
537 virtual HRESULT i_onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
538 virtual HRESULT i_onSharedFolderChange() { return S_OK; }
539 virtual HRESULT i_onVMProcessPriorityChange(VMProcPriority_T /* aPriority */) { return S_OK; }
540 virtual HRESULT i_onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
541 virtual HRESULT i_onClipboardFileTransferModeChange(BOOL /* aEnable */) { return S_OK; }
542 virtual HRESULT i_onDnDModeChange(DnDMode_T /* aDnDMode */) { return S_OK; }
543 virtual HRESULT i_onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
544 virtual HRESULT i_onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */,
545 BOOL /* silent */) { return S_OK; }
546 virtual HRESULT i_onRecordingChange(BOOL /* aEnable */) { return S_OK; }
547
548 HRESULT i_saveRegistryEntry(settings::MachineRegistryEntry &data);
549
550 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
551 void i_copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
552
553 void i_getLogFolder(Utf8Str &aLogFolder);
554 Utf8Str i_getLogFilename(ULONG idx);
555 Utf8Str i_getHardeningLogFilename(void);
556 Utf8Str i_getDefaultNVRAMFilename();
557 Utf8Str i_getSnapshotNVRAMFilename();
558
559 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
560
561 bool i_isUSBControllerPresent();
562
563 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
564 const Utf8Str &strType,
565 const std::vector<com::Utf8Str> &aEnvironmentChanges,
566 ProgressProxy *aProgress);
567
568 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
569 {
570 HRESULT rc;
571 *directControl = mData->mSession.mDirectControl;
572
573 if (!*directControl)
574 rc = E_ACCESSDENIED;
575 else
576 rc = S_OK;
577
578 return rc;
579 }
580
581 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
582 ComPtr<IInternalSessionControl> *aControl = NULL,
583 bool aRequireVM = false,
584 bool aAllowClosing = false);
585 bool i_isSessionSpawning();
586
587 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
588 ComPtr<IInternalSessionControl> *aControl = NULL)
589 { return i_isSessionOpen(aMachine, aControl, false /* aRequireVM */, true /* aAllowClosing */); }
590
591 bool i_isSessionOpenVM(ComObjPtr<SessionMachine> &aMachine,
592 ComPtr<IInternalSessionControl> *aControl = NULL)
593 { return i_isSessionOpen(aMachine, aControl, true /* aRequireVM */, false /* aAllowClosing */); }
594
595 bool i_checkForSpawnFailure();
596
597 HRESULT i_prepareRegister();
598
599 HRESULT i_getSharedFolder(const Utf8Str &aName,
600 ComObjPtr<SharedFolder> &aSharedFolder,
601 bool aSetError = false)
602 {
603 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
604 return i_findSharedFolder(aName, aSharedFolder, aSetError);
605 }
606
607 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
608 MachineState_T *aState = NULL,
609 BOOL *aRegistered = NULL);
610 void i_releaseStateDependency();
611
612 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
613 ComObjPtr<StorageController> &aStorageController,
614 bool aSetError = false);
615
616 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
617 MediumAttachmentList &aAttachments);
618
619 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
620 ComObjPtr<USBController> &aUSBController,
621 bool aSetError = false);
622
623 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
624 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
625 bool fSetError = false)
626 {
627 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
628 pBandwidthGroup,
629 fSetError);
630 }
631
632 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
633
634protected:
635
636 class ClientToken;
637
638 HRESULT i_checkStateDependency(StateDependency aDepType);
639
640 Machine *i_getMachine();
641
642 void i_ensureNoStateDependencies();
643
644 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
645
646 HRESULT i_findSharedFolder(const Utf8Str &aName,
647 ComObjPtr<SharedFolder> &aSharedFolder,
648 bool aSetError = false);
649
650 HRESULT i_loadSettings(bool aRegistered);
651 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
652 const Guid *puuidRegistry);
653 HRESULT i_loadSnapshot(const settings::Snapshot &data,
654 const Guid &aCurSnapshotId,
655 Snapshot *aParentSnapshot);
656 HRESULT i_loadHardware(const Guid *puuidRegistry,
657 const Guid *puuidSnapshot,
658 const settings::Hardware &data,
659 const settings::Debugging *pDbg,
660 const settings::Autostart *pAutostart);
661 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
662 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
663 HRESULT i_loadStorageControllers(const settings::Storage &data,
664 const Guid *puuidRegistry,
665 const Guid *puuidSnapshot);
666 HRESULT i_loadStorageDevices(StorageController *aStorageController,
667 const settings::StorageController &data,
668 const Guid *puuidRegistry,
669 const Guid *puuidSnapshot);
670
671 HRESULT i_findSnapshotById(const Guid &aId,
672 ComObjPtr<Snapshot> &aSnapshot,
673 bool aSetError = false);
674 HRESULT i_findSnapshotByName(const Utf8Str &strName,
675 ComObjPtr<Snapshot> &aSnapshot,
676 bool aSetError = false);
677
678 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
679
680 enum
681 {
682 /* flags for #saveSettings() */
683 SaveS_ResetCurStateModified = 0x01,
684 SaveS_Force = 0x04,
685 /* flags for #saveStateSettings() */
686 SaveSTS_CurStateModified = 0x20,
687 SaveSTS_StateFilePath = 0x40,
688 SaveSTS_StateTimeStamp = 0x80
689 };
690
691 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
692 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
693
694 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
695 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
696 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
697 settings::Autostart *pAutostart);
698 HRESULT i_saveStorageControllers(settings::Storage &data);
699 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
700 settings::StorageController &data);
701 HRESULT i_saveStateSettings(int aFlags);
702
703 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
704
705 HRESULT i_createImplicitDiffs(IProgress *aProgress,
706 ULONG aWeight,
707 bool aOnline);
708 HRESULT i_deleteImplicitDiffs(bool aOnline);
709
710 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
711 const Utf8Str &aControllerName,
712 LONG aControllerPort,
713 LONG aDevice);
714 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
715 ComObjPtr<Medium> pMedium);
716 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
717 Guid &id);
718
719 HRESULT i_detachDevice(MediumAttachment *pAttach,
720 AutoWriteLock &writeLock,
721 Snapshot *pSnapshot);
722
723 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
724 Snapshot *pSnapshot,
725 CleanupMode_T cleanupMode,
726 MediaList &llMedia);
727
728 void i_commitMedia(bool aOnline = false);
729 void i_rollbackMedia();
730
731 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
732
733 void i_rollback(bool aNotify);
734 void i_commit();
735 void i_copyFrom(Machine *aThat);
736 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
737
738 Utf8Str i_getExtraData(const Utf8Str &strKey);
739
740 com::Utf8Str i_controllerNameFromBusType(StorageBus_T aBusType);
741
742#ifdef VBOX_WITH_GUEST_PROPS
743 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
744 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
745 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
746 const com::Utf8Str &aFlags, bool fDelete);
747 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
748 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
749 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
750 const com::Utf8Str &aFlags, bool fDelete);
751 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
752 std::vector<com::Utf8Str> &aNames,
753 std::vector<com::Utf8Str> &aValues,
754 std::vector<LONG64> &aTimestamps,
755 std::vector<com::Utf8Str> &aFlags);
756 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
757 std::vector<com::Utf8Str> &aNames,
758 std::vector<com::Utf8Str> &aValues,
759 std::vector<LONG64> &aTimestamps,
760 std::vector<com::Utf8Str> &aFlags);
761
762#endif /* VBOX_WITH_GUEST_PROPS */
763
764#ifdef VBOX_WITH_RESOURCE_USAGE_API
765 void i_getDiskList(MediaList &list);
766 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
767
768 pm::CollectorGuest *mCollectorGuest;
769#endif /* VBOX_WITH_RESOURCE_USAGE_API */
770
771#ifdef VBOX_WITH_CLOUD_NET
772HRESULT i_connectToCloudNetwork(ProgressProxy *aProgress);
773HRESULT i_disconnectFromCloudNetwork();
774#endif /* VBOX_WITH_CLOUD_NET */
775
776 Machine * const mPeer;
777
778 VirtualBox * const mParent;
779
780 Shareable<Data> mData;
781 Shareable<SSData> mSSData;
782
783 Backupable<UserData> mUserData;
784 Backupable<HWData> mHWData;
785
786 /**
787 * Hard disk and other media data.
788 *
789 * The usage policy is the same as for mHWData, but a separate field
790 * is necessary because hard disk data requires different procedures when
791 * taking or deleting snapshots, etc.
792 *
793 * @todo r=klaus change this to a regular list and use the normal way to
794 * handle the settings when creating a session or taking a snapshot.
795 * Same thing applies to mStorageControllers and mUSBControllers.
796 */
797 Backupable<MediumAttachmentList> mMediumAttachments;
798
799 // the following fields need special backup/rollback/commit handling,
800 // so they cannot be a part of HWData
801
802 const ComObjPtr<VRDEServer> mVRDEServer;
803 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
804 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
805 const ComObjPtr<AudioAdapter> mAudioAdapter;
806 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
807 const ComObjPtr<BIOSSettings> mBIOSSettings;
808 const ComObjPtr<RecordingSettings> mRecordingSettings;
809 const ComObjPtr<BandwidthControl> mBandwidthControl;
810
811 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
812 NetworkAdapterVector mNetworkAdapters;
813
814 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
815 Backupable<StorageControllerList> mStorageControllers;
816
817 typedef std::list<ComObjPtr<USBController> > USBControllerList;
818 Backupable<USBControllerList> mUSBControllers;
819
820 uint64_t uRegistryNeedsSaving;
821
822 /**
823 * Abstract base class for all Machine or SessionMachine related
824 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
825 * a (non-static) method as its thread function, so instead we have it call
826 * the static Machine::taskHandler, which then calls the handler() method
827 * in here (implemented by the subclasses).
828 */
829 class Task : public ThreadTask
830 {
831 public:
832 Task(Machine *m, Progress *p, const Utf8Str &t)
833 : ThreadTask(t),
834 m_pMachine(m),
835 m_machineCaller(m),
836 m_pProgress(p),
837 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
838 {}
839 virtual ~Task(){}
840
841 void modifyBackedUpState(MachineState_T s)
842 {
843 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
844 }
845
846 ComObjPtr<Machine> m_pMachine;
847 AutoCaller m_machineCaller;
848 ComObjPtr<Progress> m_pProgress;
849 const MachineState_T m_machineStateBackup;
850 };
851
852 class DeleteConfigTask;
853 void i_deleteConfigHandler(DeleteConfigTask &task);
854
855 friend class Appliance;
856 friend class RecordingSettings;
857 friend class RecordingScreenSettings;
858 friend class SessionMachine;
859 friend class SnapshotMachine;
860 friend class VirtualBox;
861
862 friend class MachineCloneVM;
863 friend class MachineMoveVM;
864private:
865 // wrapped IMachine properties
866 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
867 HRESULT getIcon(std::vector<BYTE> &aIcon);
868 HRESULT setIcon(const std::vector<BYTE> &aIcon);
869 HRESULT getAccessible(BOOL *aAccessible);
870 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
871 HRESULT getName(com::Utf8Str &aName);
872 HRESULT setName(const com::Utf8Str &aName);
873 HRESULT getDescription(com::Utf8Str &aDescription);
874 HRESULT setDescription(const com::Utf8Str &aDescription);
875 HRESULT getId(com::Guid &aId);
876 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
877 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
878 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
879 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
880 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
881 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
882 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
883 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
884 HRESULT getCPUCount(ULONG *aCPUCount);
885 HRESULT setCPUCount(ULONG aCPUCount);
886 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
887 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
888 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
889 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
890 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
891 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
892 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
893 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
894 HRESULT getMemorySize(ULONG *aMemorySize);
895 HRESULT setMemorySize(ULONG aMemorySize);
896 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
897 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
898 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
899 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
900 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
901 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
902 HRESULT getVRAMSize(ULONG *aVRAMSize);
903 HRESULT setVRAMSize(ULONG aVRAMSize);
904 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
905 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
906 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
907 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
908 HRESULT getMonitorCount(ULONG *aMonitorCount);
909 HRESULT setMonitorCount(ULONG aMonitorCount);
910 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
911 HRESULT getRecordingSettings(ComPtr<IRecordingSettings> &aRecordingSettings);
912 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
913 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
914 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
915 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
916 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
917 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
918 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
919 HRESULT setHPETEnabled(BOOL aHPETEnabled);
920 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
921 HRESULT setChipsetType(ChipsetType_T aChipsetType);
922 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
923 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
924 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
925 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
926 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
927 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
928 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
929 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
930 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
931 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
932 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
933 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
934 HRESULT getSettingsModified(BOOL *aSettingsModified);
935 HRESULT getSessionState(SessionState_T *aSessionState);
936 HRESULT getSessionType(SessionType_T *aSessionType);
937 HRESULT getSessionName(com::Utf8Str &aSessionType);
938 HRESULT getSessionPID(ULONG *aSessionPID);
939 HRESULT getState(MachineState_T *aState);
940 HRESULT getLastStateChange(LONG64 *aLastStateChange);
941 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
942 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
943 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
944 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
945 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
946 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
947 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
948 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
949 HRESULT getClipboardFileTransfersEnabled(BOOL *aEnabled);
950 HRESULT setClipboardFileTransfersEnabled(BOOL aEnabled);
951 HRESULT getDnDMode(DnDMode_T *aDnDMode);
952 HRESULT setDnDMode(DnDMode_T aDnDMode);
953 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
954 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
955 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
956 HRESULT setTeleporterPort(ULONG aTeleporterPort);
957 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
958 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
959 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
960 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
961 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
962 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
963 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
964 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
965 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
966 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
967 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
968 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
969 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
970 HRESULT setIOCacheSize(ULONG aIOCacheSize);
971 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
972 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
973 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
974 HRESULT setTracingEnabled(BOOL aTracingEnabled);
975 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
976 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
977 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
978 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
979 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
980 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
981 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
982 HRESULT setAutostartDelay(ULONG aAutostartDelay);
983 HRESULT getAutostopType(AutostopType_T *aAutostopType);
984 HRESULT setAutostopType(AutostopType_T aAutostopType);
985 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
986 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
987 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
988 HRESULT getVMProcessPriority(VMProcPriority_T *aVMProcessPriority);
989 HRESULT setVMProcessPriority(VMProcPriority_T aVMProcessPriority);
990
991 // wrapped IMachine methods
992 HRESULT lockMachine(const ComPtr<ISession> &aSession,
993 LockType_T aLockType);
994 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
995 const com::Utf8Str &aType,
996 const std::vector<com::Utf8Str> &aEnvironmentChanges,
997 ComPtr<IProgress> &aProgress);
998 HRESULT setBootOrder(ULONG aPosition,
999 DeviceType_T aDevice);
1000 HRESULT getBootOrder(ULONG aPosition,
1001 DeviceType_T *aDevice);
1002 HRESULT attachDevice(const com::Utf8Str &aName,
1003 LONG aControllerPort,
1004 LONG aDevice,
1005 DeviceType_T aType,
1006 const ComPtr<IMedium> &aMedium);
1007 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
1008 LONG aControllerPort,
1009 LONG aDevice,
1010 DeviceType_T aType);
1011 HRESULT detachDevice(const com::Utf8Str &aName,
1012 LONG aControllerPort,
1013 LONG aDevice);
1014 HRESULT passthroughDevice(const com::Utf8Str &aName,
1015 LONG aControllerPort,
1016 LONG aDevice,
1017 BOOL aPassthrough);
1018 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
1019 LONG aControllerPort,
1020 LONG aDevice,
1021 BOOL aTemporaryEject);
1022 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
1023 LONG aControllerPort,
1024 LONG aDevice,
1025 BOOL aNonRotational);
1026 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
1027 LONG aControllerPort,
1028 LONG aDevice,
1029 BOOL aDiscard);
1030 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
1031 LONG aControllerPort,
1032 LONG aDevice,
1033 BOOL aHotPluggable);
1034 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
1035 LONG aControllerPort,
1036 LONG aDevice,
1037 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
1038 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
1039 LONG aControllerPort,
1040 LONG aDevice);
1041 HRESULT unmountMedium(const com::Utf8Str &aName,
1042 LONG aControllerPort,
1043 LONG aDevice,
1044 BOOL aForce);
1045 HRESULT mountMedium(const com::Utf8Str &aName,
1046 LONG aControllerPort,
1047 LONG aDevice,
1048 const ComPtr<IMedium> &aMedium,
1049 BOOL aForce);
1050 HRESULT getMedium(const com::Utf8Str &aName,
1051 LONG aControllerPort,
1052 LONG aDevice,
1053 ComPtr<IMedium> &aMedium);
1054 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
1055 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
1056 HRESULT getMediumAttachment(const com::Utf8Str &aName,
1057 LONG aControllerPort,
1058 LONG aDevice,
1059 ComPtr<IMediumAttachment> &aAttachment);
1060 HRESULT attachHostPCIDevice(LONG aHostAddress,
1061 LONG aDesiredGuestAddress,
1062 BOOL aTryToUnbind);
1063 HRESULT detachHostPCIDevice(LONG aHostAddress);
1064 HRESULT getNetworkAdapter(ULONG aSlot,
1065 ComPtr<INetworkAdapter> &aAdapter);
1066 HRESULT addStorageController(const com::Utf8Str &aName,
1067 StorageBus_T aConnectionType,
1068 ComPtr<IStorageController> &aController);
1069 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1070 ComPtr<IStorageController> &aStorageController);
1071 HRESULT getStorageControllerByInstance(StorageBus_T aConnectionType,
1072 ULONG aInstance,
1073 ComPtr<IStorageController> &aStorageController);
1074 HRESULT removeStorageController(const com::Utf8Str &aName);
1075 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1076 BOOL aBootable);
1077 HRESULT addUSBController(const com::Utf8Str &aName,
1078 USBControllerType_T aType,
1079 ComPtr<IUSBController> &aController);
1080 HRESULT removeUSBController(const com::Utf8Str &aName);
1081 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1082 ComPtr<IUSBController> &aController);
1083 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1084 ULONG *aControllers);
1085 HRESULT getSerialPort(ULONG aSlot,
1086 ComPtr<ISerialPort> &aPort);
1087 HRESULT getParallelPort(ULONG aSlot,
1088 ComPtr<IParallelPort> &aPort);
1089 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1090 HRESULT getExtraData(const com::Utf8Str &aKey,
1091 com::Utf8Str &aValue);
1092 HRESULT setExtraData(const com::Utf8Str &aKey,
1093 const com::Utf8Str &aValue);
1094 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1095 BOOL *aValue);
1096 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1097 BOOL aValue);
1098 HRESULT getCPUIDLeafByOrdinal(ULONG aOrdinal,
1099 ULONG *aIdx,
1100 ULONG *aSubIdx,
1101 ULONG *aValEax,
1102 ULONG *aValEbx,
1103 ULONG *aValEcx,
1104 ULONG *aValEdx);
1105 HRESULT getCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1106 ULONG *aValEax,
1107 ULONG *aValEbx,
1108 ULONG *aValEcx,
1109 ULONG *aValEdx);
1110 HRESULT setCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1111 ULONG aValEax,
1112 ULONG aValEbx,
1113 ULONG aValEcx,
1114 ULONG aValEdx);
1115 HRESULT removeCPUIDLeaf(ULONG aIdx, ULONG aSubIdx);
1116 HRESULT removeAllCPUIDLeaves();
1117 HRESULT getHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1118 BOOL *aValue);
1119 HRESULT setHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1120 BOOL aValue);
1121 HRESULT setSettingsFilePath(const com::Utf8Str &aSettingsFilePath,
1122 ComPtr<IProgress> &aProgress);
1123 HRESULT saveSettings();
1124 HRESULT discardSettings();
1125 HRESULT unregister(AutoCaller &aAutoCaller,
1126 CleanupMode_T aCleanupMode,
1127 std::vector<ComPtr<IMedium> > &aMedia);
1128 HRESULT deleteConfig(const std::vector<ComPtr<IMedium> > &aMedia,
1129 ComPtr<IProgress> &aProgress);
1130 HRESULT exportTo(const ComPtr<IAppliance> &aAppliance,
1131 const com::Utf8Str &aLocation,
1132 ComPtr<IVirtualSystemDescription> &aDescription);
1133 HRESULT findSnapshot(const com::Utf8Str &aNameOrId,
1134 ComPtr<ISnapshot> &aSnapshot);
1135 HRESULT createSharedFolder(const com::Utf8Str &aName,
1136 const com::Utf8Str &aHostPath,
1137 BOOL aWritable,
1138 BOOL aAutomount,
1139 const com::Utf8Str &aAutoMountPoint);
1140 HRESULT removeSharedFolder(const com::Utf8Str &aName);
1141 HRESULT canShowConsoleWindow(BOOL *aCanShow);
1142 HRESULT showConsoleWindow(LONG64 *aWinId);
1143 HRESULT getGuestProperty(const com::Utf8Str &aName,
1144 com::Utf8Str &aValue,
1145 LONG64 *aTimestamp,
1146 com::Utf8Str &aFlags);
1147 HRESULT getGuestPropertyValue(const com::Utf8Str &aProperty,
1148 com::Utf8Str &aValue);
1149 HRESULT getGuestPropertyTimestamp(const com::Utf8Str &aProperty,
1150 LONG64 *aValue);
1151 HRESULT setGuestProperty(const com::Utf8Str &aProperty,
1152 const com::Utf8Str &aValue,
1153 const com::Utf8Str &aFlags);
1154 HRESULT setGuestPropertyValue(const com::Utf8Str &aProperty,
1155 const com::Utf8Str &aValue);
1156 HRESULT deleteGuestProperty(const com::Utf8Str &aName);
1157 HRESULT enumerateGuestProperties(const com::Utf8Str &aPatterns,
1158 std::vector<com::Utf8Str> &aNames,
1159 std::vector<com::Utf8Str> &aValues,
1160 std::vector<LONG64> &aTimestamps,
1161 std::vector<com::Utf8Str> &aFlags);
1162 HRESULT querySavedGuestScreenInfo(ULONG aScreenId,
1163 ULONG *aOriginX,
1164 ULONG *aOriginY,
1165 ULONG *aWidth,
1166 ULONG *aHeight,
1167 BOOL *aEnabled);
1168 HRESULT readSavedThumbnailToArray(ULONG aScreenId,
1169 BitmapFormat_T aBitmapFormat,
1170 ULONG *aWidth,
1171 ULONG *aHeight,
1172 std::vector<BYTE> &aData);
1173 HRESULT querySavedScreenshotInfo(ULONG aScreenId,
1174 ULONG *aWidth,
1175 ULONG *aHeight,
1176 std::vector<BitmapFormat_T> &aBitmapFormats);
1177 HRESULT readSavedScreenshotToArray(ULONG aScreenId,
1178 BitmapFormat_T aBitmapFormat,
1179 ULONG *aWidth,
1180 ULONG *aHeight,
1181 std::vector<BYTE> &aData);
1182
1183 HRESULT hotPlugCPU(ULONG aCpu);
1184 HRESULT hotUnplugCPU(ULONG aCpu);
1185 HRESULT getCPUStatus(ULONG aCpu,
1186 BOOL *aAttached);
1187 HRESULT getEffectiveParavirtProvider(ParavirtProvider_T *aParavirtProvider);
1188 HRESULT queryLogFilename(ULONG aIdx,
1189 com::Utf8Str &aFilename);
1190 HRESULT readLog(ULONG aIdx,
1191 LONG64 aOffset,
1192 LONG64 aSize,
1193 std::vector<BYTE> &aData);
1194 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1195 CloneMode_T aMode,
1196 const std::vector<CloneOptions_T> &aOptions,
1197 ComPtr<IProgress> &aProgress);
1198 HRESULT moveTo(const com::Utf8Str &aTargetPath,
1199 const com::Utf8Str &aType,
1200 ComPtr<IProgress> &aProgress);
1201 HRESULT saveState(ComPtr<IProgress> &aProgress);
1202 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1203 HRESULT discardSavedState(BOOL aFRemoveFile);
1204 HRESULT takeSnapshot(const com::Utf8Str &aName,
1205 const com::Utf8Str &aDescription,
1206 BOOL aPause,
1207 com::Guid &aId,
1208 ComPtr<IProgress> &aProgress);
1209 HRESULT deleteSnapshot(const com::Guid &aId,
1210 ComPtr<IProgress> &aProgress);
1211 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1212 ComPtr<IProgress> &aProgress);
1213 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1214 const com::Guid &aEndId,
1215 ComPtr<IProgress> &aProgress);
1216 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1217 ComPtr<IProgress> &aProgress);
1218 HRESULT applyDefaults(const com::Utf8Str &aFlags);
1219
1220 // wrapped IInternalMachineControl properties
1221
1222 // wrapped IInternalMachineControl methods
1223 HRESULT updateState(MachineState_T aState);
1224 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1225 HRESULT endPowerUp(LONG aResult);
1226 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1227 HRESULT endPoweringDown(LONG aResult,
1228 const com::Utf8Str &aErrMsg);
1229 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1230 BOOL *aMatched,
1231 ULONG *aMaskedInterfaces);
1232 HRESULT captureUSBDevice(const com::Guid &aId,
1233 const com::Utf8Str &aCaptureFilename);
1234 HRESULT detachUSBDevice(const com::Guid &aId,
1235 BOOL aDone);
1236 HRESULT autoCaptureUSBDevices();
1237 HRESULT detachAllUSBDevices(BOOL aDone);
1238 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1239 ComPtr<IProgress> &aProgress);
1240 HRESULT finishOnlineMergeMedium();
1241 HRESULT clipboardAreaRegister(const std::vector<com::Utf8Str> &aParms, ULONG *aID);
1242 HRESULT clipboardAreaUnregister(ULONG aID);
1243 HRESULT clipboardAreaAttach(ULONG aID);
1244 HRESULT clipboardAreaDetach(ULONG aID);
1245 HRESULT clipboardAreaGetMostRecent(ULONG *aID);
1246 HRESULT clipboardAreaGetRefCount(ULONG aID, ULONG *aRefCount);
1247 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1248 std::vector<com::Utf8Str> &aValues,
1249 std::vector<LONG64> &aTimestamps,
1250 std::vector<com::Utf8Str> &aFlags);
1251 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1252 const com::Utf8Str &aValue,
1253 LONG64 aTimestamp,
1254 const com::Utf8Str &aFlags);
1255 HRESULT lockMedia();
1256 HRESULT unlockMedia();
1257 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1258 ComPtr<IMediumAttachment> &aNewAttachment);
1259 HRESULT reportVmStatistics(ULONG aValidStats,
1260 ULONG aCpuUser,
1261 ULONG aCpuKernel,
1262 ULONG aCpuIdle,
1263 ULONG aMemTotal,
1264 ULONG aMemFree,
1265 ULONG aMemBalloon,
1266 ULONG aMemShared,
1267 ULONG aMemCache,
1268 ULONG aPagedTotal,
1269 ULONG aMemAllocTotal,
1270 ULONG aMemFreeTotal,
1271 ULONG aMemBalloonTotal,
1272 ULONG aMemSharedTotal,
1273 ULONG aVmNetRx,
1274 ULONG aVmNetTx);
1275 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1276 com::Utf8Str &aResult);
1277};
1278
1279// SessionMachine class
1280////////////////////////////////////////////////////////////////////////////////
1281
1282/**
1283 * @note Notes on locking objects of this class:
1284 * SessionMachine shares some data with the primary Machine instance (pointed
1285 * to by the |mPeer| member). In order to provide data consistency it also
1286 * shares its lock handle. This means that whenever you lock a SessionMachine
1287 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1288 * instance is also locked in the same lock mode. Keep it in mind.
1289 */
1290class ATL_NO_VTABLE SessionMachine :
1291 public Machine
1292{
1293public:
1294 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1295
1296 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1297
1298 DECLARE_PROTECT_FINAL_CONSTRUCT()
1299
1300 BEGIN_COM_MAP(SessionMachine)
1301 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1302 COM_INTERFACE_ENTRY(IMachine)
1303 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1304 COM_INTERFACE_ENTRY(IInternalMachineControl)
1305 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1306 END_COM_MAP()
1307
1308 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1309
1310 HRESULT FinalConstruct();
1311 void FinalRelease();
1312
1313 struct Uninit
1314 {
1315 enum Reason { Unexpected, Abnormal, Normal };
1316 };
1317
1318 // public initializer/uninitializer for internal purposes only
1319 HRESULT init(Machine *aMachine);
1320 void uninit() { uninit(Uninit::Unexpected); }
1321 void uninit(Uninit::Reason aReason);
1322
1323
1324 // util::Lockable interface
1325 RWLockHandle *lockHandle() const;
1326
1327 // public methods only for internal purposes
1328
1329 virtual bool i_isSessionMachine() const
1330 {
1331 return true;
1332 }
1333
1334#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1335 bool i_checkForDeath();
1336
1337 void i_getTokenId(Utf8Str &strTokenId);
1338#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1339 IToken *i_getToken();
1340#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1341 // getClientToken must be only used by callers who can guarantee that
1342 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1343 ClientToken *i_getClientToken();
1344
1345 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1346 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1347 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1348 IN_BSTR aGuestIp, LONG aGuestPort);
1349 HRESULT i_onStorageControllerChange(const com::Guid &aMachineId, const com::Utf8Str &aControllerName);
1350 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1351 HRESULT i_onVMProcessPriorityChange(VMProcPriority_T aPriority);
1352 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1353 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1354 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1355 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1356 HRESULT i_onVRDEServerChange(BOOL aRestart);
1357 HRESULT i_onRecordingChange(BOOL aEnable);
1358 HRESULT i_onUSBControllerChange();
1359 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1360 IVirtualBoxErrorInfo *aError,
1361 ULONG aMaskedIfs,
1362 const com::Utf8Str &aCaptureFilename);
1363 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1364 IVirtualBoxErrorInfo *aError);
1365 HRESULT i_onSharedFolderChange();
1366 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1367 HRESULT i_onClipboardFileTransferModeChange(BOOL aEnable);
1368 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1369 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1370 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1371 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1372
1373 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1374
1375 HRESULT i_lockMedia();
1376 HRESULT i_unlockMedia();
1377
1378 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1379
1380private:
1381
1382 // wrapped IInternalMachineControl properties
1383
1384 // wrapped IInternalMachineControl methods
1385 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1386 HRESULT updateState(MachineState_T aState);
1387 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1388 HRESULT endPowerUp(LONG aResult);
1389 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1390 HRESULT endPoweringDown(LONG aResult,
1391 const com::Utf8Str &aErrMsg);
1392 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1393 BOOL *aMatched,
1394 ULONG *aMaskedInterfaces);
1395 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1396 HRESULT detachUSBDevice(const com::Guid &aId,
1397 BOOL aDone);
1398 HRESULT autoCaptureUSBDevices();
1399 HRESULT detachAllUSBDevices(BOOL aDone);
1400 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1401 ComPtr<IProgress> &aProgress);
1402 HRESULT finishOnlineMergeMedium();
1403 HRESULT clipboardAreaRegister(const std::vector<com::Utf8Str> &aParms, ULONG *aID);
1404 HRESULT clipboardAreaUnregister(ULONG aID);
1405 HRESULT clipboardAreaAttach(ULONG aID);
1406 HRESULT clipboardAreaDetach(ULONG aID);
1407 HRESULT clipboardAreaGetMostRecent(ULONG *aID);
1408 HRESULT clipboardAreaGetRefCount(ULONG aID, ULONG *aRefCount);
1409 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1410 std::vector<com::Utf8Str> &aValues,
1411 std::vector<LONG64> &aTimestamps,
1412 std::vector<com::Utf8Str> &aFlags);
1413 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1414 const com::Utf8Str &aValue,
1415 LONG64 aTimestamp,
1416 const com::Utf8Str &aFlags);
1417 HRESULT lockMedia();
1418 HRESULT unlockMedia();
1419 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1420 ComPtr<IMediumAttachment> &aNewAttachment);
1421 HRESULT reportVmStatistics(ULONG aValidStats,
1422 ULONG aCpuUser,
1423 ULONG aCpuKernel,
1424 ULONG aCpuIdle,
1425 ULONG aMemTotal,
1426 ULONG aMemFree,
1427 ULONG aMemBalloon,
1428 ULONG aMemShared,
1429 ULONG aMemCache,
1430 ULONG aPagedTotal,
1431 ULONG aMemAllocTotal,
1432 ULONG aMemFreeTotal,
1433 ULONG aMemBalloonTotal,
1434 ULONG aMemSharedTotal,
1435 ULONG aVmNetRx,
1436 ULONG aVmNetTx);
1437 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1438 com::Utf8Str &aResult);
1439
1440
1441 struct ConsoleTaskData
1442 {
1443 ConsoleTaskData()
1444 : mLastState(MachineState_Null),
1445 mDeleteSnapshotInfo(NULL)
1446 { }
1447
1448 MachineState_T mLastState;
1449 ComObjPtr<Progress> mProgress;
1450
1451 // used when deleting online snaphshot
1452 void *mDeleteSnapshotInfo;
1453 };
1454
1455 class SaveStateTask;
1456 class SnapshotTask;
1457 class TakeSnapshotTask;
1458 class DeleteSnapshotTask;
1459 class RestoreSnapshotTask;
1460
1461 void i_saveStateHandler(SaveStateTask &aTask);
1462
1463 // Override some functionality for SessionMachine, this is where the
1464 // real action happens (the Machine methods are just dummies).
1465 HRESULT saveState(ComPtr<IProgress> &aProgress);
1466 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1467 HRESULT discardSavedState(BOOL aFRemoveFile);
1468 HRESULT takeSnapshot(const com::Utf8Str &aName,
1469 const com::Utf8Str &aDescription,
1470 BOOL aPause,
1471 com::Guid &aId,
1472 ComPtr<IProgress> &aProgress);
1473 HRESULT deleteSnapshot(const com::Guid &aId,
1474 ComPtr<IProgress> &aProgress);
1475 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1476 ComPtr<IProgress> &aProgress);
1477 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1478 const com::Guid &aEndId,
1479 ComPtr<IProgress> &aProgress);
1480 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1481 ComPtr<IProgress> &aProgress);
1482
1483 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1484
1485 void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
1486 static void i_takeSnapshotProgressCancelCallback(void *pvUser);
1487 HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
1488 HRESULT i_deleteSnapshot(const com::Guid &aStartId,
1489 const com::Guid &aEndId,
1490 BOOL aDeleteAllChildren,
1491 ComPtr<IProgress> &aProgress);
1492 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1493 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1494
1495 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1496 const Guid &machineId,
1497 const Guid &snapshotId,
1498 bool fOnlineMergePossible,
1499 MediumLockList *aVMMALockList,
1500 ComObjPtr<Medium> &aSource,
1501 ComObjPtr<Medium> &aTarget,
1502 bool &fMergeForward,
1503 ComObjPtr<Medium> &pParentForTarget,
1504 MediumLockList * &aChildrenToReparent,
1505 bool &fNeedOnlineMerge,
1506 MediumLockList * &aMediumLockList,
1507 ComPtr<IToken> &aHDLockToken);
1508 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1509 const ComObjPtr<Medium> &aSource,
1510 MediumLockList *aChildrenToReparent,
1511 bool fNeedsOnlineMerge,
1512 MediumLockList *aMediumLockList,
1513 const ComPtr<IToken> &aHDLockToken,
1514 const Guid &aMediumId,
1515 const Guid &aSnapshotId);
1516 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1517 const ComObjPtr<Medium> &aSource,
1518 const ComObjPtr<Medium> &aTarget,
1519 bool fMergeForward,
1520 const ComObjPtr<Medium> &pParentForTarget,
1521 MediumLockList *aChildrenToReparent,
1522 MediumLockList *aMediumLockList,
1523 ComObjPtr<Progress> &aProgress,
1524 bool *pfNeedsMachineSaveSettings);
1525
1526 HRESULT i_setMachineState(MachineState_T aMachineState);
1527 HRESULT i_updateMachineStateOnClient();
1528
1529 bool mRemoveSavedState;
1530
1531 ConsoleTaskData mConsoleTaskData;
1532
1533 /** client token for this machine */
1534 ClientToken *mClientToken;
1535
1536 int miNATNetworksStarted;
1537
1538 AUTHLIBRARYCONTEXT mAuthLibCtx;
1539};
1540
1541// SnapshotMachine class
1542////////////////////////////////////////////////////////////////////////////////
1543
1544/**
1545 * @note Notes on locking objects of this class:
1546 * SnapshotMachine shares some data with the primary Machine instance (pointed
1547 * to by the |mPeer| member). In order to provide data consistency it also
1548 * shares its lock handle. This means that whenever you lock a SessionMachine
1549 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1550 * instance is also locked in the same lock mode. Keep it in mind.
1551 */
1552class ATL_NO_VTABLE SnapshotMachine :
1553 public Machine
1554{
1555public:
1556 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1557
1558 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1559
1560 DECLARE_PROTECT_FINAL_CONSTRUCT()
1561
1562 BEGIN_COM_MAP(SnapshotMachine)
1563 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1564 COM_INTERFACE_ENTRY(IMachine)
1565 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1566 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1567 END_COM_MAP()
1568
1569 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1570
1571 HRESULT FinalConstruct();
1572 void FinalRelease();
1573
1574 // public initializer/uninitializer for internal purposes only
1575 HRESULT init(SessionMachine *aSessionMachine,
1576 IN_GUID aSnapshotId,
1577 const Utf8Str &aStateFilePath);
1578 HRESULT initFromSettings(Machine *aMachine,
1579 const settings::Hardware &hardware,
1580 const settings::Debugging *pDbg,
1581 const settings::Autostart *pAutostart,
1582 IN_GUID aSnapshotId,
1583 const Utf8Str &aStateFilePath);
1584 void uninit();
1585
1586 // util::Lockable interface
1587 RWLockHandle *lockHandle() const;
1588
1589 // public methods only for internal purposes
1590
1591 virtual bool i_isSnapshotMachine() const
1592 {
1593 return true;
1594 }
1595
1596 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1597
1598 // unsafe inline public methods for internal purposes only (ensure there is
1599 // a caller and a read lock before calling them!)
1600
1601 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1602
1603private:
1604
1605 Guid mSnapshotId;
1606 /** This field replaces mPeer for SessionMachine instances, as having
1607 * a peer reference is plain meaningless and causes many subtle problems
1608 * with saving settings and the like. */
1609 Machine * const mMachine;
1610
1611 friend class Snapshot;
1612};
1613
1614// third party methods that depend on SnapshotMachine definition
1615
1616inline const Guid &Machine::i_getSnapshotId() const
1617{
1618 return (i_isSnapshotMachine())
1619 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1620 : Guid::Empty;
1621}
1622
1623
1624#endif /* !MAIN_INCLUDED_MachineImpl_h */
1625/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette