VirtualBox

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

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

Main/Settings: Drop global iomgr and iobackend settings

  • 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 29218 2010-05-07 14:52:27Z 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.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
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 BOOL mIoCacheEnabled;
299 ULONG mIoCacheSize;
300 ULONG mIoBandwidthMax;
301 };
302
303 /**
304 * Hard disk and other media data.
305 *
306 * The usage policy is the same as for HWData, but a separate structure
307 * is necessary because hard disk data requires different procedures when
308 * taking or deleting snapshots, etc.
309 *
310 * The data variable is |mMediaData|.
311 */
312 struct MediaData
313 {
314 MediaData();
315 ~MediaData();
316
317 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
318 AttachmentList mAttachments;
319 };
320
321 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine)
322
323 DECLARE_NOT_AGGREGATABLE(Machine)
324
325 DECLARE_PROTECT_FINAL_CONSTRUCT()
326
327 BEGIN_COM_MAP(Machine)
328 COM_INTERFACE_ENTRY(ISupportErrorInfo)
329 COM_INTERFACE_ENTRY(IMachine)
330 COM_INTERFACE_ENTRY(IDispatch)
331 END_COM_MAP()
332
333 DECLARE_EMPTY_CTOR_DTOR(Machine)
334
335 HRESULT FinalConstruct();
336 void FinalRelease();
337
338 // public initializer/uninitializer for internal purposes only:
339
340 // initializer for creating a new, empty machine
341 HRESULT init(VirtualBox *aParent,
342 const Utf8Str &strConfigFile,
343 const Utf8Str &strName,
344 const Guid &aId,
345 GuestOSType *aOsType = NULL,
346 BOOL aOverride = FALSE,
347 BOOL aNameSync = TRUE);
348
349 // initializer for loading existing machine XML (either registered or not)
350 HRESULT init(VirtualBox *aParent,
351 const Utf8Str &strConfigFile,
352 const Guid *aId);
353
354 // initializer for machine config in memory (OVF import)
355 HRESULT init(VirtualBox *aParent,
356 const Utf8Str &strName,
357 const settings::MachineConfigFile &config);
358
359 void uninit();
360
361protected:
362 HRESULT initImpl(VirtualBox *aParent,
363 const Utf8Str &strConfigFile);
364 HRESULT initDataAndChildObjects();
365 HRESULT registeredInit();
366 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
367 void uninitDataAndChildObjects();
368
369public:
370 // IMachine properties
371 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
372 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
373 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
374 STDMETHOD(COMGETTER(Name))(BSTR *aName);
375 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
376 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
377 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
378 STDMETHOD(COMGETTER(Id))(BSTR *aId);
379 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
380 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
381 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
382 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
383 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
384 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
385 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
386 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
387 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
388 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
389 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
390 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
391 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
392 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
393 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
394 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
395 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
396 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
397 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
398 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
399 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
402 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
403 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
404 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
405 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
406 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
407 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
408 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
409 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
410 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
411 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
412 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
413 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
414 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
415 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
416 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
417 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
418 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
419 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
420 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
421 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
422 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
423 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
424 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
425 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
426 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
427 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
428 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
429 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
430 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
431 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
432 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
433 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
434 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
435 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
436 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
437 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
438 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
439 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
440 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
441 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
442 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
443 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
444 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
445 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
446 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
447 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
448 STDMETHOD(COMGETTER(IoBandwidthMax)) (ULONG *aIoBandwidthMax);
449 STDMETHOD(COMSETTER(IoBandwidthMax)) (ULONG aIoBandwidthMax);
450
451 // IMachine methods
452 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
453 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
454 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
455 LONG aDevice, DeviceType_T aType, IN_BSTR aId);
456 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
457 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
458 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
459 LONG aDevice, IN_BSTR aId, BOOL aForce);
460 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
461 IMedium **aMedium);
462 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
463 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
464 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
465 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
466 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
467 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
468 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
469 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
470 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
471 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
472 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
473 STDMETHOD(RemoveAllCPUIDLeaves)();
474 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
475 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
476 STDMETHOD(SaveSettings)();
477 STDMETHOD(DiscardSettings)();
478 STDMETHOD(DeleteSettings)();
479 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
480 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
481 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
482 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
483 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
484 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
485 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
486 STDMETHOD(ShowConsoleWindow)(ULONG64 *aWinId);
487 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
488 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
489 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, ULONG64 *aTimestamp);
490 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
491 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
492 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
493 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
494 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
495 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
496 STDMETHOD(RemoveStorageController(IN_BSTR aName));
497 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
498 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
499 STDMETHOD(QuerySavedThumbnailSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
500 STDMETHOD(ReadSavedThumbnailToArray)(BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
501 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
502 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
503 STDMETHOD(HotPlugCPU(ULONG aCpu));
504 STDMETHOD(HotUnplugCPU(ULONG aCpu));
505 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
506 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
507 STDMETHOD(ReadLog(ULONG aIdx, ULONG64 aOffset, ULONG64 aSize, ComSafeArrayOut(BYTE, aData)));
508
509 // public methods only for internal purposes
510
511 /**
512 * Simple run-time type identification without having to enable C++ RTTI.
513 * The class IDs are defined in VirtualBoxBase.h.
514 * @return
515 */
516 virtual VBoxClsID getClassID() const
517 {
518 return clsidMachine;
519 }
520
521 /**
522 * Override of the default locking class to be used for validating lock
523 * order with the standard member lock handle.
524 */
525 virtual VBoxLockingClass getLockingClass() const
526 {
527 return LOCKCLASS_MACHINEOBJECT;
528 }
529
530 /// @todo (dmik) add lock and make non-inlined after revising classes
531 // that use it. Note: they should enter Machine lock to keep the returned
532 // information valid!
533 bool isRegistered() { return !!mData->mRegistered; }
534
535 // unsafe inline public methods for internal purposes only (ensure there is
536 // a caller and a read lock before calling them!)
537
538 /**
539 * Returns the VirtualBox object this machine belongs to.
540 *
541 * @note This method doesn't check this object's readiness. Intended to be
542 * used by ready Machine children (whose readiness is bound to the parent's
543 * one) or after doing addCaller() manually.
544 */
545 VirtualBox* getVirtualBox() const { return mParent; }
546
547 /**
548 * Returns this machine ID.
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 adding a caller manually.
553 */
554 const Guid& getId() const { return mData->mUuid; }
555
556 /**
557 * Returns the snapshot ID this machine represents or an empty UUID if this
558 * instance is not SnapshotMachine.
559 *
560 * @note This method doesn't check this object's readiness. Intended to be
561 * used by ready Machine children (whose readiness is bound to the parent's
562 * one) or after adding a caller manually.
563 */
564 inline const Guid& getSnapshotId() const;
565
566 /**
567 * Returns this machine's full settings file path.
568 *
569 * @note This method doesn't lock this object or check its readiness.
570 * Intended to be used only after doing addCaller() manually and locking it
571 * for reading.
572 */
573 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
574
575 /**
576 * Returns this machine name.
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 Bstr& getName() const { return mUserData->mName; }
583
584 enum
585 {
586 IsModified_MachineData = 0x0001,
587 IsModified_Storage = 0x0002,
588 IsModified_NetworkAdapters = 0x0008,
589 IsModified_SerialPorts = 0x0010,
590 IsModified_ParallelPorts = 0x0020,
591 IsModified_VRDPServer = 0x0040,
592 IsModified_AudioAdapter = 0x0080,
593 IsModified_USB = 0x0100,
594 IsModified_BIOS = 0x0200,
595 IsModified_SharedFolders = 0x0400,
596 IsModified_Snapshots = 0x0800
597 };
598
599 void setModified(uint32_t fl);
600
601 // callback handlers
602 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
603 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
604 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
605 virtual HRESULT onVRDPServerChange() { return S_OK; }
606 virtual HRESULT onUSBControllerChange() { return S_OK; }
607 virtual HRESULT onStorageControllerChange() { return S_OK; }
608 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
609 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
610 virtual HRESULT onSharedFolderChange() { return S_OK; }
611
612 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
613
614 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
615 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
616
617 void getLogFolder(Utf8Str &aLogFolder);
618 Utf8Str queryLogFilename(ULONG idx);
619
620 HRESULT openSession(IInternalSessionControl *aControl);
621 HRESULT openRemoteSession(IInternalSessionControl *aControl,
622 IN_BSTR aType, IN_BSTR aEnvironment,
623 Progress *aProgress);
624 HRESULT openExistingSession(IInternalSessionControl *aControl);
625
626 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
627 {
628 HRESULT rc;
629 *directControl = mData->mSession.mDirectControl;
630
631 if (!*directControl)
632 rc = E_ACCESSDENIED;
633 else
634 rc = S_OK;
635
636 return rc;
637 }
638
639#if defined(RT_OS_WINDOWS)
640
641 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
642 ComPtr<IInternalSessionControl> *aControl = NULL,
643 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
644 bool isSessionSpawning(RTPROCESS *aPID = NULL);
645
646 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
647 ComPtr<IInternalSessionControl> *aControl = NULL,
648 HANDLE *aIPCSem = NULL)
649 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
650
651#elif defined(RT_OS_OS2)
652
653 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
654 ComPtr<IInternalSessionControl> *aControl = NULL,
655 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
656
657 bool isSessionSpawning(RTPROCESS *aPID = NULL);
658
659 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
660 ComPtr<IInternalSessionControl> *aControl = NULL,
661 HMTX *aIPCSem = NULL)
662 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
663
664#else
665
666 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
667 ComPtr<IInternalSessionControl> *aControl = NULL,
668 bool aAllowClosing = false);
669 bool isSessionSpawning();
670
671 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
672 ComPtr<IInternalSessionControl> *aControl = NULL)
673 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
674
675#endif
676
677 bool checkForSpawnFailure();
678
679 HRESULT trySetRegistered(BOOL aRegistered);
680
681 HRESULT getSharedFolder(CBSTR aName,
682 ComObjPtr<SharedFolder> &aSharedFolder,
683 bool aSetError = false)
684 {
685 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
686 return findSharedFolder(aName, aSharedFolder, aSetError);
687 }
688
689 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
690 MachineState_T *aState = NULL,
691 BOOL *aRegistered = NULL);
692 void releaseStateDependency();
693
694 // for VirtualBoxSupportErrorInfoImpl
695 static const wchar_t *getComponentName() { return L"Machine"; }
696
697protected:
698
699 HRESULT checkStateDependency(StateDependency aDepType);
700
701 Machine *getMachine();
702
703 void ensureNoStateDependencies();
704
705 virtual HRESULT setMachineState(MachineState_T aMachineState);
706
707 HRESULT findSharedFolder(CBSTR aName,
708 ComObjPtr<SharedFolder> &aSharedFolder,
709 bool aSetError = false);
710
711 HRESULT loadSettings(bool aRegistered);
712 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
713 HRESULT loadSnapshot(const settings::Snapshot &data,
714 const Guid &aCurSnapshotId,
715 Snapshot *aParentSnapshot);
716 HRESULT loadHardware(const settings::Hardware &data);
717 HRESULT loadStorageControllers(const settings::Storage &data,
718 const Guid *aSnapshotId = NULL);
719 HRESULT loadStorageDevices(StorageController *aStorageController,
720 const settings::StorageController &data,
721 const Guid *aSnapshotId = NULL);
722
723 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
724 bool aSetError = false);
725 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
726 bool aSetError = false);
727
728 HRESULT getStorageControllerByName(const Utf8Str &aName,
729 ComObjPtr<StorageController> &aStorageController,
730 bool aSetError = false);
731
732 HRESULT getMediumAttachmentsOfController(CBSTR aName,
733 MediaData::AttachmentList &aAttachments);
734
735 enum
736 {
737 /* flags for #saveSettings() */
738 SaveS_ResetCurStateModified = 0x01,
739 SaveS_InformCallbacksAnyway = 0x02,
740 SaveS_Force = 0x04,
741 /* flags for #saveStateSettings() */
742 SaveSTS_CurStateModified = 0x20,
743 SaveSTS_StateFilePath = 0x40,
744 SaveSTS_StateTimeStamp = 0x80,
745 };
746
747 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
748 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
749
750 void copyMachineDataToSettings(settings::MachineConfigFile &config);
751 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
752 HRESULT saveHardware(settings::Hardware &data);
753 HRESULT saveStorageControllers(settings::Storage &data);
754 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
755 settings::StorageController &data);
756 HRESULT saveStateSettings(int aFlags);
757
758 HRESULT createImplicitDiffs(const Bstr &aFolder,
759 IProgress *aProgress,
760 ULONG aWeight,
761 bool aOnline,
762 bool *pfNeedsSaveSettings);
763 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
764
765 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
766 IN_BSTR aControllerName,
767 LONG aControllerPort,
768 LONG aDevice);
769 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
770 ComObjPtr<Medium> pMedium);
771 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
772 Guid &id);
773
774 void commitMedia(bool aOnline = false);
775 void rollbackMedia();
776
777 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
778
779 void rollback(bool aNotify);
780 void commit();
781 void copyFrom(Machine *aThat);
782
783#ifdef VBOX_WITH_GUEST_PROPS
784 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
785 ULONG64 *aTimestamp, BSTR *aFlags) const;
786 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
787 ULONG64 *aTimestamp, BSTR *aFlags) const;
788 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
789 IN_BSTR aFlags);
790 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
791 IN_BSTR aFlags);
792 HRESULT enumerateGuestPropertiesInService
793 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
794 ComSafeArrayOut(BSTR, aValues),
795 ComSafeArrayOut(ULONG64, aTimestamps),
796 ComSafeArrayOut(BSTR, aFlags));
797 HRESULT enumerateGuestPropertiesOnVM
798 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
799 ComSafeArrayOut(BSTR, aValues),
800 ComSafeArrayOut(ULONG64, aTimestamps),
801 ComSafeArrayOut(BSTR, aFlags));
802#endif /* VBOX_WITH_GUEST_PROPS */
803
804#ifdef VBOX_WITH_RESOURCE_USAGE_API
805 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
806 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
807
808 pm::CollectorGuestHAL *mGuestHAL;
809#endif /* VBOX_WITH_RESOURCE_USAGE_API */
810
811 Machine* const mPeer;
812
813 VirtualBox* const mParent;
814
815 Shareable<Data> mData;
816 Shareable<SSData> mSSData;
817
818 Backupable<UserData> mUserData;
819 Backupable<HWData> mHWData;
820 Backupable<MediaData> mMediaData;
821
822 // the following fields need special backup/rollback/commit handling,
823 // so they cannot be a part of HWData
824
825 const ComObjPtr<VRDPServer> mVRDPServer;
826 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
827 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
828 const ComObjPtr<AudioAdapter> mAudioAdapter;
829 const ComObjPtr<USBController> mUSBController;
830 const ComObjPtr<BIOSSettings> mBIOSSettings;
831 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
832
833 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
834 Backupable<StorageControllerList> mStorageControllers;
835
836 friend class SessionMachine;
837 friend class SnapshotMachine;
838 friend class Appliance;
839};
840
841// SessionMachine class
842////////////////////////////////////////////////////////////////////////////////
843
844/**
845 * @note Notes on locking objects of this class:
846 * SessionMachine shares some data with the primary Machine instance (pointed
847 * to by the |mPeer| member). In order to provide data consistency it also
848 * shares its lock handle. This means that whenever you lock a SessionMachine
849 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
850 * instance is also locked in the same lock mode. Keep it in mind.
851 */
852class ATL_NO_VTABLE SessionMachine :
853 public VirtualBoxSupportTranslation<SessionMachine>,
854 public Machine,
855 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
856{
857public:
858
859 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
860
861 DECLARE_NOT_AGGREGATABLE(SessionMachine)
862
863 DECLARE_PROTECT_FINAL_CONSTRUCT()
864
865 BEGIN_COM_MAP(SessionMachine)
866 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
867 COM_INTERFACE_ENTRY(ISupportErrorInfo)
868 COM_INTERFACE_ENTRY(IMachine)
869 COM_INTERFACE_ENTRY(IInternalMachineControl)
870 END_COM_MAP()
871
872 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
873
874 HRESULT FinalConstruct();
875 void FinalRelease();
876
877 // public initializer/uninitializer for internal purposes only
878 HRESULT init(Machine *aMachine);
879 void uninit() { uninit(Uninit::Unexpected); }
880
881 // util::Lockable interface
882 RWLockHandle *lockHandle() const;
883
884 // IInternalMachineControl methods
885 STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
886 STDMETHOD(UpdateState)(MachineState_T machineState);
887 STDMETHOD(GetIPCId)(BSTR *id);
888 STDMETHOD(SetPowerUpInfo)(IVirtualBoxErrorInfo *aError);
889 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
890 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
891 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
892 STDMETHOD(AutoCaptureUSBDevices)();
893 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
894 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
895 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
896 STDMETHOD(EndSavingState)(BOOL aSuccess);
897 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
898 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
899 IN_BSTR aName,
900 IN_BSTR aDescription,
901 IProgress *aConsoleProgress,
902 BOOL fTakingSnapshotOnline,
903 BSTR *aStateFilePath);
904 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
905 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
906 MachineState_T *aMachineState, IProgress **aProgress);
907 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
908 IMedium *aSource, IMedium *aTarget,
909 BOOL fMergeForward,
910 IMedium *pParentForTarget,
911 ComSafeArrayIn(IMedium *, aChildrenToReparent));
912 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
913 ISnapshot *aSnapshot,
914 MachineState_T *aMachineState,
915 IProgress **aProgress);
916 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
917 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
918 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
919 ULONG64 aTimestamp, IN_BSTR aFlags);
920 STDMETHOD(LockMedia)() { return lockMedia(); }
921 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
922
923 // public methods only for internal purposes
924
925 /**
926 * Simple run-time type identification without having to enable C++ RTTI.
927 * The class IDs are defined in VirtualBoxBase.h.
928 * @return
929 */
930 virtual VBoxClsID getClassID() const
931 {
932 return clsidSessionMachine;
933 }
934
935 bool checkForDeath();
936
937 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
938 HRESULT onStorageControllerChange();
939 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
940 HRESULT onSerialPortChange(ISerialPort *serialPort);
941 HRESULT onParallelPortChange(IParallelPort *parallelPort);
942 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
943 HRESULT onVRDPServerChange();
944 HRESULT onUSBControllerChange();
945 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
946 IVirtualBoxErrorInfo *aError,
947 ULONG aMaskedIfs);
948 HRESULT onUSBDeviceDetach(IN_BSTR aId,
949 IVirtualBoxErrorInfo *aError);
950 HRESULT onSharedFolderChange();
951
952 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
953
954private:
955
956 struct SnapshotData
957 {
958 SnapshotData() : mLastState(MachineState_Null) {}
959
960 MachineState_T mLastState;
961
962 // used when taking snapshot
963 ComObjPtr<Snapshot> mSnapshot;
964
965 // used when saving state
966 Guid mProgressId;
967 Utf8Str mStateFilePath;
968 };
969
970 struct Uninit
971 {
972 enum Reason { Unexpected, Abnormal, Normal };
973 };
974
975 struct SnapshotTask;
976 struct DeleteSnapshotTask;
977 struct RestoreSnapshotTask;
978
979 friend struct DeleteSnapshotTask;
980 friend struct RestoreSnapshotTask;
981
982 void uninit(Uninit::Reason aReason);
983
984 HRESULT endSavingState(BOOL aSuccess);
985
986 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
987
988 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
989 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
990
991 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
992 const Guid &machineId,
993 const Guid &snapshotId,
994 bool fOnlineMergePossible,
995 MediumLockList *aVMMALockList,
996 ComObjPtr<Medium> &aSource,
997 ComObjPtr<Medium> &aTarget,
998 bool &fMergeForward,
999 ComObjPtr<Medium> &pParentForTarget,
1000 MediaList &aChildrenToReparent,
1001 bool &fNeedOnlineMerge,
1002 MediumLockList * &aMediumLockList);
1003 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1004 const ComObjPtr<Medium> &aSource,
1005 const MediaList &aChildrenToReparent,
1006 bool fNeedsOnlineMerge,
1007 MediumLockList *aMediumLockList,
1008 const Guid &aMediumId,
1009 const Guid &aSnapshotId);
1010 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1011 const ComObjPtr<Medium> &aSource,
1012 const ComObjPtr<Medium> &aTarget,
1013 bool fMergeForward,
1014 const ComObjPtr<Medium> &pParentForTarget,
1015 const MediaList &aChildrenToReparent,
1016 MediumLockList *aMediumLockList,
1017 ComObjPtr<Progress> &aProgress,
1018 bool *pfNeedsSaveSettings);
1019
1020 HRESULT lockMedia();
1021 void unlockMedia();
1022
1023 HRESULT setMachineState(MachineState_T aMachineState);
1024 HRESULT updateMachineStateOnClient();
1025
1026 HRESULT mRemoveSavedState;
1027
1028 SnapshotData mSnapshotData;
1029
1030 /** interprocess semaphore handle for this machine */
1031#if defined(RT_OS_WINDOWS)
1032 HANDLE mIPCSem;
1033 Bstr mIPCSemName;
1034 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1035 ComPtr<IInternalSessionControl> *aControl,
1036 HANDLE *aIPCSem, bool aAllowClosing);
1037#elif defined(RT_OS_OS2)
1038 HMTX mIPCSem;
1039 Bstr mIPCSemName;
1040 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1041 ComPtr<IInternalSessionControl> *aControl,
1042 HMTX *aIPCSem, bool aAllowClosing);
1043#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1044 int mIPCSem;
1045# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1046 Bstr mIPCKey;
1047# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1048#else
1049# error "Port me!"
1050#endif
1051
1052 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1053};
1054
1055// SnapshotMachine class
1056////////////////////////////////////////////////////////////////////////////////
1057
1058/**
1059 * @note Notes on locking objects of this class:
1060 * SnapshotMachine shares some data with the primary Machine instance (pointed
1061 * to by the |mPeer| member). In order to provide data consistency it also
1062 * shares its lock handle. This means that whenever you lock a SessionMachine
1063 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1064 * instance is also locked in the same lock mode. Keep it in mind.
1065 */
1066class ATL_NO_VTABLE SnapshotMachine :
1067 public VirtualBoxSupportTranslation<SnapshotMachine>,
1068 public Machine
1069{
1070public:
1071
1072 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
1073
1074 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1075
1076 DECLARE_PROTECT_FINAL_CONSTRUCT()
1077
1078 BEGIN_COM_MAP(SnapshotMachine)
1079 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1080 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1081 COM_INTERFACE_ENTRY(IMachine)
1082 END_COM_MAP()
1083
1084 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1085
1086 HRESULT FinalConstruct();
1087 void FinalRelease();
1088
1089 // public initializer/uninitializer for internal purposes only
1090 HRESULT init(SessionMachine *aSessionMachine,
1091 IN_GUID aSnapshotId,
1092 const Utf8Str &aStateFilePath);
1093 HRESULT init(Machine *aMachine,
1094 const settings::Hardware &hardware,
1095 const settings::Storage &storage,
1096 IN_GUID aSnapshotId,
1097 const Utf8Str &aStateFilePath);
1098 void uninit();
1099
1100 // util::Lockable interface
1101 RWLockHandle *lockHandle() const;
1102
1103 // public methods only for internal purposes
1104
1105 /**
1106 * Simple run-time type identification without having to enable C++ RTTI.
1107 * The class IDs are defined in VirtualBoxBase.h.
1108 * @return
1109 */
1110 virtual VBoxClsID getClassID() const
1111 {
1112 return clsidSnapshotMachine;
1113 }
1114
1115 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1116
1117 // unsafe inline public methods for internal purposes only (ensure there is
1118 // a caller and a read lock before calling them!)
1119
1120 const Guid& getSnapshotId() const { return mSnapshotId; }
1121
1122private:
1123
1124 Guid mSnapshotId;
1125
1126 friend class Snapshot;
1127};
1128
1129// third party methods that depend on SnapshotMachine definiton
1130
1131inline const Guid &Machine::getSnapshotId() const
1132{
1133 return getClassID() != clsidSnapshotMachine
1134 ? Guid::Empty
1135 : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
1136}
1137
1138
1139#endif // ____H_MACHINEIMPL
1140/* 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