VirtualBox

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

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

Main: mark machine as dirty when snapshot name or description are changed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.0 KB
Line 
1/* $Id: MachineImpl.h 28774 2010-04-26 17:23:41Z 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.215389.xyz. 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 IsModified_Snapshots = 0x0800
607 };
608
609 void setModified(uint32_t fl);
610
611 // callback handlers
612 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
613 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
614 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
615 virtual HRESULT onVRDPServerChange() { return S_OK; }
616 virtual HRESULT onUSBControllerChange() { return S_OK; }
617 virtual HRESULT onStorageControllerChange() { return S_OK; }
618 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
619 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
620 virtual HRESULT onSharedFolderChange() { return S_OK; }
621
622 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
623
624 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
625 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
626
627 void getLogFolder(Utf8Str &aLogFolder);
628 Utf8Str queryLogFilename(ULONG idx);
629
630 HRESULT openSession(IInternalSessionControl *aControl);
631 HRESULT openRemoteSession(IInternalSessionControl *aControl,
632 IN_BSTR aType, IN_BSTR aEnvironment,
633 Progress *aProgress);
634 HRESULT openExistingSession(IInternalSessionControl *aControl);
635
636 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
637 {
638 HRESULT rc;
639 *directControl = mData->mSession.mDirectControl;
640
641 if (!*directControl)
642 rc = E_ACCESSDENIED;
643 else
644 rc = S_OK;
645
646 return rc;
647 }
648
649#if defined(RT_OS_WINDOWS)
650
651 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
652 ComPtr<IInternalSessionControl> *aControl = NULL,
653 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
654 bool isSessionSpawning(RTPROCESS *aPID = NULL);
655
656 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
657 ComPtr<IInternalSessionControl> *aControl = NULL,
658 HANDLE *aIPCSem = NULL)
659 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
660
661#elif defined(RT_OS_OS2)
662
663 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
664 ComPtr<IInternalSessionControl> *aControl = NULL,
665 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
666
667 bool isSessionSpawning(RTPROCESS *aPID = NULL);
668
669 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
670 ComPtr<IInternalSessionControl> *aControl = NULL,
671 HMTX *aIPCSem = NULL)
672 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
673
674#else
675
676 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
677 ComPtr<IInternalSessionControl> *aControl = NULL,
678 bool aAllowClosing = false);
679 bool isSessionSpawning();
680
681 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
682 ComPtr<IInternalSessionControl> *aControl = NULL)
683 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
684
685#endif
686
687 bool checkForSpawnFailure();
688
689 HRESULT trySetRegistered(BOOL aRegistered);
690
691 HRESULT getSharedFolder(CBSTR aName,
692 ComObjPtr<SharedFolder> &aSharedFolder,
693 bool aSetError = false)
694 {
695 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
696 return findSharedFolder(aName, aSharedFolder, aSetError);
697 }
698
699 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
700 MachineState_T *aState = NULL,
701 BOOL *aRegistered = NULL);
702 void releaseStateDependency();
703
704 // for VirtualBoxSupportErrorInfoImpl
705 static const wchar_t *getComponentName() { return L"Machine"; }
706
707protected:
708
709 HRESULT checkStateDependency(StateDependency aDepType);
710
711 Machine *getMachine();
712
713 void ensureNoStateDependencies();
714
715 virtual HRESULT setMachineState(MachineState_T aMachineState);
716
717 HRESULT findSharedFolder(CBSTR aName,
718 ComObjPtr<SharedFolder> &aSharedFolder,
719 bool aSetError = false);
720
721 HRESULT loadSettings(bool aRegistered);
722 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config);
723 HRESULT loadSnapshot(const settings::Snapshot &data,
724 const Guid &aCurSnapshotId,
725 Snapshot *aParentSnapshot);
726 HRESULT loadHardware(const settings::Hardware &data);
727 HRESULT loadStorageControllers(const settings::Storage &data,
728 const Guid *aSnapshotId = NULL);
729 HRESULT loadStorageDevices(StorageController *aStorageController,
730 const settings::StorageController &data,
731 const Guid *aSnapshotId = NULL);
732
733 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
734 bool aSetError = false);
735 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
736 bool aSetError = false);
737
738 HRESULT getStorageControllerByName(const Utf8Str &aName,
739 ComObjPtr<StorageController> &aStorageController,
740 bool aSetError = false);
741
742 HRESULT getMediumAttachmentsOfController(CBSTR aName,
743 MediaData::AttachmentList &aAttachments);
744
745 enum
746 {
747 /* flags for #saveSettings() */
748 SaveS_ResetCurStateModified = 0x01,
749 SaveS_InformCallbacksAnyway = 0x02,
750 SaveS_Force = 0x04,
751 /* flags for #saveStateSettings() */
752 SaveSTS_CurStateModified = 0x20,
753 SaveSTS_StateFilePath = 0x40,
754 SaveSTS_StateTimeStamp = 0x80,
755 };
756
757 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
758 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
759
760 void copyMachineDataToSettings(settings::MachineConfigFile &config);
761 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
762 HRESULT saveHardware(settings::Hardware &data);
763 HRESULT saveStorageControllers(settings::Storage &data);
764 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
765 settings::StorageController &data);
766 HRESULT saveStateSettings(int aFlags);
767
768 HRESULT createImplicitDiffs(const Bstr &aFolder,
769 IProgress *aProgress,
770 ULONG aWeight,
771 bool aOnline,
772 bool *pfNeedsSaveSettings);
773 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
774
775 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
776 IN_BSTR aControllerName,
777 LONG aControllerPort,
778 LONG aDevice);
779 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
780 ComObjPtr<Medium> pMedium);
781 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
782 Guid &id);
783
784 void commitMedia(bool aOnline = false);
785 void rollbackMedia();
786
787 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
788
789 void rollback(bool aNotify);
790 void commit();
791 void copyFrom(Machine *aThat);
792
793#ifdef VBOX_WITH_GUEST_PROPS
794 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
795 ULONG64 *aTimestamp, BSTR *aFlags) const;
796 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
797 ULONG64 *aTimestamp, BSTR *aFlags) const;
798 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
799 IN_BSTR aFlags);
800 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
801 IN_BSTR aFlags);
802 HRESULT enumerateGuestPropertiesInService
803 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
804 ComSafeArrayOut(BSTR, aValues),
805 ComSafeArrayOut(ULONG64, aTimestamps),
806 ComSafeArrayOut(BSTR, aFlags));
807 HRESULT enumerateGuestPropertiesOnVM
808 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
809 ComSafeArrayOut(BSTR, aValues),
810 ComSafeArrayOut(ULONG64, aTimestamps),
811 ComSafeArrayOut(BSTR, aFlags));
812#endif /* VBOX_WITH_GUEST_PROPS */
813
814#ifdef VBOX_WITH_RESOURCE_USAGE_API
815 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
816 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
817
818 pm::CollectorGuestHAL *mGuestHAL;
819#endif /* VBOX_WITH_RESOURCE_USAGE_API */
820
821 Machine* const mPeer;
822
823 VirtualBox* const mParent;
824
825 Shareable<Data> mData;
826 Shareable<SSData> mSSData;
827
828 Backupable<UserData> mUserData;
829 Backupable<HWData> mHWData;
830 Backupable<MediaData> mMediaData;
831
832 // the following fields need special backup/rollback/commit handling,
833 // so they cannot be a part of HWData
834
835 const ComObjPtr<VRDPServer> mVRDPServer;
836 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
837 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
838 const ComObjPtr<AudioAdapter> mAudioAdapter;
839 const ComObjPtr<USBController> mUSBController;
840 const ComObjPtr<BIOSSettings> mBIOSSettings;
841 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
842
843 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
844 Backupable<StorageControllerList> mStorageControllers;
845
846 friend class SessionMachine;
847 friend class SnapshotMachine;
848 friend class Appliance;
849};
850
851// SessionMachine class
852////////////////////////////////////////////////////////////////////////////////
853
854/**
855 * @note Notes on locking objects of this class:
856 * SessionMachine shares some data with the primary Machine instance (pointed
857 * to by the |mPeer| member). In order to provide data consistency it also
858 * shares its lock handle. This means that whenever you lock a SessionMachine
859 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
860 * instance is also locked in the same lock mode. Keep it in mind.
861 */
862class ATL_NO_VTABLE SessionMachine :
863 public VirtualBoxSupportTranslation<SessionMachine>,
864 public Machine,
865 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
866{
867public:
868
869 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
870
871 DECLARE_NOT_AGGREGATABLE(SessionMachine)
872
873 DECLARE_PROTECT_FINAL_CONSTRUCT()
874
875 BEGIN_COM_MAP(SessionMachine)
876 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
877 COM_INTERFACE_ENTRY(ISupportErrorInfo)
878 COM_INTERFACE_ENTRY(IMachine)
879 COM_INTERFACE_ENTRY(IInternalMachineControl)
880 END_COM_MAP()
881
882 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
883
884 HRESULT FinalConstruct();
885 void FinalRelease();
886
887 // public initializer/uninitializer for internal purposes only
888 HRESULT init(Machine *aMachine);
889 void uninit() { uninit(Uninit::Unexpected); }
890
891 // util::Lockable interface
892 RWLockHandle *lockHandle() const;
893
894 // IInternalMachineControl methods
895 STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
896 STDMETHOD(UpdateState)(MachineState_T machineState);
897 STDMETHOD(GetIPCId)(BSTR *id);
898 STDMETHOD(SetPowerUpInfo)(IVirtualBoxErrorInfo *aError);
899 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
900 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
901 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
902 STDMETHOD(AutoCaptureUSBDevices)();
903 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
904 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
905 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
906 STDMETHOD(EndSavingState)(BOOL aSuccess);
907 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
908 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
909 IN_BSTR aName,
910 IN_BSTR aDescription,
911 IProgress *aConsoleProgress,
912 BOOL fTakingSnapshotOnline,
913 BSTR *aStateFilePath);
914 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
915 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
916 MachineState_T *aMachineState, IProgress **aProgress);
917 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
918 ISnapshot *aSnapshot,
919 MachineState_T *aMachineState,
920 IProgress **aProgress);
921 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
922 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
923 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
924 ULONG64 aTimestamp, IN_BSTR aFlags);
925 STDMETHOD(LockMedia)() { return lockMedia(); }
926 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
927
928 // public methods only for internal purposes
929
930 /**
931 * Simple run-time type identification without having to enable C++ RTTI.
932 * The class IDs are defined in VirtualBoxBase.h.
933 * @return
934 */
935 virtual VBoxClsID getClassID() const
936 {
937 return clsidSessionMachine;
938 }
939
940 bool checkForDeath();
941
942 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
943 HRESULT onStorageControllerChange();
944 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
945 HRESULT onSerialPortChange(ISerialPort *serialPort);
946 HRESULT onParallelPortChange(IParallelPort *parallelPort);
947 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
948 HRESULT onVRDPServerChange();
949 HRESULT onUSBControllerChange();
950 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
951 IVirtualBoxErrorInfo *aError,
952 ULONG aMaskedIfs);
953 HRESULT onUSBDeviceDetach(IN_BSTR aId,
954 IVirtualBoxErrorInfo *aError);
955 HRESULT onSharedFolderChange();
956
957 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
958
959private:
960
961 struct SnapshotData
962 {
963 SnapshotData() : mLastState(MachineState_Null) {}
964
965 MachineState_T mLastState;
966
967 // used when taking snapshot
968 ComObjPtr<Snapshot> mSnapshot;
969
970 // used when saving state
971 Guid mProgressId;
972 Utf8Str mStateFilePath;
973 };
974
975 struct Uninit
976 {
977 enum Reason { Unexpected, Abnormal, Normal };
978 };
979
980 struct SnapshotTask;
981 struct DeleteSnapshotTask;
982 struct RestoreSnapshotTask;
983
984 friend struct DeleteSnapshotTask;
985 friend struct RestoreSnapshotTask;
986
987 void uninit(Uninit::Reason aReason);
988
989 HRESULT endSavingState(BOOL aSuccess);
990
991 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
992
993 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
994 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
995
996 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
997 const Guid &machineId,
998 const Guid &snapshotId,
999 bool fOnlineMergePossible,
1000 MediumLockList *aVMMALockList,
1001 ComObjPtr<Medium> &aSource,
1002 ComObjPtr<Medium> &aTarget,
1003 bool &fMergeForward,
1004 ComObjPtr<Medium> &pParentForTarget,
1005 MediaList &aChildrenToReparent,
1006 bool &fNeedOnlineMerge,
1007 MediumLockList * &aMediumLockList);
1008 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1009 const ComObjPtr<Medium> &aSource,
1010 const MediaList &aChildrenToReparent,
1011 bool fNeedsOnlineMerge,
1012 MediumLockList *aMediumLockList,
1013 const Guid &aMediumId,
1014 const Guid &aSnapshotId);
1015
1016 HRESULT lockMedia();
1017 void unlockMedia();
1018
1019 HRESULT setMachineState(MachineState_T aMachineState);
1020 HRESULT updateMachineStateOnClient();
1021
1022 HRESULT mRemoveSavedState;
1023
1024 SnapshotData mSnapshotData;
1025
1026 /** interprocess semaphore handle for this machine */
1027#if defined(RT_OS_WINDOWS)
1028 HANDLE mIPCSem;
1029 Bstr mIPCSemName;
1030 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1031 ComPtr<IInternalSessionControl> *aControl,
1032 HANDLE *aIPCSem, bool aAllowClosing);
1033#elif defined(RT_OS_OS2)
1034 HMTX mIPCSem;
1035 Bstr mIPCSemName;
1036 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1037 ComPtr<IInternalSessionControl> *aControl,
1038 HMTX *aIPCSem, bool aAllowClosing);
1039#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1040 int mIPCSem;
1041# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1042 Bstr mIPCKey;
1043# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1044#else
1045# error "Port me!"
1046#endif
1047
1048 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1049};
1050
1051// SnapshotMachine class
1052////////////////////////////////////////////////////////////////////////////////
1053
1054/**
1055 * @note Notes on locking objects of this class:
1056 * SnapshotMachine shares some data with the primary Machine instance (pointed
1057 * to by the |mPeer| member). In order to provide data consistency it also
1058 * shares its lock handle. This means that whenever you lock a SessionMachine
1059 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1060 * instance is also locked in the same lock mode. Keep it in mind.
1061 */
1062class ATL_NO_VTABLE SnapshotMachine :
1063 public VirtualBoxSupportTranslation<SnapshotMachine>,
1064 public Machine
1065{
1066public:
1067
1068 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
1069
1070 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1071
1072 DECLARE_PROTECT_FINAL_CONSTRUCT()
1073
1074 BEGIN_COM_MAP(SnapshotMachine)
1075 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
1076 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1077 COM_INTERFACE_ENTRY(IMachine)
1078 END_COM_MAP()
1079
1080 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1081
1082 HRESULT FinalConstruct();
1083 void FinalRelease();
1084
1085 // public initializer/uninitializer for internal purposes only
1086 HRESULT init(SessionMachine *aSessionMachine,
1087 IN_GUID aSnapshotId,
1088 const Utf8Str &aStateFilePath);
1089 HRESULT init(Machine *aMachine,
1090 const settings::Hardware &hardware,
1091 const settings::Storage &storage,
1092 IN_GUID aSnapshotId,
1093 const Utf8Str &aStateFilePath);
1094 void uninit();
1095
1096 // util::Lockable interface
1097 RWLockHandle *lockHandle() const;
1098
1099 // public methods only for internal purposes
1100
1101 /**
1102 * Simple run-time type identification without having to enable C++ RTTI.
1103 * The class IDs are defined in VirtualBoxBase.h.
1104 * @return
1105 */
1106 virtual VBoxClsID getClassID() const
1107 {
1108 return clsidSnapshotMachine;
1109 }
1110
1111 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1112
1113 // unsafe inline public methods for internal purposes only (ensure there is
1114 // a caller and a read lock before calling them!)
1115
1116 const Guid& getSnapshotId() const { return mSnapshotId; }
1117
1118private:
1119
1120 Guid mSnapshotId;
1121
1122 friend class Snapshot;
1123};
1124
1125// third party methods that depend on SnapshotMachine definiton
1126
1127inline const Guid &Machine::getSnapshotId() const
1128{
1129 return getClassID() != clsidSnapshotMachine
1130 ? Guid::Empty
1131 : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
1132}
1133
1134
1135#endif // ____H_MACHINEIMPL
1136/* 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