OSVR-Core
PluginSpecificRegistrationContext.h
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_PluginSpecificRegistrationContext_h_GUID_8C008527_0BF6_408F_3C73_4FE76B77D856
26 #define INCLUDED_PluginSpecificRegistrationContext_h_GUID_8C008527_0BF6_408F_3C73_4FE76B77D856
27 
28 // Internal Includes
29 #include <osvr/PluginHost/Export.h>
35 #include <osvr/Util/SharedPtr.h>
36 #include <osvr/Util/AnyMap_fwd.h>
38 #include <osvr/Util/LogLevel.h>
39 #include <osvr/Util/Logger.h>
40 
41 // Library/third-party includes
42 #include <boost/noncopyable.hpp>
43 
44 // Standard includes
45 #include <string>
46 
47 namespace osvr {
48 namespace pluginhost {
49 
52  class PluginSpecificRegistrationContext : boost::noncopyable {
53  public:
63  OSVR_PLUGINHOST_EXPORT static PluginRegPtr
64  create(std::string const &name);
65 
68  OSVR_PLUGINHOST_EXPORT static PluginSpecificRegistrationContext &
69  get(OSVR_PluginRegContext ctx);
70 
72  OSVR_PLUGINHOST_EXPORT OSVR_PluginRegContext extractOpaquePointer();
73 
75  OSVR_PLUGINHOST_EXPORT virtual ~PluginSpecificRegistrationContext();
76 
80  OSVR_PLUGINHOST_EXPORT virtual RegistrationContext &getParent() = 0;
81 
85  OSVR_PLUGINHOST_EXPORT virtual RegistrationContext const &
86  getParent() const = 0;
87 
89  OSVR_PLUGINHOST_EXPORT virtual util::AnyMap &data() = 0;
90 
92  OSVR_PLUGINHOST_EXPORT virtual util::AnyMap const &data() const = 0;
93 
98 
101  OSVR_PLUGINHOST_EXPORT virtual void registerDataWithDeleteCallback(
102  OSVR_PluginDataDeleteCallback deleteCallback, void *pluginData) = 0;
103 
106  template <typename T> T *registerDataWithGenericDelete(T *data) {
107  registerDataWithDeleteCallback(&::osvr::util::generic_deleter<T>,
108  static_cast<void *>(data));
109  return data;
110  }
111 
114  OSVR_PLUGINHOST_EXPORT virtual void registerHardwareDetectCallback(
115  OSVR_HardwareDetectCallback detectCallback, void *userData) = 0;
116 
127  OSVR_PLUGINHOST_EXPORT virtual void registerDriverInstantiationCallback(
128  const char *name, OSVR_DriverInstantiationCallback constructor,
129  void *userData) = 0;
131 
133  OSVR_PLUGINHOST_EXPORT const std::string &getName() const;
134 
139  OSVR_PLUGINHOST_EXPORT void log(util::log::LogLevel severity,
140  const char *message);
141 
142  protected:
144  PluginSpecificRegistrationContext(std::string const &name);
145 
146  private:
147  std::string const m_name;
148  osvr::util::log::LoggerPtr m_logger;
149  };
150 
151 } // namespace pluginhost
152 } // namespace osvr
153 
154 #endif // INCLUDED_PluginSpecificRegistrationContext_h_GUID_8C008527_0BF6_408F_3C73_4FE76B77D856
virtual OSVR_PLUGINHOST_EXPORT RegistrationContext & getParent()=0
Get parent registration context.
Header providing a templated deleter function.
Class responsible for hosting plugins, along with their registration and destruction.
Definition: RegistrationContext.h:53
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Class providing the external interface of a registration context backing a single plugin...
Definition: PluginSpecificRegistrationContext.h:52
Header declaring plugin callback types.
virtual OSVR_PLUGINHOST_EXPORT void registerHardwareDetectCallback(OSVR_HardwareDetectCallback detectCallback, void *userData)=0
Register a callback to be invoked on some hardware detection event.
Header forward-declaring PluginSpecificRegistrationContext.
Header to bring shared_ptr into the osvr namespace.
virtual OSVR_PLUGINHOST_EXPORT void registerDriverInstantiationCallback(const char *name, OSVR_DriverInstantiationCallback constructor, void *userData)=0
Register a callback for constructing a driver by name with parameters.
virtual OSVR_PLUGINHOST_EXPORT void registerDataWithDeleteCallback(OSVR_PluginDataDeleteCallback deleteCallback, void *pluginData)=0
Register data and a delete callback to be called on plugin unload.
A data structure storing "any" by name, to reduce coupling.
Definition: AnyMap.h:42
virtual OSVR_PLUGINHOST_EXPORT ~PluginSpecificRegistrationContext()
Destructor.
Definition: PluginSpecificRegistrationContext.cpp:39
LogLevel
Log message severity levels.
Definition: LogLevel.h:45
Header forward-declaring a concealed implementation class and specifying the smart pointer to hold it...
void(* OSVR_PluginDataDeleteCallback)(void *pluginData)
Function type of a Plugin Data Delete callback.
Definition: PluginCallbackTypesC.h:48
OSVR_ReturnCode(* OSVR_HardwareDetectCallback)(OSVR_PluginRegContext ctx, void *userData)
Function type of a Hardware Detect callback.
Definition: PluginCallbackTypesC.h:51
PluginSpecificRegistrationContext(std::string const &name)
Constructor for derived class use only.
Definition: PluginSpecificRegistrationContext.cpp:62
Header forward-declaring declaring osvr::util::AnyMap.
OSVR_PLUGINHOST_EXPORT void log(util::log::LogLevel severity, const char *message)
Log a message to the plugin-specific channel.
Definition: PluginSpecificRegistrationContext.cpp:66
OSVR_PLUGINHOST_EXPORT OSVR_PluginRegContext extractOpaquePointer()
Extracts the opaque pointer for this interface to send to C.
Definition: PluginSpecificRegistrationContext.cpp:54
Header.
Header declaring the opaque plugin registration context type.
Header to include for OSVR-internal usage of the logging mechanism: provides the needed definition of...
OSVR_PLUGINHOST_EXPORT const std::string & getName() const
Accessor for plugin name.
Definition: PluginSpecificRegistrationContext.cpp:58
T * registerDataWithGenericDelete(T *data)
Register data allocated with new to be deleted on plugin unload.
Definition: PluginSpecificRegistrationContext.h:106
OSVR_ReturnCode(* OSVR_DriverInstantiationCallback)(OSVR_PluginRegContext ctx, const char *params, void *userData)
Function type of a driver instantiation callback.
Definition: PluginCallbackTypesC.h:55
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin&#39;s entry point and other locations of control flow transfer...
Definition: PluginRegContextC.h:47
shared_ptr< PluginSpecificRegistrationContextImpl > PluginRegPtr
Pointer with ownership semantics for cleanup of plugins.
Definition: PluginRegPtr.h:33
virtual OSVR_PLUGINHOST_EXPORT util::AnyMap & data()=0
Access the data storage map.
static OSVR_PLUGINHOST_EXPORT PluginRegPtr create(std::string const &name)
Factory function that creates a plugin-specific registration context.
Definition: PluginSpecificRegistrationContext.cpp:42
Header forward-declaring RegistrationContext.