1 | /* $Id: VirtualBoxImpl.h 21878 2009-07-30 12:42:08Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2009 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 | class Machine;
|
---|
44 | class SessionMachine;
|
---|
45 | class HardDisk;
|
---|
46 | class DVDImage;
|
---|
47 | class FloppyImage;
|
---|
48 | class MachineCollection;
|
---|
49 | class GuestOSType;
|
---|
50 | class GuestOSTypeCollection;
|
---|
51 | class SharedFolder;
|
---|
52 | class Progress;
|
---|
53 | class ProgressCollection;
|
---|
54 | class Host;
|
---|
55 | class SystemProperties;
|
---|
56 | class DHCPServer;
|
---|
57 |
|
---|
58 | #ifdef RT_OS_WINDOWS
|
---|
59 | class SVCHlpClient;
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | struct VMClientWatcherData;
|
---|
63 |
|
---|
64 | class ATL_NO_VTABLE VirtualBox :
|
---|
65 | public VirtualBoxBaseWithChildrenNEXT,
|
---|
66 | public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
|
---|
67 | public VirtualBoxSupportTranslation<VirtualBox>,
|
---|
68 | VBOX_SCRIPTABLE_IMPL(IVirtualBox)
|
---|
69 | #ifdef RT_OS_WINDOWS
|
---|
70 | , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
|
---|
71 | #endif
|
---|
72 | {
|
---|
73 |
|
---|
74 | public:
|
---|
75 |
|
---|
76 | typedef std::list <ComPtr<IVirtualBoxCallback> > CallbackList;
|
---|
77 | typedef std::vector <ComPtr<IVirtualBoxCallback> > CallbackVector;
|
---|
78 |
|
---|
79 | typedef std::vector <ComObjPtr<SessionMachine> > SessionMachineVector;
|
---|
80 | typedef std::vector <ComObjPtr<Machine> > MachineVector;
|
---|
81 |
|
---|
82 | typedef std::vector <ComPtr<IInternalSessionControl> > InternalControlVector;
|
---|
83 |
|
---|
84 | class CallbackEvent;
|
---|
85 | friend class CallbackEvent;
|
---|
86 |
|
---|
87 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualBox)
|
---|
88 |
|
---|
89 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
|
---|
90 |
|
---|
91 | DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
92 | DECLARE_NOT_AGGREGATABLE(VirtualBox)
|
---|
93 |
|
---|
94 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
95 |
|
---|
96 | BEGIN_COM_MAP(VirtualBox)
|
---|
97 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
98 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
99 | COM_INTERFACE_ENTRY(IVirtualBox)
|
---|
100 | END_COM_MAP()
|
---|
101 |
|
---|
102 | NS_DECL_ISUPPORTS
|
---|
103 |
|
---|
104 | /* to postpone generation of the default ctor/dtor */
|
---|
105 | VirtualBox();
|
---|
106 | ~VirtualBox();
|
---|
107 |
|
---|
108 | HRESULT FinalConstruct();
|
---|
109 | void FinalRelease();
|
---|
110 |
|
---|
111 | /* public initializer/uninitializer for internal purposes only */
|
---|
112 | HRESULT init();
|
---|
113 | void uninit();
|
---|
114 |
|
---|
115 | /* IVirtualBox properties */
|
---|
116 | STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
|
---|
117 | STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
|
---|
118 | STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
|
---|
119 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
120 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
121 | STDMETHOD(COMGETTER(SettingsFileVersion)) (BSTR *aSettingsFileVersion);
|
---|
122 | STDMETHOD(COMGETTER(SettingsFormatVersion)) (BSTR *aSettingsFormatVersion);
|
---|
123 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
124 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
125 | STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
|
---|
126 | STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IHardDisk *, aHardDisks));
|
---|
127 | STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IDVDImage *, aDVDImages));
|
---|
128 | STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IFloppyImage *, aFloppyImages));
|
---|
129 | STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
|
---|
130 | STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
|
---|
131 | STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
|
---|
132 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
133 | STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
|
---|
134 |
|
---|
135 | /* IVirtualBox methods */
|
---|
136 |
|
---|
137 | STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
|
---|
138 | IN_BSTR aId, IMachine **aMachine);
|
---|
139 | STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
|
---|
140 | IN_BSTR aId, IMachine **aMachine);
|
---|
141 | STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
142 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
143 | STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
|
---|
144 | STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
|
---|
145 | STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
|
---|
146 | STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
|
---|
147 |
|
---|
148 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
|
---|
149 | IHardDisk **aHardDisk);
|
---|
150 | STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
|
---|
151 | BOOL aSetImageId, IN_BSTR aImageId,
|
---|
152 | BOOL aSetParentId, IN_BSTR aParentId,
|
---|
153 | IHardDisk **aHardDisk);
|
---|
154 | STDMETHOD(GetHardDisk) (IN_BSTR aId, IHardDisk **aHardDisk);
|
---|
155 | STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IHardDisk **aHardDisk);
|
---|
156 |
|
---|
157 | STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
|
---|
158 | IDVDImage **aDVDImage);
|
---|
159 | STDMETHOD(GetDVDImage) (IN_BSTR aId, IDVDImage **aDVDImage);
|
---|
160 | STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IDVDImage **aDVDImage);
|
---|
161 |
|
---|
162 | STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
|
---|
163 | IFloppyImage **aFloppyImage);
|
---|
164 | STDMETHOD(GetFloppyImage) (IN_BSTR aId, IFloppyImage **aFloppyImage);
|
---|
165 | STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IFloppyImage **aFloppyImage);
|
---|
166 |
|
---|
167 | STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
|
---|
168 | STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
|
---|
169 | STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
|
---|
170 | STDMETHOD(GetNextExtraDataKey) (IN_BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
|
---|
171 | STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
|
---|
172 | STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
|
---|
173 | STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
|
---|
174 | STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
|
---|
175 | IN_BSTR aType, IN_BSTR aEnvironment,
|
---|
176 | IProgress **aProgress);
|
---|
177 | STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
|
---|
178 |
|
---|
179 | STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
180 | STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
|
---|
181 |
|
---|
182 | STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
|
---|
183 | BSTR *aChanged, BSTR *aValues);
|
---|
184 |
|
---|
185 | STDMETHOD(SaveSettings)();
|
---|
186 | STDMETHOD(SaveSettingsWithBackup) (BSTR *aBakFileName);
|
---|
187 |
|
---|
188 | // STDMETHOD(CreateDHCPServerForInterface) (/*IHostNetworkInterface * aIinterface, */IDHCPServer ** aServer);
|
---|
189 | STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
190 | // STDMETHOD(FindDHCPServerForInterface) (IHostNetworkInterface * aIinterface, IDHCPServer ** aServer);
|
---|
191 | STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
192 | STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
|
---|
193 |
|
---|
194 | /* public methods only for internal purposes */
|
---|
195 |
|
---|
196 | HRESULT postEvent (Event *event);
|
---|
197 |
|
---|
198 | HRESULT addProgress (IProgress *aProgress);
|
---|
199 | HRESULT removeProgress (IN_GUID aId);
|
---|
200 |
|
---|
201 | #ifdef RT_OS_WINDOWS
|
---|
202 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
203 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
204 | HRESULT startSVCHelperClient (bool aPrivileged,
|
---|
205 | SVCHelperClientFunc aFunc,
|
---|
206 | void *aUser, Progress *aProgress);
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | void addProcessToReap (RTPROCESS pid);
|
---|
210 | void updateClientWatcher();
|
---|
211 |
|
---|
212 | void onMachineStateChange (const Guid &aId, MachineState_T aState);
|
---|
213 | void onMachineDataChange (const Guid &aId);
|
---|
214 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
215 | Bstr &aError);
|
---|
216 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
217 | void onMachineRegistered (const Guid &aId, BOOL aRegistered);
|
---|
218 | void onSessionStateChange (const Guid &aId, SessionState_T aState);
|
---|
219 |
|
---|
220 | void onSnapshotTaken (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
221 | void onSnapshotDiscarded (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
222 | void onSnapshotChange (const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
223 | void onGuestPropertyChange (const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
224 | IN_BSTR aFlags);
|
---|
225 |
|
---|
226 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
227 |
|
---|
228 | void getOpenedMachines (SessionMachineVector &aMachines,
|
---|
229 | InternalControlVector *aControls = NULL);
|
---|
230 |
|
---|
231 | /** Shortcut to #getOpenedMachines (aMachines, &aControls). */
|
---|
232 | void getOpenedMachinesAndControls (SessionMachineVector &aMachines,
|
---|
233 | InternalControlVector &aControls)
|
---|
234 | { getOpenedMachines (aMachines, &aControls); }
|
---|
235 |
|
---|
236 | bool isMachineIdValid (const Guid &aId)
|
---|
237 | {
|
---|
238 | return SUCCEEDED (findMachine (aId, false /* aSetError */, NULL));
|
---|
239 | }
|
---|
240 |
|
---|
241 | HRESULT findMachine (const Guid &aId, bool aSetError,
|
---|
242 | ComObjPtr<Machine> *machine = NULL);
|
---|
243 |
|
---|
244 | HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
|
---|
245 | bool aSetError, ComObjPtr<HardDisk> *aHardDisk = NULL);
|
---|
246 | HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
|
---|
247 | bool aSetError, ComObjPtr<DVDImage> *aImage = NULL);
|
---|
248 | HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
|
---|
249 | bool aSetError, ComObjPtr<FloppyImage> *aImage = NULL);
|
---|
250 |
|
---|
251 | const ComObjPtr<Host> &host() { return mData.mHost; }
|
---|
252 | const ComObjPtr<SystemProperties> &systemProperties()
|
---|
253 | { return mData.mSystemProperties; }
|
---|
254 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
255 | const ComObjPtr<PerformanceCollector> &performanceCollector()
|
---|
256 | { return mData.mPerformanceCollector; }
|
---|
257 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
258 |
|
---|
259 |
|
---|
260 | /** Returns the VirtualBox home directory */
|
---|
261 | const Utf8Str &homeDir() { return mData.mHomeDir; }
|
---|
262 |
|
---|
263 | int calculateFullPath (const char *aPath, Utf8Str &aResult);
|
---|
264 | void calculateRelativePath (const char *aPath, Utf8Str &aResult);
|
---|
265 |
|
---|
266 | HRESULT registerHardDisk(HardDisk *aHardDisk, bool aSaveRegistry = true);
|
---|
267 | HRESULT unregisterHardDisk(HardDisk *aHardDisk, bool aSaveRegistry = true);
|
---|
268 |
|
---|
269 | HRESULT registerDVDImage(DVDImage *aImage, bool aSaveRegistry = true);
|
---|
270 | HRESULT unregisterDVDImage(DVDImage *aImage, bool aSaveRegistry = true);
|
---|
271 |
|
---|
272 | HRESULT registerFloppyImage (FloppyImage *aImage, bool aSaveRegistry = true);
|
---|
273 | HRESULT unregisterFloppyImage (FloppyImage *aImage, bool aSaveRegistry = true);
|
---|
274 |
|
---|
275 | HRESULT cast (IHardDisk *aFrom, ComObjPtr<HardDisk> &aTo);
|
---|
276 |
|
---|
277 | HRESULT saveSettings();
|
---|
278 | HRESULT updateSettings (const char *aOldPath, const char *aNewPath);
|
---|
279 |
|
---|
280 | const Bstr &settingsFileName() { return mData.mCfgFile.mName; }
|
---|
281 |
|
---|
282 | static HRESULT ensureFilePathExists (const char *aFileName);
|
---|
283 |
|
---|
284 | static HRESULT loadSettingsTree (settings::XmlTreeBackend &aTree,
|
---|
285 | xml::File &aFile,
|
---|
286 | bool aValidate,
|
---|
287 | bool aCatchLoadErrors,
|
---|
288 | bool aAddDefaults,
|
---|
289 | Utf8Str *aFormatVersion = NULL);
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Shortcut to loadSettingsTree (aTree, aFile, true, true, true).
|
---|
293 | *
|
---|
294 | * Used when the settings file is to be loaded for the first time for the
|
---|
295 | * given object in order to recreate it from the stored settings.
|
---|
296 | *
|
---|
297 | * @param aFormatVersion Where to store the current format version of the
|
---|
298 | * loaded settings tree.
|
---|
299 | */
|
---|
300 | static HRESULT loadSettingsTree_FirstTime (settings::XmlTreeBackend &aTree,
|
---|
301 | xml::File &aFile,
|
---|
302 | Utf8Str &aFormatVersion)
|
---|
303 | {
|
---|
304 | return loadSettingsTree (aTree, aFile, true, true, true,
|
---|
305 | &aFormatVersion);
|
---|
306 | }
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, true).
|
---|
310 | *
|
---|
311 | * Used when the settings file is loaded again (after it has been fully
|
---|
312 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
313 | * look at settings that don't have any representation within object's
|
---|
314 | * data fields.
|
---|
315 | */
|
---|
316 | static HRESULT loadSettingsTree_Again (settings::XmlTreeBackend &aTree,
|
---|
317 | xml::File &aFile)
|
---|
318 | {
|
---|
319 | return loadSettingsTree (aTree, aFile, true, false, true);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Shortcut to loadSettingsTree (aTree, aFile, true, false, false).
|
---|
324 | *
|
---|
325 | * Used when the settings file is loaded again (after it has been fully
|
---|
326 | * checked and validated by #loadSettingsTree_FirstTime()) in order to
|
---|
327 | * update some settings and then save them back.
|
---|
328 | */
|
---|
329 | static HRESULT loadSettingsTree_ForUpdate (settings::XmlTreeBackend &aTree,
|
---|
330 | xml::File &aFile)
|
---|
331 | {
|
---|
332 | return loadSettingsTree (aTree, aFile, true, false, false);
|
---|
333 | }
|
---|
334 |
|
---|
335 | static HRESULT saveSettingsTree (settings::TreeBackend &aTree,
|
---|
336 | xml::File &aFile,
|
---|
337 | Utf8Str &aFormatVersion);
|
---|
338 |
|
---|
339 | static HRESULT backupSettingsFile (const Bstr &aFileName,
|
---|
340 | const Utf8Str &aOldFormat,
|
---|
341 | Bstr &aBakFileName);
|
---|
342 |
|
---|
343 | static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Returns a lock handle used to protect changes to the hard disk hierarchy
|
---|
347 | * (e.g. serialize access to the HardDisk::mParent fields and methods
|
---|
348 | * adding/removing children). When using this lock, the following rules must
|
---|
349 | * be obeyed:
|
---|
350 | *
|
---|
351 | * 1. The write lock on this handle must be either held alone on the thread
|
---|
352 | * or requested *after* the VirtualBox object lock. Mixing with other
|
---|
353 | * locks is prohibited.
|
---|
354 | *
|
---|
355 | * 2. The read lock on this handle may be intermixed with any other lock
|
---|
356 | * with the exception that it must be requested *after* the VirtualBox
|
---|
357 | * object lock.
|
---|
358 | */
|
---|
359 | RWLockHandle *hardDiskTreeLockHandle() { return &mHardDiskTreeLockHandle; }
|
---|
360 |
|
---|
361 | /* for VirtualBoxSupportErrorInfoImpl */
|
---|
362 | static const wchar_t *getComponentName() { return L"VirtualBox"; }
|
---|
363 |
|
---|
364 | private:
|
---|
365 |
|
---|
366 | typedef std::list <ComObjPtr<Machine> > MachineList;
|
---|
367 | typedef std::list <ComObjPtr<GuestOSType> > GuestOSTypeList;
|
---|
368 |
|
---|
369 | typedef std::map <Guid, ComPtr<IProgress> > ProgressMap;
|
---|
370 |
|
---|
371 | typedef std::list <ComObjPtr<HardDisk> > HardDiskList;
|
---|
372 | typedef std::list <ComObjPtr<DVDImage> > DVDImageList;
|
---|
373 | typedef std::list <ComObjPtr<FloppyImage> > FloppyImageList;
|
---|
374 | typedef std::list <ComObjPtr<SharedFolder> > SharedFolderList;
|
---|
375 | typedef std::list <ComObjPtr<DHCPServer> > DHCPServerList;
|
---|
376 |
|
---|
377 | typedef std::map <Guid, ComObjPtr<HardDisk> > HardDiskMap;
|
---|
378 |
|
---|
379 | /**
|
---|
380 | * Reimplements VirtualBoxWithTypedChildren::childrenLock() to return a
|
---|
381 | * dedicated lock instead of the main object lock. The dedicated lock for
|
---|
382 | * child map operations frees callers of init() methods of these children
|
---|
383 | * from acquiring a write parent (VirtualBox) lock (which would be mandatory
|
---|
384 | * otherwise). Since VirtualBox has a lot of heterogenous children which
|
---|
385 | * init() methods are called here and there, it definitely makes sense.
|
---|
386 | */
|
---|
387 | RWLockHandle *childrenLock() { return &mChildrenMapLockHandle; }
|
---|
388 |
|
---|
389 | HRESULT checkMediaForConflicts2 (const Guid &aId, const Bstr &aLocation,
|
---|
390 | Utf8Str &aConflictType);
|
---|
391 |
|
---|
392 | HRESULT loadMachines (const settings::Key &aGlobal);
|
---|
393 | HRESULT loadMedia (const settings::Key &aGlobal);
|
---|
394 | HRESULT loadNetservices (const settings::Key &aGlobal);
|
---|
395 |
|
---|
396 | HRESULT registerMachine (Machine *aMachine);
|
---|
397 |
|
---|
398 | HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
|
---|
399 | bool aSaveRegistry = true);
|
---|
400 | HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
|
---|
401 | bool aSaveRegistry = true);
|
---|
402 |
|
---|
403 | HRESULT lockConfig();
|
---|
404 | HRESULT unlockConfig();
|
---|
405 |
|
---|
406 | /** @note This method is not thread safe */
|
---|
407 | bool isConfigLocked() { return mData.mCfgFile.mHandle != NIL_RTFILE; }
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * Main VirtualBox data structure.
|
---|
411 | * @note |const| members are persistent during lifetime so can be accessed
|
---|
412 | * without locking.
|
---|
413 | */
|
---|
414 | struct Data
|
---|
415 | {
|
---|
416 | Data();
|
---|
417 |
|
---|
418 | struct CfgFile
|
---|
419 | {
|
---|
420 | CfgFile() : mHandle (NIL_RTFILE) {}
|
---|
421 |
|
---|
422 | const Bstr mName;
|
---|
423 | RTFILE mHandle;
|
---|
424 | /** Flag indicating that the config file is read-only. */
|
---|
425 | BOOL mReadonly;
|
---|
426 | };
|
---|
427 |
|
---|
428 | // const data members not requiring locking
|
---|
429 | const Utf8Str mHomeDir;
|
---|
430 |
|
---|
431 | // const objects not requiring locking
|
---|
432 | const ComObjPtr<Host> mHost;
|
---|
433 | const ComObjPtr<SystemProperties> mSystemProperties;
|
---|
434 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
435 | const ComObjPtr<PerformanceCollector> mPerformanceCollector;
|
---|
436 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
437 |
|
---|
438 | CfgFile mCfgFile;
|
---|
439 |
|
---|
440 | Utf8Str mSettingsFileVersion;
|
---|
441 |
|
---|
442 | MachineList mMachines;
|
---|
443 | GuestOSTypeList mGuestOSTypes;
|
---|
444 |
|
---|
445 | ProgressMap mProgressOperations;
|
---|
446 |
|
---|
447 | HardDiskList mHardDisks;
|
---|
448 | DVDImageList mDVDImages;
|
---|
449 | FloppyImageList mFloppyImages;
|
---|
450 | SharedFolderList mSharedFolders;
|
---|
451 | DHCPServerList mDHCPServers;
|
---|
452 |
|
---|
453 | /// @todo NEWMEDIA do we really need this map? Used only in
|
---|
454 | /// find() it seems
|
---|
455 | HardDiskMap mHardDiskMap;
|
---|
456 |
|
---|
457 | CallbackList mCallbacks;
|
---|
458 | };
|
---|
459 |
|
---|
460 | Data mData;
|
---|
461 |
|
---|
462 | /** Client watcher thread data structure */
|
---|
463 | struct ClientWatcherData
|
---|
464 | {
|
---|
465 | ClientWatcherData()
|
---|
466 | #if defined(RT_OS_WINDOWS)
|
---|
467 | : mUpdateReq (NULL)
|
---|
468 | #elif defined(RT_OS_OS2)
|
---|
469 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
470 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
471 | : mUpdateReq (NIL_RTSEMEVENT)
|
---|
472 | #else
|
---|
473 | # error "Port me!"
|
---|
474 | #endif
|
---|
475 | , mThread (NIL_RTTHREAD) {}
|
---|
476 |
|
---|
477 | // const objects not requiring locking
|
---|
478 | #if defined(RT_OS_WINDOWS)
|
---|
479 | const HANDLE mUpdateReq;
|
---|
480 | #elif defined(RT_OS_OS2)
|
---|
481 | const RTSEMEVENT mUpdateReq;
|
---|
482 | #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
|
---|
483 | const RTSEMEVENT mUpdateReq;
|
---|
484 | #else
|
---|
485 | # error "Port me!"
|
---|
486 | #endif
|
---|
487 | const RTTHREAD mThread;
|
---|
488 |
|
---|
489 | typedef std::list <RTPROCESS> ProcessList;
|
---|
490 | ProcessList mProcesses;
|
---|
491 | };
|
---|
492 |
|
---|
493 | ClientWatcherData mWatcherData;
|
---|
494 |
|
---|
495 | const RTTHREAD mAsyncEventThread;
|
---|
496 | EventQueue * const mAsyncEventQ;
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * "Safe" lock. May only be used if guaranteed that no other locks are
|
---|
500 | * requested while holding it and no functions that may do so are called.
|
---|
501 | * Currently, protects the following:
|
---|
502 | *
|
---|
503 | * - mProgressOperations
|
---|
504 | */
|
---|
505 | RWLockHandle mSafeLock;
|
---|
506 |
|
---|
507 | RWLockHandle mHardDiskTreeLockHandle;
|
---|
508 | RWLockHandle mChildrenMapLockHandle;
|
---|
509 |
|
---|
510 | static Bstr sVersion;
|
---|
511 | static ULONG sRevision;
|
---|
512 | static Bstr sPackageType;
|
---|
513 | static Bstr sSettingsFormatVersion;
|
---|
514 |
|
---|
515 | static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
|
---|
516 | static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
|
---|
517 |
|
---|
518 | #ifdef RT_OS_WINDOWS
|
---|
519 | static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
|
---|
520 | #endif
|
---|
521 | };
|
---|
522 |
|
---|
523 | ////////////////////////////////////////////////////////////////////////////////
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * Abstract callback event class to asynchronously call VirtualBox callbacks
|
---|
527 | * on a dedicated event thread. Subclasses reimplement #handleCallback()
|
---|
528 | * to call appropriate IVirtualBoxCallback methods depending on the event
|
---|
529 | * to be dispatched.
|
---|
530 | *
|
---|
531 | * @note The VirtualBox instance passed to the constructor is strongly
|
---|
532 | * referenced, so that the VirtualBox singleton won't be released until the
|
---|
533 | * event gets handled by the event thread.
|
---|
534 | */
|
---|
535 | class VirtualBox::CallbackEvent : public Event
|
---|
536 | {
|
---|
537 | public:
|
---|
538 |
|
---|
539 | CallbackEvent (VirtualBox *aVirtualBox) : mVirtualBox (aVirtualBox)
|
---|
540 | {
|
---|
541 | Assert (aVirtualBox);
|
---|
542 | }
|
---|
543 |
|
---|
544 | void *handler();
|
---|
545 |
|
---|
546 | virtual void handleCallback (const ComPtr<IVirtualBoxCallback> &aCallback) = 0;
|
---|
547 |
|
---|
548 | private:
|
---|
549 |
|
---|
550 | /*
|
---|
551 | * Note that this is a weak ref -- the CallbackEvent handler thread
|
---|
552 | * is bound to the lifetime of the VirtualBox instance, so it's safe.
|
---|
553 | */
|
---|
554 | ComObjPtr<VirtualBox, ComWeakRef> mVirtualBox;
|
---|
555 | };
|
---|
556 |
|
---|
557 | #endif // ____H_VIRTUALBOXIMPL
|
---|
558 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|