VirtualBox

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

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

Main/Machine+Snapshot+Medium: Big medium locking cleanup and straightened up the responsibilities between Snapshot and Medium. Rewritten task handling and cleaned up task implementation for medium operations. Implemented IMedium::mergeTo (no way to call it via any frontend yet), making the method parameters similar to IMedium::cloneto. Plus lots of other minor cleanups.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette