15 #ifndef LIBSTATISTICS_COLLECTOR__TOPIC_STATISTICS_COLLECTOR__RECEIVED_MESSAGE_PERIOD_HPP_
16 #define LIBSTATISTICS_COLLECTOR__TOPIC_STATISTICS_COLLECTOR__RECEIVED_MESSAGE_PERIOD_HPP_
22 #include "constants.hpp"
23 #include "libstatistics_collector/topic_statistics_collector/topic_statistics_collector.hpp"
27 namespace libstatistics_collector
29 namespace topic_statistics_collector
32 constexpr
const int64_t kUninitializedTime{0};
50 ResetTimeLastMessageReceived();
62 void OnMessageReceived(
const T & received_message,
const rcl_time_point_value_t now_nanoseconds)
63 override RCPPUTILS_TSA_REQUIRES(mutex_)
65 std::unique_lock<std::mutex> ulock{mutex_};
67 (void) received_message;
69 if (time_last_message_received_ == kUninitializedTime) {
70 time_last_message_received_ = now_nanoseconds;
72 const std::chrono::nanoseconds nanos{now_nanoseconds - time_last_message_received_};
73 const auto period = std::chrono::duration<double, std::milli>(nanos);
74 time_last_message_received_ = now_nanoseconds;
86 return topic_statistics_constants::kMsgPeriodStatName;
96 return topic_statistics_constants::kMillisecondUnitName;
106 ResetTimeLastMessageReceived();
119 void ResetTimeLastMessageReceived()
121 time_last_message_received_ = kUninitializedTime;
127 rcl_time_point_value_t time_last_message_received_ RCPPUTILS_TSA_GUARDED_BY(mutex_) =
129 mutable std::mutex mutex_;
135 #endif // LIBSTATISTICS_COLLECTOR__TOPIC_STATISTICS_COLLECTOR__RECEIVED_MESSAGE_PERIOD_HPP_