25 #define OSVR_DEV_VERBOSE_DISABLE
39 #include <boost/thread.hpp>
53 OSVR_IN_READS(len)
const char *bytestream,
56 "In osvrDeviceSendData, trying to send a message of length " << len);
59 dev->sendData(msg, bytestream, len);
68 "In osvrDeviceSendData, trying to send a timestamped message of length "
72 dev->sendData(*timestamp, msg, bytestream, len);
84 dev->setDeviceDescriptor(std::string(json, len));
90 OSVR_IN_STRZ
const char *name,
93 OSVR_DEV_VERBOSE(
"In osvrDeviceRegisterMessageType for a message named "
98 osvr::connection::Connection::retrieveConnection(
107 }
catch (std::exception &e) {
108 std::cerr <<
"Error in osvrDeviceRegisterMessageType: " << e.what()
117 template <
typename FactoryFunction>
118 inline static OSVR_ReturnCode
122 osvr::connection::DeviceTokenPtr dev = f(*options);
124 OSVR_DEV_VERBOSE(
"Device token factory returned a null "
125 "pointer - this shouldn't happen!");
135 }
catch (std::exception &e) {
136 std::cerr <<
"Error in osvrDeviceGenericInit: " << e.what()
145 template <
typename FactoryFunction>
146 inline static OSVR_ReturnCode
151 return osvrDeviceGenericInit(options, device, f);
154 template <
typename FactoryFunction>
155 inline static OSVR_ReturnCode
160 return osvrDeviceGenericInit(options, name, device, f);
164 OSVR_IN_STRZ
const char *name,
167 OSVR_DEV_VERBOSE(
"In osvrDeviceSyncInit for a device named " << name);
168 return osvrDeviceGenericInit(ctx, name, device,
173 OSVR_IN_STRZ
const char *name,
177 return osvrDeviceGenericInit(options, name, device,
185 OSVR_IN_OPT
void *userData) {
186 OSVR_DEV_VERBOSE(
"In osvrDeviceRegisterUpdateCallback");
188 "osvrDeviceRegisterUpdateCallback device token", dev);
189 dev->setUpdateCallback(
190 [updateCallback, userData] {
return updateCallback(userData); });
195 OSVR_IN_STRZ
const char *name,
198 OSVR_DEV_VERBOSE(
"In osvrDeviceAsyncInit for a device named " << name);
199 return osvrDeviceGenericInit(ctx, name, device,
200 OSVR_DeviceTokenObject::createAsyncDevice);
205 OSVR_IN_STRZ
const char *name,
209 return osvrDeviceGenericInit(options, name, device,
210 OSVR_DeviceTokenObject::createAsyncDevice);
214 boost::this_thread::sleep(boost::posix_time::microseconds(microseconds));
OSVR_ReturnCode osvrDeviceAsyncInit(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceToken *device)
Initialize an asynchronous device token.
Header providing C++ interface wrappers around functionality in PluginRegistrationC.h.
OSVR_ReturnCode osvrDeviceSendTimestampedData(OSVR_DeviceToken dev, const OSVR_TimeValue *timestamp, OSVR_MessageType msg, const char *bytestream, size_t len)
Send a raw bytestream from your device, with a known timestamp.
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
#define OSVR_PLUGIN_HANDLE_NULL_CONTEXT_CONSTRUCTOR(FUNC, CONTEXT_NAME)
Internal macro for use in C API function implementations to check the validity of a context parameter...
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
void setName(std::string const &n)
Set the (unqualified) name of the device to create.
Structure used internally to construct the desired type of device.
#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...
Base class for connection-specific message type registration.
OSVR_ReturnCode osvrDeviceAsyncInitWithOptions(OSVR_PluginRegContext, const char *name, OSVR_DeviceInitOptions options, OSVR_DeviceToken *device)
Initialize an asynchronous device token.
OSVR_ReturnCode osvrDeviceRegisterUpdateCallback(OSVR_DeviceToken dev, OSVR_DeviceUpdateCallback updateCallback, void *userData)
Register the update callback of a device.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
OSVR_ReturnCode osvrDeviceMicrosleep(uint64_t microseconds)
Request a thread sleep for at least the given number of microseconds. DO NOT use within a Sync plugin...
T * registerObjectForDeletion(OSVR_PluginRegContext ctx, T *obj)
Registers an object to be destroyed with delete when the plugin is unloaded.
OSVR_ReturnCode osvrDeviceSendData(OSVR_DeviceToken dev, OSVR_MessageType msg, const char *bytestream, size_t len)
Send a raw bytestream from your device.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
OSVR_DeviceInitOptions osvrDeviceCreateInitOptions(OSVR_PluginRegContext ctx)
Create a OSVR_DeviceInitOptions object.
OSVR_ReturnCode osvrDeviceSendJsonDescriptor(OSVR_DeviceToken dev, const char *json, size_t len)
Submit a JSON self-descriptor string for the device.
OSVR_ReturnCode osvrDeviceSyncInitWithOptions(OSVR_PluginRegContext, const char *name, OSVR_DeviceInitOptions options, OSVR_DeviceToken *device)
Initialize a synchronous device token.
void notifyToken(OSVR_DeviceTokenObject *dev)
Notify all those interested what the device token is.
unique_ptr< MessageType > MessageTypePtr
a uniquely-owned handle for holding a message type registration.
Internal, configured header file for verbosity macros.
T * registerDataWithGenericDelete(T *data)
Register data allocated with new to be deleted on plugin unload.
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...
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
OSVR_ReturnCode(* OSVR_DeviceUpdateCallback)(void *userData)
Function type of a Device Update callback.
static osvr::connection::DeviceTokenPtr createSyncDevice(osvr::connection::DeviceInitObject &init)
Creates a device token (and underlying ConnectionDevice) that has an update method that runs in the s...
OSVR_ReturnCode osvrDeviceSyncInit(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceToken *device)
Initialize a synchronous device token.
OSVR_ReturnCode osvrDeviceRegisterMessageType(OSVR_PluginRegContext ctx, const char *name, OSVR_MessageType *msgtype)
Register (or recall) a message type by name.
osvr::pluginhost::PluginSpecificRegistrationContext * getContext()
Retrieves the plugin context.
static PluginSpecificRegistrationContext & get(OSVR_PluginRegContext ctx)
Retrieve this interface from an OSVR_PluginRegContext opaque pointer.