ILLIXR: Illinois Extended Reality Testbed
|
A service locator for ILLIXR. More...
#include <phonebook.hpp>
Classes | |
class | service |
A 'service' that can be registered in the phonebook. More... | |
Public Member Functions | |
template<typename specific_service > | |
void | register_impl (std::shared_ptr< specific_service > impl) |
Registers an implementation of baseclass for future calls to lookup. More... | |
template<typename specific_service > | |
std::shared_ptr< specific_service > | lookup_impl () const |
Look up an implementation of specific_service , which should be registered first. More... | |
A service locator for ILLIXR.
This will be explained through an exmaple: Suppose one dynamically-loaded plugin, A_plugin
, needs a service, B_service
, provided by another, B_plugin
. A_plugin
cannot statically construct a B_service
, because the implementation B_plugin
is dynamically loaded. However, B_plugin
can register an implementation of B_service
when it is loaded, and A_plugin
can lookup that implementation without knowing it.
B_service.hpp
in common
:
B_plugin.hpp
:
A_plugin.cpp
:
If the implementation of B_service
is not known to A_plugin
(the usual case), B_service should be an [abstract class][2]. In either case
B_serviceshould be in
common`, so both plugins can refer to it.
One could even selectively return a different implementation of B_service
depending on the caller (through the parameters), but we have not encountered the need for that yet.
|
inline |
Look up an implementation of specific_service
, which should be registered first.
Safe to be called from any thread.
Do not call delete
on the returned object; it is still managed by phonebook.
if | an implementation is not already registered. |
|
inline |
Registers an implementation of baseclass
for future calls to lookup.
Safe to be called from any thread.
The implementation will be owned by phonebook (phonebook calls delete
).