VirtualBox

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

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

USB: Integrate USB sniffer. Make it possible to specify a file to dump the traffic to when attaching a USB device with VBoxManage

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