Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 1 | #include "absl/flags/flag.h" |
| 2 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 3 | #include "aos/events/shm_event_loop.h" |
| 4 | #include "aos/init.h" |
Sarah Newman | 45a64df | 2022-04-11 19:33:46 -0700 | [diff] [blame] | 5 | #include "aos/logging/dynamic_logging.h" |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 6 | #include "aos/network/message_bridge_client_lib.h" |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame] | 7 | #include "aos/network/sctp_lib.h" |
Austin Schuh | b0e439d | 2023-05-15 10:55:40 -0700 | [diff] [blame] | 8 | #include "aos/sha256.h" |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame] | 9 | #include "aos/util/file.h" |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 10 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 11 | ABSL_FLAG(std::string, config, "aos_config.json", "Path to the config."); |
| 12 | ABSL_FLAG(int32_t, rt_priority, -1, "If > 0, run as this RT priority"); |
| 13 | ABSL_FLAG(bool, wants_sctp_authentication, false, |
| 14 | "When set, try to use SCTP authentication if provided by the kernel"); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 15 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 16 | namespace aos::message_bridge { |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 17 | |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame] | 18 | using ::aos::util::ReadFileToVecOrDie; |
| 19 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 20 | int Main() { |
| 21 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 22 | aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config)); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 23 | |
| 24 | aos::ShmEventLoop event_loop(&config.message()); |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 25 | if (absl::GetFlag(FLAGS_rt_priority) > 0) { |
| 26 | event_loop.SetRuntimeRealtimePriority(absl::GetFlag(FLAGS_rt_priority)); |
Austin Schuh | a922ad0 | 2021-10-23 23:25:50 -0700 | [diff] [blame] | 27 | } |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 28 | |
Adam Snaider | dd847fd | 2023-06-26 16:34:15 -0700 | [diff] [blame] | 29 | MessageBridgeClient app(&event_loop, Sha256(config.span()), |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame^] | 30 | absl::GetFlag(FLAGS_wants_sctp_authentication) |
Adam Snaider | dd847fd | 2023-06-26 16:34:15 -0700 | [diff] [blame] | 31 | ? SctpAuthMethod::kAuth |
| 32 | : SctpAuthMethod::kNoAuth); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 33 | |
Sarah Newman | 45a64df | 2022-04-11 19:33:46 -0700 | [diff] [blame] | 34 | logging::DynamicLogging dynamic_logging(&event_loop); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 35 | // TODO(austin): Save messages into a vector to be logged. One file per |
| 36 | // channel? Need to sort out ordering. |
| 37 | // |
| 38 | // TODO(austin): Low priority, "reliable" logging channel. |
| 39 | |
| 40 | event_loop.Run(); |
| 41 | |
| 42 | return EXIT_SUCCESS; |
| 43 | } |
| 44 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 45 | } // namespace aos::message_bridge |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 46 | |
| 47 | int main(int argc, char **argv) { |
| 48 | aos::InitGoogle(&argc, &argv); |
| 49 | |
| 50 | return aos::message_bridge::Main(); |
| 51 | } |