VirtualBox

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

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

Main: snapshots code cleanup, renames, documentation, coding style

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