Skip to content

Commit

Permalink
Log printer (#14)
Browse files Browse the repository at this point in the history
* simple plugin to log every sec

* prepare 1.0.0
  • Loading branch information
XdoctorwhoZ authored Jan 5, 2025
1 parent 996c6f1 commit d117c67
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "pza-plugin-vi"
edition = "2021"
version = "0.1.2"
version = "1.0.0"

[lib]
path = "src/lib.rs"
crate-type = ["lib", "cdylib"]

[dependencies]
# Core
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.2.0" }
panduza-platform-core = { git = "https://github.com/Panduza/panduza-platform-core", tag = "0.2.1" }
# Main async framework for the platform
tokio = { version = "1.40.0", features = ["full"] }
# Json serialization & deserialization
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ panduza_platform_core::plugin_interface!("vi");
//
// Import modules
mod daq;
mod platform_logger;
mod repl;
mod tester;

Expand All @@ -16,6 +17,7 @@ pub fn plugin_producers() -> Vec<Box<dyn Producer>> {
producers.push(repl::Package::default().boxed());
producers.push(daq::Package::default().boxed());
producers.push(tester::Package::default().boxed());
producers.push(platform_logger::Package::default().boxed());
return producers;
}

Expand Down
34 changes: 34 additions & 0 deletions src/platform_logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pub mod device;
use device::Device;
use panduza_platform_core::{DriverOperations, Producer};

#[derive(Default)]
pub struct Package {}

impl Package {
pub fn boxed(self) -> Box<Self> {
Box::new(self)
}
}

impl Producer for Package {
fn manufacturer(&self) -> String {
"vi".to_string()
}

fn model(&self) -> String {
"platform_logger".to_string()
}

fn description(&self) -> String {
"Virtual logger interface".to_string()
}

fn props(&self) -> panduza_platform_core::Props {
panduza_platform_core::Props::default()
}

fn produce(&self) -> Result<Box<dyn DriverOperations>, panduza_platform_core::Error> {
return Ok(Box::new(Device::default()));
}
}
34 changes: 34 additions & 0 deletions src/platform_logger/device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use async_trait::async_trait;
use panduza_platform_core::{log_info, spawn_loop, Container, DriverOperations, Error, Instance};
use std::time::Duration;
use tokio::time::sleep;

#[derive(Default)]
///
///
pub struct Device {}

#[async_trait]
impl DriverOperations for Device {
///
///
///
async fn mount(&mut self, instance: Instance) -> Result<(), Error> {
let mut instance_2 = instance.clone();
spawn_loop!("test", instance_2, {
let mut counter: u64 = 0;
loop {
log_info!(instance.logger(), "Hello {}", counter);
tokio::time::sleep(Duration::from_secs(1)).await;
counter += 1;
}
});
Ok(())
}
///
/// Easiest way to implement the reboot event
///
async fn wait_reboot_event(&mut self, mut _device: Instance) {
sleep(Duration::from_secs(5)).await;
}
}

0 comments on commit d117c67

Please sign in to comment.