VirtualBox

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

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

Main/OVF: write vbox:uuid attribute for each disk on export

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