OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
PluginRegistrationC.cpp
Go to the documentation of this file.
1 
12 // Copyright 2014 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 // Internal Includes
28 #include "HandleNullContext.h"
29 #include <osvr/Util/Verbosity.h>
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 #include <iostream>
37 
39  OSVR_INOUT_PTR OSVR_PluginRegContext ctx,
40  OSVR_IN OSVR_HardwareDetectCallback detectCallback,
41  OSVR_IN_OPT void *userData) {
42  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrPluginRegisterHardwareDetectCallback",
43  ctx);
44 
45  try {
47  .registerHardwareDetectCallback(detectCallback, userData);
48  } catch (std::exception &e) {
49  std::cerr << "Error in osvrPluginRegisterHardwareDetectCallback - "
50  "caught exception reporting: " << e.what() << std::endl;
51  return OSVR_RETURN_FAILURE;
52  }
53  return OSVR_RETURN_SUCCESS;
54 }
55 
57  OSVR_INOUT_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name,
58  OSVR_IN_PTR OSVR_DriverInstantiationCallback cb,
59  OSVR_IN_OPT void *userData) {
60  try {
62  .registerDriverInstantiationCallback(name, cb, userData);
63  } catch (std::exception &e) {
64  std::cerr << "Error in osvrRegisterDriverInstantiationCallback - "
65  "caught exception reporting: " << e.what() << std::endl;
66  return OSVR_RETURN_FAILURE;
67  }
68  return OSVR_RETURN_SUCCESS;
69 }
70 
72  OSVR_INOUT_PTR OSVR_PluginRegContext ctx,
73  OSVR_IN OSVR_PluginDataDeleteCallback deleteCallback,
74  OSVR_INOUT_PTR void *pluginData) {
75  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrPluginRegisterDataWithDeleteCallback",
76  ctx);
79  context->registerDataWithDeleteCallback(deleteCallback, pluginData);
80  return OSVR_RETURN_SUCCESS;
81 }
82 
83 void osvrPluginLog(OSVR_INOUT_PTR OSVR_PluginRegContext ctx,
84  OSVR_IN OSVR_LogLevel severity,
85  OSVR_IN const char *message) {
86  if (!ctx) {
87  std::cerr << "[OSVR] " << message << std::endl;
88  return;
89  }
90 
93  auto s = static_cast<osvr::util::log::LogLevel>(severity);
94  context->log(s, message);
95 }
96 
OSVR_ReturnCode osvrPluginRegisterHardwareDetectCallback(OSVR_PluginRegContext ctx, OSVR_HardwareDetectCallback detectCallback, void *userData)
Register a callback in your plugin to be notified when hardware should be detected again...
virtual void registerDriverInstantiationCallback(const char *name, OSVR_DriverInstantiationCallback constructor, void *userData)=0
Register a callback for constructing a driver by name with parameters.
Class providing the external interface of a registration context backing a single plugin...
void(* OSVR_PluginDataDeleteCallback)(void *pluginData)
Function type of a Plugin Data Delete callback.
OSVR_ReturnCode osvrRegisterDriverInstantiationCallback(OSVR_PluginRegContext ctx, const char *name, OSVR_DriverInstantiationCallback cb, void *userData)
Register an instantiation callback (constructor) for a driver type. The given constructor may be call...
virtual void registerHardwareDetectCallback(OSVR_HardwareDetectCallback detectCallback, void *userData)=0
Register a callback to be invoked on some hardware detection event.
#define OSVR_PLUGIN_HANDLE_NULL_CONTEXT(FUNC, CONTEXT_NAME)
Internal macro for use in C API function implementations to check the validity of a context parameter...
OSVR_ReturnCode(* OSVR_HardwareDetectCallback)(OSVR_PluginRegContext ctx, void *userData)
Function type of a Hardware Detect callback.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
void osvrPluginLog(OSVR_PluginRegContext ctx, OSVR_LogLevel severity, const char *message)
Log a message to the plugin's log channel.
void log(util::log::LogLevel severity, const char *message)
Log a message to the plugin-specific channel.
OSVR_ReturnCode(* OSVR_DriverInstantiationCallback)(OSVR_PluginRegContext ctx, const char *params, void *userData)
Function type of a driver instantiation callback.
OSVR_LogLevel
Log message severity levels.
Definition: LogLevelC.h:44
virtual void registerDataWithDeleteCallback(OSVR_PluginDataDeleteCallback deleteCallback, void *pluginData)=0
Register data and a delete callback to be called on plugin unload.
Internal, configured header file for verbosity macros.
OSVR_ReturnCode osvrPluginRegisterDataWithDeleteCallback(OSVR_PluginRegContext ctx, OSVR_PluginDataDeleteCallback deleteCallback, void *pluginData)
Register plugin data along with an appropriate deleter callback.
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin's entry point and other locations of control flow transfer...
static PluginSpecificRegistrationContext & get(OSVR_PluginRegContext ctx)
Retrieve this interface from an OSVR_PluginRegContext opaque pointer.