VirtualBox

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

Last change on this file since 51856 was 51498, checked in by vboxsync, 11 years ago

6813 - MachineImpl use of server side wrappers + misc mods on other classes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 64.0 KB
Line 
1/* $Id: MachineImpl.h 51498 2014-06-02 18:53:08Z 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
536 void i_composeSavedStateFilename(Utf8Str &strStateFilePath);
537
538 void i_getDefaultVideoCaptureFile(Utf8Str &strFile);
539
540 bool i_isUSBControllerPresent();
541
542 HRESULT i_launchVMProcess(IInternalSessionControl *aControl,
543 const Utf8Str &strType,
544 const Utf8Str &strEnvironment,
545 ProgressProxy *aProgress);
546
547 HRESULT i_getDirectControl(ComPtr<IInternalSessionControl> *directControl)
548 {
549 HRESULT rc;
550 *directControl = mData->mSession.mDirectControl;
551
552 if (!*directControl)
553 rc = E_ACCESSDENIED;
554 else
555 rc = S_OK;
556
557 return rc;
558 }
559
560 bool i_isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
561 ComPtr<IInternalSessionControl> *aControl = NULL,
562 bool aAllowClosing = false);
563 bool i_isSessionSpawning();
564
565 bool i_isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
566 ComPtr<IInternalSessionControl> *aControl = NULL)
567 { return i_isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
568
569 bool i_checkForSpawnFailure();
570
571 HRESULT i_prepareRegister();
572
573 HRESULT i_getSharedFolder(CBSTR aName,
574 ComObjPtr<SharedFolder> &aSharedFolder,
575 bool aSetError = false)
576 {
577 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
578 return i_findSharedFolder(aName, aSharedFolder, aSetError);
579 }
580
581 HRESULT i_addStateDependency(StateDependency aDepType = AnyStateDep,
582 MachineState_T *aState = NULL,
583 BOOL *aRegistered = NULL);
584 void i_releaseStateDependency();
585
586 HRESULT i_getBandwidthGroup(const Utf8Str &strBandwidthGroup,
587 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
588 bool fSetError = false)
589 {
590 return mBandwidthControl->i_getBandwidthGroupByName(strBandwidthGroup,
591 pBandwidthGroup,
592 fSetError);
593 }
594
595
596
597protected:
598
599 class ClientToken;
600
601 HRESULT i_checkStateDependency(StateDependency aDepType);
602
603 Machine *i_getMachine();
604
605 void i_ensureNoStateDependencies();
606
607 virtual HRESULT i_setMachineState(MachineState_T aMachineState);
608
609 HRESULT i_findSharedFolder(const Utf8Str &aName,
610 ComObjPtr<SharedFolder> &aSharedFolder,
611 bool aSetError = false);
612
613 HRESULT i_loadSettings(bool aRegistered);
614 HRESULT i_loadMachineDataFromSettings(const settings::MachineConfigFile &config,
615 const Guid *puuidRegistry);
616 HRESULT i_loadSnapshot(const settings::Snapshot &data,
617 const Guid &aCurSnapshotId,
618 Snapshot *aParentSnapshot);
619 HRESULT i_loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
620 const settings::Autostart *pAutostart);
621 HRESULT i_loadDebugging(const settings::Debugging *pDbg);
622 HRESULT i_loadAutostart(const settings::Autostart *pAutostart);
623 HRESULT i_loadStorageControllers(const settings::Storage &data,
624 const Guid *puuidRegistry,
625 const Guid *puuidSnapshot);
626 HRESULT i_loadStorageDevices(StorageController *aStorageController,
627 const settings::StorageController &data,
628 const Guid *puuidRegistry,
629 const Guid *puuidSnapshot);
630
631 HRESULT i_findSnapshotById(const Guid &aId,
632 ComObjPtr<Snapshot> &aSnapshot,
633 bool aSetError = false);
634 HRESULT i_findSnapshotByName(const Utf8Str &strName,
635 ComObjPtr<Snapshot> &aSnapshot,
636 bool aSetError = false);
637
638 HRESULT i_getStorageControllerByName(const Utf8Str &aName,
639 ComObjPtr<StorageController> &aStorageController,
640 bool aSetError = false);
641
642 HRESULT i_getMediumAttachmentsOfController(const Utf8Str &aName,
643 MediaData::AttachmentList &aAttachments);
644
645 HRESULT i_getUSBControllerByName(const Utf8Str &aName,
646 ComObjPtr<USBController> &aUSBController,
647 bool aSetError = false);
648
649 ULONG i_getUSBControllerCountByType(USBControllerType_T enmType);
650
651 enum
652 {
653 /* flags for #saveSettings() */
654 SaveS_ResetCurStateModified = 0x01,
655 SaveS_InformCallbacksAnyway = 0x02,
656 SaveS_Force = 0x04,
657 /* flags for #saveStateSettings() */
658 SaveSTS_CurStateModified = 0x20,
659 SaveSTS_StateFilePath = 0x40,
660 SaveSTS_StateTimeStamp = 0x80
661 };
662
663 HRESULT i_prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
664 HRESULT i_saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
665
666 void i_copyMachineDataToSettings(settings::MachineConfigFile &config);
667 HRESULT i_saveAllSnapshots(settings::MachineConfigFile &config);
668 HRESULT i_saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
669 settings::Autostart *pAutostart);
670 HRESULT i_saveStorageControllers(settings::Storage &data);
671 HRESULT i_saveStorageDevices(ComObjPtr<StorageController> aStorageController,
672 settings::StorageController &data);
673 HRESULT i_saveStateSettings(int aFlags);
674
675 void i_addMediumToRegistry(ComObjPtr<Medium> &pMedium);
676
677 HRESULT i_createImplicitDiffs(IProgress *aProgress,
678 ULONG aWeight,
679 bool aOnline);
680 HRESULT i_deleteImplicitDiffs(bool aOnline);
681
682 MediumAttachment* i_findAttachment(const MediaData::AttachmentList &ll,
683 IN_BSTR aControllerName,
684 LONG aControllerPort,
685 LONG aDevice);
686 MediumAttachment* i_findAttachment(const MediaData::AttachmentList &ll,
687 ComObjPtr<Medium> pMedium);
688 MediumAttachment* i_findAttachment(const MediaData::AttachmentList &ll,
689 Guid &id);
690
691 HRESULT i_detachDevice(MediumAttachment *pAttach,
692 AutoWriteLock &writeLock,
693 Snapshot *pSnapshot);
694
695 HRESULT i_detachAllMedia(AutoWriteLock &writeLock,
696 Snapshot *pSnapshot,
697 CleanupMode_T cleanupMode,
698 MediaList &llMedia);
699
700 void i_commitMedia(bool aOnline = false);
701 void i_rollbackMedia();
702
703 bool i_isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
704
705 void i_rollback(bool aNotify);
706 void i_commit();
707 void i_copyFrom(Machine *aThat);
708 bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
709
710 struct DeleteTask;
711 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
712 HRESULT i_deleteTaskWorker(DeleteTask &task);
713 Utf8Str i_getExtraData(const Utf8Str &strKey);
714
715#ifdef VBOX_WITH_GUEST_PROPS
716 HRESULT i_getGuestPropertyFromService(const com::Utf8Str &aName, com::Utf8Str &aValue,
717 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
718 HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
719 const com::Utf8Str &aFlags);
720 HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
721 LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
722 HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
723 const com::Utf8Str &aFlags);
724 HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
725 std::vector<com::Utf8Str> &aNames,
726 std::vector<com::Utf8Str> &aValues,
727 std::vector<LONG64> &aTimestamps,
728 std::vector<com::Utf8Str> &aFlags);
729 HRESULT i_enumerateGuestPropertiesOnVM(const com::Utf8Str &aPatterns,
730 std::vector<com::Utf8Str> &aNames,
731 std::vector<com::Utf8Str> &aValues,
732 std::vector<LONG64> &aTimestamps,
733 std::vector<com::Utf8Str> &aFlags);
734
735#endif /* VBOX_WITH_GUEST_PROPS */
736
737#ifdef VBOX_WITH_RESOURCE_USAGE_API
738 void i_getDiskList(MediaList &list);
739 void i_registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
740
741 pm::CollectorGuest *mCollectorGuest;
742#endif /* VBOX_WITH_RESOURCE_USAGE_API */
743
744 Machine * const mPeer;
745
746 VirtualBox * const mParent;
747
748 Shareable<Data> mData;
749 Shareable<SSData> mSSData;
750
751 Backupable<UserData> mUserData;
752 Backupable<HWData> mHWData;
753 Backupable<MediaData> mMediaData;
754
755 // the following fields need special backup/rollback/commit handling,
756 // so they cannot be a part of HWData
757
758 const ComObjPtr<VRDEServer> mVRDEServer;
759 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
760 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
761 const ComObjPtr<AudioAdapter> mAudioAdapter;
762 const ComObjPtr<USBDeviceFilters> mUSBDeviceFilters;
763 const ComObjPtr<BIOSSettings> mBIOSSettings;
764 const ComObjPtr<BandwidthControl> mBandwidthControl;
765
766 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
767 NetworkAdapterVector mNetworkAdapters;
768
769 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
770 Backupable<StorageControllerList> mStorageControllers;
771
772 typedef std::list<ComObjPtr<USBController> > USBControllerList;
773 Backupable<USBControllerList> mUSBControllers;
774
775 uint64_t uRegistryNeedsSaving;
776
777 friend class SessionMachine;
778 friend class SnapshotMachine;
779 friend class Appliance;
780 friend class VirtualBox;
781
782 friend class MachineCloneVM;
783
784private:
785 // wrapped IMachine properties
786 HRESULT getParent(ComPtr<IVirtualBox> &aParent);
787 HRESULT getIcon(std::vector<BYTE> &aIcon);
788 HRESULT setIcon(const std::vector<BYTE> &aIcon);
789 HRESULT getAccessible(BOOL *aAccessible);
790 HRESULT getAccessError(ComPtr<IVirtualBoxErrorInfo> &aAccessError);
791 HRESULT getName(com::Utf8Str &aName);
792 HRESULT setName(const com::Utf8Str &aName);
793 HRESULT getDescription(com::Utf8Str &aDescription);
794 HRESULT setDescription(const com::Utf8Str &aDescription);
795 HRESULT getId(com::Guid &aId);
796 HRESULT getGroups(std::vector<com::Utf8Str> &aGroups);
797 HRESULT setGroups(const std::vector<com::Utf8Str> &aGroups);
798 HRESULT getOSTypeId(com::Utf8Str &aOSTypeId);
799 HRESULT setOSTypeId(const com::Utf8Str &aOSTypeId);
800 HRESULT getHardwareVersion(com::Utf8Str &aHardwareVersion);
801 HRESULT setHardwareVersion(const com::Utf8Str &aHardwareVersion);
802 HRESULT getHardwareUUID(com::Guid &aHardwareUUID);
803 HRESULT setHardwareUUID(const com::Guid &aHardwareUUID);
804 HRESULT getCPUCount(ULONG *aCPUCount);
805 HRESULT setCPUCount(ULONG aCPUCount);
806 HRESULT getCPUHotPlugEnabled(BOOL *aCPUHotPlugEnabled);
807 HRESULT setCPUHotPlugEnabled(BOOL aCPUHotPlugEnabled);
808 HRESULT getCPUExecutionCap(ULONG *aCPUExecutionCap);
809 HRESULT setCPUExecutionCap(ULONG aCPUExecutionCap);
810 HRESULT getMemorySize(ULONG *aMemorySize);
811 HRESULT setMemorySize(ULONG aMemorySize);
812 HRESULT getMemoryBalloonSize(ULONG *aMemoryBalloonSize);
813 HRESULT setMemoryBalloonSize(ULONG aMemoryBalloonSize);
814 HRESULT getPageFusionEnabled(BOOL *aPageFusionEnabled);
815 HRESULT setPageFusionEnabled(BOOL aPageFusionEnabled);
816 HRESULT getGraphicsControllerType(GraphicsControllerType_T *aGraphicsControllerType);
817 HRESULT setGraphicsControllerType(GraphicsControllerType_T aGraphicsControllerType);
818 HRESULT getVRAMSize(ULONG *aVRAMSize);
819 HRESULT setVRAMSize(ULONG aVRAMSize);
820 HRESULT getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled);
821 HRESULT setAccelerate3DEnabled(BOOL aAccelerate3DEnabled);
822 HRESULT getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled);
823 HRESULT setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled);
824 HRESULT getMonitorCount(ULONG *aMonitorCount);
825 HRESULT setMonitorCount(ULONG aMonitorCount);
826 HRESULT getVideoCaptureEnabled(BOOL *aVideoCaptureEnabled);
827 HRESULT setVideoCaptureEnabled(BOOL aVideoCaptureEnabled);
828 HRESULT getVideoCaptureScreens(std::vector<BOOL> &aVideoCaptureScreens);
829 HRESULT setVideoCaptureScreens(const std::vector<BOOL> &aVideoCaptureScreens);
830 HRESULT getVideoCaptureFile(com::Utf8Str &aVideoCaptureFile);
831 HRESULT setVideoCaptureFile(const com::Utf8Str &aVideoCaptureFile);
832 HRESULT getVideoCaptureWidth(ULONG *aVideoCaptureWidth);
833 HRESULT setVideoCaptureWidth(ULONG aVideoCaptureWidth);
834 HRESULT getVideoCaptureHeight(ULONG *aVideoCaptureHeight);
835 HRESULT setVideoCaptureHeight(ULONG aVideoCaptureHeight);
836 HRESULT getVideoCaptureRate(ULONG *aVideoCaptureRate);
837 HRESULT setVideoCaptureRate(ULONG aVideoCaptureRate);
838 HRESULT getVideoCaptureFPS(ULONG *aVideoCaptureFPS);
839 HRESULT setVideoCaptureFPS(ULONG aVideoCaptureFPS);
840 HRESULT getBIOSSettings(ComPtr<IBIOSSettings> &aBIOSSettings);
841 HRESULT getFirmwareType(FirmwareType_T *aFirmwareType);
842 HRESULT setFirmwareType(FirmwareType_T aFirmwareType);
843 HRESULT getPointingHIDType(PointingHIDType_T *aPointingHIDType);
844 HRESULT setPointingHIDType(PointingHIDType_T aPointingHIDType);
845 HRESULT getKeyboardHIDType(KeyboardHIDType_T *aKeyboardHIDType);
846 HRESULT setKeyboardHIDType(KeyboardHIDType_T aKeyboardHIDType);
847 HRESULT getHPETEnabled(BOOL *aHPETEnabled);
848 HRESULT setHPETEnabled(BOOL aHPETEnabled);
849 HRESULT getChipsetType(ChipsetType_T *aChipsetType);
850 HRESULT setChipsetType(ChipsetType_T aChipsetType);
851 HRESULT getSnapshotFolder(com::Utf8Str &aSnapshotFolder);
852 HRESULT setSnapshotFolder(const com::Utf8Str &aSnapshotFolder);
853 HRESULT getVRDEServer(ComPtr<IVRDEServer> &aVRDEServer);
854 HRESULT getEmulatedUSBCardReaderEnabled(BOOL *aEmulatedUSBCardReaderEnabled);
855 HRESULT setEmulatedUSBCardReaderEnabled(BOOL aEmulatedUSBCardReaderEnabled);
856 HRESULT getMediumAttachments(std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
857 HRESULT getUSBControllers(std::vector<ComPtr<IUSBController> > &aUSBControllers);
858 HRESULT getUSBDeviceFilters(ComPtr<IUSBDeviceFilters> &aUSBDeviceFilters);
859 HRESULT getAudioAdapter(ComPtr<IAudioAdapter> &aAudioAdapter);
860 HRESULT getStorageControllers(std::vector<ComPtr<IStorageController> > &aStorageControllers);
861 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
862 HRESULT getSettingsModified(BOOL *aSettingsModified);
863 HRESULT getSessionState(SessionState_T *aSessionState);
864 HRESULT getSessionType(com::Utf8Str &aSessionType);
865 HRESULT getSessionPID(ULONG *aSessionPID);
866 HRESULT getState(MachineState_T *aState);
867 HRESULT getLastStateChange(LONG64 *aLastStateChange);
868 HRESULT getStateFilePath(com::Utf8Str &aStateFilePath);
869 HRESULT getLogFolder(com::Utf8Str &aLogFolder);
870 HRESULT getCurrentSnapshot(ComPtr<ISnapshot> &aCurrentSnapshot);
871 HRESULT getSnapshotCount(ULONG *aSnapshotCount);
872 HRESULT getCurrentStateModified(BOOL *aCurrentStateModified);
873 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
874 HRESULT getClipboardMode(ClipboardMode_T *aClipboardMode);
875 HRESULT setClipboardMode(ClipboardMode_T aClipboardMode);
876 HRESULT getDnDMode(DnDMode_T *aDnDMode);
877 HRESULT setDnDMode(DnDMode_T aDnDMode);
878 HRESULT getGuestPropertyNotificationPatterns(com::Utf8Str &aGuestPropertyNotificationPatterns);
879 HRESULT setGuestPropertyNotificationPatterns(const com::Utf8Str &aGuestPropertyNotificationPatterns);
880 HRESULT getTeleporterEnabled(BOOL *aTeleporterEnabled);
881 HRESULT setTeleporterEnabled(BOOL aTeleporterEnabled);
882 HRESULT getTeleporterPort(ULONG *aTeleporterPort);
883 HRESULT setTeleporterPort(ULONG aTeleporterPort);
884 HRESULT getTeleporterAddress(com::Utf8Str &aTeleporterAddress);
885 HRESULT setTeleporterAddress(const com::Utf8Str &aTeleporterAddress);
886 HRESULT getTeleporterPassword(com::Utf8Str &aTeleporterPassword);
887 HRESULT setTeleporterPassword(const com::Utf8Str &aTeleporterPassword);
888 HRESULT getParavirtProvider(ParavirtProvider_T *aParavirtProvider);
889 HRESULT setParavirtProvider(ParavirtProvider_T aParavirtProvider);
890 HRESULT getFaultToleranceState(FaultToleranceState_T *aFaultToleranceState);
891 HRESULT setFaultToleranceState(FaultToleranceState_T aFaultToleranceState);
892 HRESULT getFaultTolerancePort(ULONG *aFaultTolerancePort);
893 HRESULT setFaultTolerancePort(ULONG aFaultTolerancePort);
894 HRESULT getFaultToleranceAddress(com::Utf8Str &aFaultToleranceAddress);
895 HRESULT setFaultToleranceAddress(const com::Utf8Str &aFaultToleranceAddress);
896 HRESULT getFaultTolerancePassword(com::Utf8Str &aFaultTolerancePassword);
897 HRESULT setFaultTolerancePassword(const com::Utf8Str &aFaultTolerancePassword);
898 HRESULT getFaultToleranceSyncInterval(ULONG *aFaultToleranceSyncInterval);
899 HRESULT setFaultToleranceSyncInterval(ULONG aFaultToleranceSyncInterval);
900 HRESULT getRTCUseUTC(BOOL *aRTCUseUTC);
901 HRESULT setRTCUseUTC(BOOL aRTCUseUTC);
902 HRESULT getIOCacheEnabled(BOOL *aIOCacheEnabled);
903 HRESULT setIOCacheEnabled(BOOL aIOCacheEnabled);
904 HRESULT getIOCacheSize(ULONG *aIOCacheSize);
905 HRESULT setIOCacheSize(ULONG aIOCacheSize);
906 HRESULT getPCIDeviceAssignments(std::vector<ComPtr<IPCIDeviceAttachment> > &aPCIDeviceAssignments);
907 HRESULT getBandwidthControl(ComPtr<IBandwidthControl> &aBandwidthControl);
908 HRESULT getTracingEnabled(BOOL *aTracingEnabled);
909 HRESULT setTracingEnabled(BOOL aTracingEnabled);
910 HRESULT getTracingConfig(com::Utf8Str &aTracingConfig);
911 HRESULT setTracingConfig(const com::Utf8Str &aTracingConfig);
912 HRESULT getAllowTracingToAccessVM(BOOL *aAllowTracingToAccessVM);
913 HRESULT setAllowTracingToAccessVM(BOOL aAllowTracingToAccessVM);
914 HRESULT getAutostartEnabled(BOOL *aAutostartEnabled);
915 HRESULT setAutostartEnabled(BOOL aAutostartEnabled);
916 HRESULT getAutostartDelay(ULONG *aAutostartDelay);
917 HRESULT setAutostartDelay(ULONG aAutostartDelay);
918 HRESULT getAutostopType(AutostopType_T *aAutostopType);
919 HRESULT setAutostopType(AutostopType_T aAutostopType);
920 HRESULT getDefaultFrontend(com::Utf8Str &aDefaultFrontend);
921 HRESULT setDefaultFrontend(const com::Utf8Str &aDefaultFrontend);
922 HRESULT getUSBProxyAvailable(BOOL *aUSBProxyAvailable);
923
924 // wrapped IMachine methods
925 HRESULT lockMachine(const ComPtr<ISession> &aSession,
926 LockType_T aLockType);
927 HRESULT launchVMProcess(const ComPtr<ISession> &aSession,
928 const com::Utf8Str &aType,
929 const com::Utf8Str &aEnvironment,
930 ComPtr<IProgress> &aProgress);
931 HRESULT setBootOrder(ULONG aPosition,
932 DeviceType_T aDevice);
933 HRESULT getBootOrder(ULONG aPosition,
934 DeviceType_T *aDevice);
935 HRESULT attachDevice(const com::Utf8Str &aName,
936 LONG aControllerPort,
937 LONG aDevice,
938 DeviceType_T aType,
939 const ComPtr<IMedium> &aMedium);
940 HRESULT attachDeviceWithoutMedium(const com::Utf8Str &aName,
941 LONG aControllerPort,
942 LONG aDevice,
943 DeviceType_T aType);
944 HRESULT detachDevice(const com::Utf8Str &aName,
945 LONG aControllerPort,
946 LONG aDevice);
947 HRESULT passthroughDevice(const com::Utf8Str &aName,
948 LONG aControllerPort,
949 LONG aDevice,
950 BOOL aPassthrough);
951 HRESULT temporaryEjectDevice(const com::Utf8Str &aName,
952 LONG aControllerPort,
953 LONG aDevice,
954 BOOL aTemporaryEject);
955 HRESULT nonRotationalDevice(const com::Utf8Str &aName,
956 LONG aControllerPort,
957 LONG aDevice,
958 BOOL aNonRotational);
959 HRESULT setAutoDiscardForDevice(const com::Utf8Str &aName,
960 LONG aControllerPort,
961 LONG aDevice,
962 BOOL aDiscard);
963 HRESULT setHotPluggableForDevice(const com::Utf8Str &aName,
964 LONG aControllerPort,
965 LONG aDevice,
966 BOOL aHotPluggable);
967 HRESULT setBandwidthGroupForDevice(const com::Utf8Str &aName,
968 LONG aControllerPort,
969 LONG aDevice,
970 const ComPtr<IBandwidthGroup> &aBandwidthGroup);
971 HRESULT setNoBandwidthGroupForDevice(const com::Utf8Str &aName,
972 LONG aControllerPort,
973 LONG aDevice);
974 HRESULT unmountMedium(const com::Utf8Str &aName,
975 LONG aControllerPort,
976 LONG aDevice,
977 BOOL aForce);
978 HRESULT mountMedium(const com::Utf8Str &aName,
979 LONG aControllerPort,
980 LONG aDevice,
981 const ComPtr<IMedium> &aMedium,
982 BOOL aForce);
983 HRESULT getMedium(const com::Utf8Str &aName,
984 LONG aControllerPort,
985 LONG aDevice,
986 ComPtr<IMedium> &aMedium);
987 HRESULT getMediumAttachmentsOfController(const com::Utf8Str &aName,
988 std::vector<ComPtr<IMediumAttachment> > &aMediumAttachments);
989 HRESULT getMediumAttachment(const com::Utf8Str &aName,
990 LONG aControllerPort,
991 LONG aDevice,
992 ComPtr<IMediumAttachment> &aAttachment);
993 HRESULT attachHostPCIDevice(LONG aHostAddress,
994 LONG aDesiredGuestAddress,
995 BOOL aTryToUnbind);
996 HRESULT detachHostPCIDevice(LONG aHostAddress);
997 HRESULT getNetworkAdapter(ULONG aSlot,
998 ComPtr<INetworkAdapter> &aAdapter);
999 HRESULT addStorageController(const com::Utf8Str &aName,
1000 StorageBus_T aConnectionType,
1001 ComPtr<IStorageController> &aController);
1002 HRESULT getStorageControllerByName(const com::Utf8Str &aName,
1003 ComPtr<IStorageController> &aStorageController);
1004 HRESULT getStorageControllerByInstance(ULONG aInstance,
1005 ComPtr<IStorageController> &aStorageController);
1006 HRESULT removeStorageController(const com::Utf8Str &aName);
1007 HRESULT setStorageControllerBootable(const com::Utf8Str &aName,
1008 BOOL aBootable);
1009 HRESULT addUSBController(const com::Utf8Str &aName,
1010 USBControllerType_T aType,
1011 ComPtr<IUSBController> &aController);
1012 HRESULT removeUSBController(const com::Utf8Str &aName);
1013 HRESULT getUSBControllerByName(const com::Utf8Str &aName,
1014 ComPtr<IUSBController> &aController);
1015 HRESULT getUSBControllerCountByType(USBControllerType_T aType,
1016 ULONG *aControllers);
1017 HRESULT getSerialPort(ULONG aSlot,
1018 ComPtr<ISerialPort> &aPort);
1019 HRESULT getParallelPort(ULONG aSlot,
1020 ComPtr<IParallelPort> &aPort);
1021 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
1022 HRESULT getExtraData(const com::Utf8Str &aKey,
1023 com::Utf8Str &aValue);
1024 HRESULT setExtraData(const com::Utf8Str &aKey,
1025 const com::Utf8Str &aValue);
1026 HRESULT getCPUProperty(CPUPropertyType_T aProperty,
1027 BOOL *aValue);
1028 HRESULT setCPUProperty(CPUPropertyType_T aProperty,
1029 BOOL aValue);
1030 HRESULT getCPUIDLeaf(ULONG aId,
1031 ULONG *aValEax,
1032 ULONG *aValEbx,
1033 ULONG *aValEcx,
1034 ULONG *aValEdx);
1035 HRESULT setCPUIDLeaf(ULONG aId,
1036 ULONG aValEax,
1037 ULONG aValEbx,
1038 ULONG aValEcx,
1039 ULONG aValEdx);
1040 HRESULT removeCPUIDLeaf(ULONG aId);
1041 HRESULT removeAllCPUIDLeaves();
1042 HRESULT getHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1043 BOOL *aValue);
1044 HRESULT setHWVirtExProperty(HWVirtExPropertyType_T aProperty,
1045 BOOL aValue);
1046 HRESULT setSettingsFilePath(const com::Utf8Str &aSettingsFilePath,
1047 ComPtr<IProgress> &aProgress);
1048 HRESULT saveSettings();
1049 HRESULT discardSettings();
1050 HRESULT unregister(CleanupMode_T aCleanupMode,
1051 std::vector<ComPtr<IMedium> > &aMedia);
1052 HRESULT deleteConfig(const std::vector<ComPtr<IMedium> > &aMedia,
1053 ComPtr<IProgress> &aProgress);
1054 HRESULT exportTo(const ComPtr<IAppliance> &aAppliance,
1055 const com::Utf8Str &aLocation,
1056 ComPtr<IVirtualSystemDescription> &aDescription);
1057 HRESULT findSnapshot(const com::Utf8Str &aNameOrId,
1058 ComPtr<ISnapshot> &aSnapshot);
1059 HRESULT createSharedFolder(const com::Utf8Str &aName,
1060 const com::Utf8Str &aHostPath,
1061 BOOL aWritable,
1062 BOOL aAutomount);
1063 HRESULT removeSharedFolder(const com::Utf8Str &aName);
1064 HRESULT canShowConsoleWindow(BOOL *aCanShow);
1065 HRESULT showConsoleWindow(LONG64 *aWinId);
1066 HRESULT getGuestProperty(const com::Utf8Str &aName,
1067 com::Utf8Str &aValue,
1068 LONG64 *aTimestamp,
1069 com::Utf8Str &aFlags);
1070 HRESULT getGuestPropertyValue(const com::Utf8Str &aProperty,
1071 com::Utf8Str &aValue);
1072 HRESULT getGuestPropertyTimestamp(const com::Utf8Str &aProperty,
1073 LONG64 *aValue);
1074 HRESULT setGuestProperty(const com::Utf8Str &aProperty,
1075 const com::Utf8Str &aValue,
1076 const com::Utf8Str &aFlags);
1077 HRESULT setGuestPropertyValue(const com::Utf8Str &aProperty,
1078 const com::Utf8Str &aValue);
1079 HRESULT deleteGuestProperty(const com::Utf8Str &aName);
1080 HRESULT enumerateGuestProperties(const com::Utf8Str &aPatterns,
1081 std::vector<com::Utf8Str> &aNames,
1082 std::vector<com::Utf8Str> &aValues,
1083 std::vector<LONG64> &aTimestamps,
1084 std::vector<com::Utf8Str> &aFlags);
1085 HRESULT querySavedGuestScreenInfo(ULONG aScreenId,
1086 ULONG *aOriginX,
1087 ULONG *aOriginY,
1088 ULONG *aWidth,
1089 ULONG *aHeight,
1090 BOOL *aEnabled);
1091 HRESULT querySavedThumbnailSize(ULONG aScreenId,
1092 ULONG *aSize,
1093 ULONG *aWidth,
1094 ULONG *aHeight);
1095 HRESULT readSavedThumbnailToArray(ULONG aScreenId,
1096 BOOL aBGR,
1097 ULONG *aWidth,
1098 ULONG *aHeight,
1099 std::vector<BYTE> &aData);
1100 HRESULT readSavedThumbnailPNGToArray(ULONG aScreenId,
1101 ULONG *aWidth,
1102 ULONG *aHeight,
1103 std::vector<BYTE> &aData);
1104 HRESULT querySavedScreenshotPNGSize(ULONG aScreenId,
1105 ULONG *aSize,
1106 ULONG *aWidth,
1107 ULONG *aHeight);
1108 HRESULT readSavedScreenshotPNGToArray(ULONG aScreenId,
1109 ULONG *aWidth,
1110 ULONG *aHeight,
1111 std::vector<BYTE> &aData);
1112 HRESULT hotPlugCPU(ULONG aCpu);
1113 HRESULT hotUnplugCPU(ULONG aCpu);
1114 HRESULT getCPUStatus(ULONG aCpu,
1115 BOOL *aAttached);
1116 HRESULT queryLogFilename(ULONG aIdx,
1117 com::Utf8Str &aFilename);
1118 HRESULT readLog(ULONG aIdx,
1119 LONG64 aOffset,
1120 LONG64 aSize,
1121 std::vector<BYTE> &aData);
1122 HRESULT cloneTo(const ComPtr<IMachine> &aTarget,
1123 CloneMode_T aMode,
1124 const std::vector<CloneOptions_T> &aOptions,
1125 ComPtr<IProgress> &aProgress);
1126
1127 // wrapped IInternalMachineControl properties
1128
1129 // wrapped IInternalMachineControl methods
1130 HRESULT setRemoveSavedStateFile(BOOL aRemove);
1131 HRESULT updateState(MachineState_T aState);
1132 HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
1133 HRESULT endPowerUp(LONG aResult);
1134 HRESULT beginPoweringDown(ComPtr<IProgress> &aProgress);
1135 HRESULT endPoweringDown(LONG aResult,
1136 const com::Utf8Str &aErrMsg);
1137 HRESULT runUSBDeviceFilters(const ComPtr<IUSBDevice> &aDevice,
1138 BOOL *aMatched,
1139 ULONG *aMaskedInterfaces);
1140 HRESULT captureUSBDevice(const com::Guid &aId);
1141 HRESULT detachUSBDevice(const com::Guid &aId,
1142 BOOL aDone);
1143 HRESULT autoCaptureUSBDevices();
1144 HRESULT detachAllUSBDevices(BOOL aDone);
1145 HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
1146 ComPtr<IProgress> &aProgress);
1147 HRESULT beginSavingState(ComPtr<IProgress> &aProgress,
1148 com::Utf8Str &aStateFilePath);
1149 HRESULT endSavingState(LONG aResult,
1150 const com::Utf8Str &aErrMsg);
1151 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
1152 HRESULT beginTakingSnapshot(const ComPtr<IConsole> &aInitiator,
1153 const com::Utf8Str &aName,
1154 const com::Utf8Str &aDescription,
1155 const ComPtr<IProgress> &aConsoleProgress,
1156 BOOL aFTakingSnapshotOnline,
1157 com::Utf8Str &aStateFilePath);
1158 HRESULT endTakingSnapshot(BOOL aSuccess);
1159 HRESULT deleteSnapshot(const ComPtr<IConsole> &aInitiator,
1160 const com::Guid &aStartId,
1161 const com::Guid &aEndId,
1162 BOOL aDeleteAllChildren,
1163 MachineState_T *aMachineState,
1164 ComPtr<IProgress> &aProgress);
1165 HRESULT finishOnlineMergeMedium();
1166 HRESULT restoreSnapshot(const ComPtr<IConsole> &aInitiator,
1167 const ComPtr<ISnapshot> &aSnapshot,
1168 MachineState_T *aMachineState,
1169 ComPtr<IProgress> &aProgress);
1170 HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
1171 std::vector<com::Utf8Str> &aValues,
1172 std::vector<LONG64> &aTimestamps,
1173 std::vector<com::Utf8Str> &aFlags);
1174 HRESULT pushGuestProperty(const com::Utf8Str &aName,
1175 const com::Utf8Str &aValue,
1176 LONG64 aTimestamp,
1177 const com::Utf8Str &aFlags);
1178 HRESULT lockMedia();
1179 HRESULT unlockMedia();
1180 HRESULT ejectMedium(const ComPtr<IMediumAttachment> &aAttachment,
1181 ComPtr<IMediumAttachment> &aNewAttachment);
1182 HRESULT reportVmStatistics(ULONG aValidStats,
1183 ULONG aCpuUser,
1184 ULONG aCpuKernel,
1185 ULONG aCpuIdle,
1186 ULONG aMemTotal,
1187 ULONG aMemFree,
1188 ULONG aMemBalloon,
1189 ULONG aMemShared,
1190 ULONG aMemCache,
1191 ULONG aPagedTotal,
1192 ULONG aMemAllocTotal,
1193 ULONG aMemFreeTotal,
1194 ULONG aMemBalloonTotal,
1195 ULONG aMemSharedTotal,
1196 ULONG aVmNetRx,
1197 ULONG aVmNetTx);
1198
1199
1200
1201
1202};
1203
1204// SessionMachine class
1205////////////////////////////////////////////////////////////////////////////////
1206
1207/**
1208 * @note Notes on locking objects of this class:
1209 * SessionMachine shares some data with the primary Machine instance (pointed
1210 * to by the |mPeer| member). In order to provide data consistency it also
1211 * shares its lock handle. This means that whenever you lock a SessionMachine
1212 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1213 * instance is also locked in the same lock mode. Keep it in mind.
1214 */
1215class ATL_NO_VTABLE SessionMachine :
1216 public Machine
1217{
1218public:
1219 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
1220
1221 DECLARE_NOT_AGGREGATABLE(SessionMachine)
1222
1223 DECLARE_PROTECT_FINAL_CONSTRUCT()
1224
1225 BEGIN_COM_MAP(SessionMachine)
1226 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1227 COM_INTERFACE_ENTRY(IInternalMachineControl)
1228 END_COM_MAP()
1229
1230 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
1231
1232 HRESULT FinalConstruct();
1233 void FinalRelease();
1234
1235 struct Uninit
1236 {
1237 enum Reason { Unexpected, Abnormal, Normal };
1238 };
1239
1240 // public initializer/uninitializer for internal purposes only
1241 HRESULT init(Machine *aMachine);
1242 void uninit() { uninit(Uninit::Unexpected); }
1243 void uninit(Uninit::Reason aReason);
1244
1245
1246 // util::Lockable interface
1247 RWLockHandle *lockHandle() const;
1248
1249 // IInternalMachineControl methods
1250 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
1251 STDMETHOD(UpdateState)(MachineState_T machineState);
1252 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
1253 STDMETHOD(EndPowerUp)(LONG iResult);
1254 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
1255 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
1256 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
1257 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
1258 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
1259 STDMETHOD(AutoCaptureUSBDevices)();
1260 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
1261 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
1262 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
1263 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
1264 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
1265 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
1266 IN_BSTR aName,
1267 IN_BSTR aDescription,
1268 IProgress *aConsoleProgress,
1269 BOOL fTakingSnapshotOnline,
1270 BSTR *aStateFilePath);
1271 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
1272 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
1273 IN_BSTR aEndID, BOOL fDeleteAllChildren,
1274 MachineState_T *aMachineState, IProgress **aProgress);
1275 STDMETHOD(FinishOnlineMergeMedium)();
1276 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1277 ISnapshot *aSnapshot,
1278 MachineState_T *aMachineState,
1279 IProgress **aProgress);
1280 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1281 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1282 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1283 LONG64 aTimestamp, IN_BSTR aFlags);
1284 STDMETHOD(LockMedia)();
1285 STDMETHOD(UnlockMedia)();
1286 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1287 IMediumAttachment **aNewAttachment);
1288 STDMETHOD(ReportVmStatistics)(ULONG aValidStats, ULONG aCpuUser,
1289 ULONG aCpuKernel, ULONG aCpuIdle,
1290 ULONG aMemTotal, ULONG aMemFree,
1291 ULONG aMemBalloon, ULONG aMemShared,
1292 ULONG aMemCache, ULONG aPageTotal,
1293 ULONG aAllocVMM, ULONG aFreeVMM,
1294 ULONG aBalloonedVMM, ULONG aSharedVMM,
1295 ULONG aVmNetRx, ULONG aVmNetTx);
1296
1297 // public methods only for internal purposes
1298
1299 virtual bool i_isSessionMachine() const
1300 {
1301 return true;
1302 }
1303
1304#ifndef VBOX_WITH_GENERIC_SESSION_WATCHER
1305 bool i_checkForDeath();
1306
1307 void i_getTokenId(Utf8Str &strTokenId);
1308#else /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1309 IToken *i_getToken();
1310#endif /* VBOX_WITH_GENERIC_SESSION_WATCHER */
1311 // getClientToken must be only used by callers who can guarantee that
1312 // the object cannot be deleted in the mean time, i.e. have a caller/lock.
1313 ClientToken *i_getClientToken();
1314
1315 HRESULT i_onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1316 HRESULT i_onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1317 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort,
1318 IN_BSTR aGuestIp, LONG aGuestPort);
1319 HRESULT i_onStorageControllerChange();
1320 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1321 HRESULT i_onSerialPortChange(ISerialPort *serialPort);
1322 HRESULT i_onParallelPortChange(IParallelPort *parallelPort);
1323 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
1324 HRESULT i_onVRDEServerChange(BOOL aRestart);
1325 HRESULT i_onVideoCaptureChange();
1326 HRESULT i_onUSBControllerChange();
1327 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice,
1328 IVirtualBoxErrorInfo *aError,
1329 ULONG aMaskedIfs);
1330 HRESULT i_onUSBDeviceDetach(IN_BSTR aId,
1331 IVirtualBoxErrorInfo *aError);
1332 HRESULT i_onSharedFolderChange();
1333 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
1334 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
1335 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1336 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
1337 HRESULT i_onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1338
1339 bool i_hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1340
1341 HRESULT lockMedia();
1342 HRESULT unlockMedia();
1343
1344private:
1345
1346 struct ConsoleTaskData
1347 {
1348 ConsoleTaskData()
1349 : mLastState(MachineState_Null), mDeleteSnapshotInfo(NULL)
1350 { }
1351
1352 MachineState_T mLastState;
1353 ComObjPtr<Progress> mProgress;
1354
1355 // used when taking snapshot
1356 ComObjPtr<Snapshot> mSnapshot;
1357
1358 // used when deleting online snapshot
1359 void *mDeleteSnapshotInfo;
1360
1361 // used when saving state (either as part of a snapshot or separate)
1362 Utf8Str strStateFilePath;
1363 };
1364
1365 struct SnapshotTask;
1366 struct DeleteSnapshotTask;
1367 struct RestoreSnapshotTask;
1368
1369 friend struct DeleteSnapshotTask;
1370 friend struct RestoreSnapshotTask;
1371
1372 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1373 void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1374
1375 void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1376 void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1377
1378 HRESULT i_prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1379 const Guid &machineId,
1380 const Guid &snapshotId,
1381 bool fOnlineMergePossible,
1382 MediumLockList *aVMMALockList,
1383 ComObjPtr<Medium> &aSource,
1384 ComObjPtr<Medium> &aTarget,
1385 bool &fMergeForward,
1386 ComObjPtr<Medium> &pParentForTarget,
1387 MediumLockList * &aChildrenToReparent,
1388 bool &fNeedOnlineMerge,
1389 MediumLockList * &aMediumLockList,
1390 ComPtr<IToken> &aHDLockToken);
1391 void i_cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1392 const ComObjPtr<Medium> &aSource,
1393 MediumLockList *aChildrenToReparent,
1394 bool fNeedsOnlineMerge,
1395 MediumLockList *aMediumLockList,
1396 const ComPtr<IToken> &aHDLockToken,
1397 const Guid &aMediumId,
1398 const Guid &aSnapshotId);
1399 HRESULT i_onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1400 const ComObjPtr<Medium> &aSource,
1401 const ComObjPtr<Medium> &aTarget,
1402 bool fMergeForward,
1403 const ComObjPtr<Medium> &pParentForTarget,
1404 MediumLockList *aChildrenToReparent,
1405 MediumLockList *aMediumLockList,
1406 ComObjPtr<Progress> &aProgress,
1407 bool *pfNeedsMachineSaveSettings);
1408
1409 HRESULT i_setMachineState(MachineState_T aMachineState);
1410 HRESULT i_updateMachineStateOnClient();
1411
1412 HRESULT mRemoveSavedState;
1413
1414 ConsoleTaskData mConsoleTaskData;
1415
1416 /** client token for this machine */
1417 ClientToken *mClientToken;
1418
1419 int miNATNetworksStarted;
1420
1421 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1422};
1423
1424// SnapshotMachine class
1425////////////////////////////////////////////////////////////////////////////////
1426
1427/**
1428 * @note Notes on locking objects of this class:
1429 * SnapshotMachine shares some data with the primary Machine instance (pointed
1430 * to by the |mPeer| member). In order to provide data consistency it also
1431 * shares its lock handle. This means that whenever you lock a SessionMachine
1432 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1433 * instance is also locked in the same lock mode. Keep it in mind.
1434 */
1435class ATL_NO_VTABLE SnapshotMachine :
1436 public Machine
1437{
1438public:
1439 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1440
1441 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1442
1443 DECLARE_PROTECT_FINAL_CONSTRUCT()
1444
1445 BEGIN_COM_MAP(SnapshotMachine)
1446 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1447 END_COM_MAP()
1448
1449 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1450
1451 HRESULT FinalConstruct();
1452 void FinalRelease();
1453
1454 // public initializer/uninitializer for internal purposes only
1455 HRESULT init(SessionMachine *aSessionMachine,
1456 IN_GUID aSnapshotId,
1457 const Utf8Str &aStateFilePath);
1458 HRESULT initFromSettings(Machine *aMachine,
1459 const settings::Hardware &hardware,
1460 const settings::Debugging *pDbg,
1461 const settings::Autostart *pAutostart,
1462 const settings::Storage &storage,
1463 IN_GUID aSnapshotId,
1464 const Utf8Str &aStateFilePath);
1465 void uninit();
1466
1467 // util::Lockable interface
1468 RWLockHandle *lockHandle() const;
1469
1470 // public methods only for internal purposes
1471
1472 virtual bool i_isSnapshotMachine() const
1473 {
1474 return true;
1475 }
1476
1477 HRESULT i_onSnapshotChange(Snapshot *aSnapshot);
1478
1479 // unsafe inline public methods for internal purposes only (ensure there is
1480 // a caller and a read lock before calling them!)
1481
1482 const Guid& i_getSnapshotId() const { return mSnapshotId; }
1483
1484private:
1485
1486 Guid mSnapshotId;
1487 /** This field replaces mPeer for SessionMachine instances, as having
1488 * a peer reference is plain meaningless and causes many subtle problems
1489 * with saving settings and the like. */
1490 Machine * const mMachine;
1491
1492 friend class Snapshot;
1493};
1494
1495// third party methods that depend on SnapshotMachine definition
1496
1497inline const Guid &Machine::i_getSnapshotId() const
1498{
1499 return (i_isSnapshotMachine())
1500 ? static_cast<const SnapshotMachine*>(this)->i_getSnapshotId()
1501 : Guid::Empty;
1502}
1503
1504
1505#endif // ____H_MACHINEIMPL
1506/* 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