VirtualBox

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

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

Main: fixed typo of mRemoveSavedState, thanks PVS

  • 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 52801 2014-09-22 07:07:19Z 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 BOOL aBGR,
1106 ULONG *aWidth,
1107 ULONG *aHeight,
1108 std::vector<BYTE> &aData);
1109 HRESULT readSavedThumbnailPNGToArray(ULONG aScreenId,
1110 ULONG *aWidth,
1111 ULONG *aHeight,
1112 std::vector<BYTE> &aData);
1113 HRESULT querySavedScreenshotPNGSize(ULONG aScreenId,
1114 ULONG *aSize,
1115 ULONG *aWidth,
1116 ULONG *aHeight);
1117 HRESULT readSavedScreenshotPNGToArray(ULONG aScreenId,
1118 ULONG *aWidth,
1119 ULONG *aHeight,
1120 std::vector<BYTE> &aData);
1121 HRESULT hotPlugCPU(ULONG aCpu);
1122 HRESULT hotUnplugCPU(ULONG aCpu);
1123 HRESULT getCPUStatus(ULONG aCpu,
1124 BOOL *aAttached);
1125 HRESULT getEffectiveParavirtProvider(ParavirtProvider_T *aParavirtProvider);
1126 HRESULT queryLogFilename(ULONG aIdx,
1127 com::Utf8Str &aFilename);
1128 HRESULT readLog(ULONG aIdx,
1129 LONG64 aOffset,
1130 LONG64 aSize,
1131 std::vector<BYTE> &aData);
1132 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1133 CloneMode_T aMode,
1134 const std::vector<CloneOptions_T> &aOptions,
1135 ComPtr<IProgress> &aProgress);
1136
1137 // wrapped IInternalMachineControl properties
1138
1139 // wrapped IInternalMachineControl methods
1140 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1141 HRESULT updateState(MachineState_T aState);
1142 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1143 HRESULT endPowerUp(LONG aResult);
1144 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1145 HRESULT endPoweringDown(LONG aResult,
1146 const com::Utf8Str &aErrMsg);
1147 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1148 BOOL *aMatched,
1149 ULONG *aMaskedInterfaces);
1150 HRESULT captureUSBDevice(const com::Guid &aId);
1151 HRESULT detachUSBDevice(const com::Guid &aId,
1152 BOOL aDone);
1153 HRESULT autoCaptureUSBDevices();
1154 HRESULT detachAllUSBDevices(BOOL aDone);
1155 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1156 ComPtr<IProgress> &aProgress);
1157 HRESULT beginSavingState(ComPtr<IProgress> &aProgress,
1158 com::Utf8Str &aStateFilePath);
1159 HRESULT endSavingState(LONG aResult,
1160 const com::Utf8Str &aErrMsg);
1161 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1162 HRESULT beginTakingSnapshot(const ComPtr<IConsole> &aInitiator,
1163 const com::Utf8Str &aName,
1164 const com::Utf8Str &aDescription,
1165 const ComPtr<IProgress> &aConsoleProgress,
1166 BOOL aFTakingSnapshotOnline,
1167 com::Utf8Str &aStateFilePath);
1168 HRESULT endTakingSnapshot(BOOL aSuccess);
1169 HRESULT deleteSnapshot(const ComPtr<IConsole> &aInitiator,
1170 const com::Guid &aStartId,
1171 const com::Guid &aEndId,
1172 BOOL aDeleteAllChildren,
1173 MachineState_T *aMachineState,
1174 ComPtr<IProgress> &aProgress);
1175 HRESULT finishOnlineMergeMedium();
1176 HRESULT restoreSnapshot(const ComPtr<IConsole> &aInitiator,
1177 const ComPtr<ISnapshot> &aSnapshot,
1178 MachineState_T *aMachineState,
1179 ComPtr<IProgress> &aProgress);
1180 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1181 std::vector<com::Utf8Str> &aValues,
1182 std::vector<LONG64> &aTimestamps,
1183 std::vector<com::Utf8Str> &aFlags);
1184 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1185 const com::Utf8Str &aValue,
1186 LONG64 aTimestamp,
1187 const com::Utf8Str &aFlags);
1188 HRESULT lockMedia();
1189 HRESULT unlockMedia();
1190 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1191 ComPtr<IMediumAttachment> &aNewAttachment);
1192 HRESULT reportVmStatistics(ULONG aValidStats,
1193 ULONG aCpuUser,
1194 ULONG aCpuKernel,
1195 ULONG aCpuIdle,
1196 ULONG aMemTotal,
1197 ULONG aMemFree,
1198 ULONG aMemBalloon,
1199 ULONG aMemShared,
1200 ULONG aMemCache,
1201 ULONG aPagedTotal,
1202 ULONG aMemAllocTotal,
1203 ULONG aMemFreeTotal,
1204 ULONG aMemBalloonTotal,
1205 ULONG aMemSharedTotal,
1206 ULONG aVmNetRx,
1207 ULONG aVmNetTx);
1208
1209
1210
1211
1212};
1213
1214// SessionMachine class
1215////////////////////////////////////////////////////////////////////////////////
1216
1217/**
1218 * @note Notes on locking objects of this class:
1219 * SessionMachine shares some data with the primary Machine instance (pointed
1220 * to by the |mPeer| member). In order to provide data consistency it also
1221 * shares its lock handle. This means that whenever you lock a SessionMachine
1222 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1223 * instance is also locked in the same lock mode. Keep it in mind.
1224 */
1225class ATL_NO_VTABLE SessionMachine :
1226 public Machine
1227{
1228public:
1229 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1230
1231 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1232
1233 DECLARE_PROTECT_FINAL_CONSTRUCT()
1234
1235 BEGIN_COM_MAP(SessionMachine)
1236 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1237 COM_INTERFACE_ENTRY(IInternalMachineControl)
1238 END_COM_MAP()
1239
1240 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1241
1242 HRESULT FinalConstruct();
1243 void FinalRelease();
1244
1245 struct Uninit
1246 {
1247 enum Reason { Unexpected, Abnormal, Normal };
1248 };
1249
1250 // public initializer/uninitializer for internal purposes only
1251 HRESULT init(Machine *aMachine);
1252 void uninit() { uninit(Uninit::Unexpected); }
1253 void uninit(Uninit::Reason aReason);
1254
1255
1256 // util::Lockable interface
1257 RWLockHandle *lockHandle() const;
1258
1259 // public methods only for internal purposes
1260
1261 virtual bool i_isSessionMachine() const
1262 {
1263 return true;
1264 }
1265
1266#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1267 bool i_checkForDeath();
1268
1269 void i_getTokenId(Utf8Str &strTokenId);
1270#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1271 IToken *i_getToken();
1272#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1273 // getClientToken must be only used by callers who can guarantee that
1274 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1275 ClientToken *i_getClientToken();
1276
1277 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1278 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1279 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1280 IN_BSTR aGuestIp, LONG aGuestPort);
1281 HRESULT i_onStorageControllerChange();
1282 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1283 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1284 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1285 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1286 HRESULT i_onVRDEServerChange(BOOL aRestart);
1287 HRESULT i_onVideoCaptureChange();
1288 HRESULT i_onUSBControllerChange();
1289 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1290 IVirtualBoxErrorInfo *aError,
1291 ULONG aMaskedIfs);
1292 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1293 IVirtualBoxErrorInfo *aError);
1294 HRESULT i_onSharedFolderChange();
1295 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1296 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1297 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1298 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1299 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1300
1301 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1302
1303 HRESULT i_lockMedia();
1304 HRESULT i_unlockMedia();
1305
1306private:
1307
1308 // wrapped IInternalMachineControl properties
1309
1310 // wrapped IInternalMachineControl methods
1311 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1312 HRESULT updateState(MachineState_T aState);
1313 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1314 HRESULT endPowerUp(LONG aResult);
1315 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1316 HRESULT endPoweringDown(LONG aResult,
1317 const com::Utf8Str &aErrMsg);
1318 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1319 BOOL *aMatched,
1320 ULONG *aMaskedInterfaces);
1321 HRESULT captureUSBDevice(const com::Guid &aId);
1322 HRESULT detachUSBDevice(const com::Guid &aId,
1323 BOOL aDone);
1324 HRESULT autoCaptureUSBDevices();
1325 HRESULT detachAllUSBDevices(BOOL aDone);
1326 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1327 ComPtr<IProgress> &aProgress);
1328 HRESULT beginSavingState(ComPtr<IProgress> &aProgress,
1329 com::Utf8Str &aStateFilePath);
1330 HRESULT endSavingState(LONG aResult,
1331 const com::Utf8Str &aErrMsg);
1332 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1333 HRESULT beginTakingSnapshot(const ComPtr<IConsole> &aInitiator,
1334 const com::Utf8Str &aName,
1335 const com::Utf8Str &aDescription,
1336 const ComPtr<IProgress> &aConsoleProgress,
1337 BOOL aFTakingSnapshotOnline,
1338 com::Utf8Str &aStateFilePath);
1339 HRESULT endTakingSnapshot(BOOL aSuccess);
1340 HRESULT deleteSnapshot(const ComPtr<IConsole> &aInitiator,
1341 const com::Guid &aStartId,
1342 const com::Guid &aEndId,
1343 BOOL aDeleteAllChildren,
1344 MachineState_T *aMachineState,
1345 ComPtr<IProgress> &aProgress);
1346 HRESULT finishOnlineMergeMedium();
1347 HRESULT restoreSnapshot(const ComPtr<IConsole> &aInitiator,
1348 const ComPtr<ISnapshot> &aSnapshot,
1349 MachineState_T *aMachineState,
1350 ComPtr<IProgress> &aProgress);
1351 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1352 std::vector<com::Utf8Str> &aValues,
1353 std::vector<LONG64> &aTimestamps,
1354 std::vector<com::Utf8Str> &aFlags);
1355 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1356 const com::Utf8Str &aValue,
1357 LONG64 aTimestamp,
1358 const com::Utf8Str &aFlags);
1359 HRESULT lockMedia();
1360 HRESULT unlockMedia();
1361 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1362 ComPtr<IMediumAttachment> &aNewAttachment);
1363 HRESULT reportVmStatistics(ULONG aValidStats,
1364 ULONG aCpuUser,
1365 ULONG aCpuKernel,
1366 ULONG aCpuIdle,
1367 ULONG aMemTotal,
1368 ULONG aMemFree,
1369 ULONG aMemBalloon,
1370 ULONG aMemShared,
1371 ULONG aMemCache,
1372 ULONG aPagedTotal,
1373 ULONG aMemAllocTotal,
1374 ULONG aMemFreeTotal,
1375 ULONG aMemBalloonTotal,
1376 ULONG aMemSharedTotal,
1377 ULONG aVmNetRx,
1378 ULONG aVmNetTx);
1379
1380
1381 struct ConsoleTaskData
1382 {
1383 ConsoleTaskData()
1384 : mLastState(MachineState_Null), mDeleteSnapshotInfo(NULL)
1385 { }
1386
1387 MachineState_T mLastState;
1388 ComObjPtr<Progress> mProgress;
1389
1390 // used when taking snapshot
1391 ComObjPtr<Snapshot> mSnapshot;
1392
1393 // used when deleting online snapshot
1394 void *mDeleteSnapshotInfo;
1395
1396 // used when saving state (either as part of a snapshot or separate)
1397 Utf8Str strStateFilePath;
1398 };
1399
1400 struct SnapshotTask;
1401 struct DeleteSnapshotTask;
1402 struct RestoreSnapshotTask;
1403
1404 friend struct DeleteSnapshotTask;
1405 friend struct RestoreSnapshotTask;
1406
1407 HRESULT i_endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1408 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1409
1410 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1411 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1412
1413 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1414 const Guid &machineId,
1415 const Guid &snapshotId,
1416 bool fOnlineMergePossible,
1417 MediumLockList *aVMMALockList,
1418 ComObjPtr<Medium> &aSource,
1419 ComObjPtr<Medium> &aTarget,
1420 bool &fMergeForward,
1421 ComObjPtr<Medium> &pParentForTarget,
1422 MediumLockList * &aChildrenToReparent,
1423 bool &fNeedOnlineMerge,
1424 MediumLockList * &aMediumLockList,
1425 ComPtr<IToken> &aHDLockToken);
1426 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1427 const ComObjPtr<Medium> &aSource,
1428 MediumLockList *aChildrenToReparent,
1429 bool fNeedsOnlineMerge,
1430 MediumLockList *aMediumLockList,
1431 const ComPtr<IToken> &aHDLockToken,
1432 const Guid &aMediumId,
1433 const Guid &aSnapshotId);
1434 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1435 const ComObjPtr<Medium> &aSource,
1436 const ComObjPtr<Medium> &aTarget,
1437 bool fMergeForward,
1438 const ComObjPtr<Medium> &pParentForTarget,
1439 MediumLockList *aChildrenToReparent,
1440 MediumLockList *aMediumLockList,
1441 ComObjPtr<Progress> &aProgress,
1442 bool *pfNeedsMachineSaveSettings);
1443
1444 HRESULT i_setMachineState(MachineState_T aMachineState);
1445 HRESULT i_updateMachineStateOnClient();
1446
1447 bool mRemoveSavedState;
1448
1449 ConsoleTaskData mConsoleTaskData;
1450
1451 /** client token for this machine */
1452 ClientToken *mClientToken;
1453
1454 int miNATNetworksStarted;
1455
1456 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1457};
1458
1459// SnapshotMachine class
1460////////////////////////////////////////////////////////////////////////////////
1461
1462/**
1463 * @note Notes on locking objects of this class:
1464 * SnapshotMachine shares some data with the primary Machine instance (pointed
1465 * to by the |mPeer| member). In order to provide data consistency it also
1466 * shares its lock handle. This means that whenever you lock a SessionMachine
1467 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1468 * instance is also locked in the same lock mode. Keep it in mind.
1469 */
1470class ATL_NO_VTABLE SnapshotMachine :
1471 public Machine
1472{
1473public:
1474 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1475
1476 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1477
1478 DECLARE_PROTECT_FINAL_CONSTRUCT()
1479
1480 BEGIN_COM_MAP(SnapshotMachine)
1481 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1482 END_COM_MAP()
1483
1484 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1485
1486 HRESULT FinalConstruct();
1487 void FinalRelease();
1488
1489 // public initializer/uninitializer for internal purposes only
1490 HRESULT init(SessionMachine *aSessionMachine,
1491 IN_GUID aSnapshotId,
1492 const Utf8Str &aStateFilePath);
1493 HRESULT initFromSettings(Machine *aMachine,
1494 const settings::Hardware &hardware,
1495 const settings::Debugging *pDbg,
1496 const settings::Autostart *pAutostart,
1497 const settings::Storage &storage,
1498 IN_GUID aSnapshotId,
1499 const Utf8Str &aStateFilePath);
1500 void uninit();
1501
1502 // util::Lockable interface
1503 RWLockHandle *lockHandle() const;
1504
1505 // public methods only for internal purposes
1506
1507 virtual bool i_isSnapshotMachine() const
1508 {
1509 return true;
1510 }
1511
1512 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1513
1514 // unsafe inline public methods for internal purposes only (ensure there is
1515 // a caller and a read lock before calling them!)
1516
1517 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1518
1519private:
1520
1521 Guid mSnapshotId;
1522 /** This field replaces mPeer for SessionMachine instances, as having
1523 * a peer reference is plain meaningless and causes many subtle problems
1524 * with saving settings and the like. */
1525 Machine * const mMachine;
1526
1527 friend class Snapshot;
1528};
1529
1530// third party methods that depend on SnapshotMachine definition
1531
1532inline const Guid &Machine::i_getSnapshotId() const
1533{
1534 return (i_isSnapshotMachine())
1535 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1536 : Guid::Empty;
1537}
1538
1539
1540#endif // ____H_MACHINEIMPL
1541/* 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