VirtualBox

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

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

Shared paging property for IMachine and IGuest added (not implemented).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.5 KB
Line 
1/* $Id: MachineImpl.h 29225 2010-05-07 16:01:34Z 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 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(SharedPagingEnabled))(BOOL *enabled);
396 STDMETHOD(COMSETTER(SharedPagingEnabled))(BOOL enabled);
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(IoCacheEnabled)) (BOOL *aEnabled);
447 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
448 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
449 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
450 STDMETHOD(COMGETTER(IoBandwidthMax)) (ULONG *aIoBandwidthMax);
451 STDMETHOD(COMSETTER(IoBandwidthMax)) (ULONG aIoBandwidthMax);
452
453 // IMachine methods
454 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
455 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
456 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
457 LONG aDevice, DeviceType_T aType, IN_BSTR aId);
458 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
459 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
460 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
461 LONG aDevice, IN_BSTR aId, BOOL aForce);
462 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
463 IMedium **aMedium);
464 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
465 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
466 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
467 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
468 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
469 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
470 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
471 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
472 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
473 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
474 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
475 STDMETHOD(RemoveAllCPUIDLeaves)();
476 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
477 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
478 STDMETHOD(SaveSettings)();
479 STDMETHOD(DiscardSettings)();
480 STDMETHOD(DeleteSettings)();
481 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
482 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
483 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
484 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
485 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
486 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
487 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
488 STDMETHOD(ShowConsoleWindow)(ULONG64 *aWinId);
489 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
490 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
491 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, ULONG64 *aTimestamp);
492 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
493 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
494 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
495 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
496 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
497 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
498 STDMETHOD(RemoveStorageController(IN_BSTR aName));
499 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
500 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
501 STDMETHOD(QuerySavedThumbnailSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
502 STDMETHOD(ReadSavedThumbnailToArray)(BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
503 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
504 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
505 STDMETHOD(HotPlugCPU(ULONG aCpu));
506 STDMETHOD(HotUnplugCPU(ULONG aCpu));
507 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
508 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
509 STDMETHOD(ReadLog(ULONG aIdx, ULONG64 aOffset, ULONG64 aSize, ComSafeArrayOut(BYTE, aData)));
510
511 // public methods only for internal purposes
512
513 /**
514 * Simple run-time type identification without having to enable C++ RTTI.
515 * The class IDs are defined in VirtualBoxBase.h.
516 * @return
517 */
518 virtual VBoxClsID getClassID() const
519 {
520 return clsidMachine;
521 }
522
523 /**
524 * Override of the default locking class to be used for validating lock
525 * order with the standard member lock handle.
526 */
527 virtual VBoxLockingClass getLockingClass() const
528 {
529 return LOCKCLASS_MACHINEOBJECT;
530 }
531
532 /// @todo (dmik) add lock and make non-inlined after revising classes
533 // that use it. Note: they should enter Machine lock to keep the returned
534 // information valid!
535 bool isRegistered() { return !!mData->mRegistered; }
536
537 // unsafe inline public methods for internal purposes only (ensure there is
538 // a caller and a read lock before calling them!)
539
540 /**
541 * Returns the VirtualBox object this machine belongs to.
542 *
543 * @note This method doesn't check this object's readiness. Intended to be
544 * used by ready Machine children (whose readiness is bound to the parent's
545 * one) or after doing addCaller() manually.
546 */
547 VirtualBox* getVirtualBox() const { return mParent; }
548
549 /**
550 * Returns this machine ID.
551 *
552 * @note This method doesn't check this object's readiness. Intended to be
553 * used by ready Machine children (whose readiness is bound to the parent's
554 * one) or after adding a caller manually.
555 */
556 const Guid& getId() const { return mData->mUuid; }
557
558 /**
559 * Returns the snapshot ID this machine represents or an empty UUID if this
560 * instance is not SnapshotMachine.
561 *
562 * @note This method doesn't check this object's readiness. Intended to be
563 * used by ready Machine children (whose readiness is bound to the parent's
564 * one) or after adding a caller manually.
565 */
566 inline const Guid& getSnapshotId() const;
567
568 /**
569 * Returns this machine's full settings file path.
570 *
571 * @note This method doesn't lock this object or check its readiness.
572 * Intended to be used only after doing addCaller() manually and locking it
573 * for reading.
574 */
575 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
576
577 /**
578 * Returns this machine name.
579 *
580 * @note This method doesn't lock this object or check its readiness.
581 * Intended to be used only after doing addCaller() manually and locking it
582 * for reading.
583 */
584 const Bstr& getName() const { return mUserData->mName; }
585
586 enum
587 {
588 IsModified_MachineData = 0x0001,
589 IsModified_Storage = 0x0002,
590 IsModified_NetworkAdapters = 0x0008,
591 IsModified_SerialPorts = 0x0010,
592 IsModified_ParallelPorts = 0x0020,
593 IsModified_VRDPServer = 0x0040,
594 IsModified_AudioAdapter = 0x0080,
595 IsModified_USB = 0x0100,
596 IsModified_BIOS = 0x0200,
597 IsModified_SharedFolders = 0x0400,
598 IsModified_Snapshots = 0x0800
599 };
600
601 void setModified(uint32_t fl);
602
603 // callback handlers
604 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
605 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
606 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
607 virtual HRESULT onVRDPServerChange() { return S_OK; }
608 virtual HRESULT onUSBControllerChange() { return S_OK; }
609 virtual HRESULT onStorageControllerChange() { return S_OK; }
610 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
611 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
612 virtual HRESULT onSharedFolderChange() { return S_OK; }
613
614 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
615
616 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
617 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
618
619 void getLogFolder(Utf8Str &aLogFolder);
620 Utf8Str queryLogFilename(ULONG idx);
621
622 HRESULT openSession(IInternalSessionControl *aControl);
623 HRESULT openRemoteSession(IInternalSessionControl *aControl,
624 IN_BSTR aType, IN_BSTR aEnvironment,
625 Progress *aProgress);
626 HRESULT openExistingSession(IInternalSessionControl *aControl);
627
628 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
629 {
630 HRESULT rc;
631 *directControl = mData->mSession.mDirectControl;
632
633 if (!*directControl)
634 rc = E_ACCESSDENIED;
635 else
636 rc = S_OK;
637
638 return rc;
639 }
640
641#if defined(RT_OS_WINDOWS)
642
643 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
644 ComPtr<IInternalSessionControl> *aControl = NULL,
645 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
646 bool isSessionSpawning(RTPROCESS *aPID = NULL);
647
648 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
649 ComPtr<IInternalSessionControl> *aControl = NULL,
650 HANDLE *aIPCSem = NULL)
651 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
652
653#elif defined(RT_OS_OS2)
654
655 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
656 ComPtr<IInternalSessionControl> *aControl = NULL,
657 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
658
659 bool isSessionSpawning(RTPROCESS *aPID = NULL);
660
661 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
662 ComPtr<IInternalSessionControl> *aControl = NULL,
663 HMTX *aIPCSem = NULL)
664 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
665
666#else
667
668 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
669 ComPtr<IInternalSessionControl> *aControl = NULL,
670 bool aAllowClosing = false);
671 bool isSessionSpawning();
672
673 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
674 ComPtr<IInternalSessionControl> *aControl = NULL)
675 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
676
677#endif
678
679 bool checkForSpawnFailure();
680
681 HRESULT trySetRegistered(BOOL aRegistered);
682
683 HRESULT getSharedFolder(CBSTR aName,
684 ComObjPtr<SharedFolder> &aSharedFolder,
685 bool aSetError = false)
686 {
687 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
688 return findSharedFolder(aName, aSharedFolder, aSetError);
689 }
690
691 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
692 MachineState_T *aState = NULL,
693 BOOL *aRegistered = NULL);
694 void releaseStateDependency();
695
696 // for VirtualBoxSupportErrorInfoImpl
697 static const wchar_t *getComponentName() { return L"Machine"; }
698
699protected:
700
701 HRESULT checkStateDependency(StateDependency aDepType);
702
703 Machine *getMachine();
704
705 void ensureNoStateDependencies();
706
707 virtual HRESULT setMachineState(MachineState_T aMachineState);
708
709 HRESULT findSharedFolder(CBSTR aName,
710 ComObjPtr<SharedFolder> &aSharedFolder,
711 bool aSetError = false);
712
713 HRESULT loadSettings(bool aRegistered);
714 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
715 HRESULT loadSnapshot(const settings::Snapshot &data,
716 const Guid &aCurSnapshotId,
717 Snapshot *aParentSnapshot);
718 HRESULT loadHardware(const settings::Hardware &data);
719 HRESULT loadStorageControllers(const settings::Storage &data,
720 const Guid *aSnapshotId = NULL);
721 HRESULT loadStorageDevices(StorageController *aStorageController,
722 const settings::StorageController &data,
723 const Guid *aSnapshotId = NULL);
724
725 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
726 bool aSetError = false);
727 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
728 bool aSetError = false);
729
730 HRESULT getStorageControllerByName(const Utf8Str &aName,
731 ComObjPtr<StorageController> &aStorageController,
732 bool aSetError = false);
733
734 HRESULT getMediumAttachmentsOfController(CBSTR aName,
735 MediaData::AttachmentList &aAttachments);
736
737 enum
738 {
739 /* flags for #saveSettings() */
740 SaveS_ResetCurStateModified = 0x01,
741 SaveS_InformCallbacksAnyway = 0x02,
742 SaveS_Force = 0x04,
743 /* flags for #saveStateSettings() */
744 SaveSTS_CurStateModified = 0x20,
745 SaveSTS_StateFilePath = 0x40,
746 SaveSTS_StateTimeStamp = 0x80,
747 };
748
749 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
750 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
751
752 void copyMachineDataToSettings(settings::MachineConfigFile &config);
753 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
754 HRESULT saveHardware(settings::Hardware &data);
755 HRESULT saveStorageControllers(settings::Storage &data);
756 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
757 settings::StorageController &data);
758 HRESULT saveStateSettings(int aFlags);
759
760 HRESULT createImplicitDiffs(const Bstr &aFolder,
761 IProgress *aProgress,
762 ULONG aWeight,
763 bool aOnline,
764 bool *pfNeedsSaveSettings);
765 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
766
767 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
768 IN_BSTR aControllerName,
769 LONG aControllerPort,
770 LONG aDevice);
771 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
772 ComObjPtr<Medium> pMedium);
773 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
774 Guid &id);
775
776 void commitMedia(bool aOnline = false);
777 void rollbackMedia();
778
779 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
780
781 void rollback(bool aNotify);
782 void commit();
783 void copyFrom(Machine *aThat);
784
785#ifdef VBOX_WITH_GUEST_PROPS
786 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
787 ULONG64 *aTimestamp, BSTR *aFlags) const;
788 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
789 ULONG64 *aTimestamp, BSTR *aFlags) const;
790 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
791 IN_BSTR aFlags);
792 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
793 IN_BSTR aFlags);
794 HRESULT enumerateGuestPropertiesInService
795 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
796 ComSafeArrayOut(BSTR, aValues),
797 ComSafeArrayOut(ULONG64, aTimestamps),
798 ComSafeArrayOut(BSTR, aFlags));
799 HRESULT enumerateGuestPropertiesOnVM
800 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
801 ComSafeArrayOut(BSTR, aValues),
802 ComSafeArrayOut(ULONG64, aTimestamps),
803 ComSafeArrayOut(BSTR, aFlags));
804#endif /* VBOX_WITH_GUEST_PROPS */
805
806#ifdef VBOX_WITH_RESOURCE_USAGE_API
807 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
808 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
809
810 pm::CollectorGuestHAL *mGuestHAL;
811#endif /* VBOX_WITH_RESOURCE_USAGE_API */
812
813 Machine* const mPeer;
814
815 VirtualBox* const mParent;
816
817 Shareable<Data> mData;
818 Shareable<SSData> mSSData;
819
820 Backupable<UserData> mUserData;
821 Backupable<HWData> mHWData;
822 Backupable<MediaData> mMediaData;
823
824 // the following fields need special backup/rollback/commit handling,
825 // so they cannot be a part of HWData
826
827 const ComObjPtr<VRDPServer> mVRDPServer;
828 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
829 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
830 const ComObjPtr<AudioAdapter> mAudioAdapter;
831 const ComObjPtr<USBController> mUSBController;
832 const ComObjPtr<BIOSSettings> mBIOSSettings;
833 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
834
835 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
836 Backupable<StorageControllerList> mStorageControllers;
837
838 friend class SessionMachine;
839 friend class SnapshotMachine;
840 friend class Appliance;
841};
842
843// SessionMachine class
844////////////////////////////////////////////////////////////////////////////////
845
846/**
847 * @note Notes on locking objects of this class:
848 * SessionMachine shares some data with the primary Machine instance (pointed
849 * to by the |mPeer| member). In order to provide data consistency it also
850 * shares its lock handle. This means that whenever you lock a SessionMachine
851 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
852 * instance is also locked in the same lock mode. Keep it in mind.
853 */
854class ATL_NO_VTABLE SessionMachine :
855 public VirtualBoxSupportTranslation<SessionMachine>,
856 public Machine,
857 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
858{
859public:
860
861 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
862
863 DECLARE_NOT_AGGREGATABLE(SessionMachine)
864
865 DECLARE_PROTECT_FINAL_CONSTRUCT()
866
867 BEGIN_COM_MAP(SessionMachine)
868 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
869 COM_INTERFACE_ENTRY(ISupportErrorInfo)
870 COM_INTERFACE_ENTRY(IMachine)
871 COM_INTERFACE_ENTRY(IInternalMachineControl)
872 END_COM_MAP()
873
874 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
875
876 HRESULT FinalConstruct();
877 void FinalRelease();
878
879 // public initializer/uninitializer for internal purposes only
880 HRESULT init(Machine *aMachine);
881 void uninit() { uninit(Uninit::Unexpected); }
882
883 // util::Lockable interface
884 RWLockHandle *lockHandle() const;
885
886 // IInternalMachineControl methods
887 STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
888 STDMETHOD(UpdateState)(MachineState_T machineState);
889 STDMETHOD(GetIPCId)(BSTR *id);
890 STDMETHOD(SetPowerUpInfo)(IVirtualBoxErrorInfo *aError);
891 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
892 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
893 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
894 STDMETHOD(AutoCaptureUSBDevices)();
895 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
896 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
897 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
898 STDMETHOD(EndSavingState)(BOOL aSuccess);
899 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
900 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
901 IN_BSTR aName,
902 IN_BSTR aDescription,
903 IProgress *aConsoleProgress,
904 BOOL fTakingSnapshotOnline,
905 BSTR *aStateFilePath);
906 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
907 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
908 MachineState_T *aMachineState, IProgress **aProgress);
909 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
910 IMedium *aSource, IMedium *aTarget,
911 BOOL fMergeForward,
912 IMedium *pParentForTarget,
913 ComSafeArrayIn(IMedium *, aChildrenToReparent));
914 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
915 ISnapshot *aSnapshot,
916 MachineState_T *aMachineState,
917 IProgress **aProgress);
918 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
919 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
920 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
921 ULONG64 aTimestamp, IN_BSTR aFlags);
922 STDMETHOD(LockMedia)() { return lockMedia(); }
923 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
924
925 // public methods only for internal purposes
926
927 /**
928 * Simple run-time type identification without having to enable C++ RTTI.
929 * The class IDs are defined in VirtualBoxBase.h.
930 * @return
931 */
932 virtual VBoxClsID getClassID() const
933 {
934 return clsidSessionMachine;
935 }
936
937 bool checkForDeath();
938
939 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
940 HRESULT onStorageControllerChange();
941 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
942 HRESULT onSerialPortChange(ISerialPort *serialPort);
943 HRESULT onParallelPortChange(IParallelPort *parallelPort);
944 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
945 HRESULT onVRDPServerChange();
946 HRESULT onUSBControllerChange();
947 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
948 IVirtualBoxErrorInfo *aError,
949 ULONG aMaskedIfs);
950 HRESULT onUSBDeviceDetach(IN_BSTR aId,
951 IVirtualBoxErrorInfo *aError);
952 HRESULT onSharedFolderChange();
953
954 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
955
956private:
957
958 struct SnapshotData
959 {
960 SnapshotData() : mLastState(MachineState_Null) {}
961
962 MachineState_T mLastState;
963
964 // used when taking snapshot
965 ComObjPtr<Snapshot> mSnapshot;
966
967 // used when saving state
968 Guid mProgressId;
969 Utf8Str mStateFilePath;
970 };
971
972 struct Uninit
973 {
974 enum Reason { Unexpected, Abnormal, Normal };
975 };
976
977 struct SnapshotTask;
978 struct DeleteSnapshotTask;
979 struct RestoreSnapshotTask;
980
981 friend struct DeleteSnapshotTask;
982 friend struct RestoreSnapshotTask;
983
984 void uninit(Uninit::Reason aReason);
985
986 HRESULT endSavingState(BOOL aSuccess);
987
988 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
989
990 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
991 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
992
993 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
994 const Guid &machineId,
995 const Guid &snapshotId,
996 bool fOnlineMergePossible,
997 MediumLockList *aVMMALockList,
998 ComObjPtr<Medium> &aSource,
999 ComObjPtr<Medium> &aTarget,
1000 bool &fMergeForward,
1001 ComObjPtr<Medium> &pParentForTarget,
1002 MediaList &aChildrenToReparent,
1003 bool &fNeedOnlineMerge,
1004 MediumLockList * &aMediumLockList);
1005 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1006 const ComObjPtr<Medium> &aSource,
1007 const MediaList &aChildrenToReparent,
1008 bool fNeedsOnlineMerge,
1009 MediumLockList *aMediumLockList,
1010 const Guid &aMediumId,
1011 const Guid &aSnapshotId);
1012 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1013 const ComObjPtr<Medium> &aSource,
1014 const ComObjPtr<Medium> &aTarget,
1015 bool fMergeForward,
1016 const ComObjPtr<Medium> &pParentForTarget,
1017 const MediaList &aChildrenToReparent,
1018 MediumLockList *aMediumLockList,
1019 ComObjPtr<Progress> &aProgress,
1020 bool *pfNeedsSaveSettings);
1021
1022 HRESULT lockMedia();
1023 void unlockMedia();
1024
1025 HRESULT setMachineState(MachineState_T aMachineState);
1026 HRESULT updateMachineStateOnClient();
1027
1028 HRESULT mRemoveSavedState;
1029
1030 SnapshotData mSnapshotData;
1031
1032 /** interprocess semaphore handle for this machine */
1033#if defined(RT_OS_WINDOWS)
1034 HANDLE mIPCSem;
1035 Bstr mIPCSemName;
1036 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1037 ComPtr<IInternalSessionControl> *aControl,
1038 HANDLE *aIPCSem, bool aAllowClosing);
1039#elif defined(RT_OS_OS2)
1040 HMTX mIPCSem;
1041 Bstr mIPCSemName;
1042 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1043 ComPtr<IInternalSessionControl> *aControl,
1044 HMTX *aIPCSem, bool aAllowClosing);
1045#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1046 int mIPCSem;
1047# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1048 Bstr mIPCKey;
1049# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1050#else
1051# error "Port me!"
1052#endif
1053
1054 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1055};
1056
1057// SnapshotMachine class
1058////////////////////////////////////////////////////////////////////////////////
1059
1060/**
1061 * @note Notes on locking objects of this class:
1062 * SnapshotMachine shares some data with the primary Machine instance (pointed
1063 * to by the |mPeer| member). In order to provide data consistency it also
1064 * shares its lock handle. This means that whenever you lock a SessionMachine
1065 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1066 * instance is also locked in the same lock mode. Keep it in mind.
1067 */
1068class ATL_NO_VTABLE SnapshotMachine :
1069 public VirtualBoxSupportTranslation<SnapshotMachine>,
1070 public Machine
1071{
1072public:
1073
1074 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
1075
1076 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1077
1078 DECLARE_PROTECT_FINAL_CONSTRUCT()
1079
1080 BEGIN_COM_MAP(SnapshotMachine)
1081 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1082 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1083 COM_INTERFACE_ENTRY(IMachine)
1084 END_COM_MAP()
1085
1086 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1087
1088 HRESULT FinalConstruct();
1089 void FinalRelease();
1090
1091 // public initializer/uninitializer for internal purposes only
1092 HRESULT init(SessionMachine *aSessionMachine,
1093 IN_GUID aSnapshotId,
1094 const Utf8Str &aStateFilePath);
1095 HRESULT init(Machine *aMachine,
1096 const settings::Hardware &hardware,
1097 const settings::Storage &storage,
1098 IN_GUID aSnapshotId,
1099 const Utf8Str &aStateFilePath);
1100 void uninit();
1101
1102 // util::Lockable interface
1103 RWLockHandle *lockHandle() const;
1104
1105 // public methods only for internal purposes
1106
1107 /**
1108 * Simple run-time type identification without having to enable C++ RTTI.
1109 * The class IDs are defined in VirtualBoxBase.h.
1110 * @return
1111 */
1112 virtual VBoxClsID getClassID() const
1113 {
1114 return clsidSnapshotMachine;
1115 }
1116
1117 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1118
1119 // unsafe inline public methods for internal purposes only (ensure there is
1120 // a caller and a read lock before calling them!)
1121
1122 const Guid& getSnapshotId() const { return mSnapshotId; }
1123
1124private:
1125
1126 Guid mSnapshotId;
1127
1128 friend class Snapshot;
1129};
1130
1131// third party methods that depend on SnapshotMachine definiton
1132
1133inline const Guid &Machine::getSnapshotId() const
1134{
1135 return getClassID() != clsidSnapshotMachine
1136 ? Guid::Empty
1137 : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
1138}
1139
1140
1141#endif // ____H_MACHINEIMPL
1142/* 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