VirtualBox

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

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

Added page fusion xml config entry

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