25 #define OSVR_DEV_VERBOSE_DISABLE
32 #include <boost/range/adaptor/reversed.hpp>
38 namespace pluginhost {
42 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContextImpl:\t"
43 <<
"Creating a plugin registration context for "
49 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContextImpl:\t"
50 "Destroying plugin reg context for "
54 for (
auto &ptr : m_dataList | boost::adaptors::reversed) {
61 libfunc::PluginHandle &handle) {
67 if (m_parent !=
nullptr && m_parent != &parent) {
68 throw std::logic_error(
69 "Can't set the registration context parent - already set!");
75 if (m_parent ==
nullptr) {
76 throw std::logic_error(
77 "Can't access the registration context parent - it is null!");
84 if (m_parent ==
nullptr) {
85 throw std::logic_error(
86 "Can't access the registration context parent - it is null!");
93 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContext:\t"
94 "In triggerHardwareDetectCallbacks for "
97 for (
auto const &f : m_hardwareDetectCallbacks) {
103 const std::string &driverName,
const std::string ¶ms)
const {
104 auto it = m_driverInstantiationCallbacks.find(driverName);
105 if (it == end(m_driverInstantiationCallbacks)) {
106 throw std::logic_error(
"No driver initialization callback was "
107 "registered for the driver name " +
110 OSVR_ReturnCode ret = (it->second)(params.c_str());
112 throw std::runtime_error(
"Failure returned from driver "
113 "initialization callback by name " +
120 m_dataList.emplace_back(pluginData, deleteCallback);
121 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContext:\t"
124 <<
" data delete callbacks registered for "
130 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContext:\t"
131 "In registerHardwareDetectCallback");
132 m_hardwareDetectCallbacks.emplace_back(detectCallback, userData);
133 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContext:\t"
135 << m_hardwareDetectCallbacks.size()
136 <<
" hardware detect callbacks registered for "
144 OSVR_DEV_VERBOSE(
"PluginSpecificRegistrationContext:\t"
145 "In registerDriverInstantiationCallback");
148 throw std::logic_error(
"Cannot register a driver instantiation "
149 "callback with an empty name!");
151 using namespace std::placeholders;
152 auto it = m_driverInstantiationCallbacks.find(name);
153 if (it != end(m_driverInstantiationCallbacks)) {
154 throw std::logic_error(
"A driver initialization callback by this "
155 "name for this plugin has already been "
159 m_driverInstantiationCallbacks[name] =
160 [constructor, opaque, userData](
const char *params) {
161 return constructor(opaque, params, userData);
void setParent(RegistrationContext &parent)
Set parent registration context.
virtual void registerDriverInstantiationCallback(const char *name, OSVR_DriverInstantiationCallback constructor, void *userData)
Register a callback for constructing a driver by name with parameters.
Class responsible for hosting plugins, along with their registration and destruction.
virtual util::AnyMap & data()
Access the data storage map.
void instantiateDriver(const std::string &driverName, const std::string ¶ms=std::string()) const
Call a driver instantiation callback for the given driver name.
Class providing the external interface of a registration context backing a single plugin...
const std::string & getName() const
Accessor for plugin name.
void(* OSVR_PluginDataDeleteCallback)(void *pluginData)
Function type of a Plugin Data Delete callback.
A data structure storing "any" by name, to reduce coupling.
OSVR_ReturnCode(* OSVR_HardwareDetectCallback)(OSVR_PluginRegContext ctx, void *userData)
Function type of a Hardware Detect callback.
void takePluginHandle(libfunc::PluginHandle &handle)
Assume ownership of the plugin handle keeping the plugin library loaded.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
void triggerHardwareDetectCallbacks()
Call all hardware detect callbacks registered by this plugin, if any.
virtual RegistrationContext & getParent()
Get parent registration context.
OSVR_PluginRegContext extractOpaquePointer()
Extracts the opaque pointer for this interface to send to C.
~PluginSpecificRegistrationContextImpl()
Destructor.
PluginSpecificRegistrationContextImpl(std::string const &name)
Constructor.
OSVR_ReturnCode(* OSVR_DriverInstantiationCallback)(OSVR_PluginRegContext ctx, const char *params, void *userData)
Function type of a driver instantiation callback.
virtual void registerHardwareDetectCallback(OSVR_HardwareDetectCallback detectCallback, void *userData)
Register a callback to be invoked on some hardware detection event.
Internal, configured header file for verbosity macros.
virtual void registerDataWithDeleteCallback(OSVR_PluginDataDeleteCallback deleteCallback, void *pluginData)
Register data and a delete callback to be called on plugin unload.