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