VirtualBox

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

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

Main: clean up Machine::init() and instance data

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