Conversation
rclcpp/include/rclcpp/time.hpp
Outdated
| Time(const builtin_interfaces::msg::Time & time_msg) // NOLINT | ||
| : rcl_time_(get_empty_time_point()) | ||
| { | ||
| rcl_time_.nanoseconds = RCL_S_TO_NS(time_msg.sec); |
There was a problem hiding this comment.
this overlap the comments in ros2/rcutils#44 but nothing prevents time_msg.sec to be negative here. (same everywhere below)
rclcpp/include/rclcpp/time.hpp
Outdated
| Time(int32_t seconds, uint32_t nanoseconds) | ||
| : rcl_time_(get_empty_time_point()) | ||
| { | ||
| uint64_t ns = RCL_S_TO_NS(static_cast<uint64_t>(seconds)); |
There was a problem hiding this comment.
Doesn't this need to check if seconds is negative?
Same below.
There was a problem hiding this comment.
should be corrected, however I only found one spot, where it was missing. Where's the other one?
There was a problem hiding this comment.
Nvm, all other static_casts have a check like if (seconds < 0) { before.
rclcpp/include/rclcpp/time.hpp
Outdated
| rcl_time_.nanoseconds = nanoseconds; | ||
| } | ||
|
|
||
| Time(const builtin_interfaces::msg::Time & time_msg) // NOLINT |
There was a problem hiding this comment.
Why does this require NOLINT?
There was a problem hiding this comment.
lint wants it to be explicit, however as it's used as a copy constructor it can't be explicit (code won't compile wo/).
2394c80 to
f598ea2
Compare
|
OK, so I think that's up for a final review. Given the underlying c API, I decided to write only one class |
rclcpp/src/rclcpp/time.cpp
Outdated
|
|
||
| if (ret != RCL_RET_OK) { | ||
| rclcpp::exceptions::throw_from_rcl_error( | ||
| ret, "could not initialize time source: "); |
There was a problem hiding this comment.
I think the : is redundant:
rclcpp/rclcpp/src/rclcpp/exceptions.cpp
Lines 59 to 61 in b906768
rclcpp/src/rclcpp/time.cpp
Outdated
| rcl_time_(init_time_point(rcl_time_source_)) | ||
| { | ||
| if (seconds < 0) { | ||
| throw std::runtime_error("can't convert a negative time msg to rclcpp::Time"); |
There was a problem hiding this comment.
I would recommend this message instead, which I think is more to the point:
"cannot store a negative time point in rclcpp::Time"
There was a problem hiding this comment.
Also below in at least one more place.
rclcpp/src/rclcpp/time.cpp
Outdated
| throw std::runtime_error("can't convert a negative time msg to rclcpp::Time"); | ||
| } | ||
|
|
||
| uint64_t ns = RCL_S_TO_NS(static_cast<uint64_t>(seconds)); |
There was a problem hiding this comment.
nitpick: you could assign this directly into rcl_time_.nanoseconds which is also a uint64_t.
| Time::operator==(const rclcpp::Time & rhs) const | ||
| { | ||
| if (rcl_time_.time_source->type != rhs.rcl_time_.time_source->type) { | ||
| throw std::runtime_error("can't compare times with different time sources"); |
There was a problem hiding this comment.
I think we need to have a better overview of how this class should work. For example, I think that the fact that you cannot compare two Time objects with different sources is a runtime error is very inconvenient. Ideally it would be a compiler error when you try to compare a "system based" time point and a "steady based" time point. This pattern makes more sense when you're abstracting "system based" time point from "ROS based" time point because they have the same reference point. We might need to rethink the way it is setup in rcl as well to reflect this.
There was a problem hiding this comment.
Agreed. I don't know if there should be three different time classes around. Open for opinions. I just basically need the default time class (and their operators) as for now.
rclcpp/src/rclcpp/time.cpp
Outdated
|
|
||
| auto ns = rcl_time_.nanoseconds + rhs.rcl_time_.nanoseconds; | ||
| if (ns < rcl_time_.nanoseconds) { | ||
| throw std::runtime_error("addition leads to uint64_t overflow"); |
There was a problem hiding this comment.
Probably http://en.cppreference.com/w/cpp/error/overflow_error instead of runtime.
rclcpp/src/rclcpp/time.cpp
Outdated
|
|
||
| auto ns = rcl_time_.nanoseconds - rhs.rcl_time_.nanoseconds; | ||
| if (ns > rcl_time_.nanoseconds) { | ||
| throw std::runtime_error("subtraction leads to uint64_t underflow"); |
There was a problem hiding this comment.
rclcpp/test/test_time.cpp
Outdated
| FAIL(); | ||
| } catch (const std::exception &) { | ||
| SUCCEED(); | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
woooaaaah, that's so cool that you can actually put a complete block of code in it. thanks for that. didn't know it :)
There was a problem hiding this comment.
If the invoked code is supposed to raise a specific exception I would suggest to use EXPECT_THROW rather than EXPECT_ANY_THROW.
wjwwood
left a comment
There was a problem hiding this comment.
+1, my comments were addressed to my satisfaction (though there were some things pointed out in the meeting that I missed)
|
typo 2: 2c33365 |
|
@Karsten1987 these tests are failing on windows debug nightlies: http://ci.ros2.org/job/nightly_win_deb/568/testReport/junit/(root)/TestTime/operators/ |
…ation_tests_against_rmw_implementations Enable test_action_communication to compile against available rmw
connects to #352