blob: 13d75c5c1e723df9c58a715267ea4bb8bc89e40b [file] [log] [blame]
#ifndef AOS_EVENTS_MESSAGE_COUNTER_H_
#define AOS_EVENTS_MESSAGE_COUNTER_H_
#include "aos/events/event_loop.h"
namespace aos::testing {
// Simple class to count messages on a channel easily. This only counts
// messages published while running.
template <typename T>
class MessageCounter {
public:
MessageCounter(aos::EventLoop *event_loop, std::string_view name) {
event_loop->MakeNoArgWatcher<T>(name, [this]() { ++count_; });
}
// Returns the number of messages seen so far.
size_t count() const { return count_; }
private:
size_t count_ = 0;
};
} // namespace aos::testing
#endif // AOS_EVENTS_MESSAGE_COUNTER_H_