VirtualBox

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

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

Main: update guest properties API to work with API wrappers, removed unnecesary BSTR conversion.

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