This commit is contained in:
Matthias Janetschek
2015-05-21 17:50:39 +02:00
parent 19cb6e5cbe
commit d63423aee9
1309 changed files with 329 additions and 481521 deletions
+10 -6
View File
@@ -5,10 +5,15 @@ project(hos_cpp_utils)
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
hos_libvariant
roscpp
hos_deps
)
message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
find_package(libvariant REQUIRED)
message("libvariant_INCLUDE_DIR: ${libvariant_INCLUDE_DIR}")
message("libvariant_LIBRARY: ${libvariant_LIBRARY}")
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
@@ -81,8 +86,6 @@ find_package(catkin REQUIRED COMPONENTS
catkin_package(
INCLUDE_DIRS include/${PROJECT_NAME}/
LIBRARIES hos_cpp_utils
CATKIN_DEPENDS roscpp
# DEPENDS system_lib
)
###########
@@ -96,16 +99,17 @@ add_definitions(
include_directories(
${catkin_INCLUDE_DIRS}
include
include/hos_libvariant
${libvariant_INCLUDE_DIR}
include/hos_cpp_utils
)
## Declare a cpp library
add_library(hos_cpp_utils STATIC
src/HosSchemaLoader/HosSchemaLoader.cpp
src/hos/utils/SchemaLoader.cpp
)
target_link_libraries(hos_cpp_utils
${catkin_LIBRARIES}
${libvariant_LIBRARY}
)
## Specify additional locations of header files
@@ -0,0 +1,33 @@
#pragma once
#include <Variant/Schema.h>
#include <ros/ros.h>
#include <string>
namespace hos {
namespace utils {
class SchemaLoader: public libvariant::SchemaLoader {
private:
std::string ros_param_ns;
std::string prefix;
ros::NodeHandle nodeHandle;
bool loadTypeSchema(std::string schema);
public:
SchemaLoader(std::string ns = "/hos/types/repository", std::string prefix = "hos:schema://")
: ros_param_ns(ns), prefix(prefix), nodeHandle("~") {}
virtual bool HandleMissing(const std::string &uri, LoaderError &error);
};
} // namespace libvariant
} // namespace hos
+6 -2
View File
@@ -33,7 +33,7 @@
<!-- Examples: -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- <build_depend>message_generation</build_depend>
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use run_depend for packages you need at runtime: -->
@@ -43,7 +43,11 @@
<!-- <test_depend>gtest</test_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<build_depend>hos_libvariant</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>hos_deps</build_depend>
<run_depend>hos_libvariant</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>hos_deps</run_depend>
<!-- The export tag contains other, unspecified, tags -->
@@ -51,4 +55,4 @@
<!-- Other tools can request additional information be placed here -->
</export>
</package>
</package>
@@ -0,0 +1,40 @@
#include <hos/utils/SchemaLoader.h>
namespace hos {
namespace utils {
bool SchemaLoader::HandleMissing(const std::string &uri, LoaderError &error) {
if (uri.compare(0, prefix.size(), prefix) == 0) {
return loadTypeSchema(uri.substr(prefix.size()));
} else {
return SchemaLoader::HandleMissing(uri, error);
}
}
bool SchemaLoader::loadTypeSchema(std::string schema) {
std::string pkey = std::string(ros_param_ns).append("/").append(schema);
std::string pvalue;
nodeHandle.getParam(pkey, pvalue);
if (!pvalue.empty()) {
::libvariant::Variant v = ::libvariant::Deserialize(pvalue, ::libvariant::SERIALIZE_JSON);
if (v.IsMap()) {
std::string sk = std::string(prefix).append(schema);
AddSchema(sk, v);
return true;
} else {
return false;
}
} else {
return false;
}
}
}
}