VirtualBox

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

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

Main: live snapshot merging. initially limited to forward merging (i.e. everything but the first snapshot can be deleted)

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