Skip to content

Commit

Permalink
[YAML Parser] Support parameter value parsing (ros2#471)
Browse files Browse the repository at this point in the history
* Support parameter YAML string value parsing.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Address peer review comments.

- Improve test coverage using new getter API.
- Unify function return style and improve readability.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Clean up allocations in rcl_yaml_param_parser package tests.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Jul 12, 2019
1 parent f9ceef5 commit 5fde9c0
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 134 deletions.
3 changes: 3 additions & 0 deletions rcl_yaml_param_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ install(TARGETS ${PROJECT_NAME}
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
find_package(osrf_testing_tools_cpp REQUIRED)
ament_lint_auto_find_test_dependencies()

# Gtests
Expand All @@ -57,6 +58,8 @@ if(BUILD_TESTING)
)
if(TARGET test_parse_yaml)
target_link_libraries(test_parse_yaml ${PROJECT_NAME})
target_include_directories(test_parse_yaml
PRIVATE ${osrf_testing_tools_cpp_INCLUDE_DIRS})
endif()

endif()
Expand Down
33 changes: 29 additions & 4 deletions rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,53 @@ extern "C"
{
#endif

/// \brief Init param structure
/// \brief Initialize parameter structure
/// \param[in] allocator memory allocator to be used
/// \return a pointer to param structure on success or NULL on failure
RCL_YAML_PARAM_PARSER_PUBLIC
rcl_params_t * rcl_yaml_node_struct_init(
const rcutils_allocator_t allocator);

/// \brief Free param structure
/// \param[in] params_st points to the populated paramter struct
/// \brief Free parameter structure
/// \param[in] params_st points to the populated parameter struct
RCL_YAML_PARAM_PARSER_PUBLIC
void rcl_yaml_node_struct_fini(
rcl_params_t * params_st);

/// \brief Parse the YAML file, initialize and populate params_st
/// \param[in] file_path is the path to the YAML file
/// \param[inout] params_st points to the populated paramter struct
/// \param[inout] params_st points to the populated parameter struct
/// \return true on success and false on failure
RCL_YAML_PARAM_PARSER_PUBLIC
bool rcl_parse_yaml_file(
const char * file_path,
rcl_params_t * params_st);

/// \brief Parse a parameter value as a YAML string, updating params_st accordingly
/// \param[in] node_name is the name of the node to which the parameter belongs
/// \param[in] param_name is the name of the parameter whose value will be parsed
/// \param[in] yaml_value is the parameter value as a YAML string to be parsed
/// \param[inout] params_st points to the parameter struct
/// \return true on success and false on failure
RCL_YAML_PARAM_PARSER_PUBLIC
bool rcl_parse_yaml_value(
const char * node_name,
const char * param_name,
const char * yaml_value,
rcl_params_t * params_st);

/// \brief Get the variant value for a given parameter, zero initializing it in the
/// process if not present already
/// \param[in] node_name is the name of the node to which the parameter belongs
/// \param[in] param_name is the name of the parameter whose value is to be retrieved
/// \param[inout] params_st points to the populated (or to be populated) parameter struct
/// \return parameter variant value on success and NULL on failure
RCL_YAML_PARAM_PARSER_PUBLIC
rcl_variant_t * rcl_yaml_node_struct_get(
const char * node_name,
const char * param_name,
rcl_params_t * params_st);

/// \brief Print the parameter structure to stdout
/// \param[in] params_st points to the populated parameter struct
RCL_YAML_PARAM_PARSER_PUBLIC
Expand Down
1 change: 1 addition & 0 deletions rcl_yaml_param_parser/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>osrf_testing_tools_cpp</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
Loading

0 comments on commit 5fde9c0

Please sign in to comment.