VirtualBox

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

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

6219: New parameters related to file size / recording time limitation for VM Video Capture have been added (vcpmaxtime, vcpmaxsize and vcpoptions - special codec options in key=value format). EbmlWriter has been refactored. Removed some redundant code.

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