Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ default-members = ["drmemd"]
resolver = "2"

[workspace.dependencies]
async-trait = { version = "0.1", default-features = false }
chrono = { version = "0.4", default-features = false }
futures = { version = "0.3", default-features = false }
toml = { version = "0.8", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions drivers/drmem-drv-ntp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drmem-drv-ntp"
version = "0.5.0"
version = "0.6.0"
authors = ["Rich Neswold <rich.neswold@gmail.com>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down Expand Up @@ -30,4 +30,4 @@ tracing-futures.default-features = false
tracing-subscriber.workspace = true
tracing-subscriber.default-features = false

drmem-api = { path = "../../drmem-api", version = "0.5" }
drmem-api = { path = "../../drmem-api", version = "0.6" }
46 changes: 22 additions & 24 deletions drivers/drmem-drv-ntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use drmem_api::{
driver::{self, DriverConfig},
Error, Result,
};
use std::convert::Infallible;
use std::future::Future;
use std::sync::Arc;
use std::{convert::Infallible, pin::Pin};
use std::{
net::{SocketAddr, SocketAddrV4},
str,
Expand Down Expand Up @@ -110,13 +110,6 @@ pub struct Instance {
seq: u16,
}

pub struct Devices {
d_state: driver::ReadOnlyDevice<bool>,
d_source: driver::ReadOnlyDevice<String>,
d_offset: driver::ReadOnlyDevice<f64>,
d_delay: driver::ReadOnlyDevice<f64>,
}

impl Instance {
pub const NAME: &'static str = "ntp";

Expand Down Expand Up @@ -364,14 +357,19 @@ impl Instance {
}
}

impl driver::API for Instance {
type DeviceSet = Devices;
pub struct Devices {
d_state: driver::ReadOnlyDevice<bool>,
d_source: driver::ReadOnlyDevice<String>,
d_offset: driver::ReadOnlyDevice<f64>,
d_delay: driver::ReadOnlyDevice<f64>,
}

fn register_devices(
core: driver::RequestChan,
impl driver::Registrator for Devices {
fn register_devices<'a>(
core: &'a mut driver::RequestChan,
_: &DriverConfig,
max_history: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>> {
) -> impl Future<Output = Result<Self>> + Send + 'a {
// It's safe to use `.unwrap()` for these names because, in a
// fully-tested, released version of this driver, we would
// have seen and fixed any panics.
Expand Down Expand Up @@ -403,13 +401,17 @@ impl driver::API for Instance {
})
})
}
}

impl driver::API for Instance {
type HardwareType = Devices;

fn create_instance(
cfg: &DriverConfig,
) -> Pin<Box<dyn Future<Output = Result<Box<Self>>> + Send>> {
) -> impl Future<Output = Result<Box<Self>>> + Send {
let addr = Instance::get_cfg_address(cfg);

let fut = async move {
async move {
// Validate the configuration.

let addr = addr?;
Expand All @@ -423,16 +425,14 @@ impl driver::API for Instance {
}
}
Err(Error::OperationError("couldn't create socket".to_owned()))
};

Box::pin(fut)
}
}

fn run<'a>(
&'a mut self,
devices: Arc<Mutex<Devices>>,
) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>> {
let fut = async move {
devices: Arc<Mutex<Self::HardwareType>>,
) -> impl Future<Output = Infallible> + Send + 'a {
async move {
// Record the peer's address in the "cfg" field of the
// span.

Expand Down Expand Up @@ -504,9 +504,7 @@ impl driver::API for Instance {
devices.d_state.report_update(false).await;
}
}
};

Box::pin(fut)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/drmem-drv-sump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drmem-drv-sump"
version = "0.5.0"
version = "0.6.0"
authors = ["Rich Neswold <rich.neswold@gmail.com>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down Expand Up @@ -33,4 +33,4 @@ tracing-futures.default-features = false
tracing-subscriber.workspace = true
tracing-subscriber.default-features = false

drmem-api = { path = "../../drmem-api", version = "0.5" }
drmem-api = { path = "../../drmem-api", version = "0.6" }
48 changes: 23 additions & 25 deletions drivers/drmem-drv-sump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use drmem_api::{
driver::{self, DriverConfig},
Error, Result,
};
use std::convert::Infallible;
use std::future::Future;
use std::net::SocketAddrV4;
use std::sync::Arc;
use std::{convert::Infallible, pin::Pin};
use tokio::{
io::{self, AsyncReadExt},
net::{
Expand Down Expand Up @@ -150,14 +150,6 @@ pub struct Instance {
_tx: OwnedWriteHalf,
}

pub struct Devices {
d_service: driver::ReadOnlyDevice<bool>,
d_state: driver::ReadOnlyDevice<bool>,
d_duty: driver::ReadOnlyDevice<f64>,
d_inflow: driver::ReadOnlyDevice<f64>,
d_duration: driver::ReadOnlyDevice<f64>,
}

impl Instance {
pub const NAME: &'static str = "sump-gpio";

Expand Down Expand Up @@ -282,14 +274,20 @@ impl Instance {
}
}

impl driver::API for Instance {
type DeviceSet = Devices;
pub struct Devices {
d_service: driver::ReadOnlyDevice<bool>,
d_state: driver::ReadOnlyDevice<bool>,
d_duty: driver::ReadOnlyDevice<f64>,
d_inflow: driver::ReadOnlyDevice<f64>,
d_duration: driver::ReadOnlyDevice<f64>,
}

fn register_devices(
core: driver::RequestChan,
impl driver::Registrator for Devices {
fn register_devices<'a>(
core: &'a mut driver::RequestChan,
_: &DriverConfig,
max_history: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>> {
) -> impl Future<Output = Result<Self>> + Send + 'a {
let service_name = "service".parse::<device::Base>().unwrap();
let state_name = "state".parse::<device::Base>().unwrap();
let duty_name = "duty".parse::<device::Base>().unwrap();
Expand Down Expand Up @@ -322,14 +320,18 @@ impl driver::API for Instance {
})
})
}
}

impl driver::API for Instance {
type HardwareType = Devices;

fn create_instance(
cfg: &DriverConfig,
) -> Pin<Box<dyn Future<Output = Result<Box<Self>>> + Send>> {
) -> impl Future<Output = Result<Box<Self>>> + Send {
let addr = Instance::get_cfg_address(cfg);
let gpm = Instance::get_cfg_gpm(cfg);

let fut = async move {
async move {
// Validate the configuration.

let addr = addr?;
Expand All @@ -348,16 +350,14 @@ impl driver::API for Instance {
rx,
_tx,
}))
};

Box::pin(fut)
}
}

fn run<'a>(
&'a mut self,
devices: Arc<Mutex<Devices>>,
) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>> {
let fut = async move {
devices: Arc<Mutex<Self::HardwareType>>,
) -> impl Future<Output = Infallible> + Send + 'a {
async move {
// Record the peer's address in the "cfg" field of the
// span.

Expand Down Expand Up @@ -415,9 +415,7 @@ impl driver::API for Instance {
}
}
}
};

Box::pin(fut)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/drmem-drv-tplink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drmem-drv-tplink"
version = "0.5.0"
version = "0.6.0"
authors = ["Rich Neswold <rich.neswold@gmail.com>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down Expand Up @@ -45,4 +45,4 @@ serde_json.workspace = true
serde_json.default-features = false
serde_json.features = ["std"]

drmem-api = { path = "../../drmem-api", version = "0.5" }
drmem-api = { path = "../../drmem-api", version = "0.6" }
Loading