Skip to content

Commit

Permalink
Make use of a lambda function instead of a method for log
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Ezequiel Marchi <brian.marchi65@gmail.com>
  • Loading branch information
BMarchi committed Oct 15, 2019
1 parent 654505e commit 5343f2c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
10 changes: 0 additions & 10 deletions rclcpp/include/rclcpp/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,6 @@ class Clock
JumpHandler::post_callback_t post_callback,
const rcl_jump_threshold_t & threshold);

/// Get current time from the time source specified by Clock::get_clock_type() const noexcept.
/**
* \param now A pointer to time point value, which will be
* set to the current time according to the underlying clock.
* \return RCUTILS_RET_OK if time was successfully retrieved
*/
RCLCPP_PUBLIC
rcutils_ret_t
get_now_as_rcutils_time_point(rcutils_time_point_value_t * now);

private:
// Invoke time jump callback
RCLCPP_PUBLIC
Expand Down
8 changes: 7 additions & 1 deletion rclcpp/resource/logging.hpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ def is_supported_feature_combination(feature_combination):
::std::is_same<typename std::remove_cv<typename std::remove_reference<decltype(logger)>::type>::type, \
typename ::rclcpp::Logger>::value, \
"First argument to logging macros must be an rclcpp::Logger"); \
@[ if 'throttle' in feature_combination]@ \
std::function<rcutils_ret_t (rcutils_time_point_value_t *)> get_time_point = [&clock](rcutils_time_point_value_t * time_point) -> rcutils_ret_t { \
*time_point = clock.now().nanoseconds(); \
return RCUTILS_RET_OK; \
}; \
@[ end if] \
RCUTILS_LOG_@(severity)@(suffix)_NAMED( \
@{params = ['clock.get_now_as_rcutils_time_point' if p == 'clock' and 'throttle' in feature_combination else p for p in params]}@
@{params = ['get_time_point' if p == 'clock' and 'throttle' in feature_combination else p for p in params]}@
@[ if params]@
@(''.join([' ' + p + ', \\\n' for p in params]))@
@[ end if]@
Expand Down
9 changes: 1 addition & 8 deletions rclcpp/src/rclcpp/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Clock::now()
{
Time now(0, 0, rcl_clock_.type);

auto ret = get_now_as_rcutils_time_point(&now.rcl_time_.nanoseconds);
auto ret = rcl_clock_get_now(&rcl_clock_, &now.rcl_time_.nanoseconds);
if (ret != RCL_RET_OK) {
exceptions::throw_from_rcl_error(ret, "could not get current time stamp");
}
Expand Down Expand Up @@ -141,11 +141,4 @@ Clock::create_jump_callback(
// *INDENT-ON*
}

rcutils_ret_t
Clock::get_now_as_rcutils_time_point(
rcutils_time_point_value_t * now)
{
return rcl_clock_get_now(&rcl_clock_, now);
}

} // namespace rclcpp

0 comments on commit 5343f2c

Please sign in to comment.