1 | /* $Id: VirtualBoxImpl.h 10595 2008-07-14 12:23:57Z 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(PackageType)) (BSTR *aPackageType);
|
---|
120 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
121 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
122 | STDMETHOD(COMGETTER(SettingsFileVersion)) (BSTR *aSettingsFileVersion);
|
---|
123 | STDMETHOD(COMGETTER(SettingsFormatVersion)) (BSTR *aSettingsFormatVersion);
|
---|
124 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
125 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
126 | STDMETHOD(COMGETTER(Machines)) (IMachineCollection **aMachines);
|
---|
127 | STDMETHOD(COMGETTER(Machines2)) (ComSafeArrayOut (IMachine *, aMachines));
|
---|
128 | STDMETHOD(COMGETTER(HardDisks)) (IHardDiskCollection **aHardDisks);
|
---|
129 | STDMETHOD(COMGETTER(DVDImages)) (IDVDImageCollection **aDVDImages);
|
---|
130 | STDMETHOD(COMGETTER(FloppyImages)) (IFloppyImageCollection **aFloppyImages);
|
---|
131 | STDMETHOD(COMGETTER(ProgressOperations)) (IProgressCollection **aOperations);
|
---|
132 | STDMETHOD(COMGETTER(GuestOSTypes)) (IGuestOSTypeCollection **aGuestOSTypes);
|
---|
133 | STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
|
---|
134 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
135 |
|
---|
136 | /* IVirtualBox methods */
|
---|
137 |
|
---|
138 | STDMETHOD(CreateMachine) (INPTR BSTR aBaseFolder, INPTR BSTR aName,
|
---|
139 | INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
140 | STDMETHOD(CreateLegacyMachine) (INPTR BSTR aSettingsFile, INPTR BSTR aName,
|
---|
141 | INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
142 | STDMETHOD(OpenMachine) (INPTR BSTR aSettingsFile, IMachine **aMachine);
|
---|
143 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
144 | STDMETHOD(GetMachine) (INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
145 | STDMETHOD(FindMachine) (INPTR BSTR aName, IMachine **aMachine);
|
---|
146 | STDMETHOD(UnregisterMachine) (INPTR GUIDPARAM aId, IMachine **aMachine);
|
---|
147 |
|
---|
148 | STDMETHOD(CreateHardDisk) (HardDiskStorageType_T aStorageType, IHardDisk **aHardDisk);
|
---|
149 | STDMETHOD(OpenHardDisk) (INPTR BSTR aLocation, IHardDisk **aHardDisk);
|
---|
150 | STDMETHOD(OpenVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
|
---|
151 | STDMETHOD(RegisterHardDisk) (IHardDisk *aHardDisk);
|
---|
152 | STDMETHOD(GetHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
|
---|
153 | STDMETHOD(FindHardDisk) (INPTR BSTR aLocation, IHardDisk **aHardDisk);
|
---|
154 | STDMETHOD(FindVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
|
---|
155 | STDMETHOD(UnregisterHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
|
---|
156 |
|
---|
157 | STDMETHOD(OpenDVDImage) (INPTR BSTR aFilePath, INPTR GUIDPARAM aId,
|
---|
158 | IDVDImage **aDVDImage);
|
---|
159 | STDMETHOD(RegisterDVDImage) (IDVDImage *aDVDImage);
|
---|
160 | STDMETHOD(GetDVDImage) (INPTR GUIDPARAM aId, IDVDImage **aDVDImage);
|
---|
161 | STDMETHOD(FindDVDImage) (INPTR BSTR aFilePath, IDVDImage **aDVDImage);
|
---|
162 | STDMETHOD(GetDVDImageUsage) (INPTR GUIDPARAM aId,
|
---|
163 | ResourceUsage_T aUsage,
|
---|
164 | BSTR *aMachineIDs);
|
---|
165 | STDMETHOD(UnregisterDVDImage) (INPTR GUIDPARAM aId, IDVDImage **aDVDImage);
|
---|
166 |
|
---|
167 | STDMETHOD(OpenFloppyImage) (INPTR BSTR aFilePath, INPTR GUIDPARAM aId,
|
---|
168 | IFloppyImage **aFloppyImage);
|
---|
169 | STDMETHOD(RegisterFloppyImage) (IFloppyImage *aFloppyImage);
|
---|
170 | STDMETHOD(GetFloppyImage) (INPTR GUIDPARAM id, IFloppyImage **aFloppyImage);
|
---|
171 | STDMETHOD(FindFloppyImage) (INPTR BSTR aFilePath, IFloppyImage **aFloppyImage);
|
---|
172 | STDMETHOD(GetFloppyImageUsage) (INPTR GUIDPARAM aId,
|
---|
173 | ResourceUsage_T aUsage,
|
---|
174 | BSTR *aMachineIDs);
|
---|
175 | STDMETHOD(UnregisterFloppyImage) (INPTR GUIDPARAM aId, IFloppyImage **aFloppyImage);
|
---|
176 |
|
---|
177 | STDMETHOD(GetGuestOSType) (INPTR BSTR aId, IGuestOSType **aType);
|
---|
178 | STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable);
|
---|
179 | STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
|
---|
180 | STDMETHOD(GetNextExtraDataKey) (INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
|
---|
181 | STDMETHOD(GetExtraData) (INPTR BSTR aKey, BSTR *aValue);
|
---|
182 | STDMETHOD(SetExtraData) (INPTR BSTR aKey, INPTR BSTR aValue);
|
---|
183 | STDMETHOD(OpenSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
|
---|
184 | STDMETHOD(OpenRemoteSession) (ISession *aSession, INPTR GUIDPARAM aMachineId,
|
---|
185 | INPTR BSTR aType, INPTR BSTR aEnvironment,
|
---|
186 | IProgress **aProgress);
|
---|
187 | STDMETHOD(OpenExistingSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
|
---|
188 |
|
---|
189 | STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
190 | STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
191 |
|
---|
192 | STDMETHOD(WaitForPropertyChange) (INPTR BSTR aWhat, ULONG aTimeout,
|
---|
193 | BSTR *aChanged, BSTR *aValues);
|
---|
194 |
|
---|
195 | STDMETHOD(SaveSettings)();
|
---|
196 | STDMETHOD(SaveSettingsWithBackup) (BSTR *aBakFileName);
|
---|
197 |
|
---|
198 | /* public methods only for internal purposes */
|
---|
199 |
|
---|
200 | HRESULT postEvent (Event *event);
|
---|
201 |
|
---|
202 | HRESULT addProgress (IProgress *aProgress);
|
---|
203 | HRESULT removeProgress (INPTR GUIDPARAM aId);
|
---|
204 |
|
---|
205 | #ifdef RT_OS_WINDOWS
|
---|
206 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
207 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
208 | HRESULT startSVCHelperClient (bool aPrivileged,
|
---|
209 | SVCHelperClientFunc aFunc,
|
---|
210 | void *aUser, Progress *aProgress);
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | void addProcessToReap (RTPROCESS pid);
|
---|
214 | void updateClientWatcher();
|
---|
215 |
|
---|
216 | void onMachineStateChange (const Guid &aId, MachineState_T aState);
|
---|
217 | void onMachineDataChange (const Guid &aId);
|
---|
218 | BOOL onExtraDataCanChange(const Guid &aId, INPTR BSTR aKey, INPTR BSTR aValue,
|
---|
219 | Bstr &aError);
|
---|
220 | void onExtraDataChange(const Guid &aId, INPTR BSTR aKey, INPTR BSTR aValue);
|
---|
221 | void onMachineRegistered (const Guid &aId, BOOL aRegistered);
|
---|
222 | void onSessionStateChange (const Guid &aId, SessionState_T aState);
|
---|
223 |
|
---|
224 | void onSnapshotTaken (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
225 | void onSnapshotDiscarded (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
226 | void onSnapshotChange (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
227 |
|
---|
228 | ComObjPtr <GuestOSType> getUnknownOSType();
|
---|
229 |
|
---|
230 | typedef std::vector <ComObjPtr <SessionMachine> > SessionMachineVector;
|
---|
231 | void getOpenedMachines (SessionMachineVector &aVector);
|
---|
232 |
|
---|
233 | bool isMachineIdValid (const Guid &aId)
|
---|
234 | {
|
---|
235 | return SUCCEEDED (findMachine (aId, false /* aSetError */, NULL));
|
---|
236 | }
|
---|
237 |
|
---|
238 | /// @todo (dmik) remove and make findMachine() public instead
|
---|
239 | // after switching to VirtualBoxBaseNEXT
|
---|
240 | HRESULT getMachine (const Guid &aId, ComObjPtr <Machine> &aMachine,
|
---|
241 | bool aSetError = false)
|
---|
242 | {
|
---|
243 | return findMachine (aId, aSetError, &aMachine);
|
---|
244 | }
|
---|
245 |
|
---|
246 | /// @todo (dmik) remove and make findHardDisk() public instead
|
---|
247 | // after switching to VirtualBoxBaseNEXT
|
---|
248 | HRESULT getHardDisk (const Guid &aId, ComObjPtr <HardDisk> &aHardDisk)
|
---|
249 | {
|
---|
250 | return findHardDisk (&aId, NULL, true /* aDoSetError */, &aHardDisk);
|
---|
251 | }
|
---|
252 |
|
---|
253 | bool getDVDImageUsage (const Guid &aId, ResourceUsage_T aUsage,
|
---|
254 | Bstr *aMachineIDs = NULL);
|
---|
255 | bool getFloppyImageUsage (const Guid &aId, ResourceUsage_T aUsage,
|
---|
256 | Bstr *aMachineIDs = NULL);
|
---|
257 |
|
---|
258 | const ComObjPtr <Host> &host() { return mData.mHost; }
|
---|
259 | const ComObjPtr <SystemProperties> &systemProperties()
|
---|
260 | { return mData.mSystemProperties; }
|
---|
261 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
262 | const ComObjPtr <PerformanceCollector> &performanceCollector()
|
---|
263 | { return mData.mPerformanceCollector; }
|
---|
264 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
265 |
|
---|
266 |
|
---|
267 | /** Returns the VirtualBox home directory */
|
---|
268 | const Utf8Str &homeDir() { return mData.mHomeDir; }
|
---|
269 |
|
---|
270 | void calculateRelativePath (const char *aPath, Utf8Str &aResult);
|
---|
271 |
|
---|
272 | enum RHD_Flags { RHD_Internal, RHD_External, RHD_OnStartUp };
|
---|
273 | HRESULT registerHardDisk (HardDisk *aHardDisk, RHD_Flags aFlags);
|
---|
274 | HRESULT unregisterHardDisk (HardDisk *aHardDisk);
|
---|
275 | HRESULT unregisterDiffHardDisk (HardDisk *aHardDisk);
|
---|
276 |
|
---|
277 | HRESULT saveSettings();
|
---|
278 | HRESULT updateSettings (const char *aOldPath, const char *aNewPath);
|
---|
279 |
|
---|
280 | const Bstr &settingsFileName() { return mData.mCfgFile.mName; }
|
---|
281 |
|
---|
282 | class SettingsTreeHelper : public settings::XmlTreeBackend::InputResolver
|
---|
283 | , public settings::XmlTreeBackend::AutoConverter
|
---|
284 | {
|
---|
285 | public:
|
---|
286 |
|
---|
287 | // InputResolver interface
|
---|
288 | settings::Input *resolveEntity (const char *aURI, const char *aID);
|
---|
289 |
|
---|
290 | // AutoConverter interface
|
---|
291 | bool needsConversion (const settings::Key &aRoot, char **aOldVersion) const;
|
---|
292 | const char *templateUri() const;
|
---|
293 | };
|
---|
294 |
|
---|
295 | static HRESULT loadSettingsTree (settings::XmlTreeBackend &aTree,
|
---|
296 | settings::File &aFile,
|
---|
297 | bool aValidate,
|
---|
298 | bool aCatchLoadErrors,
|
---|
299 | bool aAddDefaults,
|
---|
300 | Utf8Str *aFormatVersion = NULL);
|
---|
301 |
|
---|
302 | /**
|
---|
303 | * Shortcut to loadSettingsTree (aTree, aFile, true, true, true).
|
---|
304 | *
|
---|
305 | * Used when the settings file is to be loaded for the first time for the
|
---|
306 | * given object in order to recreate it from the stored settings.
|
---|
307 | *
|
---|
308 | * @param aFormatVersion Where to store the current format version of the
|
---|
309 | * loaded settings tree.
|
---|
310 | */
|
---|
311 | static HRESULT loadSettingsTree_FirstTime (settings::XmlTreeBackend &aTree,
|
---|
312 | settings::File &aFile,
|
---|
313 | Utf8Str &aFormatVersion)
|
---|
314 | {
|
---|
315 | return loadSettingsTree (aTree, aFile, true, true, true,
|
---|
316 | &aFormatVersion);
|
---|
317 | }
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, true).
|
---|
321 | *
|
---|
322 | * Used when the settings file is loaded again (after it has been fully
|
---|
323 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
324 | * look at settings that don't have any representation within object's
|
---|
325 | * data fields.
|
---|
326 | */
|
---|
327 | static HRESULT loadSettingsTree_Again (settings::XmlTreeBackend &aTree,
|
---|
328 | settings::File &aFile)
|
---|
329 | {
|
---|
330 | return loadSettingsTree (aTree, aFile, true, false, true);
|
---|
331 | }
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, false).
|
---|
335 | *
|
---|
336 | * Used when the settings file is loaded again (after it has been fully
|
---|
337 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
338 | * update some settings and then save them back.
|
---|
339 | */
|
---|
340 | static HRESULT loadSettingsTree_ForUpdate (settings::XmlTreeBackend &aTree,
|
---|
341 | settings::File &aFile)
|
---|
342 | {
|
---|
343 | return loadSettingsTree (aTree, aFile, true, false, false);
|
---|
344 | }
|
---|
345 |
|
---|
346 | static HRESULT saveSettingsTree (settings::TreeBackend &aTree,
|
---|
347 | settings::File &aFile,
|
---|
348 | Utf8Str &aFormatVersion);
|
---|
349 |
|
---|
350 | static HRESULT backupSettingsFile (const Bstr &aFileName,
|
---|
351 | const Utf8Str &aOldFormat,
|
---|
352 | Bstr &aBakFileName);
|
---|
353 |
|
---|
354 | static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
|
---|
355 |
|
---|
356 | /* for VirtualBoxSupportErrorInfoImpl */
|
---|
357 | static const wchar_t *getComponentName() { return L"VirtualBox"; }
|
---|
358 |
|
---|
359 | private:
|
---|
360 |
|
---|
361 | typedef std::list <ComObjPtr <Machine> > MachineList;
|
---|
362 | typedef std::list <ComObjPtr <GuestOSType> > GuestOSTypeList;
|
---|
363 | typedef std::list <ComPtr <IProgress> > ProgressList;
|
---|
364 |
|
---|
365 | typedef std::list <ComObjPtr <HardDisk> > HardDiskList;
|
---|
366 | typedef std::list <ComObjPtr <DVDImage> > DVDImageList;
|
---|
367 | typedef std::list <ComObjPtr <FloppyImage> > FloppyImageList;
|
---|
368 | typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
|
---|
369 |
|
---|
370 | typedef std::map <Guid, ComObjPtr <HardDisk> > HardDiskMap;
|
---|
371 |
|
---|
372 | HRESULT findMachine (const Guid &aId, bool aSetError,
|
---|
373 | ComObjPtr <Machine> *machine = NULL);
|
---|
374 |
|
---|
375 | HRESULT findHardDisk (const Guid *aId, const BSTR aLocation,
|
---|
376 | bool aSetError, ComObjPtr <HardDisk> *aHardDisk = NULL);
|
---|
377 |
|
---|
378 | HRESULT findVirtualDiskImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
379 | bool aSetError, ComObjPtr <HVirtualDiskImage> *aImage = NULL);
|
---|
380 | HRESULT findDVDImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
381 | bool aSetError, ComObjPtr <DVDImage> *aImage = NULL);
|
---|
382 | HRESULT findFloppyImage (const Guid *aId, const BSTR aFilePathFull,
|
---|
383 | bool aSetError, ComObjPtr <FloppyImage> *aImage = NULL);
|
---|
384 |
|
---|
385 | HRESULT checkMediaForConflicts (HardDisk *aHardDisk,
|
---|
386 | const Guid *aId, const BSTR aFilePathFull);
|
---|
387 |
|
---|
388 | HRESULT loadMachines (const settings::Key &aGlobal);
|
---|
389 | HRESULT loadDisks (const settings::Key &aGlobal);
|
---|
390 | HRESULT loadHardDisks (const settings::Key &aNode);
|
---|
391 |
|
---|
392 | HRESULT saveHardDisks (settings::Key &aNode);
|
---|
393 |
|
---|
394 | HRESULT registerMachine (Machine *aMachine);
|
---|
395 |
|
---|
396 | HRESULT registerDVDImage (DVDImage *aImage, bool aOnStartUp);
|
---|
397 | HRESULT registerFloppyImage (FloppyImage *aImage, bool aOnStartUp);
|
---|
398 |
|
---|
399 | HRESULT lockConfig();
|
---|
400 | HRESULT unlockConfig();
|
---|
401 |
|
---|
402 | /** @note This method is not thread safe */
|
---|
403 | bool isConfigLocked() { return mData.mCfgFile.mHandle != NIL_RTFILE; }
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Main VirtualBox data structure.
|
---|
407 | * @note |const| members are persistent during lifetime so can be accessed
|
---|
408 | * without locking.
|
---|
409 | */
|
---|
410 | struct Data
|
---|
411 | {
|
---|
412 | Data();
|
---|
413 |
|
---|
414 | struct CfgFile
|
---|
415 | {
|
---|
416 | CfgFile() : mHandle (NIL_RTFILE) {}
|
---|
417 |
|
---|
418 | const Bstr mName;
|
---|
419 | RTFILE mHandle;
|
---|
420 | };
|
---|
421 |
|
---|
422 | // const data members not requiring locking
|
---|
423 | const Utf8Str mHomeDir;
|
---|
424 |
|
---|
425 | // const objects not requiring locking
|
---|
426 | const ComObjPtr <Host> mHost;
|
---|
427 | const ComObjPtr <SystemProperties> mSystemProperties;
|
---|
428 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
429 | const ComObjPtr <PerformanceCollector> mPerformanceCollector;
|
---|
430 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
431 |
|
---|
432 | CfgFile mCfgFile;
|
---|
433 |
|
---|
434 | Utf8Str mSettingsFileVersion;
|
---|
435 |
|
---|
436 | MachineList mMachines;
|
---|
437 | GuestOSTypeList mGuestOSTypes;
|
---|
438 |
|
---|
439 | ProgressList mProgressOperations;
|
---|
440 | HardDiskList mHardDisks;
|
---|
441 | DVDImageList mDVDImages;
|
---|
442 | FloppyImageList mFloppyImages;
|
---|
443 | SharedFolderList mSharedFolders;
|
---|
444 |
|
---|
445 | HardDiskMap mHardDiskMap;
|
---|
446 |
|
---|
447 | CallbackList mCallbacks;
|
---|
448 | };
|
---|
449 |
|
---|
450 | Data mData;
|
---|
451 |
|
---|
452 | /** Client watcher thread data structure */
|
---|
453 | struct ClientWatcherData
|
---|
454 | {
|
---|
455 | ClientWatcherData()
|
---|
456 | #if defined(RT_OS_WINDOWS)
|
---|
457 | : mUpdateReq (NULL)
|
---|
458 | #elif defined(RT_OS_OS2)
|
---|
459 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
460 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
461 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
462 | #else
|
---|
463 | # error "Port me!"
|
---|
464 | #endif
|
---|
465 | , mThread (NIL_RTTHREAD) {}
|
---|
466 |
|
---|
467 | // const objects not requiring locking
|
---|
468 | #if defined(RT_OS_WINDOWS)
|
---|
469 | const HANDLE mUpdateReq;
|
---|
470 | #elif defined(RT_OS_OS2)
|
---|
471 | const RTSEMEVENT mUpdateReq;
|
---|
472 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
473 | const RTSEMEVENT mUpdateReq;
|
---|
474 | #else
|
---|
475 | # error "Port me!"
|
---|
476 | #endif
|
---|
477 | const RTTHREAD mThread;
|
---|
478 |
|
---|
479 | typedef std::list <RTPROCESS> ProcessList;
|
---|
480 | ProcessList mProcesses;
|
---|
481 | };
|
---|
482 |
|
---|
483 | ClientWatcherData mWatcherData;
|
---|
484 |
|
---|
485 | const RTTHREAD mAsyncEventThread;
|
---|
486 | EventQueue * const mAsyncEventQ;
|
---|
487 | /** Lock for calling EventQueue->post() */
|
---|
488 | RWLockHandle mAsyncEventQLock;
|
---|
489 |
|
---|
490 | static Bstr sVersion;
|
---|
491 | static Bstr sPackageType;
|
---|
492 | static Bstr sSettingsFormatVersion;
|
---|
493 |
|
---|
494 | static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
|
---|
495 | static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
|
---|
496 |
|
---|
497 | #ifdef RT_OS_WINDOWS
|
---|
498 | static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
|
---|
499 | #endif
|
---|
500 | };
|
---|
501 |
|
---|
502 | ////////////////////////////////////////////////////////////////////////////////
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Abstract callback event class to asynchronously call VirtualBox callbacks
|
---|
506 | * on a dedicated event thread. Subclasses reimplement #handleCallback()
|
---|
507 | * to call appropriate IVirtualBoxCallback methods depending on the event
|
---|
508 | * to be dispatched.
|
---|
509 | *
|
---|
510 | * @note The VirtualBox instance passed to the constructor is strongly
|
---|
511 | * referenced, so that the VirtualBox singleton won't be released until the
|
---|
512 | * event gets handled by the event thread.
|
---|
513 | */
|
---|
514 | class VirtualBox::CallbackEvent : public Event
|
---|
515 | {
|
---|
516 | public:
|
---|
517 |
|
---|
518 | CallbackEvent (VirtualBox *aVirtualBox) : mVirtualBox (aVirtualBox)
|
---|
519 | {
|
---|
520 | Assert (aVirtualBox);
|
---|
521 | }
|
---|
522 |
|
---|
523 | void *handler();
|
---|
524 |
|
---|
525 | virtual void handleCallback (const ComPtr <IVirtualBoxCallback> &aCallback) = 0;
|
---|
526 |
|
---|
527 | private:
|
---|
528 |
|
---|
529 | /*
|
---|
530 | * Note that this is a weak ref -- the CallbackEvent handler thread
|
---|
531 | * is bound to the lifetime of the VirtualBox instance, so it's safe.
|
---|
532 | */
|
---|
533 | ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
|
---|
534 | };
|
---|
535 |
|
---|
536 | #endif // ____H_VIRTUALBOXIMPL
|
---|