OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AnalysisPluginKitC.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 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 // Internal Includes
32 #include <osvr/Util/MacroToolsC.h>
33 #include <osvr/Util/Verbosity.h>
34 #include "../Connection/VrpnConnectionKind.h"
35 
36 // Library/third-party includes
37 #include <vrpn_ConnectionPtr.h>
38 
39 // Standard includes
40 // - none
41 
43 #define OSVR_VALIDATE_OUTPUT_PTR(X, DESC) \
44  OSVR_UTIL_MULTILINE_BEGIN \
45  if (nullptr == (X)) { \
46  OSVR_DEV_VERBOSE("Passed a null pointer for output parameter " #X \
47  ", " DESC "!"); \
48  return OSVR_RETURN_FAILURE; \
49  } \
50  OSVR_UTIL_MULTILINE_END
51 
52 class vrpn_Connection;
53 
54 namespace {
55 inline vrpn_Connection *
56 extractVrpnConnection(osvr::connection::Connection &conn) {
57  vrpn_Connection *ret = nullptr;
58  if (std::string(conn.getConnectionKindID()) ==
59  osvr::connection::getVRPNConnectionKindID()) {
60  ret = static_cast<vrpn_Connection *>(conn.getUnderlyingObject());
61  }
62  return ret;
63 }
64 } // namespace
65 
66 OSVR_ReturnCode
68  OSVR_IN_STRZ const char *name,
69  OSVR_IN_PTR OSVR_DeviceInitOptions options,
70  OSVR_OUT_PTR OSVR_DeviceToken *device,
71  OSVR_OUT_PTR OSVR_ClientContext *clientCtx) {
72  if (!ctx) {
73  OSVR_DEV_VERBOSE("osvrAnalysisSyncInit: can't use a null plugin "
74  "registration context.");
75  return OSVR_RETURN_FAILURE;
76  }
77  if (!name || !(name[0])) {
78  OSVR_DEV_VERBOSE(
79  "osvrAnalysisSyncInit: can't use a null or empty device name.");
80  return OSVR_RETURN_FAILURE;
81  }
82  OSVR_VALIDATE_OUTPUT_PTR(device, "device token");
83  OSVR_VALIDATE_OUTPUT_PTR(clientCtx, "client context");
84 
85  auto initialResult =
86  osvrDeviceSyncInitWithOptions(ctx, name, options, device);
87  if (initialResult == OSVR_RETURN_FAILURE) {
88  OSVR_DEV_VERBOSE(
89  "osvrAnalysisSyncInit: couldn't create initial device token.");
90  return OSVR_RETURN_FAILURE;
91  }
92 
94  auto osvrConn = osvr::connection::Connection::retrieveConnection(
96  .getParent());
97  auto vrpnConn = extractVrpnConnection(*osvrConn);
98 
100 
102  auto clientCtxSmart = osvr::common::wrapSharedContext(
103  osvr::client::createAnalysisClientContext(
104  "org.osvr.analysisplugin" , "localhost" ,
105  vrpn_ConnectionPtr(vrpnConn)));
106  auto &dev = **device;
108  dev.acquireObject(clientCtxSmart);
109 
111  dev.setPreConnectionInteract([=] { clientCtxSmart->update(); });
112 
114  *clientCtx = clientCtxSmart.get();
115  return OSVR_RETURN_SUCCESS;
116 }
Header.
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
virtual void * getUnderlyingObject()
Access implementation details.
Definition: Connection.cpp:170
Class wrapping a messaging transport (server or internal) connection.
Definition: Connection.h:56
Structure used internally to construct the desired type of device.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
ClientContextSharedPtr wrapSharedContext(T *context)
Wrap a client context pointer in a shared pointer with the correct custom deleter.
#define OSVR_VALIDATE_OUTPUT_PTR(X, DESC)
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrDeviceSyncInitWithOptions(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceInitOptions options, OSVR_DeviceToken *device)
Initialize a synchronous device token.
virtual const char * getConnectionKindID()
Returns some implementation-defined string based on the dynamic type of the connection.
Definition: Connection.cpp:172
Internal, configured header file for verbosity macros.
Header containing basic macro tools.
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...
OSVR_ReturnCode osvrAnalysisSyncInit(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceInitOptions options, OSVR_DeviceToken *device, OSVR_ClientContext *clientCtx)
Initialize a synchronous analysis device token with the options specified, also returning the associa...
static PluginSpecificRegistrationContext & get(OSVR_PluginRegContext ctx)
Retrieve this interface from an OSVR_PluginRegContext opaque pointer.