Skip to content

Commit

Permalink
Merge pull request #126 from rneswold/pull-request
Browse files Browse the repository at this point in the history
Refactoring pull request
  • Loading branch information
rneswold authored Aug 23, 2024
2 parents b9916e0 + 2c4b865 commit 32fad78
Show file tree
Hide file tree
Showing 24 changed files with 476 additions and 435 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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.4.0"
version = "0.5.0"
authors = ["Rich Neswold <[email protected]>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down
38 changes: 23 additions & 15 deletions drivers/drmem-drv-ntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ pub struct Instance {
}

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

impl Instance {
Expand Down Expand Up @@ -384,14 +384,14 @@ impl driver::API for Instance {
Box::pin(async move {
// Define the devices managed by this driver.

let (d_state, _) =
let d_state =
core.add_ro_device(state_name, None, max_history).await?;
let (d_source, _) =
let d_source =
core.add_ro_device(source_name, None, max_history).await?;
let (d_offset, _) = core
let d_offset = core
.add_ro_device(offset_name, Some("ms"), max_history)
.await?;
let (d_delay, _) = core
let d_delay = core
.add_ro_device(delay_name, Some("ms"), max_history)
.await?;

Expand Down Expand Up @@ -454,7 +454,7 @@ impl driver::API for Instance {
let mut info = Some(server::Info::bad_value());
let mut interval = time::interval(Duration::from_millis(20_000));

let devices = devices.lock().await;
let mut devices = devices.lock().await;

loop {
interval.tick().await;
Expand All @@ -473,11 +473,19 @@ impl driver::API for Instance {
tmp.get_offset(),
tmp.get_delay()
);
(devices.d_source)(tmp.get_host().clone())
devices
.d_source
.report_update(tmp.get_host().clone())
.await;
(devices.d_offset)(tmp.get_offset()).await;
(devices.d_delay)(tmp.get_delay()).await;
(devices.d_state)(true).await;
devices
.d_offset
.report_update(tmp.get_offset())
.await;
devices
.d_delay
.report_update(tmp.get_delay())
.await;
devices.d_state.report_update(true).await;
info = host_info;
}
continue;
Expand All @@ -486,14 +494,14 @@ impl driver::API for Instance {
if info.is_some() {
warn!("no synced host information found");
info = None;
(devices.d_state)(false).await;
devices.d_state.report_update(false).await;
}
}
}
} else if info.is_some() {
warn!("we're not synced to any host");
info = None;
(devices.d_state)(false).await;
devices.d_state.report_update(false).await;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion 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.4.0"
version = "0.5.0"
authors = ["Rich Neswold <[email protected]>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down
46 changes: 24 additions & 22 deletions drivers/drmem-drv-sump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ pub struct Instance {
}

pub struct Devices {
d_service: driver::ReportReading<bool>,
d_state: driver::ReportReading<bool>,
d_duty: driver::ReportReading<f64>,
d_inflow: driver::ReportReading<f64>,
d_duration: driver::ReportReading<f64>,
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 {
Expand Down Expand Up @@ -299,17 +299,17 @@ impl driver::API for Instance {
Box::pin(async move {
// Define the devices managed by this driver.

let (d_service, _) =
let d_service =
core.add_ro_device(service_name, None, max_history).await?;
let (d_state, _) =
let d_state =
core.add_ro_device(state_name, None, max_history).await?;
let (d_duty, _) = core
let d_duty = core
.add_ro_device(duty_name, Some("%"), max_history)
.await?;
let (d_inflow, _) = core
let d_inflow = core
.add_ro_device(in_flow_name, Some("gpm"), max_history)
.await?;
let (d_duration, _) = core
let d_duration = core
.add_ro_device(dur_name, Some("min"), max_history)
.await?;

Expand Down Expand Up @@ -371,15 +371,15 @@ impl driver::API for Instance {
Span::current().record("cfg", addr.as_str());
}

let devices = devices.lock().await;
let mut devices = devices.lock().await;

(*devices.d_service)(true).await;
devices.d_service.report_update(true).await;

loop {
match self.get_reading().await {
Ok((stamp, true)) => {
if self.state.on_event(stamp) {
(devices.d_state)(true).await;
devices.d_state.report_update(true).await;
}
}

Expand All @@ -396,19 +396,21 @@ impl driver::API for Instance {
in_flow
);

(devices.d_state)(false).await;
(devices.d_duty)(duty).await;
(devices.d_inflow)(in_flow).await;
(devices.d_duration)(
((cycle as f64) / 600.0).round() / 100.0,
)
.await;
devices.d_state.report_update(false).await;
devices.d_duty.report_update(duty).await;
devices.d_inflow.report_update(in_flow).await;
devices
.d_duration
.report_update(
((cycle as f64) / 600.0).round() / 100.0,
)
.await;
}
}

Err(e) => {
(devices.d_state)(false).await;
(devices.d_service)(false).await;
devices.d_state.report_update(false).await;
devices.d_service.report_update(false).await;
panic!("couldn't read sump state -- {:?}", e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion 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.2.0"
version = "0.5.0"
authors = ["Rich Neswold <[email protected]>"]
edition = "2021"
homepage = "https://github.com/DrMemCS/drmem"
Expand Down
Loading

0 comments on commit 32fad78

Please sign in to comment.