VirtualBox

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

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

Main: remove separate snapshots tree lock, have snapshots list use machine lock instead

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