27 #include <boost/type_traits/remove_cv.hpp>
34 #include <json/value.h>
35 #include <json/reader.h>
36 #include <boost/noncopyable.hpp>
37 #include <boost/variant/get.hpp>
38 #include <boost/algorithm/string/predicate.hpp>
39 #include <boost/algorithm/string/erase.hpp>
40 #include <boost/algorithm/string.hpp>
47 static const char INTERFACES_KEY[] =
"interfaces";
48 static const char EYETRACKER_KEY[] =
"eyetracker";
49 static const char LOCATION2D_KEY[] =
"location2D";
50 static const char DIRECTION_KEY[] =
"direction";
51 static const char TRACKER_KEY[] =
"tracker";
52 static const char BUTTON_KEY[] =
"button";
53 static const char COUNT_KEY[] =
"count";
54 static const char POSITION_KEY[] =
"position";
55 static const char ORIENTATION_KEY[] =
"orientation";
56 static const char BOUNDED_KEY[] =
"bounded";
64 Json::Value &newIface,
65 std::string
const &
detail) {}
69 Json::Value &currInterface) {
71 for (
auto &
detail : currInterface.getMemberNames()) {
72 Json::Value
const &obj = augInterface[
detail];
86 std::string
const &ifaceName) {
89 Json::Value
const &iface = descriptor[INTERFACES_KEY][ifaceName];
92 int count = descriptor[INTERFACES_KEY][ifaceName][COUNT_KEY].asInt();
99 Json::Value augInterfaces(Json::objectValue);
101 for (
auto &subIface : iface.getMemberNames()) {
104 descriptor[INTERFACES_KEY][ifaceName][subIface].asBool();
108 if (boost::iequals(subIface, LOCATION2D_KEY)) {
109 augInterfaces[LOCATION2D_KEY][COUNT_KEY] = count;
110 }
else if (boost::iequals(subIface, DIRECTION_KEY)) {
111 augInterfaces[DIRECTION_KEY][COUNT_KEY] = count;
112 }
else if (boost::iequals(subIface, TRACKER_KEY)) {
114 augInterfaces[TRACKER_KEY][POSITION_KEY] =
true;
115 augInterfaces[TRACKER_KEY][ORIENTATION_KEY] =
false;
116 augInterfaces[TRACKER_KEY][BOUNDED_KEY] =
true;
117 augInterfaces[TRACKER_KEY][COUNT_KEY] = count;
118 }
else if (boost::iequals(subIface, BUTTON_KEY)) {
119 augInterfaces[BUTTON_KEY][COUNT_KEY] = count;
126 if (augInterfaces.size() > 0) {
127 Json::Value &currInterfaces = descriptor[INTERFACES_KEY];
130 descriptor[INTERFACES_KEY] = augInterfaces;
138 Json::Value descriptor;
141 if (!reader.parse(jsonDescriptor, descriptor)) {
144 return jsonDescriptor;
148 if (!descriptor.isMember(INTERFACES_KEY)) {
149 return jsonDescriptor;
152 Json::Value
const &ifaceNames = descriptor[INTERFACES_KEY];
155 if (!ifaceNames.isObject()) {
156 return jsonDescriptor;
159 for (
auto const &ifaceName : ifaceNames.getMemberNames()) {
161 if (boost::iequals(ifaceName, EYETRACKER_KEY)) {
163 }
else if (boost::iequals(ifaceName, TRACKER_KEY)) {
170 const std::string normalizedDescriptor = descriptor.toStyledString();
171 return normalizedDescriptor;
std::string normalizeDeviceDescriptor(std::string const &jsonDescriptor)
"Normalizes" a device descriptor by parsing it and adding implied interfaces to the existing device d...
void normalizeForEyeTracker(Json::Value &descriptor, std::string const &ifaceName)
For eyetracker, it will add the following interfaces to the descriptor provided that they are set to ...
void mergeIdenticalInterfaces(Json::Value &existingIface, Json::Value &newIface, std::string const &detail)
void appendCurrentIface(Json::Value &augInterface, Json::Value &currInterface)
appends json value for a given string