Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame] | 1 | #ifndef AOS_EVENTS_PONG_LIB_H_ |
| 2 | #define AOS_EVENTS_PONG_LIB_H_ |
| 3 | |
| 4 | #include "aos/events/event_loop.h" |
James Kuszmaul | 6f255b2 | 2023-11-06 13:46:54 -0800 | [diff] [blame] | 5 | #include "aos/events/ping_static.h" |
| 6 | #include "aos/events/pong_static.h" |
Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame] | 7 | |
| 8 | namespace aos { |
| 9 | |
| 10 | // Class which replies to a Ping message with a Pong message immediately. |
| 11 | class Pong { |
| 12 | public: |
| 13 | Pong(EventLoop *event_loop); |
| 14 | |
Austin Schuh | 9b1d628 | 2022-06-10 17:03:21 -0700 | [diff] [blame] | 15 | void set_quiet(bool quiet) { quiet_ = quiet; } |
| 16 | |
Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame] | 17 | private: |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 18 | void HandlePing(const examples::Ping &ping); |
Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame] | 19 | EventLoop *event_loop_; |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 20 | aos::Fetcher<examples::Ping> fetcher_; |
James Kuszmaul | 6f255b2 | 2023-11-06 13:46:54 -0800 | [diff] [blame] | 21 | aos::Sender<examples::PongStatic> sender_; |
Sarah Newman | 2f98cf0 | 2022-04-01 16:42:00 -0700 | [diff] [blame] | 22 | int32_t last_value_ = 0; |
| 23 | int32_t last_send_time_ = 0; |
Austin Schuh | 9b1d628 | 2022-06-10 17:03:21 -0700 | [diff] [blame] | 24 | |
| 25 | bool quiet_ = true; |
Austin Schuh | 6b9c415 | 2019-11-29 12:45:24 -0800 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | } // namespace aos |
| 29 | |
| 30 | #endif // AOS_EVENTS_PONG_LIB_H_ |