Skip to content

Commit

Permalink
Make it work by checking the type of the stamp field.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
clalancette committed Sep 24, 2022
1 parent 5140e0b commit ca5cd77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rcl REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rosidl_default_generators REQUIRED)
Expand All @@ -47,6 +48,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")

ament_target_dependencies(${PROJECT_NAME}
"builtin_interfaces"
"rcl"
"rcpputils"
"statistics_msgs"
Expand All @@ -66,7 +68,7 @@ ament_export_libraries(${PROJECT_NAME})
# Export modern CMake targets
ament_export_targets(${PROJECT_NAME})

ament_export_dependencies("rcl" "rcpputils" "rosidl_default_runtime" "statistics_msgs")
ament_export_dependencies("builtin_interfaces" "rcl" "rcpputils" "rosidl_default_runtime" "statistics_msgs")

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "libstatistics_collector/topic_statistics_collector/topic_statistics_collector.hpp"

#include "builtin_interfaces/msg/time.hpp"
#include "rcl/time.h"
#include "rcutils/logging_macros.h"

Expand All @@ -34,18 +35,20 @@ namespace topic_statistics_collector
{

/**
* True if the message has a header with a subfield stamp
* False if the message does not have a header
* @tparam M
*/
template<typename M, typename D = decltype(M().header.stamp)>
struct HasHeader : public std::true_type {};
template<typename M, typename = void>
struct HasHeader : public std::false_type {};

/**
* False if the message does not have a header
* True if the message has a field named 'header' with a subfield named 'stamp' of
* type builtin_interfaces::msg::Time
* @tparam M
*/
template<typename M>
struct HasHeader<M, void>: public std::false_type {};
struct HasHeader<M, typename std::enable_if<std::is_same<builtin_interfaces::msg::Time,
decltype(M().header.stamp)>::value>::type>: public std::true_type {};

/**
* Return a boolean flag indicating the timestamp is not set
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<build_depend>rosidl_default_generators</build_depend>

<depend>builtin_interfaces</depend>
<depend>rcl</depend>
<depend>rcpputils</depend>
<depend>statistics_msgs</depend>
Expand Down

0 comments on commit ca5cd77

Please sign in to comment.