VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxImpl.h@ 21087

Last change on this file since 21087 was 20842, checked in by vboxsync, 16 years ago

API and Frontends: change IVirtualBox::openHardDisk to allow modifying the image UUID and parent UUID on open

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.8 KB
Line 
1/* $Id: VirtualBoxImpl.h 20842 2009-06-23 14:48:10Z 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
43class Machine;
44class SessionMachine;
45class HardDisk;
46class DVDImage;
47class FloppyImage;
48class MachineCollection;
49class GuestOSType;
50class GuestOSTypeCollection;
51class SharedFolder;
52class Progress;
53class ProgressCollection;
54class Host;
55class SystemProperties;
56class DHCPServer;
57
58#ifdef RT_OS_WINDOWS
59class SVCHlpClient;
60#endif
61
62struct VMClientWatcherData;
63
64class ATL_NO_VTABLE VirtualBox :
65 public VirtualBoxBaseWithChildrenNEXT,
66 public VirtualBoxSupportErrorInfoImpl <VirtualBox, IVirtualBox>,
67 public VirtualBoxSupportTranslation <VirtualBox>,
68#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
74#endif
75{
76
77public:
78
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;
86
87 class CallbackEvent;
88 friend class CallbackEvent;
89
90 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualBox)
91
92 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
93
94 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
95 DECLARE_NOT_AGGREGATABLE(VirtualBox)
96
97 DECLARE_PROTECT_FINAL_CONSTRUCT()
98
99 BEGIN_COM_MAP(VirtualBox)
100 COM_INTERFACE_ENTRY(IDispatch)
101 COM_INTERFACE_ENTRY(ISupportErrorInfo)
102 COM_INTERFACE_ENTRY(IVirtualBox)
103 END_COM_MAP()
104
105 NS_DECL_ISUPPORTS
106
107 /* to postpone generation of the default ctor/dtor */
108 VirtualBox();
109 ~VirtualBox();
110
111 HRESULT FinalConstruct();
112 void FinalRelease();
113
114 /* public initializer/uninitializer for internal purposes only */
115 HRESULT init();
116 void uninit();
117
118 /* IVirtualBox properties */
119 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
120 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
121 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
122 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
123 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
124 STDMETHOD(COMGETTER(SettingsFileVersion)) (BSTR *aSettingsFileVersion);
125 STDMETHOD(COMGETTER(SettingsFormatVersion)) (BSTR *aSettingsFormatVersion);
126 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
127 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
128 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));
132 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
133 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
134 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
135 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
136 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
137
138 /* IVirtualBox methods */
139
140 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
141 IN_BSTR aId, IMachine **aMachine);
142 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
143 IN_BSTR aId, IMachine **aMachine);
144 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
145 STDMETHOD(RegisterMachine) (IMachine *aMachine);
146 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
147 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
148 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
149 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
150
151 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
152 IHardDisk **aHardDisk);
153 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
154 BOOL aSetImageId, IN_BSTR aImageId,
155 BOOL aSetParentId, IN_BSTR aParentId,
156 IHardDisk **aHardDisk);
157 STDMETHOD(GetHardDisk) (IN_BSTR aId, IHardDisk **aHardDisk);
158 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IHardDisk **aHardDisk);
159
160 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);
164
165 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);
169
170 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
171 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
172 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
173 STDMETHOD(GetNextExtraDataKey) (IN_BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
174 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
175 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
176 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
177 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
178 IN_BSTR aType, IN_BSTR aEnvironment,
179 IProgress **aProgress);
180 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
181
182 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
183 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
184
185 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
186 BSTR *aChanged, BSTR *aValues);
187
188 STDMETHOD(SaveSettings)();
189 STDMETHOD(SaveSettingsWithBackup) (BSTR *aBakFileName);
190
191// STDMETHOD(CreateDHCPServerForInterface) (/*IHostNetworkInterface * aIinterface, */IDHCPServer ** aServer);
192 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
193// STDMETHOD(FindDHCPServerForInterface) (IHostNetworkInterface * aIinterface, IDHCPServer ** aServer);
194 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
195 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
196
197 /* public methods only for internal purposes */
198
199 HRESULT postEvent (Event *event);
200
201 HRESULT addProgress (IProgress *aProgress);
202 HRESULT removeProgress (IN_GUID aId);
203
204#ifdef RT_OS_WINDOWS
205 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
206 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
207 HRESULT startSVCHelperClient (bool aPrivileged,
208 SVCHelperClientFunc aFunc,
209 void *aUser, Progress *aProgress);
210#endif
211
212 void addProcessToReap (RTPROCESS pid);
213 void updateClientWatcher();
214
215 void onMachineStateChange (const Guid &aId, MachineState_T aState);
216 void onMachineDataChange (const Guid &aId);
217 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
218 Bstr &aError);
219 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)
240 {
241 return SUCCEEDED (findMachine (aId, false /* aSetError */, NULL));
242 }
243
244 HRESULT findMachine (const Guid &aId, bool aSetError,
245 ComObjPtr <Machine> *machine = NULL);
246
247 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
248 bool aSetError, ComObjPtr<HardDisk> *aHardDisk = NULL);
249 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
250 bool aSetError, ComObjPtr<DVDImage> *aImage = NULL);
251 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; }
257#ifdef VBOX_WITH_RESOURCE_USAGE_API
258 const ComObjPtr <PerformanceCollector> &performanceCollector()
259 { return mData.mPerformanceCollector; }
260#endif /* VBOX_WITH_RESOURCE_USAGE_API */
261
262
263 /** 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);
279
280 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);
345
346 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
347
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; }
363
364 /* for VirtualBoxSupportErrorInfoImpl */
365 static const wchar_t *getComponentName() { return L"VirtualBox"; }
366
367private:
368
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);
398
399 HRESULT registerMachine (Machine *aMachine);
400
401 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
402 bool aSaveRegistry = true);
403 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
513 static Bstr sVersion;
514 static ULONG sRevision;
515 static Bstr sPackageType;
516 static Bstr sSettingsFormatVersion;
517
518 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
519 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
520
521#ifdef RT_OS_WINDOWS
522 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
523#endif
524};
525
526////////////////////////////////////////////////////////////////////////////////
527
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 */
538class VirtualBox::CallbackEvent : public Event
539{
540public:
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
551private:
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
560#endif // ____H_VIRTUALBOXIMPL
561/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette