1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class declaration
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_MACHINEIMPL
|
---|
23 | #define ____H_MACHINEIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include "VirtualBoxXMLUtil.h"
|
---|
27 | #include "ProgressImpl.h"
|
---|
28 | #include "SnapshotImpl.h"
|
---|
29 | #include "VRDPServerImpl.h"
|
---|
30 | #include "DVDDriveImpl.h"
|
---|
31 | #include "FloppyDriveImpl.h"
|
---|
32 | #include "HardDiskAttachmentImpl.h"
|
---|
33 | #include "Collection.h"
|
---|
34 | #include "NetworkAdapterImpl.h"
|
---|
35 | #include "AudioAdapterImpl.h"
|
---|
36 | #include "BIOSSettingsImpl.h"
|
---|
37 |
|
---|
38 | // generated header
|
---|
39 | #include "SchemaDefs.h"
|
---|
40 |
|
---|
41 | #include <VBox/types.h>
|
---|
42 | #include <VBox/cfgldr.h>
|
---|
43 | #include <iprt/file.h>
|
---|
44 | #include <iprt/thread.h>
|
---|
45 |
|
---|
46 | #include <list>
|
---|
47 |
|
---|
48 | // defines
|
---|
49 | ////////////////////////////////////////////////////////////////////////////////
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Checks whether the given Machine object is mutable (allows for calling setters)
|
---|
53 | * or not. When the machine is not mutable, sets error info and returns E_ACCESSDENIED.
|
---|
54 | * The translatable error message is defined in null context.
|
---|
55 | *
|
---|
56 | * This macro <b>must</b> be used within setters of all Machine children
|
---|
57 | * (DVDDrive, NetworkAdapter, AudioAdapter, etc.).
|
---|
58 | *
|
---|
59 | * @param machine the machine object (must cast to Machine *)
|
---|
60 | */
|
---|
61 | /// @todo replace with AutoStateDependency
|
---|
62 | #define CHECK_MACHINE_MUTABILITY(machine) \
|
---|
63 | do { \
|
---|
64 | if (!machine->isMutable()) \
|
---|
65 | return setError (E_ACCESSDENIED, tr ("The machine is not mutable")); \
|
---|
66 | } while (0)
|
---|
67 |
|
---|
68 | /** Like CHECK_MACHINE_MUTABILITY but a saved state is OK, too. */
|
---|
69 | /// @todo replace with AutoStateDependency
|
---|
70 | #define CHECK_MACHINE_MUTABILITY_IGNORING_SAVED(machine) \
|
---|
71 | do { \
|
---|
72 | if (!machine->isMutableIgnoringSavedState()) \
|
---|
73 | return setError (E_ACCESSDENIED, \
|
---|
74 | tr ("The machine is not mutable or in saved state")); \
|
---|
75 | } while (0)
|
---|
76 |
|
---|
77 |
|
---|
78 | // helper declarations
|
---|
79 | ////////////////////////////////////////////////////////////////////////////////
|
---|
80 |
|
---|
81 | class VirtualBox;
|
---|
82 | class Progress;
|
---|
83 | class CombinedProgress;
|
---|
84 | class Keyboard;
|
---|
85 | class Mouse;
|
---|
86 | class Display;
|
---|
87 | class MachineDebugger;
|
---|
88 | class USBController;
|
---|
89 | class Snapshot;
|
---|
90 | class SharedFolder;
|
---|
91 |
|
---|
92 | class SessionMachine;
|
---|
93 |
|
---|
94 | // Machine class
|
---|
95 | ////////////////////////////////////////////////////////////////////////////////
|
---|
96 |
|
---|
97 | class ATL_NO_VTABLE Machine :
|
---|
98 | public VirtualBoxBaseWithChildrenNEXT,
|
---|
99 | public VirtualBoxXMLUtil,
|
---|
100 | public VirtualBoxSupportErrorInfoImpl <Machine, IMachine>,
|
---|
101 | public VirtualBoxSupportTranslation <Machine>,
|
---|
102 | public IMachine
|
---|
103 | {
|
---|
104 | Q_OBJECT
|
---|
105 |
|
---|
106 | public:
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Internal machine data.
|
---|
110 | *
|
---|
111 | * Only one instance of this data exists per every machine --
|
---|
112 | * it is shared by the Machine, SessionMachine and all SnapshotMachine
|
---|
113 | * instances associated with the given machine using the util::Shareable
|
---|
114 | * template through the mData variable.
|
---|
115 | *
|
---|
116 | * @note |const| members are persistent during lifetime so can be
|
---|
117 | * accessed without locking.
|
---|
118 | *
|
---|
119 | * @note There is no need to lock anything inside init() or uninit()
|
---|
120 | * methods, because they are always serialized (see AutoCaller).
|
---|
121 | */
|
---|
122 | struct Data
|
---|
123 | {
|
---|
124 | /**
|
---|
125 | * Data structure to hold information about sessions opened for the
|
---|
126 | * given machine.
|
---|
127 | */
|
---|
128 | struct Session
|
---|
129 | {
|
---|
130 | /** Control of the direct session opened by openSession() */
|
---|
131 | ComPtr <IInternalSessionControl> mDirectControl;
|
---|
132 |
|
---|
133 | typedef std::list <ComPtr <IInternalSessionControl> > RemoteControlList;
|
---|
134 |
|
---|
135 | /** list of controls of all opened remote sessions */
|
---|
136 | RemoteControlList mRemoteControls;
|
---|
137 |
|
---|
138 | /** openRemoteSession() and OnSessionEnd() progress indicator */
|
---|
139 | ComObjPtr <Progress> mProgress;
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * PID of the session object that must be passed to openSession()
|
---|
143 | * to finalize the openRemoteSession() request
|
---|
144 | * (i.e., PID of the process created by openRemoteSession())
|
---|
145 | */
|
---|
146 | RTPROCESS mPid;
|
---|
147 |
|
---|
148 | /** Current session state */
|
---|
149 | SessionState_T mState;
|
---|
150 |
|
---|
151 | /** Session type string (for indirect sessions) */
|
---|
152 | Bstr mType;
|
---|
153 |
|
---|
154 | /** Sesison machine object */
|
---|
155 | ComObjPtr <SessionMachine> mMachine;
|
---|
156 | };
|
---|
157 |
|
---|
158 | Data();
|
---|
159 | ~Data();
|
---|
160 |
|
---|
161 | const Guid mUuid;
|
---|
162 | BOOL mRegistered;
|
---|
163 |
|
---|
164 | Bstr mConfigFile;
|
---|
165 | Bstr mConfigFileFull;
|
---|
166 |
|
---|
167 | BOOL mAccessible;
|
---|
168 | com::ErrorInfo mAccessError;
|
---|
169 |
|
---|
170 | MachineState_T mMachineState;
|
---|
171 | LONG64 mLastStateChange;
|
---|
172 |
|
---|
173 | uint32_t mMachineStateDeps;
|
---|
174 | RTSEMEVENT mZeroMachineStateDepsSem;
|
---|
175 | BOOL mWaitingStateDeps;
|
---|
176 |
|
---|
177 | BOOL mCurrentStateModified;
|
---|
178 |
|
---|
179 | RTFILE mHandleCfgFile;
|
---|
180 |
|
---|
181 | Session mSession;
|
---|
182 |
|
---|
183 | ComObjPtr <Snapshot> mFirstSnapshot;
|
---|
184 | ComObjPtr <Snapshot> mCurrentSnapshot;
|
---|
185 | };
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Saved state data.
|
---|
189 | *
|
---|
190 | * It's actually only the state file path string, but it needs to be
|
---|
191 | * separate from Data, because Machine and SessionMachine instances
|
---|
192 | * share it, while SnapshotMachine does not.
|
---|
193 | *
|
---|
194 | * The data variable is |mSSData|.
|
---|
195 | */
|
---|
196 | struct SSData
|
---|
197 | {
|
---|
198 | Bstr mStateFilePath;
|
---|
199 | };
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * User changeable machine data.
|
---|
203 | *
|
---|
204 | * This data is common for all machine snapshots, i.e. it is shared
|
---|
205 | * by all SnapshotMachine instances associated with the given machine
|
---|
206 | * using the util::Backupable template through the |mUserData| variable.
|
---|
207 | *
|
---|
208 | * SessionMachine instances can alter this data and discard changes.
|
---|
209 | *
|
---|
210 | * @note There is no need to lock anything inside init() or uninit()
|
---|
211 | * methods, because they are always serialized (see AutoCaller).
|
---|
212 | */
|
---|
213 | struct UserData
|
---|
214 | {
|
---|
215 | UserData();
|
---|
216 | ~UserData();
|
---|
217 |
|
---|
218 | bool operator== (const UserData &that) const
|
---|
219 | {
|
---|
220 | return this == &that ||
|
---|
221 | (mName == that.mName &&
|
---|
222 | mNameSync == that.mNameSync &&
|
---|
223 | mDescription == that.mDescription &&
|
---|
224 | mOSTypeId == that.mOSTypeId &&
|
---|
225 | mSnapshotFolderFull == that.mSnapshotFolderFull);
|
---|
226 | }
|
---|
227 |
|
---|
228 | Bstr mName;
|
---|
229 | BOOL mNameSync;
|
---|
230 | Bstr mDescription;
|
---|
231 | Bstr mOSTypeId;
|
---|
232 | Bstr mSnapshotFolder;
|
---|
233 | Bstr mSnapshotFolderFull;
|
---|
234 | };
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Hardware data.
|
---|
238 | *
|
---|
239 | * This data is unique for a machine and for every machine snapshot.
|
---|
240 | * Stored using the util::Backupable template in the |mHWData| variable.
|
---|
241 | *
|
---|
242 | * SessionMachine instances can alter this data and discard changes.
|
---|
243 | */
|
---|
244 | struct HWData
|
---|
245 | {
|
---|
246 | HWData();
|
---|
247 | ~HWData();
|
---|
248 |
|
---|
249 | bool operator== (const HWData &that) const;
|
---|
250 |
|
---|
251 | ULONG mMemorySize;
|
---|
252 | ULONG mVRAMSize;
|
---|
253 | ULONG mMonitorCount;
|
---|
254 | TriStateBool_T mHWVirtExEnabled;
|
---|
255 |
|
---|
256 | DeviceType_T mBootOrder [SchemaDefs::MaxBootPosition];
|
---|
257 |
|
---|
258 | typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
|
---|
259 | SharedFolderList mSharedFolders;
|
---|
260 | ClipboardMode_T mClipboardMode;
|
---|
261 | };
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Hard disk data.
|
---|
265 | *
|
---|
266 | * The usage policy is the same as for HWData, but a separate structure
|
---|
267 | * is necessarym because hard disk data requires different procedures when
|
---|
268 | * taking or discarding snapshots, etc.
|
---|
269 | *
|
---|
270 | * The data variable is |mHWData|.
|
---|
271 | */
|
---|
272 | struct HDData
|
---|
273 | {
|
---|
274 | HDData();
|
---|
275 | ~HDData();
|
---|
276 |
|
---|
277 | bool operator== (const HDData &that) const;
|
---|
278 |
|
---|
279 | typedef std::list <ComObjPtr <HardDiskAttachment> > HDAttachmentList;
|
---|
280 | HDAttachmentList mHDAttachments;
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Right after Machine::fixupHardDisks(true): |true| if hard disks
|
---|
284 | * were actually changed, |false| otherwise
|
---|
285 | */
|
---|
286 | bool mHDAttachmentsChanged;
|
---|
287 | };
|
---|
288 |
|
---|
289 | enum StateDependency
|
---|
290 | {
|
---|
291 | AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
|
---|
292 | };
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Helper class that safely manages the machine state dependency by
|
---|
296 | * calling Machine::addStateDependency() on construction and
|
---|
297 | * Machine::releaseStateDependency() on destruction. Intended for Machine
|
---|
298 | * children. The usage pattern is:
|
---|
299 | *
|
---|
300 | * @code
|
---|
301 | * AutoCaller autoCaller (this);
|
---|
302 | * CheckComRCReturnRC (autoCaller.rc());
|
---|
303 | *
|
---|
304 | * Machine::AutoStateDependency <MutableStateDep> adep (mParent);
|
---|
305 | * CheckComRCReturnRC (stateDep.rc());
|
---|
306 | * ...
|
---|
307 | * // code that depends on the particular machine state
|
---|
308 | * ...
|
---|
309 | * @endcode
|
---|
310 | *
|
---|
311 | * Note that it is more convenient to use the following individual
|
---|
312 | * shortcut classes instead of using this template directly:
|
---|
313 | * AutoAnyStateDependency, AutoMutableStateDependency and
|
---|
314 | * AutoMutableOrSavedStateDependency. The usage pattern is exactly the
|
---|
315 | * same as above except that there is no need to specify the template
|
---|
316 | * argument because it is already done by the shortcut class.
|
---|
317 | *
|
---|
318 | * @param taDepType Dependecy type to manage.
|
---|
319 | */
|
---|
320 | template <StateDependency taDepType = AnyStateDep>
|
---|
321 | class AutoStateDependency
|
---|
322 | {
|
---|
323 | public:
|
---|
324 |
|
---|
325 | AutoStateDependency (Machine *aThat)
|
---|
326 | : mThat (aThat), mRC (S_OK)
|
---|
327 | , mMachineState (MachineState_InvalidMachineState)
|
---|
328 | , mRegistered (FALSE)
|
---|
329 | {
|
---|
330 | Assert (aThat);
|
---|
331 | mRC = aThat->addStateDependency (taDepType, &mMachineState,
|
---|
332 | &mRegistered);
|
---|
333 | }
|
---|
334 | ~AutoStateDependency()
|
---|
335 | {
|
---|
336 | if (SUCCEEDED (mRC))
|
---|
337 | mThat->releaseStateDependency();
|
---|
338 | }
|
---|
339 |
|
---|
340 | /** Decreases the number of dependencies before the instance is
|
---|
341 | * destroyed. Note that will reset #rc() to E_FAIL. */
|
---|
342 | void release()
|
---|
343 | {
|
---|
344 | AssertReturnVoid (SUCCEEDED (mRC));
|
---|
345 | mThat->releaseStateDependency();
|
---|
346 | mRC = E_FAIL;
|
---|
347 | }
|
---|
348 |
|
---|
349 | /** Restores the number of callers after by #release(). #rc() will be
|
---|
350 | * reset to the result of calling addStateDependency() and must be
|
---|
351 | * rechecked to ensure the operation succeeded. */
|
---|
352 | void add()
|
---|
353 | {
|
---|
354 | AssertReturnVoid (!SUCCEEDED (mRC));
|
---|
355 | mRC = mThat->addStateDependency (taDepType, &mMachineState,
|
---|
356 | &mRegistered);
|
---|
357 | }
|
---|
358 |
|
---|
359 | /** Returns the result of Machine::addStateDependency(). */
|
---|
360 | HRESULT rc() const { return mRC; }
|
---|
361 |
|
---|
362 | /** Shortcut to SUCCEEDED (rc()). */
|
---|
363 | bool isOk() const { return SUCCEEDED (mRC); }
|
---|
364 |
|
---|
365 | /** Returns the machine state value as returned by
|
---|
366 | * Machine::addStateDependency(). */
|
---|
367 | MachineState_T machineState() const { return mMachineState; }
|
---|
368 |
|
---|
369 | /** Returns the machine state value as returned by
|
---|
370 | * Machine::addStateDependency(). */
|
---|
371 | BOOL machineRegistered() const { return mRegistered; }
|
---|
372 |
|
---|
373 | protected:
|
---|
374 |
|
---|
375 | Machine *mThat;
|
---|
376 | HRESULT mRC;
|
---|
377 | MachineState_T mMachineState;
|
---|
378 | BOOL mRegistered;
|
---|
379 |
|
---|
380 | private:
|
---|
381 |
|
---|
382 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (AutoStateDependency)
|
---|
383 | DECLARE_CLS_NEW_DELETE_NOOP (AutoStateDependency)
|
---|
384 | };
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Shortcut to AutoStateDependency <AnyStateDep>.
|
---|
388 | * See AutoStateDependency to get the usage pattern.
|
---|
389 | *
|
---|
390 | * Accepts any machine state and guarantees the state won't change before
|
---|
391 | * this object is destroyed. If the machine state cannot be protected (as
|
---|
392 | * a result of the state change currently in progress), this instance's
|
---|
393 | * #rc() method will indicate a failure, and the caller is not allowed to
|
---|
394 | * rely on any particular machine state and should return the failed
|
---|
395 | * result code to the upper level.
|
---|
396 | */
|
---|
397 | typedef AutoStateDependency <AnyStateDep> AutoAnyStateDependency;
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * Shortcut to AutoStateDependency <MutableStateDep>.
|
---|
401 | * See AutoStateDependency to get the usage pattern.
|
---|
402 | *
|
---|
403 | * Succeeds only if the machine state is in one of the mutable states, and
|
---|
404 | * guarantees the given mutable state won't change before this object is
|
---|
405 | * destroyed. If the machine is not mutable, this instance's #rc() method
|
---|
406 | * will indicate a failure, and the caller is not allowed to rely on any
|
---|
407 | * particular machine state and should return the failed result code to
|
---|
408 | * the upper level.
|
---|
409 | *
|
---|
410 | * Intended to be used within all setter methods of IMachine
|
---|
411 | * children objects (DVDDrive, NetworkAdapter, AudioAdapter, etc.) to
|
---|
412 | * provide data protection and consistency.
|
---|
413 | */
|
---|
414 | typedef AutoStateDependency <MutableStateDep> AutoMutableStateDependency;
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Shortcut to AutoStateDependency <MutableOrSavedStateDep>.
|
---|
418 | * See AutoStateDependency to get the usage pattern.
|
---|
419 | *
|
---|
420 | * Succeeds only if the machine state is in one of the mutable states, or
|
---|
421 | * if the machine is in the Saved state, and guarantees the given mutable
|
---|
422 | * state won't change before this object is destroyed. If the machine is
|
---|
423 | * not mutable, this instance's #rc() method will indicate a failure, and
|
---|
424 | * the caller is not allowed to rely on any particular machine state and
|
---|
425 | * should return the failed result code to the upper level.
|
---|
426 | *
|
---|
427 | * Intended to be used within setter methods of IMachine
|
---|
428 | * children objects that may also operate on Saved machines.
|
---|
429 | */
|
---|
430 | typedef AutoStateDependency <MutableOrSavedStateDep> AutoMutableOrSavedStateDependency;
|
---|
431 |
|
---|
432 |
|
---|
433 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Machine)
|
---|
434 |
|
---|
435 | DECLARE_NOT_AGGREGATABLE(Machine)
|
---|
436 |
|
---|
437 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
438 |
|
---|
439 | BEGIN_COM_MAP(Machine)
|
---|
440 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
441 | COM_INTERFACE_ENTRY(IMachine)
|
---|
442 | END_COM_MAP()
|
---|
443 |
|
---|
444 | NS_DECL_ISUPPORTS
|
---|
445 |
|
---|
446 | DECLARE_EMPTY_CTOR_DTOR (Machine)
|
---|
447 |
|
---|
448 | HRESULT FinalConstruct();
|
---|
449 | void FinalRelease();
|
---|
450 |
|
---|
451 | enum InitMode { Init_New, Init_Existing, Init_Registered };
|
---|
452 |
|
---|
453 | // public initializer/uninitializer for internal purposes only
|
---|
454 | HRESULT init (VirtualBox *aParent, const BSTR aConfigFile,
|
---|
455 | InitMode aMode, const BSTR aName = NULL,
|
---|
456 | BOOL aNameSync = TRUE, const Guid *aId = NULL);
|
---|
457 | void uninit();
|
---|
458 |
|
---|
459 | // IMachine properties
|
---|
460 | STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
|
---|
461 | STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
|
---|
462 | STDMETHOD(COMGETTER(AccessError)) (IVirtualBoxErrorInfo **aAccessError);
|
---|
463 | STDMETHOD(COMGETTER(Name))(BSTR *aName);
|
---|
464 | STDMETHOD(COMSETTER(Name))(INPTR BSTR aName);
|
---|
465 | STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
|
---|
466 | STDMETHOD(COMSETTER(Description))(INPTR BSTR aDescription);
|
---|
467 | STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
|
---|
468 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
469 | STDMETHOD(COMSETTER(OSTypeId)) (INPTR BSTR aOSTypeId);
|
---|
470 | STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
|
---|
471 | STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
|
---|
472 | STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
|
---|
473 | STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
|
---|
474 | STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
|
---|
475 | STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
|
---|
476 | STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
|
---|
477 | STDMETHOD(COMGETTER(HWVirtExEnabled))(TriStateBool_T *enabled);
|
---|
478 | STDMETHOD(COMSETTER(HWVirtExEnabled))(TriStateBool_T enabled);
|
---|
479 | STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
|
---|
480 | STDMETHOD(COMSETTER(SnapshotFolder))(INPTR BSTR aSavedStateFolder);
|
---|
481 | STDMETHOD(COMGETTER(HardDiskAttachments))(IHardDiskAttachmentCollection **attachments);
|
---|
482 | STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
|
---|
483 | STDMETHOD(COMGETTER(DVDDrive))(IDVDDrive **dvdDrive);
|
---|
484 | STDMETHOD(COMGETTER(FloppyDrive))(IFloppyDrive **floppyDrive);
|
---|
485 | STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
|
---|
486 | STDMETHOD(COMGETTER(USBController))(IUSBController * *a_ppUSBController);
|
---|
487 | STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *filePath);
|
---|
488 | STDMETHOD(COMGETTER(SettingsModified))(BOOL *modified);
|
---|
489 | STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
|
---|
490 | STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
|
---|
491 | STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
|
---|
492 | STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
|
---|
493 | STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
|
---|
494 | STDMETHOD(COMGETTER(StateFilePath)) (BSTR *aStateFilePath);
|
---|
495 | STDMETHOD(COMGETTER(LogFolder)) (BSTR *aLogFolder);
|
---|
496 | STDMETHOD(COMGETTER(CurrentSnapshot)) (ISnapshot **aCurrentSnapshot);
|
---|
497 | STDMETHOD(COMGETTER(SnapshotCount)) (ULONG *aSnapshotCount);
|
---|
498 | STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
|
---|
499 | STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
|
---|
500 | STDMETHOD(COMGETTER(ClipboardMode)) (ClipboardMode_T *aClipboardMode);
|
---|
501 | STDMETHOD(COMSETTER(ClipboardMode)) (ClipboardMode_T aClipboardMode);
|
---|
502 |
|
---|
503 | // IMachine methods
|
---|
504 | STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
|
---|
505 | STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
|
---|
506 | STDMETHOD(AttachHardDisk)(INPTR GUIDPARAM aId, DiskControllerType_T aCtl, LONG aDev);
|
---|
507 | STDMETHOD(GetHardDisk)(DiskControllerType_T aCtl, LONG aDev, IHardDisk **aHardDisk);
|
---|
508 | STDMETHOD(DetachHardDisk) (DiskControllerType_T aCtl, LONG aDev);
|
---|
509 | STDMETHOD(GetNetworkAdapter) (ULONG slot, INetworkAdapter **adapter);
|
---|
510 | STDMETHOD(GetNextExtraDataKey)(INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
|
---|
511 | STDMETHOD(GetExtraData)(INPTR BSTR aKey, BSTR *aValue);
|
---|
512 | STDMETHOD(SetExtraData)(INPTR BSTR aKey, INPTR BSTR aValue);
|
---|
513 | STDMETHOD(SaveSettings)();
|
---|
514 | STDMETHOD(DiscardSettings)();
|
---|
515 | STDMETHOD(DeleteSettings)();
|
---|
516 | STDMETHOD(GetSnapshot) (INPTR GUIDPARAM aId, ISnapshot **aSnapshot);
|
---|
517 | STDMETHOD(FindSnapshot) (INPTR BSTR aName, ISnapshot **aSnapshot);
|
---|
518 | STDMETHOD(SetCurrentSnapshot) (INPTR GUIDPARAM aId);
|
---|
519 | STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
|
---|
520 | STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
|
---|
521 | STDMETHOD(CanShowConsoleWindow) (BOOL *aCanShow);
|
---|
522 | STDMETHOD(ShowConsoleWindow) (ULONG64 *aWinId);
|
---|
523 |
|
---|
524 | // public methods only for internal purposes
|
---|
525 |
|
---|
526 | /// @todo (dmik) add lock and make non-inlined after revising classes
|
---|
527 | // that use it (actually, the CHECK_MACHINE_MUTABILITY macro).
|
---|
528 | // Note: these classes should enter Machine lock to keep the returned
|
---|
529 | // information valid!
|
---|
530 | /// @todo replace with AutoStateDependency
|
---|
531 | bool isMutable()
|
---|
532 | {
|
---|
533 | return ((!mData->mRegistered) ||
|
---|
534 | (mType == IsSessionMachine &&
|
---|
535 | mData->mMachineState <= MachineState_Paused &&
|
---|
536 | mData->mMachineState != MachineState_Saved));
|
---|
537 | }
|
---|
538 |
|
---|
539 | /// @todo (dmik) add lock and make non-inlined after revising classes
|
---|
540 | // that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).
|
---|
541 | // Note: these classes should enter Machine lock to keep the returned
|
---|
542 | // information valid!
|
---|
543 | /// @todo replace with AutoStateDependency
|
---|
544 | bool isMutableIgnoringSavedState()
|
---|
545 | {
|
---|
546 | return ((!mData->mRegistered) ||
|
---|
547 | (mType == IsSessionMachine &&
|
---|
548 | mData->mMachineState <= MachineState_Paused));
|
---|
549 | }
|
---|
550 |
|
---|
551 | /// @todo (dmik) add lock and make non-inlined after revising classes
|
---|
552 | // that use it. Note: they should enter Machine lock to keep the returned
|
---|
553 | // information valid!
|
---|
554 | bool isRegistered() { return !!mData->mRegistered; }
|
---|
555 |
|
---|
556 | ComObjPtr <SessionMachine> sessionMachine();
|
---|
557 |
|
---|
558 | // Note: the below methods are intended to be called only after adding
|
---|
559 | // a caller to the Machine instance and, when necessary, from under
|
---|
560 | // the Machine lock in appropriate mode
|
---|
561 |
|
---|
562 | /// @todo (dmik) revise code using these methods: improving incapsulation
|
---|
563 | // should make them not necessary
|
---|
564 |
|
---|
565 | const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() { return mParent; }
|
---|
566 |
|
---|
567 | const Shareable <Data> &data() const { return mData; }
|
---|
568 | const Backupable <UserData> &userData() const { return mUserData; }
|
---|
569 | const Backupable <HDData> &hdData() const { return mHDData; }
|
---|
570 |
|
---|
571 | const Shareable <SSData> &ssData() const { return mSSData; }
|
---|
572 |
|
---|
573 | const ComObjPtr <DVDDrive> &dvdDrive() { return mDVDDrive; }
|
---|
574 | const ComObjPtr <FloppyDrive> &floppyDrive() { return mFloppyDrive; }
|
---|
575 | const ComObjPtr <USBController> &usbController() { return mUSBController; }
|
---|
576 |
|
---|
577 | virtual HRESULT onDVDDriveChange() { return S_OK; }
|
---|
578 | virtual HRESULT onFloppyDriveChange() { return S_OK; }
|
---|
579 | virtual HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter) { return S_OK; }
|
---|
580 | virtual HRESULT onVRDPServerChange() { return S_OK; }
|
---|
581 | virtual HRESULT onUSBControllerChange() { return S_OK; }
|
---|
582 |
|
---|
583 | int calculateFullPath (const char *aPath, Utf8Str &aResult);
|
---|
584 | void calculateRelativePath (const char *aPath, Utf8Str &aResult);
|
---|
585 |
|
---|
586 | void getLogFolder (Utf8Str &aLogFolder);
|
---|
587 |
|
---|
588 | HRESULT openSession (IInternalSessionControl *aControl);
|
---|
589 | HRESULT openRemoteSession (IInternalSessionControl *aControl,
|
---|
590 | INPTR BSTR aType, Progress *aProgress);
|
---|
591 | HRESULT openExistingSession (IInternalSessionControl *aControl);
|
---|
592 |
|
---|
593 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
594 |
|
---|
595 | HRESULT getSharedFolder (const BSTR aName,
|
---|
596 | ComObjPtr <SharedFolder> &aSharedFolder,
|
---|
597 | bool aSetError = false)
|
---|
598 | {
|
---|
599 | AutoLock alock (this);
|
---|
600 | return findSharedFolder (aName, aSharedFolder, aSetError);
|
---|
601 | }
|
---|
602 |
|
---|
603 | HRESULT addStateDependency (StateDependency aDepType = AnyStateDep,
|
---|
604 | MachineState_T *aState = NULL,
|
---|
605 | BOOL *aRegistered = NULL);
|
---|
606 | void releaseStateDependency();
|
---|
607 |
|
---|
608 | // for VirtualBoxSupportErrorInfoImpl
|
---|
609 | static const wchar_t *getComponentName() { return L"Machine"; }
|
---|
610 |
|
---|
611 | protected:
|
---|
612 |
|
---|
613 | enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
|
---|
614 |
|
---|
615 | HRESULT registeredInit();
|
---|
616 |
|
---|
617 | inline Machine *machine();
|
---|
618 |
|
---|
619 | void uninitDataAndChildObjects();
|
---|
620 |
|
---|
621 | void checkStateDependencies (AutoLock &aLock);
|
---|
622 |
|
---|
623 | virtual HRESULT setMachineState (MachineState_T aMachineState);
|
---|
624 |
|
---|
625 | HRESULT findSharedFolder (const BSTR aName,
|
---|
626 | ComObjPtr <SharedFolder> &aSharedFolder,
|
---|
627 | bool aSetError = false);
|
---|
628 |
|
---|
629 | HRESULT loadSettings (bool aRegistered);
|
---|
630 | HRESULT loadSnapshot (CFGNODE aNode, const Guid &aCurSnapshotId,
|
---|
631 | Snapshot *aParentSnapshot);
|
---|
632 | HRESULT loadHardware (CFGNODE aNode);
|
---|
633 | HRESULT loadHardDisks (CFGNODE aNode, bool aRegistered,
|
---|
634 | const Guid *aSnapshotId = NULL);
|
---|
635 |
|
---|
636 | HRESULT openConfigLoader (CFGHANDLE *aLoader, bool aIsNew = false);
|
---|
637 | HRESULT closeConfigLoader (CFGHANDLE aLoader, bool aSaveBeforeClose);
|
---|
638 |
|
---|
639 | HRESULT findSnapshotNode (Snapshot *aSnapshot, CFGNODE aMachineNode,
|
---|
640 | CFGNODE *aSnapshotsNode, CFGNODE *aSnapshotNode);
|
---|
641 |
|
---|
642 | HRESULT findSnapshot (const Guid &aId, ComObjPtr <Snapshot> &aSnapshot,
|
---|
643 | bool aSetError = false);
|
---|
644 | HRESULT findSnapshot (const BSTR aName, ComObjPtr <Snapshot> &aSnapshot,
|
---|
645 | bool aSetError = false);
|
---|
646 |
|
---|
647 | HRESULT findHardDiskAttachment (const ComObjPtr <HardDisk> &aHd,
|
---|
648 | ComObjPtr <Machine> *aMachine,
|
---|
649 | ComObjPtr <Snapshot> *aSnapshot,
|
---|
650 | ComObjPtr <HardDiskAttachment> *aHda);
|
---|
651 |
|
---|
652 | HRESULT prepareSaveSettings (bool &aRenamed, bool &aNew);
|
---|
653 | HRESULT saveSettings (bool aMarkCurStateAsModified = true,
|
---|
654 | bool aInformCallbacksAnyway = false);
|
---|
655 |
|
---|
656 | enum
|
---|
657 | {
|
---|
658 | // ops for #saveSnapshotSettings()
|
---|
659 | SaveSS_NoOp = 0x00, SaveSS_AddOp = 0x01,
|
---|
660 | SaveSS_UpdateAttrsOp = 0x02, SaveSS_UpdateAllOp = 0x03,
|
---|
661 | SaveSS_OpMask = 0xF,
|
---|
662 | // flags for #saveSnapshotSettings()
|
---|
663 | SaveSS_UpdateCurStateModified = 0x40,
|
---|
664 | SaveSS_UpdateCurrentId = 0x80,
|
---|
665 | // flags for #saveStateSettings()
|
---|
666 | SaveSTS_CurStateModified = 0x20,
|
---|
667 | SaveSTS_StateFilePath = 0x40,
|
---|
668 | SaveSTS_StateTimeStamp = 0x80,
|
---|
669 | };
|
---|
670 |
|
---|
671 | HRESULT saveSnapshotSettings (Snapshot *aSnapshot, int aOpFlags);
|
---|
672 | HRESULT saveSnapshotSettingsWorker (CFGNODE aMachineNode,
|
---|
673 | Snapshot *aSnapshot, int aOpFlags);
|
---|
674 |
|
---|
675 | HRESULT saveSnapshot (CFGNODE aNode, Snapshot *aSnapshot, bool aAttrsOnly);
|
---|
676 | HRESULT saveHardware (CFGNODE aNode);
|
---|
677 | HRESULT saveHardDisks (CFGNODE aNode);
|
---|
678 |
|
---|
679 | HRESULT saveStateSettings (int aFlags);
|
---|
680 |
|
---|
681 | HRESULT wipeOutImmutableDiffs();
|
---|
682 |
|
---|
683 | HRESULT fixupHardDisks (bool aCommit);
|
---|
684 |
|
---|
685 | HRESULT createSnapshotDiffs (const Guid *aSnapshotId,
|
---|
686 | const Bstr &aFolder,
|
---|
687 | const ComObjPtr <Progress> &aProgress,
|
---|
688 | bool aOnline);
|
---|
689 | HRESULT deleteSnapshotDiffs (const ComObjPtr <Snapshot> &aSnapshot);
|
---|
690 |
|
---|
691 | HRESULT lockConfig();
|
---|
692 | HRESULT unlockConfig();
|
---|
693 |
|
---|
694 | /** @note This method is not thread safe */
|
---|
695 | BOOL isConfigLocked()
|
---|
696 | {
|
---|
697 | return !!mData && mData->mHandleCfgFile != NIL_RTFILE;
|
---|
698 | }
|
---|
699 |
|
---|
700 | bool isInOwnDir (Utf8Str *aSettingsDir = NULL);
|
---|
701 |
|
---|
702 | bool isModified();
|
---|
703 | bool isReallyModified (bool aIgnoreUserData = false);
|
---|
704 | void rollback (bool aNotify);
|
---|
705 | HRESULT commit();
|
---|
706 | void copyFrom (Machine *aThat);
|
---|
707 |
|
---|
708 | const InstanceType mType;
|
---|
709 |
|
---|
710 | const ComObjPtr <Machine, ComWeakRef> mPeer;
|
---|
711 |
|
---|
712 | const ComObjPtr <VirtualBox, ComWeakRef> mParent;
|
---|
713 |
|
---|
714 | Shareable <Data> mData;
|
---|
715 | Shareable <SSData> mSSData;
|
---|
716 |
|
---|
717 | Backupable <UserData> mUserData;
|
---|
718 | Backupable <HWData> mHWData;
|
---|
719 | Backupable <HDData> mHDData;
|
---|
720 |
|
---|
721 | // the following fields need special backup/rollback/commit handling,
|
---|
722 | // so they cannot be a part of HWData
|
---|
723 |
|
---|
724 | const ComObjPtr <VRDPServer> mVRDPServer;
|
---|
725 | const ComObjPtr <DVDDrive> mDVDDrive;
|
---|
726 | const ComObjPtr <FloppyDrive> mFloppyDrive;
|
---|
727 | const ComObjPtr <AudioAdapter> mAudioAdapter;
|
---|
728 | const ComObjPtr <USBController> mUSBController;
|
---|
729 | const ComObjPtr <BIOSSettings> mBIOSSettings;
|
---|
730 |
|
---|
731 | const ComObjPtr <NetworkAdapter>
|
---|
732 | mNetworkAdapters [SchemaDefs::NetworkAdapterCount];
|
---|
733 |
|
---|
734 | friend class SessionMachine;
|
---|
735 | friend class SnapshotMachine;
|
---|
736 | };
|
---|
737 |
|
---|
738 | // SessionMachine class
|
---|
739 | ////////////////////////////////////////////////////////////////////////////////
|
---|
740 |
|
---|
741 | /**
|
---|
742 | * @note Notes on locking objects of this class:
|
---|
743 | * SessionMachine shares some data with the primary Machine instance (pointed
|
---|
744 | * to by the |mPeer| member). In order to provide data consistency it also
|
---|
745 | * shares its lock handle. This means that whenever you lock a SessionMachine
|
---|
746 | * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
|
---|
747 | * instance is also locked in the same lock mode. Keep it in mind.
|
---|
748 | */
|
---|
749 | class ATL_NO_VTABLE SessionMachine :
|
---|
750 | public VirtualBoxSupportTranslation <SessionMachine>,
|
---|
751 | public Machine,
|
---|
752 | public IInternalMachineControl
|
---|
753 | {
|
---|
754 | public:
|
---|
755 |
|
---|
756 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
|
---|
757 |
|
---|
758 | DECLARE_NOT_AGGREGATABLE(SessionMachine)
|
---|
759 |
|
---|
760 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
761 |
|
---|
762 | BEGIN_COM_MAP(SessionMachine)
|
---|
763 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
764 | COM_INTERFACE_ENTRY(IMachine)
|
---|
765 | COM_INTERFACE_ENTRY(IInternalMachineControl)
|
---|
766 | END_COM_MAP()
|
---|
767 |
|
---|
768 | NS_DECL_ISUPPORTS
|
---|
769 |
|
---|
770 | DECLARE_EMPTY_CTOR_DTOR (SessionMachine)
|
---|
771 |
|
---|
772 | HRESULT FinalConstruct();
|
---|
773 | void FinalRelease();
|
---|
774 |
|
---|
775 | // public initializer/uninitializer for internal purposes only
|
---|
776 | HRESULT init (Machine *aMachine);
|
---|
777 | void uninit() { uninit (Uninit::Unexpected); }
|
---|
778 |
|
---|
779 | // AutoLock::Lockable interface
|
---|
780 | AutoLock::Handle *lockHandle() const;
|
---|
781 |
|
---|
782 | // IInternalMachineControl methods
|
---|
783 | STDMETHOD(UpdateState)(MachineState_T machineState);
|
---|
784 | STDMETHOD(GetIPCId)(BSTR *id);
|
---|
785 | STDMETHOD(RunUSBDeviceFilters) (IUSBDevice *aUSBDevice, BOOL *aMatched);
|
---|
786 | STDMETHOD(CaptureUSBDevice) (INPTR GUIDPARAM aId);
|
---|
787 | STDMETHOD(ReleaseUSBDevice) (INPTR GUIDPARAM aId);
|
---|
788 | STDMETHOD(AutoCaptureUSBDevices)();
|
---|
789 | STDMETHOD(ReleaseAllUSBDevices)();
|
---|
790 | STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
|
---|
791 | STDMETHOD(BeginSavingState) (IProgress *aProgress, BSTR *aStateFilePath);
|
---|
792 | STDMETHOD(EndSavingState) (BOOL aSuccess);
|
---|
793 | STDMETHOD(BeginTakingSnapshot) (IConsole *aInitiator,
|
---|
794 | INPTR BSTR aName, INPTR BSTR aDescription,
|
---|
795 | IProgress *aProgress, BSTR *aStateFilePath,
|
---|
796 | IProgress **aServerProgress);
|
---|
797 | STDMETHOD(EndTakingSnapshot) (BOOL aSuccess);
|
---|
798 | STDMETHOD(DiscardSnapshot) (IConsole *aInitiator, INPTR GUIDPARAM aId,
|
---|
799 | MachineState_T *aMachineState, IProgress **aProgress);
|
---|
800 | STDMETHOD(DiscardCurrentState) (
|
---|
801 | IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
|
---|
802 | STDMETHOD(DiscardCurrentSnapshotAndState) (
|
---|
803 | IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
|
---|
804 |
|
---|
805 | // public methods only for internal purposes
|
---|
806 |
|
---|
807 | bool checkForDeath();
|
---|
808 | #ifdef __WIN__
|
---|
809 | HANDLE ipcSem() { return mIPCSem; }
|
---|
810 | #endif
|
---|
811 |
|
---|
812 | HRESULT onDVDDriveChange();
|
---|
813 | HRESULT onFloppyDriveChange();
|
---|
814 | HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
|
---|
815 | HRESULT onVRDPServerChange();
|
---|
816 | HRESULT onUSBControllerChange();
|
---|
817 | HRESULT onUSBDeviceAttach (IUSBDevice *aDevice,
|
---|
818 | IVirtualBoxErrorInfo *aError);
|
---|
819 | HRESULT onUSBDeviceDetach (INPTR GUIDPARAM aId,
|
---|
820 | IVirtualBoxErrorInfo *aError);
|
---|
821 |
|
---|
822 | private:
|
---|
823 |
|
---|
824 | struct SnapshotData
|
---|
825 | {
|
---|
826 | SnapshotData() : mLastState (MachineState_InvalidMachineState) {}
|
---|
827 |
|
---|
828 | MachineState_T mLastState;
|
---|
829 |
|
---|
830 | // used when taking snapshot
|
---|
831 | ComObjPtr <Snapshot> mSnapshot;
|
---|
832 | ComObjPtr <Progress> mServerProgress;
|
---|
833 | ComObjPtr <CombinedProgress> mCombinedProgress;
|
---|
834 |
|
---|
835 | // used when saving state
|
---|
836 | Guid mProgressId;
|
---|
837 | Bstr mStateFilePath;
|
---|
838 | };
|
---|
839 |
|
---|
840 | struct Uninit {
|
---|
841 | enum Reason { Unexpected, Abnormal, Normal };
|
---|
842 | };
|
---|
843 |
|
---|
844 | struct Task;
|
---|
845 | struct TakeSnapshotTask;
|
---|
846 | struct DiscardSnapshotTask;
|
---|
847 | struct DiscardCurrentStateTask;
|
---|
848 |
|
---|
849 | friend struct TakeSnapshotTask;
|
---|
850 | friend struct DiscardSnapshotTask;
|
---|
851 | friend struct DiscardCurrentStateTask;
|
---|
852 |
|
---|
853 | void uninit (Uninit::Reason aReason);
|
---|
854 |
|
---|
855 | HRESULT endSavingState (BOOL aSuccess);
|
---|
856 | HRESULT endTakingSnapshot (BOOL aSuccess);
|
---|
857 |
|
---|
858 | typedef std::map <ComObjPtr <Machine>, MachineState_T> AffectedMachines;
|
---|
859 |
|
---|
860 | void takeSnapshotHandler (TakeSnapshotTask &aTask);
|
---|
861 | void discardSnapshotHandler (DiscardSnapshotTask &aTask);
|
---|
862 | void discardCurrentStateHandler (DiscardCurrentStateTask &aTask);
|
---|
863 |
|
---|
864 | HRESULT setMachineState (MachineState_T aMachineState);
|
---|
865 | HRESULT updateMachineStateOnClient();
|
---|
866 |
|
---|
867 | SnapshotData mSnapshotData;
|
---|
868 |
|
---|
869 | /** interprocess semaphore handle (id) for this machine */
|
---|
870 | #if defined(__WIN__)
|
---|
871 | HANDLE mIPCSem;
|
---|
872 | Bstr mIPCSemName;
|
---|
873 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
874 | int mIPCSem;
|
---|
875 | #endif
|
---|
876 |
|
---|
877 | static DECLCALLBACK(int) taskHandler (RTTHREAD thread, void *pvUser);
|
---|
878 | };
|
---|
879 |
|
---|
880 | // SnapshotMachine class
|
---|
881 | ////////////////////////////////////////////////////////////////////////////////
|
---|
882 |
|
---|
883 | /**
|
---|
884 | * @note Notes on locking objects of this class:
|
---|
885 | * SnapshotMachine shares some data with the primary Machine instance (pointed
|
---|
886 | * to by the |mPeer| member). In order to provide data consistency it also
|
---|
887 | * shares its lock handle. This means that whenever you lock a SessionMachine
|
---|
888 | * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
|
---|
889 | * instance is also locked in the same lock mode. Keep it in mind.
|
---|
890 | */
|
---|
891 | class ATL_NO_VTABLE SnapshotMachine :
|
---|
892 | public VirtualBoxSupportTranslation <SnapshotMachine>,
|
---|
893 | public Machine
|
---|
894 | {
|
---|
895 | public:
|
---|
896 |
|
---|
897 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
|
---|
898 |
|
---|
899 | DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
|
---|
900 |
|
---|
901 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
902 |
|
---|
903 | BEGIN_COM_MAP(SnapshotMachine)
|
---|
904 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
905 | COM_INTERFACE_ENTRY(IMachine)
|
---|
906 | END_COM_MAP()
|
---|
907 |
|
---|
908 | NS_DECL_ISUPPORTS
|
---|
909 |
|
---|
910 | DECLARE_EMPTY_CTOR_DTOR (SnapshotMachine)
|
---|
911 |
|
---|
912 | HRESULT FinalConstruct();
|
---|
913 | void FinalRelease();
|
---|
914 |
|
---|
915 | // public initializer/uninitializer for internal purposes only
|
---|
916 | HRESULT init (SessionMachine *aSessionMachine,
|
---|
917 | INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
|
---|
918 | HRESULT init (Machine *aMachine, CFGNODE aHWNode, CFGNODE aHDAsNode,
|
---|
919 | INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
|
---|
920 | void uninit();
|
---|
921 |
|
---|
922 | // AutoLock::Lockable interface
|
---|
923 | AutoLock::Handle *lockHandle() const;
|
---|
924 |
|
---|
925 | // public methods only for internal purposes
|
---|
926 |
|
---|
927 | HRESULT onSnapshotChange (Snapshot *aSnapshot);
|
---|
928 |
|
---|
929 | private:
|
---|
930 |
|
---|
931 | Guid mSnapshotId;
|
---|
932 | };
|
---|
933 |
|
---|
934 | ////////////////////////////////////////////////////////////////////////////////
|
---|
935 |
|
---|
936 | /**
|
---|
937 | * Returns a pointer to the Machine object for this machine that acts like a
|
---|
938 | * parent for complex machine data objects such as shared folders, etc.
|
---|
939 | *
|
---|
940 | * For primary Machine objects and for SnapshotMachine objects, returns this
|
---|
941 | * object's pointer itself. For SessoinMachine objects, returns the peer
|
---|
942 | * (primary) machine pointer.
|
---|
943 | */
|
---|
944 | inline Machine *Machine::machine()
|
---|
945 | {
|
---|
946 | if (mType == IsSessionMachine)
|
---|
947 | return mPeer;
|
---|
948 | return this;
|
---|
949 | }
|
---|
950 |
|
---|
951 | COM_DECL_READONLY_ENUM_AND_COLLECTION (Machine)
|
---|
952 |
|
---|
953 | #endif // ____H_MACHINEIMPL
|
---|