Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 1 | #include <chrono> |
| 2 | |
| 3 | #include "aos/configuration.h" |
| 4 | #include "aos/events/pingpong_generated.h" |
| 5 | #include "aos/events/shm_event_loop.h" |
| 6 | #include "aos/init.h" |
| 7 | #include "aos/json_to_flatbuffer.h" |
| 8 | #include "gflags/gflags.h" |
| 9 | #include "glog/logging.h" |
| 10 | |
| 11 | namespace aos { |
| 12 | |
| 13 | namespace chrono = std::chrono; |
| 14 | |
| 15 | class Pong { |
| 16 | public: |
| 17 | Pong(EventLoop *event_loop) |
| 18 | : event_loop_(event_loop), |
| 19 | sender_(event_loop_->MakeSender<examples::Pong>("/test")) { |
| 20 | event_loop_->MakeWatcher("/test", [this](const examples::Ping &ping) { |
| 21 | aos::Sender<examples::Pong>::Builder msg = sender_.MakeBuilder(); |
| 22 | examples::Pong::Builder builder = msg.MakeBuilder<examples::Pong>(); |
| 23 | builder.add_value(ping.value()); |
| 24 | builder.add_initial_send_time(ping.send_time()); |
| 25 | CHECK(msg.Send(builder.Finish())); |
| 26 | }); |
| 27 | |
| 28 | event_loop_->SetRuntimeRealtimePriority(5); |
| 29 | } |
| 30 | |
| 31 | private: |
| 32 | EventLoop *event_loop_; |
| 33 | aos::Sender<examples::Pong> sender_; |
| 34 | }; |
| 35 | |
| 36 | } // namespace aos |
| 37 | |
| 38 | int main(int argc, char **argv) { |
| 39 | FLAGS_logtostderr = true; |
| 40 | google::InitGoogleLogging(argv[0]); |
| 41 | ::gflags::ParseCommandLineFlags(&argc, &argv, true); |
| 42 | |
| 43 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 44 | aos::configuration::ReadConfig("aos/events/config.fb.json"); |
| 45 | |
| 46 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 47 | |
| 48 | aos::Pong ping(&event_loop); |
| 49 | |
| 50 | event_loop.Run(); |
| 51 | |
| 52 | ::aos::Cleanup(); |
| 53 | return 0; |
| 54 | } |