VirtualBox

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

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

Main, frontends: unsigned long long -> long long

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.2 KB
Line 
1/* $Id: MachineImpl.h 31698 2010-08-16 15:00:05Z 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 LONG64 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(FaultToleranceState))(FaultToleranceState_T *aEnabled);
435 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
436 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
437 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
438 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
439 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
440 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
441 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
442 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
443 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
444 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
445 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
446 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
447 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
448 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
449 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
450 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
451 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
452 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
453 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
454
455 // IMachine methods
456 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
457 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
458
459 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
460 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
461 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
462 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
463 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
464 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
465 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
466 LONG aDevice, IN_BSTR aId, BOOL aForce);
467 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
468 IMedium **aMedium);
469 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
470 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
471 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
472 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
473 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
474 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
475 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
476 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
477 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
478 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
479 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
480 STDMETHOD(RemoveAllCPUIDLeaves)();
481 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
482 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
483 STDMETHOD(SaveSettings)();
484 STDMETHOD(DiscardSettings)();
485 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
486 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
487 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
488 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
489 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
490 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
491 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
492 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
493 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
494 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
495 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
496 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
497 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
498 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
499 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
500 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
501 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
502 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
503 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
504 STDMETHOD(RemoveStorageController(IN_BSTR aName));
505 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
506 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
507 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
508 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
509 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
510 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
511 STDMETHOD(HotPlugCPU(ULONG aCpu));
512 STDMETHOD(HotUnplugCPU(ULONG aCpu));
513 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
514 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
515 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
516
517 // public methods only for internal purposes
518
519 virtual bool isSnapshotMachine() const
520 {
521 return false;
522 }
523
524 virtual bool isSessionMachine() const
525 {
526 return false;
527 }
528
529 /**
530 * Override of the default locking class to be used for validating lock
531 * order with the standard member lock handle.
532 */
533 virtual VBoxLockingClass getLockingClass() const
534 {
535 return LOCKCLASS_MACHINEOBJECT;
536 }
537
538 /// @todo (dmik) add lock and make non-inlined after revising classes
539 // that use it. Note: they should enter Machine lock to keep the returned
540 // information valid!
541 bool isRegistered() { return !!mData->mRegistered; }
542
543 // unsafe inline public methods for internal purposes only (ensure there is
544 // a caller and a read lock before calling them!)
545
546 /**
547 * Returns the VirtualBox object this machine belongs to.
548 *
549 * @note This method doesn't check this object's readiness. Intended to be
550 * used by ready Machine children (whose readiness is bound to the parent's
551 * one) or after doing addCaller() manually.
552 */
553 VirtualBox* getVirtualBox() const { return mParent; }
554
555 /**
556 * Returns this machine ID.
557 *
558 * @note This method doesn't check this object's readiness. Intended to be
559 * used by ready Machine children (whose readiness is bound to the parent's
560 * one) or after adding a caller manually.
561 */
562 const Guid& getId() const { return mData->mUuid; }
563
564 /**
565 * Returns the snapshot ID this machine represents or an empty UUID if this
566 * instance is not SnapshotMachine.
567 *
568 * @note This method doesn't check this object's readiness. Intended to be
569 * used by ready Machine children (whose readiness is bound to the parent's
570 * one) or after adding a caller manually.
571 */
572 inline const Guid& getSnapshotId() const;
573
574 /**
575 * Returns this machine's full settings file path.
576 *
577 * @note This method doesn't lock this object or check its readiness.
578 * Intended to be used only after doing addCaller() manually and locking it
579 * for reading.
580 */
581 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
582
583 /**
584 * Returns this machine name.
585 *
586 * @note This method doesn't lock this object or check its readiness.
587 * Intended to be used only after doing addCaller() manually and locking it
588 * for reading.
589 */
590 const Utf8Str& getName() const { return mUserData->s.strName; }
591
592 enum
593 {
594 IsModified_MachineData = 0x0001,
595 IsModified_Storage = 0x0002,
596 IsModified_NetworkAdapters = 0x0008,
597 IsModified_SerialPorts = 0x0010,
598 IsModified_ParallelPorts = 0x0020,
599 IsModified_VRDPServer = 0x0040,
600 IsModified_AudioAdapter = 0x0080,
601 IsModified_USB = 0x0100,
602 IsModified_BIOS = 0x0200,
603 IsModified_SharedFolders = 0x0400,
604 IsModified_Snapshots = 0x0800
605 };
606
607 void setModified(uint32_t fl);
608
609 // callback handlers
610 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
611 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
612 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
613 virtual HRESULT onVRDPServerChange(BOOL /* aRestart */) { return S_OK; }
614 virtual HRESULT onUSBControllerChange() { return S_OK; }
615 virtual HRESULT onStorageControllerChange() { return S_OK; }
616 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
617 virtual HRESULT onCPUPriorityChange(ULONG /* aCpuPriority */) { return S_OK; }
618 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
619 virtual HRESULT onSharedFolderChange() { return S_OK; }
620
621 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
622
623 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
624 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
625
626 void getLogFolder(Utf8Str &aLogFolder);
627 Utf8Str queryLogFilename(ULONG idx);
628
629 HRESULT openRemoteSession(IInternalSessionControl *aControl,
630 IN_BSTR aType, IN_BSTR aEnvironment,
631 ProgressProxy *aProgress);
632
633 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
634 {
635 HRESULT rc;
636 *directControl = mData->mSession.mDirectControl;
637
638 if (!*directControl)
639 rc = E_ACCESSDENIED;
640 else
641 rc = S_OK;
642
643 return rc;
644 }
645
646#if defined(RT_OS_WINDOWS)
647
648 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
649 ComPtr<IInternalSessionControl> *aControl = NULL,
650 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
651 bool isSessionSpawning(RTPROCESS *aPID = NULL);
652
653 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
654 ComPtr<IInternalSessionControl> *aControl = NULL,
655 HANDLE *aIPCSem = NULL)
656 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
657
658#elif defined(RT_OS_OS2)
659
660 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
661 ComPtr<IInternalSessionControl> *aControl = NULL,
662 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
663
664 bool isSessionSpawning(RTPROCESS *aPID = NULL);
665
666 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
667 ComPtr<IInternalSessionControl> *aControl = NULL,
668 HMTX *aIPCSem = NULL)
669 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
670
671#else
672
673 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
674 ComPtr<IInternalSessionControl> *aControl = NULL,
675 bool aAllowClosing = false);
676 bool isSessionSpawning();
677
678 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
679 ComPtr<IInternalSessionControl> *aControl = NULL)
680 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
681
682#endif
683
684 bool checkForSpawnFailure();
685
686 HRESULT prepareRegister();
687
688 HRESULT getSharedFolder(CBSTR aName,
689 ComObjPtr<SharedFolder> &aSharedFolder,
690 bool aSetError = false)
691 {
692 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
693 return findSharedFolder(aName, aSharedFolder, aSetError);
694 }
695
696 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
697 MachineState_T *aState = NULL,
698 BOOL *aRegistered = NULL);
699 void releaseStateDependency();
700
701protected:
702
703 HRESULT checkStateDependency(StateDependency aDepType);
704
705 Machine *getMachine();
706
707 void ensureNoStateDependencies();
708
709 virtual HRESULT setMachineState(MachineState_T aMachineState);
710
711 HRESULT findSharedFolder(CBSTR aName,
712 ComObjPtr<SharedFolder> &aSharedFolder,
713 bool aSetError = false);
714
715 HRESULT loadSettings(bool aRegistered);
716 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
717 HRESULT loadSnapshot(const settings::Snapshot &data,
718 const Guid &aCurSnapshotId,
719 Snapshot *aParentSnapshot);
720 HRESULT loadHardware(const settings::Hardware &data);
721 HRESULT loadStorageControllers(const settings::Storage &data,
722 const Guid *aSnapshotId = NULL);
723 HRESULT loadStorageDevices(StorageController *aStorageController,
724 const settings::StorageController &data,
725 const Guid *aSnapshotId = NULL);
726
727 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
728 bool aSetError = false);
729 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
730 bool aSetError = false);
731
732 HRESULT getStorageControllerByName(const Utf8Str &aName,
733 ComObjPtr<StorageController> &aStorageController,
734 bool aSetError = false);
735
736 HRESULT getMediumAttachmentsOfController(CBSTR aName,
737 MediaData::AttachmentList &aAttachments);
738
739 enum
740 {
741 /* flags for #saveSettings() */
742 SaveS_ResetCurStateModified = 0x01,
743 SaveS_InformCallbacksAnyway = 0x02,
744 SaveS_Force = 0x04,
745 /* flags for #saveStateSettings() */
746 SaveSTS_CurStateModified = 0x20,
747 SaveSTS_StateFilePath = 0x40,
748 SaveSTS_StateTimeStamp = 0x80
749 };
750
751 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
752 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
753
754 void copyMachineDataToSettings(settings::MachineConfigFile &config);
755 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
756 HRESULT saveHardware(settings::Hardware &data);
757 HRESULT saveStorageControllers(settings::Storage &data);
758 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
759 settings::StorageController &data);
760 HRESULT saveStateSettings(int aFlags);
761
762 HRESULT createImplicitDiffs(IProgress *aProgress,
763 ULONG aWeight,
764 bool aOnline,
765 bool *pfNeedsSaveSettings);
766 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
767
768 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
769 IN_BSTR aControllerName,
770 LONG aControllerPort,
771 LONG aDevice);
772 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
773 ComObjPtr<Medium> pMedium);
774 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
775 Guid &id);
776
777 HRESULT detachDevice(MediumAttachment *pAttach,
778 AutoWriteLock &writeLock,
779 Snapshot *pSnapshot,
780 bool *pfNeedsSaveSettings);
781 HRESULT detachAllMedia(AutoWriteLock &writeLock,
782 Snapshot *pSnapshot,
783 CleanupMode_T cleanupMode,
784 MediaList &llMedia);
785
786 void commitMedia(bool aOnline = false);
787 void rollbackMedia();
788
789 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
790
791 void rollback(bool aNotify);
792 void commit();
793 void copyFrom(Machine *aThat);
794
795 struct DeleteTask;
796 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
797 HRESULT deleteTaskWorker(DeleteTask &task);
798
799#ifdef VBOX_WITH_GUEST_PROPS
800 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
801 LONG64 *aTimestamp, BSTR *aFlags) const;
802 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
803 LONG64 *aTimestamp, BSTR *aFlags) const;
804 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
805 IN_BSTR aFlags);
806 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
807 IN_BSTR aFlags);
808 HRESULT enumerateGuestPropertiesInService
809 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
810 ComSafeArrayOut(BSTR, aValues),
811 ComSafeArrayOut(LONG64, aTimestamps),
812 ComSafeArrayOut(BSTR, aFlags));
813 HRESULT enumerateGuestPropertiesOnVM
814 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
815 ComSafeArrayOut(BSTR, aValues),
816 ComSafeArrayOut(LONG64, aTimestamps),
817 ComSafeArrayOut(BSTR, aFlags));
818#endif /* VBOX_WITH_GUEST_PROPS */
819
820#ifdef VBOX_WITH_RESOURCE_USAGE_API
821 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
822
823 pm::CollectorGuestHAL *mGuestHAL;
824#endif /* VBOX_WITH_RESOURCE_USAGE_API */
825
826 Machine* const mPeer;
827
828 VirtualBox * const mParent;
829
830 Shareable<Data> mData;
831 Shareable<SSData> mSSData;
832
833 Backupable<UserData> mUserData;
834 Backupable<HWData> mHWData;
835 Backupable<MediaData> mMediaData;
836
837 // the following fields need special backup/rollback/commit handling,
838 // so they cannot be a part of HWData
839
840 const ComObjPtr<VRDPServer> mVRDPServer;
841 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
842 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
843 const ComObjPtr<AudioAdapter> mAudioAdapter;
844 const ComObjPtr<USBController> mUSBController;
845 const ComObjPtr<BIOSSettings> mBIOSSettings;
846 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
847
848 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
849 Backupable<StorageControllerList> mStorageControllers;
850
851 friend class SessionMachine;
852 friend class SnapshotMachine;
853 friend class Appliance;
854};
855
856// SessionMachine class
857////////////////////////////////////////////////////////////////////////////////
858
859/**
860 * @note Notes on locking objects of this class:
861 * SessionMachine shares some data with the primary Machine instance (pointed
862 * to by the |mPeer| member). In order to provide data consistency it also
863 * shares its lock handle. This means that whenever you lock a SessionMachine
864 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
865 * instance is also locked in the same lock mode. Keep it in mind.
866 */
867class ATL_NO_VTABLE SessionMachine :
868 public Machine,
869 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
870{
871public:
872 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
873
874 DECLARE_NOT_AGGREGATABLE(SessionMachine)
875
876 DECLARE_PROTECT_FINAL_CONSTRUCT()
877
878 BEGIN_COM_MAP(SessionMachine)
879 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
880 COM_INTERFACE_ENTRY(ISupportErrorInfo)
881 COM_INTERFACE_ENTRY(IMachine)
882 COM_INTERFACE_ENTRY(IInternalMachineControl)
883 END_COM_MAP()
884
885 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
886
887 HRESULT FinalConstruct();
888 void FinalRelease();
889
890 // public initializer/uninitializer for internal purposes only
891 HRESULT init(Machine *aMachine);
892 void uninit() { uninit(Uninit::Unexpected); }
893
894 // util::Lockable interface
895 RWLockHandle *lockHandle() const;
896
897 // IInternalMachineControl methods
898 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
899 STDMETHOD(UpdateState)(MachineState_T machineState);
900 STDMETHOD(GetIPCId)(BSTR *id);
901 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
902 STDMETHOD(EndPowerUp)(LONG iResult);
903 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
904 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
905 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
906 STDMETHOD(AutoCaptureUSBDevices)();
907 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
908 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
909 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
910 STDMETHOD(EndSavingState)(BOOL aSuccess);
911 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
912 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
913 IN_BSTR aName,
914 IN_BSTR aDescription,
915 IProgress *aConsoleProgress,
916 BOOL fTakingSnapshotOnline,
917 BSTR *aStateFilePath);
918 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
919 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
920 MachineState_T *aMachineState, IProgress **aProgress);
921 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
922 IMedium *aSource, IMedium *aTarget,
923 BOOL fMergeForward,
924 IMedium *pParentForTarget,
925 ComSafeArrayIn(IMedium *, aChildrenToReparent));
926 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
927 ISnapshot *aSnapshot,
928 MachineState_T *aMachineState,
929 IProgress **aProgress);
930 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
931 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
932 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
933 LONG64 aTimestamp, IN_BSTR aFlags);
934 STDMETHOD(LockMedia)() { return lockMedia(); }
935 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
936
937 // public methods only for internal purposes
938
939 virtual bool isSessionMachine() const
940 {
941 return true;
942 }
943
944 bool checkForDeath();
945
946 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
947 HRESULT onStorageControllerChange();
948 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
949 HRESULT onSerialPortChange(ISerialPort *serialPort);
950 HRESULT onParallelPortChange(IParallelPort *parallelPort);
951 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
952 HRESULT onCPUPriorityChange(ULONG aCpuPriority);
953 HRESULT onVRDPServerChange(BOOL aRestart);
954 HRESULT onUSBControllerChange();
955 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
956 IVirtualBoxErrorInfo *aError,
957 ULONG aMaskedIfs);
958 HRESULT onUSBDeviceDetach(IN_BSTR aId,
959 IVirtualBoxErrorInfo *aError);
960 HRESULT onSharedFolderChange();
961
962 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
963
964private:
965
966 struct SnapshotData
967 {
968 SnapshotData() : mLastState(MachineState_Null) {}
969
970 MachineState_T mLastState;
971
972 // used when taking snapshot
973 ComObjPtr<Snapshot> mSnapshot;
974
975 // used when saving state
976 Guid mProgressId;
977 Utf8Str mStateFilePath;
978 };
979
980 struct Uninit
981 {
982 enum Reason { Unexpected, Abnormal, Normal };
983 };
984
985 struct SnapshotTask;
986 struct DeleteSnapshotTask;
987 struct RestoreSnapshotTask;
988
989 friend struct DeleteSnapshotTask;
990 friend struct RestoreSnapshotTask;
991
992 void uninit(Uninit::Reason aReason);
993
994 HRESULT endSavingState(BOOL aSuccess);
995
996 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
997
998 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
999 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1000
1001 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1002 const Guid &machineId,
1003 const Guid &snapshotId,
1004 bool fOnlineMergePossible,
1005 MediumLockList *aVMMALockList,
1006 ComObjPtr<Medium> &aSource,
1007 ComObjPtr<Medium> &aTarget,
1008 bool &fMergeForward,
1009 ComObjPtr<Medium> &pParentForTarget,
1010 MediaList &aChildrenToReparent,
1011 bool &fNeedOnlineMerge,
1012 MediumLockList * &aMediumLockList);
1013 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1014 const ComObjPtr<Medium> &aSource,
1015 const MediaList &aChildrenToReparent,
1016 bool fNeedsOnlineMerge,
1017 MediumLockList *aMediumLockList,
1018 const Guid &aMediumId,
1019 const Guid &aSnapshotId);
1020 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1021 const ComObjPtr<Medium> &aSource,
1022 const ComObjPtr<Medium> &aTarget,
1023 bool fMergeForward,
1024 const ComObjPtr<Medium> &pParentForTarget,
1025 const MediaList &aChildrenToReparent,
1026 MediumLockList *aMediumLockList,
1027 ComObjPtr<Progress> &aProgress,
1028 bool *pfNeedsMachineSaveSettings);
1029
1030 HRESULT lockMedia();
1031 void unlockMedia();
1032
1033 HRESULT setMachineState(MachineState_T aMachineState);
1034 HRESULT updateMachineStateOnClient();
1035
1036 HRESULT mRemoveSavedState;
1037
1038 SnapshotData mSnapshotData;
1039
1040 /** interprocess semaphore handle for this machine */
1041#if defined(RT_OS_WINDOWS)
1042 HANDLE mIPCSem;
1043 Bstr mIPCSemName;
1044 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1045 ComPtr<IInternalSessionControl> *aControl,
1046 HANDLE *aIPCSem, bool aAllowClosing);
1047#elif defined(RT_OS_OS2)
1048 HMTX mIPCSem;
1049 Bstr mIPCSemName;
1050 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1051 ComPtr<IInternalSessionControl> *aControl,
1052 HMTX *aIPCSem, bool aAllowClosing);
1053#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1054 int mIPCSem;
1055# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1056 Bstr mIPCKey;
1057# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1058#else
1059# error "Port me!"
1060#endif
1061
1062 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1063};
1064
1065// SnapshotMachine class
1066////////////////////////////////////////////////////////////////////////////////
1067
1068/**
1069 * @note Notes on locking objects of this class:
1070 * SnapshotMachine shares some data with the primary Machine instance (pointed
1071 * to by the |mPeer| member). In order to provide data consistency it also
1072 * shares its lock handle. This means that whenever you lock a SessionMachine
1073 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1074 * instance is also locked in the same lock mode. Keep it in mind.
1075 */
1076class ATL_NO_VTABLE SnapshotMachine :
1077 public Machine
1078{
1079public:
1080 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1081
1082 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1083
1084 DECLARE_PROTECT_FINAL_CONSTRUCT()
1085
1086 BEGIN_COM_MAP(SnapshotMachine)
1087 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1088 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1089 COM_INTERFACE_ENTRY(IMachine)
1090 END_COM_MAP()
1091
1092 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1093
1094 HRESULT FinalConstruct();
1095 void FinalRelease();
1096
1097 // public initializer/uninitializer for internal purposes only
1098 HRESULT init(SessionMachine *aSessionMachine,
1099 IN_GUID aSnapshotId,
1100 const Utf8Str &aStateFilePath);
1101 HRESULT init(Machine *aMachine,
1102 const settings::Hardware &hardware,
1103 const settings::Storage &storage,
1104 IN_GUID aSnapshotId,
1105 const Utf8Str &aStateFilePath);
1106 void uninit();
1107
1108 // util::Lockable interface
1109 RWLockHandle *lockHandle() const;
1110
1111 // public methods only for internal purposes
1112
1113 virtual bool isSnapshotMachine() const
1114 {
1115 return true;
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 (isSnapshotMachine())
1137 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1138 : Guid::Empty;
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