VirtualBox

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

Last change on this file since 22162 was 22143, checked in by vboxsync, 16 years ago

video 2d accel: Main & ui settings

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