VirtualBox

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

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

Main: remove unused arg

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