From b7f684b5a169ef3362944e8d8eff214dc54c9815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Sat, 7 Sep 2024 17:59:55 -0300 Subject: [PATCH] src: Rename File drivers to Tlog --- src/cli.rs | 7 +++- src/drivers/file/mod.rs | 2 -- src/drivers/mod.rs | 14 ++++---- src/drivers/tlog/mod.rs | 2 ++ .../{file/server.rs => tlog/reader.rs} | 33 ++++++++++--------- .../{file/client.rs => tlog/writer.rs} | 33 ++++++++++--------- 6 files changed, 49 insertions(+), 42 deletions(-) delete mode 100644 src/drivers/file/mod.rs create mode 100644 src/drivers/tlog/mod.rs rename src/drivers/{file/server.rs => tlog/reader.rs} (94%) rename src/drivers/{file/client.rs => tlog/writer.rs} (85%) diff --git a/src/cli.rs b/src/cli.rs index 967403ba..eba963ca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -184,7 +184,12 @@ mod tests { ("udps:192.168.1.5:6789", true), ("udpin:0.0.0.0:5000", true), ("udpin:192.168.1.5:6789", true), - ("filec:/tmp/little_potato.tlog", true), + ("tlogc:/tmp/little_potato.tlog", true), + ("tlogs:/tmp/little_potato.tlog", true), + ("tlogr:/tmp/little_potato.tlog", true), + ("tlogw:/tmp/little_potato.tlog", true), + ("tlogreader:/tmp/little_potato.tlog", true), + ("tlogwriter:/tmp/little_potato.tlog", true), ]; for (endpoint, expected) in endpoints { diff --git a/src/drivers/file/mod.rs b/src/drivers/file/mod.rs deleted file mode 100644 index c07f47e0..00000000 --- a/src/drivers/file/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod client; -pub mod server; diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 2d3333b5..85b2d841 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -1,7 +1,7 @@ pub mod fake; -pub mod file; pub mod serial; pub mod tcp; +pub mod tlog; pub mod udp; use std::sync::Arc; @@ -18,8 +18,8 @@ use crate::protocol::Protocol; pub enum Type { FakeClient, FakeSource, - FileClient, - FileServer, + TlogWriter, + TlogReader, Serial, TcpClient, TcpServer, @@ -176,12 +176,12 @@ pub struct ExtInfo { pub fn endpoints() -> Vec { vec![ ExtInfo { - driver_ext: Box::new(file::client::FileClientInfo), - typ: Type::FileClient, + driver_ext: Box::new(tlog::writer::TlogWriterInfo), + typ: Type::TlogWriter, }, ExtInfo { - driver_ext: Box::new(file::server::FileServerInfo), - typ: Type::FileServer, + driver_ext: Box::new(tlog::reader::TlogReaderInfo), + typ: Type::TlogReader, }, ExtInfo { driver_ext: Box::new(serial::SerialInfo), diff --git a/src/drivers/tlog/mod.rs b/src/drivers/tlog/mod.rs new file mode 100644 index 00000000..c9134a0e --- /dev/null +++ b/src/drivers/tlog/mod.rs @@ -0,0 +1,2 @@ +pub mod reader; +pub mod writer; diff --git a/src/drivers/file/server.rs b/src/drivers/tlog/reader.rs similarity index 94% rename from src/drivers/file/server.rs rename to src/drivers/tlog/reader.rs index 140a61bf..49a9cc3a 100644 --- a/src/drivers/file/server.rs +++ b/src/drivers/tlog/reader.rs @@ -12,15 +12,15 @@ use crate::{ protocol::Protocol, }; -pub struct FileServer { +pub struct TlogReader { pub path: PathBuf, on_message: Callbacks<(u64, Arc)>, } -pub struct FileServerBuilder(FileServer); +pub struct TlogReaderBuilder(TlogReader); -impl FileServerBuilder { - pub fn build(self) -> FileServer { +impl TlogReaderBuilder { + pub fn build(self) -> TlogReader { self.0 } @@ -33,10 +33,10 @@ impl FileServerBuilder { } } -impl FileServer { +impl TlogReader { #[instrument(level = "debug")] - pub fn builder(path: PathBuf) -> FileServerBuilder { - FileServerBuilder(Self { + pub fn builder(path: PathBuf) -> TlogReaderBuilder { + TlogReaderBuilder(Self { path, on_message: Callbacks::new(), }) @@ -118,30 +118,31 @@ impl FileServer { } #[async_trait::async_trait] -impl Driver for FileServer { +impl Driver for TlogReader { #[instrument(level = "debug", skip(self, hub_sender))] async fn run(&self, hub_sender: broadcast::Sender>) -> Result<()> { let file = tokio::fs::File::open(self.path.clone()).await?; let reader = tokio::io::BufReader::with_capacity(1024, file); - FileServer::handle_file(self, reader, hub_sender).await + TlogReader::handle_file(self, reader, hub_sender).await } #[instrument(level = "debug", skip(self))] fn info(&self) -> Box { - return Box::new(FileServerInfo); + return Box::new(TlogReaderInfo); } } -pub struct FileServerInfo; -impl DriverInfo for FileServerInfo { +pub struct TlogReaderInfo; +impl DriverInfo for TlogReaderInfo { fn name(&self) -> &str { - "FileServer" + "TlogReader" } fn valid_schemes(&self) -> Vec { vec![ - "filesource".to_string(), + "filereader".to_string(), + "filer".to_string(), "fileserver".to_string(), "files".to_string(), ] @@ -197,7 +198,7 @@ impl DriverInfo for FileServerInfo { } fn create_endpoint_from_url(&self, url: &url::Url) -> Option> { - Some(Arc::new(FileServer::builder(url.path().into()).build())) + Some(Arc::new(TlogReader::builder(url.path().into()).build())) } } @@ -222,7 +223,7 @@ mod tests { let tlog_file = PathBuf::from_str("tests/files/00025-2024-04-22_18-49-07.tlog").unwrap(); - let driver = FileServer::builder(tlog_file.clone()) + let driver = TlogReader::builder(tlog_file.clone()) .on_message(move |args: (u64, Arc)| { let messages_received = messages_received_cloned.clone(); diff --git a/src/drivers/file/client.rs b/src/drivers/tlog/writer.rs similarity index 85% rename from src/drivers/file/client.rs rename to src/drivers/tlog/writer.rs index 37d5ffa7..7a7ff5da 100644 --- a/src/drivers/file/client.rs +++ b/src/drivers/tlog/writer.rs @@ -13,15 +13,15 @@ use crate::{ protocol::Protocol, }; -pub struct FileClient { +pub struct TlogWriter { pub path: PathBuf, on_message: Callbacks<(u64, Arc)>, } -pub struct FileClientBuilder(FileClient); +pub struct TlogWriterBuilder(TlogWriter); -impl FileClientBuilder { - pub fn build(self) -> FileClient { +impl TlogWriterBuilder { + pub fn build(self) -> TlogWriter { self.0 } @@ -34,10 +34,10 @@ impl FileClientBuilder { } } -impl FileClient { +impl TlogWriter { #[instrument(level = "debug")] - pub fn builder(path: PathBuf) -> FileClientBuilder { - FileClientBuilder(Self { + pub fn builder(path: PathBuf) -> TlogWriterBuilder { + TlogWriterBuilder(Self { path, on_message: Callbacks::new(), }) @@ -81,38 +81,39 @@ impl FileClient { } } - debug!("FileClient write task finished"); + debug!("TlogClient write task finished"); Ok(()) } } #[async_trait::async_trait] -impl Driver for FileClient { +impl Driver for TlogWriter { #[instrument(level = "debug", skip(self, hub_sender))] async fn run(&self, hub_sender: broadcast::Sender>) -> Result<()> { let file = tokio::fs::File::create(self.path.clone()).await?; let writer = tokio::io::BufWriter::with_capacity(1024, file); let hub_receiver = hub_sender.subscribe(); - FileClient::handle_client(self, writer, hub_receiver).await + TlogWriter::handle_client(self, writer, hub_receiver).await } #[instrument(level = "debug", skip(self))] fn info(&self) -> Box { - return Box::new(FileClientInfo); + return Box::new(TlogWriterInfo); } } -pub struct FileClientInfo; -impl DriverInfo for FileClientInfo { +pub struct TlogWriterInfo; +impl DriverInfo for TlogWriterInfo { fn name(&self) -> &str { - "FileClient" + "Tlogwriter" } fn valid_schemes(&self) -> Vec { vec![ - "fileclient".to_string(), "filewriter".to_string(), + "filew".to_string(), + "fileclient".to_string(), "filec".to_string(), ] } @@ -136,6 +137,6 @@ impl DriverInfo for FileClientInfo { } fn create_endpoint_from_url(&self, url: &url::Url) -> Option> { - Some(Arc::new(FileClient::builder(url.path().into()).build())) + Some(Arc::new(TlogWriter::builder(url.path().into()).build())) } }