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