185
173
STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
186
174
BSTR *aChanged, BSTR *aValues);
188
STDMETHOD(SaveSettings)();
189
STDMETHOD(SaveSettingsWithBackup) (BSTR *aBakFileName);
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);
197
182
/* public methods only for internal purposes */
199
HRESULT postEvent (Event *event);
201
HRESULT addProgress (IProgress *aProgress);
202
HRESULT removeProgress (IN_GUID aId);
184
void dumpAllBackRefs();
187
HRESULT postEvent(Event *event);
189
HRESULT addProgress(IProgress *aProgress);
190
HRESULT removeProgress(IN_GUID aId);
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);
212
200
void addProcessToReap (RTPROCESS pid);
213
201
void updateClientWatcher();
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,
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);
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,
229
ComObjPtr <GuestOSType> getUnknownOSType();
231
void getOpenedMachines (SessionMachineVector &aMachines,
232
InternalControlVector *aControls = NULL);
234
/** Shortcut to #getOpenedMachines (aMachines, &aControls). */
235
void getOpenedMachinesAndControls (SessionMachineVector &aMachines,
236
InternalControlVector &aControls)
237
{ getOpenedMachines (aMachines, &aControls); }
239
bool isMachineIdValid (const Guid &aId)
208
void onMachineRegistered(const Guid &aId, BOOL aRegistered);
209
void onSessionStateChange(const Guid &aId, SessionState_T aState);
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,
217
ComObjPtr<GuestOSType> getUnknownOSType();
219
void getOpenedMachines(SessionMachineList &aMachines,
220
InternalControlList *aControls = NULL);
222
bool isMachineIdValid(const Guid &aId)
241
return SUCCEEDED (findMachine (aId, false /* aSetError */, NULL));
224
return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
244
227
HRESULT findMachine (const Guid &aId, bool aSetError,
245
ComObjPtr <Machine> *machine = NULL);
228
ComObjPtr<Machine> *machine = NULL);
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);
254
const ComObjPtr <Host> &host() { return mData.mHost; }
255
const ComObjPtr <SystemProperties> &systemProperties()
256
{ return mData.mSystemProperties; }
235
bool aSetError, ComObjPtr<Medium> *aImage = NULL);
237
HRESULT findGuestOSType(CBSTR bstrOSType,
238
GuestOSType*& pGuestOSType);
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 */
246
const Utf8Str& getDefaultMachineFolder() const;
247
const Utf8Str& getDefaultHardDiskFolder() const;
248
const Utf8Str& getDefaultHardDiskFormat() const;
263
250
/** Returns the VirtualBox home directory */
264
const Utf8Str &homeDir() { return mData.mHomeDir; }
266
int calculateFullPath (const char *aPath, Utf8Str &aResult);
267
void calculateRelativePath (const char *aPath, Utf8Str &aResult);
269
HRESULT registerHardDisk(HardDisk *aHardDisk, bool aSaveRegistry = true);
270
HRESULT unregisterHardDisk(HardDisk *aHardDisk, bool aSaveRegistry = true);
272
HRESULT registerDVDImage(DVDImage *aImage, bool aSaveRegistry = true);
273
HRESULT unregisterDVDImage(DVDImage *aImage, bool aSaveRegistry = true);
275
HRESULT registerFloppyImage (FloppyImage *aImage, bool aSaveRegistry = true);
276
HRESULT unregisterFloppyImage (FloppyImage *aImage, bool aSaveRegistry = true);
278
HRESULT cast (IHardDisk *aFrom, ComObjPtr<HardDisk> &aTo);
251
const Utf8Str& homeDir() const;
253
int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
254
void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
256
HRESULT registerHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
257
HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
259
HRESULT registerDVDImage(Medium *aImage, bool aSaveRegistry = true);
260
HRESULT unregisterDVDImage(Medium *aImage, bool aSaveRegistry = true);
262
HRESULT registerFloppyImage (Medium *aImage, bool aSaveRegistry = true);
263
HRESULT unregisterFloppyImage (Medium *aImage, bool aSaveRegistry = true);
265
HRESULT cast (IMedium *aFrom, ComObjPtr<Medium> &aTo);
280
267
HRESULT saveSettings();
281
HRESULT updateSettings (const char *aOldPath, const char *aNewPath);
283
const Bstr &settingsFileName() { return mData.mCfgFile.mName; }
285
static HRESULT ensureFilePathExists (const char *aFileName);
287
static HRESULT loadSettingsTree (settings::XmlTreeBackend &aTree,
290
bool aCatchLoadErrors,
292
Utf8Str *aFormatVersion = NULL);
295
* Shortcut to loadSettingsTree (aTree, aFile, true, true, true).
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.
300
* @param aFormatVersion Where to store the current format version of the
301
* loaded settings tree.
303
static HRESULT loadSettingsTree_FirstTime (settings::XmlTreeBackend &aTree,
305
Utf8Str &aFormatVersion)
307
return loadSettingsTree (aTree, aFile, true, true, true,
312
* Shortcut to loadSettingsTree (aTree, aFile, true, false, true).
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
319
static HRESULT loadSettingsTree_Again (settings::XmlTreeBackend &aTree,
322
return loadSettingsTree (aTree, aFile, true, false, true);
326
* Shortcut to loadSettingsTree (aTree, aFile, true, false, false).
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.
332
static HRESULT loadSettingsTree_ForUpdate (settings::XmlTreeBackend &aTree,
335
return loadSettingsTree (aTree, aFile, true, false, false);
338
static HRESULT saveSettingsTree (settings::TreeBackend &aTree,
340
Utf8Str &aFormatVersion);
342
static HRESULT backupSettingsFile (const Bstr &aFileName,
343
const Utf8Str &aOldFormat,
268
HRESULT updateSettings(const char *aOldPath, const char *aNewPath);
270
static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
346
272
static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
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
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.
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
362
RWLockHandle *hardDiskTreeLockHandle() { return &mHardDiskTreeLockHandle; }
274
const Utf8Str& settingsFilePath();
276
RWLockHandle& hardDiskTreeLockHandle();
277
RWLockHandle* childrenLock();
364
279
/* for VirtualBoxSupportErrorInfoImpl */
365
280
static const wchar_t *getComponentName() { return L"VirtualBox"; }
369
typedef std::list <ComObjPtr <Machine> > MachineList;
370
typedef std::list <ComObjPtr <GuestOSType> > GuestOSTypeList;
372
typedef std::map <Guid, ComPtr <IProgress> > ProgressMap;
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;
380
typedef std::map <Guid, ComObjPtr<HardDisk> > HardDiskMap;
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.
390
RWLockHandle *childrenLock() { return &mChildrenMapLockHandle; }
392
HRESULT checkMediaForConflicts2 (const Guid &aId, const Bstr &aLocation,
393
Utf8Str &aConflictType);
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);
399
287
HRESULT registerMachine (Machine *aMachine);
401
289
HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
402
bool aSaveRegistry = true);
290
bool aSaveRegistry = true);
403
291
HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
404
bool aSaveRegistry = true);
406
HRESULT lockConfig();
407
HRESULT unlockConfig();
409
/** @note This method is not thread safe */
410
bool isConfigLocked() { return mData.mCfgFile.mHandle != NIL_RTFILE; }
413
* Main VirtualBox data structure.
414
* @note |const| members are persistent during lifetime so can be accessed
423
CfgFile() : mHandle (NIL_RTFILE) {}
427
/** Flag indicating that the config file is read-only. */
431
// const data members not requiring locking
432
const Utf8Str mHomeDir;
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 */
443
Utf8Str mSettingsFileVersion;
445
MachineList mMachines;
446
GuestOSTypeList mGuestOSTypes;
448
ProgressMap mProgressOperations;
450
HardDiskList mHardDisks;
451
DVDImageList mDVDImages;
452
FloppyImageList mFloppyImages;
453
SharedFolderList mSharedFolders;
454
DHCPServerList mDHCPServers;
456
/// @todo NEWMEDIA do we really need this map? Used only in
458
HardDiskMap mHardDiskMap;
460
CallbackList mCallbacks;
465
/** Client watcher thread data structure */
466
struct ClientWatcherData
469
#if defined(RT_OS_WINDOWS)
471
#elif defined(RT_OS_OS2)
472
: mUpdateReq (NIL_RTSEMEVENT)
473
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
474
: mUpdateReq (NIL_RTSEMEVENT)
478
, mThread (NIL_RTTHREAD) {}
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;
490
const RTTHREAD mThread;
492
typedef std::list <RTPROCESS> ProcessList;
493
ProcessList mProcesses;
496
ClientWatcherData mWatcherData;
498
const RTTHREAD mAsyncEventThread;
499
EventQueue * const mAsyncEventQ;
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:
506
* - mProgressOperations
508
RWLockHandle mSafeLock;
510
RWLockHandle mHardDiskTreeLockHandle;
511
RWLockHandle mChildrenMapLockHandle;
292
bool aSaveRegistry = true);
294
struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
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;
518
302
static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
519
303
static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);