From 9719499d6adca817ab6461d7cf009ef353c11d23 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 10:56:16 -0400 Subject: [PATCH 01/73] add gesture component --- inc/osvr/Common/GestureComponent.h | 137 ++++++++++++++++ src/osvr/Common/GestureComponent.cpp | 236 +++++++++++++++++++++++++++ 2 files changed, 373 insertions(+) create mode 100644 inc/osvr/Common/GestureComponent.h create mode 100644 src/osvr/Common/GestureComponent.cpp diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h new file mode 100644 index 000000000..89c6946b7 --- /dev/null +++ b/inc/osvr/Common/GestureComponent.h @@ -0,0 +1,137 @@ +/** @file + @brief Header + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA +#define INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA + +// Internal Includes +#include +#include +#include +#include +#include +#include +#include + +#include + +// Library/third-party includes +#include + +// Standard includes +// - none + +namespace osvr { +namespace common { + + struct GestureData { + OSVR_ChannelCount sensor; + OSVR_GestureState gestureState; + StringID gestureID; + }; + + struct GestureMap { + GestureData data; + SerializedStringMap serializedMap; + }; + + namespace messages { + class GestureRecord : public MessageRegistration { + public: + class MessageSerialization; + + static const char *identifier(); + }; + + class GestureMapRecord : public MessageRegistration { + public: + class MessageSerialization; + + static const char *identifier(); + }; + + } // namespace messages + + /// @brief BaseDevice component + class GestureComponent : public DeviceComponent { + public: + /// @brief Factory method + /// + /// Required to ensure that allocation and deallocation stay on the same + /// side of a DLL line. + static OSVR_COMMON_EXPORT shared_ptr + create(OSVR_ChannelCount numSensor = 1); + + void recordParent(Parent &dev); + + /// @brief Message from server to client, containing Gesture data. + messages::GestureRecord gestureRecord; + + /// @brief Message from server to client, containing gesture map + messages::GestureMapRecord gestureMapRecord; + + OSVR_COMMON_EXPORT void sendGestureData( + OSVR_GestureState gestureState, std::string const &gestureName, + OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); + + void m_sendGestureMap(OSVR_TimeValue const ×tamp); + + typedef std::function GestureHandler; + + typedef std::function + GestureMapHandler; + + OSVR_COMMON_EXPORT void registerGestureHandler(GestureHandler cb); + OSVR_COMMON_EXPORT void registerGestureMapHandler(GestureMapHandler cb); + + private: + GestureComponent(OSVR_ChannelCount numChan); + virtual void m_parentSet(); + + static int VRPN_CALLBACK + m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p); + static int VRPN_CALLBACK + m_handleGestureMapRecord(void *userdata, vrpn_HANDLERPARAM p); + + void m_checkFirst(OSVR_GestureState const &gesture); + + OSVR_ChannelCount m_numSensor; + std::vector m_cb; + std::vector m_cb_map; + + bool m_gotOne; + // name to ID map used by the server + RegisteredStringMap m_gestureNameMap; + + /// @brief Common component for system device + common::CommonComponent *m_commonComponent; + }; + +} // namespace common +} // namespace osvr + +#endif // INCLUDED_GestureComponent_h_GUID_F9F3BC3E_1DB2_498F_FD8E_273A269220DA diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp new file mode 100644 index 000000000..fc461ae49 --- /dev/null +++ b/src/osvr/Common/GestureComponent.cpp @@ -0,0 +1,236 @@ +/** @file + @brief Implementation + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include +#include +#include + +#include +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + +namespace osvr { +namespace common { + + namespace messages { + class GestureRecord::MessageSerialization { + public: + MessageSerialization(OSVR_GestureState const &state, + OSVR_GestureID gestureID, + OSVR_ChannelCount sensor) + : m_gestureState(state), m_gestureID(gestureID), + m_sensor(sensor) {} + + MessageSerialization() {} + + template void processMessage(T &p) { + p(m_gestureState); + p(m_gestureID); + p(m_sensor); + } + GestureData getData() const { + GestureData ret; + ret.sensor = m_sensor; + ret.gestureID = m_gestureID; + ret.gestureState = m_gestureState; + return ret; + } + + private: + OSVR_GestureState m_gestureState; + StringID m_gestureID; + OSVR_ChannelCount m_sensor; + }; + const char *GestureRecord::identifier() { + return "com.osvr.gesture.gesturerecord"; + } + + class GestureMapRecord::MessageSerialization { + public: + MessageSerialization(SerializedStringMap serializedMap) + : m_serializedMap(serializedMap) {} + + MessageSerialization() {} + + template void processMessage(T &p) { + p(m_serializedMap); + } + GestureMap getData() const { + GestureMap ret; + ret.serializedMap = m_serializedMap; + return ret; + } + + private: + SerializedStringMap m_serializedMap; + }; + const char *GestureMapRecord::identifier() { + return "com.osvr.gesture.gesturemaprecord"; + } + + } // namespace messages + + shared_ptr + GestureComponent::create(OSVR_ChannelCount numChan) { + shared_ptr ret(new GestureComponent(numChan)); + return ret; + } + + GestureComponent::GestureComponent(OSVR_ChannelCount numChan) + : m_numSensor(numChan) { + + // populate the gesture map + m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIP_LEFT); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIP_RIGHT); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_UP); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_DOWN); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SINGLE_TAP); + m_gestureNameMap.registerStringID(OSVR_GESTURE_DOUBLE_TAP); + m_gestureNameMap.registerStringID(OSVR_GESTURE_PINCH); + m_gestureNameMap.registerStringID(OSVR_GESTURE_FINGER_SPREAD); + m_gestureNameMap.registerStringID(OSVR_GESTURE_CIRCLE); + m_gestureNameMap.registerStringID(OSVR_GESTURE_LONG_PRESS); + m_gestureNameMap.registerStringID(OSVR_GESTURE_OPEN_HAND); + m_gestureNameMap.registerStringID(OSVR_GESTURE_CLOSED_HAND); + } + + void GestureComponent::recordParent(Parent &dev) { + BOOST_ASSERT_MSG(nullptr == m_parent, + "recordParent should only be called once!"); + m_parent = &dev; + m_parentSet(); + + // add a ping handler to re-send gesture map everytime the new + // connection(ping) occurs + m_commonComponent = + m_getParent().addComponent(osvr::common::CommonComponent::create()); + OSVR_TimeValue now; + osvrTimeValueGetNow(&now); + m_commonComponent->registerPingHandler([&] { m_sendGestureMap(now); }); + } + + void GestureComponent::sendGestureData(OSVR_GestureState gestureState, + std::string const &gestureName, + OSVR_ChannelCount sensor, + OSVR_TimeValue const ×tamp) { + + Buffer<> buf; + + StringID gestureID = m_gestureNameMap.getStringID(gestureName); + + // if we just inserted new gesture ID then send gesture map + if (m_gestureNameMap.isUpdateAvailable()) { + m_sendGestureMap(timestamp); + } + + messages::GestureRecord::MessageSerialization msg(gestureState, + gestureID, sensor); + serialize(buf, msg); + + m_getParent().packMessage(buf, gestureRecord.getMessageType(), + timestamp); + } + + void GestureComponent::m_sendGestureMap(OSVR_TimeValue const ×tamp) { + + Buffer<> buf; + + SerializedStringMap serializedMap = m_gestureNameMap.getMap(); + + messages::GestureMapRecord::MessageSerialization msg(serializedMap); + serialize(buf, msg); + + m_getParent().packMessage(buf, gestureMapRecord.getMessageType(), + timestamp); + } + + int VRPN_CALLBACK + GestureComponent::m_handleGestureRecord(void *userdata, + vrpn_HANDLERPARAM p) { + auto self = static_cast(userdata); + auto bufReader = readExternalBuffer(p.buffer, p.payload_len); + + messages::GestureRecord::MessageSerialization msg; + deserialize(bufReader, msg); + auto data = msg.getData(); + auto timestamp = util::time::fromStructTimeval(p.msg_time); + + for (auto const &cb : self->m_cb) { + cb(data, timestamp); + } + return 0; + } + + int VRPN_CALLBACK + GestureComponent::m_handleGestureMapRecord(void *userdata, + vrpn_HANDLERPARAM p) { + auto self = static_cast(userdata); + auto bufwrap = ExternalBufferReadingWrapper( + reinterpret_cast(p.buffer), p.payload_len); + auto bufReader = BufferReader(bufwrap); + + messages::GestureMapRecord::MessageSerialization msg; + deserialize(bufReader, msg); + auto data = msg.getData(); + auto timestamp = util::time::fromStructTimeval(p.msg_time); + + for (auto const &cb : self->m_cb_map) { + cb(data, timestamp); + } + return 0; + } + + void GestureComponent::registerGestureHandler(GestureHandler handler) { + if (m_cb.empty()) { + m_registerHandler(&GestureComponent::m_handleGestureRecord, this, + gestureRecord.getMessageType()); + } + m_cb.push_back(handler); + } + void + GestureComponent::registerGestureMapHandler(GestureMapHandler handler) { + if (m_cb_map.empty()) { + m_registerHandler(&GestureComponent::m_handleGestureMapRecord, this, + gestureMapRecord.getMessageType()); + } + m_cb_map.push_back(handler); + } + + void GestureComponent::m_parentSet() { + m_getParent().registerMessageType(gestureRecord); + m_getParent().registerMessageType(gestureMapRecord); + } + +} // namespace common +} // namespace osvr \ No newline at end of file From c7a1fd5c98b5a383b794ee483bdbefa06f227cff Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 10:59:23 -0400 Subject: [PATCH 02/73] update cmake build for common (include gesture and registeredstringmap) --- src/osvr/Common/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/osvr/Common/CMakeLists.txt b/src/osvr/Common/CMakeLists.txt index 4dd0aace9..48dece48e 100644 --- a/src/osvr/Common/CMakeLists.txt +++ b/src/osvr/Common/CMakeLists.txt @@ -62,6 +62,7 @@ set(API "${HEADER_LOCATION}/Endianness.h" "${HEADER_LOCATION}/EyeTrackerComponent.h" "${HEADER_LOCATION}/GeneralizedTransform.h" + "${HEADER_LOCATION}/GestureComponent.h" "${HEADER_LOCATION}/GetEnvironmentVariable.h" "${HEADER_LOCATION}/ImagingComponent.h" "${CMAKE_CURRENT_BINARY_DIR}/ImagingComponentConfig.h" @@ -105,6 +106,7 @@ set(API "${HEADER_LOCATION}/ReportStateTraits.h" "${HEADER_LOCATION}/ReportTraits.h" "${HEADER_LOCATION}/ReportTypes.h" + "${HEADER_LOCATION}/RegisteredStringMap.h" "${HEADER_LOCATION}/ResolveFullTree.h" "${HEADER_LOCATION}/ResolveTreeNode.h" "${HEADER_LOCATION}/RouteContainer.h" @@ -141,6 +143,7 @@ set(SOURCE DirectionComponent.cpp EyeTrackerComponent.cpp GeneralizedTransform.cpp + GestureComponent.cpp GetEnvironmentVariable.cpp GetJSONStringFromTree.h ImagingComponent.cpp From e60a4c05925d658e1bd088df2ac1cb6149cb8509 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:04:36 -0400 Subject: [PATCH 03/73] changes to device component --- inc/osvr/Common/DeviceComponent.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/osvr/Common/DeviceComponent.h b/inc/osvr/Common/DeviceComponent.h index 2e1620a68..5d8c94e33 100644 --- a/inc/osvr/Common/DeviceComponent.h +++ b/inc/osvr/Common/DeviceComponent.h @@ -45,7 +45,7 @@ namespace common { /// @brief Called (only) by BaseDevice when being added: effectively /// records a "parent pointer" that does not convey ownership. - void recordParent(Parent &dev); + virtual void recordParent(Parent &dev); /// @brief Called during mainloop void update(); @@ -75,9 +75,9 @@ namespace common { /// @brief Implementation-specific (optional) stuff to do during /// mainloop virtual void m_update(); + Parent *m_parent; private: - Parent *m_parent; MessageHandlerList m_messageHandlers; }; } // namespace common From 48f2c7c74db82788f8134c6bc1f79e240f522b86 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:09:33 -0400 Subject: [PATCH 04/73] add definitions for gesture report, state, and pre-defined set --- inc/osvr/Util/ClientReportTypesC.h | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index 85fa5a5a1..82daa8233 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -340,6 +340,45 @@ typedef struct OSVR_NaviPositionReport { OSVR_NaviPositionState state; } OSVR_NaviPositionReport; +/** @brief Type of int to identify gestures */ +typedef uint32_t OSVR_GestureID; + +/** @brief Type of string to identify gesture name */ +typedef char const *OSVR_GestureName; + +/** @brief Type of Gesture state */ +typedef uint8_t OSVR_GestureState; + +/** @brief OSVR_GestureState value indicating "gesture started/currently in + process(ocurring)" + (should be used for continuous gestures, since discrete start and complete + at the same time) */ +#define OSVR_GESTURE_IN_PROCESS (1) + +/** @brief OSVR_GestureState value indicating "gesture is finished" */ +#define OSVR_GESTURE_COMPLETE (0) + +/** @brief a list of pre-set gestures available (can be expanded) */ +#define OSVR_GESTURE_SWIP_LEFT "SwipeLeft" +#define OSVR_GESTURE_SWIP_RIGHT "SwipeRight" +#define OSVR_GESTURE_SCROLL_UP "ScrollUp" +#define OSVR_GESTURE_SCROLL_DOWN "ScrollDown" +#define OSVR_GESTURE_SINGLE_TAP "SingleTap" +#define OSVR_GESTURE_DOUBLE_TAP "DoubleTap" +#define OSVR_GESTURE_PINCH "Pinch" +#define OSVR_GESTURE_FINGER_SPREAD "FingerSpread" +#define OSVR_GESTURE_CIRCLE "Circle" +#define OSVR_GESTURE_LONG_PRESS "LongPress" +#define OSVR_GESTURE_OPEN_HAND "OpenHand" +#define OSVR_GESTURE_CLOSED_HAND "ClosedHand" + +/** @brief Report type for a gesture event */ +typedef struct OSVR_GestureReport { + OSVR_GestureName gestureName; + OSVR_GestureState state; + OSVR_ChannelCount sensor; +} OSVR_GestureReport; + /** @} */ /** @} */ From fc912f7373a26b4451685eba5a201c3436a650e8 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:11:21 -0400 Subject: [PATCH 05/73] add gesture interface definition to pluginkit --- inc/osvr/PluginKit/GestureInterfaceC.h | 82 ++++++++++++++++++++++++ src/osvr/PluginKit/GestureInterfaceC.cpp | 77 ++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 inc/osvr/PluginKit/GestureInterfaceC.h create mode 100644 src/osvr/PluginKit/GestureInterfaceC.cpp diff --git a/inc/osvr/PluginKit/GestureInterfaceC.h b/inc/osvr/PluginKit/GestureInterfaceC.h new file mode 100644 index 000000000..9ea7007cf --- /dev/null +++ b/inc/osvr/PluginKit/GestureInterfaceC.h @@ -0,0 +1,82 @@ +/** @file + @brief Header + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_GestureInterfaceC_h_GUID_1BED0900_2C34_47B4_1B62_169A0E3E80D4 +#define INCLUDED_GestureInterfaceC_h_GUID_1BED0900_2C34_47B4_1B62_169A0E3E80D4 + +// Internal Includes +#include +#include +#include + +// Library/third-party includes +// - none + +// Standard includes + +OSVR_EXTERN_C_BEGIN + +/** @brief Opaque type used in conjunction with a device token to send data on + * Gesture Interface +*/ +typedef struct OSVR_GestureDeviceInterfaceObject *OSVR_GestureDeviceInterface; + +/** @brief Specify that your device will implement the Gesture interface. + +@param opts The device init options object. +@param [out] iface An interface object you should retain with the same +lifetime as the device token in order to send messages conforming to an +Gesture interface. +@param numSensors The number of sensors you will be reporting Gesture data : +You can report 1+ sensors. This parameter may be subject to external limitations +*/ +OSVR_PLUGINKIT_EXPORT +OSVR_ReturnCode +osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, + OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface, + OSVR_IN OSVR_ChannelCount numSensors + OSVR_CPP_ONLY(= 1)) OSVR_FUNC_NONNULL((1, 2)); + +/** @brief Report data for a specific sensor. +@param dev Device token +@param iface Gesture interface +@param gestureName String name of gesture +@param gestureState Current state of gesture (In process vs Completed) +@param sensor Sensor number +@param timestamp Timestamp correlating to Gesture data. +*/ +OSVR_PLUGINKIT_EXPORT +OSVR_ReturnCode +osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN_PTR const char *gestureName, + OSVR_IN_PTR OSVR_GestureState gestureState, + OSVR_IN OSVR_ChannelCount sensor, + OSVR_IN_PTR OSVR_TimeValue const *timestamp) + OSVR_FUNC_NONNULL((1, 5)); +/** @} */ /* end of group */ + +OSVR_EXTERN_C_END + +#endif // INCLUDED_GestureInterfaceC_h_GUID_1BED0900_2C34_47B4_1B62_169A0E3E80D4 diff --git a/src/osvr/PluginKit/GestureInterfaceC.cpp b/src/osvr/PluginKit/GestureInterfaceC.cpp new file mode 100644 index 000000000..39ce60b02 --- /dev/null +++ b/src/osvr/PluginKit/GestureInterfaceC.cpp @@ -0,0 +1,77 @@ +/** @file + @brief Implementation + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include +#include +#include +#include "HandleNullContext.h" +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + +struct OSVR_GestureDeviceInterfaceObject + : public osvr::connection::DeviceInterfaceBase { + osvr::common::GestureComponent *gesture; +}; + +OSVR_ReturnCode +osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, + OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface, + OSVR_IN OSVR_ChannelCount numSensors) { + + OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceGestureConfigure", opts); + OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceGestureConfigure", iface); + OSVR_GestureDeviceInterface ifaceObj = + opts->makeInterfaceObject(); + *iface = ifaceObj; + auto gesture = osvr::common::GestureComponent::create(numSensors); + ifaceObj->gesture = gesture.get(); + opts->addComponent(gesture); + return OSVR_RETURN_SUCCESS; +} + +OSVR_ReturnCode +osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN_PTR const char *gestureName, + OSVR_IN_PTR OSVR_GestureState gestureState, + OSVR_IN OSVR_ChannelCount sensor, + OSVR_IN_PTR OSVR_TimeValue const *timestamp) { + auto guard = iface->getSendGuard(); + if (guard->lock()) { + iface->gesture->sendGestureData(gestureState, gestureName, sensor, + *timestamp); + return OSVR_RETURN_SUCCESS; + } + + return OSVR_RETURN_FAILURE; +} \ No newline at end of file From 661830cccd8a0b1eceaa6240f612e0eac5b4e6c8 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:11:51 -0400 Subject: [PATCH 06/73] update plugin kit cmake build --- src/osvr/PluginKit/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/osvr/PluginKit/CMakeLists.txt b/src/osvr/PluginKit/CMakeLists.txt index cdc28be5b..9dbc6cb11 100644 --- a/src/osvr/PluginKit/CMakeLists.txt +++ b/src/osvr/PluginKit/CMakeLists.txt @@ -8,6 +8,7 @@ set(API "${HEADER_LOCATION}/DeviceInterfaceC.h" "${HEADER_LOCATION}/DirectionInterfaceC.h" "${HEADER_LOCATION}/EyeTrackerInterfaceC.h" + "${HEADER_LOCATION}/GestureInterfaceC.h" "${HEADER_LOCATION}/ImagingInterface.h" "${HEADER_LOCATION}/ImagingInterfaceC.h" "${HEADER_LOCATION}/Location2DInterfaceC.h" @@ -25,6 +26,7 @@ set(SOURCE DirectionInterfaceC.cpp HandleNullContext.h EyeTrackerInterfaceC.cpp + GestureInterfaceC.cpp ImagingInterfaceC.cpp Location2DInterfaceC.cpp LocomotionInterfaceC.cpp @@ -54,6 +56,7 @@ target_link_libraries(${LIBNAME_FULL} osvrConnection osvrUtilCpp osvrCommon + jsoncpp_lib vendored-vrpn boost_thread) From ccc8f3aaa290e594678abe14e16bc9b429ee91f2 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:16:32 -0400 Subject: [PATCH 07/73] add client callback method definitions for gesture report --- inc/osvr/ClientKit/InterfaceCallbackC.h | 1 + inc/osvr/ClientKit/InterfaceStateC.h | 1 + src/osvr/ClientKit/InterfaceCallbackC.cpp | 1 + src/osvr/ClientKit/InterfaceStateC.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/inc/osvr/ClientKit/InterfaceCallbackC.h b/inc/osvr/ClientKit/InterfaceCallbackC.h index dde1cef97..9f2825a9b 100644 --- a/inc/osvr/ClientKit/InterfaceCallbackC.h +++ b/inc/osvr/ClientKit/InterfaceCallbackC.h @@ -69,6 +69,7 @@ OSVR_INTERFACE_CALLBACK_METHOD(EyeTracker3D) OSVR_INTERFACE_CALLBACK_METHOD(EyeTrackerBlink) OSVR_INTERFACE_CALLBACK_METHOD(NaviVelocity) OSVR_INTERFACE_CALLBACK_METHOD(NaviPosition) +OSVR_INTERFACE_CALLBACK_METHOD(Gesture) #undef OSVR_INTERFACE_CALLBACK_METHOD diff --git a/inc/osvr/ClientKit/InterfaceStateC.h b/inc/osvr/ClientKit/InterfaceStateC.h index edf9f085c..2358c340f 100644 --- a/inc/osvr/ClientKit/InterfaceStateC.h +++ b/inc/osvr/ClientKit/InterfaceStateC.h @@ -71,6 +71,7 @@ OSVR_CALLBACK_METHODS(EyeTracker3D) OSVR_CALLBACK_METHODS(EyeTrackerBlink) OSVR_CALLBACK_METHODS(NaviVelocity) OSVR_CALLBACK_METHODS(NaviPosition) +OSVR_CALLBACK_METHODS(Gesture) #undef OSVR_CALLBACK_METHODS diff --git a/src/osvr/ClientKit/InterfaceCallbackC.cpp b/src/osvr/ClientKit/InterfaceCallbackC.cpp index 4dc266c64..795c3603b 100644 --- a/src/osvr/ClientKit/InterfaceCallbackC.cpp +++ b/src/osvr/ClientKit/InterfaceCallbackC.cpp @@ -59,5 +59,6 @@ OSVR_CALLBACK_METHODS(EyeTracker3D) OSVR_CALLBACK_METHODS(EyeTrackerBlink) OSVR_CALLBACK_METHODS(NaviVelocity) OSVR_CALLBACK_METHODS(NaviPosition) +OSVR_CALLBACK_METHODS(Gesture) #undef OSVR_CALLBACK_METHODS diff --git a/src/osvr/ClientKit/InterfaceStateC.cpp b/src/osvr/ClientKit/InterfaceStateC.cpp index 7ac485ae6..c64ebbf99 100644 --- a/src/osvr/ClientKit/InterfaceStateC.cpp +++ b/src/osvr/ClientKit/InterfaceStateC.cpp @@ -59,5 +59,6 @@ OSVR_CALLBACK_METHODS(EyeTracker3D) OSVR_CALLBACK_METHODS(EyeTrackerBlink) OSVR_CALLBACK_METHODS(NaviVelocity) OSVR_CALLBACK_METHODS(NaviPosition) +OSVR_CALLBACK_METHODS(Gesture) #undef OSVR_CALLBACK_METHODS From ee9e34fc0c94044e50d1726c23dec9274acb52ac Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:19:49 -0400 Subject: [PATCH 08/73] add defns for gesture report type --- inc/osvr/Common/ReportState.h | 9 +++++++++ inc/osvr/Common/ReportTypes.h | 2 +- src/osvr/GenerateForReportTypes.cmake | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/inc/osvr/Common/ReportState.h b/inc/osvr/Common/ReportState.h index 10be61702..0205f43d1 100644 --- a/inc/osvr/Common/ReportState.h +++ b/inc/osvr/Common/ReportState.h @@ -107,6 +107,15 @@ namespace common { } }; + // Template specialization to handle OSVR_GestureReport + template <> struct ReportStateGetter { + static OSVR_GestureState const &apply(OSVR_GestureReport const &r) { + return r.state; + } + static OSVR_GestureState apply(OSVR_GestureReport &r) { + return r.state; + } + }; } // namespace traits /// @brief Generic const accessor for the "state" member of a report. diff --git a/inc/osvr/Common/ReportTypes.h b/inc/osvr/Common/ReportTypes.h index 353e5ead4..d73331067 100644 --- a/inc/osvr/Common/ReportTypes.h +++ b/inc/osvr/Common/ReportTypes.h @@ -50,7 +50,7 @@ namespace common { OSVR_ImagingReport, OSVR_Location2DReport, OSVR_DirectionReport, OSVR_EyeTracker2DReport, OSVR_EyeTracker3DReport, OSVR_EyeTrackerBlinkReport, OSVR_NaviVelocityReport, - OSVR_NaviPositionReport>; + OSVR_NaviPositionReport, OSVR_GestureReport>; } // namespace traits } // namespace common diff --git a/src/osvr/GenerateForReportTypes.cmake b/src/osvr/GenerateForReportTypes.cmake index 50d4da6ea..1f36eab74 100644 --- a/src/osvr/GenerateForReportTypes.cmake +++ b/src/osvr/GenerateForReportTypes.cmake @@ -18,6 +18,7 @@ set(OSVR_REPORT_TYPES EyeTrackerBlink NaviVelocity NaviPosition + Gesture CACHE INTERNAL "" FORCE) # Generate a file using a template with the placeholder @BODY@, as well as a From 27b9e0800c9fb9fa567bb1e289b6e4661708c85c Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:22:36 -0400 Subject: [PATCH 09/73] add client side gesture remote factory --- src/osvr/Client/GestureRemoteFactory.cpp | 161 +++++++++++++++++++++++ src/osvr/Client/GestureRemoteFactory.h | 65 +++++++++ 2 files changed, 226 insertions(+) create mode 100644 src/osvr/Client/GestureRemoteFactory.cpp create mode 100644 src/osvr/Client/GestureRemoteFactory.h diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp new file mode 100644 index 000000000..1d0208e05 --- /dev/null +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -0,0 +1,161 @@ +/** @file + @brief Implementation + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include "GestureRemoteFactory.h" +#include "VRPNConnectionCollection.h" +#include +#include +#include +#include +#include +#include +#include "InterfaceTree.h" +#include +#include +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + +namespace osvr { +namespace client { + + class NetworkGestureRemoteHandler : public RemoteHandler { + public: + NetworkGestureRemoteHandler(vrpn_ConnectionPtr const &conn, + std::string const &deviceName, + boost::optional sensor, + common::InterfaceList &ifaces) + : m_dev(common::createClientDevice(deviceName, conn)), + m_interfaces(ifaces), m_all(!sensor.is_initialized()), + m_sensor(sensor) { + + auto gesture = common::GestureComponent::create(); + m_dev->addComponent(gesture); + + gesture->registerGestureHandler( + [&](common::GestureData const &data, + util::time::TimeValue const ×tamp) { + m_handleGesture(data, timestamp); + }); + gesture->registerGestureMapHandler( + [&](common::GestureMap const &dataMap, + util::time::TimeValue const ×tamp) { + m_handleGestureMap(dataMap, timestamp); + }); + + /**/ + OSVR_DEV_VERBOSE("Constructed an Gesture Handler for " + << deviceName); + } + + /// @brief Deleted assignment operator. + NetworkGestureRemoteHandler & + operator=(NetworkGestureRemoteHandler const &) = delete; + + virtual ~NetworkGestureRemoteHandler() { + /// @todo do we need to unregister? + } + + virtual void update() { m_dev->update(); } + + private: + void m_handleGesture(common::GestureData const &data, + util::time::TimeValue const ×tamp) { + if (!m_all && *m_sensor != data.sensor) { + /// doesn't match our filter. + return; + } + + OSVR_GestureReport report; + + osvr::common::StringID id = + localGestureMap.convertPeerToLocalID(data.gestureID); + if (id.empty()) { + // could not find a peer to local mapping, discarding report + return; + } + std::string gestureName = localGestureMap.getNameFromID(id); + + if (gestureName.empty()) { + // could not find gesture name for this id, discarding report + return; + } + report.sensor = data.sensor; + report.state = data.gestureState; + report.gestureName = gestureName.c_str(); + common::ClientInterfacePtr anInterface; + for (auto &iface : m_interfaces) { + anInterface = iface; + iface->triggerCallbacks(timestamp, report); + } + } + + void m_handleGestureMap(common::GestureMap const &data, + util::time::TimeValue const ×tamp) { + + // got the gesture map, will need to sync with ours + localGestureMap.setupPeerMappings(data.serializedMap); + } + + common::BaseDevicePtr m_dev; + common::InterfaceList &m_interfaces; + bool m_all; + boost::optional m_sensor; + // map to keep track of gesture map and server to local ID map + common::CorrelatedStringMap localGestureMap; + }; + + GestureRemoteFactory::GestureRemoteFactory( + VRPNConnectionCollection const &conns) + : m_conns(conns) {} + + shared_ptr GestureRemoteFactory:: + operator()(common::OriginalSource const &source, + common::InterfaceList &ifaces, common::ClientContext &) { + + shared_ptr ret; + + if (source.hasTransform()) { + OSVR_DEV_VERBOSE( + "Ignoring transform found on route for Gesture data!"); + } + + auto const &devElt = source.getDeviceElement(); + + /// @todo find out why make_shared causes a crash here + ret.reset(new NetworkGestureRemoteHandler( + m_conns.getConnection(devElt), devElt.getFullDeviceName(), + source.getSensorNumberAsChannelCount(), ifaces)); + return ret; + } + +} // namespace client +} // namespace osvr \ No newline at end of file diff --git a/src/osvr/Client/GestureRemoteFactory.h b/src/osvr/Client/GestureRemoteFactory.h new file mode 100644 index 000000000..1dd151555 --- /dev/null +++ b/src/osvr/Client/GestureRemoteFactory.h @@ -0,0 +1,65 @@ +/** @file + @brief Header + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_GestureRemoteFactory_h_GUID_800D466C_603D_46AC_F20C_DAD679778CA6 +#define INCLUDED_GestureRemoteFactory_h_GUID_800D466C_603D_46AC_F20C_DAD679778CA6 + +// Internal Includes +#include "VRPNConnectionCollection.h" +#include +#include +#include +#include "RemoteHandler.h" +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + +namespace osvr { +namespace client { + + class GestureRemoteFactory { + public: + GestureRemoteFactory(VRPNConnectionCollection const &conns); + + template void registerWith(T &factory) const { + factory.addFactory("gesture", *this); + } + + shared_ptr + operator()(common::OriginalSource const &source, + common::InterfaceList &ifaces, common::ClientContext &ctx); + + private: + VRPNConnectionCollection m_conns; + }; + +} // namespace client +} // namespace osvr + +#endif // INCLUDED_GestureRemoteFactory_h_GUID_800D466C_603D_46AC_F20C_DAD679778CA6 From 893d8182e536761821ed5e0fabba5357eddfdec6 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:23:55 -0400 Subject: [PATCH 10/73] update cmake build for client/ --- src/osvr/Client/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osvr/Client/CMakeLists.txt b/src/osvr/Client/CMakeLists.txt index c0ee766d0..56426a08a 100644 --- a/src/osvr/Client/CMakeLists.txt +++ b/src/osvr/Client/CMakeLists.txt @@ -33,6 +33,8 @@ set(SOURCE DisplayInput.cpp EyeTrackerRemoteFactory.cpp EyeTrackerRemoteFactory.h + GestureRemoteFactory.cpp + GestureRemoteFactory.h ImagingRemoteFactory.cpp ImagingRemoteFactory.h InterfaceTree.cpp From 2dd88cfe7714a3111c4b8ad2b22a66e91bfdff09 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:26:25 -0400 Subject: [PATCH 11/73] add a sample gesture plugin --- examples/plugin/CMakeLists.txt | 2 + examples/plugin/com_osvr_example_Gesture.cpp | 121 ++++++++++++++++++ examples/plugin/com_osvr_example_Gesture.json | 20 +++ 3 files changed, 143 insertions(+) create mode 100644 examples/plugin/com_osvr_example_Gesture.cpp create mode 100644 examples/plugin/com_osvr_example_Gesture.json diff --git a/examples/plugin/CMakeLists.txt b/examples/plugin/CMakeLists.txt index 00604e724..1a3444385 100644 --- a/examples/plugin/CMakeLists.txt +++ b/examples/plugin/CMakeLists.txt @@ -4,6 +4,7 @@ set(OSVR_EXAMPLE_DEVICE_PLUGINS_SIMPLE com_osvr_example_Configured com_osvr_example_DummyDetectAndCreateAsync com_osvr_example_EyeTracker + com_osvr_example_Gesture com_osvr_example_Locomotion com_osvr_example_MultipleAsync org_osvr_example_Tracker) @@ -39,6 +40,7 @@ endforeach() foreach(pluginname com_osvr_example_Configured com_osvr_example_EyeTracker + com_osvr_example_Gesture com_osvr_example_Locomotion org_osvr_example_Tracker com_osvr_example_MultipleAsync) diff --git a/examples/plugin/com_osvr_example_Gesture.cpp b/examples/plugin/com_osvr_example_Gesture.cpp new file mode 100644 index 000000000..e537bbb99 --- /dev/null +++ b/examples/plugin/com_osvr_example_Gesture.cpp @@ -0,0 +1,121 @@ +/** @date 2015 + + @author + Sensics, Inc. + +*/ + +// Copyright 2015 Sensics Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include + +// Generated JSON header file +#include "com_osvr_example_Gesture_json.h" + +// Library/third-party includes + +// Standard includes +#include +#include +#include + +// Anonymous namespace to avoid symbol collision +namespace { + +OSVR_MessageType gestureMessage; + +class GestureDevice { + public: + GestureDevice(OSVR_PluginRegContext ctx) { + /// Create the initialization options + OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); + + osvrDeviceGestureConfigure(opts, &m_gesture, 2); + + /// Create the sync device token with the options + m_dev.initSync(ctx, "Gesture", opts); + + /// Send JSON descriptor + m_dev.sendJsonDescriptor(com_osvr_example_Gesture_json); + + /// Register update callback + m_dev.registerUpdateCallback(this); + } + + OSVR_ReturnCode update() { + + OSVR_TimeValue times; + + osvrTimeValueGetNow(×); + + std::string gestureName0 = "fist"; + std::string gestureName1 = "swipe"; + std::string gestureName2 = "lasso"; + OSVR_GestureState state = OSVR_GESTURE_COMPLETE; + + osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_CIRCLE, + state, 0, ×); + osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_CLOSED_HAND, + state, 1, ×); + osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_DOUBLE_TAP, + state, 2, ×); + + return OSVR_RETURN_SUCCESS; + } + + private: + osvr::pluginkit::DeviceToken m_dev; + OSVR_GestureDeviceInterface m_gesture; +}; + +class HardwareDetection { + public: + HardwareDetection() : m_found(false) {} + OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx) { + + if (m_found) { + return OSVR_RETURN_SUCCESS; + } + + std::cout << "PLUGIN: Got a hardware detection request" << std::endl; + + /// we always detect device in sample plugin + m_found = true; + + std::cout << "PLUGIN: We have detected Gesture device! " << std::endl; + /// Create our device object + osvr::pluginkit::registerObjectForDeletion(ctx, new GestureDevice(ctx)); + + return OSVR_RETURN_SUCCESS; + } + + private: + bool m_found; +}; +} // namespace + +OSVR_PLUGIN(com_osvr_example_Gesture) { + + osvrDeviceRegisterMessageType(ctx, "GestureMessage", &gestureMessage); + + osvr::pluginkit::PluginContext context(ctx); + + /// Register a detection callback function object. + context.registerHardwareDetectCallback(new HardwareDetection()); + + return OSVR_RETURN_SUCCESS; +} \ No newline at end of file diff --git a/examples/plugin/com_osvr_example_Gesture.json b/examples/plugin/com_osvr_example_Gesture.json new file mode 100644 index 000000000..9ae999f32 --- /dev/null +++ b/examples/plugin/com_osvr_example_Gesture.json @@ -0,0 +1,20 @@ +{ + "deviceVendor": "Sensics", + "deviceName": "Gesture", + "author": "Georgiy Frolov georgiy@sensics.com", + "version": 1, + "lastModified": "", + "interfaces": { + "gesture": { + "count": 2 + } + }, + "semantic": { + "left": "gesture/0", + "right": "gesture/1" + }, + "automaticAliases": { + "/me/hands/left": "semantic/left", + "/me/hands/right": "semantic/right" + } +} \ No newline at end of file From 53ae6cac58cf3a3360b3c1c580c7458aa1e861a8 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:26:56 -0400 Subject: [PATCH 12/73] add osvr server config for sample gesture plugin --- apps/osvr_server_config.gesture.sample.json | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 apps/osvr_server_config.gesture.sample.json diff --git a/apps/osvr_server_config.gesture.sample.json b/apps/osvr_server_config.gesture.sample.json new file mode 100644 index 000000000..415cabc80 --- /dev/null +++ b/apps/osvr_server_config.gesture.sample.json @@ -0,0 +1,26 @@ +{ + "plugins": [ + "com_osvr_example_Gesture" + ], + "routes": [ + { + "destination": "/me/hands/left", + "source": { + "child": { + "tracker": "/com_osvr_example_Gesture/Gesture", + "sensor": 0 + } + } + }, + { + "destination": "/me/hands/right", + "source": { + "child": { + "tracker": "/com_osvr_example_Gesture/Gesture", + "sensor": 1 + } + } + } + ], + "display": "displays/HMD.json" +} \ No newline at end of file From d5f50ee7f2dcbceb197a52e4698eb4058b82bebd Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 11:27:16 -0400 Subject: [PATCH 13/73] add a sample gesture client app --- examples/clients/CMakeLists.txt | 1 + examples/clients/Gesture.cpp | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 examples/clients/Gesture.cpp diff --git a/examples/clients/CMakeLists.txt b/examples/clients/CMakeLists.txt index dc6abb225..c568c8ea6 100644 --- a/examples/clients/CMakeLists.txt +++ b/examples/clients/CMakeLists.txt @@ -16,6 +16,7 @@ set(CLIENTS Location2D Direction Locomotion + Gesture MinimalInit TrackerState ViewerEyeSurfaces) diff --git a/examples/clients/Gesture.cpp b/examples/clients/Gesture.cpp new file mode 100644 index 000000000..abd1e292e --- /dev/null +++ b/examples/clients/Gesture.cpp @@ -0,0 +1,71 @@ +/** @file + @brief Implementation + + @date 2015 + + @author + Sensics, Inc. + + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include + +// Library/third-party includes + +// Standard includes +#include +#include + +void printGestureReport(const OSVR_GestureReport *report) { + + std::string state; + if (report->state == OSVR_GESTURE_COMPLETE) { + state = "COMPLETE"; + } else { + state = "IN PROCESS"; + } + std::cout << report->gestureName << "; " << state << "\t" << std::endl; +} + +void gestureCallback(void * /*userdata*/, const OSVR_TimeValue * /*timestamp*/, + const OSVR_GestureReport *report) { + std::cout << "Got Gesture Report, for sensor #" << report->sensor + << std::endl; + printGestureReport(report); +} + +int main() { + osvr::clientkit::ClientContext context( + "com.osvr.exampleclients.GestureCallback"); + + osvr::clientkit::Interface location = + context.getInterface("/com_osvr_example_Gesture/Gesture/gesture"); + + location.registerCallback(&gestureCallback, NULL); + + // Pretend that this is your application's mainloop. + while (1) { + context.update(); + } + + std::cout << "Library shut down, exiting." << std::endl; + return 0; +} \ No newline at end of file From 97ef4fdef4f41bc7431146faa568a155b1e99f60 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 15:58:04 -0400 Subject: [PATCH 14/73] simplify reading from buffer --- src/osvr/Common/GestureComponent.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index fc461ae49..8af26b6ff 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -196,9 +196,7 @@ namespace common { GestureComponent::m_handleGestureMapRecord(void *userdata, vrpn_HANDLERPARAM p) { auto self = static_cast(userdata); - auto bufwrap = ExternalBufferReadingWrapper( - reinterpret_cast(p.buffer), p.payload_len); - auto bufReader = BufferReader(bufwrap); + auto bufReader = readExternalBuffer(p.buffer, p.payload_len); messages::GestureMapRecord::MessageSerialization msg; deserialize(bufReader, msg); From e004f57533de22cab7cf1e768a5e22332cc65d14 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 16:26:07 -0400 Subject: [PATCH 15/73] revert to using m_parentSet instead of overriding recordParent --- inc/osvr/Common/DeviceComponent.h | 4 ++-- inc/osvr/Common/GestureComponent.h | 2 -- src/osvr/Common/GestureComponent.cpp | 26 ++++++++++---------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/inc/osvr/Common/DeviceComponent.h b/inc/osvr/Common/DeviceComponent.h index 5d8c94e33..2e1620a68 100644 --- a/inc/osvr/Common/DeviceComponent.h +++ b/inc/osvr/Common/DeviceComponent.h @@ -45,7 +45,7 @@ namespace common { /// @brief Called (only) by BaseDevice when being added: effectively /// records a "parent pointer" that does not convey ownership. - virtual void recordParent(Parent &dev); + void recordParent(Parent &dev); /// @brief Called during mainloop void update(); @@ -75,9 +75,9 @@ namespace common { /// @brief Implementation-specific (optional) stuff to do during /// mainloop virtual void m_update(); - Parent *m_parent; private: + Parent *m_parent; MessageHandlerList m_messageHandlers; }; } // namespace common diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 89c6946b7..3c1b471d9 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -84,8 +84,6 @@ namespace common { static OSVR_COMMON_EXPORT shared_ptr create(OSVR_ChannelCount numSensor = 1); - void recordParent(Parent &dev); - /// @brief Message from server to client, containing Gesture data. messages::GestureRecord gestureRecord; diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index 8af26b6ff..217beba6d 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -125,21 +125,6 @@ namespace common { m_gestureNameMap.registerStringID(OSVR_GESTURE_CLOSED_HAND); } - void GestureComponent::recordParent(Parent &dev) { - BOOST_ASSERT_MSG(nullptr == m_parent, - "recordParent should only be called once!"); - m_parent = &dev; - m_parentSet(); - - // add a ping handler to re-send gesture map everytime the new - // connection(ping) occurs - m_commonComponent = - m_getParent().addComponent(osvr::common::CommonComponent::create()); - OSVR_TimeValue now; - osvrTimeValueGetNow(&now); - m_commonComponent->registerPingHandler([&] { m_sendGestureMap(now); }); - } - void GestureComponent::sendGestureData(OSVR_GestureState gestureState, std::string const &gestureName, OSVR_ChannelCount sensor, @@ -196,7 +181,7 @@ namespace common { GestureComponent::m_handleGestureMapRecord(void *userdata, vrpn_HANDLERPARAM p) { auto self = static_cast(userdata); - auto bufReader = readExternalBuffer(p.buffer, p.payload_len); + auto bufReader = readExternalBuffer(p.buffer, p.payload_len); messages::GestureMapRecord::MessageSerialization msg; deserialize(bufReader, msg); @@ -226,6 +211,15 @@ namespace common { } void GestureComponent::m_parentSet() { + + // add a ping handler to re-send gesture map everytime the new + // connection(ping) occurs + m_commonComponent = + m_getParent().addComponent(osvr::common::CommonComponent::create()); + OSVR_TimeValue now; + osvrTimeValueGetNow(&now); + m_commonComponent->registerPingHandler([&] { m_sendGestureMap(now); }); + m_getParent().registerMessageType(gestureRecord); m_getParent().registerMessageType(gestureMapRecord); } From 17f77ac5f31a13485281a16aad18cf26a53b72a0 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 20 Jul 2015 16:29:55 -0400 Subject: [PATCH 16/73] fix a couple typos --- inc/osvr/Util/ClientReportTypesC.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index 82daa8233..4ccaeb11d 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -359,8 +359,8 @@ typedef uint8_t OSVR_GestureState; #define OSVR_GESTURE_COMPLETE (0) /** @brief a list of pre-set gestures available (can be expanded) */ -#define OSVR_GESTURE_SWIP_LEFT "SwipeLeft" -#define OSVR_GESTURE_SWIP_RIGHT "SwipeRight" +#define OSVR_GESTURE_SWIPE_LEFT "SwipeLeft" +#define OSVR_GESTURE_SWIPE_RIGHT "SwipeRight" #define OSVR_GESTURE_SCROLL_UP "ScrollUp" #define OSVR_GESTURE_SCROLL_DOWN "ScrollDown" #define OSVR_GESTURE_SINGLE_TAP "SingleTap" From 275d2884ec251a067d51c3b9acdff9b4cc384713 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 21 Jul 2015 08:44:06 -0400 Subject: [PATCH 17/73] fix class name, a typo --- src/osvr/Client/GestureRemoteFactory.cpp | 17 ++++++++--------- src/osvr/Common/GestureComponent.cpp | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index 1d0208e05..d3fde3c34 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -47,12 +47,12 @@ namespace osvr { namespace client { - class NetworkGestureRemoteHandler : public RemoteHandler { + class GestureRemoteHandler : public RemoteHandler { public: - NetworkGestureRemoteHandler(vrpn_ConnectionPtr const &conn, - std::string const &deviceName, - boost::optional sensor, - common::InterfaceList &ifaces) + GestureRemoteHandler(vrpn_ConnectionPtr const &conn, + std::string const &deviceName, + boost::optional sensor, + common::InterfaceList &ifaces) : m_dev(common::createClientDevice(deviceName, conn)), m_interfaces(ifaces), m_all(!sensor.is_initialized()), m_sensor(sensor) { @@ -77,10 +77,9 @@ namespace client { } /// @brief Deleted assignment operator. - NetworkGestureRemoteHandler & - operator=(NetworkGestureRemoteHandler const &) = delete; + GestureRemoteHandler &operator=(GestureRemoteHandler const &) = delete; - virtual ~NetworkGestureRemoteHandler() { + virtual ~GestureRemoteHandler() { /// @todo do we need to unregister? } @@ -151,7 +150,7 @@ namespace client { auto const &devElt = source.getDeviceElement(); /// @todo find out why make_shared causes a crash here - ret.reset(new NetworkGestureRemoteHandler( + ret.reset(new GestureRemoteHandler( m_conns.getConnection(devElt), devElt.getFullDeviceName(), source.getSensorNumberAsChannelCount(), ifaces)); return ret; diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index 217beba6d..664d9c119 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -111,8 +111,8 @@ namespace common { : m_numSensor(numChan) { // populate the gesture map - m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIP_LEFT); - m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIP_RIGHT); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIPE_LEFT); + m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_UP); m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_DOWN); m_gestureNameMap.registerStringID(OSVR_GESTURE_SINGLE_TAP); From b6fe7a2b8795d819a80785ae89785363ad0e2ad3 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 30 Jul 2015 11:44:22 -0400 Subject: [PATCH 18/73] update gesture interface to send gesture ID --- inc/osvr/PluginKit/GestureInterfaceC.h | 36 ++++++++++++++++++++++-- src/osvr/PluginKit/GestureInterfaceC.cpp | 27 ++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/inc/osvr/PluginKit/GestureInterfaceC.h b/inc/osvr/PluginKit/GestureInterfaceC.h index 9ea7007cf..66beb91d5 100644 --- a/inc/osvr/PluginKit/GestureInterfaceC.h +++ b/inc/osvr/PluginKit/GestureInterfaceC.h @@ -59,10 +59,21 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, OSVR_IN OSVR_ChannelCount numSensors OSVR_CPP_ONLY(= 1)) OSVR_FUNC_NONNULL((1, 2)); +/** @brief Obtain an ID for a given gesture name +@param iface GestureInterface +@param gestureName String name of gesture +@param gestureID pointer to an id variable +*/ +OSVR_PLUGINKIT_EXPORT +void +osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN_PTR const char *gestureName, + OSVR_IN_PTR OSVR_GestureID *gestureID) + OSVR_FUNC_NONNULL((1, 2)); + /** @brief Report data for a specific sensor. -@param dev Device token @param iface Gesture interface -@param gestureName String name of gesture +@param gestureID ID of the gesture corresponding to specific name @param gestureState Current state of gesture (In process vs Completed) @param sensor Sensor number @param timestamp Timestamp correlating to Gesture data. @@ -70,11 +81,32 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN OSVR_GestureID gestureID, + OSVR_IN_PTR OSVR_GestureState gestureState, + OSVR_IN OSVR_ChannelCount sensor, + OSVR_IN_PTR OSVR_TimeValue const *timestamp) + OSVR_FUNC_NONNULL((1, 5)); + + +/** @brief Report data for a specific sensor. +@param iface Gesture interface +@param gestureName String name of gesture +@param gestureState Current state of gesture (In process vs Completed) +@param sensor Sensor number +@param timestamp Timestamp correlating to Gesture data. +*/ +OSVR_PLUGINKIT_EXPORT +OSVR_ReturnCode +osvrDeviceGestureReportDataWithName(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, OSVR_IN_PTR const char *gestureName, OSVR_IN_PTR OSVR_GestureState gestureState, OSVR_IN OSVR_ChannelCount sensor, OSVR_IN_PTR OSVR_TimeValue const *timestamp) OSVR_FUNC_NONNULL((1, 5)); + + + + /** @} */ /* end of group */ OSVR_EXTERN_C_END diff --git a/src/osvr/PluginKit/GestureInterfaceC.cpp b/src/osvr/PluginKit/GestureInterfaceC.cpp index 39ce60b02..29372d269 100644 --- a/src/osvr/PluginKit/GestureInterfaceC.cpp +++ b/src/osvr/PluginKit/GestureInterfaceC.cpp @@ -60,8 +60,35 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, return OSVR_RETURN_SUCCESS; } +void +osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, +OSVR_IN_PTR const char *gestureName, +OSVR_IN_PTR OSVR_GestureID *gestureID){ + + *gestureID = iface->gesture->getGestureID(gestureName); + +} + OSVR_ReturnCode osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, +OSVR_IN OSVR_GestureID gestureID, +OSVR_IN_PTR OSVR_GestureState gestureState, +OSVR_IN OSVR_ChannelCount sensor, +OSVR_IN_PTR OSVR_TimeValue const *timestamp){ + + auto guard = iface->getSendGuard(); + if (guard->lock()) { + iface->gesture->sendGestureData(gestureState, gestureID, sensor, + *timestamp); + return OSVR_RETURN_SUCCESS; + } + + return OSVR_RETURN_FAILURE; + +} + +OSVR_ReturnCode +osvrDeviceGestureReportDataWithName(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, OSVR_IN_PTR const char *gestureName, OSVR_IN_PTR OSVR_GestureState gestureState, OSVR_IN OSVR_ChannelCount sensor, From 885f3ceed4c04674041a8a924f02cd1b170ac0f6 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 30 Jul 2015 11:45:09 -0400 Subject: [PATCH 19/73] send gesture data with ID instead of string in component --- inc/osvr/Common/GestureComponent.h | 6 ++++++ src/osvr/Common/GestureComponent.cpp | 31 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 3c1b471d9..a1d84d65a 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -94,6 +94,10 @@ namespace common { OSVR_GestureState gestureState, std::string const &gestureName, OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); + OSVR_COMMON_EXPORT void sendGestureData( + OSVR_GestureState gestureState, OSVR_GestureID gestureID, + OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); + void m_sendGestureMap(OSVR_TimeValue const ×tamp); typedef std::function buf; + + messages::GestureRecord::MessageSerialization msg(gestureState, + gestureID, sensor); + serialize(buf, msg); + + m_getParent().packMessage(buf, gestureRecord.getMessageType(), + timestamp); + + } + void GestureComponent::m_sendGestureMap(OSVR_TimeValue const ×tamp) { Buffer<> buf; @@ -224,5 +239,21 @@ namespace common { m_getParent().registerMessageType(gestureMapRecord); } + OSVR_GestureID GestureComponent::getGestureID(const char *gestureName){ + + OSVR_GestureID gestureID = m_gestureNameMap.getStringID(gestureName); + + OSVR_TimeValue now; + osvrTimeValueGetNow(&now); + + // if we just inserted new gesture ID then send gesture map + if (m_gestureNameMap.isUpdateAvailable()) { + m_sendGestureMap(now); + } + + return gestureID; + } + + } // namespace common } // namespace osvr \ No newline at end of file From e537a978df4a6c359e8b3a4053787296fbb52efd Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 30 Jul 2015 11:45:48 -0400 Subject: [PATCH 20/73] change gesture report to use ID instead of string --- inc/osvr/Util/ClientReportTypesC.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index 4ccaeb11d..78e9cb90f 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -373,10 +373,17 @@ typedef uint8_t OSVR_GestureState; #define OSVR_GESTURE_CLOSED_HAND "ClosedHand" /** @brief Report type for a gesture event */ -typedef struct OSVR_GestureReport { +typedef struct OSVR_GestureReportWithName { OSVR_GestureName gestureName; OSVR_GestureState state; OSVR_ChannelCount sensor; +} OSVR_GestureReportWithName; + +/** @brief Report type for a gesture event */ +typedef struct OSVR_GestureReport { + OSVR_GestureID gestureID; + OSVR_GestureState state; + OSVR_ChannelCount sensor; } OSVR_GestureReport; /** @} */ From 2f38f8307b5f0ee178a53b449b17f7da28daa3c0 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 30 Jul 2015 11:46:23 -0400 Subject: [PATCH 21/73] update report field for callback --- src/osvr/Client/GestureRemoteFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index d3fde3c34..f5445b5ef 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -109,7 +109,7 @@ namespace client { } report.sensor = data.sensor; report.state = data.gestureState; - report.gestureName = gestureName.c_str(); + report.gestureID = data.gestureID; common::ClientInterfacePtr anInterface; for (auto &iface : m_interfaces) { anInterface = iface; From e3fe87117d434cd414ee4d15998c03008562112d Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 30 Jul 2015 11:47:15 -0400 Subject: [PATCH 22/73] change sample gesture plugin to use updated pluginkit api --- examples/plugin/com_osvr_example_Gesture.cpp | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/plugin/com_osvr_example_Gesture.cpp b/examples/plugin/com_osvr_example_Gesture.cpp index e537bbb99..80770e82a 100644 --- a/examples/plugin/com_osvr_example_Gesture.cpp +++ b/examples/plugin/com_osvr_example_Gesture.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include // Anonymous namespace to avoid symbol collision namespace { @@ -45,10 +47,14 @@ class GestureDevice { OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); osvrDeviceGestureConfigure(opts, &m_gesture, 2); - + /// Create the sync device token with the options m_dev.initSync(ctx, "Gesture", opts); + //get an ID for gesture names to be used in plugin + osvrDeviceGestureGetID(m_gesture, OSVR_GESTURE_DOUBLE_TAP, &m_double_tap_gesture); + osvrDeviceGestureGetID(m_gesture, "FIST", &m_fist_gesture); + /// Send JSON descriptor m_dev.sendJsonDescriptor(com_osvr_example_Gesture_json); @@ -58,21 +64,17 @@ class GestureDevice { OSVR_ReturnCode update() { + std::this_thread::sleep_for(std::chrono::milliseconds( + 1000)); // Simulate waiting a quarter second for data. + OSVR_TimeValue times; osvrTimeValueGetNow(×); - - std::string gestureName0 = "fist"; - std::string gestureName1 = "swipe"; - std::string gestureName2 = "lasso"; - OSVR_GestureState state = OSVR_GESTURE_COMPLETE; - - osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_CIRCLE, - state, 0, ×); - osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_CLOSED_HAND, - state, 1, ×); - osvrDeviceGestureReportData(m_gesture, OSVR_GESTURE_DOUBLE_TAP, - state, 2, ×); + + osvrDeviceGestureReportData(m_gesture, m_double_tap_gesture, + OSVR_GESTURE_COMPLETE, 0, ×); + osvrDeviceGestureReportData(m_gesture, m_fist_gesture, + OSVR_GESTURE_COMPLETE, 1, ×); return OSVR_RETURN_SUCCESS; } @@ -80,6 +82,9 @@ class GestureDevice { private: osvr::pluginkit::DeviceToken m_dev; OSVR_GestureDeviceInterface m_gesture; + OSVR_GestureID m_fist_gesture; + OSVR_GestureID m_double_tap_gesture; + }; class HardwareDetection { From 83e37b4c0cf2ecf931d9e7e8ea173f92721d2254 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:42:20 -0400 Subject: [PATCH 23/73] move the handling of registeredstringmap to systemcomponent to keep only one set for server and client (each) --- inc/osvr/Common/SystemComponent.h | 57 +++++++++++++++++++- src/osvr/Common/SystemComponent.cpp | 81 ++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 3 deletions(-) diff --git a/inc/osvr/Common/SystemComponent.h b/inc/osvr/Common/SystemComponent.h index 9c9bc8a5f..16cf3d1b5 100644 --- a/inc/osvr/Common/SystemComponent.h +++ b/inc/osvr/Common/SystemComponent.h @@ -32,14 +32,25 @@ #include #include +#include +#include +#include +#include + // Library/third-party includes #include +#include // Standard includes // - none namespace osvr { namespace common { + + struct MapData{ + SerializedStringMap serializedMap; + }; + namespace messages { class RoutesFromServer : public MessageRegistration { public: @@ -69,8 +80,26 @@ namespace common { class MessageSerialization; static const char *identifier(); }; + + /// message to send serialized name to ID map + class RegisteredStringMapRecord : public MessageRegistration { + public: + class MessageSerialization; + + static const char *identifier(); + }; + } // namespace messages + struct RegStringMapData{ + RegisteredStringMap map; + CorrelatedStringMap corrMap; + }; + + typedef shared_ptr MapPtr; + + typedef shared_ptr SystemComponentPtr; + /// @brief BaseDevice component, to be used only with the "OSVR" special /// device. class SystemComponent : public DeviceComponent { @@ -112,13 +141,39 @@ namespace common { OSVR_COMMON_EXPORT void sendReplacementTree(PathTree &tree); + /// @brief Request a copy of MapPtr to the name to ID map + OSVR_COMMON_EXPORT MapPtr getRegStringMap(); + + /// @brief Message from server to client, containing registeredStringMap + messages::RegisteredStringMapRecord regStringMap; + + OSVR_COMMON_EXPORT void sendRegisteredStringMap(); + + typedef std::function + RegisteredStringMapHandler; + OSVR_COMMON_EXPORT void registerStringMapHandler( + RegisteredStringMapHandler cb); + + + private: SystemComponent(); virtual void m_parentSet(); + static int VRPN_CALLBACK m_handleReplaceTree(void *userdata, vrpn_HANDLERPARAM p); - std::vector m_replaceTreeHandlers; + + static int VRPN_CALLBACK + m_handleRegStringMap(void *userdata, vrpn_HANDLERPARAM p); + std::vector m_cb_map; + + // name to ID map used by the server + MapPtr m_nameToIDMap; + + /// @brief Common component for system device + common::CommonComponent *m_commonComponent; }; } // namespace common } // namespace osvr diff --git a/src/osvr/Common/SystemComponent.cpp b/src/osvr/Common/SystemComponent.cpp index a1c881091..059cfcc7e 100644 --- a/src/osvr/Common/SystemComponent.cpp +++ b/src/osvr/Common/SystemComponent.cpp @@ -27,15 +27,16 @@ #include #include #include -#include #include #include +#include // Library/third-party includes #include // Standard includes // - none +#include namespace osvr { namespace common { @@ -93,6 +94,29 @@ namespace common { const char *ReplacementTreeFromServer::identifier() { return "com.osvr.system.ReplacementTreeFromServer"; } + + class RegisteredStringMapRecord::MessageSerialization { + public: + MessageSerialization(SerializedStringMap serializedMap) + : m_serializedMap(serializedMap) {} + + MessageSerialization() {} + + template void processMessage(T &p) { + p(m_serializedMap); + } + MapData getData() const { + MapData ret; + ret.serializedMap = m_serializedMap; + return ret; + } + + private: + SerializedStringMap m_serializedMap; + }; + const char *RegisteredStringMapRecord::identifier() { + return "com.osvr.system.regstringmaprecord"; + } } // namespace messages const char *SystemComponent::deviceName() { @@ -104,7 +128,7 @@ namespace common { return ret; } - SystemComponent::SystemComponent() {} + SystemComponent::SystemComponent() : m_nameToIDMap(new RegStringMapData) {} void SystemComponent::sendRoutes(std::string const &routes) { Buffer<> buf; @@ -148,11 +172,46 @@ namespace common { m_replaceTreeHandlers.push_back(cb); } + MapPtr SystemComponent::getRegStringMap(){ + return m_nameToIDMap; + } + + void SystemComponent::sendRegisteredStringMap() { + + Buffer<> buf; + // serialize the map before sending it + SerializedStringMap serializedMap = m_nameToIDMap->map.getMap(); + + messages::RegisteredStringMapRecord::MessageSerialization msg(serializedMap); + serialize(buf, msg); + m_getParent().packMessage(buf, regStringMap.getMessageType()); + } + + void + SystemComponent::registerStringMapHandler(RegisteredStringMapHandler handler) { + if (m_cb_map.empty()) { + m_registerHandler(&SystemComponent::m_handleRegStringMap, this, + regStringMap.getMessageType()); + } + m_cb_map.push_back(handler); + } + void SystemComponent::m_parentSet() { + + // add a ping handler to re-send string to ID map everytime the new + // connection(ping) occurs + m_commonComponent = + m_getParent().addComponent(osvr::common::CommonComponent::create()); + OSVR_TimeValue now; + osvrTimeValueGetNow(&now); + m_commonComponent->registerPingHandler([&] { + sendRegisteredStringMap(); }); + m_getParent().registerMessageType(routesOut); m_getParent().registerMessageType(appStartup); m_getParent().registerMessageType(routeIn); m_getParent().registerMessageType(treeOut); + m_getParent().registerMessageType(regStringMap); } int SystemComponent::m_handleReplaceTree(void *userdata, @@ -169,5 +228,23 @@ namespace common { } return 0; } + + int VRPN_CALLBACK + SystemComponent::m_handleRegStringMap(void *userdata, + vrpn_HANDLERPARAM p) { + auto self = static_cast(userdata); + auto bufReader = readExternalBuffer(p.buffer, p.payload_len); + messages::RegisteredStringMapRecord::MessageSerialization msg; + deserialize(bufReader, msg); + auto data = msg.getData(); + auto timestamp = util::time::fromStructTimeval(p.msg_time); + + for (auto const &cb : self->m_cb_map) { + cb(data, timestamp); + } + return 0; + } + + } // namespace common } // namespace osvr From 31ee758c4a7d627bcaef8ad50389acb120bd0466 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:44:17 -0400 Subject: [PATCH 24/73] add accessor for system component to client context. this will allow client to get access to registered string map --- src/osvr/Client/PureClientContext.cpp | 21 +++++++++++++++++++-- src/osvr/Client/PureClientContext.h | 12 ++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/osvr/Client/PureClientContext.cpp b/src/osvr/Client/PureClientContext.cpp index 3a5f7cc70..ff72c836c 100644 --- a/src/osvr/Client/PureClientContext.cpp +++ b/src/osvr/Client/PureClientContext.cpp @@ -104,8 +104,15 @@ namespace client { /// Create the system client device. m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn); - m_systemComponent = - m_systemDevice->addComponent(common::SystemComponent::create()); + m_systemComponent = common::SystemComponent::create(); + m_systemDevice->addComponent(m_systemComponent); + + /// Receive string map data whenever it comes + m_systemComponent->registerStringMapHandler( + [&](common::MapData const &dataMap, + util::time::TimeValue const ×tamp) { + m_handleRegStringMap(dataMap, timestamp); + }); using DedupJsonFunction = common::DeduplicatingFunctionWrapper; m_systemComponent->registerReplaceTreeHandler( @@ -205,9 +212,19 @@ namespace client { return m_roomToWorld; } + shared_ptr PureClientContext::m_getSystemComponent() { + return m_systemComponent; + } + void PureClientContext::m_setRoomToWorldTransform( common::Transform const &xform) { m_roomToWorld = xform; } + + void PureClientContext::m_handleRegStringMap(common::MapData const &data, + util::time::TimeValue const ×tamp){ + auto map = m_systemComponent->getRegStringMap(); + map->corrMap.setupPeerMappings(data.serializedMap); + } } // namespace client } // namespace osvr diff --git a/src/osvr/Client/PureClientContext.h b/src/osvr/Client/PureClientContext.h index 73757aa1f..0474439de 100644 --- a/src/osvr/Client/PureClientContext.h +++ b/src/osvr/Client/PureClientContext.h @@ -28,7 +28,7 @@ // Internal Includes #include #include -#include +#include #include #include #include @@ -38,6 +38,8 @@ #include #include #include +#include "RemoteHandlerFactory.h" +#include // Library/third-party includes #include @@ -74,6 +76,8 @@ namespace client { common::PathTree const &m_getPathTree() const override; + virtual shared_ptr m_getSystemComponent(); + common::Transform const &m_getRoomToWorldTransform() const override; void m_setRoomToWorldTransform(common::Transform const &xform) override; @@ -91,7 +95,7 @@ namespace client { /// @brief The system component providing access to sending/receiving /// control messages. - common::SystemComponent *m_systemComponent; + shared_ptr m_systemComponent; /// @brief All open VRPN connections, keyed by host VRPNConnectionCollection m_vrpnConns; @@ -114,6 +118,10 @@ namespace client { /// @brief Manager of client interface objects and their interaction /// with the path tree. ClientInterfaceObjectManager m_ifaceMgr; + + /// @brief Called whenever an updated string to ID map is available + void m_handleRegStringMap(common::MapData const &data, + util::time::TimeValue const ×tamp); }; } // namespace client } // namespace osvr From 2923bbfbc0909c84ae108a06c6dc6a15893c70ff Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:52:33 -0400 Subject: [PATCH 25/73] move RegisteredStringMap out of gesture component --- inc/osvr/Common/GestureComponent.h | 46 +++------ src/osvr/Common/GestureComponent.cpp | 149 ++++++--------------------- 2 files changed, 43 insertions(+), 152 deletions(-) diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index a1d84d65a..affd01661 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -35,7 +35,8 @@ #include #include -#include +#include +#include // Library/third-party includes #include @@ -52,11 +53,6 @@ namespace common { StringID gestureID; }; - struct GestureMap { - GestureData data; - SerializedStringMap serializedMap; - }; - namespace messages { class GestureRecord : public MessageRegistration { public: @@ -65,13 +61,6 @@ namespace common { static const char *identifier(); }; - class GestureMapRecord : public MessageRegistration { - public: - class MessageSerialization; - - static const char *identifier(); - }; - } // namespace messages /// @brief BaseDevice component @@ -82,18 +71,13 @@ namespace common { /// Required to ensure that allocation and deallocation stay on the same /// side of a DLL line. static OSVR_COMMON_EXPORT shared_ptr - create(OSVR_ChannelCount numSensor = 1); + create(SystemComponentPtr sysComp); + + //OSVR_COMMON_EXPORT ~GestureComponent(); /// @brief Message from server to client, containing Gesture data. messages::GestureRecord gestureRecord; - /// @brief Message from server to client, containing gesture map - messages::GestureMapRecord gestureMapRecord; - - OSVR_COMMON_EXPORT void sendGestureData( - OSVR_GestureState gestureState, std::string const &gestureName, - OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); - OSVR_COMMON_EXPORT void sendGestureData( OSVR_GestureState gestureState, OSVR_GestureID gestureID, OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); @@ -103,36 +87,30 @@ namespace common { typedef std::function GestureHandler; - typedef std::function - GestureMapHandler; - OSVR_COMMON_EXPORT void registerGestureHandler(GestureHandler cb); - OSVR_COMMON_EXPORT void registerGestureMapHandler(GestureMapHandler cb); OSVR_COMMON_EXPORT OSVR_GestureID getGestureID(const char *gestureName); private: - GestureComponent(OSVR_ChannelCount numChan); + GestureComponent(SystemComponentPtr sysComp); + virtual void m_parentSet(); static int VRPN_CALLBACK m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p); - static int VRPN_CALLBACK - m_handleGestureMapRecord(void *userdata, vrpn_HANDLERPARAM p); void m_checkFirst(OSVR_GestureState const &gesture); OSVR_ChannelCount m_numSensor; std::vector m_cb; - std::vector m_cb_map; - bool m_gotOne; // name to ID map used by the server - RegisteredStringMap m_gestureNameMap; + //RegisteredStringMap m_gestureNameMap; + MapPtr m_gestureNameMap; - /// @brief Common component for system device - common::CommonComponent *m_commonComponent; + /// @brief System device component + shared_ptr m_sysComponent; + }; } // namespace common diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index 1cdf82e11..75d5aaad3 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -30,10 +30,6 @@ #include #include -#include -#include -#include - // Library/third-party includes // - none @@ -76,77 +72,44 @@ namespace common { return "com.osvr.gesture.gesturerecord"; } - class GestureMapRecord::MessageSerialization { - public: - MessageSerialization(SerializedStringMap serializedMap) - : m_serializedMap(serializedMap) {} - - MessageSerialization() {} - - template void processMessage(T &p) { - p(m_serializedMap); - } - GestureMap getData() const { - GestureMap ret; - ret.serializedMap = m_serializedMap; - return ret; - } - - private: - SerializedStringMap m_serializedMap; - }; - const char *GestureMapRecord::identifier() { - return "com.osvr.gesture.gesturemaprecord"; - } - } // namespace messages shared_ptr - GestureComponent::create(OSVR_ChannelCount numChan) { - shared_ptr ret(new GestureComponent(numChan)); + GestureComponent::create(SystemComponentPtr sysComp) { + shared_ptr ret(new GestureComponent(sysComp)); return ret; } - GestureComponent::GestureComponent(OSVR_ChannelCount numChan) - : m_numSensor(numChan) { + GestureComponent::GestureComponent(SystemComponentPtr sysComp) + { + // Add system component and gesture map + m_sysComponent = sysComp; + m_gestureNameMap = m_sysComponent->getRegStringMap(); // populate the gesture map - m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIPE_LEFT); - m_gestureNameMap.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); - m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_UP); - m_gestureNameMap.registerStringID(OSVR_GESTURE_SCROLL_DOWN); - m_gestureNameMap.registerStringID(OSVR_GESTURE_SINGLE_TAP); - m_gestureNameMap.registerStringID(OSVR_GESTURE_DOUBLE_TAP); - m_gestureNameMap.registerStringID(OSVR_GESTURE_PINCH); - m_gestureNameMap.registerStringID(OSVR_GESTURE_FINGER_SPREAD); - m_gestureNameMap.registerStringID(OSVR_GESTURE_CIRCLE); - m_gestureNameMap.registerStringID(OSVR_GESTURE_LONG_PRESS); - m_gestureNameMap.registerStringID(OSVR_GESTURE_OPEN_HAND); - m_gestureNameMap.registerStringID(OSVR_GESTURE_CLOSED_HAND); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_LEFT); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_UP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_DOWN); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SINGLE_TAP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_DOUBLE_TAP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_PINCH); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_FINGER_SPREAD); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CIRCLE); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_LONG_PRESS); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_OPEN_HAND); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CLOSED_HAND); + + //send out an updated map + m_sysComponent->sendRegisteredStringMap(); } - void GestureComponent::sendGestureData(OSVR_GestureState gestureState, - std::string const &gestureName, - OSVR_ChannelCount sensor, - OSVR_TimeValue const ×tamp) { - - Buffer<> buf; - - StringID gestureID = m_gestureNameMap.getStringID(gestureName); - - // if we just inserted new gesture ID then send gesture map - if (m_gestureNameMap.isUpdateAvailable()) { - m_sendGestureMap(timestamp); - } - - messages::GestureRecord::MessageSerialization msg(gestureState, - gestureID, sensor); - serialize(buf, msg); - - m_getParent().packMessage(buf, gestureRecord.getMessageType(), - timestamp); + /* + GestureComponent::~GestureComponent(){ + m_gestureNameMap.reset(); + m_sysComponent.reset(); } - + */ void GestureComponent::sendGestureData( OSVR_GestureState gestureState, OSVR_GestureID gestureID, OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp){ @@ -162,19 +125,6 @@ namespace common { } - void GestureComponent::m_sendGestureMap(OSVR_TimeValue const ×tamp) { - - Buffer<> buf; - - SerializedStringMap serializedMap = m_gestureNameMap.getMap(); - - messages::GestureMapRecord::MessageSerialization msg(serializedMap); - serialize(buf, msg); - - m_getParent().packMessage(buf, gestureMapRecord.getMessageType(), - timestamp); - } - int VRPN_CALLBACK GestureComponent::m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p) { @@ -192,23 +142,6 @@ namespace common { return 0; } - int VRPN_CALLBACK - GestureComponent::m_handleGestureMapRecord(void *userdata, - vrpn_HANDLERPARAM p) { - auto self = static_cast(userdata); - auto bufReader = readExternalBuffer(p.buffer, p.payload_len); - - messages::GestureMapRecord::MessageSerialization msg; - deserialize(bufReader, msg); - auto data = msg.getData(); - auto timestamp = util::time::fromStructTimeval(p.msg_time); - - for (auto const &cb : self->m_cb_map) { - cb(data, timestamp); - } - return 0; - } - void GestureComponent::registerGestureHandler(GestureHandler handler) { if (m_cb.empty()) { m_registerHandler(&GestureComponent::m_handleGestureRecord, this, @@ -216,44 +149,24 @@ namespace common { } m_cb.push_back(handler); } - void - GestureComponent::registerGestureMapHandler(GestureMapHandler handler) { - if (m_cb_map.empty()) { - m_registerHandler(&GestureComponent::m_handleGestureMapRecord, this, - gestureMapRecord.getMessageType()); - } - m_cb_map.push_back(handler); - } void GestureComponent::m_parentSet() { - - // add a ping handler to re-send gesture map everytime the new - // connection(ping) occurs - m_commonComponent = - m_getParent().addComponent(osvr::common::CommonComponent::create()); - OSVR_TimeValue now; - osvrTimeValueGetNow(&now); - m_commonComponent->registerPingHandler([&] { m_sendGestureMap(now); }); - m_getParent().registerMessageType(gestureRecord); - m_getParent().registerMessageType(gestureMapRecord); } OSVR_GestureID GestureComponent::getGestureID(const char *gestureName){ - - OSVR_GestureID gestureID = m_gestureNameMap.getStringID(gestureName); + + OSVR_GestureID gestureID = m_gestureNameMap->map.getStringID(gestureName); OSVR_TimeValue now; osvrTimeValueGetNow(&now); // if we just inserted new gesture ID then send gesture map - if (m_gestureNameMap.isUpdateAvailable()) { - m_sendGestureMap(now); + if (m_gestureNameMap->map.isUpdateAvailable()) { + m_sysComponent->sendRegisteredStringMap(); } - return gestureID; } - } // namespace common } // namespace osvr \ No newline at end of file From e71c6fcdafe140664e90d7f5238fbef80cff3863 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:53:56 -0400 Subject: [PATCH 26/73] move RegisteredStringMap out of remote factory and use system component instead --- src/osvr/Client/GestureRemoteFactory.cpp | 41 ++++++++---------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index f5445b5ef..aca7b3e15 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -52,12 +52,15 @@ namespace client { GestureRemoteHandler(vrpn_ConnectionPtr const &conn, std::string const &deviceName, boost::optional sensor, - common::InterfaceList &ifaces) + common::InterfaceList &ifaces, + common::ClientContext* ctx) : m_dev(common::createClientDevice(deviceName, conn)), m_interfaces(ifaces), m_all(!sensor.is_initialized()), - m_sensor(sensor) { + m_sensor(sensor), m_ctx(ctx){ - auto gesture = common::GestureComponent::create(); + m_sysComponent = m_ctx->getSystemComponent(); + m_gestureNameMap = m_sysComponent->getRegStringMap(); + auto gesture = common::GestureComponent::create(m_sysComponent); m_dev->addComponent(gesture); gesture->registerGestureHandler( @@ -65,11 +68,6 @@ namespace client { util::time::TimeValue const ×tamp) { m_handleGesture(data, timestamp); }); - gesture->registerGestureMapHandler( - [&](common::GestureMap const &dataMap, - util::time::TimeValue const ×tamp) { - m_handleGestureMap(dataMap, timestamp); - }); /**/ OSVR_DEV_VERBOSE("Constructed an Gesture Handler for " @@ -94,22 +92,16 @@ namespace client { } OSVR_GestureReport report; - - osvr::common::StringID id = - localGestureMap.convertPeerToLocalID(data.gestureID); + StringID id = + m_gestureNameMap->corrMap.convertPeerToLocalID(data.gestureID); if (id.empty()) { // could not find a peer to local mapping, discarding report return; } - std::string gestureName = localGestureMap.getNameFromID(id); - if (gestureName.empty()) { - // could not find gesture name for this id, discarding report - return; - } report.sensor = data.sensor; report.state = data.gestureState; - report.gestureID = data.gestureID; + report.gestureID = id; common::ClientInterfacePtr anInterface; for (auto &iface : m_interfaces) { anInterface = iface; @@ -117,19 +109,14 @@ namespace client { } } - void m_handleGestureMap(common::GestureMap const &data, - util::time::TimeValue const ×tamp) { - - // got the gesture map, will need to sync with ours - localGestureMap.setupPeerMappings(data.serializedMap); - } - common::BaseDevicePtr m_dev; common::InterfaceList &m_interfaces; bool m_all; boost::optional m_sensor; // map to keep track of gesture map and server to local ID map - common::CorrelatedStringMap localGestureMap; + common::MapPtr m_gestureNameMap; + common::ClientContext* m_ctx; + shared_ptr m_sysComponent; }; GestureRemoteFactory::GestureRemoteFactory( @@ -138,7 +125,7 @@ namespace client { shared_ptr GestureRemoteFactory:: operator()(common::OriginalSource const &source, - common::InterfaceList &ifaces, common::ClientContext &) { + common::InterfaceList &ifaces, common::ClientContext &ctx) { shared_ptr ret; @@ -152,7 +139,7 @@ namespace client { /// @todo find out why make_shared causes a crash here ret.reset(new GestureRemoteHandler( m_conns.getConnection(devElt), devElt.getFullDeviceName(), - source.getSensorNumberAsChannelCount(), ifaces)); + source.getSensorNumberAsChannelCount(), ifaces, &ctx)); return ret; } From 4ac55ec992defc0b5dfd8c517d5714e06af624a7 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:54:47 -0400 Subject: [PATCH 27/73] add accessor to parent (RegistrationContext) --- inc/osvr/Connection/DeviceInitObject.h | 3 +++ src/osvr/Connection/DeviceInitObject.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/inc/osvr/Connection/DeviceInitObject.h b/inc/osvr/Connection/DeviceInitObject.h index 311aefab4..42fc1ecfd 100644 --- a/inc/osvr/Connection/DeviceInitObject.h +++ b/inc/osvr/Connection/DeviceInitObject.h @@ -37,6 +37,7 @@ #include #include #include +#include // Library/third-party includes #include @@ -156,6 +157,8 @@ struct OSVR_DeviceInitObject : boost::noncopyable { return m_components; } + OSVR_CONNECTION_EXPORT osvr::pluginhost::RegistrationContext* getParentContext(); + private: osvr::pluginhost::PluginSpecificRegistrationContext *m_context; osvr::connection::ConnectionPtr m_conn; diff --git a/src/osvr/Connection/DeviceInitObject.cpp b/src/osvr/Connection/DeviceInitObject.cpp index 7950c160b..c7d647c26 100644 --- a/src/osvr/Connection/DeviceInitObject.cpp +++ b/src/osvr/Connection/DeviceInitObject.cpp @@ -127,3 +127,8 @@ osvr::pluginhost::PluginSpecificRegistrationContext * OSVR_DeviceInitObject::getContext() { return m_context; } + +osvr::pluginhost::RegistrationContext* OSVR_DeviceInitObject::getParentContext(){ + + return &m_context->getParent(); +} \ No newline at end of file From dafdf8d1efbe5dd034ff6cbd0c703d194d038291 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:55:43 -0400 Subject: [PATCH 28/73] add ClientKit methods to convert ID to string from RegisteredStringMap --- inc/osvr/ClientKit/Context.h | 25 +++++++++++++++++++ inc/osvr/ClientKit/Context_decl.h | 13 +++------- inc/osvr/ClientKit/InterfaceC.h | 29 +++++++++++++++++++++- src/osvr/ClientKit/CMakeLists.txt | 4 ++- src/osvr/ClientKit/InterfaceC.cpp | 41 +++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 11 deletions(-) diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index 71d7b0043..e272fc39d 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -38,6 +38,7 @@ // Standard includes #include #include +#include namespace osvr { @@ -112,6 +113,30 @@ namespace clientkit { return osvrClientCheckStatus(m_context) == OSVR_RETURN_SUCCESS; } + inline std::string ClientContext::getNamefromID(StringID id) { + + size_t length = 0; + OSVR_ReturnCode ret = osvrClientGetNameLength( + m_context, id, &length); + if (OSVR_RETURN_SUCCESS != ret) { + throw std::runtime_error( + "Invalid context or null reference to length variable."); + } + + if (0 == length) { + return std::string(); + } + + boost::scoped_array buf(new char[length]); + ret = osvrClientGetNameFromID(m_context, id, buf.get(), + length); + if (OSVR_RETURN_SUCCESS != ret) { + throw std::runtime_error("Invalid context, null reference to " + "buffer, or buffer is too small."); + } + return std::string(buf.get()); + } + } // end namespace clientkit } // end namespace osvr diff --git a/inc/osvr/ClientKit/Context_decl.h b/inc/osvr/ClientKit/Context_decl.h index e805e1d57..447538d64 100644 --- a/inc/osvr/ClientKit/Context_decl.h +++ b/inc/osvr/ClientKit/Context_decl.h @@ -25,17 +25,9 @@ #ifndef INCLUDED_ClientContext_decl_h_GUID_1EFFF79A_3D9F_4794_9F98_37010949F386 #define INCLUDED_ClientContext_decl_h_GUID_1EFFF79A_3D9F_4794_9F98_37010949F386 -// Internal Includes -// - none - -// Library/third-party includes -// - none - -// Standard includes -// - none - // Internal Includes #include +#include // Library/third-party includes #include @@ -98,6 +90,9 @@ namespace clientkit { /// @brief Gets the bare OSVR_ClientContext. OSVR_ClientContext get(); + /// @brief converts ID to string name + std::string getNamefromID(StringID id); + private: OSVR_ClientContext m_context; }; diff --git a/inc/osvr/ClientKit/InterfaceC.h b/inc/osvr/ClientKit/InterfaceC.h index 728350536..aec548bec 100644 --- a/inc/osvr/ClientKit/InterfaceC.h +++ b/inc/osvr/ClientKit/InterfaceC.h @@ -40,7 +40,7 @@ /* none */ /* Standard includes */ -/* none */ +#include OSVR_EXTERN_C_BEGIN /** @addtogroup ClientKit @@ -69,6 +69,33 @@ osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientFreeInterface(OSVR_ClientContext ctx, OSVR_ClientInterface iface); +/** @brief Get the length of a string parameter associated with the given path. +@param ctx Client context +@param path A resource path (null-terminated string) +@param[out] len The length of the string value, including null terminator. 0 +if the parameter does not exist or is not a string. + +*/ +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode +osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len); + +/** @brief Convert the ID to string name representation + +@param ctx Client context +@param id An id that corresponds to an entry in string to ID map +@param [in, out] buf A buffer that you allocate of appropriate size. +Must be at least the length returned by osvrClientGetStringParameterLength. +Will contain the null-terminated string parameter value. +@param len The length of the buffer you're providing. If the buffer is too +short, an error is returned and the buffer is unchanged. + +@returns It will copy the name of entry name that corresponds to the +provided id +*/ +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode +osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, + char *buf, size_t len); + /** @} */ OSVR_EXTERN_C_END diff --git a/src/osvr/ClientKit/CMakeLists.txt b/src/osvr/ClientKit/CMakeLists.txt index 48b0834af..71227e2e4 100644 --- a/src/osvr/ClientKit/CMakeLists.txt +++ b/src/osvr/ClientKit/CMakeLists.txt @@ -55,7 +55,9 @@ target_link_libraries(${LIBNAME_FULL} osvrClient osvrUtilCpp osvrCommon - eigen-headers) + eigen-headers + jsoncpp_lib + vendored-vrpn) ### # C++ (header-only) interface diff --git a/src/osvr/ClientKit/InterfaceC.cpp b/src/osvr/ClientKit/InterfaceC.cpp index 7116a415a..5f4e89b4e 100644 --- a/src/osvr/ClientKit/InterfaceC.cpp +++ b/src/osvr/ClientKit/InterfaceC.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include // Library/third-party includes // - none @@ -71,3 +73,42 @@ OSVR_ReturnCode osvrClientFreeInterface(OSVR_ClientContext ctx, } return OSVR_RETURN_SUCCESS; } + +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode +osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len){ + + if (ctx == nullptr) { + return OSVR_RETURN_FAILURE; + } + if (len == nullptr) { + return OSVR_RETURN_FAILURE; + } + std::string entryName = + ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID(StringID(id)); + *len = entryName.empty() ? 0 : (entryName.size() + 1); + return OSVR_RETURN_SUCCESS; +} + +OSVR_ReturnCode +osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, + char *buf, size_t len){ + + if (ctx == nullptr) { + return OSVR_RETURN_FAILURE; + } + if (buf == nullptr) { + return OSVR_RETURN_FAILURE; + } + + std::string entryName = + ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID(StringID(id)); + + if (entryName.size() + 1 > len) { + /// buffer too small. + return OSVR_RETURN_FAILURE; + } + entryName.copy(buf, entryName.size()); + buf[entryName.size()] = '\0'; + return OSVR_RETURN_SUCCESS; + +} From 6acdcfd8ef1ea351c2dc036df01a43aa72bc7956 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:56:23 -0400 Subject: [PATCH 29/73] add accessor for SystemComponent --- inc/osvr/Common/ClientContext.h | 8 ++++++++ src/osvr/Common/ClientContext.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/inc/osvr/Common/ClientContext.h b/inc/osvr/Common/ClientContext.h index da7c3c721..6186156b4 100644 --- a/inc/osvr/Common/ClientContext.h +++ b/inc/osvr/Common/ClientContext.h @@ -34,6 +34,7 @@ #include #include #include +#include #include // Library/third-party includes @@ -87,6 +88,9 @@ struct OSVR_ClientContextObject : boost::noncopyable { /// @brief Accessor for the path tree. OSVR_COMMON_EXPORT osvr::common::PathTree const &getPathTree() const; + /// @brief Accessor for the system component + OSVR_COMMON_EXPORT std::shared_ptr getSystemComponent(); + /// @brief Pass (smart-pointer) ownership of some object to the client /// context. template void *acquireObject(T obj) { @@ -153,6 +157,10 @@ struct OSVR_ClientContextObject : boost::noncopyable { virtual void m_setRoomToWorldTransform(osvr::common::Transform const &xform) = 0; + /// @brief Implementation of accessor for the path tree. + OSVR_COMMON_EXPORT virtual std::shared_ptr + m_getSystemComponent() = 0; + std::string const m_appId; InterfaceList m_interfaces; osvr::common::ClientInterfaceFactory m_clientInterfaceFactory; diff --git a/src/osvr/Common/ClientContext.cpp b/src/osvr/Common/ClientContext.cpp index 64b1941a5..d60a17dc5 100644 --- a/src/osvr/Common/ClientContext.cpp +++ b/src/osvr/Common/ClientContext.cpp @@ -122,6 +122,10 @@ osvr::common::PathTree const &OSVR_ClientContextObject::getPathTree() const { return m_getPathTree(); } +std::shared_ptr OSVR_ClientContextObject::getSystemComponent(){ + return m_getSystemComponent(); +} + void OSVR_ClientContextObject::sendRoute(std::string const &route) { m_sendRoute(route); } From 31607bc8925951ea591a998dd4e8c65af9a3840f Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Mon, 10 Aug 2015 18:57:28 -0400 Subject: [PATCH 30/73] move ID out of RegisteredStringMap to a separate place --- inc/osvr/Util/ID.h | 74 ++++++++++++++++++++++++++++++++++++ src/osvr/Util/CMakeLists.txt | 1 + 2 files changed, 75 insertions(+) create mode 100644 inc/osvr/Util/ID.h diff --git a/inc/osvr/Util/ID.h b/inc/osvr/Util/ID.h new file mode 100644 index 000000000..de6b8385a --- /dev/null +++ b/inc/osvr/Util/ID.h @@ -0,0 +1,74 @@ +/** @file + @brief Header + + @date 2015 + + @author + Sensics, Inc. + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 +#define INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 + + +// Internal Includes +// - none + +// Library/third-party includes +// - none + +// Standard includes +#include +#include + + /// idea from the + /// http://www.ilikebigbits.com/blog/2014/5/6/type-safe-identifiers-in-c + template class ID { + public: + static ID invalid() { return ID(); } + + // Default constructor which will set m_val to a 0xffffffff (UINT32 max) + // and signify empty. + ID() : m_val(0xffffffff) {} + + // Explicit constructor: + explicit ID(impl val) : m_val(val) {} + + // Explicit conversion to get back the impl: + // explicit operator impl() const { return m_val; } + + // Implicit conversion to get back the impl + operator impl() const { return m_val; } + + bool empty() const { return m_val == 0xffffffff ? true : false; } + + // this messes with implicit conversion (type casting) + /* + friend bool operator>(ID a, impl b) { return a.m_val > b; } + friend bool operator<(ID a, impl b) { return a.m_val < b; } + friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } + friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } + */ + impl m_val; + }; + + typedef ID StringID; + typedef ID PeerStringID; + +#endif // INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 + diff --git a/src/osvr/Util/CMakeLists.txt b/src/osvr/Util/CMakeLists.txt index 72618293c..544801c88 100644 --- a/src/osvr/Util/CMakeLists.txt +++ b/src/osvr/Util/CMakeLists.txt @@ -65,6 +65,7 @@ set(API "${HEADER_LOCATION}/ExtractYaw.h" "${HEADER_LOCATION}/Finally.h" "${HEADER_LOCATION}/Flag.h" + "${HEADER_LOCATION}/ID.h" "${HEADER_LOCATION}/GenericCaller.h" "${HEADER_LOCATION}/GenericDeleter.h" "${HEADER_LOCATION}/GuardInterface.h" From cfe1ff701a7ead882ba88aa379e5f71fb9e883a5 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 17:15:01 -0400 Subject: [PATCH 31/73] remove unnecessary destructor, change pointer type, and minor corrections --- inc/osvr/Common/GestureComponent.h | 24 ++++--- src/osvr/Common/GestureComponent.cpp | 97 +++++++++++++--------------- 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index affd01661..7c352ea24 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -71,16 +71,15 @@ namespace common { /// Required to ensure that allocation and deallocation stay on the same /// side of a DLL line. static OSVR_COMMON_EXPORT shared_ptr - create(SystemComponentPtr sysComp); - - //OSVR_COMMON_EXPORT ~GestureComponent(); + create(common::SystemComponent *systemComponent); /// @brief Message from server to client, containing Gesture data. messages::GestureRecord gestureRecord; - OSVR_COMMON_EXPORT void sendGestureData( - OSVR_GestureState gestureState, OSVR_GestureID gestureID, - OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp); + OSVR_COMMON_EXPORT void + sendGestureData(OSVR_GestureState gestureState, + OSVR_GestureID gestureID, OSVR_ChannelCount sensor, + OSVR_TimeValue const ×tamp); void m_sendGestureMap(OSVR_TimeValue const ×tamp); @@ -89,10 +88,10 @@ namespace common { OSVR_COMMON_EXPORT void registerGestureHandler(GestureHandler cb); - OSVR_COMMON_EXPORT OSVR_GestureID getGestureID(const char *gestureName); + OSVR_COMMON_EXPORT OSVR_GestureID getGestureID(const char *gestureName); private: - GestureComponent(SystemComponentPtr sysComp); + GestureComponent(common::SystemComponent *systemComponent); virtual void m_parentSet(); @@ -105,12 +104,11 @@ namespace common { std::vector m_cb; // name to ID map used by the server - //RegisteredStringMap m_gestureNameMap; - MapPtr m_gestureNameMap; + // RegisteredStringMap m_gestureNameMap; + MapPtr m_gestureNameMap; - /// @brief System device component - shared_ptr m_sysComponent; - + /// @brief System device component + common::SystemComponent *m_systemComponent; }; } // namespace common diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index 75d5aaad3..7a5124db6 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -75,55 +75,49 @@ namespace common { } // namespace messages shared_ptr - GestureComponent::create(SystemComponentPtr sysComp) { - shared_ptr ret(new GestureComponent(sysComp)); + GestureComponent::create(common::SystemComponent *systemComponent) { + shared_ptr ret(new GestureComponent(systemComponent)); return ret; } - GestureComponent::GestureComponent(SystemComponentPtr sysComp) - { - // Add system component and gesture map - m_sysComponent = sysComp; - m_gestureNameMap = m_sysComponent->getRegStringMap(); + GestureComponent::GestureComponent( + common::SystemComponent *systemComponent) { + // Add system component and gesture map + m_systemComponent = systemComponent; + m_gestureNameMap = m_systemComponent->getRegStringMap(); // populate the gesture map m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_LEFT); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_UP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_DOWN); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SINGLE_TAP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_DOUBLE_TAP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_PINCH); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_FINGER_SPREAD); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CIRCLE); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_LONG_PRESS); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_OPEN_HAND); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CLOSED_HAND); - - //send out an updated map - m_sysComponent->sendRegisteredStringMap(); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_UP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_DOWN); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SINGLE_TAP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_DOUBLE_TAP); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_PINCH); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_FINGER_SPREAD); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CIRCLE); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_LONG_PRESS); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_OPEN_HAND); + m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CLOSED_HAND); + + // send out an updated map + m_systemComponent->sendRegisteredStringMap(); } - /* - GestureComponent::~GestureComponent(){ - m_gestureNameMap.reset(); - m_sysComponent.reset(); - } - */ - void GestureComponent::sendGestureData( - OSVR_GestureState gestureState, OSVR_GestureID gestureID, - OSVR_ChannelCount sensor, OSVR_TimeValue const ×tamp){ - - Buffer<> buf; + void GestureComponent::sendGestureData(OSVR_GestureState gestureState, + OSVR_GestureID gestureID, + OSVR_ChannelCount sensor, + OSVR_TimeValue const ×tamp) { - messages::GestureRecord::MessageSerialization msg(gestureState, - gestureID, sensor); - serialize(buf, msg); + Buffer<> buf; - m_getParent().packMessage(buf, gestureRecord.getMessageType(), - timestamp); + messages::GestureRecord::MessageSerialization msg(gestureState, + gestureID, sensor); + serialize(buf, msg); - } + m_getParent().packMessage(buf, gestureRecord.getMessageType(), + timestamp); + } int VRPN_CALLBACK GestureComponent::m_handleGestureRecord(void *userdata, @@ -154,19 +148,20 @@ namespace common { m_getParent().registerMessageType(gestureRecord); } - OSVR_GestureID GestureComponent::getGestureID(const char *gestureName){ - - OSVR_GestureID gestureID = m_gestureNameMap->map.getStringID(gestureName); - - OSVR_TimeValue now; - osvrTimeValueGetNow(&now); - - // if we just inserted new gesture ID then send gesture map - if (m_gestureNameMap->map.isUpdateAvailable()) { - m_sysComponent->sendRegisteredStringMap(); - } - return gestureID; - } + OSVR_GestureID GestureComponent::getGestureID(const char *gestureName) { + + OSVR_GestureID gestureID = + m_gestureNameMap->map.getStringID(gestureName); + + OSVR_TimeValue now; + osvrTimeValueGetNow(&now); + + // if we just inserted new gesture ID then send gesture map + if (m_gestureNameMap->map.isUpdateAvailable()) { + m_systemComponent->sendRegisteredStringMap(); + } + return gestureID; + } } // namespace common } // namespace osvr \ No newline at end of file From 1fcbf16e1173ab848d683c89b5811d9ad4a143fa Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 17:37:47 -0400 Subject: [PATCH 32/73] add getter/setter to SystemComponent to let gesture(and other components) access to it thru DeviceInitObject --- inc/osvr/PluginHost/RegistrationContext.h | 12 +++++++++++- src/osvr/PluginHost/CMakeLists.txt | 2 ++ src/osvr/PluginHost/RegistrationContext.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/inc/osvr/PluginHost/RegistrationContext.h b/inc/osvr/PluginHost/RegistrationContext.h index 51996dd1b..5c51158a3 100644 --- a/inc/osvr/PluginHost/RegistrationContext.h +++ b/inc/osvr/PluginHost/RegistrationContext.h @@ -33,6 +33,7 @@ #include #include #include +#include // Library/third-party includes #include @@ -90,8 +91,15 @@ namespace pluginhost { /// @brief Const access the data storage map. OSVR_PLUGINHOST_EXPORT util::AnyMap const &data() const; - /// @} + /// @brief Store a copy of system component + OSVR_PLUGINHOST_EXPORT void + setSystemComponent(common::SystemComponent *systemComponent); + + /// @brief Return a copy of system component + OSVR_PLUGINHOST_EXPORT common::SystemComponent *getSystemComponent(); + + /// @} private: /// @brief Map of plugin names to owning pointers for plugin /// registration. @@ -102,6 +110,8 @@ namespace pluginhost { struct Impl; /// Private impl. unique_ptr m_impl; + + common::SystemComponent *m_systemComponent; }; } // namespace pluginhost } // namespace osvr diff --git a/src/osvr/PluginHost/CMakeLists.txt b/src/osvr/PluginHost/CMakeLists.txt index 1b09f0f54..5f3b2d654 100644 --- a/src/osvr/PluginHost/CMakeLists.txt +++ b/src/osvr/PluginHost/CMakeLists.txt @@ -41,6 +41,8 @@ target_link_libraries(${LIBNAME_FULL} PUBLIC libfunctionality::functionality osvrUtilCpp + osvrCommon + jsoncpp_lib PRIVATE boost_filesystem) diff --git a/src/osvr/PluginHost/RegistrationContext.cpp b/src/osvr/PluginHost/RegistrationContext.cpp index 8ea44c6c7..f81016de7 100644 --- a/src/osvr/PluginHost/RegistrationContext.cpp +++ b/src/osvr/PluginHost/RegistrationContext.cpp @@ -187,5 +187,15 @@ namespace pluginhost { util::AnyMap &RegistrationContext::data() { return m_data; } util::AnyMap const &RegistrationContext::data() const { return m_data; } + + void RegistrationContext::setSystemComponent( + common::SystemComponent *systemComponent) { + m_systemComponent = systemComponent; + } + + common::SystemComponent *RegistrationContext::getSystemComponent() { + return m_systemComponent; + } + } // namespace pluginhost } // namespace osvr From d1788154b12b3c1a766a3825d4b106f527c5a28d Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 17:41:27 -0400 Subject: [PATCH 33/73] use deviceInitOpts to give SystemComponent ptr to GestureComponent, remove unnecessary args to GestureInterface, clean up comments --- inc/osvr/Connection/DeviceInitObject.h | 3 +- inc/osvr/PluginKit/GestureInterfaceC.h | 36 ++++----------------- src/osvr/Connection/DeviceInitObject.cpp | 3 +- src/osvr/PluginKit/GestureInterfaceC.cpp | 41 +++++++----------------- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/inc/osvr/Connection/DeviceInitObject.h b/inc/osvr/Connection/DeviceInitObject.h index 42fc1ecfd..b7d277c5d 100644 --- a/inc/osvr/Connection/DeviceInitObject.h +++ b/inc/osvr/Connection/DeviceInitObject.h @@ -157,7 +157,8 @@ struct OSVR_DeviceInitObject : boost::noncopyable { return m_components; } - OSVR_CONNECTION_EXPORT osvr::pluginhost::RegistrationContext* getParentContext(); + OSVR_CONNECTION_EXPORT osvr::pluginhost::RegistrationContext * + getParentContext(); private: osvr::pluginhost::PluginSpecificRegistrationContext *m_context; diff --git a/inc/osvr/PluginKit/GestureInterfaceC.h b/inc/osvr/PluginKit/GestureInterfaceC.h index 66beb91d5..12198dd24 100644 --- a/inc/osvr/PluginKit/GestureInterfaceC.h +++ b/inc/osvr/PluginKit/GestureInterfaceC.h @@ -49,15 +49,12 @@ typedef struct OSVR_GestureDeviceInterfaceObject *OSVR_GestureDeviceInterface; @param [out] iface An interface object you should retain with the same lifetime as the device token in order to send messages conforming to an Gesture interface. -@param numSensors The number of sensors you will be reporting Gesture data : -You can report 1+ sensors. This parameter may be subject to external limitations */ OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, - OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface, - OSVR_IN OSVR_ChannelCount numSensors - OSVR_CPP_ONLY(= 1)) OSVR_FUNC_NONNULL((1, 2)); + OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface) + OSVR_FUNC_NONNULL((1, 2)); /** @brief Obtain an ID for a given gesture name @param iface GestureInterface @@ -65,15 +62,14 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, @param gestureID pointer to an id variable */ OSVR_PLUGINKIT_EXPORT -void -osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, - OSVR_IN_PTR const char *gestureName, - OSVR_IN_PTR OSVR_GestureID *gestureID) +void osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN_PTR const char *gestureName, + OSVR_IN_PTR OSVR_GestureID *gestureID) OSVR_FUNC_NONNULL((1, 2)); /** @brief Report data for a specific sensor. @param iface Gesture interface -@param gestureID ID of the gesture corresponding to specific name +@param gestureID Pre-fetched ID of the gesture @param gestureState Current state of gesture (In process vs Completed) @param sensor Sensor number @param timestamp Timestamp correlating to Gesture data. @@ -87,26 +83,6 @@ osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, OSVR_IN_PTR OSVR_TimeValue const *timestamp) OSVR_FUNC_NONNULL((1, 5)); - -/** @brief Report data for a specific sensor. -@param iface Gesture interface -@param gestureName String name of gesture -@param gestureState Current state of gesture (In process vs Completed) -@param sensor Sensor number -@param timestamp Timestamp correlating to Gesture data. -*/ -OSVR_PLUGINKIT_EXPORT -OSVR_ReturnCode -osvrDeviceGestureReportDataWithName(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, - OSVR_IN_PTR const char *gestureName, - OSVR_IN_PTR OSVR_GestureState gestureState, - OSVR_IN OSVR_ChannelCount sensor, - OSVR_IN_PTR OSVR_TimeValue const *timestamp) - OSVR_FUNC_NONNULL((1, 5)); - - - - /** @} */ /* end of group */ OSVR_EXTERN_C_END diff --git a/src/osvr/Connection/DeviceInitObject.cpp b/src/osvr/Connection/DeviceInitObject.cpp index c7d647c26..17adfa46d 100644 --- a/src/osvr/Connection/DeviceInitObject.cpp +++ b/src/osvr/Connection/DeviceInitObject.cpp @@ -128,7 +128,8 @@ OSVR_DeviceInitObject::getContext() { return m_context; } -osvr::pluginhost::RegistrationContext* OSVR_DeviceInitObject::getParentContext(){ +osvr::pluginhost::RegistrationContext * +OSVR_DeviceInitObject::getParentContext() { return &m_context->getParent(); } \ No newline at end of file diff --git a/src/osvr/PluginKit/GestureInterfaceC.cpp b/src/osvr/PluginKit/GestureInterfaceC.cpp index 29372d269..2d0c85de5 100644 --- a/src/osvr/PluginKit/GestureInterfaceC.cpp +++ b/src/osvr/PluginKit/GestureInterfaceC.cpp @@ -32,6 +32,7 @@ #include "HandleNullContext.h" #include #include +#include // Library/third-party includes // - none @@ -46,56 +47,38 @@ struct OSVR_GestureDeviceInterfaceObject OSVR_ReturnCode osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, - OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface, - OSVR_IN OSVR_ChannelCount numSensors) { + OSVR_OUT_PTR OSVR_GestureDeviceInterface *iface) { OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceGestureConfigure", opts); OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceGestureConfigure", iface); OSVR_GestureDeviceInterface ifaceObj = opts->makeInterfaceObject(); *iface = ifaceObj; - auto gesture = osvr::common::GestureComponent::create(numSensors); + + auto systemComponent = opts->getParentContext()->getSystemComponent(); + auto gesture = osvr::common::GestureComponent::create(systemComponent); ifaceObj->gesture = gesture.get(); opts->addComponent(gesture); return OSVR_RETURN_SUCCESS; } -void -osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, -OSVR_IN_PTR const char *gestureName, -OSVR_IN_PTR OSVR_GestureID *gestureID){ - - *gestureID = iface->gesture->getGestureID(gestureName); +void osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN_PTR const char *gestureName, + OSVR_IN_PTR OSVR_GestureID *gestureID) { + *gestureID = iface->gesture->getGestureID(gestureName); } OSVR_ReturnCode osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, -OSVR_IN OSVR_GestureID gestureID, -OSVR_IN_PTR OSVR_GestureState gestureState, -OSVR_IN OSVR_ChannelCount sensor, -OSVR_IN_PTR OSVR_TimeValue const *timestamp){ - - auto guard = iface->getSendGuard(); - if (guard->lock()) { - iface->gesture->sendGestureData(gestureState, gestureID, sensor, - *timestamp); - return OSVR_RETURN_SUCCESS; - } - - return OSVR_RETURN_FAILURE; - -} - -OSVR_ReturnCode -osvrDeviceGestureReportDataWithName(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, - OSVR_IN_PTR const char *gestureName, + OSVR_IN OSVR_GestureID gestureID, OSVR_IN_PTR OSVR_GestureState gestureState, OSVR_IN OSVR_ChannelCount sensor, OSVR_IN_PTR OSVR_TimeValue const *timestamp) { + auto guard = iface->getSendGuard(); if (guard->lock()) { - iface->gesture->sendGestureData(gestureState, gestureName, sensor, + iface->gesture->sendGestureData(gestureState, gestureID, sensor, *timestamp); return OSVR_RETURN_SUCCESS; } From 886b506576c7b6985c742b3cb9ac6fef80d01eaa Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 17:53:08 -0400 Subject: [PATCH 34/73] minor changes to sample gesture plugin --- examples/plugin/com_osvr_example_Gesture.cpp | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/plugin/com_osvr_example_Gesture.cpp b/examples/plugin/com_osvr_example_Gesture.cpp index 80770e82a..9a6489c47 100644 --- a/examples/plugin/com_osvr_example_Gesture.cpp +++ b/examples/plugin/com_osvr_example_Gesture.cpp @@ -45,15 +45,15 @@ class GestureDevice { GestureDevice(OSVR_PluginRegContext ctx) { /// Create the initialization options OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); + osvrDeviceGestureConfigure(opts, &m_gesture); - osvrDeviceGestureConfigure(opts, &m_gesture, 2); - /// Create the sync device token with the options m_dev.initSync(ctx, "Gesture", opts); - //get an ID for gesture names to be used in plugin - osvrDeviceGestureGetID(m_gesture, OSVR_GESTURE_DOUBLE_TAP, &m_double_tap_gesture); - osvrDeviceGestureGetID(m_gesture, "FIST", &m_fist_gesture); + // get an ID for gesture names to be used in plugin + osvrDeviceGestureGetID(m_gesture, OSVR_GESTURE_DOUBLE_TAP, + &m_double_tap_gesture); + osvrDeviceGestureGetID(m_gesture, "FIST", &m_fist_gesture); /// Send JSON descriptor m_dev.sendJsonDescriptor(com_osvr_example_Gesture_json); @@ -70,10 +70,10 @@ class GestureDevice { OSVR_TimeValue times; osvrTimeValueGetNow(×); - - osvrDeviceGestureReportData(m_gesture, m_double_tap_gesture, + + osvrDeviceGestureReportData(m_gesture, m_double_tap_gesture, OSVR_GESTURE_COMPLETE, 0, ×); - osvrDeviceGestureReportData(m_gesture, m_fist_gesture, + osvrDeviceGestureReportData(m_gesture, m_fist_gesture, OSVR_GESTURE_COMPLETE, 1, ×); return OSVR_RETURN_SUCCESS; @@ -82,9 +82,8 @@ class GestureDevice { private: osvr::pluginkit::DeviceToken m_dev; OSVR_GestureDeviceInterface m_gesture; - OSVR_GestureID m_fist_gesture; - OSVR_GestureID m_double_tap_gesture; - + OSVR_GestureID m_fist_gesture; + OSVR_GestureID m_double_tap_gesture; }; class HardwareDetection { @@ -98,7 +97,7 @@ class HardwareDetection { std::cout << "PLUGIN: Got a hardware detection request" << std::endl; - /// we always detect device in sample plugin + /// we always detect device in sample plugin m_found = true; std::cout << "PLUGIN: We have detected Gesture device! " << std::endl; From c44d480620853753210ab748e73af288add772fe Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 17:55:50 -0400 Subject: [PATCH 35/73] use raw ptr instead of shared one in ClientContext --- inc/osvr/Common/ClientContext.h | 6 +++--- src/osvr/Client/PureClientContext.cpp | 11 +++++++---- src/osvr/Client/PureClientContext.h | 7 +++---- src/osvr/Common/ClientContext.cpp | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/inc/osvr/Common/ClientContext.h b/inc/osvr/Common/ClientContext.h index 6186156b4..a0f2233b4 100644 --- a/inc/osvr/Common/ClientContext.h +++ b/inc/osvr/Common/ClientContext.h @@ -89,7 +89,7 @@ struct OSVR_ClientContextObject : boost::noncopyable { OSVR_COMMON_EXPORT osvr::common::PathTree const &getPathTree() const; /// @brief Accessor for the system component - OSVR_COMMON_EXPORT std::shared_ptr getSystemComponent(); + OSVR_COMMON_EXPORT osvr::common::SystemComponent *getSystemComponent(); /// @brief Pass (smart-pointer) ownership of some object to the client /// context. @@ -158,8 +158,8 @@ struct OSVR_ClientContextObject : boost::noncopyable { m_setRoomToWorldTransform(osvr::common::Transform const &xform) = 0; /// @brief Implementation of accessor for the path tree. - OSVR_COMMON_EXPORT virtual std::shared_ptr - m_getSystemComponent() = 0; + OSVR_COMMON_EXPORT virtual osvr::common::SystemComponent * + m_getSystemComponent() = 0; std::string const m_appId; InterfaceList m_interfaces; diff --git a/src/osvr/Client/PureClientContext.cpp b/src/osvr/Client/PureClientContext.cpp index ff72c836c..b9f4c021e 100644 --- a/src/osvr/Client/PureClientContext.cpp +++ b/src/osvr/Client/PureClientContext.cpp @@ -104,8 +104,8 @@ namespace client { /// Create the system client device. m_systemDevice = common::createClientDevice(sysDeviceName, m_mainConn); - m_systemComponent = common::SystemComponent::create(); - m_systemDevice->addComponent(m_systemComponent); + m_systemComponent = + m_systemDevice->addComponent(common::SystemComponent::create()); /// Receive string map data whenever it comes m_systemComponent->registerStringMapHandler( @@ -210,6 +210,9 @@ namespace client { common::Transform const & PureClientContext::m_getRoomToWorldTransform() const { return m_roomToWorld; + + common::SystemComponent *PureClientContext::m_getSystemComponent() { + return m_systemComponent; } shared_ptr PureClientContext::m_getSystemComponent() { @@ -221,8 +224,8 @@ namespace client { m_roomToWorld = xform; } - void PureClientContext::m_handleRegStringMap(common::MapData const &data, - util::time::TimeValue const ×tamp){ + void PureClientContext::m_handleRegStringMap( + common::MapData const &data, util::time::TimeValue const ×tamp) { auto map = m_systemComponent->getRegStringMap(); map->corrMap.setupPeerMappings(data.serializedMap); } diff --git a/src/osvr/Client/PureClientContext.h b/src/osvr/Client/PureClientContext.h index 0474439de..0a8bad08c 100644 --- a/src/osvr/Client/PureClientContext.h +++ b/src/osvr/Client/PureClientContext.h @@ -39,7 +39,6 @@ #include #include #include "RemoteHandlerFactory.h" -#include // Library/third-party includes #include @@ -76,7 +75,7 @@ namespace client { common::PathTree const &m_getPathTree() const override; - virtual shared_ptr m_getSystemComponent(); + virtual common::SystemComponent *m_getSystemComponent(); common::Transform const &m_getRoomToWorldTransform() const override; @@ -95,7 +94,7 @@ namespace client { /// @brief The system component providing access to sending/receiving /// control messages. - shared_ptr m_systemComponent; + common::SystemComponent *m_systemComponent; /// @brief All open VRPN connections, keyed by host VRPNConnectionCollection m_vrpnConns; @@ -121,7 +120,7 @@ namespace client { /// @brief Called whenever an updated string to ID map is available void m_handleRegStringMap(common::MapData const &data, - util::time::TimeValue const ×tamp); + util::time::TimeValue const ×tamp); }; } // namespace client } // namespace osvr diff --git a/src/osvr/Common/ClientContext.cpp b/src/osvr/Common/ClientContext.cpp index d60a17dc5..a9ed99e1d 100644 --- a/src/osvr/Common/ClientContext.cpp +++ b/src/osvr/Common/ClientContext.cpp @@ -122,7 +122,7 @@ osvr::common::PathTree const &OSVR_ClientContextObject::getPathTree() const { return m_getPathTree(); } -std::shared_ptr OSVR_ClientContextObject::getSystemComponent(){ +osvr::common::SystemComponent *OSVR_ClientContextObject::getSystemComponent() { return m_getSystemComponent(); } From 140874609fdc7b8c311b626a760cf008884302df Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 18:10:04 -0400 Subject: [PATCH 36/73] missed clang format on these --- inc/osvr/ClientKit/Context.h | 10 +-- inc/osvr/ClientKit/InterfaceC.h | 4 +- inc/osvr/Common/SystemComponent.h | 61 ++++++++------- inc/osvr/Util/ClientReportTypesC.h | 6 +- inc/osvr/Util/ID.h | 54 +++++++------ src/osvr/ClientKit/InterfaceC.cpp | 20 ++--- src/osvr/Common/SystemComponent.cpp | 115 ++++++++++++++-------------- 7 files changed, 131 insertions(+), 139 deletions(-) diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index e272fc39d..80bf4799b 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -114,10 +114,9 @@ namespace clientkit { } inline std::string ClientContext::getNamefromID(StringID id) { - + size_t length = 0; - OSVR_ReturnCode ret = osvrClientGetNameLength( - m_context, id, &length); + OSVR_ReturnCode ret = osvrClientGetNameLength(m_context, id, &length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error( "Invalid context or null reference to length variable."); @@ -128,11 +127,10 @@ namespace clientkit { } boost::scoped_array buf(new char[length]); - ret = osvrClientGetNameFromID(m_context, id, buf.get(), - length); + ret = osvrClientGetNameFromID(m_context, id, buf.get(), length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error("Invalid context, null reference to " - "buffer, or buffer is too small."); + "buffer, or buffer is too small."); } return std::string(buf.get()); } diff --git a/inc/osvr/ClientKit/InterfaceC.h b/inc/osvr/ClientKit/InterfaceC.h index aec548bec..cb4ed514f 100644 --- a/inc/osvr/ClientKit/InterfaceC.h +++ b/inc/osvr/ClientKit/InterfaceC.h @@ -93,8 +93,8 @@ short, an error is returned and the buffer is unchanged. provided id */ OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode -osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, - char *buf, size_t len); +osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, char *buf, + size_t len); /** @} */ OSVR_EXTERN_C_END diff --git a/inc/osvr/Common/SystemComponent.h b/inc/osvr/Common/SystemComponent.h index 16cf3d1b5..fcb02d19f 100644 --- a/inc/osvr/Common/SystemComponent.h +++ b/inc/osvr/Common/SystemComponent.h @@ -47,9 +47,9 @@ namespace osvr { namespace common { - struct MapData{ - SerializedStringMap serializedMap; - }; + struct MapData { + SerializedStringMap serializedMap; + }; namespace messages { class RoutesFromServer : public MessageRegistration { @@ -81,23 +81,24 @@ namespace common { static const char *identifier(); }; - /// message to send serialized name to ID map - class RegisteredStringMapRecord : public MessageRegistration { - public: - class MessageSerialization; + /// message to send serialized name to ID map + class RegisteredStringMapRecord + : public MessageRegistration { + public: + class MessageSerialization; - static const char *identifier(); - }; + static const char *identifier(); + }; } // namespace messages - struct RegStringMapData{ - RegisteredStringMap map; - CorrelatedStringMap corrMap; - }; + struct RegStringMapData { + RegisteredStringMap map; + CorrelatedStringMap corrMap; + }; + + typedef shared_ptr MapPtr; - typedef shared_ptr MapPtr; - typedef shared_ptr SystemComponentPtr; /// @brief BaseDevice component, to be used only with the "OSVR" special @@ -141,21 +142,19 @@ namespace common { OSVR_COMMON_EXPORT void sendReplacementTree(PathTree &tree); - /// @brief Request a copy of MapPtr to the name to ID map + /// @brief Request a copy of MapPtr to the name to ID map OSVR_COMMON_EXPORT MapPtr getRegStringMap(); - /// @brief Message from server to client, containing registeredStringMap - messages::RegisteredStringMapRecord regStringMap; - - OSVR_COMMON_EXPORT void sendRegisteredStringMap(); - - typedef std::function - RegisteredStringMapHandler; - OSVR_COMMON_EXPORT void registerStringMapHandler( - RegisteredStringMapHandler cb); + /// @brief Message from server to client, containing registeredStringMap + messages::RegisteredStringMapRecord regStringMap; + OSVR_COMMON_EXPORT void sendRegisteredStringMap(); + typedef std::function + RegisteredStringMapHandler; + OSVR_COMMON_EXPORT void + registerStringMapHandler(RegisteredStringMapHandler cb); private: SystemComponent(); @@ -165,12 +164,12 @@ namespace common { m_handleReplaceTree(void *userdata, vrpn_HANDLERPARAM p); std::vector m_replaceTreeHandlers; - static int VRPN_CALLBACK - m_handleRegStringMap(void *userdata, vrpn_HANDLERPARAM p); - std::vector m_cb_map; + static int VRPN_CALLBACK + m_handleRegStringMap(void *userdata, vrpn_HANDLERPARAM p); + std::vector m_cb_map; - // name to ID map used by the server - MapPtr m_nameToIDMap; + // name to ID map used by the server + MapPtr m_nameToIDMap; /// @brief Common component for system device common::CommonComponent *m_commonComponent; diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index 78e9cb90f..bbce37952 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -381,9 +381,9 @@ typedef struct OSVR_GestureReportWithName { /** @brief Report type for a gesture event */ typedef struct OSVR_GestureReport { - OSVR_GestureID gestureID; - OSVR_GestureState state; - OSVR_ChannelCount sensor; + OSVR_GestureID gestureID; + OSVR_GestureState state; + OSVR_ChannelCount sensor; } OSVR_GestureReport; /** @} */ diff --git a/inc/osvr/Util/ID.h b/inc/osvr/Util/ID.h index de6b8385a..2ae6751b0 100644 --- a/inc/osvr/Util/ID.h +++ b/inc/osvr/Util/ID.h @@ -25,7 +25,6 @@ #ifndef INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 #define INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 - // Internal Includes // - none @@ -36,39 +35,38 @@ #include #include - /// idea from the - /// http://www.ilikebigbits.com/blog/2014/5/6/type-safe-identifiers-in-c - template class ID { - public: - static ID invalid() { return ID(); } +/// idea from the +/// http://www.ilikebigbits.com/blog/2014/5/6/type-safe-identifiers-in-c +template class ID { + public: + static ID invalid() { return ID(); } - // Default constructor which will set m_val to a 0xffffffff (UINT32 max) - // and signify empty. - ID() : m_val(0xffffffff) {} + // Default constructor which will set m_val to a 0xffffffff (UINT32 max) + // and signify empty. + ID() : m_val(0xffffffff) {} - // Explicit constructor: - explicit ID(impl val) : m_val(val) {} + // Explicit constructor: + explicit ID(impl val) : m_val(val) {} - // Explicit conversion to get back the impl: - // explicit operator impl() const { return m_val; } + // Explicit conversion to get back the impl: + // explicit operator impl() const { return m_val; } - // Implicit conversion to get back the impl - operator impl() const { return m_val; } + // Implicit conversion to get back the impl + operator impl() const { return m_val; } - bool empty() const { return m_val == 0xffffffff ? true : false; } + bool empty() const { return m_val == 0xffffffff ? true : false; } - // this messes with implicit conversion (type casting) - /* - friend bool operator>(ID a, impl b) { return a.m_val > b; } - friend bool operator<(ID a, impl b) { return a.m_val < b; } - friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } - friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } - */ - impl m_val; - }; + // this messes with implicit conversion (type casting) + /* + friend bool operator>(ID a, impl b) { return a.m_val > b; } + friend bool operator<(ID a, impl b) { return a.m_val < b; } + friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } + friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } + */ + impl m_val; +}; - typedef ID StringID; - typedef ID PeerStringID; +typedef ID StringID; +typedef ID PeerStringID; #endif // INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 - diff --git a/src/osvr/ClientKit/InterfaceC.cpp b/src/osvr/ClientKit/InterfaceC.cpp index 5f4e89b4e..c599bf3b8 100644 --- a/src/osvr/ClientKit/InterfaceC.cpp +++ b/src/osvr/ClientKit/InterfaceC.cpp @@ -75,24 +75,24 @@ OSVR_ReturnCode osvrClientFreeInterface(OSVR_ClientContext ctx, } OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode -osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len){ - +osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len) { + if (ctx == nullptr) { return OSVR_RETURN_FAILURE; } if (len == nullptr) { return OSVR_RETURN_FAILURE; } - std::string entryName = - ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID(StringID(id)); + std::string entryName = + ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( + StringID(id)); *len = entryName.empty() ? 0 : (entryName.size() + 1); return OSVR_RETURN_SUCCESS; } -OSVR_ReturnCode -osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, - char *buf, size_t len){ - +OSVR_ReturnCode osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, + char *buf, size_t len) { + if (ctx == nullptr) { return OSVR_RETURN_FAILURE; } @@ -101,7 +101,8 @@ osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, } std::string entryName = - ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID(StringID(id)); + ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( + StringID(id)); if (entryName.size() + 1 > len) { /// buffer too small. @@ -110,5 +111,4 @@ osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, entryName.copy(buf, entryName.size()); buf[entryName.size()] = '\0'; return OSVR_RETURN_SUCCESS; - } diff --git a/src/osvr/Common/SystemComponent.cpp b/src/osvr/Common/SystemComponent.cpp index 059cfcc7e..36e26dd42 100644 --- a/src/osvr/Common/SystemComponent.cpp +++ b/src/osvr/Common/SystemComponent.cpp @@ -95,28 +95,28 @@ namespace common { return "com.osvr.system.ReplacementTreeFromServer"; } - class RegisteredStringMapRecord::MessageSerialization { - public: - MessageSerialization(SerializedStringMap serializedMap) - : m_serializedMap(serializedMap) {} - - MessageSerialization() {} - - template void processMessage(T &p) { - p(m_serializedMap); - } - MapData getData() const { - MapData ret; - ret.serializedMap = m_serializedMap; - return ret; - } - - private: - SerializedStringMap m_serializedMap; - }; - const char *RegisteredStringMapRecord::identifier() { - return "com.osvr.system.regstringmaprecord"; - } + class RegisteredStringMapRecord::MessageSerialization { + public: + MessageSerialization(SerializedStringMap serializedMap) + : m_serializedMap(serializedMap) {} + + MessageSerialization() {} + + template void processMessage(T &p) { + p(m_serializedMap); + } + MapData getData() const { + MapData ret; + ret.serializedMap = m_serializedMap; + return ret; + } + + private: + SerializedStringMap m_serializedMap; + }; + const char *RegisteredStringMapRecord::identifier() { + return "com.osvr.system.regstringmaprecord"; + } } // namespace messages const char *SystemComponent::deviceName() { @@ -172,29 +172,28 @@ namespace common { m_replaceTreeHandlers.push_back(cb); } - MapPtr SystemComponent::getRegStringMap(){ - return m_nameToIDMap; - } + MapPtr SystemComponent::getRegStringMap() { return m_nameToIDMap; } - void SystemComponent::sendRegisteredStringMap() { + void SystemComponent::sendRegisteredStringMap() { - Buffer<> buf; - // serialize the map before sending it - SerializedStringMap serializedMap = m_nameToIDMap->map.getMap(); + Buffer<> buf; + // serialize the map before sending it + SerializedStringMap serializedMap = m_nameToIDMap->map.getMap(); - messages::RegisteredStringMapRecord::MessageSerialization msg(serializedMap); - serialize(buf, msg); - m_getParent().packMessage(buf, regStringMap.getMessageType()); - } + messages::RegisteredStringMapRecord::MessageSerialization msg( + serializedMap); + serialize(buf, msg); + m_getParent().packMessage(buf, regStringMap.getMessageType()); + } - void - SystemComponent::registerStringMapHandler(RegisteredStringMapHandler handler) { - if (m_cb_map.empty()) { - m_registerHandler(&SystemComponent::m_handleRegStringMap, this, - regStringMap.getMessageType()); - } - m_cb_map.push_back(handler); - } + void SystemComponent::registerStringMapHandler( + RegisteredStringMapHandler handler) { + if (m_cb_map.empty()) { + m_registerHandler(&SystemComponent::m_handleRegStringMap, this, + regStringMap.getMessageType()); + } + m_cb_map.push_back(handler); + } void SystemComponent::m_parentSet() { @@ -204,14 +203,14 @@ namespace common { m_getParent().addComponent(osvr::common::CommonComponent::create()); OSVR_TimeValue now; osvrTimeValueGetNow(&now); - m_commonComponent->registerPingHandler([&] { - sendRegisteredStringMap(); }); + m_commonComponent->registerPingHandler( + [&] { sendRegisteredStringMap(); }); m_getParent().registerMessageType(routesOut); m_getParent().registerMessageType(appStartup); m_getParent().registerMessageType(routeIn); m_getParent().registerMessageType(treeOut); - m_getParent().registerMessageType(regStringMap); + m_getParent().registerMessageType(regStringMap); } int SystemComponent::m_handleReplaceTree(void *userdata, @@ -229,22 +228,20 @@ namespace common { return 0; } - int VRPN_CALLBACK - SystemComponent::m_handleRegStringMap(void *userdata, - vrpn_HANDLERPARAM p) { - auto self = static_cast(userdata); - auto bufReader = readExternalBuffer(p.buffer, p.payload_len); - messages::RegisteredStringMapRecord::MessageSerialization msg; - deserialize(bufReader, msg); - auto data = msg.getData(); - auto timestamp = util::time::fromStructTimeval(p.msg_time); - - for (auto const &cb : self->m_cb_map) { - cb(data, timestamp); - } - return 0; - } + int VRPN_CALLBACK + SystemComponent::m_handleRegStringMap(void *userdata, vrpn_HANDLERPARAM p) { + auto self = static_cast(userdata); + auto bufReader = readExternalBuffer(p.buffer, p.payload_len); + messages::RegisteredStringMapRecord::MessageSerialization msg; + deserialize(bufReader, msg); + auto data = msg.getData(); + auto timestamp = util::time::fromStructTimeval(p.msg_time); + for (auto const &cb : self->m_cb_map) { + cb(data, timestamp); + } + return 0; + } } // namespace common } // namespace osvr From d31ca3815eb56d8f5b107223203f3c3b0d2af2d9 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 18:10:30 -0400 Subject: [PATCH 37/73] use regular ptr instead of the shared --- src/osvr/Client/GestureRemoteFactory.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index aca7b3e15..66738856e 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -53,10 +53,10 @@ namespace client { std::string const &deviceName, boost::optional sensor, common::InterfaceList &ifaces, - common::ClientContext* ctx) + common::ClientContext *ctx) : m_dev(common::createClientDevice(deviceName, conn)), m_interfaces(ifaces), m_all(!sensor.is_initialized()), - m_sensor(sensor), m_ctx(ctx){ + m_sensor(sensor), m_ctx(ctx) { m_sysComponent = m_ctx->getSystemComponent(); m_gestureNameMap = m_sysComponent->getRegStringMap(); @@ -101,7 +101,7 @@ namespace client { report.sensor = data.sensor; report.state = data.gestureState; - report.gestureID = id; + report.gestureID = id; common::ClientInterfacePtr anInterface; for (auto &iface : m_interfaces) { anInterface = iface; @@ -115,8 +115,8 @@ namespace client { boost::optional m_sensor; // map to keep track of gesture map and server to local ID map common::MapPtr m_gestureNameMap; - common::ClientContext* m_ctx; - shared_ptr m_sysComponent; + common::ClientContext *m_ctx; + common::SystemComponent *m_sysComponent; }; GestureRemoteFactory::GestureRemoteFactory( From c71e467dcfb5f4bdba13a18fe53608b1fe91f4d4 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 18:11:11 -0400 Subject: [PATCH 38/73] set SystemComponent for RegistrationContext --- src/osvr/Server/ServerImpl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osvr/Server/ServerImpl.cpp b/src/osvr/Server/ServerImpl.cpp index cfb41193f..05873b179 100644 --- a/src/osvr/Server/ServerImpl.cpp +++ b/src/osvr/Server/ServerImpl.cpp @@ -89,6 +89,8 @@ namespace server { m_systemComponent = m_systemDevice->addComponent(common::SystemComponent::create()); + m_ctx->setSystemComponent(m_systemComponent); + m_systemComponent->registerClientRouteUpdateHandler( &ServerImpl::m_handleUpdatedRoute, this); From f958d27353daa89dca346dfde8aae4d0b6da5135 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 18:12:37 -0400 Subject: [PATCH 39/73] print gesture name in the client app --- examples/clients/Gesture.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/clients/Gesture.cpp b/examples/clients/Gesture.cpp index abd1e292e..ea21219c2 100644 --- a/examples/clients/Gesture.cpp +++ b/examples/clients/Gesture.cpp @@ -34,7 +34,11 @@ #include #include -void printGestureReport(const OSVR_GestureReport *report) { +typedef struct ContextData { + osvr::clientkit::ClientContext *context; +} ContextData; + +void printGestureReport(const OSVR_GestureReport *report, std::string name) { std::string state; if (report->state == OSVR_GESTURE_COMPLETE) { @@ -42,28 +46,33 @@ void printGestureReport(const OSVR_GestureReport *report) { } else { state = "IN PROCESS"; } - std::cout << report->gestureName << "; " << state << "\t" << std::endl; + std::cout << name << "; " << report->gestureID << "; " << state << "\t" + << std::endl; } -void gestureCallback(void * /*userdata*/, const OSVR_TimeValue * /*timestamp*/, +void gestureCallback(void *userdata, const OSVR_TimeValue * /*timestamp*/, const OSVR_GestureReport *report) { + auto ctx = static_cast(userdata); + std::string name = ctx->context->getNamefromID(StringID(report->gestureID)); std::cout << "Got Gesture Report, for sensor #" << report->sensor << std::endl; - printGestureReport(report); + printGestureReport(report, name); } int main() { - osvr::clientkit::ClientContext context( + + ContextData ctx; + ctx.context = new osvr::clientkit::ClientContext( "com.osvr.exampleclients.GestureCallback"); - osvr::clientkit::Interface location = - context.getInterface("/com_osvr_example_Gesture/Gesture/gesture"); + osvr::clientkit::Interface gesture = + ctx.context->getInterface("/com_osvr_example_Gesture/Gesture/gesture"); - location.registerCallback(&gestureCallback, NULL); + gesture.registerCallback(&gestureCallback, static_cast(&ctx)); // Pretend that this is your application's mainloop. while (1) { - context.update(); + ctx.context->update(); } std::cout << "Library shut down, exiting." << std::endl; From 2577b3863bbab971260d5ac63c25a4d7dcc5a68b Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Tue, 11 Aug 2015 18:34:48 -0400 Subject: [PATCH 40/73] remove unnecessary includes --- inc/osvr/Common/ClientContext.h | 1 - inc/osvr/Common/GestureComponent.h | 2 -- inc/osvr/Common/SystemComponent.h | 2 -- src/osvr/Common/SystemComponent.cpp | 2 +- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/inc/osvr/Common/ClientContext.h b/inc/osvr/Common/ClientContext.h index a0f2233b4..b76580f9e 100644 --- a/inc/osvr/Common/ClientContext.h +++ b/inc/osvr/Common/ClientContext.h @@ -35,7 +35,6 @@ #include #include #include -#include // Library/third-party includes #include diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 7c352ea24..9cda29c01 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -34,9 +34,7 @@ #include #include #include - #include -#include // Library/third-party includes #include diff --git a/inc/osvr/Common/SystemComponent.h b/inc/osvr/Common/SystemComponent.h index fcb02d19f..b19cea222 100644 --- a/inc/osvr/Common/SystemComponent.h +++ b/inc/osvr/Common/SystemComponent.h @@ -31,9 +31,7 @@ #include #include #include - #include -#include #include #include diff --git a/src/osvr/Common/SystemComponent.cpp b/src/osvr/Common/SystemComponent.cpp index 36e26dd42..9babfa04e 100644 --- a/src/osvr/Common/SystemComponent.cpp +++ b/src/osvr/Common/SystemComponent.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,6 @@ // Standard includes // - none -#include namespace osvr { namespace common { From e8583b09f098ceb5e6a5e171c58b0dea848fde7b Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 2 Sep 2015 18:04:34 -0400 Subject: [PATCH 41/73] minor cleanup of unused stuff --- inc/osvr/Util/ClientReportTypesC.h | 7 ------- src/osvr/Client/PureClientContext.cpp | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index bbce37952..2f7e6e503 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -372,13 +372,6 @@ typedef uint8_t OSVR_GestureState; #define OSVR_GESTURE_OPEN_HAND "OpenHand" #define OSVR_GESTURE_CLOSED_HAND "ClosedHand" -/** @brief Report type for a gesture event */ -typedef struct OSVR_GestureReportWithName { - OSVR_GestureName gestureName; - OSVR_GestureState state; - OSVR_ChannelCount sensor; -} OSVR_GestureReportWithName; - /** @brief Report type for a gesture event */ typedef struct OSVR_GestureReport { OSVR_GestureID gestureID; diff --git a/src/osvr/Client/PureClientContext.cpp b/src/osvr/Client/PureClientContext.cpp index b9f4c021e..f3a6cba2b 100644 --- a/src/osvr/Client/PureClientContext.cpp +++ b/src/osvr/Client/PureClientContext.cpp @@ -225,7 +225,7 @@ namespace client { } void PureClientContext::m_handleRegStringMap( - common::MapData const &data, util::time::TimeValue const ×tamp) { + common::MapData const &data, util::time::TimeValue const &) { auto map = m_systemComponent->getRegStringMap(); map->corrMap.setupPeerMappings(data.serializedMap); } From 1d4524e4a50c03897be0d48ecff08e34c17233e7 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 2 Sep 2015 18:21:20 -0400 Subject: [PATCH 42/73] changes to the typesafe ID class --- inc/osvr/Util/ID.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/inc/osvr/Util/ID.h b/inc/osvr/Util/ID.h index 2ae6751b0..f7a68d7fe 100644 --- a/inc/osvr/Util/ID.h +++ b/inc/osvr/Util/ID.h @@ -48,21 +48,16 @@ template class ID { // Explicit constructor: explicit ID(impl val) : m_val(val) {} - // Explicit conversion to get back the impl: - // explicit operator impl() const { return m_val; } - - // Implicit conversion to get back the impl - operator impl() const { return m_val; } - bool empty() const { return m_val == 0xffffffff ? true : false; } - // this messes with implicit conversion (type casting) - /* - friend bool operator>(ID a, impl b) { return a.m_val > b; } - friend bool operator<(ID a, impl b) { return a.m_val < b; } + operator impl & () {return m_val; } friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } - */ + + impl& value() { return m_val; } + impl value() const { return m_val; } + + private: impl m_val; }; From 0e6831b70f4b62c80151df6cd2a36ad881369a02 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 2 Sep 2015 18:40:55 -0400 Subject: [PATCH 43/73] remove unused ClientInterfacePtr --- src/osvr/Client/GestureRemoteFactory.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index 66738856e..69a9671b8 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -102,9 +102,7 @@ namespace client { report.sensor = data.sensor; report.state = data.gestureState; report.gestureID = id; - common::ClientInterfacePtr anInterface; for (auto &iface : m_interfaces) { - anInterface = iface; iface->triggerCallbacks(timestamp, report); } } From 630994aa1bce3d655111cb8ba66fb1557113eda6 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Fri, 4 Sep 2015 13:58:02 -0400 Subject: [PATCH 44/73] update includes for gesture remote factory --- src/osvr/Client/GestureRemoteFactory.cpp | 2 +- src/osvr/Client/GestureRemoteFactory.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index 69a9671b8..513f0c8dd 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -32,7 +32,7 @@ #include #include #include -#include "InterfaceTree.h" +#include #include #include #include diff --git a/src/osvr/Client/GestureRemoteFactory.h b/src/osvr/Client/GestureRemoteFactory.h index 1dd151555..a692aff2a 100644 --- a/src/osvr/Client/GestureRemoteFactory.h +++ b/src/osvr/Client/GestureRemoteFactory.h @@ -31,7 +31,7 @@ #include #include #include -#include "RemoteHandler.h" +#include #include // Library/third-party includes From 1652bd339912f742a7e19ab9131715389520277a Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Fri, 4 Sep 2015 13:58:59 -0400 Subject: [PATCH 45/73] add accessor for sys component to joint client context --- src/osvr/JointClientKit/JointClientContext.cpp | 4 ++++ src/osvr/JointClientKit/JointClientContext.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/osvr/JointClientKit/JointClientContext.cpp b/src/osvr/JointClientKit/JointClientContext.cpp index e8c55f132..8690318a3 100644 --- a/src/osvr/JointClientKit/JointClientContext.cpp +++ b/src/osvr/JointClientKit/JointClientContext.cpp @@ -122,6 +122,10 @@ namespace client { common::ClientInterfacePtr const &iface) { m_ifaceMgr.releaseInterface(iface); } + + common::SystemComponent *JointClientContext::m_getSystemComponent() { + return m_systemComponent; + } bool JointClientContext::m_getStatus() const { /// Always connected, but don't always have a path tree. diff --git a/src/osvr/JointClientKit/JointClientContext.h b/src/osvr/JointClientKit/JointClientContext.h index dcc10f16e..2a100d0c7 100644 --- a/src/osvr/JointClientKit/JointClientContext.h +++ b/src/osvr/JointClientKit/JointClientContext.h @@ -78,6 +78,8 @@ namespace client { common::PathTree const &m_getPathTree() const override; + virtual osvr::common::SystemComponent *m_getSystemComponent(); + common::Transform const &m_getRoomToWorldTransform() const override { return m_roomToWorld; } From 7403fd67e4d605cd81deaa02e5560d1761112a73 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Fri, 4 Sep 2015 14:00:00 -0400 Subject: [PATCH 46/73] misc comment updates --- inc/osvr/Common/ClientContext.h | 2 +- inc/osvr/Util/ID.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/osvr/Common/ClientContext.h b/inc/osvr/Common/ClientContext.h index b76580f9e..b4526fdb0 100644 --- a/inc/osvr/Common/ClientContext.h +++ b/inc/osvr/Common/ClientContext.h @@ -156,7 +156,7 @@ struct OSVR_ClientContextObject : boost::noncopyable { virtual void m_setRoomToWorldTransform(osvr::common::Transform const &xform) = 0; - /// @brief Implementation of accessor for the path tree. + /// @brief Implementation of accessor for the system component OSVR_COMMON_EXPORT virtual osvr::common::SystemComponent * m_getSystemComponent() = 0; diff --git a/inc/osvr/Util/ID.h b/inc/osvr/Util/ID.h index f7a68d7fe..6682c8472 100644 --- a/inc/osvr/Util/ID.h +++ b/inc/osvr/Util/ID.h @@ -50,11 +50,11 @@ template class ID { bool empty() const { return m_val == 0xffffffff ? true : false; } - operator impl & () {return m_val; } + operator impl &() { return m_val; } friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } - impl& value() { return m_val; } + impl &value() { return m_val; } impl value() const { return m_val; } private: From 83a61c37de5bd9bb23140eeb12651e91ad88ecd2 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Fri, 4 Sep 2015 14:00:21 -0400 Subject: [PATCH 47/73] add gesture remote factory to remote handler --- src/osvr/Client/RemoteHandlerFactory.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osvr/Client/RemoteHandlerFactory.cpp b/src/osvr/Client/RemoteHandlerFactory.cpp index 806257763..e13d94f51 100644 --- a/src/osvr/Client/RemoteHandlerFactory.cpp +++ b/src/osvr/Client/RemoteHandlerFactory.cpp @@ -28,6 +28,7 @@ #include "ButtonRemoteFactory.h" #include "DirectionRemoteFactory.h" #include "EyeTrackerRemoteFactory.h" +#include "GestureRemoteFactory.h" #include "ImagingRemoteFactory.h" #include "Location2DRemoteFactory.h" #include "LocomotionRemoteFactory.h" @@ -49,6 +50,7 @@ namespace client { ButtonRemoteFactory(conns).registerWith(factory); ImagingRemoteFactory(conns).registerWith(factory); EyeTrackerRemoteFactory(conns).registerWith(factory); + GestureRemoteFactory(conns).registerWith(factory); Location2DRemoteFactory(conns).registerWith(factory); LocomotionRemoteFactory(conns).registerWith(factory); DirectionRemoteFactory(conns).registerWith(factory); From 14825b0720c6143ffa15cde4b6c2af5ceeefd05b Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 15:53:16 -0500 Subject: [PATCH 48/73] clang-format --- examples/plugin/com_osvr_example_Gesture.cpp | 4 ++-- inc/osvr/ClientKit/InterfaceC.h | 5 ++--- inc/osvr/Common/GestureComponent.h | 4 ++-- src/osvr/Common/DirectionComponent.cpp | 5 ++--- src/osvr/Common/GestureComponent.cpp | 5 ++--- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/plugin/com_osvr_example_Gesture.cpp b/examples/plugin/com_osvr_example_Gesture.cpp index 9a6489c47..b70229601 100644 --- a/examples/plugin/com_osvr_example_Gesture.cpp +++ b/examples/plugin/com_osvr_example_Gesture.cpp @@ -64,8 +64,8 @@ class GestureDevice { OSVR_ReturnCode update() { - std::this_thread::sleep_for(std::chrono::milliseconds( - 1000)); // Simulate waiting a quarter second for data. + std::this_thread::sleep_for(std::chrono::milliseconds( + 1000)); // Simulate waiting a quarter second for data. OSVR_TimeValue times; diff --git a/inc/osvr/ClientKit/InterfaceC.h b/inc/osvr/ClientKit/InterfaceC.h index cb4ed514f..c35df62df 100644 --- a/inc/osvr/ClientKit/InterfaceC.h +++ b/inc/osvr/ClientKit/InterfaceC.h @@ -92,9 +92,8 @@ short, an error is returned and the buffer is unchanged. @returns It will copy the name of entry name that corresponds to the provided id */ -OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode -osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, char *buf, - size_t len); +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetNameFromID( + OSVR_ClientContext ctx, uint32_t id, char *buf, size_t len); /** @} */ OSVR_EXTERN_C_END diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 9cda29c01..34b1cd32a 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -93,8 +93,8 @@ namespace common { virtual void m_parentSet(); - static int VRPN_CALLBACK - m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p); + static int VRPN_CALLBACK m_handleGestureRecord(void *userdata, + vrpn_HANDLERPARAM p); void m_checkFirst(OSVR_GestureState const &gesture); diff --git a/src/osvr/Common/DirectionComponent.cpp b/src/osvr/Common/DirectionComponent.cpp index a11f8d467..61b0d1f19 100644 --- a/src/osvr/Common/DirectionComponent.cpp +++ b/src/osvr/Common/DirectionComponent.cpp @@ -86,9 +86,8 @@ namespace common { timestamp); } - int VRPN_CALLBACK - DirectionComponent::m_handleDirectionRecord(void *userdata, - vrpn_HANDLERPARAM p) { + int VRPN_CALLBACK DirectionComponent::m_handleDirectionRecord( + void *userdata, vrpn_HANDLERPARAM p) { auto self = static_cast(userdata); auto bufReader = readExternalBuffer(p.buffer, p.payload_len); diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index 7a5124db6..a3cb9d571 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -119,9 +119,8 @@ namespace common { timestamp); } - int VRPN_CALLBACK - GestureComponent::m_handleGestureRecord(void *userdata, - vrpn_HANDLERPARAM p) { + int VRPN_CALLBACK GestureComponent::m_handleGestureRecord( + void *userdata, vrpn_HANDLERPARAM p) { auto self = static_cast(userdata); auto bufReader = readExternalBuffer(p.buffer, p.payload_len); From 39b99e5eef60da4db62057d632d58ffa193e59f7 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 16:03:30 -0500 Subject: [PATCH 49/73] Move and fix the sample config for a gesture server. --- apps/osvr_server_config.gesture.sample.json | 26 ------------------- .../osvr_server_config.gesture.sample.json | 9 +++++++ 2 files changed, 9 insertions(+), 26 deletions(-) delete mode 100644 apps/osvr_server_config.gesture.sample.json create mode 100644 apps/sample-configs/osvr_server_config.gesture.sample.json diff --git a/apps/osvr_server_config.gesture.sample.json b/apps/osvr_server_config.gesture.sample.json deleted file mode 100644 index 415cabc80..000000000 --- a/apps/osvr_server_config.gesture.sample.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "plugins": [ - "com_osvr_example_Gesture" - ], - "routes": [ - { - "destination": "/me/hands/left", - "source": { - "child": { - "tracker": "/com_osvr_example_Gesture/Gesture", - "sensor": 0 - } - } - }, - { - "destination": "/me/hands/right", - "source": { - "child": { - "tracker": "/com_osvr_example_Gesture/Gesture", - "sensor": 1 - } - } - } - ], - "display": "displays/HMD.json" -} \ No newline at end of file diff --git a/apps/sample-configs/osvr_server_config.gesture.sample.json b/apps/sample-configs/osvr_server_config.gesture.sample.json new file mode 100644 index 000000000..4a8d34a6f --- /dev/null +++ b/apps/sample-configs/osvr_server_config.gesture.sample.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + "com_osvr_example_Gesture" + ], + "aliases": { + "/me/hands/left/gesture": "/com_osvr_example_Gesture/Gesture/gesture/0", + "/me/hands/right/gesture": "/com_osvr_example_Gesture/Gesture/gesture/1" + } +} From 31014b7082a30c181e5d9888ff70c31c4d68b248 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 16:18:17 -0500 Subject: [PATCH 50/73] Fix usage error in ClientReportTypes --- inc/osvr/Util/ClientReportTypesC.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index 2f7e6e503..dd8fff49e 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -350,10 +350,10 @@ typedef char const *OSVR_GestureName; typedef uint8_t OSVR_GestureState; /** @brief OSVR_GestureState value indicating "gesture started/currently in - process(ocurring)" + progress (occurring)" (should be used for continuous gestures, since discrete start and complete at the same time) */ -#define OSVR_GESTURE_IN_PROCESS (1) +#define OSVR_GESTURE_IN_PROGRESS (1) /** @brief OSVR_GestureState value indicating "gesture is finished" */ #define OSVR_GESTURE_COMPLETE (0) From 9303d2044776649bef47686973492659a46d77fa Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 16:18:52 -0500 Subject: [PATCH 51/73] Fix GestureInterfaceC.h annotations, parameters, and doc. --- inc/osvr/PluginKit/GestureInterfaceC.h | 40 ++++++++++++-------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/inc/osvr/PluginKit/GestureInterfaceC.h b/inc/osvr/PluginKit/GestureInterfaceC.h index 12198dd24..234508f29 100644 --- a/inc/osvr/PluginKit/GestureInterfaceC.h +++ b/inc/osvr/PluginKit/GestureInterfaceC.h @@ -45,10 +45,10 @@ typedef struct OSVR_GestureDeviceInterfaceObject *OSVR_GestureDeviceInterface; /** @brief Specify that your device will implement the Gesture interface. -@param opts The device init options object. -@param [out] iface An interface object you should retain with the same -lifetime as the device token in order to send messages conforming to an -Gesture interface. + @param opts The device init options object. + @param [out] iface An interface object you should retain with the same + lifetime as the device token in order to send messages conforming to an + Gesture interface. */ OSVR_PLUGINKIT_EXPORT OSVR_ReturnCode @@ -57,31 +57,29 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, OSVR_FUNC_NONNULL((1, 2)); /** @brief Obtain an ID for a given gesture name -@param iface GestureInterface -@param gestureName String name of gesture -@param gestureID pointer to an id variable + @param iface GestureInterface + @param gestureName String name of gesture + @param gestureID pointer to an id variable */ OSVR_PLUGINKIT_EXPORT void osvrDeviceGestureGetID(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, - OSVR_IN_PTR const char *gestureName, - OSVR_IN_PTR OSVR_GestureID *gestureID) + OSVR_IN_STRZ const char *gestureName, + OSVR_OUT_PTR OSVR_GestureID *gestureID) OSVR_FUNC_NONNULL((1, 2)); /** @brief Report data for a specific sensor. -@param iface Gesture interface -@param gestureID Pre-fetched ID of the gesture -@param gestureState Current state of gesture (In process vs Completed) -@param sensor Sensor number -@param timestamp Timestamp correlating to Gesture data. + @param iface Gesture interface + @param gestureID Pre-fetched ID of the gesture + @param gestureState Current state of gesture (In process vs Completed) + @param sensor Sensor number + @param timestamp Timestamp correlating to Gesture data. */ OSVR_PLUGINKIT_EXPORT -OSVR_ReturnCode -osvrDeviceGestureReportData(OSVR_IN_PTR OSVR_GestureDeviceInterface iface, - OSVR_IN OSVR_GestureID gestureID, - OSVR_IN_PTR OSVR_GestureState gestureState, - OSVR_IN OSVR_ChannelCount sensor, - OSVR_IN_PTR OSVR_TimeValue const *timestamp) - OSVR_FUNC_NONNULL((1, 5)); +OSVR_ReturnCode osvrDeviceGestureReportData( + OSVR_IN_PTR OSVR_GestureDeviceInterface iface, + OSVR_IN OSVR_GestureID gestureID, OSVR_IN OSVR_GestureState gestureState, + OSVR_IN OSVR_ChannelCount sensor, + OSVR_IN_PTR OSVR_TimeValue const *timestamp) OSVR_FUNC_NONNULL((1, 5)); /** @} */ /* end of group */ From f8e19d63a15cbc16fbc0968d481bccc07a03a7f8 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 16:22:36 -0500 Subject: [PATCH 52/73] Substantial simplification of the gesture example --- examples/clients/Gesture.cpp | 41 +++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/examples/clients/Gesture.cpp b/examples/clients/Gesture.cpp index ea21219c2..e865b181f 100644 --- a/examples/clients/Gesture.cpp +++ b/examples/clients/Gesture.cpp @@ -34,47 +34,36 @@ #include #include -typedef struct ContextData { - osvr::clientkit::ClientContext *context; -} ContextData; - -void printGestureReport(const OSVR_GestureReport *report, std::string name) { - - std::string state; - if (report->state == OSVR_GESTURE_COMPLETE) { - state = "COMPLETE"; - } else { - state = "IN PROCESS"; - } - std::cout << name << "; " << report->gestureID << "; " << state << "\t" - << std::endl; -} - void gestureCallback(void *userdata, const OSVR_TimeValue * /*timestamp*/, const OSVR_GestureReport *report) { - auto ctx = static_cast(userdata); - std::string name = ctx->context->getNamefromID(StringID(report->gestureID)); - std::cout << "Got Gesture Report, for sensor #" << report->sensor + auto &ctx = *static_cast(userdata); + + /// You would typically not do this every frame - you'd retrieve the ID + /// based on the string, and then just compare the ID. This is just to make + /// a more compelling example. + std::string name = ctx.getNamefromID(StringID(report->gestureID)); + std::cout << "Gesture: Sensor " << report->sensor << ": ID " + << report->gestureID << " (" << name << ") " + << (report->state == OSVR_GESTURE_COMPLETE ? "COMPLETE" + : "IN PROGRESS") << std::endl; - printGestureReport(report, name); } int main() { - ContextData ctx; - ctx.context = new osvr::clientkit::ClientContext( + osvr::clientkit::ClientContext ctx( "com.osvr.exampleclients.GestureCallback"); osvr::clientkit::Interface gesture = - ctx.context->getInterface("/com_osvr_example_Gesture/Gesture/gesture"); + ctx.getInterface("/com_osvr_example_Gesture/Gesture/gesture"); - gesture.registerCallback(&gestureCallback, static_cast(&ctx)); + gesture.registerCallback(&gestureCallback, &ctx); // Pretend that this is your application's mainloop. while (1) { - ctx.context->update(); + ctx.update(); } std::cout << "Library shut down, exiting." << std::endl; return 0; -} \ No newline at end of file +} From db4a545ea96587d33d8d10269cf9570eabfe0257 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 15 Sep 2015 16:57:07 -0500 Subject: [PATCH 53/73] Gesture clientkit method name changes and some doc cleanups --- inc/osvr/ClientKit/Context.h | 7 ++++--- inc/osvr/ClientKit/InterfaceC.h | 25 +++++++++++-------------- src/osvr/ClientKit/InterfaceC.cpp | 15 +++++++++++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index 80bf4799b..97b95b7dd 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -113,10 +113,11 @@ namespace clientkit { return osvrClientCheckStatus(m_context) == OSVR_RETURN_SUCCESS; } - inline std::string ClientContext::getNamefromID(StringID id) { + inline std::string ClientContext::getGestureNamefromID(StringID id) { size_t length = 0; - OSVR_ReturnCode ret = osvrClientGetNameLength(m_context, id, &length); + OSVR_ReturnCode ret = + osvrClientGetGestureNameLength(m_context, id, &length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error( "Invalid context or null reference to length variable."); @@ -127,7 +128,7 @@ namespace clientkit { } boost::scoped_array buf(new char[length]); - ret = osvrClientGetNameFromID(m_context, id, buf.get(), length); + ret = osvrClientGetGestureNameFromID(m_context, id, buf.get(), length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error("Invalid context, null reference to " "buffer, or buffer is too small."); diff --git a/inc/osvr/ClientKit/InterfaceC.h b/inc/osvr/ClientKit/InterfaceC.h index c35df62df..249d75d76 100644 --- a/inc/osvr/ClientKit/InterfaceC.h +++ b/inc/osvr/ClientKit/InterfaceC.h @@ -76,23 +76,20 @@ osvrClientFreeInterface(OSVR_ClientContext ctx, OSVR_ClientInterface iface); if the parameter does not exist or is not a string. */ -OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode -osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len); +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetGestureNameLength( + OSVR_ClientContext ctx, uint32_t id, size_t *len); -/** @brief Convert the ID to string name representation +/** @brief Convert the gesture ID to string name representation -@param ctx Client context -@param id An id that corresponds to an entry in string to ID map -@param [in, out] buf A buffer that you allocate of appropriate size. -Must be at least the length returned by osvrClientGetStringParameterLength. -Will contain the null-terminated string parameter value. -@param len The length of the buffer you're providing. If the buffer is too -short, an error is returned and the buffer is unchanged. - -@returns It will copy the name of entry name that corresponds to the -provided id + @param ctx Client context + @param id An id that corresponds to an entry in gesture string to ID map + @param [in, out] buf A buffer that you allocate of appropriate size. + Must be at least the length returned by osvrClientGetStringParameterLength. + Will contain the null-terminated string name of the gesture ID. + @param len The length of the buffer you're providing. If the buffer is too + short, an error is returned and the buffer is unchanged. */ -OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetNameFromID( +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetGestureNameFromID( OSVR_ClientContext ctx, uint32_t id, char *buf, size_t len); /** @} */ diff --git a/src/osvr/ClientKit/InterfaceC.cpp b/src/osvr/ClientKit/InterfaceC.cpp index c599bf3b8..ac876cd91 100644 --- a/src/osvr/ClientKit/InterfaceC.cpp +++ b/src/osvr/ClientKit/InterfaceC.cpp @@ -74,8 +74,8 @@ OSVR_ReturnCode osvrClientFreeInterface(OSVR_ClientContext ctx, return OSVR_RETURN_SUCCESS; } -OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode -osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len) { +OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetGestureNameLength( + OSVR_ClientContext ctx, uint32_t id, size_t *len) { if (ctx == nullptr) { return OSVR_RETURN_FAILURE; @@ -83,6 +83,8 @@ osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len) { if (len == nullptr) { return OSVR_RETURN_FAILURE; } + /// @todo Shouldn't be hardcoded as the only registered string map - this + /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( StringID(id)); @@ -90,8 +92,9 @@ osvrClientGetNameLength(OSVR_ClientContext ctx, uint32_t id, size_t *len) { return OSVR_RETURN_SUCCESS; } -OSVR_ReturnCode osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, - char *buf, size_t len) { +OSVR_ReturnCode osvrClientGetGestureNameFromID(OSVR_ClientContext ctx, + uint32_t id, char *buf, + size_t len) { if (ctx == nullptr) { return OSVR_RETURN_FAILURE; @@ -100,6 +103,8 @@ OSVR_ReturnCode osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, return OSVR_RETURN_FAILURE; } + /// @todo Shouldn't be hardcoded as the only registered string map - this + /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( StringID(id)); @@ -108,6 +113,8 @@ OSVR_ReturnCode osvrClientGetNameFromID(OSVR_ClientContext ctx, uint32_t id, /// buffer too small. return OSVR_RETURN_FAILURE; } + + /// @todo refactor to eliminate duplication entryName.copy(buf, entryName.size()); buf[entryName.size()] = '\0'; return OSVR_RETURN_SUCCESS; From c0aa2edf4a3efd830793edf5c8d68bd3a7d95fb8 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 16 Sep 2015 17:54:30 -0500 Subject: [PATCH 54/73] Fix configuring of pluginhost - can't put jsoncpp as a public lib. --- src/osvr/PluginHost/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/osvr/PluginHost/CMakeLists.txt b/src/osvr/PluginHost/CMakeLists.txt index 5f3b2d654..1b09f0f54 100644 --- a/src/osvr/PluginHost/CMakeLists.txt +++ b/src/osvr/PluginHost/CMakeLists.txt @@ -41,8 +41,6 @@ target_link_libraries(${LIBNAME_FULL} PUBLIC libfunctionality::functionality osvrUtilCpp - osvrCommon - jsoncpp_lib PRIVATE boost_filesystem) From ac6218be73f5034ca568ed5b440a794781e5d5f3 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 16 Sep 2015 18:29:03 -0500 Subject: [PATCH 55/73] Substantially overhaul the type-safe ID template. No more overriding operator& or providing non-const value accessors or implicit conversion. It's also now properly in a namespace, and uses traits classes to determine the underlying value type as well as the "invalid/empty" sentinel value. --- inc/osvr/Util/ID.h | 67 ------------------------------------ src/osvr/Util/CMakeLists.txt | 1 - 2 files changed, 68 deletions(-) delete mode 100644 inc/osvr/Util/ID.h diff --git a/inc/osvr/Util/ID.h b/inc/osvr/Util/ID.h deleted file mode 100644 index 6682c8472..000000000 --- a/inc/osvr/Util/ID.h +++ /dev/null @@ -1,67 +0,0 @@ -/** @file - @brief Header - - @date 2015 - - @author - Sensics, Inc. - -*/ - -// Copyright 2015 Sensics, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 -#define INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 - -// Internal Includes -// - none - -// Library/third-party includes -// - none - -// Standard includes -#include -#include - -/// idea from the -/// http://www.ilikebigbits.com/blog/2014/5/6/type-safe-identifiers-in-c -template class ID { - public: - static ID invalid() { return ID(); } - - // Default constructor which will set m_val to a 0xffffffff (UINT32 max) - // and signify empty. - ID() : m_val(0xffffffff) {} - - // Explicit constructor: - explicit ID(impl val) : m_val(val) {} - - bool empty() const { return m_val == 0xffffffff ? true : false; } - - operator impl &() { return m_val; } - friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } - friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } - - impl &value() { return m_val; } - impl value() const { return m_val; } - - private: - impl m_val; -}; - -typedef ID StringID; -typedef ID PeerStringID; - -#endif // INCLUDED_ID_h_GUID_137CA336_382A_4796_7735_4521F02D5AC2 diff --git a/src/osvr/Util/CMakeLists.txt b/src/osvr/Util/CMakeLists.txt index 544801c88..72618293c 100644 --- a/src/osvr/Util/CMakeLists.txt +++ b/src/osvr/Util/CMakeLists.txt @@ -65,7 +65,6 @@ set(API "${HEADER_LOCATION}/ExtractYaw.h" "${HEADER_LOCATION}/Finally.h" "${HEADER_LOCATION}/Flag.h" - "${HEADER_LOCATION}/ID.h" "${HEADER_LOCATION}/GenericCaller.h" "${HEADER_LOCATION}/GenericDeleter.h" "${HEADER_LOCATION}/GuardInterface.h" From 290910312ccf70c94031d0a7053f8f3b5ca4bd6b Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 16 Sep 2015 18:47:11 -0500 Subject: [PATCH 56/73] Work on fixing StringID usages. --- inc/osvr/ClientKit/Context.h | 6 +++--- inc/osvr/ClientKit/Context_decl.h | 10 ++++++---- inc/osvr/Common/GestureComponent.h | 3 ++- inc/osvr/Common/SerializationTraits.h | 6 +++--- src/osvr/ClientKit/InterfaceC.cpp | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index 97b95b7dd..5eb157f7f 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -113,11 +113,11 @@ namespace clientkit { return osvrClientCheckStatus(m_context) == OSVR_RETURN_SUCCESS; } - inline std::string ClientContext::getGestureNamefromID(StringID id) { + inline std::string ClientContext::getGestureNamefromID(util::StringID id) { size_t length = 0; OSVR_ReturnCode ret = - osvrClientGetGestureNameLength(m_context, id, &length); + osvrClientGetGestureNameLength(m_context, id.get(), &length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error( "Invalid context or null reference to length variable."); @@ -128,7 +128,7 @@ namespace clientkit { } boost::scoped_array buf(new char[length]); - ret = osvrClientGetGestureNameFromID(m_context, id, buf.get(), length); + ret = osvrClientGetGestureNameFromID(m_context, id.get(), buf.get(), length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error("Invalid context, null reference to " "buffer, or buffer is too small."); diff --git a/inc/osvr/ClientKit/Context_decl.h b/inc/osvr/ClientKit/Context_decl.h index 447538d64..52817440f 100644 --- a/inc/osvr/ClientKit/Context_decl.h +++ b/inc/osvr/ClientKit/Context_decl.h @@ -27,7 +27,7 @@ // Internal Includes #include -#include +#include // Library/third-party includes #include @@ -87,12 +87,14 @@ namespace clientkit { /// from false to true without calling update() - consider a loop. bool checkStatus() const; + /// @brief converts gesture ID to string name. Not for frequent use - + /// typical usage is to get a gesture ID from a string, and use that for + /// comparison. + std::string getGestureNamefromID(util::StringID id); + /// @brief Gets the bare OSVR_ClientContext. OSVR_ClientContext get(); - /// @brief converts ID to string name - std::string getNamefromID(StringID id); - private: OSVR_ClientContext m_context; }; diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 34b1cd32a..58027aa72 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -35,6 +35,7 @@ #include #include #include +#include // Library/third-party includes #include @@ -48,7 +49,7 @@ namespace common { struct GestureData { OSVR_ChannelCount sensor; OSVR_GestureState gestureState; - StringID gestureID; + util::StringID gestureID; }; namespace messages { diff --git a/inc/osvr/Common/SerializationTraits.h b/inc/osvr/Common/SerializationTraits.h index 943783611..1eca182cb 100644 --- a/inc/osvr/Common/SerializationTraits.h +++ b/inc/osvr/Common/SerializationTraits.h @@ -105,7 +105,7 @@ namespace common { /// @brief Serialize a value to a buffer, with optional tag to specify /// non-default traits. template > + typename Tag = DefaultSerializationTag> inline void serializeRaw(BufferType &buf, T const &v, Tag const &tag = Tag()) { SerializationTraits::serialize(buf, v, tag); @@ -114,7 +114,7 @@ namespace common { /// @brief Deserialize a value from a buffer, with optional tag to /// specify non-default traits. template > + typename Tag = DefaultSerializationTag> inline void deserializeRaw(BufferReaderType &reader, T &v, Tag const &tag = Tag()) { SerializationTraits::deserialize(reader, v, tag); @@ -122,7 +122,7 @@ namespace common { /// @brief Get the size a value from a buffer, with optional tag to /// specify non-default traits. - template > + template > inline size_t getBufferSpaceRequiredRaw(size_t existingBufferSize, T const &v, Tag const &tag = Tag()) { diff --git a/src/osvr/ClientKit/InterfaceC.cpp b/src/osvr/ClientKit/InterfaceC.cpp index ac876cd91..546f9aeca 100644 --- a/src/osvr/ClientKit/InterfaceC.cpp +++ b/src/osvr/ClientKit/InterfaceC.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include // Library/third-party includes // - none @@ -87,7 +87,7 @@ OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetGestureNameLength( /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( - StringID(id)); + osvr::util::StringID(id)); *len = entryName.empty() ? 0 : (entryName.size() + 1); return OSVR_RETURN_SUCCESS; } @@ -107,7 +107,7 @@ OSVR_ReturnCode osvrClientGetGestureNameFromID(OSVR_ClientContext ctx, /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( - StringID(id)); + osvr::util::StringID(id)); if (entryName.size() + 1 > len) { /// buffer too small. From 832efd54ea2341879b23be9e472806313f9476d5 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 17 Sep 2015 14:07:07 -0500 Subject: [PATCH 57/73] Fix build --- examples/clients/Gesture.cpp | 4 +++- inc/osvr/ClientKit/Context.h | 4 ++-- src/osvr/Client/GestureRemoteFactory.cpp | 8 ++++---- src/osvr/Common/GestureComponent.cpp | 11 ++++------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/clients/Gesture.cpp b/examples/clients/Gesture.cpp index e865b181f..a3ff6186d 100644 --- a/examples/clients/Gesture.cpp +++ b/examples/clients/Gesture.cpp @@ -27,8 +27,10 @@ #include #include #include +#include // Library/third-party includes +// - none // Standard includes #include @@ -41,7 +43,7 @@ void gestureCallback(void *userdata, const OSVR_TimeValue * /*timestamp*/, /// You would typically not do this every frame - you'd retrieve the ID /// based on the string, and then just compare the ID. This is just to make /// a more compelling example. - std::string name = ctx.getNamefromID(StringID(report->gestureID)); + std::string name = ctx.getGestureNamefromID(osvr::util::StringID(report->gestureID)); std::cout << "Gesture: Sensor " << report->sensor << ": ID " << report->gestureID << " (" << name << ") " << (report->state == OSVR_GESTURE_COMPLETE ? "COMPLETE" diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index 5eb157f7f..c47b103e5 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -117,7 +117,7 @@ namespace clientkit { size_t length = 0; OSVR_ReturnCode ret = - osvrClientGetGestureNameLength(m_context, id.get(), &length); + osvrClientGetGestureNameLength(m_context, id.value(), &length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error( "Invalid context or null reference to length variable."); @@ -128,7 +128,7 @@ namespace clientkit { } boost::scoped_array buf(new char[length]); - ret = osvrClientGetGestureNameFromID(m_context, id.get(), buf.get(), length); + ret = osvrClientGetGestureNameFromID(m_context, id.value(), buf.get(), length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error("Invalid context, null reference to " "buffer, or buffer is too small."); diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index 513f0c8dd..da9b08f6c 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -92,8 +92,8 @@ namespace client { } OSVR_GestureReport report; - StringID id = - m_gestureNameMap->corrMap.convertPeerToLocalID(data.gestureID); + util::StringID id = + m_gestureNameMap->corrMap.convertPeerToLocalID(util::PeerStringID(data.gestureID.value())); if (id.empty()) { // could not find a peer to local mapping, discarding report return; @@ -101,7 +101,7 @@ namespace client { report.sensor = data.sensor; report.state = data.gestureState; - report.gestureID = id; + report.gestureID = id.value(); for (auto &iface : m_interfaces) { iface->triggerCallbacks(timestamp, report); } @@ -142,4 +142,4 @@ namespace client { } } // namespace client -} // namespace osvr \ No newline at end of file +} // namespace osvr diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index a3cb9d571..e424e8324 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -65,11 +65,11 @@ namespace common { private: OSVR_GestureState m_gestureState; - StringID m_gestureID; + util::StringID m_gestureID; OSVR_ChannelCount m_sensor; }; const char *GestureRecord::identifier() { - return "com.osvr.gesture.gesturerecord"; + return "org.osvr.gesture.gesturerecord"; } } // namespace messages @@ -150,10 +150,7 @@ namespace common { OSVR_GestureID GestureComponent::getGestureID(const char *gestureName) { OSVR_GestureID gestureID = - m_gestureNameMap->map.getStringID(gestureName); - - OSVR_TimeValue now; - osvrTimeValueGetNow(&now); + m_gestureNameMap->map.getStringID(gestureName).value(); // if we just inserted new gesture ID then send gesture map if (m_gestureNameMap->map.isUpdateAvailable()) { @@ -163,4 +160,4 @@ namespace common { } } // namespace common -} // namespace osvr \ No newline at end of file +} // namespace osvr From 65011826d68e81adaef06022856168b94103cbbc Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 17 Sep 2015 18:05:47 -0500 Subject: [PATCH 58/73] Use the StringBufferBuilder in ClientKit. --- inc/osvr/ClientKit/Context.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/inc/osvr/ClientKit/Context.h b/inc/osvr/ClientKit/Context.h index c47b103e5..9fd7fa097 100755 --- a/inc/osvr/ClientKit/Context.h +++ b/inc/osvr/ClientKit/Context.h @@ -38,7 +38,6 @@ // Standard includes #include #include -#include namespace osvr { @@ -127,13 +126,15 @@ namespace clientkit { return std::string(); } - boost::scoped_array buf(new char[length]); - ret = osvrClientGetGestureNameFromID(m_context, id.value(), buf.get(), length); + util::StringBufferBuilder buf; + + ret = osvrClientGetGestureNameFromID( + m_context, id.value(), buf.getBufferOfSize(length), length); if (OSVR_RETURN_SUCCESS != ret) { throw std::runtime_error("Invalid context, null reference to " "buffer, or buffer is too small."); } - return std::string(buf.get()); + return buf.str(); } } // end namespace clientkit From b0af05dead8bc2e7e611ec493d8241b2293903a2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 17 Sep 2015 18:06:01 -0500 Subject: [PATCH 59/73] Work on registered string map --- src/osvr/Common/GestureComponent.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index e424e8324..f761d6738 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -153,7 +153,8 @@ namespace common { m_gestureNameMap->map.getStringID(gestureName).value(); // if we just inserted new gesture ID then send gesture map - if (m_gestureNameMap->map.isUpdateAvailable()) { + if (m_gestureNameMap->map.isModified()) { + m_gestureNameMap->map.clearModifiedFlag(); m_systemComponent->sendRegisteredStringMap(); } return gestureID; From 8f86845796258efce0354abd0f57b11f8b115c53 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 21 Sep 2015 11:16:17 -0500 Subject: [PATCH 60/73] Some generation of gesture-related files. --- src/osvr/Util/CMakeLists.txt | 31 ++++++++++++++++++++++++++++++- src/osvr/Util/GesturesData.txt | 12 ++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/osvr/Util/GesturesData.txt diff --git a/src/osvr/Util/CMakeLists.txt b/src/osvr/Util/CMakeLists.txt index 72618293c..69a11966f 100644 --- a/src/osvr/Util/CMakeLists.txt +++ b/src/osvr/Util/CMakeLists.txt @@ -24,6 +24,33 @@ include(CheckCXXSymbolExists) check_cxx_symbol_exists("std::align" "memory" OSVR_HAVE_STDALIGN) configure_file(StdAlignWrapper.h.in "${CMAKE_CURRENT_BINARY_DIR}/StdAlignWrapper.h" @ONLY) +### +# Gestures-related generation +### +set(GESTURE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/GesturesData.txt") +# Dummy configure to make us re-cmake +configure_file("${GESTURE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/GesturesData.dummy") + +# Parse the gesture list +file(STRINGS "${GESTURE_FILE}" _gestures) +set(BODY) +set(GESTURE_NAMES) +foreach(line ${_gestures}) + string(REGEX REPLACE ":.*" "" gesture_name "${line}") + string(REGEX REPLACE "[^:]*:" "" gesture_string "${line}") + set(BODY "${BODY}\n#define ${gesture_name} \"${gesture_string}\"") + list(APPEND GESTURE_NAMES "${gesture_name}") +endforeach() + +# Create the PredefinedGestures header. +configure_file("PredefinedGesturesC.h.in" "${CMAKE_CURRENT_BINARY_DIR}/PredefinedGesturesC.h" @ONLY) + +# Create the X-Macro header for gestures. +osvr_generate_x_macro(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/PredefinedGesturesXMacroC.h" + INVOCATION_NAME OSVR_GESTURE_X + DEPENDS "${GESTURE_FILE}" + ELEMENTS ${GESTURE_NAMES}) + ### # Library build ### @@ -122,7 +149,9 @@ set(API "${HEADER_LOCATION}/Vec2C.h" "${HEADER_LOCATION}/Vec3C.h" "${HEADER_LOCATION}/WindowsVariantC.h" - "${CMAKE_CURRENT_BINARY_DIR}/PlatformConfig.h") + "${CMAKE_CURRENT_BINARY_DIR}/PlatformConfig.h" + "${CMAKE_CURRENT_BINARY_DIR}/PredefinedGesturesC.h" + "${CMAKE_CURRENT_BINARY_DIR}/PredefinedGesturesXMacroC.h") set(SOURCE AlignedMemoryC.cpp diff --git a/src/osvr/Util/GesturesData.txt b/src/osvr/Util/GesturesData.txt new file mode 100644 index 000000000..832ed4196 --- /dev/null +++ b/src/osvr/Util/GesturesData.txt @@ -0,0 +1,12 @@ +OSVR_GESTURE_SWIPE_LEFT:SwipeLeft +OSVR_GESTURE_SWIPE_RIGHT:SwipeRight +OSVR_GESTURE_SCROLL_UP:ScrollUp +OSVR_GESTURE_SCROLL_DOWN:ScrollDown +OSVR_GESTURE_SINGLE_TAP:SingleTap +OSVR_GESTURE_DOUBLE_TAP:DoubleTap +OSVR_GESTURE_PINCH:Pinch +OSVR_GESTURE_FINGER_SPREAD:FingerSpread +OSVR_GESTURE_CIRCLE:Circle +OSVR_GESTURE_LONG_PRESS:LongPress +OSVR_GESTURE_OPEN_HAND:OpenHand +OSVR_GESTURE_CLOSED_HAND:ClosedHand \ No newline at end of file From de03a0855a04953e65ebf77c74dbe439c32c0ff9 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 21 Sep 2015 11:23:18 -0500 Subject: [PATCH 61/73] Use generated gesture define header. --- inc/osvr/Util/ClientReportTypesC.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/inc/osvr/Util/ClientReportTypesC.h b/inc/osvr/Util/ClientReportTypesC.h index dd8fff49e..65289833a 100644 --- a/inc/osvr/Util/ClientReportTypesC.h +++ b/inc/osvr/Util/ClientReportTypesC.h @@ -38,6 +38,7 @@ #include #include #include +#include /* Library/third-party includes */ /* none */ @@ -358,20 +359,6 @@ typedef uint8_t OSVR_GestureState; /** @brief OSVR_GestureState value indicating "gesture is finished" */ #define OSVR_GESTURE_COMPLETE (0) -/** @brief a list of pre-set gestures available (can be expanded) */ -#define OSVR_GESTURE_SWIPE_LEFT "SwipeLeft" -#define OSVR_GESTURE_SWIPE_RIGHT "SwipeRight" -#define OSVR_GESTURE_SCROLL_UP "ScrollUp" -#define OSVR_GESTURE_SCROLL_DOWN "ScrollDown" -#define OSVR_GESTURE_SINGLE_TAP "SingleTap" -#define OSVR_GESTURE_DOUBLE_TAP "DoubleTap" -#define OSVR_GESTURE_PINCH "Pinch" -#define OSVR_GESTURE_FINGER_SPREAD "FingerSpread" -#define OSVR_GESTURE_CIRCLE "Circle" -#define OSVR_GESTURE_LONG_PRESS "LongPress" -#define OSVR_GESTURE_OPEN_HAND "OpenHand" -#define OSVR_GESTURE_CLOSED_HAND "ClosedHand" - /** @brief Report type for a gesture event */ typedef struct OSVR_GestureReport { OSVR_GestureID gestureID; From 685bdf930beaddd97fd77728a47a4fc3784f3eb6 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 21 Sep 2015 11:23:34 -0500 Subject: [PATCH 62/73] Gesture and System component changes. --- inc/osvr/Common/GestureComponent.h | 18 +++++---- inc/osvr/Common/SystemComponent.h | 42 ++++++++++----------- src/osvr/Common/GestureComponent.cpp | 53 +++++++++++++++------------ src/osvr/Common/SystemComponent.cpp | 55 +++++++++++----------------- 4 files changed, 81 insertions(+), 87 deletions(-) diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index 58027aa72..e13964a02 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -70,7 +70,7 @@ namespace common { /// Required to ensure that allocation and deallocation stay on the same /// side of a DLL line. static OSVR_COMMON_EXPORT shared_ptr - create(common::SystemComponent *systemComponent); + create(common::SystemComponent &systemComponent); /// @brief Message from server to client, containing Gesture data. messages::GestureRecord gestureRecord; @@ -90,9 +90,12 @@ namespace common { OSVR_COMMON_EXPORT OSVR_GestureID getGestureID(const char *gestureName); private: - GestureComponent(common::SystemComponent *systemComponent); - virtual void m_parentSet(); + explicit GestureComponent(common::SystemComponent &systemComponent); + + void m_parentSet() override; + + util::StringID m_getStringID(std::string const& str); static int VRPN_CALLBACK m_handleGestureRecord(void *userdata, vrpn_HANDLERPARAM p); @@ -102,12 +105,11 @@ namespace common { OSVR_ChannelCount m_numSensor; std::vector m_cb; - // name to ID map used by the server - // RegisteredStringMap m_gestureNameMap; - MapPtr m_gestureNameMap; - /// @brief System device component - common::SystemComponent *m_systemComponent; + common::SystemComponent &m_systemComponent; + + /// name to ID map used by the server + GestureDataPtr m_gestureNameMap; }; } // namespace common diff --git a/inc/osvr/Common/SystemComponent.h b/inc/osvr/Common/SystemComponent.h index b19cea222..14a724614 100644 --- a/inc/osvr/Common/SystemComponent.h +++ b/inc/osvr/Common/SystemComponent.h @@ -40,15 +40,12 @@ #include // Standard includes -// - none +#include +#include namespace osvr { namespace common { - struct MapData { - SerializedStringMap serializedMap; - }; - namespace messages { class RoutesFromServer : public MessageRegistration { public: @@ -95,8 +92,8 @@ namespace common { CorrelatedStringMap corrMap; }; - typedef shared_ptr MapPtr; - + using GestureMapData = std::vector; + using GestureDataPtr = shared_ptr; typedef shared_ptr SystemComponentPtr; /// @brief BaseDevice component, to be used only with the "OSVR" special @@ -136,38 +133,37 @@ namespace common { typedef std::function JsonHandler; - OSVR_COMMON_EXPORT void registerReplaceTreeHandler(JsonHandler cb); + OSVR_COMMON_EXPORT void + registerReplaceTreeHandler(JsonHandler const &cb); OSVR_COMMON_EXPORT void sendReplacementTree(PathTree &tree); - /// @brief Request a copy of MapPtr to the name to ID map - OSVR_COMMON_EXPORT MapPtr getRegStringMap(); + /// @brief Get shared ownership of the gesture map data structures + OSVR_COMMON_EXPORT GestureDataPtr getGestureMap(); /// @brief Message from server to client, containing registeredStringMap - messages::RegisteredStringMapRecord regStringMap; + messages::RegisteredStringMapRecord gestureStringMap; - OSVR_COMMON_EXPORT void sendRegisteredStringMap(); + OSVR_COMMON_EXPORT void sendGestureMap(); - typedef std::function - RegisteredStringMapHandler; + typedef std::function GestureMapHandler; OSVR_COMMON_EXPORT void - registerStringMapHandler(RegisteredStringMapHandler cb); + registerGestureMapHandler(GestureMapHandler const &cb); private: SystemComponent(); virtual void m_parentSet(); - static int VRPN_CALLBACK - m_handleReplaceTree(void *userdata, vrpn_HANDLERPARAM p); + static int VRPN_CALLBACK m_handleReplaceTree(void *userdata, + vrpn_HANDLERPARAM p); std::vector m_replaceTreeHandlers; - static int VRPN_CALLBACK - m_handleRegStringMap(void *userdata, vrpn_HANDLERPARAM p); - std::vector m_cb_map; + static int VRPN_CALLBACK m_handleRegStringMap(void *userdata, + vrpn_HANDLERPARAM p); + std::vector m_cb_map; - // name to ID map used by the server - MapPtr m_nameToIDMap; + // name to ID map used by the gesture interface class + GestureDataPtr m_nameToIDMap; /// @brief Common component for system device common::CommonComponent *m_commonComponent; diff --git a/src/osvr/Common/GestureComponent.cpp b/src/osvr/Common/GestureComponent.cpp index f761d6738..9b76bf204 100644 --- a/src/osvr/Common/GestureComponent.cpp +++ b/src/osvr/Common/GestureComponent.cpp @@ -29,6 +29,7 @@ #include #include #include +#include // Library/third-party includes // - none @@ -75,33 +76,37 @@ namespace common { } // namespace messages shared_ptr - GestureComponent::create(common::SystemComponent *systemComponent) { + GestureComponent::create(common::SystemComponent &systemComponent) { shared_ptr ret(new GestureComponent(systemComponent)); return ret; } - GestureComponent::GestureComponent( - common::SystemComponent *systemComponent) { - // Add system component and gesture map - m_systemComponent = systemComponent; - m_gestureNameMap = m_systemComponent->getRegStringMap(); + GestureComponent::GestureComponent(common::SystemComponent &systemComponent) + : m_systemComponent(systemComponent), + m_gestureNameMap(m_systemComponent.getGestureMap()) { // populate the gesture map - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_LEFT); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SWIPE_RIGHT); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_UP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SCROLL_DOWN); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_SINGLE_TAP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_DOUBLE_TAP); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_PINCH); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_FINGER_SPREAD); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CIRCLE); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_LONG_PRESS); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_OPEN_HAND); - m_gestureNameMap->map.registerStringID(OSVR_GESTURE_CLOSED_HAND); +#define OSVR_X(GESTURE) m_getStringID(GESTURE); + OSVR_GESTURE_X() +#undef OSVR_X + +#if 0 + m_getStringID(OSVR_GESTURE_SWIPE_LEFT); + m_getStringID(OSVR_GESTURE_SWIPE_RIGHT); + m_getStringID(OSVR_GESTURE_SCROLL_UP); + m_getStringID(OSVR_GESTURE_SCROLL_DOWN); + m_getStringID(OSVR_GESTURE_SINGLE_TAP); + m_getStringID(OSVR_GESTURE_DOUBLE_TAP); + m_getStringID(OSVR_GESTURE_PINCH); + m_getStringID(OSVR_GESTURE_FINGER_SPREAD); + m_getStringID(OSVR_GESTURE_CIRCLE); + m_getStringID(OSVR_GESTURE_LONG_PRESS); + m_getStringID(OSVR_GESTURE_OPEN_HAND); + m_getStringID(OSVR_GESTURE_CLOSED_HAND); +#endif // send out an updated map - m_systemComponent->sendRegisteredStringMap(); + m_systemComponent.sendGestureMap(); } void GestureComponent::sendGestureData(OSVR_GestureState gestureState, @@ -135,6 +140,10 @@ namespace common { return 0; } + util::StringID GestureComponent::m_getStringID(std::string const &str) { + return m_gestureNameMap->map.getStringID(str); + } + void GestureComponent::registerGestureHandler(GestureHandler handler) { if (m_cb.empty()) { m_registerHandler(&GestureComponent::m_handleGestureRecord, this, @@ -149,13 +158,11 @@ namespace common { OSVR_GestureID GestureComponent::getGestureID(const char *gestureName) { - OSVR_GestureID gestureID = - m_gestureNameMap->map.getStringID(gestureName).value(); + OSVR_GestureID gestureID = m_getStringID(gestureName).value(); // if we just inserted new gesture ID then send gesture map if (m_gestureNameMap->map.isModified()) { - m_gestureNameMap->map.clearModifiedFlag(); - m_systemComponent->sendRegisteredStringMap(); + m_systemComponent.sendGestureMap(); } return gestureID; } diff --git a/src/osvr/Common/SystemComponent.cpp b/src/osvr/Common/SystemComponent.cpp index 9babfa04e..999650b0d 100644 --- a/src/osvr/Common/SystemComponent.cpp +++ b/src/osvr/Common/SystemComponent.cpp @@ -97,22 +97,16 @@ namespace common { class RegisteredStringMapRecord::MessageSerialization { public: - MessageSerialization(SerializedStringMap serializedMap) - : m_serializedMap(serializedMap) {} + explicit MessageSerialization(RegisteredStringMap const &myMap) + : m_data(myMap.getEntries()) {} - MessageSerialization() {} + MessageSerialization() = default; - template void processMessage(T &p) { - p(m_serializedMap); - } - MapData getData() const { - MapData ret; - ret.serializedMap = m_serializedMap; - return ret; - } + template void processMessage(T &p) { p(m_data); } + GestureMapData const &getData() const { return m_data; } private: - SerializedStringMap m_serializedMap; + GestureMapData m_data; }; const char *RegisteredStringMapRecord::identifier() { return "com.osvr.system.regstringmaprecord"; @@ -128,7 +122,8 @@ namespace common { return ret; } - SystemComponent::SystemComponent() : m_nameToIDMap(new RegStringMapData) {} + SystemComponent::SystemComponent() + : m_nameToIDMap(make_shared()) {} void SystemComponent::sendRoutes(std::string const &routes) { Buffer<> buf; @@ -164,7 +159,7 @@ namespace common { m_getParent().sendPending(); // forcing this since it will cause // shuffling of remotes on the client. } - void SystemComponent::registerReplaceTreeHandler(JsonHandler cb) { + void SystemComponent::registerReplaceTreeHandler(JsonHandler const &cb) { if (m_replaceTreeHandlers.empty()) { m_registerHandler(&SystemComponent::m_handleReplaceTree, this, treeOut.getMessageType()); @@ -172,27 +167,24 @@ namespace common { m_replaceTreeHandlers.push_back(cb); } - MapPtr SystemComponent::getRegStringMap() { return m_nameToIDMap; } - - void SystemComponent::sendRegisteredStringMap() { + GestureDataPtr SystemComponent::getGestureMap() { return m_nameToIDMap; } + void SystemComponent::sendGestureMap() { + m_nameToIDMap->map.clearModifiedFlag(); Buffer<> buf; - // serialize the map before sending it - SerializedStringMap serializedMap = m_nameToIDMap->map.getMap(); - - messages::RegisteredStringMapRecord::MessageSerialization msg( - serializedMap); + auto msg = messages::RegisteredStringMapRecord::MessageSerialization{ + m_nameToIDMap->map}; serialize(buf, msg); - m_getParent().packMessage(buf, regStringMap.getMessageType()); + m_getParent().packMessage(buf, gestureStringMap.getMessageType()); } - void SystemComponent::registerStringMapHandler( - RegisteredStringMapHandler handler) { + void + SystemComponent::registerGestureMapHandler(GestureMapHandler const &cb) { if (m_cb_map.empty()) { m_registerHandler(&SystemComponent::m_handleRegStringMap, this, - regStringMap.getMessageType()); + gestureStringMap.getMessageType()); } - m_cb_map.push_back(handler); + m_cb_map.push_back(cb); } void SystemComponent::m_parentSet() { @@ -201,16 +193,13 @@ namespace common { // connection(ping) occurs m_commonComponent = m_getParent().addComponent(osvr::common::CommonComponent::create()); - OSVR_TimeValue now; - osvrTimeValueGetNow(&now); - m_commonComponent->registerPingHandler( - [&] { sendRegisteredStringMap(); }); m_getParent().registerMessageType(routesOut); m_getParent().registerMessageType(appStartup); m_getParent().registerMessageType(routeIn); m_getParent().registerMessageType(treeOut); - m_getParent().registerMessageType(regStringMap); + m_getParent().registerMessageType(gestureStringMap); + m_commonComponent->registerPingHandler([&] { sendGestureMap(); }); } int SystemComponent::m_handleReplaceTree(void *userdata, @@ -238,7 +227,7 @@ namespace common { auto timestamp = util::time::fromStructTimeval(p.msg_time); for (auto const &cb : self->m_cb_map) { - cb(data, timestamp); + cb(data); } return 0; } From e994a6ddabd7bb131a2f8c9ccfe901b8fd3f7721 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 21 Sep 2015 14:53:17 -0500 Subject: [PATCH 63/73] Add missing file. --- src/osvr/Util/PredefinedGesturesC.h.in | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/osvr/Util/PredefinedGesturesC.h.in diff --git a/src/osvr/Util/PredefinedGesturesC.h.in b/src/osvr/Util/PredefinedGesturesC.h.in new file mode 100644 index 000000000..82d930501 --- /dev/null +++ b/src/osvr/Util/PredefinedGesturesC.h.in @@ -0,0 +1,58 @@ +/** @file + @brief Header + + Must be c-safe! + + @date 2015 + + @author + Sensics, Inc. + +*/ + +/* +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +*/ + +#ifndef INCLUDED_PredefinedGesturesC_h_GUID_1B515E73_97E5_44BA_76DE_A51C4B201C62 +#define INCLUDED_PredefinedGesturesC_h_GUID_1B515E73_97E5_44BA_76DE_A51C4B201C62 + +/* Internal Includes */ +#include + +/* Library/third-party includes */ +/* none */ + +/* Standard includes */ +/* none */ + +OSVR_EXTERN_C_BEGIN + +/** @addtogroup ClientKit +@{ +*/ + +/** @name Pre-defined gestures and their strings. +@{ +*/ + +@BODY@ + +/** @} */ + +/** @} */ + +OSVR_EXTERN_C_END +#endif From a0c1d2dd11a0de2097b5fc7da6f524771aacffd0 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 12:17:37 -0400 Subject: [PATCH 64/73] remove unused timestamp param and use updated function names --- src/osvr/Client/PureClientContext.cpp | 15 +++++++-------- src/osvr/Client/PureClientContext.h | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/osvr/Client/PureClientContext.cpp b/src/osvr/Client/PureClientContext.cpp index f3a6cba2b..653ec7742 100644 --- a/src/osvr/Client/PureClientContext.cpp +++ b/src/osvr/Client/PureClientContext.cpp @@ -108,11 +108,10 @@ namespace client { m_systemDevice->addComponent(common::SystemComponent::create()); /// Receive string map data whenever it comes - m_systemComponent->registerStringMapHandler( - [&](common::MapData const &dataMap, - util::time::TimeValue const ×tamp) { - m_handleRegStringMap(dataMap, timestamp); - }); + m_systemComponent->registerGestureMapHandler( + [&](common::GestureMapData const &dataMap) { + m_handleRegStringMap(dataMap); + }); using DedupJsonFunction = common::DeduplicatingFunctionWrapper; m_systemComponent->registerReplaceTreeHandler( @@ -225,9 +224,9 @@ namespace client { } void PureClientContext::m_handleRegStringMap( - common::MapData const &data, util::time::TimeValue const &) { - auto map = m_systemComponent->getRegStringMap(); - map->corrMap.setupPeerMappings(data.serializedMap); + common::GestureMapData const &data) { + auto map = m_systemComponent->getGestureMap(); + map->corrMap.setupPeerMappings(data); } } // namespace client } // namespace osvr diff --git a/src/osvr/Client/PureClientContext.h b/src/osvr/Client/PureClientContext.h index 0a8bad08c..c437415b6 100644 --- a/src/osvr/Client/PureClientContext.h +++ b/src/osvr/Client/PureClientContext.h @@ -119,8 +119,7 @@ namespace client { ClientInterfaceObjectManager m_ifaceMgr; /// @brief Called whenever an updated string to ID map is available - void m_handleRegStringMap(common::MapData const &data, - util::time::TimeValue const ×tamp); + void m_handleRegStringMap(common::GestureMapData const &data); }; } // namespace client } // namespace osvr From 152d6f2da32ae675f2f401cd4e47afa74c8601ab Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 12:19:42 -0400 Subject: [PATCH 65/73] use updated function names --- src/osvr/Client/GestureRemoteFactory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index da9b08f6c..39c31e115 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -59,8 +59,8 @@ namespace client { m_sensor(sensor), m_ctx(ctx) { m_sysComponent = m_ctx->getSystemComponent(); - m_gestureNameMap = m_sysComponent->getRegStringMap(); - auto gesture = common::GestureComponent::create(m_sysComponent); + m_gestureNameMap = m_sysComponent->getGestureMap(); + auto gesture = common::GestureComponent::create(*m_sysComponent); m_dev->addComponent(gesture); gesture->registerGestureHandler( @@ -112,7 +112,7 @@ namespace client { bool m_all; boost::optional m_sensor; // map to keep track of gesture map and server to local ID map - common::MapPtr m_gestureNameMap; + common::GestureDataPtr m_gestureNameMap; common::ClientContext *m_ctx; common::SystemComponent *m_sysComponent; }; From 58e1746a1c4b9a81858bcb4ab64ca86022cd9153 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 12:20:02 -0400 Subject: [PATCH 66/73] minor gesture sample plugin update --- examples/plugin/com_osvr_example_Gesture.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/plugin/com_osvr_example_Gesture.cpp b/examples/plugin/com_osvr_example_Gesture.cpp index b70229601..8b4d5553a 100644 --- a/examples/plugin/com_osvr_example_Gesture.cpp +++ b/examples/plugin/com_osvr_example_Gesture.cpp @@ -53,7 +53,7 @@ class GestureDevice { // get an ID for gesture names to be used in plugin osvrDeviceGestureGetID(m_gesture, OSVR_GESTURE_DOUBLE_TAP, &m_double_tap_gesture); - osvrDeviceGestureGetID(m_gesture, "FIST", &m_fist_gesture); + osvrDeviceGestureGetID(m_gesture, "LASSO", &m_lasso_gesture); /// Send JSON descriptor m_dev.sendJsonDescriptor(com_osvr_example_Gesture_json); @@ -73,7 +73,7 @@ class GestureDevice { osvrDeviceGestureReportData(m_gesture, m_double_tap_gesture, OSVR_GESTURE_COMPLETE, 0, ×); - osvrDeviceGestureReportData(m_gesture, m_fist_gesture, + osvrDeviceGestureReportData(m_gesture, m_lasso_gesture, OSVR_GESTURE_COMPLETE, 1, ×); return OSVR_RETURN_SUCCESS; @@ -82,7 +82,7 @@ class GestureDevice { private: osvr::pluginkit::DeviceToken m_dev; OSVR_GestureDeviceInterface m_gesture; - OSVR_GestureID m_fist_gesture; + OSVR_GestureID m_lasso_gesture; OSVR_GestureID m_double_tap_gesture; }; From 943f6565cf4af9606340586bc8bc8ab7eb853736 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 12:20:51 -0400 Subject: [PATCH 67/73] use updated function names --- src/osvr/ClientKit/InterfaceC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/osvr/ClientKit/InterfaceC.cpp b/src/osvr/ClientKit/InterfaceC.cpp index 546f9aeca..75587caf7 100644 --- a/src/osvr/ClientKit/InterfaceC.cpp +++ b/src/osvr/ClientKit/InterfaceC.cpp @@ -86,7 +86,7 @@ OSVR_CLIENTKIT_EXPORT OSVR_ReturnCode osvrClientGetGestureNameLength( /// @todo Shouldn't be hardcoded as the only registered string map - this /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = - ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( + ctx->getSystemComponent()->getGestureMap()->corrMap.getStringFromId( osvr::util::StringID(id)); *len = entryName.empty() ? 0 : (entryName.size() + 1); return OSVR_RETURN_SUCCESS; @@ -106,8 +106,8 @@ OSVR_ReturnCode osvrClientGetGestureNameFromID(OSVR_ClientContext ctx, /// @todo Shouldn't be hardcoded as the only registered string map - this /// should be accessible as "interface-class-level" data for Gesture. std::string entryName = - ctx->getSystemComponent()->getRegStringMap()->corrMap.getNameFromID( - osvr::util::StringID(id)); + ctx->getSystemComponent()->getGestureMap()->corrMap.getStringFromId( + osvr::util::StringID(id)); if (entryName.size() + 1 > len) { /// buffer too small. From 08330f3e71f9721ec2e4cf15246cdd0de81fb592 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 12:22:03 -0400 Subject: [PATCH 68/73] use sysComponent reference for GestureComponent constructor --- src/osvr/PluginKit/GestureInterfaceC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osvr/PluginKit/GestureInterfaceC.cpp b/src/osvr/PluginKit/GestureInterfaceC.cpp index 2d0c85de5..488f919d9 100644 --- a/src/osvr/PluginKit/GestureInterfaceC.cpp +++ b/src/osvr/PluginKit/GestureInterfaceC.cpp @@ -56,7 +56,7 @@ osvrDeviceGestureConfigure(OSVR_INOUT_PTR OSVR_DeviceInitOptions opts, *iface = ifaceObj; auto systemComponent = opts->getParentContext()->getSystemComponent(); - auto gesture = osvr::common::GestureComponent::create(systemComponent); + auto gesture = osvr::common::GestureComponent::create(*systemComponent); ifaceObj->gesture = gesture.get(); opts->addComponent(gesture); return OSVR_RETURN_SUCCESS; From 508c7ac1dd892ba010f22957fe71a6303bf25f84 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 14:00:15 -0400 Subject: [PATCH 69/73] disable assignment operator due to reference members which generates compiler warnings --- inc/osvr/Common/GestureComponent.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/osvr/Common/GestureComponent.h b/inc/osvr/Common/GestureComponent.h index e13964a02..b5a04a4b5 100644 --- a/inc/osvr/Common/GestureComponent.h +++ b/inc/osvr/Common/GestureComponent.h @@ -92,6 +92,9 @@ namespace common { private: explicit GestureComponent(common::SystemComponent &systemComponent); + // @brief Disable assignment operator, since we have reference + /// members + GestureComponent &operator=(const GestureComponent &) = delete; void m_parentSet() override; From af47f617ade280a217575984188fbd50be707eda Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Wed, 23 Sep 2015 14:00:41 -0400 Subject: [PATCH 70/73] remove unused timestamp variable --- src/osvr/Common/SystemComponent.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/osvr/Common/SystemComponent.cpp b/src/osvr/Common/SystemComponent.cpp index 999650b0d..86fbd9478 100644 --- a/src/osvr/Common/SystemComponent.cpp +++ b/src/osvr/Common/SystemComponent.cpp @@ -224,7 +224,6 @@ namespace common { messages::RegisteredStringMapRecord::MessageSerialization msg; deserialize(bufReader, msg); auto data = msg.getData(); - auto timestamp = util::time::fromStructTimeval(p.msg_time); for (auto const &cb : self->m_cb_map) { cb(data); From 6a18aad45c4af69d84e3863648ac53a33d0783c7 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 10 Mar 2016 16:19:34 -0500 Subject: [PATCH 71/73] add SystemComponent accessor to AnalysisClientContext --- src/osvr/Client/AnalysisClientContext.cpp | 4 ++++ src/osvr/Client/AnalysisClientContext.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/osvr/Client/AnalysisClientContext.cpp b/src/osvr/Client/AnalysisClientContext.cpp index d4c77bedc..4d979506d 100644 --- a/src/osvr/Client/AnalysisClientContext.cpp +++ b/src/osvr/Client/AnalysisClientContext.cpp @@ -115,5 +115,9 @@ namespace client { common::PathTree const &AnalysisClientContext::m_getPathTree() const { return m_pathTreeOwner.get(); } + + common::SystemComponent *AnalysisClientContext::m_getSystemComponent() { + return m_systemComponent; + } } // namespace client } // namespace osvr diff --git a/src/osvr/Client/AnalysisClientContext.h b/src/osvr/Client/AnalysisClientContext.h index b6b8706b5..aa55bc8db 100644 --- a/src/osvr/Client/AnalysisClientContext.h +++ b/src/osvr/Client/AnalysisClientContext.h @@ -80,6 +80,8 @@ namespace client { } bool m_getStatus() const override; + common::SystemComponent *m_getSystemComponent() override; + /// @brief the vrpn_Connection corresponding to m_host vrpn_ConnectionPtr m_mainConn; From 0d41b05dff59a08025c63af23961633e581eb327 Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 10 Mar 2016 16:20:48 -0500 Subject: [PATCH 72/73] use RemoteHandlerInternals instead of InterfaceList --- src/osvr/Client/GestureRemoteFactory.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/osvr/Client/GestureRemoteFactory.cpp b/src/osvr/Client/GestureRemoteFactory.cpp index 39c31e115..b10ce6f70 100644 --- a/src/osvr/Client/GestureRemoteFactory.cpp +++ b/src/osvr/Client/GestureRemoteFactory.cpp @@ -25,6 +25,7 @@ // Internal Includes #include "GestureRemoteFactory.h" +#include "RemoteHandlerInternals.h" #include "VRPNConnectionCollection.h" #include #include @@ -55,7 +56,7 @@ namespace client { common::InterfaceList &ifaces, common::ClientContext *ctx) : m_dev(common::createClientDevice(deviceName, conn)), - m_interfaces(ifaces), m_all(!sensor.is_initialized()), + m_internals(ifaces), m_all(!sensor.is_initialized()), m_sensor(sensor), m_ctx(ctx) { m_sysComponent = m_ctx->getSystemComponent(); @@ -92,8 +93,8 @@ namespace client { } OSVR_GestureReport report; - util::StringID id = - m_gestureNameMap->corrMap.convertPeerToLocalID(util::PeerStringID(data.gestureID.value())); + util::StringID id = m_gestureNameMap->corrMap.convertPeerToLocalID( + util::PeerStringID(data.gestureID.value())); if (id.empty()) { // could not find a peer to local mapping, discarding report return; @@ -102,13 +103,11 @@ namespace client { report.sensor = data.sensor; report.state = data.gestureState; report.gestureID = id.value(); - for (auto &iface : m_interfaces) { - iface->triggerCallbacks(timestamp, report); - } + m_internals.setStateAndTriggerCallbacks(timestamp, report); } common::BaseDevicePtr m_dev; - common::InterfaceList &m_interfaces; + RemoteHandlerInternals m_internals; bool m_all; boost::optional m_sensor; // map to keep track of gesture map and server to local ID map From 78de9043a4b8ae986e9ddbe4fab66049ee5e9dac Mon Sep 17 00:00:00 2001 From: Georgiy Frolov Date: Thu, 10 Mar 2016 16:22:55 -0500 Subject: [PATCH 73/73] remove duplicate method, use updated path for include --- src/osvr/Client/PureClientContext.cpp | 5 +---- src/osvr/Client/PureClientContext.h | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/osvr/Client/PureClientContext.cpp b/src/osvr/Client/PureClientContext.cpp index 653ec7742..dafc57d2e 100644 --- a/src/osvr/Client/PureClientContext.cpp +++ b/src/osvr/Client/PureClientContext.cpp @@ -209,12 +209,9 @@ namespace client { common::Transform const & PureClientContext::m_getRoomToWorldTransform() const { return m_roomToWorld; - - common::SystemComponent *PureClientContext::m_getSystemComponent() { - return m_systemComponent; } - shared_ptr PureClientContext::m_getSystemComponent() { + common::SystemComponent *PureClientContext::m_getSystemComponent() { return m_systemComponent; } diff --git a/src/osvr/Client/PureClientContext.h b/src/osvr/Client/PureClientContext.h index c437415b6..477a7838d 100644 --- a/src/osvr/Client/PureClientContext.h +++ b/src/osvr/Client/PureClientContext.h @@ -38,7 +38,7 @@ #include #include #include -#include "RemoteHandlerFactory.h" +#include // Library/third-party includes #include @@ -75,7 +75,7 @@ namespace client { common::PathTree const &m_getPathTree() const override; - virtual common::SystemComponent *m_getSystemComponent(); + common::SystemComponent *m_getSystemComponent() override; common::Transform const &m_getRoomToWorldTransform() const override;