Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gesture interface merge #181

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
9719499
add gesture component
gfrolov Jul 20, 2015
c7a1fd5
update cmake build for common (include gesture and registeredstringmap)
gfrolov Jul 20, 2015
e60a4c0
changes to device component
gfrolov Jul 20, 2015
48f2c7c
add definitions for gesture report, state, and pre-defined set
gfrolov Jul 20, 2015
fc912f7
add gesture interface definition to pluginkit
gfrolov Jul 20, 2015
661830c
update plugin kit cmake build
gfrolov Jul 20, 2015
ccc8f3a
add client callback method definitions for gesture report
gfrolov Jul 20, 2015
ee9e34f
add defns for gesture report type
gfrolov Jul 20, 2015
27b9e08
add client side gesture remote factory
gfrolov Jul 20, 2015
893d818
update cmake build for client/
gfrolov Jul 20, 2015
2dd88cf
add a sample gesture plugin
gfrolov Jul 20, 2015
53ae6ca
add osvr server config for sample gesture plugin
gfrolov Jul 20, 2015
d5f50ee
add a sample gesture client app
gfrolov Jul 20, 2015
97ef4fd
simplify reading from buffer
gfrolov Jul 20, 2015
e004f57
revert to using m_parentSet instead of overriding recordParent
gfrolov Jul 20, 2015
17f77ac
fix a couple typos
gfrolov Jul 20, 2015
275d288
fix class name, a typo
gfrolov Jul 21, 2015
b6fe7a2
update gesture interface to send gesture ID
gfrolov Jul 30, 2015
885f3ce
send gesture data with ID instead of string in component
gfrolov Jul 30, 2015
e537a97
change gesture report to use ID instead of string
gfrolov Jul 30, 2015
2f38f83
update report field for callback
gfrolov Jul 30, 2015
e3fe871
change sample gesture plugin to use updated pluginkit api
gfrolov Jul 30, 2015
83e37b4
move the handling of registeredstringmap to systemcomponent to keep o…
gfrolov Aug 10, 2015
31ee758
add accessor for system component to client context. this will allow …
gfrolov Aug 10, 2015
2923bbf
move RegisteredStringMap out of gesture component
gfrolov Aug 10, 2015
e71c6fc
move RegisteredStringMap out of remote factory and use system compone…
gfrolov Aug 10, 2015
4ac55ec
add accessor to parent (RegistrationContext)
gfrolov Aug 10, 2015
dafdf8d
add ClientKit methods to convert ID to string from RegisteredStringMap
gfrolov Aug 10, 2015
6acdcfd
add accessor for SystemComponent
gfrolov Aug 10, 2015
31607bc
move ID out of RegisteredStringMap to a separate place
gfrolov Aug 10, 2015
cfe1ff7
remove unnecessary destructor, change pointer type, and minor correct…
gfrolov Aug 11, 2015
1fcbf16
add getter/setter to SystemComponent to let gesture(and other compone…
gfrolov Aug 11, 2015
d178815
use deviceInitOpts to give SystemComponent ptr to GestureComponent, r…
gfrolov Aug 11, 2015
886b506
minor changes to sample gesture plugin
gfrolov Aug 11, 2015
c44d480
use raw ptr instead of shared one in ClientContext
gfrolov Aug 11, 2015
1408746
missed clang format on these
gfrolov Aug 11, 2015
d31ca38
use regular ptr instead of the shared
gfrolov Aug 11, 2015
c71e467
set SystemComponent for RegistrationContext
gfrolov Aug 11, 2015
f958d27
print gesture name in the client app
gfrolov Aug 11, 2015
2577b38
remove unnecessary includes
gfrolov Aug 11, 2015
e8583b0
minor cleanup of unused stuff
gfrolov Sep 2, 2015
1d4524e
changes to the typesafe ID class
gfrolov Sep 2, 2015
0e6831b
remove unused ClientInterfacePtr
gfrolov Sep 2, 2015
630994a
update includes for gesture remote factory
gfrolov Sep 4, 2015
1652bd3
add accessor for sys component to joint client context
gfrolov Sep 4, 2015
7403fd6
misc comment updates
gfrolov Sep 4, 2015
83a61c3
add gesture remote factory to remote handler
gfrolov Sep 4, 2015
14825b0
clang-format
rpavlik Sep 15, 2015
39b99e5
Move and fix the sample config for a gesture server.
rpavlik Sep 15, 2015
31014b7
Fix usage error in ClientReportTypes
rpavlik Sep 15, 2015
9303d20
Fix GestureInterfaceC.h annotations, parameters, and doc.
rpavlik Sep 15, 2015
f8e19d6
Substantial simplification of the gesture example
rpavlik Sep 15, 2015
db4a545
Gesture clientkit method name changes and some doc cleanups
rpavlik Sep 15, 2015
c0aa2ed
Fix configuring of pluginhost - can't put jsoncpp as a public lib.
rpavlik Sep 16, 2015
ac6218b
Substantially overhaul the type-safe ID template.
rpavlik Sep 16, 2015
2909103
Work on fixing StringID usages.
rpavlik Sep 16, 2015
832efd5
Fix build
rpavlik Sep 17, 2015
6501182
Use the StringBufferBuilder in ClientKit.
rpavlik Sep 17, 2015
b0af05d
Work on registered string map
rpavlik Sep 17, 2015
8f86845
Some generation of gesture-related files.
rpavlik Sep 21, 2015
de03a08
Use generated gesture define header.
rpavlik Sep 21, 2015
685bdf9
Gesture and System component changes.
rpavlik Sep 21, 2015
e994a6d
Add missing file.
rpavlik Sep 21, 2015
a0c1d2d
remove unused timestamp param and use updated function names
gfrolov Sep 23, 2015
152d6f2
use updated function names
gfrolov Sep 23, 2015
58e1746
minor gesture sample plugin update
gfrolov Sep 23, 2015
943f656
use updated function names
gfrolov Sep 23, 2015
08330f3
use sysComponent reference for GestureComponent constructor
gfrolov Sep 23, 2015
508c7ac
disable assignment operator due to reference members which generates …
gfrolov Sep 23, 2015
af47f61
remove unused timestamp variable
gfrolov Sep 23, 2015
6a18aad
add SystemComponent accessor to AnalysisClientContext
Mar 10, 2016
0d41b05
use RemoteHandlerInternals instead of InterfaceList
Mar 10, 2016
78de904
remove duplicate method, use updated path for include
Mar 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/sample-configs/osvr_server_config.gesture.sample.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions examples/clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(CLIENTS
Location2D
Direction
Locomotion
Gesture
MinimalInit
TrackerState
ViewerEyeSurfaces)
Expand Down
71 changes: 71 additions & 0 deletions examples/clients/Gesture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/** @file
@brief Implementation

@date 2015

@author
Sensics, Inc.
<http://sensics.com/osvr>

*/

// 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 <osvr/ClientKit/Context.h>
#include <osvr/ClientKit/Interface.h>
#include <osvr/Util/ClientReportTypesC.h>
#include <osvr/Util/StringIds.h>

// Library/third-party includes
// - none

// Standard includes
#include <iostream>
#include <string>

void gestureCallback(void *userdata, const OSVR_TimeValue * /*timestamp*/,
const OSVR_GestureReport *report) {
auto &ctx = *static_cast<osvr::clientkit::ClientContext *>(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.getGestureNamefromID(osvr::util::StringID(report->gestureID));
std::cout << "Gesture: Sensor " << report->sensor << ": ID "
<< report->gestureID << " (" << name << ") "
<< (report->state == OSVR_GESTURE_COMPLETE ? "COMPLETE"
: "IN PROGRESS")
<< std::endl;
}

int main() {

osvr::clientkit::ClientContext ctx(
"com.osvr.exampleclients.GestureCallback");

osvr::clientkit::Interface gesture =
ctx.getInterface("/com_osvr_example_Gesture/Gesture/gesture");

gesture.registerCallback(&gestureCallback, &ctx);

// Pretend that this is your application's mainloop.
while (1) {
ctx.update();
}

std::cout << "Library shut down, exiting." << std::endl;
return 0;
}
2 changes: 2 additions & 0 deletions examples/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
125 changes: 125 additions & 0 deletions examples/plugin/com_osvr_example_Gesture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/** @date 2015

@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// 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 <osvr/PluginKit/PluginKit.h>
#include <osvr/PluginKit/GestureInterfaceC.h>

// Generated JSON header file
#include "com_osvr_example_Gesture_json.h"

// Library/third-party includes

// Standard includes
#include <iostream>
#include <memory>
#include <ctime>
#include <chrono>
#include <thread>

// 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);

/// 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, "LASSO", &m_lasso_gesture);

/// Send JSON descriptor
m_dev.sendJsonDescriptor(com_osvr_example_Gesture_json);

/// Register update callback
m_dev.registerUpdateCallback(this);
}

OSVR_ReturnCode update() {

std::this_thread::sleep_for(std::chrono::milliseconds(
1000)); // Simulate waiting a quarter second for data.

OSVR_TimeValue times;

osvrTimeValueGetNow(&times);

osvrDeviceGestureReportData(m_gesture, m_double_tap_gesture,
OSVR_GESTURE_COMPLETE, 0, &times);
osvrDeviceGestureReportData(m_gesture, m_lasso_gesture,
OSVR_GESTURE_COMPLETE, 1, &times);

return OSVR_RETURN_SUCCESS;
}

private:
osvr::pluginkit::DeviceToken m_dev;
OSVR_GestureDeviceInterface m_gesture;
OSVR_GestureID m_lasso_gesture;
OSVR_GestureID m_double_tap_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;
}
20 changes: 20 additions & 0 deletions examples/plugin/com_osvr_example_Gesture.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
25 changes: 25 additions & 0 deletions inc/osvr/ClientKit/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ namespace clientkit {
return osvrClientCheckStatus(m_context) == OSVR_RETURN_SUCCESS;
}

inline std::string ClientContext::getGestureNamefromID(util::StringID id) {

size_t length = 0;
OSVR_ReturnCode ret =
osvrClientGetGestureNameLength(m_context, id.value(), &length);
if (OSVR_RETURN_SUCCESS != ret) {
throw std::runtime_error(
"Invalid context or null reference to length variable.");
}

if (0 == length) {
return std::string();
}

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 buf.str();
}

} // end namespace clientkit

} // end namespace osvr
Expand Down
15 changes: 6 additions & 9 deletions inc/osvr/ClientKit/Context_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <osvr/ClientKit/ContextC.h>
#include <osvr/Util/StringIds.h>

// Library/third-party includes
#include <boost/noncopyable.hpp>
Expand Down Expand Up @@ -95,6 +87,11 @@ 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();

Expand Down
25 changes: 24 additions & 1 deletion inc/osvr/ClientKit/InterfaceC.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* none */

/* Standard includes */
/* none */
#include <stdint.h>

OSVR_EXTERN_C_BEGIN
/** @addtogroup ClientKit
Expand Down Expand Up @@ -69,6 +69,29 @@ 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 osvrClientGetGestureNameLength(
OSVR_ClientContext ctx, uint32_t id, size_t *len);

/** @brief Convert the gesture ID to string name representation

@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 osvrClientGetGestureNameFromID(
OSVR_ClientContext ctx, uint32_t id, char *buf, size_t len);

/** @} */
OSVR_EXTERN_C_END

Expand Down
1 change: 1 addition & 0 deletions inc/osvr/ClientKit/InterfaceCallbackC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions inc/osvr/ClientKit/InterfaceStateC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading