VirtualBox

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

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

Main: bring back boolean argument to IConsole::discardSavedState()

  • 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 31574 2010-08-11 14:54:09Z 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 lockMachine() */
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 // list of files to delete in Delete(); this list is filled by Unregister()
185 std::list<Utf8Str> llFilesToDelete;
186 };
187
188 /**
189 * Saved state data.
190 *
191 * It's actually only the state file path string, but it needs to be
192 * separate from Data, because Machine and SessionMachine instances
193 * share it, while SnapshotMachine does not.
194 *
195 * The data variable is |mSSData|.
196 */
197 struct SSData
198 {
199 Utf8Str mStateFilePath;
200 };
201
202 /**
203 * User changeable machine data.
204 *
205 * This data is common for all machine snapshots, i.e. it is shared
206 * by all SnapshotMachine instances associated with the given machine
207 * using the util::Backupable template through the |mUserData| variable.
208 *
209 * SessionMachine instances can alter this data and discard changes.
210 *
211 * @note There is no need to lock anything inside init() or uninit()
212 * methods, because they are always serialized (see AutoCaller).
213 */
214 struct UserData
215 {
216 settings::MachineUserData s;
217 Utf8Str m_strSnapshotFolderFull;
218 };
219
220 /**
221 * Hardware data.
222 *
223 * This data is unique for a machine and for every machine snapshot.
224 * Stored using the util::Backupable template in the |mHWData| variable.
225 *
226 * SessionMachine instances can alter this data and discard changes.
227 */
228 struct HWData
229 {
230 /**
231 * Data structure to hold information about a guest property.
232 */
233 struct GuestProperty {
234 /** Property name */
235 Utf8Str strName;
236 /** Property value */
237 Utf8Str strValue;
238 /** Property timestamp */
239 ULONG64 mTimestamp;
240 /** Property flags */
241 ULONG mFlags;
242 };
243
244 HWData();
245 ~HWData();
246
247 Bstr mHWVersion;
248 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
249 ULONG mMemorySize;
250 ULONG mMemoryBalloonSize;
251 BOOL mPageFusionEnabled;
252 ULONG mVRAMSize;
253 ULONG mMonitorCount;
254 BOOL mHWVirtExEnabled;
255 BOOL mHWVirtExExclusive;
256 BOOL mHWVirtExNestedPagingEnabled;
257 BOOL mHWVirtExLargePagesEnabled;
258 BOOL mHWVirtExVPIDEnabled;
259 BOOL mAccelerate2DVideoEnabled;
260 BOOL mPAEEnabled;
261 BOOL mSyntheticCpu;
262 ULONG mCPUCount;
263 BOOL mCPUHotPlugEnabled;
264 ULONG mCpuPriority;
265 BOOL mAccelerate3DEnabled;
266 BOOL mHpetEnabled;
267
268 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
269
270 settings::CpuIdLeaf mCpuIdStdLeafs[10];
271 settings::CpuIdLeaf mCpuIdExtLeafs[10];
272
273 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
274
275 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
276 SharedFolderList mSharedFolders;
277
278 ClipboardMode_T mClipboardMode;
279
280 typedef std::list<GuestProperty> GuestPropertyList;
281 GuestPropertyList mGuestProperties;
282 Utf8Str mGuestPropertyNotificationPatterns;
283
284 FirmwareType_T mFirmwareType;
285 KeyboardHidType_T mKeyboardHidType;
286 PointingHidType_T mPointingHidType;
287
288 BOOL mIoCacheEnabled;
289 ULONG mIoCacheSize;
290 };
291
292 /**
293 * Hard disk and other media data.
294 *
295 * The usage policy is the same as for HWData, but a separate structure
296 * is necessary because hard disk data requires different procedures when
297 * taking or deleting snapshots, etc.
298 *
299 * The data variable is |mMediaData|.
300 */
301 struct MediaData
302 {
303 MediaData();
304 ~MediaData();
305
306 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
307 AttachmentList mAttachments;
308 };
309
310 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
311
312 DECLARE_NOT_AGGREGATABLE(Machine)
313
314 DECLARE_PROTECT_FINAL_CONSTRUCT()
315
316 BEGIN_COM_MAP(Machine)
317 COM_INTERFACE_ENTRY(ISupportErrorInfo)
318 COM_INTERFACE_ENTRY(IMachine)
319 COM_INTERFACE_ENTRY(IDispatch)
320 END_COM_MAP()
321
322 DECLARE_EMPTY_CTOR_DTOR(Machine)
323
324 HRESULT FinalConstruct();
325 void FinalRelease();
326
327 // public initializer/uninitializer for internal purposes only:
328
329 // initializer for creating a new, empty machine
330 HRESULT init(VirtualBox *aParent,
331 const Utf8Str &strConfigFile,
332 const Utf8Str &strName,
333 const Guid &aId,
334 GuestOSType *aOsType = NULL,
335 BOOL aOverride = FALSE,
336 BOOL aNameSync = TRUE);
337
338 // initializer for loading existing machine XML (either registered or not)
339 HRESULT init(VirtualBox *aParent,
340 const Utf8Str &strConfigFile,
341 const Guid *aId);
342
343 // initializer for machine config in memory (OVF import)
344 HRESULT init(VirtualBox *aParent,
345 const Utf8Str &strName,
346 const settings::MachineConfigFile &config);
347
348 void uninit();
349
350#ifdef VBOX_WITH_RESOURCE_USAGE_API
351 // Needed from VirtualBox, for the delayed metrics cleanup.
352 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
353#endif /* VBOX_WITH_RESOURCE_USAGE_API */
354
355protected:
356 HRESULT initImpl(VirtualBox *aParent,
357 const Utf8Str &strConfigFile);
358 HRESULT initDataAndChildObjects();
359 HRESULT registeredInit();
360 HRESULT tryCreateMachineConfigFile(BOOL aOverride);
361 void uninitDataAndChildObjects();
362
363public:
364 // IMachine properties
365 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
366 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
367 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
368 STDMETHOD(COMGETTER(Name))(BSTR *aName);
369 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
370 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
371 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
372 STDMETHOD(COMGETTER(Id))(BSTR *aId);
373 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
374 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
375 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
376 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
377 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
378 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
379 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
380 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
381 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
382 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
383 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
384 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
385 STDMETHOD(COMGETTER(CPUPriority))(ULONG *aPriority);
386 STDMETHOD(COMSETTER(CPUPriority))(ULONG aPriority);
387 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
388 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
389 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
390 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
391 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
392 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
393 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
394 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
395 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
396 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
397 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
398 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
399 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
400 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
401 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
402 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
403 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
404 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
405 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
406 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
407 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
408 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
409 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
410 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
411 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
412 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
413 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
414 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
415 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
416 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
417 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
418 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
419 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
420 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
421 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
422 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
423 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
424 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
425 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
426 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
427 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
428 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
429 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
430 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
431 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
432 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
433 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
434 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
435 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
436 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
437 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
438 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
439 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
440 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
441 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
442 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
443 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
444 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
445 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
446
447 // IMachine methods
448 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
449 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
450
451 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
452 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
453 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
454 LONG aDevice, DeviceType_T aType, IN_BSTR aId);
455 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
456 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
457 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
458 LONG aDevice, IN_BSTR aId, BOOL aForce);
459 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
460 IMedium **aMedium);
461 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
462 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
463 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
464 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
465 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
466 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
467 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
468 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
469 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
470 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
471 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
472 STDMETHOD(RemoveAllCPUIDLeaves)();
473 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
474 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
475 STDMETHOD(SaveSettings)();
476 STDMETHOD(DiscardSettings)();
477 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
478 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
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, BOOL aAutoMount);
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 Utf8Str& getName() const { return mUserData->s.strName; }
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 onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
610 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
611 virtual HRESULT onSharedFolderChange() { return S_OK; }
612
613 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
614
615 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
616 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
617
618 void getLogFolder(Utf8Str &aLogFolder);
619 Utf8Str queryLogFilename(ULONG idx);
620
621 HRESULT openRemoteSession(IInternalSessionControl *aControl,
622 IN_BSTR aType, IN_BSTR aEnvironment,
623 ProgressProxy *aProgress);
624
625 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
626 {
627 HRESULT rc;
628 *directControl = mData->mSession.mDirectControl;
629
630 if (!*directControl)
631 rc = E_ACCESSDENIED;
632 else
633 rc = S_OK;
634
635 return rc;
636 }
637
638#if defined(RT_OS_WINDOWS)
639
640 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
641 ComPtr<IInternalSessionControl> *aControl = NULL,
642 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
643 bool isSessionSpawning(RTPROCESS *aPID = NULL);
644
645 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
646 ComPtr<IInternalSessionControl> *aControl = NULL,
647 HANDLE *aIPCSem = NULL)
648 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
649
650#elif defined(RT_OS_OS2)
651
652 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
653 ComPtr<IInternalSessionControl> *aControl = NULL,
654 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
655
656 bool isSessionSpawning(RTPROCESS *aPID = NULL);
657
658 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
659 ComPtr<IInternalSessionControl> *aControl = NULL,
660 HMTX *aIPCSem = NULL)
661 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
662
663#else
664
665 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
666 ComPtr<IInternalSessionControl> *aControl = NULL,
667 bool aAllowClosing = false);
668 bool isSessionSpawning();
669
670 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
671 ComPtr<IInternalSessionControl> *aControl = NULL)
672 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
673
674#endif
675
676 bool checkForSpawnFailure();
677
678 HRESULT prepareRegister();
679
680 HRESULT getSharedFolder(CBSTR aName,
681 ComObjPtr<SharedFolder> &aSharedFolder,
682 bool aSetError = false)
683 {
684 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
685 return findSharedFolder(aName, aSharedFolder, aSetError);
686 }
687
688 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
689 MachineState_T *aState = NULL,
690 BOOL *aRegistered = NULL);
691 void releaseStateDependency();
692
693protected:
694
695 HRESULT checkStateDependency(StateDependency aDepType);
696
697 Machine *getMachine();
698
699 void ensureNoStateDependencies();
700
701 virtual HRESULT setMachineState(MachineState_T aMachineState);
702
703 HRESULT findSharedFolder(CBSTR aName,
704 ComObjPtr<SharedFolder> &aSharedFolder,
705 bool aSetError = false);
706
707 HRESULT loadSettings(bool aRegistered);
708 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
709 HRESULT loadSnapshot(const settings::Snapshot &data,
710 const Guid &aCurSnapshotId,
711 Snapshot *aParentSnapshot);
712 HRESULT loadHardware(const settings::Hardware &data);
713 HRESULT loadStorageControllers(const settings::Storage &data,
714 const Guid *aSnapshotId = NULL);
715 HRESULT loadStorageDevices(StorageController *aStorageController,
716 const settings::StorageController &data,
717 const Guid *aSnapshotId = NULL);
718
719 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
720 bool aSetError = false);
721 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
722 bool aSetError = false);
723
724 HRESULT getStorageControllerByName(const Utf8Str &aName,
725 ComObjPtr<StorageController> &aStorageController,
726 bool aSetError = false);
727
728 HRESULT getMediumAttachmentsOfController(CBSTR aName,
729 MediaData::AttachmentList &aAttachments);
730
731 enum
732 {
733 /* flags for #saveSettings() */
734 SaveS_ResetCurStateModified = 0x01,
735 SaveS_InformCallbacksAnyway = 0x02,
736 SaveS_Force = 0x04,
737 /* flags for #saveStateSettings() */
738 SaveSTS_CurStateModified = 0x20,
739 SaveSTS_StateFilePath = 0x40,
740 SaveSTS_StateTimeStamp = 0x80
741 };
742
743 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
744 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
745
746 void copyMachineDataToSettings(settings::MachineConfigFile &config);
747 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
748 HRESULT saveHardware(settings::Hardware &data);
749 HRESULT saveStorageControllers(settings::Storage &data);
750 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
751 settings::StorageController &data);
752 HRESULT saveStateSettings(int aFlags);
753
754 HRESULT createImplicitDiffs(IProgress *aProgress,
755 ULONG aWeight,
756 bool aOnline,
757 bool *pfNeedsSaveSettings);
758 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
759
760 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
761 IN_BSTR aControllerName,
762 LONG aControllerPort,
763 LONG aDevice);
764 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
765 ComObjPtr<Medium> pMedium);
766 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
767 Guid &id);
768
769 HRESULT detachDevice(MediumAttachment *pAttach,
770 AutoWriteLock &writeLock,
771 Snapshot *pSnapshot,
772 bool *pfNeedsSaveSettings);
773 HRESULT detachAllMedia(AutoWriteLock &writeLock,
774 Snapshot *pSnapshot,
775 CleanupMode_T cleanupMode,
776 MediaList &llMedia);
777
778 void commitMedia(bool aOnline = false);
779 void rollbackMedia();
780
781 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
782
783 void rollback(bool aNotify);
784 void commit();
785 void copyFrom(Machine *aThat);
786
787 struct DeleteTask;
788 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
789 HRESULT deleteTaskWorker(DeleteTask &task);
790
791#ifdef VBOX_WITH_GUEST_PROPS
792 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
793 ULONG64 *aTimestamp, BSTR *aFlags) const;
794 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
795 ULONG64 *aTimestamp, BSTR *aFlags) const;
796 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
797 IN_BSTR aFlags);
798 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
799 IN_BSTR aFlags);
800 HRESULT enumerateGuestPropertiesInService
801 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
802 ComSafeArrayOut(BSTR, aValues),
803 ComSafeArrayOut(ULONG64, aTimestamps),
804 ComSafeArrayOut(BSTR, aFlags));
805 HRESULT enumerateGuestPropertiesOnVM
806 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
807 ComSafeArrayOut(BSTR, aValues),
808 ComSafeArrayOut(ULONG64, aTimestamps),
809 ComSafeArrayOut(BSTR, aFlags));
810#endif /* VBOX_WITH_GUEST_PROPS */
811
812#ifdef VBOX_WITH_RESOURCE_USAGE_API
813 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
814
815 pm::CollectorGuestHAL *mGuestHAL;
816#endif /* VBOX_WITH_RESOURCE_USAGE_API */
817
818 Machine* const mPeer;
819
820 VirtualBox * const mParent;
821
822 Shareable<Data> mData;
823 Shareable<SSData> mSSData;
824
825 Backupable<UserData> mUserData;
826 Backupable<HWData> mHWData;
827 Backupable<MediaData> mMediaData;
828
829 // the following fields need special backup/rollback/commit handling,
830 // so they cannot be a part of HWData
831
832 const ComObjPtr<VRDPServer> mVRDPServer;
833 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
834 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
835 const ComObjPtr<AudioAdapter> mAudioAdapter;
836 const ComObjPtr<USBController> mUSBController;
837 const ComObjPtr<BIOSSettings> mBIOSSettings;
838 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
839
840 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
841 Backupable<StorageControllerList> mStorageControllers;
842
843 friend class SessionMachine;
844 friend class SnapshotMachine;
845 friend class Appliance;
846};
847
848// SessionMachine class
849////////////////////////////////////////////////////////////////////////////////
850
851/**
852 * @note Notes on locking objects of this class:
853 * SessionMachine shares some data with the primary Machine instance (pointed
854 * to by the |mPeer| member). In order to provide data consistency it also
855 * shares its lock handle. This means that whenever you lock a SessionMachine
856 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
857 * instance is also locked in the same lock mode. Keep it in mind.
858 */
859class ATL_NO_VTABLE SessionMachine :
860 public Machine,
861 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
862{
863public:
864 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
865
866 DECLARE_NOT_AGGREGATABLE(SessionMachine)
867
868 DECLARE_PROTECT_FINAL_CONSTRUCT()
869
870 BEGIN_COM_MAP(SessionMachine)
871 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
872 COM_INTERFACE_ENTRY(ISupportErrorInfo)
873 COM_INTERFACE_ENTRY(IMachine)
874 COM_INTERFACE_ENTRY(IInternalMachineControl)
875 END_COM_MAP()
876
877 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
878
879 HRESULT FinalConstruct();
880 void FinalRelease();
881
882 // public initializer/uninitializer for internal purposes only
883 HRESULT init(Machine *aMachine);
884 void uninit() { uninit(Uninit::Unexpected); }
885
886 // util::Lockable interface
887 RWLockHandle *lockHandle() const;
888
889 // IInternalMachineControl methods
890 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
891 STDMETHOD(UpdateState)(MachineState_T machineState);
892 STDMETHOD(GetIPCId)(BSTR *id);
893 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
894 STDMETHOD(EndPowerUp)(LONG iResult);
895 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
896 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
897 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
898 STDMETHOD(AutoCaptureUSBDevices)();
899 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
900 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
901 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
902 STDMETHOD(EndSavingState)(BOOL aSuccess);
903 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
904 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
905 IN_BSTR aName,
906 IN_BSTR aDescription,
907 IProgress *aConsoleProgress,
908 BOOL fTakingSnapshotOnline,
909 BSTR *aStateFilePath);
910 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
911 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
912 MachineState_T *aMachineState, IProgress **aProgress);
913 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
914 IMedium *aSource, IMedium *aTarget,
915 BOOL fMergeForward,
916 IMedium *pParentForTarget,
917 ComSafeArrayIn(IMedium *, aChildrenToReparent));
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 virtual bool isSessionMachine() const
932 {
933 return true;
934 }
935
936 bool checkForDeath();
937
938 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
939 HRESULT onStorageControllerChange();
940 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
941 HRESULT onSerialPortChange(ISerialPort *serialPort);
942 HRESULT onParallelPortChange(IParallelPort *parallelPort);
943 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
944 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
945 HRESULT onVRDPServerChange(BOOL aRestart);
946 HRESULT onUSBControllerChange();
947 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
948 IVirtualBoxErrorInfo *aError,
949 ULONG aMaskedIfs);
950 HRESULT onUSBDeviceDetach(IN_BSTR aId,
951 IVirtualBoxErrorInfo *aError);
952 HRESULT onSharedFolderChange();
953
954 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
955
956private:
957
958 struct SnapshotData
959 {
960 SnapshotData() : mLastState(MachineState_Null) {}
961
962 MachineState_T mLastState;
963
964 // used when taking snapshot
965 ComObjPtr<Snapshot> mSnapshot;
966
967 // used when saving state
968 Guid mProgressId;
969 Utf8Str mStateFilePath;
970 };
971
972 struct Uninit
973 {
974 enum Reason { Unexpected, Abnormal, Normal };
975 };
976
977 struct SnapshotTask;
978 struct DeleteSnapshotTask;
979 struct RestoreSnapshotTask;
980
981 friend struct DeleteSnapshotTask;
982 friend struct RestoreSnapshotTask;
983
984 void uninit(Uninit::Reason aReason);
985
986 HRESULT endSavingState(BOOL aSuccess);
987
988 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
989
990 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
991 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
992
993 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
994 const Guid &machineId,
995 const Guid &snapshotId,
996 bool fOnlineMergePossible,
997 MediumLockList *aVMMALockList,
998 ComObjPtr<Medium> &aSource,
999 ComObjPtr<Medium> &aTarget,
1000 bool &fMergeForward,
1001 ComObjPtr<Medium> &pParentForTarget,
1002 MediaList &aChildrenToReparent,
1003 bool &fNeedOnlineMerge,
1004 MediumLockList * &aMediumLockList);
1005 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1006 const ComObjPtr<Medium> &aSource,
1007 const MediaList &aChildrenToReparent,
1008 bool fNeedsOnlineMerge,
1009 MediumLockList *aMediumLockList,
1010 const Guid &aMediumId,
1011 const Guid &aSnapshotId);
1012 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1013 const ComObjPtr<Medium> &aSource,
1014 const ComObjPtr<Medium> &aTarget,
1015 bool fMergeForward,
1016 const ComObjPtr<Medium> &pParentForTarget,
1017 const MediaList &aChildrenToReparent,
1018 MediumLockList *aMediumLockList,
1019 ComObjPtr<Progress> &aProgress,
1020 bool *pfNeedsSaveSettings);
1021
1022 HRESULT lockMedia();
1023 void unlockMedia();
1024
1025 HRESULT setMachineState(MachineState_T aMachineState);
1026 HRESULT updateMachineStateOnClient();
1027
1028 HRESULT mRemoveSavedState;
1029
1030 SnapshotData mSnapshotData;
1031
1032 /** interprocess semaphore handle for this machine */
1033#if defined(RT_OS_WINDOWS)
1034 HANDLE mIPCSem;
1035 Bstr mIPCSemName;
1036 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1037 ComPtr<IInternalSessionControl> *aControl,
1038 HANDLE *aIPCSem, bool aAllowClosing);
1039#elif defined(RT_OS_OS2)
1040 HMTX mIPCSem;
1041 Bstr mIPCSemName;
1042 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1043 ComPtr<IInternalSessionControl> *aControl,
1044 HMTX *aIPCSem, bool aAllowClosing);
1045#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1046 int mIPCSem;
1047# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1048 Bstr mIPCKey;
1049# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1050#else
1051# error "Port me!"
1052#endif
1053
1054 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1055};
1056
1057// SnapshotMachine class
1058////////////////////////////////////////////////////////////////////////////////
1059
1060/**
1061 * @note Notes on locking objects of this class:
1062 * SnapshotMachine shares some data with the primary Machine instance (pointed
1063 * to by the |mPeer| member). In order to provide data consistency it also
1064 * shares its lock handle. This means that whenever you lock a SessionMachine
1065 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1066 * instance is also locked in the same lock mode. Keep it in mind.
1067 */
1068class ATL_NO_VTABLE SnapshotMachine :
1069 public Machine
1070{
1071public:
1072 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1073
1074 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1075
1076 DECLARE_PROTECT_FINAL_CONSTRUCT()
1077
1078 BEGIN_COM_MAP(SnapshotMachine)
1079 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1080 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1081 COM_INTERFACE_ENTRY(IMachine)
1082 END_COM_MAP()
1083
1084 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1085
1086 HRESULT FinalConstruct();
1087 void FinalRelease();
1088
1089 // public initializer/uninitializer for internal purposes only
1090 HRESULT init(SessionMachine *aSessionMachine,
1091 IN_GUID aSnapshotId,
1092 const Utf8Str &aStateFilePath);
1093 HRESULT init(Machine *aMachine,
1094 const settings::Hardware &hardware,
1095 const settings::Storage &storage,
1096 IN_GUID aSnapshotId,
1097 const Utf8Str &aStateFilePath);
1098 void uninit();
1099
1100 // util::Lockable interface
1101 RWLockHandle *lockHandle() const;
1102
1103 // public methods only for internal purposes
1104
1105 virtual bool isSnapshotMachine() const
1106 {
1107 return true;
1108 }
1109
1110 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1111
1112 // unsafe inline public methods for internal purposes only (ensure there is
1113 // a caller and a read lock before calling them!)
1114
1115 const Guid& getSnapshotId() const { return mSnapshotId; }
1116
1117private:
1118
1119 Guid mSnapshotId;
1120
1121 friend class Snapshot;
1122};
1123
1124// third party methods that depend on SnapshotMachine definiton
1125
1126inline const Guid &Machine::getSnapshotId() const
1127{
1128 return (isSnapshotMachine())
1129 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1130 : Guid::Empty;
1131}
1132
1133
1134#endif // ____H_MACHINEIMPL
1135/* 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