VirtualBox

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

Last change on this file since 18719 was 18177, checked in by vboxsync, 16 years ago

Main: turn read/write param in OpenHardDisk into an enum

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.6 KB
Line 
1/* $Id: VirtualBoxImpl.h 18177 2009-03-24 13:21:12Z 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_GUID aId, IMachine **aMachine);
142 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
143 IN_GUID aId, IMachine **aMachine);
144 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
145 STDMETHOD(RegisterMachine) (IMachine *aMachine);
146 STDMETHOD(GetMachine) (IN_GUID aId, IMachine **aMachine);
147 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
148 STDMETHOD(UnregisterMachine) (IN_GUID 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, IHardDisk **aHardDisk);
154 STDMETHOD(GetHardDisk) (IN_GUID aId, IHardDisk **aHardDisk);
155 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IHardDisk **aHardDisk);
156
157 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_GUID aId,
158 IDVDImage **aDVDImage);
159 STDMETHOD(GetDVDImage) (IN_GUID aId, IDVDImage **aDVDImage);
160 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IDVDImage **aDVDImage);
161
162 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_GUID aId,
163 IFloppyImage **aFloppyImage);
164 STDMETHOD(GetFloppyImage) (IN_GUID 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_GUID aMachineId);
174 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_GUID aMachineId,
175 IN_BSTR aType, IN_BSTR aEnvironment,
176 IProgress **aProgress);
177 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_GUID 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
364private:
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 };
425
426 // const data members not requiring locking
427 const Utf8Str mHomeDir;
428
429 // const objects not requiring locking
430 const ComObjPtr <Host> mHost;
431 const ComObjPtr <SystemProperties> mSystemProperties;
432#ifdef VBOX_WITH_RESOURCE_USAGE_API
433 const ComObjPtr <PerformanceCollector> mPerformanceCollector;
434#endif /* VBOX_WITH_RESOURCE_USAGE_API */
435
436 CfgFile mCfgFile;
437
438 Utf8Str mSettingsFileVersion;
439
440 MachineList mMachines;
441 GuestOSTypeList mGuestOSTypes;
442
443 ProgressMap mProgressOperations;
444
445 HardDiskList mHardDisks;
446 DVDImageList mDVDImages;
447 FloppyImageList mFloppyImages;
448 SharedFolderList mSharedFolders;
449 DHCPServerList mDHCPServers;
450
451 /// @todo NEWMEDIA do we really need this map? Used only in
452 /// find() it seems
453 HardDiskMap mHardDiskMap;
454
455 CallbackList mCallbacks;
456 };
457
458 Data mData;
459
460 /** Client watcher thread data structure */
461 struct ClientWatcherData
462 {
463 ClientWatcherData()
464#if defined(RT_OS_WINDOWS)
465 : mUpdateReq (NULL)
466#elif defined(RT_OS_OS2)
467 : mUpdateReq (NIL_RTSEMEVENT)
468#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
469 : mUpdateReq (NIL_RTSEMEVENT)
470#else
471# error "Port me!"
472#endif
473 , mThread (NIL_RTTHREAD) {}
474
475 // const objects not requiring locking
476#if defined(RT_OS_WINDOWS)
477 const HANDLE mUpdateReq;
478#elif defined(RT_OS_OS2)
479 const RTSEMEVENT mUpdateReq;
480#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
481 const RTSEMEVENT mUpdateReq;
482#else
483# error "Port me!"
484#endif
485 const RTTHREAD mThread;
486
487 typedef std::list <RTPROCESS> ProcessList;
488 ProcessList mProcesses;
489 };
490
491 ClientWatcherData mWatcherData;
492
493 const RTTHREAD mAsyncEventThread;
494 EventQueue * const mAsyncEventQ;
495
496 /**
497 * "Safe" lock. May only be used if guaranteed that no other locks are
498 * requested while holding it and no functions that may do so are called.
499 * Currently, protects the following:
500 *
501 * - mProgressOperations
502 */
503 RWLockHandle mSafeLock;
504
505 RWLockHandle mHardDiskTreeLockHandle;
506 RWLockHandle mChildrenMapLockHandle;
507
508 static Bstr sVersion;
509 static ULONG sRevision;
510 static Bstr sPackageType;
511 static Bstr sSettingsFormatVersion;
512
513 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
514 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
515
516#ifdef RT_OS_WINDOWS
517 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
518#endif
519};
520
521////////////////////////////////////////////////////////////////////////////////
522
523/**
524 * Abstract callback event class to asynchronously call VirtualBox callbacks
525 * on a dedicated event thread. Subclasses reimplement #handleCallback()
526 * to call appropriate IVirtualBoxCallback methods depending on the event
527 * to be dispatched.
528 *
529 * @note The VirtualBox instance passed to the constructor is strongly
530 * referenced, so that the VirtualBox singleton won't be released until the
531 * event gets handled by the event thread.
532 */
533class VirtualBox::CallbackEvent : public Event
534{
535public:
536
537 CallbackEvent (VirtualBox *aVirtualBox) : mVirtualBox (aVirtualBox)
538 {
539 Assert (aVirtualBox);
540 }
541
542 void *handler();
543
544 virtual void handleCallback (const ComPtr <IVirtualBoxCallback> &aCallback) = 0;
545
546private:
547
548 /*
549 * Note that this is a weak ref -- the CallbackEvent handler thread
550 * is bound to the lifetime of the VirtualBox instance, so it's safe.
551 */
552 ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
553};
554
555#endif // ____H_VIRTUALBOXIMPL
556/* 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