VirtualBox

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

Last change on this file since 81422 was 81422, checked in by vboxsync, 5 years ago

OCI: (bugref:9469) cloud network integration concept (disabled in Config.kmk).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.6 KB
Line 
1/* $Id: MachineImpl.h 81422 2019-10-21 18:04:10Z 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.virtualbox.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
558 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
559
560 bool i_isUSBControllerPresent();
561
562 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
563 const Utf8Str &strType,
564 const std::vector<com::Utf8Str> &aEnvironmentChanges,
565 ProgressProxy *aProgress);
566
567 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
568 {
569 HRESULT rc;
570 *directControl = mData->mSession.mDirectControl;
571
572 if (!*directControl)
573 rc = E_ACCESSDENIED;
574 else
575 rc = S_OK;
576
577 return rc;
578 }
579
580 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
581 ComPtr<IInternalSessionControl> *aControl = NULL,
582 bool aRequireVM = false,
583 bool aAllowClosing = false);
584 bool i_isSessionSpawning();
585
586 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
587 ComPtr<IInternalSessionControl> *aControl = NULL)
588 { return i_isSessionOpen(aMachine, aControl, false /* aRequireVM */, true /* aAllowClosing */); }
589
590 bool i_isSessionOpenVM(ComObjPtr<SessionMachine> &aMachine,
591 ComPtr<IInternalSessionControl> *aControl = NULL)
592 { return i_isSessionOpen(aMachine, aControl, true /* aRequireVM */, false /* aAllowClosing */); }
593
594 bool i_checkForSpawnFailure();
595
596 HRESULT i_prepareRegister();
597
598 HRESULT i_getSharedFolder(const Utf8Str &aName,
599 ComObjPtr<SharedFolder> &aSharedFolder,
600 bool aSetError = false)
601 {
602 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
603 return i_findSharedFolder(aName, aSharedFolder, aSetError);
604 }
605
606 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
607 MachineState_T *aState = NULL,
608 BOOL *aRegistered = NULL);
609 void i_releaseStateDependency();
610
611 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
612 ComObjPtr<StorageController> &aStorageController,
613 bool aSetError = false);
614
615 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
616 MediumAttachmentList &aAttachments);
617
618 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
619 ComObjPtr<USBController> &aUSBController,
620 bool aSetError = false);
621
622 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
623 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
624 bool fSetError = false)
625 {
626 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
627 pBandwidthGroup,
628 fSetError);
629 }
630
631 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
632
633protected:
634
635 class ClientToken;
636
637 HRESULT i_checkStateDependency(StateDependency aDepType);
638
639 Machine *i_getMachine();
640
641 void i_ensureNoStateDependencies();
642
643 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
644
645 HRESULT i_findSharedFolder(const Utf8Str &aName,
646 ComObjPtr<SharedFolder> &aSharedFolder,
647 bool aSetError = false);
648
649 HRESULT i_loadSettings(bool aRegistered);
650 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
651 const Guid *puuidRegistry);
652 HRESULT i_loadSnapshot(const settings::Snapshot &data,
653 const Guid &aCurSnapshotId,
654 Snapshot *aParentSnapshot);
655 HRESULT i_loadHardware(const Guid *puuidRegistry,
656 const Guid *puuidSnapshot,
657 const settings::Hardware &data,
658 const settings::Debugging *pDbg,
659 const settings::Autostart *pAutostart);
660 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
661 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
662 HRESULT i_loadStorageControllers(const settings::Storage &data,
663 const Guid *puuidRegistry,
664 const Guid *puuidSnapshot);
665 HRESULT i_loadStorageDevices(StorageController *aStorageController,
666 const settings::StorageController &data,
667 const Guid *puuidRegistry,
668 const Guid *puuidSnapshot);
669
670 HRESULT i_findSnapshotById(const Guid &aId,
671 ComObjPtr<Snapshot> &aSnapshot,
672 bool aSetError = false);
673 HRESULT i_findSnapshotByName(const Utf8Str &strName,
674 ComObjPtr<Snapshot> &aSnapshot,
675 bool aSetError = false);
676
677 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
678
679 enum
680 {
681 /* flags for #saveSettings() */
682 SaveS_ResetCurStateModified = 0x01,
683 SaveS_Force = 0x04,
684 /* flags for #saveStateSettings() */
685 SaveSTS_CurStateModified = 0x20,
686 SaveSTS_StateFilePath = 0x40,
687 SaveSTS_StateTimeStamp = 0x80
688 };
689
690 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
691 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
692
693 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
694 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
695 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
696 settings::Autostart *pAutostart);
697 HRESULT i_saveStorageControllers(settings::Storage &data);
698 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
699 settings::StorageController &data);
700 HRESULT i_saveStateSettings(int aFlags);
701
702 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
703
704 HRESULT i_createImplicitDiffs(IProgress *aProgress,
705 ULONG aWeight,
706 bool aOnline);
707 HRESULT i_deleteImplicitDiffs(bool aOnline);
708
709 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
710 const Utf8Str &aControllerName,
711 LONG aControllerPort,
712 LONG aDevice);
713 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
714 ComObjPtr<Medium> pMedium);
715 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
716 Guid &id);
717
718 HRESULT i_detachDevice(MediumAttachment *pAttach,
719 AutoWriteLock &writeLock,
720 Snapshot *pSnapshot);
721
722 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
723 Snapshot *pSnapshot,
724 CleanupMode_T cleanupMode,
725 MediaList &llMedia);
726
727 void i_commitMedia(bool aOnline = false);
728 void i_rollbackMedia();
729
730 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
731
732 void i_rollback(bool aNotify);
733 void i_commit();
734 void i_copyFrom(Machine *aThat);
735 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
736
737 Utf8Str i_getExtraData(const Utf8Str &strKey);
738
739 com::Utf8Str i_controllerNameFromBusType(StorageBus_T aBusType);
740
741#ifdef VBOX_WITH_GUEST_PROPS
742 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
743 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
744 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
745 const com::Utf8Str &aFlags, bool fDelete);
746 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
747 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
748 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
749 const com::Utf8Str &aFlags, bool fDelete);
750 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
751 std::vector<com::Utf8Str> &aNames,
752 std::vector<com::Utf8Str> &aValues,
753 std::vector<LONG64> &aTimestamps,
754 std::vector<com::Utf8Str> &aFlags);
755 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
756 std::vector<com::Utf8Str> &aNames,
757 std::vector<com::Utf8Str> &aValues,
758 std::vector<LONG64> &aTimestamps,
759 std::vector<com::Utf8Str> &aFlags);
760
761#endif /* VBOX_WITH_GUEST_PROPS */
762
763#ifdef VBOX_WITH_RESOURCE_USAGE_API
764 void i_getDiskList(MediaList &list);
765 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
766
767 pm::CollectorGuest *mCollectorGuest;
768#endif /* VBOX_WITH_RESOURCE_USAGE_API */
769
770#ifdef VBOX_WITH_CLOUD_NET
771HRESULT i_connectToCloudNetwork(ProgressProxy *aProgress);
772HRESULT i_disconnectFromCloudNetwork();
773#endif /* VBOX_WITH_CLOUD_NET */
774
775 Machine * const mPeer;
776
777 VirtualBox * const mParent;
778
779 Shareable<Data> mData;
780 Shareable<SSData> mSSData;
781
782 Backupable<UserData> mUserData;
783 Backupable<HWData> mHWData;
784
785 /**
786 * Hard disk and other media data.
787 *
788 * The usage policy is the same as for mHWData, but a separate field
789 * is necessary because hard disk data requires different procedures when
790 * taking or deleting snapshots, etc.
791 *
792 * @todo r=klaus change this to a regular list and use the normal way to
793 * handle the settings when creating a session or taking a snapshot.
794 * Same thing applies to mStorageControllers and mUSBControllers.
795 */
796 Backupable<MediumAttachmentList> mMediumAttachments;
797
798 // the following fields need special backup/rollback/commit handling,
799 // so they cannot be a part of HWData
800
801 const ComObjPtr<VRDEServer> mVRDEServer;
802 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
803 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
804 const ComObjPtr<AudioAdapter> mAudioAdapter;
805 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
806 const ComObjPtr<BIOSSettings> mBIOSSettings;
807 const ComObjPtr<RecordingSettings> mRecordingSettings;
808 const ComObjPtr<BandwidthControl> mBandwidthControl;
809
810 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
811 NetworkAdapterVector mNetworkAdapters;
812
813 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
814 Backupable<StorageControllerList> mStorageControllers;
815
816 typedef std::list<ComObjPtr<USBController> > USBControllerList;
817 Backupable<USBControllerList> mUSBControllers;
818
819 uint64_t uRegistryNeedsSaving;
820
821 /**
822 * Abstract base class for all Machine or SessionMachine related
823 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
824 * a (non-static) method as its thread function, so instead we have it call
825 * the static Machine::taskHandler, which then calls the handler() method
826 * in here (implemented by the subclasses).
827 */
828 class Task : public ThreadTask
829 {
830 public:
831 Task(Machine *m, Progress *p, const Utf8Str &t)
832 : ThreadTask(t),
833 m_pMachine(m),
834 m_machineCaller(m),
835 m_pProgress(p),
836 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
837 {}
838 virtual ~Task(){}
839
840 void modifyBackedUpState(MachineState_T s)
841 {
842 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
843 }
844
845 ComObjPtr<Machine> m_pMachine;
846 AutoCaller m_machineCaller;
847 ComObjPtr<Progress> m_pProgress;
848 const MachineState_T m_machineStateBackup;
849 };
850
851 class DeleteConfigTask;
852 void i_deleteConfigHandler(DeleteConfigTask &task);
853
854 friend class Appliance;
855 friend class RecordingSettings;
856 friend class RecordingScreenSettings;
857 friend class SessionMachine;
858 friend class SnapshotMachine;
859 friend class VirtualBox;
860
861 friend class MachineCloneVM;
862 friend class MachineMoveVM;
863private:
864 // wrapped IMachine properties
865 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
866 HRESULT getIcon(std::vector<BYTE> &aIcon);
867 HRESULT setIcon(const std::vector<BYTE> &aIcon);
868 HRESULT getAccessible(BOOL *aAccessible);
869 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
870 HRESULT getName(com::Utf8Str &aName);
871 HRESULT setName(const com::Utf8Str &aName);
872 HRESULT getDescription(com::Utf8Str &aDescription);
873 HRESULT setDescription(const com::Utf8Str &aDescription);
874 HRESULT getId(com::Guid &aId);
875 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
876 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
877 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
878 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
879 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
880 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
881 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
882 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
883 HRESULT getCPUCount(ULONG *aCPUCount);
884 HRESULT setCPUCount(ULONG aCPUCount);
885 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
886 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
887 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
888 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
889 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
890 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
891 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
892 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
893 HRESULT getMemorySize(ULONG *aMemorySize);
894 HRESULT setMemorySize(ULONG aMemorySize);
895 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
896 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
897 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
898 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
899 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
900 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
901 HRESULT getVRAMSize(ULONG *aVRAMSize);
902 HRESULT setVRAMSize(ULONG aVRAMSize);
903 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
904 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
905 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
906 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
907 HRESULT getMonitorCount(ULONG *aMonitorCount);
908 HRESULT setMonitorCount(ULONG aMonitorCount);
909 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
910 HRESULT getRecordingSettings(ComPtr<IRecordingSettings> &aRecordingSettings);
911 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
912 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
913 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
914 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
915 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
916 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
917 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
918 HRESULT setHPETEnabled(BOOL aHPETEnabled);
919 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
920 HRESULT setChipsetType(ChipsetType_T aChipsetType);
921 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
922 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
923 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
924 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
925 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
926 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
927 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
928 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
929 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
930 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
931 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
932 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
933 HRESULT getSettingsModified(BOOL *aSettingsModified);
934 HRESULT getSessionState(SessionState_T *aSessionState);
935 HRESULT getSessionType(SessionType_T *aSessionType);
936 HRESULT getSessionName(com::Utf8Str &aSessionType);
937 HRESULT getSessionPID(ULONG *aSessionPID);
938 HRESULT getState(MachineState_T *aState);
939 HRESULT getLastStateChange(LONG64 *aLastStateChange);
940 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
941 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
942 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
943 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
944 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
945 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
946 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
947 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
948 HRESULT getClipboardFileTransfersEnabled(BOOL *aEnabled);
949 HRESULT setClipboardFileTransfersEnabled(BOOL aEnabled);
950 HRESULT getDnDMode(DnDMode_T *aDnDMode);
951 HRESULT setDnDMode(DnDMode_T aDnDMode);
952 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
953 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
954 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
955 HRESULT setTeleporterPort(ULONG aTeleporterPort);
956 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
957 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
958 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
959 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
960 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
961 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
962 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
963 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
964 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
965 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
966 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
967 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
968 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
969 HRESULT setIOCacheSize(ULONG aIOCacheSize);
970 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
971 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
972 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
973 HRESULT setTracingEnabled(BOOL aTracingEnabled);
974 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
975 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
976 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
977 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
978 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
979 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
980 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
981 HRESULT setAutostartDelay(ULONG aAutostartDelay);
982 HRESULT getAutostopType(AutostopType_T *aAutostopType);
983 HRESULT setAutostopType(AutostopType_T aAutostopType);
984 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
985 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
986 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
987 HRESULT getVMProcessPriority(VMProcPriority_T *aVMProcessPriority);
988 HRESULT setVMProcessPriority(VMProcPriority_T aVMProcessPriority);
989
990 // wrapped IMachine methods
991 HRESULT lockMachine(const ComPtr<ISession> &aSession,
992 LockType_T aLockType);
993 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
994 const com::Utf8Str &aType,
995 const std::vector<com::Utf8Str> &aEnvironmentChanges,
996 ComPtr<IProgress> &aProgress);
997 HRESULT setBootOrder(ULONG aPosition,
998 DeviceType_T aDevice);
999 HRESULT getBootOrder(ULONG aPosition,
1000 DeviceType_T *aDevice);
1001 HRESULT attachDevice(const com::Utf8Str &aName,
1002 LONG aControllerPort,
1003 LONG aDevice,
1004 DeviceType_T aType,
1005 const ComPtr<IMedium> &aMedium);
1006 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
1007 LONG aControllerPort,
1008 LONG aDevice,
1009 DeviceType_T aType);
1010 HRESULT detachDevice(const com::Utf8Str &aName,
1011 LONG aControllerPort,
1012 LONG aDevice);
1013 HRESULT passthroughDevice(const com::Utf8Str &aName,
1014 LONG aControllerPort,
1015 LONG aDevice,
1016 BOOL aPassthrough);
1017 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
1018 LONG aControllerPort,
1019 LONG aDevice,
1020 BOOL aTemporaryEject);
1021 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
1022 LONG aControllerPort,
1023 LONG aDevice,
1024 BOOL aNonRotational);
1025 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
1026 LONG aControllerPort,
1027 LONG aDevice,
1028 BOOL aDiscard);
1029 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
1030 LONG aControllerPort,
1031 LONG aDevice,
1032 BOOL aHotPluggable);
1033 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
1034 LONG aControllerPort,
1035 LONG aDevice,
1036 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
1037 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
1038 LONG aControllerPort,
1039 LONG aDevice);
1040 HRESULT unmountMedium(const com::Utf8Str &aName,
1041 LONG aControllerPort,
1042 LONG aDevice,
1043 BOOL aForce);
1044 HRESULT mountMedium(const com::Utf8Str &aName,
1045 LONG aControllerPort,
1046 LONG aDevice,
1047 const ComPtr<IMedium> &aMedium,
1048 BOOL aForce);
1049 HRESULT getMedium(const com::Utf8Str &aName,
1050 LONG aControllerPort,
1051 LONG aDevice,
1052 ComPtr<IMedium> &aMedium);
1053 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
1054 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
1055 HRESULT getMediumAttachment(const com::Utf8Str &aName,
1056 LONG aControllerPort,
1057 LONG aDevice,
1058 ComPtr<IMediumAttachment> &aAttachment);
1059 HRESULT attachHostPCIDevice(LONG aHostAddress,
1060 LONG aDesiredGuestAddress,
1061 BOOL aTryToUnbind);
1062 HRESULT detachHostPCIDevice(LONG aHostAddress);
1063 HRESULT getNetworkAdapter(ULONG aSlot,
1064 ComPtr<INetworkAdapter> &aAdapter);
1065 HRESULT addStorageController(const com::Utf8Str &aName,
1066 StorageBus_T aConnectionType,
1067 ComPtr<IStorageController> &aController);
1068 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1069 ComPtr<IStorageController> &aStorageController);
1070 HRESULT getStorageControllerByInstance(StorageBus_T aConnectionType,
1071 ULONG aInstance,
1072 ComPtr<IStorageController> &aStorageController);
1073 HRESULT removeStorageController(const com::Utf8Str &aName);
1074 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1075 BOOL aBootable);
1076 HRESULT addUSBController(const com::Utf8Str &aName,
1077 USBControllerType_T aType,
1078 ComPtr<IUSBController> &aController);
1079 HRESULT removeUSBController(const com::Utf8Str &aName);
1080 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1081 ComPtr<IUSBController> &aController);
1082 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1083 ULONG *aControllers);
1084 HRESULT getSerialPort(ULONG aSlot,
1085 ComPtr<ISerialPort> &aPort);
1086 HRESULT getParallelPort(ULONG aSlot,
1087 ComPtr<IParallelPort> &aPort);
1088 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1089 HRESULT getExtraData(const com::Utf8Str &aKey,
1090 com::Utf8Str &aValue);
1091 HRESULT setExtraData(const com::Utf8Str &aKey,
1092 const com::Utf8Str &aValue);
1093 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1094 BOOL *aValue);
1095 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1096 BOOL aValue);
1097 HRESULT getCPUIDLeafByOrdinal(ULONG aOrdinal,
1098 ULONG *aIdx,
1099 ULONG *aSubIdx,
1100 ULONG *aValEax,
1101 ULONG *aValEbx,
1102 ULONG *aValEcx,
1103 ULONG *aValEdx);
1104 HRESULT getCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1105 ULONG *aValEax,
1106 ULONG *aValEbx,
1107 ULONG *aValEcx,
1108 ULONG *aValEdx);
1109 HRESULT setCPUIDLeaf(ULONG aIdx, ULONG aSubIdx,
1110 ULONG aValEax,
1111 ULONG aValEbx,
1112 ULONG aValEcx,
1113 ULONG aValEdx);
1114 HRESULT removeCPUIDLeaf(ULONG aIdx, ULONG aSubIdx);
1115 HRESULT removeAllCPUIDLeaves();
1116 HRESULT getHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1117 BOOL *aValue);
1118 HRESULT setHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1119 BOOL aValue);
1120 HRESULT setSettingsFilePath(const com::Utf8Str &aSettingsFilePath,
1121 ComPtr<IProgress> &aProgress);
1122 HRESULT saveSettings();
1123 HRESULT discardSettings();
1124 HRESULT unregister(AutoCaller &aAutoCaller,
1125 CleanupMode_T aCleanupMode,
1126 std::vector<ComPtr<IMedium> > &aMedia);
1127 HRESULT deleteConfig(const std::vector<ComPtr<IMedium> > &aMedia,
1128 ComPtr<IProgress> &aProgress);
1129 HRESULT exportTo(const ComPtr<IAppliance> &aAppliance,
1130 const com::Utf8Str &aLocation,
1131 ComPtr<IVirtualSystemDescription> &aDescription);
1132 HRESULT findSnapshot(const com::Utf8Str &aNameOrId,
1133 ComPtr<ISnapshot> &aSnapshot);
1134 HRESULT createSharedFolder(const com::Utf8Str &aName,
1135 const com::Utf8Str &aHostPath,
1136 BOOL aWritable,
1137 BOOL aAutomount,
1138 const com::Utf8Str &aAutoMountPoint);
1139 HRESULT removeSharedFolder(const com::Utf8Str &aName);
1140 HRESULT canShowConsoleWindow(BOOL *aCanShow);
1141 HRESULT showConsoleWindow(LONG64 *aWinId);
1142 HRESULT getGuestProperty(const com::Utf8Str &aName,
1143 com::Utf8Str &aValue,
1144 LONG64 *aTimestamp,
1145 com::Utf8Str &aFlags);
1146 HRESULT getGuestPropertyValue(const com::Utf8Str &aProperty,
1147 com::Utf8Str &aValue);
1148 HRESULT getGuestPropertyTimestamp(const com::Utf8Str &aProperty,
1149 LONG64 *aValue);
1150 HRESULT setGuestProperty(const com::Utf8Str &aProperty,
1151 const com::Utf8Str &aValue,
1152 const com::Utf8Str &aFlags);
1153 HRESULT setGuestPropertyValue(const com::Utf8Str &aProperty,
1154 const com::Utf8Str &aValue);
1155 HRESULT deleteGuestProperty(const com::Utf8Str &aName);
1156 HRESULT enumerateGuestProperties(const com::Utf8Str &aPatterns,
1157 std::vector<com::Utf8Str> &aNames,
1158 std::vector<com::Utf8Str> &aValues,
1159 std::vector<LONG64> &aTimestamps,
1160 std::vector<com::Utf8Str> &aFlags);
1161 HRESULT querySavedGuestScreenInfo(ULONG aScreenId,
1162 ULONG *aOriginX,
1163 ULONG *aOriginY,
1164 ULONG *aWidth,
1165 ULONG *aHeight,
1166 BOOL *aEnabled);
1167 HRESULT readSavedThumbnailToArray(ULONG aScreenId,
1168 BitmapFormat_T aBitmapFormat,
1169 ULONG *aWidth,
1170 ULONG *aHeight,
1171 std::vector<BYTE> &aData);
1172 HRESULT querySavedScreenshotInfo(ULONG aScreenId,
1173 ULONG *aWidth,
1174 ULONG *aHeight,
1175 std::vector<BitmapFormat_T> &aBitmapFormats);
1176 HRESULT readSavedScreenshotToArray(ULONG aScreenId,
1177 BitmapFormat_T aBitmapFormat,
1178 ULONG *aWidth,
1179 ULONG *aHeight,
1180 std::vector<BYTE> &aData);
1181
1182 HRESULT hotPlugCPU(ULONG aCpu);
1183 HRESULT hotUnplugCPU(ULONG aCpu);
1184 HRESULT getCPUStatus(ULONG aCpu,
1185 BOOL *aAttached);
1186 HRESULT getEffectiveParavirtProvider(ParavirtProvider_T *aParavirtProvider);
1187 HRESULT queryLogFilename(ULONG aIdx,
1188 com::Utf8Str &aFilename);
1189 HRESULT readLog(ULONG aIdx,
1190 LONG64 aOffset,
1191 LONG64 aSize,
1192 std::vector<BYTE> &aData);
1193 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1194 CloneMode_T aMode,
1195 const std::vector<CloneOptions_T> &aOptions,
1196 ComPtr<IProgress> &aProgress);
1197 HRESULT moveTo(const com::Utf8Str &aTargetPath,
1198 const com::Utf8Str &aType,
1199 ComPtr<IProgress> &aProgress);
1200 HRESULT saveState(ComPtr<IProgress> &aProgress);
1201 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1202 HRESULT discardSavedState(BOOL aFRemoveFile);
1203 HRESULT takeSnapshot(const com::Utf8Str &aName,
1204 const com::Utf8Str &aDescription,
1205 BOOL aPause,
1206 com::Guid &aId,
1207 ComPtr<IProgress> &aProgress);
1208 HRESULT deleteSnapshot(const com::Guid &aId,
1209 ComPtr<IProgress> &aProgress);
1210 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1211 ComPtr<IProgress> &aProgress);
1212 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1213 const com::Guid &aEndId,
1214 ComPtr<IProgress> &aProgress);
1215 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1216 ComPtr<IProgress> &aProgress);
1217 HRESULT applyDefaults(const com::Utf8Str &aFlags);
1218
1219 // wrapped IInternalMachineControl properties
1220
1221 // wrapped IInternalMachineControl methods
1222 HRESULT updateState(MachineState_T aState);
1223 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1224 HRESULT endPowerUp(LONG aResult);
1225 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1226 HRESULT endPoweringDown(LONG aResult,
1227 const com::Utf8Str &aErrMsg);
1228 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1229 BOOL *aMatched,
1230 ULONG *aMaskedInterfaces);
1231 HRESULT captureUSBDevice(const com::Guid &aId,
1232 const com::Utf8Str &aCaptureFilename);
1233 HRESULT detachUSBDevice(const com::Guid &aId,
1234 BOOL aDone);
1235 HRESULT autoCaptureUSBDevices();
1236 HRESULT detachAllUSBDevices(BOOL aDone);
1237 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1238 ComPtr<IProgress> &aProgress);
1239 HRESULT finishOnlineMergeMedium();
1240 HRESULT clipboardAreaRegister(const std::vector<com::Utf8Str> &aParms, ULONG *aID);
1241 HRESULT clipboardAreaUnregister(ULONG aID);
1242 HRESULT clipboardAreaAttach(ULONG aID);
1243 HRESULT clipboardAreaDetach(ULONG aID);
1244 HRESULT clipboardAreaGetMostRecent(ULONG *aID);
1245 HRESULT clipboardAreaGetRefCount(ULONG aID, ULONG *aRefCount);
1246 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1247 std::vector<com::Utf8Str> &aValues,
1248 std::vector<LONG64> &aTimestamps,
1249 std::vector<com::Utf8Str> &aFlags);
1250 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1251 const com::Utf8Str &aValue,
1252 LONG64 aTimestamp,
1253 const com::Utf8Str &aFlags);
1254 HRESULT lockMedia();
1255 HRESULT unlockMedia();
1256 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1257 ComPtr<IMediumAttachment> &aNewAttachment);
1258 HRESULT reportVmStatistics(ULONG aValidStats,
1259 ULONG aCpuUser,
1260 ULONG aCpuKernel,
1261 ULONG aCpuIdle,
1262 ULONG aMemTotal,
1263 ULONG aMemFree,
1264 ULONG aMemBalloon,
1265 ULONG aMemShared,
1266 ULONG aMemCache,
1267 ULONG aPagedTotal,
1268 ULONG aMemAllocTotal,
1269 ULONG aMemFreeTotal,
1270 ULONG aMemBalloonTotal,
1271 ULONG aMemSharedTotal,
1272 ULONG aVmNetRx,
1273 ULONG aVmNetTx);
1274 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1275 com::Utf8Str &aResult);
1276};
1277
1278// SessionMachine class
1279////////////////////////////////////////////////////////////////////////////////
1280
1281/**
1282 * @note Notes on locking objects of this class:
1283 * SessionMachine shares some data with the primary Machine instance (pointed
1284 * to by the |mPeer| member). In order to provide data consistency it also
1285 * shares its lock handle. This means that whenever you lock a SessionMachine
1286 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1287 * instance is also locked in the same lock mode. Keep it in mind.
1288 */
1289class ATL_NO_VTABLE SessionMachine :
1290 public Machine
1291{
1292public:
1293 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1294
1295 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1296
1297 DECLARE_PROTECT_FINAL_CONSTRUCT()
1298
1299 BEGIN_COM_MAP(SessionMachine)
1300 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1301 COM_INTERFACE_ENTRY(IMachine)
1302 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1303 COM_INTERFACE_ENTRY(IInternalMachineControl)
1304 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1305 END_COM_MAP()
1306
1307 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1308
1309 HRESULT FinalConstruct();
1310 void FinalRelease();
1311
1312 struct Uninit
1313 {
1314 enum Reason { Unexpected, Abnormal, Normal };
1315 };
1316
1317 // public initializer/uninitializer for internal purposes only
1318 HRESULT init(Machine *aMachine);
1319 void uninit() { uninit(Uninit::Unexpected); }
1320 void uninit(Uninit::Reason aReason);
1321
1322
1323 // util::Lockable interface
1324 RWLockHandle *lockHandle() const;
1325
1326 // public methods only for internal purposes
1327
1328 virtual bool i_isSessionMachine() const
1329 {
1330 return true;
1331 }
1332
1333#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1334 bool i_checkForDeath();
1335
1336 void i_getTokenId(Utf8Str &strTokenId);
1337#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1338 IToken *i_getToken();
1339#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1340 // getClientToken must be only used by callers who can guarantee that
1341 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1342 ClientToken *i_getClientToken();
1343
1344 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1345 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1346 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1347 IN_BSTR aGuestIp, LONG aGuestPort);
1348 HRESULT i_onStorageControllerChange(const com::Guid &aMachineId, const com::Utf8Str &aControllerName);
1349 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1350 HRESULT i_onVMProcessPriorityChange(VMProcPriority_T aPriority);
1351 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1352 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1353 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1354 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1355 HRESULT i_onVRDEServerChange(BOOL aRestart);
1356 HRESULT i_onRecordingChange(BOOL aEnable);
1357 HRESULT i_onUSBControllerChange();
1358 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1359 IVirtualBoxErrorInfo *aError,
1360 ULONG aMaskedIfs,
1361 const com::Utf8Str &aCaptureFilename);
1362 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1363 IVirtualBoxErrorInfo *aError);
1364 HRESULT i_onSharedFolderChange();
1365 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1366 HRESULT i_onClipboardFileTransferModeChange(BOOL aEnable);
1367 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1368 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1369 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1370 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1371
1372 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1373
1374 HRESULT i_lockMedia();
1375 HRESULT i_unlockMedia();
1376
1377 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1378
1379private:
1380
1381 // wrapped IInternalMachineControl properties
1382
1383 // wrapped IInternalMachineControl methods
1384 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1385 HRESULT updateState(MachineState_T aState);
1386 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1387 HRESULT endPowerUp(LONG aResult);
1388 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1389 HRESULT endPoweringDown(LONG aResult,
1390 const com::Utf8Str &aErrMsg);
1391 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1392 BOOL *aMatched,
1393 ULONG *aMaskedInterfaces);
1394 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1395 HRESULT detachUSBDevice(const com::Guid &aId,
1396 BOOL aDone);
1397 HRESULT autoCaptureUSBDevices();
1398 HRESULT detachAllUSBDevices(BOOL aDone);
1399 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1400 ComPtr<IProgress> &aProgress);
1401 HRESULT finishOnlineMergeMedium();
1402 HRESULT clipboardAreaRegister(const std::vector<com::Utf8Str> &aParms, ULONG *aID);
1403 HRESULT clipboardAreaUnregister(ULONG aID);
1404 HRESULT clipboardAreaAttach(ULONG aID);
1405 HRESULT clipboardAreaDetach(ULONG aID);
1406 HRESULT clipboardAreaGetMostRecent(ULONG *aID);
1407 HRESULT clipboardAreaGetRefCount(ULONG aID, ULONG *aRefCount);
1408 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1409 std::vector<com::Utf8Str> &aValues,
1410 std::vector<LONG64> &aTimestamps,
1411 std::vector<com::Utf8Str> &aFlags);
1412 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1413 const com::Utf8Str &aValue,
1414 LONG64 aTimestamp,
1415 const com::Utf8Str &aFlags);
1416 HRESULT lockMedia();
1417 HRESULT unlockMedia();
1418 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1419 ComPtr<IMediumAttachment> &aNewAttachment);
1420 HRESULT reportVmStatistics(ULONG aValidStats,
1421 ULONG aCpuUser,
1422 ULONG aCpuKernel,
1423 ULONG aCpuIdle,
1424 ULONG aMemTotal,
1425 ULONG aMemFree,
1426 ULONG aMemBalloon,
1427 ULONG aMemShared,
1428 ULONG aMemCache,
1429 ULONG aPagedTotal,
1430 ULONG aMemAllocTotal,
1431 ULONG aMemFreeTotal,
1432 ULONG aMemBalloonTotal,
1433 ULONG aMemSharedTotal,
1434 ULONG aVmNetRx,
1435 ULONG aVmNetTx);
1436 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1437 com::Utf8Str &aResult);
1438
1439
1440 struct ConsoleTaskData
1441 {
1442 ConsoleTaskData()
1443 : mLastState(MachineState_Null),
1444 mDeleteSnapshotInfo(NULL)
1445 { }
1446
1447 MachineState_T mLastState;
1448 ComObjPtr<Progress> mProgress;
1449
1450 // used when deleting online snaphshot
1451 void *mDeleteSnapshotInfo;
1452 };
1453
1454 class SaveStateTask;
1455 class SnapshotTask;
1456 class TakeSnapshotTask;
1457 class DeleteSnapshotTask;
1458 class RestoreSnapshotTask;
1459
1460 void i_saveStateHandler(SaveStateTask &aTask);
1461
1462 // Override some functionality for SessionMachine, this is where the
1463 // real action happens (the Machine methods are just dummies).
1464 HRESULT saveState(ComPtr<IProgress> &aProgress);
1465 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1466 HRESULT discardSavedState(BOOL aFRemoveFile);
1467 HRESULT takeSnapshot(const com::Utf8Str &aName,
1468 const com::Utf8Str &aDescription,
1469 BOOL aPause,
1470 com::Guid &aId,
1471 ComPtr<IProgress> &aProgress);
1472 HRESULT deleteSnapshot(const com::Guid &aId,
1473 ComPtr<IProgress> &aProgress);
1474 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1475 ComPtr<IProgress> &aProgress);
1476 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1477 const com::Guid &aEndId,
1478 ComPtr<IProgress> &aProgress);
1479 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1480 ComPtr<IProgress> &aProgress);
1481
1482 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1483
1484 void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
1485 static void i_takeSnapshotProgressCancelCallback(void *pvUser);
1486 HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
1487 HRESULT i_deleteSnapshot(const com::Guid &aStartId,
1488 const com::Guid &aEndId,
1489 BOOL aDeleteAllChildren,
1490 ComPtr<IProgress> &aProgress);
1491 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1492 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1493
1494 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1495 const Guid &machineId,
1496 const Guid &snapshotId,
1497 bool fOnlineMergePossible,
1498 MediumLockList *aVMMALockList,
1499 ComObjPtr<Medium> &aSource,
1500 ComObjPtr<Medium> &aTarget,
1501 bool &fMergeForward,
1502 ComObjPtr<Medium> &pParentForTarget,
1503 MediumLockList * &aChildrenToReparent,
1504 bool &fNeedOnlineMerge,
1505 MediumLockList * &aMediumLockList,
1506 ComPtr<IToken> &aHDLockToken);
1507 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1508 const ComObjPtr<Medium> &aSource,
1509 MediumLockList *aChildrenToReparent,
1510 bool fNeedsOnlineMerge,
1511 MediumLockList *aMediumLockList,
1512 const ComPtr<IToken> &aHDLockToken,
1513 const Guid &aMediumId,
1514 const Guid &aSnapshotId);
1515 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1516 const ComObjPtr<Medium> &aSource,
1517 const ComObjPtr<Medium> &aTarget,
1518 bool fMergeForward,
1519 const ComObjPtr<Medium> &pParentForTarget,
1520 MediumLockList *aChildrenToReparent,
1521 MediumLockList *aMediumLockList,
1522 ComObjPtr<Progress> &aProgress,
1523 bool *pfNeedsMachineSaveSettings);
1524
1525 HRESULT i_setMachineState(MachineState_T aMachineState);
1526 HRESULT i_updateMachineStateOnClient();
1527
1528 bool mRemoveSavedState;
1529
1530 ConsoleTaskData mConsoleTaskData;
1531
1532 /** client token for this machine */
1533 ClientToken *mClientToken;
1534
1535 int miNATNetworksStarted;
1536
1537 AUTHLIBRARYCONTEXT mAuthLibCtx;
1538};
1539
1540// SnapshotMachine class
1541////////////////////////////////////////////////////////////////////////////////
1542
1543/**
1544 * @note Notes on locking objects of this class:
1545 * SnapshotMachine shares some data with the primary Machine instance (pointed
1546 * to by the |mPeer| member). In order to provide data consistency it also
1547 * shares its lock handle. This means that whenever you lock a SessionMachine
1548 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1549 * instance is also locked in the same lock mode. Keep it in mind.
1550 */
1551class ATL_NO_VTABLE SnapshotMachine :
1552 public Machine
1553{
1554public:
1555 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1556
1557 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1558
1559 DECLARE_PROTECT_FINAL_CONSTRUCT()
1560
1561 BEGIN_COM_MAP(SnapshotMachine)
1562 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1563 COM_INTERFACE_ENTRY(IMachine)
1564 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1565 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1566 END_COM_MAP()
1567
1568 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1569
1570 HRESULT FinalConstruct();
1571 void FinalRelease();
1572
1573 // public initializer/uninitializer for internal purposes only
1574 HRESULT init(SessionMachine *aSessionMachine,
1575 IN_GUID aSnapshotId,
1576 const Utf8Str &aStateFilePath);
1577 HRESULT initFromSettings(Machine *aMachine,
1578 const settings::Hardware &hardware,
1579 const settings::Debugging *pDbg,
1580 const settings::Autostart *pAutostart,
1581 IN_GUID aSnapshotId,
1582 const Utf8Str &aStateFilePath);
1583 void uninit();
1584
1585 // util::Lockable interface
1586 RWLockHandle *lockHandle() const;
1587
1588 // public methods only for internal purposes
1589
1590 virtual bool i_isSnapshotMachine() const
1591 {
1592 return true;
1593 }
1594
1595 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1596
1597 // unsafe inline public methods for internal purposes only (ensure there is
1598 // a caller and a read lock before calling them!)
1599
1600 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1601
1602private:
1603
1604 Guid mSnapshotId;
1605 /** This field replaces mPeer for SessionMachine instances, as having
1606 * a peer reference is plain meaningless and causes many subtle problems
1607 * with saving settings and the like. */
1608 Machine * const mMachine;
1609
1610 friend class Snapshot;
1611};
1612
1613// third party methods that depend on SnapshotMachine definition
1614
1615inline const Guid &Machine::i_getSnapshotId() const
1616{
1617 return (i_isSnapshotMachine())
1618 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1619 : Guid::Empty;
1620}
1621
1622
1623#endif /* !MAIN_INCLUDED_MachineImpl_h */
1624/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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