~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Main/include/VirtualBoxImpl.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

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