VirtualBox

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

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

introduced VBoxManage modifyvm --rtcuseutc

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