VirtualBox

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

Last change on this file since 72476 was 72476, checked in by vboxsync, 6 years ago

Main/Appliance: Teach importing new tricks: importing to specific location (by settings file name or base folder) and also importing straight into a group. Lots of cleanup and minor fixing (bad code quality due to lots of copy/paste, and what's worse is that the original code was broken already, using the variables inconsistently), plus some smallish coding style cleaup. Much more needed. Also fixed the incomplete use of the VM name on expert (the one in the VBox XML was not changed, and it's the preferred name on import).
VBoxManage: small updates to reflect the new features (and actually offer setting the VM name on export, which is something the GUI could do for a long time).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.4 KB
Line 
1/* $Id: MachineImpl.h 72476 2018-06-07 13:49:48Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 ____H_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "AuthLibrary.h"
22#include "VirtualBoxBase.h"
23#include "SnapshotImpl.h"
24#include "ProgressImpl.h"
25#include "VRDEServerImpl.h"
26#include "MediumAttachmentImpl.h"
27#include "PCIDeviceAttachmentImpl.h"
28#include "MediumLock.h"
29#include "NetworkAdapterImpl.h"
30#include "AudioAdapterImpl.h"
31#include "SerialPortImpl.h"
32#include "ParallelPortImpl.h"
33#include "BIOSSettingsImpl.h"
34#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
35#include "USBControllerImpl.h" // required for MachineImpl.h to compile on Windows
36#include "BandwidthControlImpl.h"
37#include "BandwidthGroupImpl.h"
38#ifdef VBOX_WITH_RESOURCE_USAGE_API
39# include "Performance.h"
40# include "PerformanceImpl.h"
41# include "ThreadTask.h"
42#endif
43
44// generated header
45#include "SchemaDefs.h"
46
47#include "VBox/com/ErrorInfo.h"
48
49#include <iprt/file.h>
50#include <iprt/thread.h>
51#include <iprt/time.h>
52
53#include <list>
54#include <vector>
55
56#include "MachineWrap.h"
57
58/** @todo r=klaus after moving the various Machine settings structs to
59 * MachineImpl.cpp it should be possible to eliminate this include. */
60#include <VBox/settings.h>
61
62// defines
63////////////////////////////////////////////////////////////////////////////////
64
65// helper declarations
66////////////////////////////////////////////////////////////////////////////////
67
68class Progress;
69class ProgressProxy;
70class Keyboard;
71class Mouse;
72class Display;
73class MachineDebugger;
74class USBController;
75class USBDeviceFilters;
76class Snapshot;
77class SharedFolder;
78class HostUSBDevice;
79class StorageController;
80class SessionMachine;
81#ifdef VBOX_WITH_UNATTENDED
82class Unattended;
83#endif
84
85// Machine class
86////////////////////////////////////////////////////////////////////////////////
87//
88class ATL_NO_VTABLE Machine :
89 public MachineWrap
90{
91
92public:
93
94 enum StateDependency
95 {
96 AnyStateDep = 0,
97 MutableStateDep,
98 MutableOrSavedStateDep,
99 MutableOrRunningStateDep,
100 MutableOrSavedOrRunningStateDep,
101 };
102
103 /**
104 * Internal machine data.
105 *
106 * Only one instance of this data exists per every machine -- it is shared
107 * by the Machine, SessionMachine and all SnapshotMachine instances
108 * associated with the given machine using the util::Shareable template
109 * through the mData variable.
110 *
111 * @note |const| members are persistent during lifetime so can be
112 * accessed without locking.
113 *
114 * @note There is no need to lock anything inside init() or uninit()
115 * methods, because they are always serialized (see AutoCaller).
116 */
117 struct Data
118 {
119 /**
120 * Data structure to hold information about sessions opened for the
121 * given machine.
122 */
123 struct Session
124 {
125 /** Type of lock which created this session */
126 LockType_T mLockType;
127
128 /** Control of the direct session opened by lockMachine() */
129 ComPtr<IInternalSessionControl> mDirectControl;
130
131 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
132
133 /** list of controls of all opened remote sessions */
134 RemoteControlList mRemoteControls;
135
136 /** launchVMProcess() and OnSessionEnd() progress indicator */
137 ComObjPtr<ProgressProxy> mProgress;
138
139 /**
140 * PID of the session object that must be passed to openSession()
141 * to finalize the launchVMProcess() request (i.e., PID of the
142 * process created by launchVMProcess())
143 */
144 RTPROCESS mPID;
145
146 /** Current session state */
147 SessionState_T mState;
148
149 /** Session name string (of the primary session) */
150 Utf8Str mName;
151
152 /** Session machine object */
153 ComObjPtr<SessionMachine> mMachine;
154
155 /** Medium object lock collection. */
156 MediumLockListMap mLockedMedia;
157 };
158
159 Data();
160 ~Data();
161
162 const Guid mUuid;
163 BOOL mRegistered;
164
165 Utf8Str m_strConfigFile;
166 Utf8Str m_strConfigFileFull;
167
168 // machine settings XML file
169 settings::MachineConfigFile *pMachineConfigFile;
170 uint32_t flModifications;
171 bool m_fAllowStateModification;
172
173 BOOL mAccessible;
174 com::ErrorInfo mAccessError;
175
176 MachineState_T mMachineState;
177 RTTIMESPEC mLastStateChange;
178
179 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
180 uint32_t mMachineStateDeps;
181 RTSEMEVENTMULTI mMachineStateDepsSem;
182 uint32_t mMachineStateChangePending;
183
184 BOOL mCurrentStateModified;
185 /** Guest properties have been modified and need saving since the
186 * machine was started, or there are transient properties which need
187 * deleting and the machine is being shut down. */
188 BOOL mGuestPropertiesModified;
189
190 Session mSession;
191
192 ComObjPtr<Snapshot> mFirstSnapshot;
193 ComObjPtr<Snapshot> mCurrentSnapshot;
194
195 // list of files to delete in Delete(); this list is filled by Unregister()
196 std::list<Utf8Str> llFilesToDelete;
197 };
198
199 /**
200 * Saved state data.
201 *
202 * It's actually only the state file path string, but it needs to be
203 * separate from Data, because Machine and SessionMachine instances
204 * share it, while SnapshotMachine does not.
205 *
206 * The data variable is |mSSData|.
207 */
208 struct SSData
209 {
210 Utf8Str strStateFilePath;
211 };
212
213 /**
214 * User changeable machine data.
215 *
216 * This data is common for all machine snapshots, i.e. it is shared
217 * by all SnapshotMachine instances associated with the given machine
218 * using the util::Backupable template through the |mUserData| variable.
219 *
220 * SessionMachine instances can alter this data and discard changes.
221 *
222 * @note There is no need to lock anything inside init() or uninit()
223 * methods, because they are always serialized (see AutoCaller).
224 */
225 struct UserData
226 {
227 settings::MachineUserData s;
228 };
229
230 /**
231 * Hardware data.
232 *
233 * This data is unique for a machine and for every machine snapshot.
234 * Stored using the util::Backupable template in the |mHWData| variable.
235 *
236 * SessionMachine instances can alter this data and discard changes.
237 *
238 * @todo r=klaus move all "pointer" objects out of this struct, as they
239 * need non-obvious handling when creating a new session or when taking
240 * a snapshot. Better do this right straight away, not relying on the
241 * template magic which doesn't work right in this case.
242 */
243 struct HWData
244 {
245 /**
246 * Data structure to hold information about a guest property.
247 */
248 struct GuestProperty {
249 /** Property value */
250 Utf8Str strValue;
251 /** Property timestamp */
252 LONG64 mTimestamp;
253 /** Property flags */
254 ULONG mFlags;
255 };
256
257 HWData();
258 ~HWData();
259
260 Bstr mHWVersion;
261 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
262 ULONG mMemorySize;
263 ULONG mMemoryBalloonSize;
264 BOOL mPageFusionEnabled;
265 GraphicsControllerType_T mGraphicsControllerType;
266 ULONG mVRAMSize;
267 ULONG mVideoCaptureWidth;
268 ULONG mVideoCaptureHeight;
269 ULONG mVideoCaptureRate;
270 ULONG mVideoCaptureFPS;
271 ULONG mVideoCaptureMaxTime;
272 ULONG mVideoCaptureMaxFileSize;
273 Utf8Str mVideoCaptureOptions;
274 Utf8Str mVideoCaptureFile;
275 BOOL mVideoCaptureEnabled;
276 BOOL maVideoCaptureScreens[SchemaDefs::MaxGuestMonitors];
277 ULONG mMonitorCount;
278 BOOL mHWVirtExEnabled;
279 BOOL mHWVirtExNestedPagingEnabled;
280 BOOL mHWVirtExLargePagesEnabled;
281 BOOL mHWVirtExVPIDEnabled;
282 BOOL mHWVirtExUXEnabled;
283 BOOL mHWVirtExForceEnabled;
284 BOOL mHWVirtExUseNativeApi;
285 BOOL mAccelerate2DVideoEnabled;
286 BOOL mPAEEnabled;
287 settings::Hardware::LongModeType mLongMode;
288 BOOL mTripleFaultReset;
289 BOOL mAPIC;
290 BOOL mX2APIC;
291 BOOL mIBPBOnVMExit;
292 BOOL mIBPBOnVMEntry;
293 BOOL mSpecCtrl;
294 BOOL mSpecCtrlByHost;
295 BOOL mNestedHWVirt;
296 ULONG mCPUCount;
297 BOOL mCPUHotPlugEnabled;
298 ULONG mCpuExecutionCap;
299 uint32_t mCpuIdPortabilityLevel;
300 Utf8Str mCpuProfile;
301 BOOL mAccelerate3DEnabled;
302 BOOL mHPETEnabled;
303
304 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
305
306 std::list<settings::CpuIdLeaf> mCpuIdLeafList;
307
308 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
309
310 typedef std::list<ComObjPtr<SharedFolder> > SharedFolderList;
311 SharedFolderList mSharedFolders;
312
313 ClipboardMode_T mClipboardMode;
314 DnDMode_T mDnDMode;
315
316 typedef std::map<Utf8Str, GuestProperty> GuestPropertyMap;
317 GuestPropertyMap mGuestProperties;
318
319 FirmwareType_T mFirmwareType;
320 KeyboardHIDType_T mKeyboardHIDType;
321 PointingHIDType_T mPointingHIDType;
322 ChipsetType_T mChipsetType;
323 ParavirtProvider_T mParavirtProvider;
324 Utf8Str mParavirtDebug;
325 BOOL mEmulatedUSBCardReaderEnabled;
326
327 BOOL mIOCacheEnabled;
328 ULONG mIOCacheSize;
329
330 typedef std::list<ComObjPtr<PCIDeviceAttachment> > PCIDeviceAssignmentList;
331 PCIDeviceAssignmentList mPCIDeviceAssignments;
332
333 settings::Debugging mDebugging;
334 settings::Autostart mAutostart;
335
336 Utf8Str mDefaultFrontend;
337 };
338
339 typedef std::list<ComObjPtr<MediumAttachment> > MediumAttachmentList;
340
341 DECLARE_EMPTY_CTOR_DTOR(Machine)
342
343 HRESULT FinalConstruct();
344 void FinalRelease();
345
346 // public initializer/uninitializer for internal purposes only:
347
348 // initializer for creating a new, empty machine
349 HRESULT init(VirtualBox *aParent,
350 const Utf8Str &strConfigFile,
351 const Utf8Str &strName,
352 const StringsList &llGroups,
353 GuestOSType *aOsType,
354 const Guid &aId,
355 bool fForceOverwrite,
356 bool fDirectoryIncludesUUID);
357
358 // initializer for loading existing machine XML (either registered or not)
359 HRESULT initFromSettings(VirtualBox *aParent,
360 const Utf8Str &strConfigFile,
361 const Guid *aId);
362
363 // initializer for machine config in memory (OVF import)
364 HRESULT init(VirtualBox *aParent,
365 const Utf8Str &strName,
366 const Utf8Str &strSettingsFilename,
367 const settings::MachineConfigFile &config);
368
369 void uninit();
370
371#ifdef VBOX_WITH_RESOURCE_USAGE_API
372 // Needed from VirtualBox, for the delayed metrics cleanup.
373 void i_unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
374#endif /* VBOX_WITH_RESOURCE_USAGE_API */
375
376protected:
377 HRESULT initImpl(VirtualBox *aParent,
378 const Utf8Str &strConfigFile);
379 HRESULT initDataAndChildObjects();
380 HRESULT i_registeredInit();
381 HRESULT i_tryCreateMachineConfigFile(bool fForceOverwrite);
382 void uninitDataAndChildObjects();
383
384public:
385
386
387 // public methods only for internal purposes
388
389 virtual bool i_isSnapshotMachine() const
390 {
391 return false;
392 }
393
394 virtual bool i_isSessionMachine() const
395 {
396 return false;
397 }
398
399 /**
400 * Override of the default locking class to be used for validating lock
401 * order with the standard member lock handle.
402 */
403 virtual VBoxLockingClass getLockingClass() const
404 {
405 return LOCKCLASS_MACHINEOBJECT;
406 }
407
408 /// @todo (dmik) add lock and make non-inlined after revising classes
409 // that use it. Note: they should enter Machine lock to keep the returned
410 // information valid!
411 bool i_isRegistered() { return !!mData->mRegistered; }
412
413 // unsafe inline public methods for internal purposes only (ensure there is
414 // a caller and a read lock before calling them!)
415
416 /**
417 * Returns the VirtualBox object this machine belongs to.
418 *
419 * @note This method doesn't check this object's readiness. Intended to be
420 * used by ready Machine children (whose readiness is bound to the parent's
421 * one) or after doing addCaller() manually.
422 */
423 VirtualBox* i_getVirtualBox() const { return mParent; }
424
425 /**
426 * Checks if this machine is accessible, without attempting to load the
427 * config file.
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 bool i_isAccessible() const { return !!mData->mAccessible; }
434
435 /**
436 * Returns this machine ID.
437 *
438 * @note This method doesn't check this object's readiness. Intended to be
439 * used by ready Machine children (whose readiness is bound to the parent's
440 * one) or after adding a caller manually.
441 */
442 const Guid& i_getId() const { return mData->mUuid; }
443
444 /**
445 * Returns the snapshot ID this machine represents or an empty UUID if this
446 * instance is not SnapshotMachine.
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 inline const Guid& i_getSnapshotId() const;
453
454 /**
455 * Returns this machine's full settings file path.
456 *
457 * @note This method doesn't lock this object or check its readiness.
458 * Intended to be used only after doing addCaller() manually and locking it
459 * for reading.
460 */
461 const Utf8Str& i_getSettingsFileFull() const { return mData->m_strConfigFileFull; }
462
463 /**
464 * Returns this machine name.
465 *
466 * @note This method doesn't lock this object or check its readiness.
467 * Intended to be used only after doing addCaller() manually and locking it
468 * for reading.
469 */
470 const Utf8Str& i_getName() const { return mUserData->s.strName; }
471
472 enum
473 {
474 IsModified_MachineData = 0x0001,
475 IsModified_Storage = 0x0002,
476 IsModified_NetworkAdapters = 0x0008,
477 IsModified_SerialPorts = 0x0010,
478 IsModified_ParallelPorts = 0x0020,
479 IsModified_VRDEServer = 0x0040,
480 IsModified_AudioAdapter = 0x0080,
481 IsModified_USB = 0x0100,
482 IsModified_BIOS = 0x0200,
483 IsModified_SharedFolders = 0x0400,
484 IsModified_Snapshots = 0x0800,
485 IsModified_BandwidthControl = 0x1000
486 };
487
488 /**
489 * Returns various information about this machine.
490 *
491 * @note This method doesn't lock this object or check its readiness.
492 * Intended to be used only after doing addCaller() manually and locking it
493 * for reading.
494 */
495 Utf8Str i_getOSTypeId() const { return mUserData->s.strOsType; }
496 ChipsetType_T i_getChipsetType() const { return mHWData->mChipsetType; }
497 ParavirtProvider_T i_getParavirtProvider() const { return mHWData->mParavirtProvider; }
498 Utf8Str i_getParavirtDebug() const { return mHWData->mParavirtDebug; }
499
500 void i_setModified(uint32_t fl, bool fAllowStateModification = true);
501 void i_setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
502
503 bool i_isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
504 void i_allowStateModification() { mData->m_fAllowStateModification = true; }
505 void i_disallowStateModification() { mData->m_fAllowStateModification = false; }
506
507 const StringsList &i_getGroups() const { return mUserData->s.llGroups; }
508
509 // callback handlers
510 virtual HRESULT i_onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
511 virtual HRESULT i_onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
512 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */,
513 IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
514 virtual HRESULT i_onAudioAdapterChange(IAudioAdapter * /* audioAdapter */) { return S_OK; }
515 virtual HRESULT i_onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
516 virtual HRESULT i_onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
517 virtual HRESULT i_onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
518 virtual HRESULT i_onUSBControllerChange() { return S_OK; }
519 virtual HRESULT i_onStorageControllerChange() { return S_OK; }
520 virtual HRESULT i_onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
521 virtual HRESULT i_onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
522 virtual HRESULT i_onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
523 virtual HRESULT i_onSharedFolderChange() { return S_OK; }
524 virtual HRESULT i_onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
525 virtual HRESULT i_onDnDModeChange(DnDMode_T /* aDnDMode */) { return S_OK; }
526 virtual HRESULT i_onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
527 virtual HRESULT i_onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */,
528 BOOL /* silent */) { return S_OK; }
529 virtual HRESULT i_onVideoCaptureChange() { return S_OK; }
530
531 HRESULT i_saveRegistryEntry(settings::MachineRegistryEntry &data);
532
533 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
534 void i_copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
535
536 void i_getLogFolder(Utf8Str &aLogFolder);
537 Utf8Str i_getLogFilename(ULONG idx);
538 Utf8Str i_getHardeningLogFilename(void);
539
540 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
541
542 void i_getDefaultVideoCaptureFile(Utf8Str &strFile);
543
544 bool i_isUSBControllerPresent();
545
546 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
547 const Utf8Str &strType,
548 const Utf8Str &strEnvironment,
549 ProgressProxy *aProgress);
550
551 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
552 {
553 HRESULT rc;
554 *directControl = mData->mSession.mDirectControl;
555
556 if (!*directControl)
557 rc = E_ACCESSDENIED;
558 else
559 rc = S_OK;
560
561 return rc;
562 }
563
564 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
565 ComPtr<IInternalSessionControl> *aControl = NULL,
566 bool aRequireVM = false,
567 bool aAllowClosing = false);
568 bool i_isSessionSpawning();
569
570 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
571 ComPtr<IInternalSessionControl> *aControl = NULL)
572 { return i_isSessionOpen(aMachine, aControl, false /* aRequireVM */, true /* aAllowClosing */); }
573
574 bool i_isSessionOpenVM(ComObjPtr<SessionMachine> &aMachine,
575 ComPtr<IInternalSessionControl> *aControl = NULL)
576 { return i_isSessionOpen(aMachine, aControl, true /* aRequireVM */, false /* aAllowClosing */); }
577
578 bool i_checkForSpawnFailure();
579
580 HRESULT i_prepareRegister();
581
582 HRESULT i_getSharedFolder(CBSTR aName,
583 ComObjPtr<SharedFolder> &aSharedFolder,
584 bool aSetError = false)
585 {
586 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
587 return i_findSharedFolder(aName, aSharedFolder, aSetError);
588 }
589
590 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
591 MachineState_T *aState = NULL,
592 BOOL *aRegistered = NULL);
593 void i_releaseStateDependency();
594
595 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
596 ComObjPtr<StorageController> &aStorageController,
597 bool aSetError = false);
598
599 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
600 MediumAttachmentList &aAttachments);
601
602 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
603 ComObjPtr<USBController> &aUSBController,
604 bool aSetError = false);
605
606 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
607 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
608 bool fSetError = false)
609 {
610 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
611 pBandwidthGroup,
612 fSetError);
613 }
614
615 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
616
617protected:
618
619 class ClientToken;
620
621 HRESULT i_checkStateDependency(StateDependency aDepType);
622
623 Machine *i_getMachine();
624
625 void i_ensureNoStateDependencies();
626
627 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
628
629 HRESULT i_findSharedFolder(const Utf8Str &aName,
630 ComObjPtr<SharedFolder> &aSharedFolder,
631 bool aSetError = false);
632
633 HRESULT i_loadSettings(bool aRegistered);
634 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
635 const Guid *puuidRegistry);
636 HRESULT i_loadSnapshot(const settings::Snapshot &data,
637 const Guid &aCurSnapshotId,
638 Snapshot *aParentSnapshot);
639 HRESULT i_loadHardware(const Guid *puuidRegistry,
640 const Guid *puuidSnapshot,
641 const settings::Hardware &data,
642 const settings::Debugging *pDbg,
643 const settings::Autostart *pAutostart);
644 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
645 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
646 HRESULT i_loadStorageControllers(const settings::Storage &data,
647 const Guid *puuidRegistry,
648 const Guid *puuidSnapshot);
649 HRESULT i_loadStorageDevices(StorageController *aStorageController,
650 const settings::StorageController &data,
651 const Guid *puuidRegistry,
652 const Guid *puuidSnapshot);
653
654 HRESULT i_findSnapshotById(const Guid &aId,
655 ComObjPtr<Snapshot> &aSnapshot,
656 bool aSetError = false);
657 HRESULT i_findSnapshotByName(const Utf8Str &strName,
658 ComObjPtr<Snapshot> &aSnapshot,
659 bool aSetError = false);
660
661 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
662
663 enum
664 {
665 /* flags for #saveSettings() */
666 SaveS_ResetCurStateModified = 0x01,
667 SaveS_Force = 0x04,
668 /* flags for #saveStateSettings() */
669 SaveSTS_CurStateModified = 0x20,
670 SaveSTS_StateFilePath = 0x40,
671 SaveSTS_StateTimeStamp = 0x80
672 };
673
674 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
675 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
676
677 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
678 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
679 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
680 settings::Autostart *pAutostart);
681 HRESULT i_saveStorageControllers(settings::Storage &data);
682 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
683 settings::StorageController &data);
684 HRESULT i_saveStateSettings(int aFlags);
685
686 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
687
688 HRESULT i_createImplicitDiffs(IProgress *aProgress,
689 ULONG aWeight,
690 bool aOnline);
691 HRESULT i_deleteImplicitDiffs(bool aOnline);
692
693 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
694 const Utf8Str &aControllerName,
695 LONG aControllerPort,
696 LONG aDevice);
697 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
698 ComObjPtr<Medium> pMedium);
699 MediumAttachment* i_findAttachment(const MediumAttachmentList &ll,
700 Guid &id);
701
702 HRESULT i_detachDevice(MediumAttachment *pAttach,
703 AutoWriteLock &writeLock,
704 Snapshot *pSnapshot);
705
706 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
707 Snapshot *pSnapshot,
708 CleanupMode_T cleanupMode,
709 MediaList &llMedia);
710
711 void i_commitMedia(bool aOnline = false);
712 void i_rollbackMedia();
713
714 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
715
716 void i_rollback(bool aNotify);
717 void i_commit();
718 void i_copyFrom(Machine *aThat);
719 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
720
721 Utf8Str i_getExtraData(const Utf8Str &strKey);
722
723#ifdef VBOX_WITH_GUEST_PROPS
724 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
725 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
726 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
727 const com::Utf8Str &aFlags, bool fDelete);
728 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
729 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
730 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
731 const com::Utf8Str &aFlags, bool fDelete);
732 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
733 std::vector<com::Utf8Str> &aNames,
734 std::vector<com::Utf8Str> &aValues,
735 std::vector<LONG64> &aTimestamps,
736 std::vector<com::Utf8Str> &aFlags);
737 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
738 std::vector<com::Utf8Str> &aNames,
739 std::vector<com::Utf8Str> &aValues,
740 std::vector<LONG64> &aTimestamps,
741 std::vector<com::Utf8Str> &aFlags);
742
743#endif /* VBOX_WITH_GUEST_PROPS */
744
745#ifdef VBOX_WITH_RESOURCE_USAGE_API
746 void i_getDiskList(MediaList &list);
747 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
748
749 pm::CollectorGuest *mCollectorGuest;
750#endif /* VBOX_WITH_RESOURCE_USAGE_API */
751
752 Machine * const mPeer;
753
754 VirtualBox * const mParent;
755
756 Shareable<Data> mData;
757 Shareable<SSData> mSSData;
758
759 Backupable<UserData> mUserData;
760 Backupable<HWData> mHWData;
761
762 /**
763 * Hard disk and other media data.
764 *
765 * The usage policy is the same as for mHWData, but a separate field
766 * is necessary because hard disk data requires different procedures when
767 * taking or deleting snapshots, etc.
768 *
769 * @todo r=klaus change this to a regular list and use the normal way to
770 * handle the settings when creating a session or taking a snapshot.
771 * Same thing applies to mStorageControllers and mUSBControllers.
772 */
773 Backupable<MediumAttachmentList> mMediumAttachments;
774
775 // the following fields need special backup/rollback/commit handling,
776 // so they cannot be a part of HWData
777
778 const ComObjPtr<VRDEServer> mVRDEServer;
779 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
780 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
781 const ComObjPtr<AudioAdapter> mAudioAdapter;
782 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
783 const ComObjPtr<BIOSSettings> mBIOSSettings;
784 const ComObjPtr<BandwidthControl> mBandwidthControl;
785
786 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
787 NetworkAdapterVector mNetworkAdapters;
788
789 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
790 Backupable<StorageControllerList> mStorageControllers;
791
792 typedef std::list<ComObjPtr<USBController> > USBControllerList;
793 Backupable<USBControllerList> mUSBControllers;
794
795 uint64_t uRegistryNeedsSaving;
796
797 /**
798 * Abstract base class for all Machine or SessionMachine related
799 * asynchronous tasks. This is necessary since RTThreadCreate cannot call
800 * a (non-static) method as its thread function, so instead we have it call
801 * the static Machine::taskHandler, which then calls the handler() method
802 * in here (implemented by the subclasses).
803 */
804 class Task : public ThreadTask
805 {
806 public:
807 Task(Machine *m, Progress *p, const Utf8Str &t)
808 : ThreadTask(t),
809 m_pMachine(m),
810 m_machineCaller(m),
811 m_pProgress(p),
812 m_machineStateBackup(m->mData->mMachineState) // save the current machine state
813 {}
814 virtual ~Task(){}
815
816 void modifyBackedUpState(MachineState_T s)
817 {
818 *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
819 }
820
821 ComObjPtr<Machine> m_pMachine;
822 AutoCaller m_machineCaller;
823 ComObjPtr<Progress> m_pProgress;
824 const MachineState_T m_machineStateBackup;
825 };
826
827 class DeleteConfigTask;
828 void i_deleteConfigHandler(DeleteConfigTask &task);
829
830 friend class SessionMachine;
831 friend class SnapshotMachine;
832 friend class Appliance;
833 friend class VirtualBox;
834
835 friend class MachineCloneVM;
836 friend class MachineMoveVM;
837private:
838 // wrapped IMachine properties
839 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
840 HRESULT getIcon(std::vector<BYTE> &aIcon);
841 HRESULT setIcon(const std::vector<BYTE> &aIcon);
842 HRESULT getAccessible(BOOL *aAccessible);
843 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
844 HRESULT getName(com::Utf8Str &aName);
845 HRESULT setName(const com::Utf8Str &aName);
846 HRESULT getDescription(com::Utf8Str &aDescription);
847 HRESULT setDescription(const com::Utf8Str &aDescription);
848 HRESULT getId(com::Guid &aId);
849 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
850 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
851 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
852 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
853 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
854 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
855 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
856 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
857 HRESULT getCPUCount(ULONG *aCPUCount);
858 HRESULT setCPUCount(ULONG aCPUCount);
859 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
860 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
861 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
862 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
863 HRESULT getCPUIDPortabilityLevel(ULONG *aCPUIDPortabilityLevel);
864 HRESULT setCPUIDPortabilityLevel(ULONG aCPUIDPortabilityLevel);
865 HRESULT getCPUProfile(com::Utf8Str &aCPUProfile);
866 HRESULT setCPUProfile(const com::Utf8Str &aCPUProfile);
867 HRESULT getMemorySize(ULONG *aMemorySize);
868 HRESULT setMemorySize(ULONG aMemorySize);
869 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
870 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
871 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
872 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
873 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
874 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
875 HRESULT getVRAMSize(ULONG *aVRAMSize);
876 HRESULT setVRAMSize(ULONG aVRAMSize);
877 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
878 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
879 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
880 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
881 HRESULT getMonitorCount(ULONG *aMonitorCount);
882 HRESULT setMonitorCount(ULONG aMonitorCount);
883 HRESULT getVideoCaptureEnabled(BOOL *aVideoCaptureEnabled);
884 HRESULT setVideoCaptureEnabled(BOOL aVideoCaptureEnabled);
885 HRESULT getVideoCaptureScreens(std::vector<BOOL> &aVideoCaptureScreens);
886 HRESULT setVideoCaptureScreens(const std::vector<BOOL> &aVideoCaptureScreens);
887 HRESULT getVideoCaptureFile(com::Utf8Str &aVideoCaptureFile);
888 HRESULT setVideoCaptureFile(const com::Utf8Str &aVideoCaptureFile);
889 HRESULT getVideoCaptureWidth(ULONG *aVideoCaptureWidth);
890 HRESULT setVideoCaptureWidth(ULONG aVideoCaptureWidth);
891 HRESULT getVideoCaptureHeight(ULONG *aVideoCaptureHeight);
892 HRESULT setVideoCaptureHeight(ULONG aVideoCaptureHeight);
893 HRESULT getVideoCaptureRate(ULONG *aVideoCaptureRate);
894 HRESULT setVideoCaptureRate(ULONG aVideoCaptureRate);
895 HRESULT getVideoCaptureFPS(ULONG *aVideoCaptureFPS);
896 HRESULT setVideoCaptureFPS(ULONG aVideoCaptureFPS);
897 HRESULT getVideoCaptureMaxTime(ULONG *aVideoCaptureMaxTime);
898 HRESULT setVideoCaptureMaxTime(ULONG aVideoCaptureMaxTime);
899 HRESULT getVideoCaptureMaxFileSize(ULONG *aVideoCaptureMaxFileSize);
900 HRESULT setVideoCaptureMaxFileSize(ULONG aVideoCaptureMaxFileSize);
901 HRESULT getVideoCaptureOptions(com::Utf8Str &aVideoCaptureOptions);
902 HRESULT setVideoCaptureOptions(const com::Utf8Str &aVideoCaptureOptions);
903 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
904 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
905 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
906 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
907 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
908 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
909 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
910 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
911 HRESULT setHPETEnabled(BOOL aHPETEnabled);
912 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
913 HRESULT setChipsetType(ChipsetType_T aChipsetType);
914 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
915 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
916 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
917 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
918 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
919 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
920 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
921 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
922 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
923 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
924 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
925 HRESULT getSettingsAuxFilePath(com::Utf8Str &aSettingsAuxFilePath);
926 HRESULT getSettingsModified(BOOL *aSettingsModified);
927 HRESULT getSessionState(SessionState_T *aSessionState);
928 HRESULT getSessionType(SessionType_T *aSessionType);
929 HRESULT getSessionName(com::Utf8Str &aSessionType);
930 HRESULT getSessionPID(ULONG *aSessionPID);
931 HRESULT getState(MachineState_T *aState);
932 HRESULT getLastStateChange(LONG64 *aLastStateChange);
933 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
934 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
935 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
936 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
937 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
938 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
939 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
940 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
941 HRESULT getDnDMode(DnDMode_T *aDnDMode);
942 HRESULT setDnDMode(DnDMode_T aDnDMode);
943 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
944 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
945 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
946 HRESULT setTeleporterPort(ULONG aTeleporterPort);
947 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
948 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
949 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
950 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
951 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
952 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
953 HRESULT getParavirtDebug(com::Utf8Str &aParavirtDebug);
954 HRESULT setParavirtDebug(const com::Utf8Str &aParavirtDebug);
955 HRESULT getFaultToleranceState(FaultToleranceState_T *aFaultToleranceState);
956 HRESULT setFaultToleranceState(FaultToleranceState_T aFaultToleranceState);
957 HRESULT getFaultTolerancePort(ULONG *aFaultTolerancePort);
958 HRESULT setFaultTolerancePort(ULONG aFaultTolerancePort);
959 HRESULT getFaultToleranceAddress(com::Utf8Str &aFaultToleranceAddress);
960 HRESULT setFaultToleranceAddress(const com::Utf8Str &aFaultToleranceAddress);
961 HRESULT getFaultTolerancePassword(com::Utf8Str &aFaultTolerancePassword);
962 HRESULT setFaultTolerancePassword(const com::Utf8Str &aFaultTolerancePassword);
963 HRESULT getFaultToleranceSyncInterval(ULONG *aFaultToleranceSyncInterval);
964 HRESULT setFaultToleranceSyncInterval(ULONG aFaultToleranceSyncInterval);
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(com::Utf8Str &aVMProcessPriority);
989 HRESULT setVMProcessPriority(const com::Utf8Str &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 com::Utf8Str &aEnvironment,
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 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 pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1241 std::vector<com::Utf8Str> &aValues,
1242 std::vector<LONG64> &aTimestamps,
1243 std::vector<com::Utf8Str> &aFlags);
1244 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1245 const com::Utf8Str &aValue,
1246 LONG64 aTimestamp,
1247 const com::Utf8Str &aFlags);
1248 HRESULT lockMedia();
1249 HRESULT unlockMedia();
1250 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1251 ComPtr<IMediumAttachment> &aNewAttachment);
1252 HRESULT reportVmStatistics(ULONG aValidStats,
1253 ULONG aCpuUser,
1254 ULONG aCpuKernel,
1255 ULONG aCpuIdle,
1256 ULONG aMemTotal,
1257 ULONG aMemFree,
1258 ULONG aMemBalloon,
1259 ULONG aMemShared,
1260 ULONG aMemCache,
1261 ULONG aPagedTotal,
1262 ULONG aMemAllocTotal,
1263 ULONG aMemFreeTotal,
1264 ULONG aMemBalloonTotal,
1265 ULONG aMemSharedTotal,
1266 ULONG aVmNetRx,
1267 ULONG aVmNetTx);
1268 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1269 com::Utf8Str &aResult);
1270};
1271
1272// SessionMachine class
1273////////////////////////////////////////////////////////////////////////////////
1274
1275/**
1276 * @note Notes on locking objects of this class:
1277 * SessionMachine shares some data with the primary Machine instance (pointed
1278 * to by the |mPeer| member). In order to provide data consistency it also
1279 * shares its lock handle. This means that whenever you lock a SessionMachine
1280 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1281 * instance is also locked in the same lock mode. Keep it in mind.
1282 */
1283class ATL_NO_VTABLE SessionMachine :
1284 public Machine
1285{
1286public:
1287 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1288
1289 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1290
1291 DECLARE_PROTECT_FINAL_CONSTRUCT()
1292
1293 BEGIN_COM_MAP(SessionMachine)
1294 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1295 COM_INTERFACE_ENTRY(IMachine)
1296 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1297 COM_INTERFACE_ENTRY(IInternalMachineControl)
1298 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1299 END_COM_MAP()
1300
1301 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1302
1303 HRESULT FinalConstruct();
1304 void FinalRelease();
1305
1306 struct Uninit
1307 {
1308 enum Reason { Unexpected, Abnormal, Normal };
1309 };
1310
1311 // public initializer/uninitializer for internal purposes only
1312 HRESULT init(Machine *aMachine);
1313 void uninit() { uninit(Uninit::Unexpected); }
1314 void uninit(Uninit::Reason aReason);
1315
1316
1317 // util::Lockable interface
1318 RWLockHandle *lockHandle() const;
1319
1320 // public methods only for internal purposes
1321
1322 virtual bool i_isSessionMachine() const
1323 {
1324 return true;
1325 }
1326
1327#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1328 bool i_checkForDeath();
1329
1330 void i_getTokenId(Utf8Str &strTokenId);
1331#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1332 IToken *i_getToken();
1333#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1334 // getClientToken must be only used by callers who can guarantee that
1335 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1336 ClientToken *i_getClientToken();
1337
1338 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1339 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1340 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1341 IN_BSTR aGuestIp, LONG aGuestPort);
1342 HRESULT i_onStorageControllerChange();
1343 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1344 HRESULT i_onAudioAdapterChange(IAudioAdapter *audioAdapter);
1345 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1346 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1347 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1348 HRESULT i_onVRDEServerChange(BOOL aRestart);
1349 HRESULT i_onVideoCaptureChange();
1350 HRESULT i_onUSBControllerChange();
1351 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1352 IVirtualBoxErrorInfo *aError,
1353 ULONG aMaskedIfs,
1354 const com::Utf8Str &aCaptureFilename);
1355 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1356 IVirtualBoxErrorInfo *aError);
1357 HRESULT i_onSharedFolderChange();
1358 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1359 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1360 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1361 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1362 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1363
1364 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1365
1366 HRESULT i_lockMedia();
1367 HRESULT i_unlockMedia();
1368
1369 HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
1370
1371private:
1372
1373 // wrapped IInternalMachineControl properties
1374
1375 // wrapped IInternalMachineControl methods
1376 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1377 HRESULT updateState(MachineState_T aState);
1378 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1379 HRESULT endPowerUp(LONG aResult);
1380 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1381 HRESULT endPoweringDown(LONG aResult,
1382 const com::Utf8Str &aErrMsg);
1383 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1384 BOOL *aMatched,
1385 ULONG *aMaskedInterfaces);
1386 HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
1387 HRESULT detachUSBDevice(const com::Guid &aId,
1388 BOOL aDone);
1389 HRESULT autoCaptureUSBDevices();
1390 HRESULT detachAllUSBDevices(BOOL aDone);
1391 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1392 ComPtr<IProgress> &aProgress);
1393 HRESULT finishOnlineMergeMedium();
1394 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1395 std::vector<com::Utf8Str> &aValues,
1396 std::vector<LONG64> &aTimestamps,
1397 std::vector<com::Utf8Str> &aFlags);
1398 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1399 const com::Utf8Str &aValue,
1400 LONG64 aTimestamp,
1401 const com::Utf8Str &aFlags);
1402 HRESULT lockMedia();
1403 HRESULT unlockMedia();
1404 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1405 ComPtr<IMediumAttachment> &aNewAttachment);
1406 HRESULT reportVmStatistics(ULONG aValidStats,
1407 ULONG aCpuUser,
1408 ULONG aCpuKernel,
1409 ULONG aCpuIdle,
1410 ULONG aMemTotal,
1411 ULONG aMemFree,
1412 ULONG aMemBalloon,
1413 ULONG aMemShared,
1414 ULONG aMemCache,
1415 ULONG aPagedTotal,
1416 ULONG aMemAllocTotal,
1417 ULONG aMemFreeTotal,
1418 ULONG aMemBalloonTotal,
1419 ULONG aMemSharedTotal,
1420 ULONG aVmNetRx,
1421 ULONG aVmNetTx);
1422 HRESULT authenticateExternal(const std::vector<com::Utf8Str> &aAuthParams,
1423 com::Utf8Str &aResult);
1424
1425
1426 struct ConsoleTaskData
1427 {
1428 ConsoleTaskData()
1429 : mLastState(MachineState_Null),
1430 mDeleteSnapshotInfo(NULL)
1431 { }
1432
1433 MachineState_T mLastState;
1434 ComObjPtr<Progress> mProgress;
1435
1436 // used when deleting online snaphshot
1437 void *mDeleteSnapshotInfo;
1438 };
1439
1440 class SaveStateTask;
1441 class SnapshotTask;
1442 class TakeSnapshotTask;
1443 class DeleteSnapshotTask;
1444 class RestoreSnapshotTask;
1445
1446 void i_saveStateHandler(SaveStateTask &aTask);
1447
1448 // Override some functionality for SessionMachine, this is where the
1449 // real action happens (the Machine methods are just dummies).
1450 HRESULT saveState(ComPtr<IProgress> &aProgress);
1451 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1452 HRESULT discardSavedState(BOOL aFRemoveFile);
1453 HRESULT takeSnapshot(const com::Utf8Str &aName,
1454 const com::Utf8Str &aDescription,
1455 BOOL aPause,
1456 com::Guid &aId,
1457 ComPtr<IProgress> &aProgress);
1458 HRESULT deleteSnapshot(const com::Guid &aId,
1459 ComPtr<IProgress> &aProgress);
1460 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
1461 ComPtr<IProgress> &aProgress);
1462 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
1463 const com::Guid &aEndId,
1464 ComPtr<IProgress> &aProgress);
1465 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
1466 ComPtr<IProgress> &aProgress);
1467
1468 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1469
1470 void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
1471 static void i_takeSnapshotProgressCancelCallback(void *pvUser);
1472 HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
1473 HRESULT i_deleteSnapshot(const com::Guid &aStartId,
1474 const com::Guid &aEndId,
1475 BOOL aDeleteAllChildren,
1476 ComPtr<IProgress> &aProgress);
1477 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1478 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1479
1480 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1481 const Guid &machineId,
1482 const Guid &snapshotId,
1483 bool fOnlineMergePossible,
1484 MediumLockList *aVMMALockList,
1485 ComObjPtr<Medium> &aSource,
1486 ComObjPtr<Medium> &aTarget,
1487 bool &fMergeForward,
1488 ComObjPtr<Medium> &pParentForTarget,
1489 MediumLockList * &aChildrenToReparent,
1490 bool &fNeedOnlineMerge,
1491 MediumLockList * &aMediumLockList,
1492 ComPtr<IToken> &aHDLockToken);
1493 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1494 const ComObjPtr<Medium> &aSource,
1495 MediumLockList *aChildrenToReparent,
1496 bool fNeedsOnlineMerge,
1497 MediumLockList *aMediumLockList,
1498 const ComPtr<IToken> &aHDLockToken,
1499 const Guid &aMediumId,
1500 const Guid &aSnapshotId);
1501 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1502 const ComObjPtr<Medium> &aSource,
1503 const ComObjPtr<Medium> &aTarget,
1504 bool fMergeForward,
1505 const ComObjPtr<Medium> &pParentForTarget,
1506 MediumLockList *aChildrenToReparent,
1507 MediumLockList *aMediumLockList,
1508 ComObjPtr<Progress> &aProgress,
1509 bool *pfNeedsMachineSaveSettings);
1510
1511 HRESULT i_setMachineState(MachineState_T aMachineState);
1512 HRESULT i_updateMachineStateOnClient();
1513
1514 bool mRemoveSavedState;
1515
1516 ConsoleTaskData mConsoleTaskData;
1517
1518 /** client token for this machine */
1519 ClientToken *mClientToken;
1520
1521 int miNATNetworksStarted;
1522
1523 AUTHLIBRARYCONTEXT mAuthLibCtx;
1524};
1525
1526// SnapshotMachine class
1527////////////////////////////////////////////////////////////////////////////////
1528
1529/**
1530 * @note Notes on locking objects of this class:
1531 * SnapshotMachine shares some data with the primary Machine instance (pointed
1532 * to by the |mPeer| member). In order to provide data consistency it also
1533 * shares its lock handle. This means that whenever you lock a SessionMachine
1534 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1535 * instance is also locked in the same lock mode. Keep it in mind.
1536 */
1537class ATL_NO_VTABLE SnapshotMachine :
1538 public Machine
1539{
1540public:
1541 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1542
1543 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1544
1545 DECLARE_PROTECT_FINAL_CONSTRUCT()
1546
1547 BEGIN_COM_MAP(SnapshotMachine)
1548 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1549 COM_INTERFACE_ENTRY(IMachine)
1550 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1551 VBOX_TWEAK_INTERFACE_ENTRY(IMachine)
1552 END_COM_MAP()
1553
1554 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1555
1556 HRESULT FinalConstruct();
1557 void FinalRelease();
1558
1559 // public initializer/uninitializer for internal purposes only
1560 HRESULT init(SessionMachine *aSessionMachine,
1561 IN_GUID aSnapshotId,
1562 const Utf8Str &aStateFilePath);
1563 HRESULT initFromSettings(Machine *aMachine,
1564 const settings::Hardware &hardware,
1565 const settings::Debugging *pDbg,
1566 const settings::Autostart *pAutostart,
1567 IN_GUID aSnapshotId,
1568 const Utf8Str &aStateFilePath);
1569 void uninit();
1570
1571 // util::Lockable interface
1572 RWLockHandle *lockHandle() const;
1573
1574 // public methods only for internal purposes
1575
1576 virtual bool i_isSnapshotMachine() const
1577 {
1578 return true;
1579 }
1580
1581 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1582
1583 // unsafe inline public methods for internal purposes only (ensure there is
1584 // a caller and a read lock before calling them!)
1585
1586 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1587
1588private:
1589
1590 Guid mSnapshotId;
1591 /** This field replaces mPeer for SessionMachine instances, as having
1592 * a peer reference is plain meaningless and causes many subtle problems
1593 * with saving settings and the like. */
1594 Machine * const mMachine;
1595
1596 friend class Snapshot;
1597};
1598
1599// third party methods that depend on SnapshotMachine definition
1600
1601inline const Guid &Machine::i_getSnapshotId() const
1602{
1603 return (i_isSnapshotMachine())
1604 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1605 : Guid::Empty;
1606}
1607
1608
1609#endif // ____H_MACHINEIMPL
1610/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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