VirtualBox

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

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

StorageController: added support for Instance number

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