26 #ifndef INCLUDED_DeviceInterface_h_GUID_A929799C_02F5_4C92_C503_36C7F59D6BA1 27 #define INCLUDED_DeviceInterface_h_GUID_A929799C_02F5_4C92_C503_36C7F59D6BA1 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 84 static OSVR_ReturnCode
update(
void *userData) {
86 return static_cast<DeviceObjectType *
>(userData)->
update();
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);
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!");
161 initAsync(ctx, name.c_str(), options);
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) {
193 OSVR_ReturnCode ret =
196 throw std::runtime_error(
"Could not send JSON descriptor!");
205 sendJsonDescriptor(json, N);
211 throw std::runtime_error(
212 "Cannot send an empty JSON descriptor!");
214 sendJsonDescriptor(json.c_str(), json.length());
222 template <
typename DeviceObjectType>
225 throw std::logic_error(
226 "Cannot register update callback for a null object!");
231 static_cast<void *>(
object));
233 throw std::runtime_error(
"Could not register update callback!");
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());
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_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceRegisterMessageType(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_OUT_PTR OSVR_MessageType *msgtype) OSVR_FUNC_NONNULL((1
Register (or recall) a message type by name.
#define OSVR_IN_STRZ
Indicates a null-terminated string function parameter that serves only as input.
Definition: AnnotationMacrosC.h:124
DeviceToken(OSVR_DeviceToken device)
Constructor wrapping an existing device token.
Definition: DeviceInterface.h:96
Wrapper class for OSVR_DeviceToken.
Definition: DeviceInterface.h:93
#define OSVR_IN_PTR
Indicates a required pointer (non-null) function parameter that serves only as input.
Definition: AnnotationMacrosC.h:108
#define OSVR_IN_OPT
Indicates a function parameter (pointer) that serves only as input, but is optional and might be NULL...
Definition: AnnotationMacrosC.h:116
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
Definition: DeviceInterface.h:83
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceSyncInitWithOptions(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_IN_PTR OSVR_DeviceInitOptions options, OSVR_OUT_PTR OSVR_DeviceToken *device) OSVR_FUNC_NONNULL((1
Initialize a synchronous device token.
void sendJsonDescriptor(OSVR_IN_READS(len) const char *json, OSVR_IN size_t len)
Submit a JSON self-descriptor string for the device.
Definition: DeviceInterface.h:190
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
Definition: TimeValue.h:51
static OSVR_ReturnCode update(void *userData)
Definition: DeviceInterface.h:84
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
void sendData(OSVR_IN OSVR_TimeValue const ×tamp, OSVR_MessageType msg, const char(&bytestream)[N])
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: DeviceInterface.h:321
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceSendTimestampedData(OSVR_IN_PTR OSVR_DeviceToken dev, OSVR_IN_PTR const OSVR_TimeValue *timestamp, OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN_READS(len) const char *bytestream, OSVR_IN size_t len) OSVR_FUNC_NONNULL((1
Send a raw bytestream from your device, with a known timestamp.
void sendData(OSVR_IN OSVR_TimeValue const ×tamp, OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN_READS(len) const char *bytestream=NULL, OSVR_IN size_t len=0)
Sends a raw bytestream from your device with a known timestamp.
Definition: DeviceInterface.h:305
void send(InterfaceType &iface, MessageType const &msg)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: DeviceInterface.h:180
OSVR_MessageType registerMessageType(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name)
Register or recall a message type by name.
Definition: DeviceInterface.h:59
void initSync(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_IN_OPT OSVR_DeviceInitOptions options=NULL)
Initialize this device token as synchronous, with the given name and options.
Definition: DeviceInterface.h:109
void send(InterfaceType &iface, MessageType const &msg, OSVR_TimeValue const ×tamp)
Send a message on a registered interface type, providing the timestamp yourself.
Definition: DeviceInterface.h:172
Structure used internally to construct the desired type of device.
Definition: DeviceInitObject.h:59
#define OSVR_IN_READS(NUM_ELEMENTS)
Indicates a buffer containing input with the specified number of elements.
Definition: AnnotationMacrosC.h:134
void sendData(OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN std::string const &bytestream)
Definition: DeviceInterface.h:272
void initSync(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN std::string const &name, OSVR_IN_OPT OSVR_DeviceInitOptions options=NULL)
Definition: DeviceInterface.h:125
Definition: newuoa.h:1888
Base class for connection-specific message type registration.
Definition: MessageType.h:38
void sendData(OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN std::vector< char > const &bytestream)
Definition: DeviceInterface.h:282
DeviceToken()
Default constructor.
Definition: DeviceInterface.h:99
struct OSVR_DeviceTokenObject * OSVR_DeviceToken
Opaque type of a registered device token within the core library.
Definition: DeviceInterfaceC.h:60
void initAsync(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_IN_OPT OSVR_DeviceInitOptions options=NULL)
Initialize this device token as asynchronous, with the given name and options.
Definition: DeviceInterface.h:137
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
void sendData(OSVR_MessageType msg, const char(&bytestream)[N])
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: DeviceInterface.h:267
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceRegisterUpdateCallback(OSVR_IN_PTR OSVR_DeviceToken dev, OSVR_IN OSVR_DeviceUpdateCallback updateCallback, OSVR_IN_OPT void *userData OSVR_CPP_ONLY(=NULL)) OSVR_FUNC_NONNULL((1))
Register the update callback of a device.
void sendJsonDescriptor(const char(&json)[N])
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: DeviceInterface.h:204
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceAsyncInitWithOptions(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_IN_PTR OSVR_DeviceInitOptions options, OSVR_OUT_PTR OSVR_DeviceToken *device) OSVR_FUNC_NONNULL((1
Initialize an asynchronous device token.
void sendJsonDescriptor(OSVR_IN std::string const &json)
Definition: DeviceInterface.h:209
Header providing a C++ wrapper around TimeValueC.h.
void initAsync(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN std::string const &name, OSVR_IN_OPT OSVR_DeviceInitOptions options=NULL)
Definition: DeviceInterface.h:154
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceAsyncInit(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_OUT_PTR OSVR_DeviceToken *device) OSVR_FUNC_NONNULL((1
Initialize an asynchronous device token.
void sendData(OSVR_IN OSVR_TimeValue const ×tamp, OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN std::string const &bytestream)
Definition: DeviceInterface.h:327
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceSyncInit(OSVR_IN_PTR OSVR_PluginRegContext ctx, OSVR_IN_STRZ const char *name, OSVR_OUT_PTR OSVR_DeviceToken *device) OSVR_FUNC_NONNULL((1
Initialize a synchronous device token.
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...
Definition: PluginRegContextC.h:47
#define OSVR_IN
Indicates a required function parameter that serves only as input.
Definition: AnnotationMacrosC.h:100
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
void sendData(OSVR_IN OSVR_TimeValue const ×tamp, OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN std::vector< char > const &bytestream)
Definition: DeviceInterface.h:339
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceSendData(OSVR_IN_PTR OSVR_DeviceToken dev, OSVR_IN_PTR OSVR_MessageType msg, OSVR_IN_READS(len) const char *bytestream, OSVR_IN size_t len) OSVR_FUNC_NONNULL((1
Send a raw bytestream from your device.
void registerUpdateCallback(OSVR_IN_PTR DeviceObjectType *object)
Given a pointer to your object that has a public OSVR_ReturnCode update() method, registers that inst...
Definition: DeviceInterface.h:223
OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceSendJsonDescriptor(OSVR_IN_PTR OSVR_DeviceToken dev, OSVR_IN_READS(len) const char *json, OSVR_IN size_t len) OSVR_FUNC_NONNULL((1
Submit a JSON self-descriptor string for the device.