Turn Rust's ping/pong into libraries
We do this to add a pingpong_test.rs in the future that
uses the libraries.
Change-Id: Iab879ea06d40c2ef706f39d23e9b144aa266e0a5
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/pong.rs b/aos/events/pong.rs
index 34da238..833cba2 100644
--- a/aos/events/pong.rs
+++ b/aos/events/pong.rs
@@ -1,13 +1,10 @@
use aos_configuration as config;
-use aos_events_event_loop_runtime::{EventLoopRuntime, Sender, Watcher};
use aos_events_shm_event_loop::ShmEventLoop;
use aos_init::WithCppFlags;
use clap::Parser;
-use futures::never::Never;
-use std::{borrow::Borrow, path::Path};
+use std::path::Path;
-use ping_rust_fbs::aos::examples as ping;
-use pong_rust_fbs::aos::examples as pong;
+use pong_lib::pong;
/// Pong portion of a ping/pong system.
#[derive(Parser, Debug)]
@@ -24,25 +21,3 @@
runtime.spawn(task);
});
}
-
-/// Responds to ping messages with an equivalent pong.
-async fn pong(event_loop: EventLoopRuntime<'_>) -> Never {
- // The watcher gives us incoming ping messages.
- let mut ping_watcher: Watcher<ping::Ping> = event_loop.make_watcher("/test").unwrap();
-
- // The sender is used to send messages back to the pong channel.
- let mut pong_sender: Sender<pong::Pong> = event_loop.make_sender("/test").unwrap();
-
- let on_run = event_loop.on_run();
- on_run.borrow().await;
- loop {
- let ping = dbg!(ping_watcher.next().await);
-
- let mut builder = pong_sender.make_builder();
- let mut pong = pong::PongBuilder::new(builder.fbb());
- pong.add_value(ping.message().unwrap().value());
- pong.add_initial_send_time(event_loop.monotonic_now().into());
- let pong = pong.finish();
- builder.send(pong).expect("Can't send pong reponse");
- }
-}