VirtualBox

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

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

Main: Live migration work.

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

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