Skip to content

Commit

Permalink
src: Rename File drivers to Tlog
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Sep 7, 2024
1 parent 9d9a4a8 commit b7f684b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 42 deletions.
7 changes: 6 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/drivers/file/mod.rs

This file was deleted.

14 changes: 7 additions & 7 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,8 +18,8 @@ use crate::protocol::Protocol;
pub enum Type {
FakeClient,
FakeSource,
FileClient,
FileServer,
TlogWriter,
TlogReader,
Serial,
TcpClient,
TcpServer,
Expand Down Expand Up @@ -176,12 +176,12 @@ pub struct ExtInfo {
pub fn endpoints() -> Vec<ExtInfo> {
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),
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/tlog/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod reader;
pub mod writer;
33 changes: 17 additions & 16 deletions src/drivers/file/server.rs → src/drivers/tlog/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::{
protocol::Protocol,
};

pub struct FileServer {
pub struct TlogReader {
pub path: PathBuf,
on_message: Callbacks<(u64, Arc<Protocol>)>,
}

pub struct FileServerBuilder(FileServer);
pub struct TlogReaderBuilder(TlogReader);

impl FileServerBuilder {
pub fn build(self) -> FileServer {
impl TlogReaderBuilder {
pub fn build(self) -> TlogReader {
self.0
}

Expand All @@ -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(),
})
Expand Down Expand Up @@ -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<Arc<Protocol>>) -> 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<dyn DriverInfo> {
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<String> {
vec![
"filesource".to_string(),
"filereader".to_string(),
"filer".to_string(),
"fileserver".to_string(),
"files".to_string(),
]
Expand Down Expand Up @@ -197,7 +198,7 @@ impl DriverInfo for FileServerInfo {
}

fn create_endpoint_from_url(&self, url: &url::Url) -> Option<Arc<dyn Driver>> {
Some(Arc::new(FileServer::builder(url.path().into()).build()))
Some(Arc::new(TlogReader::builder(url.path().into()).build()))
}
}

Expand All @@ -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<Protocol>)| {
let messages_received = messages_received_cloned.clone();

Expand Down
33 changes: 17 additions & 16 deletions src/drivers/file/client.rs → src/drivers/tlog/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use crate::{
protocol::Protocol,
};

pub struct FileClient {
pub struct TlogWriter {
pub path: PathBuf,
on_message: Callbacks<(u64, Arc<Protocol>)>,
}

pub struct FileClientBuilder(FileClient);
pub struct TlogWriterBuilder(TlogWriter);

impl FileClientBuilder {
pub fn build(self) -> FileClient {
impl TlogWriterBuilder {
pub fn build(self) -> TlogWriter {
self.0
}

Expand All @@ -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(),
})
Expand Down Expand Up @@ -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<Arc<Protocol>>) -> 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<dyn DriverInfo> {
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<String> {
vec![
"fileclient".to_string(),
"filewriter".to_string(),
"filew".to_string(),
"fileclient".to_string(),
"filec".to_string(),
]
}
Expand All @@ -136,6 +137,6 @@ impl DriverInfo for FileClientInfo {
}

fn create_endpoint_from_url(&self, url: &url::Url) -> Option<Arc<dyn Driver>> {
Some(Arc::new(FileClient::builder(url.path().into()).build()))
Some(Arc::new(TlogWriter::builder(url.path().into()).build()))
}
}

0 comments on commit b7f684b

Please sign in to comment.