VirtualBox

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

Last change on this file since 26440 was 26440, checked in by vboxsync, 15 years ago

Main: configurable HID types work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.4 KB
Line 
1/* $Id: MachineImpl.h 26440 2010-02-11 16:18:31Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class declaration
6 */
7
8/*
9 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_MACHINEIMPL
25#define ____H_MACHINEIMPL
26
27#include "VirtualBoxBase.h"
28#include "SnapshotImpl.h"
29#include "VRDPServerImpl.h"
30#include "MediumAttachmentImpl.h"
31#include "NetworkAdapterImpl.h"
32#include "AudioAdapterImpl.h"
33#include "SerialPortImpl.h"
34#include "ParallelPortImpl.h"
35#include "BIOSSettingsImpl.h"
36#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
37#include "VBox/settings.h"
38#ifdef VBOX_WITH_RESOURCE_USAGE_API
39#include "PerformanceImpl.h"
40#endif /* VBOX_WITH_RESOURCE_USAGE_API */
41
42// generated header
43#include "SchemaDefs.h"
44
45#include <VBox/types.h>
46
47#include <iprt/file.h>
48#include <iprt/thread.h>
49#include <iprt/time.h>
50
51#include <list>
52
53// defines
54////////////////////////////////////////////////////////////////////////////////
55
56// helper declarations
57////////////////////////////////////////////////////////////////////////////////
58
59class Progress;
60class Keyboard;
61class Mouse;
62class Display;
63class MachineDebugger;
64class USBController;
65class Snapshot;
66class SharedFolder;
67class HostUSBDevice;
68class StorageController;
69
70class SessionMachine;
71
72namespace settings
73{
74 class MachineConfigFile;
75 struct Snapshot;
76 struct Hardware;
77 struct Storage;
78 struct StorageController;
79 struct MachineRegistryEntry;
80}
81
82// Machine class
83////////////////////////////////////////////////////////////////////////////////
84
85class ATL_NO_VTABLE Machine :
86 public VirtualBoxBaseWithChildrenNEXT,
87 public VirtualBoxSupportErrorInfoImpl<Machine, IMachine>,
88 public VirtualBoxSupportTranslation<Machine>,
89 VBOX_SCRIPTABLE_IMPL(IMachine)
90{
91 Q_OBJECT
92
93public:
94
95 enum InitMode { Init_New, Init_Import, Init_Registered };
96
97 enum StateDependency
98 {
99 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
100 };
101
102 /**
103 * Internal machine data.
104 *
105 * Only one instance of this data exists per every machine -- it is shared
106 * by the Machine, SessionMachine and all SnapshotMachine instances
107 * associated with the given machine using the util::Shareable template
108 * through the mData variable.
109 *
110 * @note |const| members are persistent during lifetime so can be
111 * accessed without locking.
112 *
113 * @note There is no need to lock anything inside init() or uninit()
114 * methods, because they are always serialized (see AutoCaller).
115 */
116 struct Data
117 {
118 /**
119 * Data structure to hold information about sessions opened for the
120 * given machine.
121 */
122 struct Session
123 {
124 /** Control of the direct session opened by openSession() */
125 ComPtr<IInternalSessionControl> mDirectControl;
126
127 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
128
129 /** list of controls of all opened remote sessions */
130 RemoteControlList mRemoteControls;
131
132 /** openRemoteSession() and OnSessionEnd() progress indicator */
133 ComObjPtr<Progress> mProgress;
134
135 /**
136 * PID of the session object that must be passed to openSession() to
137 * finalize the openRemoteSession() request (i.e., PID of the
138 * process created by openRemoteSession())
139 */
140 RTPROCESS mPid;
141
142 /** Current session state */
143 SessionState_T mState;
144
145 /** Session type string (for indirect sessions) */
146 Bstr mType;
147
148 /** Session machine object */
149 ComObjPtr<SessionMachine> mMachine;
150
151 /**
152 * Successfully locked media list. The 2nd value in the pair is true
153 * if the medium is locked for writing and false if locked for
154 * reading.
155 */
156 typedef std::list<std::pair<ComPtr<IMedium>, bool > > LockedMedia;
157 LockedMedia mLockedMedia;
158 };
159
160 Data();
161 ~Data();
162
163 const Guid mUuid;
164 BOOL mRegistered;
165 InitMode mInitMode;
166
167 /** Flag indicating that the config file is read-only. */
168 BOOL mConfigFileReadonly;
169 Utf8Str m_strConfigFile;
170 Utf8Str m_strConfigFileFull;
171
172 // machine settings XML file
173 settings::MachineConfigFile *m_pMachineConfigFile;
174
175 BOOL mAccessible;
176 com::ErrorInfo mAccessError;
177
178 MachineState_T mMachineState;
179 RTTIMESPEC mLastStateChange;
180
181 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
182 uint32_t mMachineStateDeps;
183 RTSEMEVENTMULTI mMachineStateDepsSem;
184 uint32_t mMachineStateChangePending;
185
186 BOOL mCurrentStateModified;
187
188 RTFILE mHandleCfgFile;
189
190 Session mSession;
191
192 ComObjPtr<Snapshot> mFirstSnapshot;
193 ComObjPtr<Snapshot> mCurrentSnapshot;
194 };
195
196 /**
197 * Saved state data.
198 *
199 * It's actually only the state file path string, but it needs to be
200 * separate from Data, because Machine and SessionMachine instances
201 * share it, while SnapshotMachine does not.
202 *
203 * The data variable is |mSSData|.
204 */
205 struct SSData
206 {
207 Utf8Str mStateFilePath;
208 };
209
210 /**
211 * User changeable machine data.
212 *
213 * This data is common for all machine snapshots, i.e. it is shared
214 * by all SnapshotMachine instances associated with the given machine
215 * using the util::Backupable template through the |mUserData| variable.
216 *
217 * SessionMachine instances can alter this data and discard changes.
218 *
219 * @note There is no need to lock anything inside init() or uninit()
220 * methods, because they are always serialized (see AutoCaller).
221 */
222 struct UserData
223 {
224 UserData();
225 ~UserData();
226
227 Bstr mName;
228 BOOL mNameSync;
229 Bstr mDescription;
230 Bstr mOSTypeId;
231 Bstr mSnapshotFolder;
232 Bstr mSnapshotFolderFull;
233 BOOL mTeleporterEnabled;
234 ULONG mTeleporterPort;
235 Bstr mTeleporterAddress;
236 Bstr mTeleporterPassword;
237 BOOL mRTCUseUTC;
238 };
239
240 /**
241 * Hardware data.
242 *
243 * This data is unique for a machine and for every machine snapshot.
244 * Stored using the util::Backupable template in the |mHWData| variable.
245 *
246 * SessionMachine instances can alter this data and discard changes.
247 */
248 struct HWData
249 {
250 /**
251 * Data structure to hold information about a guest property.
252 */
253 struct GuestProperty {
254 /** Property name */
255 Utf8Str strName;
256 /** Property value */
257 Utf8Str strValue;
258 /** Property timestamp */
259 ULONG64 mTimestamp;
260 /** Property flags */
261 ULONG mFlags;
262 };
263
264 HWData();
265 ~HWData();
266
267 Bstr mHWVersion;
268 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
269 ULONG mMemorySize;
270 ULONG mMemoryBalloonSize;
271 ULONG mStatisticsUpdateInterval;
272 ULONG mVRAMSize;
273 ULONG mMonitorCount;
274 BOOL mHWVirtExEnabled;
275 BOOL mHWVirtExExclusive;
276 BOOL mHWVirtExNestedPagingEnabled;
277 BOOL mHWVirtExVPIDEnabled;
278 BOOL mAccelerate2DVideoEnabled;
279 BOOL mPAEEnabled;
280 BOOL mSyntheticCpu;
281 ULONG mCPUCount;
282 BOOL mCPUHotPlugEnabled;
283 BOOL mAccelerate3DEnabled;
284
285 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
286
287 settings::CpuIdLeaf mCpuIdStdLeafs[10];
288 settings::CpuIdLeaf mCpuIdExtLeafs[10];
289
290 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
291
292 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
293 SharedFolderList mSharedFolders;
294
295 ClipboardMode_T mClipboardMode;
296
297 typedef std::list<GuestProperty> GuestPropertyList;
298 GuestPropertyList mGuestProperties;
299 BOOL mPropertyServiceActive;
300 Utf8Str mGuestPropertyNotificationPatterns;
301
302 FirmwareType_T mFirmwareType;
303 KeyboardHidType_T mKeyboardHidType;
304 PointingHidType_T mPointingHidType;
305 };
306
307 /**
308 * Hard disk and other media data.
309 *
310 * The usage policy is the same as for HWData, but a separate structure
311 * is necessary because hard disk data requires different procedures when
312 * taking or discarding snapshots, etc.
313 *
314 * The data variable is |mMediaData|.
315 */
316 struct MediaData
317 {
318 MediaData();
319 ~MediaData();
320
321 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
322 AttachmentList mAttachments;
323 };
324
325 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine)
326
327 DECLARE_NOT_AGGREGATABLE(Machine)
328
329 DECLARE_PROTECT_FINAL_CONSTRUCT()
330
331 BEGIN_COM_MAP(Machine)
332 COM_INTERFACE_ENTRY(ISupportErrorInfo)
333 COM_INTERFACE_ENTRY(IMachine)
334 COM_INTERFACE_ENTRY(IDispatch)
335 END_COM_MAP()
336
337 DECLARE_EMPTY_CTOR_DTOR(Machine)
338
339 HRESULT FinalConstruct();
340 void FinalRelease();
341
342 // public initializer/uninitializer for internal purposes only
343 HRESULT init(VirtualBox *aParent,
344 const Utf8Str &strConfigFile,
345 InitMode aMode,
346 CBSTR aName = NULL,
347 GuestOSType *aOsType = NULL,
348 BOOL aNameSync = TRUE,
349 const Guid *aId = NULL);
350 void uninit();
351
352protected:
353 HRESULT initDataAndChildObjects();
354 void uninitDataAndChildObjects();
355
356public:
357 // IMachine properties
358 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
359 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
360 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
361 STDMETHOD(COMGETTER(Name))(BSTR *aName);
362 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
363 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
364 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
365 STDMETHOD(COMGETTER(Id))(BSTR *aId);
366 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
367 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
368 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
369 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
370 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
371 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
372 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
373 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
374 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
375 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
376 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
377 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
378 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
379 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
380 STDMETHOD(COMGETTER(StatisticsUpdateInterval))(ULONG *statisticsUpdateInterval);
381 STDMETHOD(COMSETTER(StatisticsUpdateInterval))(ULONG statisticsUpdateInterval);
382 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
383 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
384 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
385 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
386 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
387 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
388 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
389 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
390 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
391 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
392 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
393 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
394 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
395 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
396 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
397 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
398 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
399 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
400 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
401 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
402 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
403 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
404 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
405 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
406 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
407 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
408 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
409 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
410 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
411 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
412 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
413 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
414 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
415 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
416 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
417 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
418 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
419 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
420 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
421 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
422 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
423 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
424 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
425
426 // IMachine methods
427 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
428 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
429 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
430 LONG aDevice, DeviceType_T aType, IN_BSTR aId);
431 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
432 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
433 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
434 LONG aDevice, IN_BSTR aId, BOOL aForce);
435 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
436 IMedium **aMedium);
437 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
438 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
439 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
440 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
441 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
442 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
443 STDMETHOD(GetCpuProperty)(CpuPropertyType_T property, BOOL *aVal);
444 STDMETHOD(SetCpuProperty)(CpuPropertyType_T property, BOOL aVal);
445 STDMETHOD(GetCpuIdLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
446 STDMETHOD(SetCpuIdLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
447 STDMETHOD(RemoveCpuIdLeaf)(ULONG id);
448 STDMETHOD(RemoveAllCpuIdLeafs)();
449 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
450 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
451 STDMETHOD(SaveSettings)();
452 STDMETHOD(DiscardSettings)();
453 STDMETHOD(DeleteSettings)();
454 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
455 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
456 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
457 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
458 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
459 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
460 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
461 STDMETHOD(ShowConsoleWindow)(ULONG64 *aWinId);
462 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
463 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
464 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, ULONG64 *aTimestamp);
465 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
466 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
467 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
468 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
469 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
470 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
471 STDMETHOD(RemoveStorageController(IN_BSTR aName));
472 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
473 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
474 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
475 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
476 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
477 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
478 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
479 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
480
481 STDMETHOD(QuerySavedThumbnailSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
482 STDMETHOD(ReadSavedThumbnailToArray)(BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
483 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
484 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
485 STDMETHOD(HotPlugCPU(ULONG aCpu));
486 STDMETHOD(HotUnplugCPU(ULONG aCpu));
487 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
488
489 // public methods only for internal purposes
490
491 /**
492 * Simple run-time type identification without having to enable C++ RTTI.
493 * The class IDs are defined in VirtualBoxBase.h.
494 * @return
495 */
496 virtual VBoxClsID getClassID() const
497 {
498 return clsidMachine;
499 }
500
501 /**
502 * Override of the default locking class to be used for validating lock
503 * order with the standard member lock handle.
504 */
505 virtual VBoxLockingClass getLockingClass() const
506 {
507 return LOCKCLASS_MACHINEOBJECT;
508 }
509
510 /// @todo (dmik) add lock and make non-inlined after revising classes
511 // that use it. Note: they should enter Machine lock to keep the returned
512 // information valid!
513 bool isRegistered() { return !!mData->mRegistered; }
514
515 // unsafe inline public methods for internal purposes only (ensure there is
516 // a caller and a read lock before calling them!)
517
518 /**
519 * Returns the VirtualBox object this machine belongs to.
520 *
521 * @note This method doesn't check this object's readiness. Intended to be
522 * used by ready Machine children (whose readiness is bound to the parent's
523 * one) or after doing addCaller() manually.
524 */
525 const ComObjPtr<VirtualBox, ComWeakRef>& getVirtualBox() const { return mParent; }
526
527 /**
528 * Returns this machine ID.
529 *
530 * @note This method doesn't check this object's readiness. Intended to be
531 * used by ready Machine children (whose readiness is bound to the parent's
532 * one) or after adding a caller manually.
533 */
534 const Guid& getId() const { return mData->mUuid; }
535
536 /**
537 * Returns the snapshot ID this machine represents or an empty UUID if this
538 * instance is not SnapshotMachine.
539 *
540 * @note This method doesn't check this object's readiness. Intended to be
541 * used by ready Machine children (whose readiness is bound to the parent's
542 * one) or after adding a caller manually.
543 */
544 inline const Guid& getSnapshotId() const;
545
546 /**
547 * Returns this machine's full settings file path.
548 *
549 * @note This method doesn't lock this object or check its readiness.
550 * Intended to be used only after doing addCaller() manually and locking it
551 * for reading.
552 */
553 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
554
555 /**
556 * Returns this machine name.
557 *
558 * @note This method doesn't lock this object or check its readiness.
559 * Intended to be used only after doing addCaller() manually and locking it
560 * for reading.
561 */
562 const Bstr& getName() const { return mUserData->mName; }
563
564 enum
565 {
566 IsModified_MachineData = 0x0001,
567 IsModified_Storage = 0x0002,
568 IsModified_NetworkAdapters = 0x0008,
569 IsModified_SerialPorts = 0x0010,
570 IsModified_ParallelPorts = 0x0020,
571 IsModified_VRDPServer = 0x0040,
572 IsModified_AudioAdapter = 0x0080,
573 IsModified_USB = 0x0100,
574 IsModified_BIOS = 0x0200,
575 IsModified_SharedFolders = 0x0400
576 };
577
578 void setModified(uint32_t fl);
579
580 // callback handlers
581 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
582 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
583 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
584 virtual HRESULT onVRDPServerChange() { return S_OK; }
585 virtual HRESULT onUSBControllerChange() { return S_OK; }
586 virtual HRESULT onStorageControllerChange() { return S_OK; }
587 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
588 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
589 virtual HRESULT onSharedFolderChange() { return S_OK; }
590
591 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
592
593 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
594 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
595
596 void getLogFolder(Utf8Str &aLogFolder);
597
598 HRESULT openSession(IInternalSessionControl *aControl);
599 HRESULT openRemoteSession(IInternalSessionControl *aControl,
600 IN_BSTR aType, IN_BSTR aEnvironment,
601 Progress *aProgress);
602 HRESULT openExistingSession(IInternalSessionControl *aControl);
603
604#if defined(RT_OS_WINDOWS)
605
606 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
607 ComPtr<IInternalSessionControl> *aControl = NULL,
608 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
609 bool isSessionSpawning(RTPROCESS *aPID = NULL);
610
611 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
612 ComPtr<IInternalSessionControl> *aControl = NULL,
613 HANDLE *aIPCSem = NULL)
614 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
615
616#elif defined(RT_OS_OS2)
617
618 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
619 ComPtr<IInternalSessionControl> *aControl = NULL,
620 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
621
622 bool isSessionSpawning(RTPROCESS *aPID = NULL);
623
624 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
625 ComPtr<IInternalSessionControl> *aControl = NULL,
626 HMTX *aIPCSem = NULL)
627 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
628
629#else
630
631 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
632 ComPtr<IInternalSessionControl> *aControl = NULL,
633 bool aAllowClosing = false);
634 bool isSessionSpawning();
635
636 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
637 ComPtr<IInternalSessionControl> *aControl = NULL)
638 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
639
640#endif
641
642 bool checkForSpawnFailure();
643
644 HRESULT trySetRegistered(BOOL aRegistered);
645
646 HRESULT getSharedFolder(CBSTR aName,
647 ComObjPtr<SharedFolder> &aSharedFolder,
648 bool aSetError = false)
649 {
650 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
651 return findSharedFolder(aName, aSharedFolder, aSetError);
652 }
653
654 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
655 MachineState_T *aState = NULL,
656 BOOL *aRegistered = NULL);
657 void releaseStateDependency();
658
659 // for VirtualBoxSupportErrorInfoImpl
660 static const wchar_t *getComponentName() { return L"Machine"; }
661
662protected:
663
664 HRESULT registeredInit();
665
666 HRESULT checkStateDependency(StateDependency aDepType);
667
668 inline Machine *getMachine();
669
670 void ensureNoStateDependencies();
671
672 virtual HRESULT setMachineState(MachineState_T aMachineState);
673
674 HRESULT findSharedFolder(CBSTR aName,
675 ComObjPtr<SharedFolder> &aSharedFolder,
676 bool aSetError = false);
677
678 HRESULT loadSettings(bool aRegistered);
679 HRESULT loadSnapshot(const settings::Snapshot &data,
680 const Guid &aCurSnapshotId,
681 Snapshot *aParentSnapshot);
682 HRESULT loadHardware(const settings::Hardware &data);
683 HRESULT loadStorageControllers(const settings::Storage &data,
684 bool aRegistered,
685 const Guid *aSnapshotId = NULL);
686 HRESULT loadStorageDevices(StorageController *aStorageController,
687 const settings::StorageController &data,
688 bool aRegistered,
689 const Guid *aSnapshotId = NULL);
690
691 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
692 bool aSetError = false);
693 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
694 bool aSetError = false);
695
696 HRESULT getStorageControllerByName(const Utf8Str &aName,
697 ComObjPtr<StorageController> &aStorageController,
698 bool aSetError = false);
699
700 HRESULT getMediumAttachmentsOfController(CBSTR aName,
701 MediaData::AttachmentList &aAttachments);
702
703 enum
704 {
705 /* flags for #saveSettings() */
706 SaveS_ResetCurStateModified = 0x01,
707 SaveS_InformCallbacksAnyway = 0x02,
708 /* flags for #saveSnapshotSettings() */
709 SaveSS_CurStateModified = 0x40,
710 SaveSS_CurrentId = 0x80,
711 /* flags for #saveStateSettings() */
712 SaveSTS_CurStateModified = 0x20,
713 SaveSTS_StateFilePath = 0x40,
714 SaveSTS_StateTimeStamp = 0x80,
715 };
716
717 HRESULT prepareSaveSettings(bool &aRenamed, bool &aNew);
718 HRESULT saveSettings(int aFlags = 0);
719
720 HRESULT saveAllSnapshots();
721
722 HRESULT saveHardware(settings::Hardware &data);
723 HRESULT saveStorageControllers(settings::Storage &data);
724 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
725 settings::StorageController &data);
726
727 HRESULT saveStateSettings(int aFlags);
728
729 HRESULT createImplicitDiffs(const Bstr &aFolder,
730 IProgress *aProgress,
731 ULONG aWeight,
732 bool aOnline,
733 bool *pfNeedsSaveSettings);
734 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
735
736 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
737 IN_BSTR aControllerName,
738 LONG aControllerPort,
739 LONG aDevice);
740 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
741 ComObjPtr<Medium> pMedium);
742 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
743 Guid &id);
744
745 void commitMedia(bool aOnline = false);
746 void rollbackMedia();
747
748 bool isInOwnDir(Utf8Str *aSettingsDir = NULL);
749
750 void rollback(bool aNotify);
751 void commit();
752 void copyFrom(Machine *aThat);
753
754#ifdef VBOX_WITH_RESOURCE_USAGE_API
755 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
756 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
757#endif /* VBOX_WITH_RESOURCE_USAGE_API */
758
759 const ComObjPtr<Machine, ComWeakRef> mPeer;
760
761 const ComObjPtr<VirtualBox, ComWeakRef> mParent;
762
763 uint32_t m_flModifications;
764
765 Shareable<Data> mData;
766 Shareable<SSData> mSSData;
767
768 Backupable<UserData> mUserData;
769 Backupable<HWData> mHWData;
770 Backupable<MediaData> mMediaData;
771
772 // the following fields need special backup/rollback/commit handling,
773 // so they cannot be a part of HWData
774
775 const ComObjPtr<VRDPServer> mVRDPServer;
776 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
777 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
778 const ComObjPtr<AudioAdapter> mAudioAdapter;
779 const ComObjPtr<USBController> mUSBController;
780 const ComObjPtr<BIOSSettings> mBIOSSettings;
781 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
782
783 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
784 Backupable<StorageControllerList> mStorageControllers;
785
786 friend class SessionMachine;
787 friend class SnapshotMachine;
788};
789
790// SessionMachine class
791////////////////////////////////////////////////////////////////////////////////
792
793/**
794 * @note Notes on locking objects of this class:
795 * SessionMachine shares some data with the primary Machine instance (pointed
796 * to by the |mPeer| member). In order to provide data consistency it also
797 * shares its lock handle. This means that whenever you lock a SessionMachine
798 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
799 * instance is also locked in the same lock mode. Keep it in mind.
800 */
801class ATL_NO_VTABLE SessionMachine :
802 public VirtualBoxSupportTranslation<SessionMachine>,
803 public Machine,
804 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
805{
806public:
807
808 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
809
810 DECLARE_NOT_AGGREGATABLE(SessionMachine)
811
812 DECLARE_PROTECT_FINAL_CONSTRUCT()
813
814 BEGIN_COM_MAP(SessionMachine)
815 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
816 COM_INTERFACE_ENTRY(ISupportErrorInfo)
817 COM_INTERFACE_ENTRY(IMachine)
818 COM_INTERFACE_ENTRY(IInternalMachineControl)
819 END_COM_MAP()
820
821 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
822
823 HRESULT FinalConstruct();
824 void FinalRelease();
825
826 // public initializer/uninitializer for internal purposes only
827 HRESULT init(Machine *aMachine);
828 void uninit() { uninit(Uninit::Unexpected); }
829
830 // util::Lockable interface
831 RWLockHandle *lockHandle() const;
832
833 // IInternalMachineControl methods
834 STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
835 STDMETHOD(UpdateState)(MachineState_T machineState);
836 STDMETHOD(GetIPCId)(BSTR *id);
837 STDMETHOD(SetPowerUpInfo)(IVirtualBoxErrorInfo *aError);
838 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
839 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
840 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
841 STDMETHOD(AutoCaptureUSBDevices)();
842 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
843 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
844 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
845 STDMETHOD(EndSavingState)(BOOL aSuccess);
846 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
847 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
848 IN_BSTR aName,
849 IN_BSTR aDescription,
850 IProgress *aConsoleProgress,
851 BOOL fTakingSnapshotOnline,
852 BSTR *aStateFilePath);
853 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
854 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
855 MachineState_T *aMachineState, IProgress **aProgress);
856 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
857 ISnapshot *aSnapshot,
858 MachineState_T *aMachineState,
859 IProgress **aProgress);
860 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
861 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
862 STDMETHOD(PushGuestProperties)(ComSafeArrayIn(IN_BSTR, aNames), ComSafeArrayIn(IN_BSTR, aValues),
863 ComSafeArrayIn(ULONG64, aTimestamps), ComSafeArrayIn(IN_BSTR, aFlags));
864 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
865 ULONG64 aTimestamp, IN_BSTR aFlags);
866 STDMETHOD(LockMedia)() { return lockMedia(); }
867 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
868
869 // public methods only for internal purposes
870
871 /**
872 * Simple run-time type identification without having to enable C++ RTTI.
873 * The class IDs are defined in VirtualBoxBase.h.
874 * @return
875 */
876 virtual VBoxClsID getClassID() const
877 {
878 return clsidSessionMachine;
879 }
880
881 bool checkForDeath();
882
883 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
884 HRESULT onStorageControllerChange();
885 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
886 HRESULT onSerialPortChange(ISerialPort *serialPort);
887 HRESULT onParallelPortChange(IParallelPort *parallelPort);
888 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
889 HRESULT onVRDPServerChange();
890 HRESULT onUSBControllerChange();
891 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
892 IVirtualBoxErrorInfo *aError,
893 ULONG aMaskedIfs);
894 HRESULT onUSBDeviceDetach(IN_BSTR aId,
895 IVirtualBoxErrorInfo *aError);
896 HRESULT onSharedFolderChange();
897
898 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
899
900private:
901
902 struct SnapshotData
903 {
904 SnapshotData() : mLastState(MachineState_Null) {}
905
906 MachineState_T mLastState;
907
908 // used when taking snapshot
909 ComObjPtr<Snapshot> mSnapshot;
910
911 // used when saving state
912 Guid mProgressId;
913 Utf8Str mStateFilePath;
914 };
915
916 struct Uninit
917 {
918 enum Reason { Unexpected, Abnormal, Normal };
919 };
920
921 struct SnapshotTask;
922 struct DeleteSnapshotTask;
923 struct RestoreSnapshotTask;
924
925 friend struct DeleteSnapshotTask;
926 friend struct RestoreSnapshotTask;
927
928 void uninit(Uninit::Reason aReason);
929
930 HRESULT endSavingState(BOOL aSuccess);
931
932 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
933
934 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
935 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
936
937 HRESULT lockMedia();
938 void unlockMedia();
939
940 HRESULT setMachineState(MachineState_T aMachineState);
941 HRESULT updateMachineStateOnClient();
942
943 HRESULT mRemoveSavedState;
944
945 SnapshotData mSnapshotData;
946
947 /** interprocess semaphore handle for this machine */
948#if defined(RT_OS_WINDOWS)
949 HANDLE mIPCSem;
950 Bstr mIPCSemName;
951 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
952 ComPtr<IInternalSessionControl> *aControl,
953 HANDLE *aIPCSem, bool aAllowClosing);
954#elif defined(RT_OS_OS2)
955 HMTX mIPCSem;
956 Bstr mIPCSemName;
957 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
958 ComPtr<IInternalSessionControl> *aControl,
959 HMTX *aIPCSem, bool aAllowClosing);
960#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
961 int mIPCSem;
962# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
963 Bstr mIPCKey;
964# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
965#else
966# error "Port me!"
967#endif
968
969 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
970};
971
972// SnapshotMachine class
973////////////////////////////////////////////////////////////////////////////////
974
975/**
976 * @note Notes on locking objects of this class:
977 * SnapshotMachine shares some data with the primary Machine instance (pointed
978 * to by the |mPeer| member). In order to provide data consistency it also
979 * shares its lock handle. This means that whenever you lock a SessionMachine
980 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
981 * instance is also locked in the same lock mode. Keep it in mind.
982 */
983class ATL_NO_VTABLE SnapshotMachine :
984 public VirtualBoxSupportTranslation<SnapshotMachine>,
985 public Machine
986{
987public:
988
989 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
990
991 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
992
993 DECLARE_PROTECT_FINAL_CONSTRUCT()
994
995 BEGIN_COM_MAP(SnapshotMachine)
996 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
997 COM_INTERFACE_ENTRY(ISupportErrorInfo)
998 COM_INTERFACE_ENTRY(IMachine)
999 END_COM_MAP()
1000
1001 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1002
1003 HRESULT FinalConstruct();
1004 void FinalRelease();
1005
1006 // public initializer/uninitializer for internal purposes only
1007 HRESULT init(SessionMachine *aSessionMachine,
1008 IN_GUID aSnapshotId,
1009 const Utf8Str &aStateFilePath);
1010 HRESULT init(Machine *aMachine,
1011 const settings::Hardware &hardware,
1012 const settings::Storage &storage,
1013 IN_GUID aSnapshotId,
1014 const Utf8Str &aStateFilePath);
1015 void uninit();
1016
1017 // util::Lockable interface
1018 RWLockHandle *lockHandle() const;
1019
1020 // public methods only for internal purposes
1021
1022 /**
1023 * Simple run-time type identification without having to enable C++ RTTI.
1024 * The class IDs are defined in VirtualBoxBase.h.
1025 * @return
1026 */
1027 virtual VBoxClsID getClassID() const
1028 {
1029 return clsidSnapshotMachine;
1030 }
1031
1032 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1033
1034 // unsafe inline public methods for internal purposes only (ensure there is
1035 // a caller and a read lock before calling them!)
1036
1037 const Guid& getSnapshotId() const { return mSnapshotId; }
1038
1039private:
1040
1041 Guid mSnapshotId;
1042
1043 friend class Snapshot;
1044};
1045
1046// third party methods that depend on SnapshotMachine definiton
1047
1048inline const Guid &Machine::getSnapshotId() const
1049{
1050 return getClassID() != clsidSnapshotMachine
1051 ? Guid::Empty
1052 : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
1053}
1054
1055////////////////////////////////////////////////////////////////////////////////
1056
1057/**
1058 * Returns a pointer to the Machine object for this machine that acts like a
1059 * parent for complex machine data objects such as shared folders, etc.
1060 *
1061 * For primary Machine objects and for SnapshotMachine objects, returns this
1062 * object's pointer itself. For SessoinMachine objects, returns the peer
1063 * (primary) machine pointer.
1064 */
1065inline Machine *Machine::getMachine()
1066{
1067 if (getClassID() == clsidSessionMachine)
1068 return mPeer;
1069 return this;
1070}
1071
1072
1073#endif // ____H_MACHINEIMPL
1074/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette