VirtualBox

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

Last change on this file since 55168 was 55168, checked in by vboxsync, 10 years ago

Main/Machine: fix overlooked case sensitive frontend name check

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