26 #ifndef INCLUDED_DeviceInterface_h_GUID_A929799C_02F5_4C92_C503_36C7F59D6BA1
27 #define INCLUDED_DeviceInterface_h_GUID_A929799C_02F5_4C92_C503_36C7F59D6BA1
60 OSVR_IN_STRZ
const char *name) {
64 throw std::runtime_error(
"Could not register message type: " +
73 OSVR_IN std::string
const &name) {
75 throw std::runtime_error(
76 "Cannot register a message type with an empty name!");
81 #ifndef OSVR_DOXYGEN_EXTERNAL
83 template <
typename DeviceObjectType>
struct UpdateTrampoline {
84 static OSVR_ReturnCode update(
void *userData) {
86 return static_cast<DeviceObjectType *
>(userData)->update();
110 OSVR_IN_STRZ
const char *name,
119 throw std::runtime_error(
"Could not initialize device token: " +
126 OSVR_IN std::string
const &name,
129 throw std::runtime_error(
"Could not initialize device token "
130 "with an empty name field!");
132 initSync(ctx, name.c_str(), options);
138 OSVR_IN_STRZ
const char *name,
148 throw std::runtime_error(
"Could not initialize device token: " +
155 OSVR_IN std::string
const &name,
158 throw std::runtime_error(
"Could not initialize device token "
159 "with an empty name field!");
171 template <
typename InterfaceType,
typename MessageType>
172 void send(InterfaceType &iface, MessageType
const &msg,
174 iface.send(*
this, msg, timestamp);
179 template <
typename InterfaceType,
typename MessageType>
180 void send(InterfaceType &iface, MessageType
const &msg) {
191 OSVR_IN
size_t len) {
193 OSVR_ReturnCode ret =
196 throw std::runtime_error(
"Could not send JSON descriptor!");
211 throw std::runtime_error(
212 "Cannot send an empty JSON descriptor!");
222 template <
typename DeviceObjectType>
225 throw std::logic_error(
226 "Cannot register update callback for a null object!");
230 m_dev, &detail::UpdateTrampoline<DeviceObjectType>::update,
231 static_cast<void *>(
object));
233 throw std::runtime_error(
"Could not register update callback!");
252 OSVR_IN_READS(len)
const char *bytestream = NULL,
253 OSVR_IN
size_t len = 0) {
255 OSVR_ReturnCode ret =
258 throw std::runtime_error(
"Could not send data!");
268 sendData(msg, bytestream, N);
273 OSVR_IN std::string
const &bytestream) {
274 if (bytestream.empty()) {
277 sendData(msg, bytestream.data(), bytestream.length());
283 OSVR_IN std::vector<char>
const &bytestream) {
284 if (bytestream.empty()) {
287 sendData(msg, bytestream.data(), bytestream.size());
307 OSVR_IN_READS(len)
const char *bytestream = NULL,
308 OSVR_IN
size_t len = 0) {
310 m_dev, ×tamp, msg, bytestream, len);
312 throw std::runtime_error(
"Could not send data!");
323 sendData(timestamp, msg, bytestream, N);
329 OSVR_IN std::string
const &bytestream) {
330 if (bytestream.empty()) {
331 sendData(timestamp, msg);
333 sendData(timestamp, msg, bytestream.data(),
334 bytestream.length());
341 OSVR_IN std::vector<char>
const &bytestream) {
342 if (bytestream.empty()) {
343 sendData(timestamp, msg);
345 sendData(timestamp, msg, bytestream.data(), bytestream.size());
353 void m_validateToken()
const {
355 throw std::logic_error(
"Attempting an operation on a device "
356 "token that is not yet initialized!");
366 #endif // INCLUDED_DeviceInterface_h_GUID_A929799C_02F5_4C92_C503_36C7F59D6BA1
OSVR_ReturnCode osvrDeviceAsyncInit(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceToken *device)
Initialize an asynchronous device token.
DeviceToken(OSVR_DeviceToken device)
Constructor wrapping an existing device token.
Wrapper class for OSVR_DeviceToken.
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.
OSVR_MessageType registerMessageType(OSVR_PluginRegContext ctx, const char *name)
Register or recall a message type by name.
void sendData(OSVR_TimeValue const ×tamp, OSVR_MessageType msg, std::vector< char > const &bytestream)
void sendJsonDescriptor(std::string const &json)
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
The main namespace for all C++ elements of the framework, internal and external.
void sendData(OSVR_TimeValue const ×tamp, OSVR_MessageType msg, std::string const &bytestream)
void send(InterfaceType &iface, MessageType const &msg)
void initAsync(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceInitOptions options=NULL)
Initialize this device token as asynchronous, with the given name and options.
void initSync(OSVR_PluginRegContext ctx, std::string const &name, OSVR_DeviceInitOptions options=NULL)
void send(InterfaceType &iface, MessageType const &msg, OSVR_TimeValue const ×tamp)
Send a message on a registered interface type, providing the timestamp yourself.
void sendData(OSVR_MessageType msg, std::string const &bytestream)
void sendData(OSVR_TimeValue const ×tamp, OSVR_MessageType msg, const char(&bytestream)[N])
void sendData(OSVR_TimeValue const ×tamp, OSVR_MessageType msg, const char *bytestream=NULL, size_t len=0)
Sends a raw bytestream from your device with a known timestamp.
OSVR_ReturnCode osvrDeviceAsyncInitWithOptions(OSVR_PluginRegContext ctx, 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=NULL)
Register the update callback of a device.
DeviceToken()
Default constructor.
struct OSVR_DeviceTokenObject * OSVR_DeviceToken
Opaque type of a registered device token within the core library.
struct OSVR_MessageTypeObject * OSVR_MessageType
Opaque type of a registered message type within the core library.
void initAsync(OSVR_PluginRegContext ctx, std::string const &name, OSVR_DeviceInitOptions options=NULL)
struct OSVR_DeviceInitObject * OSVR_DeviceInitOptions
Opaque type of a device initialization object.
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.
void sendData(OSVR_MessageType msg, const char(&bytestream)[N])
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 ctx, const char *name, OSVR_DeviceInitOptions options, OSVR_DeviceToken *device)
Initialize a synchronous device token.
void registerUpdateCallback(DeviceObjectType *object)
Given a pointer to your object that has a public OSVR_ReturnCode update() method, registers that inst...
void sendJsonDescriptor(const char(&json)[N])
Header providing a C++ wrapper around TimeValueC.h.
void initSync(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceInitOptions options=NULL)
Initialize this device token as synchronous, with the given name and options.
void sendData(OSVR_MessageType msg, std::vector< char > const &bytestream)
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 osvrDeviceSyncInit(OSVR_PluginRegContext ctx, const char *name, OSVR_DeviceToken *device)
Initialize a synchronous device token.
void sendJsonDescriptor(const char *json, size_t len)
Submit a JSON self-descriptor string for the device.
OSVR_ReturnCode osvrDeviceRegisterMessageType(OSVR_PluginRegContext ctx, const char *name, OSVR_MessageType *msgtype)
Register (or recall) a message type by name.