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