1 | /* $Id: VirtualBoxImpl.h 12284 2008-09-09 10:26:27Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef ____H_VIRTUALBOXIMPL
|
---|
25 | #define ____H_VIRTUALBOXIMPL
|
---|
26 |
|
---|
27 | #include "VirtualBoxBase.h"
|
---|
28 |
|
---|
29 | #include "VBox/com/EventQueue.h"
|
---|
30 |
|
---|
31 | #include <list>
|
---|
32 | #include <vector>
|
---|
33 | #include <map>
|
---|
34 |
|
---|
35 | #ifdef RT_OS_WINDOWS
|
---|
36 | # include "win/resource.h"
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
40 | #include "PerformanceImpl.h"
|
---|
41 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
42 |
|
---|
43 |
|
---|
44 | class Machine;
|
---|
45 | class SessionMachine;
|
---|
46 | class HardDisk;
|
---|
47 | class HVirtualDiskImage;
|
---|
48 | class DVDImage;
|
---|
49 | class FloppyImage;
|
---|
50 | class MachineCollection;
|
---|
51 | class HardDiskCollection;
|
---|
52 | class DVDImageCollection;
|
---|
53 | class FloppyImageCollection;
|
---|
54 | class GuestOSType;
|
---|
55 | class GuestOSTypeCollection;
|
---|
56 | class SharedFolder;
|
---|
57 | class Progress;
|
---|
58 | class ProgressCollection;
|
---|
59 | class Host;
|
---|
60 | class SystemProperties;
|
---|
61 |
|
---|
62 | #ifdef RT_OS_WINDOWS
|
---|
63 | class SVCHlpClient;
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | struct VMClientWatcherData;
|
---|
67 |
|
---|
68 | class ATL_NO_VTABLE VirtualBox :
|
---|
69 | public VirtualBoxBaseWithChildrenNEXT,
|
---|
70 | public VirtualBoxSupportErrorInfoImpl <VirtualBox, IVirtualBox>,
|
---|
71 | public VirtualBoxSupportTranslation <VirtualBox>,
|
---|
72 | #ifdef RT_OS_WINDOWS
|
---|
73 | public IDispatchImpl<IVirtualBox, &IID_IVirtualBox, &LIBID_VirtualBox,
|
---|
74 | kTypeLibraryMajorVersion, kTypeLibraryMinorVersion>,
|
---|
75 | public CComCoClass<VirtualBox, &CLSID_VirtualBox>
|
---|
76 | #else
|
---|
77 | public IVirtualBox
|
---|
78 | #endif
|
---|
79 | {
|
---|
80 |
|
---|
81 | public:
|
---|
82 |
|
---|
83 | typedef std::list <ComPtr <IVirtualBoxCallback> > CallbackList;
|
---|
84 | typedef std::vector <ComPtr <IVirtualBoxCallback> > CallbackVector;
|
---|
85 |
|
---|
86 | class CallbackEvent;
|
---|
87 | friend class CallbackEvent;
|
---|
88 |
|
---|
89 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualBox)
|
---|
90 |
|
---|
91 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
|
---|
92 |
|
---|
93 | DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
94 | DECLARE_NOT_AGGREGATABLE(VirtualBox)
|
---|
95 |
|
---|
96 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
97 |
|
---|
98 | BEGIN_COM_MAP(VirtualBox)
|
---|
99 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
100 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
101 | COM_INTERFACE_ENTRY(IVirtualBox)
|
---|
102 | END_COM_MAP()
|
---|
103 |
|
---|
104 | NS_DECL_ISUPPORTS
|
---|
105 |
|
---|
106 | /* to postpone generation of the default ctor/dtor */
|
---|
107 | VirtualBox();
|
---|
108 | ~VirtualBox();
|
---|
109 |
|
---|
110 | HRESULT FinalConstruct();
|
---|
111 | void FinalRelease();
|
---|
112 |
|
---|
113 | /* public initializer/uninitializer for internal purposes only */
|
---|
114 | HRESULT init();
|
---|
115 | void uninit();
|
---|
116 |
|
---|
117 | /* IVirtualBox properties */
|
---|
118 | STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
|
---|
119 | STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
|
---|
120 | STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
|
---|
121 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
122 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
123 | STDMETHOD(COMGETTER(SettingsFileVersion)) (BSTR *aSettingsFileVersion);
|
---|
124 | STDMETHOD(COMGETTER(SettingsFormatVersion)) (BSTR *aSettingsFormatVersion);
|
---|
125 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
126 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
127 | STDMETHOD(COMGETTER(Machines)) (IMachineCollection **aMachines);
|
---|
128 | STDMETHOD(COMGETTER(Machines2)) (ComSafeArrayOut (IMachine *, aMachines));
|
---|
129 | STDMETHOD(COMGETTER(HardDisks)) (IHardDiskCollection **aHardDisks);
|
---|
130 | STDMETHOD(COMGETTER(DVDImages)) (IDVDImageCollection **aDVDImages);
|
---|
131 | STDMETHOD(COMGETTER(FloppyImages)) (IFloppyImageCollection **aFloppyImages);
|
---|
132 | STDMETHOD(COMGETTER(ProgressOperations)) (IProgressCollection **aOperations);
|
---|
133 | STDMETHOD(COMGETTER(GuestOSTypes)) (IGuestOSTypeCollection **aGuestOSTypes);
|
---|
134 | STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
|
---|
135 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
136 |
|
---|
137 | /* IVirtualBox methods */
|
---|
138 |
|
---|
139 | STDMETHOD(CreateMachine) (INPTR BSTR aBaseFolder, INPTR BSTR aName,
|
---|
140 | INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
141 | STDMETHOD(CreateLegacyMachine) (INPTR BSTR aSettingsFile, INPTR BSTR aName,
|
---|
142 | INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
143 | STDMETHOD(OpenMachine) (INPTR BSTR aSettingsFile, IMachine **aMachine);
|
---|
144 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
145 | STDMETHOD(GetMachine) (INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
146 | STDMETHOD(FindMachine) (INPTR BSTR aName, IMachine **aMachine);
|
---|
147 | STDMETHOD(UnregisterMachine) (INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
148 |
|
---|
149 | STDMETHOD(CreateHardDisk) (HardDiskStorageType_T aStorageType, IHardDisk **aHardDisk);
|
---|
150 | STDMETHOD(OpenHardDisk) (INPTR BSTR aLocation, IHardDisk **aHardDisk);
|
---|
151 | STDMETHOD(OpenVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
|
---|
152 | STDMETHOD(RegisterHardDisk) (IHardDisk *aHardDisk);
|
---|
153 | STDMETHOD(GetHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
|
---|
154 | STDMETHOD(FindHardDisk) (INPTR BSTR aLocation, IHardDisk **aHardDisk);
|
---|
155 | STDMETHOD(FindVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
|
---|
156 | STDMETHOD(UnregisterHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
|
---|
157 |
|
---|
158 | STDMETHOD(OpenDVDImage) (INPTR BSTR aFilePath, INPTR GUIDPARAM aId,
|
---|
159 | IDVDImage **aDVDImage);
|
---|
160 | STDMETHOD(RegisterDVDImage) (IDVDImage *aDVDImage);
|
---|
161 | STDMETHOD(GetDVDImage) (INPTR GUIDPARAM aId, IDVDImage **aDVDImage);
|
---|
162 | STDMETHOD(FindDVDImage) (INPTR BSTR aFilePath, IDVDImage **aDVDImage);
|
---|
163 | STDMETHOD(GetDVDImageUsage) (INPTR GUIDPARAM aId,
|
---|
164 | ResourceUsage_T aUsage,
|
---|
165 | BSTR *aMachineIDs);
|
---|
166 | STDMETHOD(UnregisterDVDImage) (INPTR GUIDPARAM aId, IDVDImage **aDVDImage);
|
---|
167 |
|
---|
168 | STDMETHOD(OpenFloppyImage) (INPTR BSTR aFilePath, INPTR GUIDPARAM aId,
|
---|
169 | IFloppyImage **aFloppyImage);
|
---|
170 | STDMETHOD(RegisterFloppyImage) (IFloppyImage *aFloppyImage);
|
---|
171 | STDMETHOD(GetFloppyImage) (INPTR GUIDPARAM id, IFloppyImage **aFloppyImage);
|
---|
172 | STDMETHOD(FindFloppyImage) (INPTR BSTR aFilePath, IFloppyImage **aFloppyImage);
|
---|
173 | STDMETHOD(GetFloppyImageUsage) (INPTR GUIDPARAM aId,
|
---|
174 | ResourceUsage_T aUsage,
|
---|
175 | BSTR *aMachineIDs);
|
---|
176 | STDMETHOD(UnregisterFloppyImage) (INPTR GUIDPARAM aId, IFloppyImage **aFloppyImage);
|
---|
177 |
|
---|
178 | STDMETHOD(GetGuestOSType) (INPTR BSTR aId, IGuestOSType **aType);
|
---|
179 | STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable);
|
---|
180 | STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
|
---|
181 | STDMETHOD(GetNextExtraDataKey) (INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
|
---|
182 | STDMETHOD(GetExtraData) (INPTR BSTR aKey, BSTR *aValue);
|
---|
183 | STDMETHOD(SetExtraData) (INPTR BSTR aKey, INPTR BSTR aValue);
|
---|
184 | STDMETHOD(OpenSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
|
---|
185 | STDMETHOD(OpenRemoteSession) (ISession *aSession, INPTR GUIDPARAM aMachineId,
|
---|
186 | INPTR BSTR aType, INPTR BSTR aEnvironment,
|
---|
187 | IProgress **aProgress);
|
---|
188 | STDMETHOD(OpenExistingSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
|
---|
189 |
|
---|
190 | STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
191 | STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
192 |
|
---|
193 | STDMETHOD(WaitForPropertyChange) (INPTR BSTR aWhat, ULONG aTimeout,
|
---|
194 | BSTR *aChanged, BSTR *aValues);
|
---|
195 |
|
---|
196 | STDMETHOD(SaveSettings)();
|
---|
197 | STDMETHOD(SaveSettingsWithBackup) (BSTR *aBakFileName);
|
---|
198 |
|
---|
199 | /* public methods only for internal purposes */
|
---|
200 |
|
---|
201 | HRESULT postEvent (Event *event);
|
---|
202 |
|
---|
203 | HRESULT addProgress (IProgress *aProgress);
|
---|
204 | HRESULT removeProgress (INPTR GUIDPARAM aId);
|
---|
205 |
|
---|
206 | #ifdef RT_OS_WINDOWS
|
---|
207 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
208 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
209 | HRESULT startSVCHelperClient (bool aPrivileged,
|
---|
210 | SVCHelperClientFunc aFunc,
|
---|
211 | void *aUser, Progress *aProgress);
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | void addProcessToReap (RTPROCESS pid);
|
---|
215 | void updateClientWatcher();
|
---|
216 |
|
---|
217 | void onMachineStateChange (const Guid &aId, MachineState_T aState);
|
---|
218 | void onMachineDataChange (const Guid &aId);
|
---|
219 | BOOL onExtraDataCanChange(const Guid &aId, INPTR BSTR aKey, INPTR BSTR aValue,
|
---|
220 | Bstr &aError);
|
---|
221 | void onExtraDataChange(const Guid &aId, INPTR BSTR aKey, INPTR BSTR aValue);
|
---|
222 | void onMachineRegistered (const Guid &aId, BOOL aRegistered);
|
---|
223 | void onSessionStateChange (const Guid &aId, SessionState_T aState);
|
---|
224 |
|
---|
225 | void onSnapshotTaken (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
226 | void onSnapshotDiscarded (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
227 | void onSnapshotChange (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
228 |
|
---|
229 | ComObjPtr <GuestOSType> getUnknownOSType();
|
---|
230 |
|
---|
231 | typedef std::vector <ComObjPtr <SessionMachine> > SessionMachineVector;
|
---|
232 | void getOpenedMachines (SessionMachineVector &aVector);
|
---|
233 |
|
---|
234 | bool isMachineIdValid (const Guid &aId)
|
---|
235 | {
|
---|
236 | return SUCCEEDED (findMachine (aId, false /* aSetError */, NULL));
|
---|
237 | }
|
---|
238 |
|
---|
239 | /// @todo (dmik) remove and make findMachine() public instead
|
---|
240 | // after switching to VirtualBoxBaseNEXT
|
---|
241 | HRESULT getMachine (const Guid &aId, ComObjPtr <Machine> &aMachine,
|
---|
242 | bool aSetError = false)
|
---|
243 | {
|
---|
244 | return findMachine (aId, aSetError, &aMachine);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /// @todo (dmik) remove and make findHardDisk() public instead
|
---|
248 | // after switching to VirtualBoxBaseNEXT
|
---|
249 | HRESULT getHardDisk (const Guid &aId, ComObjPtr <HardDisk> &aHardDisk)
|
---|
250 | {
|
---|
251 | return findHardDisk (&aId, NULL, true /* aDoSetError */, &aHardDisk);
|
---|
252 | }
|
---|
253 |
|
---|
254 | bool getDVDImageUsage (const Guid &aId, ResourceUsage_T aUsage,
|
---|
255 | Bstr *aMachineIDs = NULL);
|
---|
256 | bool getFloppyImageUsage (const Guid &aId, ResourceUsage_T aUsage,
|
---|
257 | Bstr *aMachineIDs = NULL);
|
---|
258 |
|
---|
259 | const ComObjPtr <Host> &host() { return mData.mHost; }
|
---|
260 | const ComObjPtr <SystemProperties> &systemProperties()
|
---|
261 | { return mData.mSystemProperties; }
|
---|
262 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
263 | const ComObjPtr <PerformanceCollector> &performanceCollector()
|
---|
264 | { return mData.mPerformanceCollector; }
|
---|
265 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
266 |
|
---|
267 |
|
---|
268 | /** Returns the VirtualBox home directory */
|
---|
269 | const Utf8Str &homeDir() { return mData.mHomeDir; }
|
---|
270 |
|
---|
271 | void calculateRelativePath (const char *aPath, Utf8Str &aResult);
|
---|
272 |
|
---|
273 | enum RHD_Flags { RHD_Internal, RHD_External, RHD_OnStartUp };
|
---|
274 | HRESULT registerHardDisk (HardDisk *aHardDisk, RHD_Flags aFlags);
|
---|
275 | HRESULT unregisterHardDisk (HardDisk *aHardDisk);
|
---|
276 | HRESULT unregisterDiffHardDisk (HardDisk *aHardDisk);
|
---|
277 |
|
---|
278 | HRESULT saveSettings();
|
---|
279 | HRESULT updateSettings (const char *aOldPath, const char *aNewPath);
|
---|
280 |
|
---|
281 | const Bstr &settingsFileName() { return mData.mCfgFile.mName; }
|
---|
282 |
|
---|
283 | class SettingsTreeHelper : public settings::XmlTreeBackend::InputResolver
|
---|
284 | , public settings::XmlTreeBackend::AutoConverter
|
---|
285 | {
|
---|
286 | public:
|
---|
287 |
|
---|
288 | // InputResolver interface
|
---|
289 | settings::Input *resolveEntity (const char *aURI, const char *aID);
|
---|
290 |
|
---|
291 | // AutoConverter interface
|
---|
292 | bool needsConversion (const settings::Key &aRoot, char **aOldVersion) const;
|
---|
293 | const char *templateUri() const;
|
---|
294 | };
|
---|
295 |
|
---|
296 | static HRESULT loadSettingsTree (settings::XmlTreeBackend &aTree,
|
---|
297 | settings::File &aFile,
|
---|
298 | bool aValidate,
|
---|
299 | bool aCatchLoadErrors,
|
---|
300 | bool aAddDefaults,
|
---|
301 | Utf8Str *aFormatVersion = NULL);
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Shortcut to loadSettingsTree (aTree, aFile, true, true, true).
|
---|
305 | *
|
---|
306 | * Used when the settings file is to be loaded for the first time for the
|
---|
307 | * given object in order to recreate it from the stored settings.
|
---|
308 | *
|
---|
309 | * @param aFormatVersion Where to store the current format version of the
|
---|
310 | * loaded settings tree.
|
---|
311 | */
|
---|
312 | static HRESULT loadSettingsTree_FirstTime (settings::XmlTreeBackend &aTree,
|
---|
313 | settings::File &aFile,
|
---|
314 | Utf8Str &aFormatVersion)
|
---|
315 | {
|
---|
316 | return loadSettingsTree (aTree, aFile, true, true, true,
|
---|
317 | &aFormatVersion);
|
---|
318 | }
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, true).
|
---|
322 | *
|
---|
323 | * Used when the settings file is loaded again (after it has been fully
|
---|
324 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
325 | * look at settings that don't have any representation within object's
|
---|
326 | * data fields.
|
---|
327 | */
|
---|
328 | static HRESULT loadSettingsTree_Again (settings::XmlTreeBackend &aTree,
|
---|
329 | settings::File &aFile)
|
---|
330 | {
|
---|
331 | return loadSettingsTree (aTree, aFile, true, false, true);
|
---|
332 | }
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, false).
|
---|
336 | *
|
---|
337 | * Used when the settings file is loaded again (after it has been fully
|
---|
338 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
339 | * update some settings and then save them back.
|
---|
340 | */
|
---|
341 | static HRESULT loadSettingsTree_ForUpdate (settings::XmlTreeBackend &aTree,
|
---|
342 | settings::File &aFile)
|
---|
343 | {
|
---|
344 | return loadSettingsTree (aTree, aFile, true, false, false);
|
---|
345 | }
|
---|
346 |
|
---|
347 | static HRESULT saveSettingsTree (settings::TreeBackend &aTree,
|
---|
348 | settings::File &aFile,
|
---|
349 | Utf8Str &aFormatVersion);
|
---|
350 |
|
---|
351 | static HRESULT backupSettingsFile (const Bstr &aFileName,
|
---|
352 | const Utf8Str &aOldFormat,
|
---|
353 | Bstr &aBakFileName);
|
---|
354 |
|
---|
355 | static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
|
---|
356 |
|
---|
357 | /* for VirtualBoxSupportErrorInfoImpl */
|
---|
358 | static const wchar_t *getComponentName() { return L"VirtualBox"; }
|
---|
359 |
|
---|
360 | private:
|
---|
361 |
|
---|
362 | typedef std::list <ComObjPtr <Machine> > MachineList;
|
---|
363 | typedef std::list <ComObjPtr <GuestOSType> > GuestOSTypeList;
|
---|
364 | typedef std::list <ComPtr <IProgress> > ProgressList;
|
---|
365 |
|
---|
366 | typedef std::list <ComObjPtr <HardDisk> > HardDiskList;
|
---|
367 | typedef std::list <ComObjPtr <DVDImage> > DVDImageList;
|
---|
368 | typedef std::list <ComObjPtr <FloppyImage> > FloppyImageList;
|
---|
369 | typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
|
---|
370 |
|
---|
371 | typedef std::map <Guid, ComObjPtr <HardDisk> > HardDiskMap;
|
---|
372 |
|
---|
373 | HRESULT findMachine (const Guid &aId, bool aSetError,
|
---|
374 | ComObjPtr <Machine> *machine = NULL);
|
---|
375 |
|
---|
376 | HRESULT findHardDisk (const Guid *aId, const BSTR aLocation,
|
---|
377 | bool aSetError, ComObjPtr <HardDisk> *aHardDisk = NULL);
|
---|
378 |
|
---|
379 | HRESULT findVirtualDiskImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
380 | bool aSetError, ComObjPtr <HVirtualDiskImage> *aImage = NULL);
|
---|
381 | HRESULT findDVDImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
382 | bool aSetError, ComObjPtr <DVDImage> *aImage = NULL);
|
---|
383 | HRESULT findFloppyImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
384 | bool aSetError, ComObjPtr <FloppyImage> *aImage = NULL);
|
---|
385 |
|
---|
386 | HRESULT checkMediaForConflicts (HardDisk *aHardDisk,
|
---|
387 | const Guid *aId, const BSTR aFilePathFull);
|
---|
388 |
|
---|
389 | HRESULT loadMachines (const settings::Key &aGlobal);
|
---|
390 | HRESULT loadDisks (const settings::Key &aGlobal);
|
---|
391 | HRESULT loadHardDisks (const settings::Key &aNode);
|
---|
392 |
|
---|
393 | HRESULT saveHardDisks (settings::Key &aNode);
|
---|
394 |
|
---|
395 | HRESULT registerMachine (Machine *aMachine);
|
---|
396 |
|
---|
397 | HRESULT registerDVDImage (DVDImage *aImage, bool aOnStartUp);
|
---|
398 | HRESULT registerFloppyImage (FloppyImage *aImage, bool aOnStartUp);
|
---|
399 |
|
---|
400 | HRESULT lockConfig();
|
---|
401 | HRESULT unlockConfig();
|
---|
402 |
|
---|
403 | /** @note This method is not thread safe */
|
---|
404 | bool isConfigLocked() { return mData.mCfgFile.mHandle != NIL_RTFILE; }
|
---|
405 |
|
---|
406 | /**
|
---|
407 | * Main VirtualBox data structure.
|
---|
408 | * @note |const| members are persistent during lifetime so can be accessed
|
---|
409 | * without locking.
|
---|
410 | */
|
---|
411 | struct Data
|
---|
412 | {
|
---|
413 | Data();
|
---|
414 |
|
---|
415 | struct CfgFile
|
---|
416 | {
|
---|
417 | CfgFile() : mHandle (NIL_RTFILE) {}
|
---|
418 |
|
---|
419 | const Bstr mName;
|
---|
420 | RTFILE mHandle;
|
---|
421 | };
|
---|
422 |
|
---|
423 | // const data members not requiring locking
|
---|
424 | const Utf8Str mHomeDir;
|
---|
425 |
|
---|
426 | // const objects not requiring locking
|
---|
427 | const ComObjPtr <Host> mHost;
|
---|
428 | const ComObjPtr <SystemProperties> mSystemProperties;
|
---|
429 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
430 | const ComObjPtr <PerformanceCollector> mPerformanceCollector;
|
---|
431 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
432 |
|
---|
433 | CfgFile mCfgFile;
|
---|
434 |
|
---|
435 | Utf8Str mSettingsFileVersion;
|
---|
436 |
|
---|
437 | MachineList mMachines;
|
---|
438 | GuestOSTypeList mGuestOSTypes;
|
---|
439 |
|
---|
440 | ProgressList mProgressOperations;
|
---|
441 | HardDiskList mHardDisks;
|
---|
442 | DVDImageList mDVDImages;
|
---|
443 | FloppyImageList mFloppyImages;
|
---|
444 | SharedFolderList mSharedFolders;
|
---|
445 |
|
---|
446 | HardDiskMap mHardDiskMap;
|
---|
447 |
|
---|
448 | CallbackList mCallbacks;
|
---|
449 | };
|
---|
450 |
|
---|
451 | Data mData;
|
---|
452 |
|
---|
453 | /** Client watcher thread data structure */
|
---|
454 | struct ClientWatcherData
|
---|
455 | {
|
---|
456 | ClientWatcherData()
|
---|
457 | #if defined(RT_OS_WINDOWS)
|
---|
458 | : mUpdateReq (NULL)
|
---|
459 | #elif defined(RT_OS_OS2)
|
---|
460 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
461 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
462 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
463 | #else
|
---|
464 | # error "Port me!"
|
---|
465 | #endif
|
---|
466 | , mThread (NIL_RTTHREAD) {}
|
---|
467 |
|
---|
468 | // const objects not requiring locking
|
---|
469 | #if defined(RT_OS_WINDOWS)
|
---|
470 | const HANDLE mUpdateReq;
|
---|
471 | #elif defined(RT_OS_OS2)
|
---|
472 | const RTSEMEVENT mUpdateReq;
|
---|
473 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
474 | const RTSEMEVENT mUpdateReq;
|
---|
475 | #else
|
---|
476 | # error "Port me!"
|
---|
477 | #endif
|
---|
478 | const RTTHREAD mThread;
|
---|
479 |
|
---|
480 | typedef std::list <RTPROCESS> ProcessList;
|
---|
481 | ProcessList mProcesses;
|
---|
482 | };
|
---|
483 |
|
---|
484 | ClientWatcherData mWatcherData;
|
---|
485 |
|
---|
486 | const RTTHREAD mAsyncEventThread;
|
---|
487 | EventQueue * const mAsyncEventQ;
|
---|
488 | /** Lock for calling EventQueue->post() */
|
---|
489 | RWLockHandle mAsyncEventQLock;
|
---|
490 |
|
---|
491 | static Bstr sVersion;
|
---|
492 | static ULONG sRevision;
|
---|
493 | static Bstr sPackageType;
|
---|
494 | static Bstr sSettingsFormatVersion;
|
---|
495 |
|
---|
496 | static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
|
---|
497 | static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
|
---|
498 |
|
---|
499 | #ifdef RT_OS_WINDOWS
|
---|
500 | static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
|
---|
501 | #endif
|
---|
502 | };
|
---|
503 |
|
---|
504 | ////////////////////////////////////////////////////////////////////////////////
|
---|
505 |
|
---|
506 | /**
|
---|
507 | * Abstract callback event class to asynchronously call VirtualBox callbacks
|
---|
508 | * on a dedicated event thread. Subclasses reimplement #handleCallback()
|
---|
509 | * to call appropriate IVirtualBoxCallback methods depending on the event
|
---|
510 | * to be dispatched.
|
---|
511 | *
|
---|
512 | * @note The VirtualBox instance passed to the constructor is strongly
|
---|
513 | * referenced, so that the VirtualBox singleton won't be released until the
|
---|
514 | * event gets handled by the event thread.
|
---|
515 | */
|
---|
516 | class VirtualBox::CallbackEvent : public Event
|
---|
517 | {
|
---|
518 | public:
|
---|
519 |
|
---|
520 | CallbackEvent (VirtualBox *aVirtualBox) : mVirtualBox (aVirtualBox)
|
---|
521 | {
|
---|
522 | Assert (aVirtualBox);
|
---|
523 | }
|
---|
524 |
|
---|
525 | void *handler();
|
---|
526 |
|
---|
527 | virtual void handleCallback (const ComPtr <IVirtualBoxCallback> &aCallback) = 0;
|
---|
528 |
|
---|
529 | private:
|
---|
530 |
|
---|
531 | /*
|
---|
532 | * Note that this is a weak ref -- the CallbackEvent handler thread
|
---|
533 | * is bound to the lifetime of the VirtualBox instance, so it's safe.
|
---|
534 | */
|
---|
535 | ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
|
---|
536 | };
|
---|
537 |
|
---|
538 | #endif // ____H_VIRTUALBOXIMPL
|
---|