VirtualBox

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

Last change on this file since 30764 was 30764, checked in by vboxsync, 14 years ago

back out r63543, r63544 until windows build problems can be solved properly

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