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