VirtualBox

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

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

Main: Make it possible to cancel the starting of a teleporation target.

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