From dcf6365836a8846cdb8f0c70d79b22cc05948ea4 Mon Sep 17 00:00:00 2001 From: Rich Neswold Date: Thu, 1 Jan 2026 21:54:49 -0600 Subject: [PATCH 1/4] :arrow_up: no longer need `tracing_futures` crate The functionality has been rolled into `tracing`. Who knew? --- Cargo.lock | 95 +++++++++++-------------- Cargo.toml | 3 +- drivers/drmem-drv-ntp/Cargo.toml | 3 - drivers/drmem-drv-sump/Cargo.toml | 3 - drivers/drmem-drv-tplink/Cargo.toml | 3 - drivers/drmem-drv-weather-wu/Cargo.toml | 3 - drmemd/Cargo.toml | 4 -- drmemd/src/core/mod.rs | 3 +- drmemd/src/driver/mod.rs | 3 +- drmemd/src/logic/mod.rs | 3 +- drmemd/src/logic/solar.rs | 3 +- drmemd/src/logic/tod.rs | 3 +- 12 files changed, 49 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5639813..84618a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,9 +40,9 @@ checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "async-compression" -version = "0.4.35" +version = "0.4.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07a926debf178f2d355197f9caddb08e54a9329d44748034bba349c5848cb519" +checksum = "98ec5f6c2f8bc326c994cb9e241cc257ddaba9afa8555a43cffbb5dd86efaa37" dependencies = [ "compression-codecs", "compression-core", @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "by_address" @@ -148,9 +148,9 @@ checksum = "acbc26382d871df4b7442e3df10a9402bf3cf5e55cbd66f12be38861425f0564" [[package]] name = "cc" -version = "1.2.49" +version = "1.2.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215" +checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" dependencies = [ "find-msvc-tools", "shlex", @@ -228,9 +228,9 @@ dependencies = [ [[package]] name = "compression-codecs" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34a3cbbb8b6eca96f3a5c4bf6938d5b27ced3675d69f95bb51948722870bc323" +checksum = "b0f7ac3e5b97fdce45e8922fb05cae2c37f7bbd63d30dd94821dacfd8f3f2bf2" dependencies = [ "compression-core", "flate2", @@ -385,7 +385,6 @@ dependencies = [ "tokio", "toml", "tracing", - "tracing-futures", "tracing-subscriber", ] @@ -398,7 +397,6 @@ dependencies = [ "tokio", "toml", "tracing", - "tracing-futures", "tracing-subscriber", ] @@ -414,7 +412,6 @@ dependencies = [ "tokio", "toml", "tracing", - "tracing-futures", "tracing-subscriber", ] @@ -427,7 +424,6 @@ dependencies = [ "tokio", "toml", "tracing", - "tracing-futures", "tracing-subscriber", "weather-underground", ] @@ -464,7 +460,6 @@ dependencies = [ "tokio-stream", "toml", "tracing", - "tracing-futures", "tracing-subscriber", "warp", ] @@ -504,9 +499,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" +checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" [[package]] name = "flate2" @@ -866,9 +861,9 @@ checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" [[package]] name = "icu_properties" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" dependencies = [ "icu_collections", "icu_locale_core", @@ -880,9 +875,9 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" [[package]] name = "icu_provider" @@ -960,9 +955,9 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "js-sys" @@ -1082,9 +1077,9 @@ dependencies = [ [[package]] name = "libredox" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ "bitflags 2.10.0", "libc", @@ -1413,9 +1408,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" dependencies = [ "unicode-ident", ] @@ -1498,9 +1493,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.18" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" dependencies = [ "bitflags 2.10.0", ] @@ -1654,9 +1649,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "708c0f9d5f54ba0272468c1d306a52c495b31fa155e91bc25371e6df7996908c" +checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" dependencies = [ "zeroize", ] @@ -1690,9 +1685,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" [[package]] name = "scoped-tls" @@ -1742,15 +1737,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.145" +version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da" dependencies = [ "itoa", "memchr", - "ryu", "serde", "serde_core", + "zmij", ] [[package]] @@ -1802,9 +1797,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simd-adler32" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" [[package]] name = "siphasher" @@ -1893,9 +1888,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.111" +version = "2.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +checksum = "21f182278bf2d2bcb3c88b1b08a37df029d71ce3d3ae26168e3c653b213b99d4" dependencies = [ "proc-macro2", "quote", @@ -2153,9 +2148,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "log", "pin-project-lite", @@ -2176,23 +2171,13 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.22" @@ -2897,3 +2882,9 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zmij" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de9211a9f64b825911bdf0240f58b7a8dac217fe260fc61f080a07f61372fbd5" diff --git a/Cargo.toml b/Cargo.toml index c503fe8..aa2cb40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,7 @@ futures = { version = "0.3", default-features = false } toml = { version = "0.8", default-features = false } tokio = { version = "1", default-features = false } tokio-stream = { version = "0.1", default-features = false } -tracing = { version = "0.1", default-features = false } -tracing-futures = { version = "0.2", default-features = false } +tracing = { version = "0.1", default-features = false, features = ["attributes"] } tracing-subscriber = { version = "0.3", default-features = false } serde = { version = "1", default-features = false, features = ["rc"] } serde_json = { version = "1", default-features = false } diff --git a/drivers/drmem-drv-ntp/Cargo.toml b/drivers/drmem-drv-ntp/Cargo.toml index 3528229..920e0d1 100644 --- a/drivers/drmem-drv-ntp/Cargo.toml +++ b/drivers/drmem-drv-ntp/Cargo.toml @@ -24,9 +24,6 @@ tokio.features = ["net", "time", "macros"] tracing.workspace = true tracing.default-features = false -tracing-futures.workspace = true -tracing-futures.default-features = false - tracing-subscriber.workspace = true tracing-subscriber.default-features = false diff --git a/drivers/drmem-drv-sump/Cargo.toml b/drivers/drmem-drv-sump/Cargo.toml index 4641f56..aedc07c 100644 --- a/drivers/drmem-drv-sump/Cargo.toml +++ b/drivers/drmem-drv-sump/Cargo.toml @@ -27,9 +27,6 @@ tokio.features = ["net", "io-util", "time"] tracing.workspace = true tracing.default-features = false -tracing-futures.workspace = true -tracing-futures.default-features = false - tracing-subscriber.workspace = true tracing-subscriber.default-features = false diff --git a/drivers/drmem-drv-tplink/Cargo.toml b/drivers/drmem-drv-tplink/Cargo.toml index e2fa095..dca689f 100644 --- a/drivers/drmem-drv-tplink/Cargo.toml +++ b/drivers/drmem-drv-tplink/Cargo.toml @@ -28,9 +28,6 @@ tokio.features = ["net", "time", "macros", "io-util"] tracing.workspace = true tracing.default-features = false -tracing-futures.workspace = true -tracing-futures.default-features = false - tracing-subscriber.workspace = true tracing-subscriber.default-features = false diff --git a/drivers/drmem-drv-weather-wu/Cargo.toml b/drivers/drmem-drv-weather-wu/Cargo.toml index 9f09290..cad374c 100644 --- a/drivers/drmem-drv-weather-wu/Cargo.toml +++ b/drivers/drmem-drv-weather-wu/Cargo.toml @@ -24,9 +24,6 @@ tokio.default-features = false tracing.workspace = true tracing.default-features = false -tracing-futures.workspace = true -tracing-futures.default-features = false - tracing-subscriber.workspace = true tracing-subscriber.default-features = false diff --git a/drmemd/Cargo.toml b/drmemd/Cargo.toml index 95e7f03..9c37113 100644 --- a/drmemd/Cargo.toml +++ b/drmemd/Cargo.toml @@ -39,10 +39,6 @@ tracing.workspace = true tracing.default-features = false tracing.features = ["attributes"] -tracing-futures.workspace = true -tracing-futures.default-features = false -tracing-futures.features = ["std-future", "std"] - tracing-subscriber.workspace = true tracing-subscriber.default-features = false tracing-subscriber.features = ["ansi"] diff --git a/drmemd/src/core/mod.rs b/drmemd/src/core/mod.rs index e0cca3c..67139db 100644 --- a/drmemd/src/core/mod.rs +++ b/drmemd/src/core/mod.rs @@ -2,8 +2,7 @@ use crate::backends::{store, Instance, Store}; use drmem_api::{client, driver, Error, Result}; use std::convert::Infallible; use tokio::{sync::mpsc, task::JoinHandle}; -use tracing::{info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{info, info_span, warn, Instrument}; /// Holds the state of the core task in the framework. /// diff --git a/drmemd/src/driver/mod.rs b/drmemd/src/driver/mod.rs index 83abe1c..ce9136f 100644 --- a/drmemd/src/driver/mod.rs +++ b/drmemd/src/driver/mod.rs @@ -7,8 +7,7 @@ use futures::future::Future; use std::collections::HashMap; use std::{convert::Infallible, pin::Pin, sync::Arc}; use tokio::sync::Mutex; -use tracing::{error, field, info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{error, field, info, info_span, warn, Instrument}; mod drv_cycle; mod drv_latch; diff --git a/drmemd/src/logic/mod.rs b/drmemd/src/logic/mod.rs index 6f85841..ad0319f 100644 --- a/drmemd/src/logic/mod.rs +++ b/drmemd/src/logic/mod.rs @@ -8,8 +8,7 @@ use tokio::{ task::JoinHandle, }; use tokio_stream::{wrappers::BroadcastStream, StreamExt, StreamMap}; -use tracing::{debug, error, info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{debug, error, info, info_span, warn, Instrument}; use super::config; diff --git a/drmemd/src/logic/solar.rs b/drmemd/src/logic/solar.rs index 52a5c92..8c2ddc2 100644 --- a/drmemd/src/logic/solar.rs +++ b/drmemd/src/logic/solar.rs @@ -10,8 +10,7 @@ use tokio::{ sync::{broadcast, Barrier}, time, }; -use tracing::{debug, info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{debug, info, info_span, warn, Instrument}; pub struct SolarInfo { pub elevation: f64, diff --git a/drmemd/src/logic/tod.rs b/drmemd/src/logic/tod.rs index 452fe24..ca5ca3a 100644 --- a/drmemd/src/logic/tod.rs +++ b/drmemd/src/logic/tod.rs @@ -7,8 +7,7 @@ use tokio::{ time, }; use tokio_stream::{wrappers::BroadcastStream, Stream}; -use tracing::{info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{info, info_span, warn, Instrument}; // Information related to time-of-day. We keep both UTC and local time // so clients don't have to convert between the time zones. It is From ecb6b0d7af4a96ba5fd4853814985bf9dc9c72fb Mon Sep 17 00:00:00 2001 From: Rich Neswold Date: Thu, 1 Jan 2026 21:54:49 -0600 Subject: [PATCH 2/4] :recycle: significant change to driver `run()` method The `.run()` method in the driver API passed the set of driver channels in a type that was protected by a mutex. There was no need for the serialization because only the driver would be using the channels. Back when I wrote that code, I wasn't as experienced with Rust and so that's how I got it to work. Looking at it not, I realize that I should be able to pass a mutable borrow to the `.run()` method. This commit contains the following changes: - `.run()` now takes a mutable borrow instead of `Arc>` - We don't need the `tracing_futures` crate; the `tracing` crate now supports instrumenting futures - The number of async tasks required to support drivers has been reduced; the manager task runs asynchronously, but doesn't spawn a task for the driver. Instead, it itself calls the `.run()` method. It catches any panics, as well. This cuts the number of async tasks in half. --- drivers/drmem-drv-ntp/src/lib.rs | 10 +- drivers/drmem-drv-sump/src/lib.rs | 9 +- drivers/drmem-drv-tplink/src/lib.rs | 20 +--- drivers/drmem-drv-weather-wu/src/lib.rs | 12 +-- drmem-api/src/driver/mod.rs | 10 +- drmemd/Cargo.toml | 2 +- drmemd/src/backends/redis/mod.rs | 9 +- drmemd/src/driver/drv_cycle.rs | 10 +- drmemd/src/driver/drv_latch.rs | 9 +- drmemd/src/driver/drv_map.rs | 12 +-- drmemd/src/driver/drv_memory.rs | 10 +- drmemd/src/driver/drv_timer.rs | 10 +- drmemd/src/driver/mod.rs | 137 ++++++++---------------- drmemd/src/graphql/mod.rs | 3 +- drmemd/src/main.rs | 25 ++--- 15 files changed, 89 insertions(+), 199 deletions(-) diff --git a/drivers/drmem-drv-ntp/src/lib.rs b/drivers/drmem-drv-ntp/src/lib.rs index 730169e..5e2cc78 100644 --- a/drivers/drmem-drv-ntp/src/lib.rs +++ b/drivers/drmem-drv-ntp/src/lib.rs @@ -5,13 +5,11 @@ use drmem_api::{ }; use std::convert::Infallible; use std::future::Future; -use std::sync::Arc; use std::{ net::{SocketAddr, SocketAddrV4}, str, }; use tokio::net::UdpSocket; -use tokio::sync::Mutex; use tokio::time::{self, Duration}; use tracing::{debug, error, trace, warn, Span}; @@ -428,9 +426,9 @@ impl driver::API for Instance { } } - async fn run( - &mut self, - devices: Arc>, + async fn run<'a>( + &'a mut self, + devices: &'a mut Self::HardwareType, ) -> Infallible { // Record the peer's address in the "cfg" field of the span. @@ -451,8 +449,6 @@ impl driver::API for Instance { let mut info = Some(server::Info::bad_value()); let mut interval = time::interval(Duration::from_millis(20_000)); - let mut devices = devices.lock().await; - loop { interval.tick().await; diff --git a/drivers/drmem-drv-sump/src/lib.rs b/drivers/drmem-drv-sump/src/lib.rs index f2ff658..e8d8dee 100644 --- a/drivers/drmem-drv-sump/src/lib.rs +++ b/drivers/drmem-drv-sump/src/lib.rs @@ -6,14 +6,12 @@ use drmem_api::{ use std::convert::Infallible; use std::future::Future; use std::net::SocketAddrV4; -use std::sync::Arc; use tokio::{ io::{self, AsyncReadExt}, net::{ tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream, }, - sync::Mutex, time, }; use tracing::{debug, error, info, warn, Span}; @@ -353,10 +351,7 @@ impl driver::API for Instance { } } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { // Record the peer's address in the "cfg" field of the span. { @@ -369,8 +364,6 @@ impl driver::API for Instance { Span::current().record("cfg", addr.as_str()); } - let mut devices = devices.lock().await; - // Set initial, default values for the devices. Pick values // that would make sense. diff --git a/drivers/drmem-drv-tplink/src/lib.rs b/drivers/drmem-drv-tplink/src/lib.rs index 080b7d3..c1c56da 100644 --- a/drivers/drmem-drv-tplink/src/lib.rs +++ b/drivers/drmem-drv-tplink/src/lib.rs @@ -36,11 +36,9 @@ use drmem_api::{ use futures::{Future, FutureExt}; use std::convert::Infallible; use std::net::SocketAddrV4; -use std::sync::Arc; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::TcpStream, - sync::{Mutex, MutexGuard}, time, }; use tracing::{debug, error, warn, Span}; @@ -430,7 +428,7 @@ impl Instance { async fn main_loop( &mut self, s: &mut TcpStream, - devices: &mut MutexGuard<'_, ::HardwareType>, + devices: &mut ::HardwareType, ) { // Create a 5-second interval timer which will be used to poll // the device to see if its state was changed by some outside @@ -452,7 +450,7 @@ impl Instance { brightness: ref mut d_b, indicator: ref mut d_l, .. - } = **devices; + } = *devices; // Now wait for one of three events to occur. @@ -570,17 +568,7 @@ impl driver::API for Instance { // Main run loop for the driver. - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { - // Lock the mutex for the life of the driver. There is no - // other task that wants access to these device handles. An - // Arc> is the only way I know of sharing a mutable - // value with async tasks. - - let mut devices = devices.lock().await; - + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { // Record the devices's address in the "cfg" field of the // span. @@ -594,7 +582,7 @@ impl driver::API for Instance { match Instance::connect(&self.addr).await { Ok(mut s) => { - self.main_loop(&mut s, &mut devices).await; + self.main_loop(&mut s, devices).await; } Err(e) => { warn!("couldn't connect : '{}'", e); diff --git a/drivers/drmem-drv-weather-wu/src/lib.rs b/drivers/drmem-drv-weather-wu/src/lib.rs index ed3f252..b761009 100644 --- a/drivers/drmem-drv-weather-wu/src/lib.rs +++ b/drivers/drmem-drv-weather-wu/src/lib.rs @@ -3,8 +3,7 @@ use drmem_api::{ Error, Result, }; use std::convert::{Infallible, TryFrom}; -use std::{future::Future, sync::Arc, time::SystemTime}; -use tokio::sync::Mutex; +use std::{future::Future, time::SystemTime}; use tokio::time::{interval_at, Duration, Instant}; use tracing::{debug, error, warn, Span}; use weather_underground as wu; @@ -409,12 +408,7 @@ impl driver::API for Instance { } } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { - let mut devices = devices.lock().await; - + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { Span::current().record("cfg", devices.station.as_str()); devices.error.report_update(false).await; @@ -455,7 +449,7 @@ impl driver::API for Instance { warn!("ignoring {} extra weather observations", obs.len() - 1); } devices.error.report_update(false).await; - self.handle(&obs[0], &mut devices).await; + self.handle(&obs[0], devices).await; continue; } } diff --git a/drmem-api/src/driver/mod.rs b/drmem-api/src/driver/mod.rs index 5773de1..5f328fd 100644 --- a/drmem-api/src/driver/mod.rs +++ b/drmem-api/src/driver/mod.rs @@ -4,7 +4,7 @@ use crate::types::{device, Error}; use std::future::Future; use std::{convert::Infallible, sync::Arc}; -use tokio::sync::{mpsc, oneshot, Mutex}; +use tokio::sync::{mpsc, oneshot}; use toml::value; use super::Result; @@ -315,8 +315,8 @@ pub trait API: Send + Sync { /// and if a driver panics or returns an error from this method, /// it gets reported in the log and then, after a short delay, the /// driver is restarted. - fn run( - &mut self, - devices: Arc>, - ) -> impl Future + Send + '_; + fn run<'a>( + &'a mut self, + devices: &'a mut Self::HardwareType, + ) -> impl Future + Send + 'a; } diff --git a/drmemd/Cargo.toml b/drmemd/Cargo.toml index 9c37113..371e3df 100644 --- a/drmemd/Cargo.toml +++ b/drmemd/Cargo.toml @@ -21,7 +21,7 @@ lrpar = "0.13" [dependencies] futures.workspace = true futures.default-features = false -futures.features = ["alloc"] +futures.features = ["alloc", "std"] toml.workspace = true toml.default-features = false diff --git a/drmemd/src/backends/redis/mod.rs b/drmemd/src/backends/redis/mod.rs index bf51e88..e137597 100644 --- a/drmemd/src/backends/redis/mod.rs +++ b/drmemd/src/backends/redis/mod.rs @@ -5,8 +5,10 @@ use drmem_api::{ driver::{ReportReading, RxDeviceSetting, TxDeviceSetting}, Error, Result, }; -use futures::task::{Context, Poll}; -use futures::Future; +use futures::{ + task::{Context, Poll}, + Future, +}; use redis::{ aio, streams::{StreamId, StreamInfoStreamReply}, @@ -17,8 +19,7 @@ use std::pin::Pin; use std::time; use tokio::sync::{mpsc, oneshot}; use tokio_stream::{self, Stream, StreamExt}; -use tracing::{debug, error, info, info_span, warn}; -use tracing_futures::Instrument; +use tracing::{debug, error, info, info_span, warn, Instrument}; type AioMplexConnection = aio::MultiplexedConnection; type SettingTable = HashMap; diff --git a/drmemd/src/driver/drv_cycle.rs b/drmemd/src/driver/drv_cycle.rs index 5270be5..05f96ee 100644 --- a/drmemd/src/driver/drv_cycle.rs +++ b/drmemd/src/driver/drv_cycle.rs @@ -3,8 +3,8 @@ use drmem_api::{ driver::{self, DriverConfig}, Error, Result, }; -use std::{convert::Infallible, future::Future, sync::Arc}; -use tokio::{sync::Mutex, time}; +use std::{convert::Infallible, future::Future}; +use tokio::time; use tracing::{self, debug}; // This enum represents the three states in which the device can be. @@ -251,12 +251,8 @@ impl driver::API for Instance { } } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { let mut timer = time::interval(self.millis); - let mut devices = devices.lock().await; if self.enabled_at_boot { self.state = CycleState::Cycling; diff --git a/drmemd/src/driver/drv_latch.rs b/drmemd/src/driver/drv_latch.rs index cdd7d4a..a6486cc 100644 --- a/drmemd/src/driver/drv_latch.rs +++ b/drmemd/src/driver/drv_latch.rs @@ -3,8 +3,7 @@ use drmem_api::{ driver::{self, DriverConfig}, Error, Result, }; -use std::{convert::Infallible, future::Future, sync::Arc}; -use tokio::sync::Mutex; +use std::{convert::Infallible, future::Future}; // This enum represents the two states in which the latch can be. @@ -149,11 +148,7 @@ impl driver::API for Instance { } } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { - let mut devices = devices.lock().await; + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { let mut reset = false; let mut trigger = false; diff --git a/drmemd/src/driver/drv_map.rs b/drmemd/src/driver/drv_map.rs index b29109d..d688aa8 100644 --- a/drmemd/src/driver/drv_map.rs +++ b/drmemd/src/driver/drv_map.rs @@ -3,10 +3,7 @@ use drmem_api::{ driver::{self, DriverConfig}, Error, Result, }; -use std::{ - convert::Infallible, future::Future, ops::RangeInclusive, sync::Arc, -}; -use tokio::sync::Mutex; +use std::{convert::Infallible, future::Future, ops::RangeInclusive}; #[derive(Debug, PartialEq)] struct Entry(RangeInclusive, device::Value); @@ -244,12 +241,7 @@ impl driver::API for Instance { async move { Ok(Box::new(Instance::new(init_index?, def_value?, values?))) } } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { - let mut devices = devices.lock().await; - + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { // If we have an initial value, use it. if let Some(idx) = self.init_index { diff --git a/drmemd/src/driver/drv_memory.rs b/drmemd/src/driver/drv_memory.rs index 2f732bd..0886703 100644 --- a/drmemd/src/driver/drv_memory.rs +++ b/drmemd/src/driver/drv_memory.rs @@ -3,8 +3,7 @@ use drmem_api::{ driver::{self, DriverConfig}, Error, Result, }; -use std::{convert::Infallible, future::Future, sync::Arc}; -use tokio::sync::Mutex; +use std::{convert::Infallible, future::Future}; // Defines the signature if a function that validates a // `device::Value`'s type. @@ -227,12 +226,7 @@ impl driver::API for Instance { Ok(Box::new(Instance::new())) } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { - let mut devices = devices.lock().await; - + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { loop { let (idx, val) = devices.get_next().await; diff --git a/drmemd/src/driver/drv_timer.rs b/drmemd/src/driver/drv_timer.rs index d29d8f9..8737eb7 100644 --- a/drmemd/src/driver/drv_timer.rs +++ b/drmemd/src/driver/drv_timer.rs @@ -3,8 +3,8 @@ use drmem_api::{ driver::{self, DriverConfig}, Error, Result, }; -use std::{convert::Infallible, future::Future, sync::Arc}; -use tokio::{sync::Mutex, time}; +use std::{convert::Infallible, future::Future}; +use tokio::time; use tracing::{debug, info}; // This enum represents the four states in which the timer can @@ -239,12 +239,8 @@ impl driver::API for Instance { ))) } - async fn run( - &mut self, - devices: Arc>, - ) -> Infallible { + async fn run(&mut self, devices: &mut Self::HardwareType) -> Infallible { let mut timeout = time::Instant::now(); - let mut devices = devices.lock().await; // Initialize the reported state of the timer. diff --git a/drmemd/src/driver/mod.rs b/drmemd/src/driver/mod.rs index ce9136f..cd8cc13 100644 --- a/drmemd/src/driver/mod.rs +++ b/drmemd/src/driver/mod.rs @@ -1,12 +1,10 @@ use drmem_api::{ - device, driver::{self, Registrator, API}, Result, }; use futures::future::Future; use std::collections::HashMap; use std::{convert::Infallible, pin::Pin, sync::Arc}; -use tokio::sync::Mutex; use tracing::{error, field, info, info_span, warn, Instrument}; mod drv_cycle; @@ -16,142 +14,97 @@ mod drv_memory; mod drv_timer; pub type Fut = Pin + Send>>; -pub type MgrTask = Fut; -pub type MgrFuncRet = Fut>; +pub type MgrTask = Fut>; -pub type Launcher = fn( - driver::Name, - device::Path, - driver::DriverConfig, - driver::RequestChan, - Option, -) -> MgrFuncRet; +pub type Launcher = + fn(driver::DriverConfig, driver::RequestChan, Option) -> MgrTask; type DriverInfo = (&'static str, &'static str, Launcher); // This is the main loop of the driver manager. It only returns if the // driver panics. -fn mgr_body( - name: driver::Name, - devices: T::HardwareType, +async fn mgr_body( + mut devices: T::HardwareType, cfg: driver::DriverConfig, -) -> MgrTask +) -> Infallible where T: API + Send + 'static, { - Box::pin( - async move { - const START_DELAY: u64 = 5; - const MAX_DELAY: u64 = 600; - - let mut restart_delay = START_DELAY; - let devices = Arc::new(Mutex::new(devices)); - - info!("starting instance of driver"); + const START_DELAY: u64 = 5; + const MAX_DELAY: u64 = 600; - loop { - // Create a Future that creates an instance of the driver - // using the provided configuration parameters. + let mut restart_delay = START_DELAY; - let result = T::create_instance(&cfg) - .instrument(info_span!("init", cfg = field::Empty)); + info!("starting instance of driver"); - match result.await { - Ok(mut instance) => { - let devices = devices.clone(); + loop { + // Create a Future that creates an instance of the driver + // using the provided configuration parameters. - restart_delay = START_DELAY; + let result = T::create_instance(&cfg) + .instrument(info_span!("init", cfg = field::Empty)); - // Start the driver instance as a background task - // and monitor the return value. + match result.await { + Ok(mut instance) => { + use futures::FutureExt; + use std::panic::AssertUnwindSafe; - let task = - tokio::spawn( - async move { instance.run(devices).await }, - ); + restart_delay = START_DELAY; - // Drivers are never supposed to exit so the - // JoinHandle will never return an `Ok()` - // value. We can't stop drivers from panicking, - // however, so we have to look for an `Err()` - // value. - // - // (When Rust officially supports the `!` type, we - // will be able to convert this from an - // `if-statement` to a simple assignment.) + // Drivers are never supposed to exit so + // catch_unwind() will only catch panics which means + // we need to only look for `Err(_)` values. - let Err(e) = task.await; + let Err(e) = AssertUnwindSafe(instance.run(&mut devices)) + .catch_unwind() + .await; - error!("driver exited unexpectedly -- {e}") - } - Err(e) => error!("{e}"), - } + error!("exited unexpectedly -- {e:?}") + } + Err(e) => error!("couldn't create instance -- {e}"), + } - // Delay before restarting the driver. This prevents the - // system from being compute-bound if the driver panics right - // away. + // Delay before restarting the driver. This prevents the + // system from being compute-bound if the driver panics right + // away. - warn!("delay before restarting driver ..."); - tokio::time::sleep(tokio::time::Duration::from_secs( - restart_delay, - )) - .await; + warn!("delay before restarting driver ..."); + tokio::time::sleep(tokio::time::Duration::from_secs(restart_delay)) + .await; - // Stretch the timeout each time we have to restart. Set the - // max timeout to 10 minutes. + // Stretch the timeout each time we have to restart. Set the + // max timeout to 10 minutes. - restart_delay = std::cmp::min(restart_delay * 2, MAX_DELAY); - info!("restarting instance of driver"); - } - } - .instrument(info_span!( - "driver", - name = name.as_ref(), - cfg = field::Empty - )), - ) + restart_delay = std::cmp::min(restart_delay * 2, MAX_DELAY); + info!("restarting instance of driver"); + } } // This generic function manages an instance of a specific driver. We // use generics because each driver has a different set of devices -// (T::DeviceSet), so one function wouldn't be able to handle every +// (T::HardwareType), so one function wouldn't be able to handle every // type. fn manage_instance( - name: driver::Name, - prefix: device::Path, cfg: driver::DriverConfig, mut req_chan: driver::RequestChan, max_history: Option, -) -> MgrFuncRet +) -> MgrTask where T: API + Send + 'static, { - // Return a future that returns an error if the devices couldn't - // be registered, or returns a future that manages the running - // instance. - Box::pin(async move { // Let the driver API register the necessary devices. let devices = T::HardwareType::register_devices(&mut req_chan, &cfg, max_history) - .instrument(info_span!("one-time-init", name = name.as_ref())) .await?; // Create a future that manages the instance. - let drv_name = name.clone(); - - Ok( - Box::pin(mgr_body::(name, devices, cfg).instrument(info_span!( - "mngr", - drvr = drv_name.as_ref(), - path = ?prefix - ))) as MgrTask, - ) - }) as MgrFuncRet + Ok(mgr_body::(devices, cfg).await) + }) } #[derive(Clone)] diff --git a/drmemd/src/graphql/mod.rs b/drmemd/src/graphql/mod.rs index 5c5fb99..06b3d47 100644 --- a/drmemd/src/graphql/mod.rs +++ b/drmemd/src/graphql/mod.rs @@ -10,8 +10,7 @@ use juniper_graphql_ws::ConnectionConfig; use juniper_warp::subscriptions::serve_graphql_ws; use libmdns::Responder; use std::{pin::Pin, result, sync::Arc, time::Duration}; -use tracing::{debug, error, info, info_span}; -use tracing_futures::Instrument; +use tracing::{debug, error, info, info_span, Instrument}; use warp::{http::StatusCode, reject, reply, Filter, Rejection, Reply}; pub mod config; diff --git a/drmemd/src/main.rs b/drmemd/src/main.rs index 7c7bd8b..707f086 100644 --- a/drmemd/src/main.rs +++ b/drmemd/src/main.rs @@ -5,7 +5,7 @@ extern crate lazy_static; use drmem_api::{driver::RequestChan, Error, Result}; -use futures::{future, FutureExt}; +use futures::future; use std::{convert::Infallible, sync::Arc}; use tokio::{sync::Barrier, task::JoinHandle}; use tracing::{error, info, warn}; @@ -117,24 +117,15 @@ async fn run() -> Result<()> { // then the devices couldn't be registered or some // other serious error occurred. - if let Ok(instance) = (driver_info.2)( - driver_name, - driver.prefix.clone(), + let instance = (driver_info.2)( driver.cfg.unwrap_or_default().clone(), chan, driver.max_history, - ) - .await - { - // Push the driver instance at the end of the vector. - - tasks.push(wrap_task(tokio::spawn(instance.map(Ok)))) - } else { - error!( - "couldn't prep driver {} with {} prefix", - &driver.name, driver.prefix - ); - } + ); + + // Push the driver instance at the end of the vector. + + tasks.push(wrap_task(tokio::spawn(instance))) } else { error!("no driver named {}", driver.name); return Err(Error::NotFound); @@ -196,6 +187,8 @@ async fn run() -> Result<()> { #[cfg(feature = "graphql")] { + use futures::FutureExt; + info!("starting GraphQL interface"); // This server should never exit. If it does, report an From b1024629e56c906622b3dcc189e88140c3b64e4f Mon Sep 17 00:00:00 2001 From: Rich Neswold Date: Fri, 2 Jan 2026 23:40:01 -0600 Subject: [PATCH 3/4] :memo: organize log messages for drivers --- drmemd/src/driver/mod.rs | 15 +++++++++------ drmemd/src/main.rs | 10 ++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drmemd/src/driver/mod.rs b/drmemd/src/driver/mod.rs index cd8cc13..9132ba7 100644 --- a/drmemd/src/driver/mod.rs +++ b/drmemd/src/driver/mod.rs @@ -36,14 +36,12 @@ where let mut restart_delay = START_DELAY; - info!("starting instance of driver"); - loop { // Create a Future that creates an instance of the driver // using the provided configuration parameters. let result = T::create_instance(&cfg) - .instrument(info_span!("init", cfg = field::Empty)); + .instrument(info_span!("prepping", cfg = field::Empty)); match result.await { Ok(mut instance) => { @@ -56,9 +54,13 @@ where // catch_unwind() will only catch panics which means // we need to only look for `Err(_)` values. - let Err(e) = AssertUnwindSafe(instance.run(&mut devices)) - .catch_unwind() - .await; + let Err(e) = AssertUnwindSafe( + instance + .run(&mut devices) + .instrument(info_span!("running")), + ) + .catch_unwind() + .await; error!("exited unexpectedly -- {e:?}") } @@ -99,6 +101,7 @@ where let devices = T::HardwareType::register_devices(&mut req_chan, &cfg, max_history) + .instrument(info_span!("register", cfg = field::Empty)) .await?; // Create a future that manages the instance. diff --git a/drmemd/src/main.rs b/drmemd/src/main.rs index 707f086..a56dbd0 100644 --- a/drmemd/src/main.rs +++ b/drmemd/src/main.rs @@ -8,7 +8,7 @@ use drmem_api::{driver::RequestChan, Error, Result}; use futures::future; use std::{convert::Infallible, sync::Arc}; use tokio::{sync::Barrier, task::JoinHandle}; -use tracing::{error, info, warn}; +use tracing::{error, info, info_span, warn, Instrument}; mod config; mod core; @@ -125,7 +125,13 @@ async fn run() -> Result<()> { // Push the driver instance at the end of the vector. - tasks.push(wrap_task(tokio::spawn(instance))) + tasks.push(wrap_task(tokio::spawn(instance.instrument( + info_span!( + "driver", + name = driver_name.as_ref(), + prefix = driver.prefix.to_string() + ), + )))) } else { error!("no driver named {}", driver.name); return Err(Error::NotFound); From 297a0a89e318e6e31b2956a438ea8b011ad66df7 Mon Sep 17 00:00:00 2001 From: Rich Neswold Date: Sat, 3 Jan 2026 00:16:25 -0600 Subject: [PATCH 4/4] :sparkles: create `ResettableState` trait If a driver crashes, we need to set the driver channels into a known state. All types returned by the `Registrator` types must implement the `ResettableState` trait. The default implementation is to do nothing. Most types are fine with this. Types that need to do some resetting, can add their reset logic with this trait. --- drivers/drmem-drv-ntp/src/lib.rs | 4 +++- drivers/drmem-drv-sump/src/lib.rs | 4 +++- drmem-api/src/driver/classes/dimmer_type.rs | 2 ++ drmem-api/src/driver/classes/switch_type.rs | 2 ++ drmem-api/src/driver/classes/weather_type.rs | 2 ++ drmem-api/src/driver/mod.rs | 6 +++++- drmem-api/src/driver/rw_device.rs | 5 +++++ drmem-api/src/driver/shared_rw_device.rs | 9 +++++++++ drmemd/src/driver/drv_cycle.rs | 4 +++- drmemd/src/driver/drv_latch.rs | 4 +++- drmemd/src/driver/drv_map.rs | 4 +++- drmemd/src/driver/drv_memory.rs | 4 +++- drmemd/src/driver/drv_timer.rs | 4 +++- drmemd/src/driver/mod.rs | 4 +++- 14 files changed, 49 insertions(+), 9 deletions(-) diff --git a/drivers/drmem-drv-ntp/src/lib.rs b/drivers/drmem-drv-ntp/src/lib.rs index 5e2cc78..211e1b0 100644 --- a/drivers/drmem-drv-ntp/src/lib.rs +++ b/drivers/drmem-drv-ntp/src/lib.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::convert::Infallible; @@ -532,3 +532,5 @@ mod tests { .is_none()); } } + +impl ResettableState for Devices {} diff --git a/drivers/drmem-drv-sump/src/lib.rs b/drivers/drmem-drv-sump/src/lib.rs index e8d8dee..422ad0b 100644 --- a/drivers/drmem-drv-sump/src/lib.rs +++ b/drivers/drmem-drv-sump/src/lib.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::convert::Infallible; @@ -515,3 +515,5 @@ mod tests { assert_eq!(Instance::elapsed(3600000 * 24), "1d0h0m"); } } + +impl ResettableState for Devices {} diff --git a/drmem-api/src/driver/classes/dimmer_type.rs b/drmem-api/src/driver/classes/dimmer_type.rs index b647b6e..d455943 100644 --- a/drmem-api/src/driver/classes/dimmer_type.rs +++ b/drmem-api/src/driver/classes/dimmer_type.rs @@ -68,3 +68,5 @@ impl Registrator for Dimmer { } } } + +impl crate::driver::ResettableState for Dimmer {} diff --git a/drmem-api/src/driver/classes/switch_type.rs b/drmem-api/src/driver/classes/switch_type.rs index 68872e9..167d5c0 100644 --- a/drmem-api/src/driver/classes/switch_type.rs +++ b/drmem-api/src/driver/classes/switch_type.rs @@ -47,3 +47,5 @@ impl Registrator for Switch { } } } + +impl crate::driver::ResettableState for Switch {} diff --git a/drmem-api/src/driver/classes/weather_type.rs b/drmem-api/src/driver/classes/weather_type.rs index 7d61125..034a8aa 100644 --- a/drmem-api/src/driver/classes/weather_type.rs +++ b/drmem-api/src/driver/classes/weather_type.rs @@ -205,3 +205,5 @@ impl Registrator for Weather { } } } + +impl crate::driver::ResettableState for Weather {} diff --git a/drmem-api/src/driver/mod.rs b/drmem-api/src/driver/mod.rs index 5f328fd..558a290 100644 --- a/drmem-api/src/driver/mod.rs +++ b/drmem-api/src/driver/mod.rs @@ -254,6 +254,10 @@ impl RequestChan { } } +pub trait ResettableState { + fn reset_state(&mut self) {} +} + /// A trait which manages details about driver registration. /// /// All drivers will implement a type, or use one of the predefined @@ -261,7 +265,7 @@ impl RequestChan { /// /// The only function in this trait is one to register the device(s) /// with core and return the set of handles. -pub trait Registrator: Sized + Send { +pub trait Registrator: ResettableState + Sized + Send { fn register_devices<'a>( drc: &'a mut RequestChan, cfg: &DriverConfig, diff --git a/drmem-api/src/driver/rw_device.rs b/drmem-api/src/driver/rw_device.rs index 9331280..1cefe23 100644 --- a/drmem-api/src/driver/rw_device.rs +++ b/drmem-api/src/driver/rw_device.rs @@ -102,6 +102,11 @@ where } } +impl super::ResettableState for ReadWriteDevice where + T: device::ReadWriteCompat +{ +} + #[cfg(test)] mod tests { use super::*; diff --git a/drmem-api/src/driver/shared_rw_device.rs b/drmem-api/src/driver/shared_rw_device.rs index a54b7fe..4577bc8 100644 --- a/drmem-api/src/driver/shared_rw_device.rs +++ b/drmem-api/src/driver/shared_rw_device.rs @@ -453,6 +453,15 @@ where } } +impl super::ResettableState for SharedReadWriteDevice +where + T: device::ReadWriteCompat, +{ + fn reset_state(&mut self) { + self.state = State::Unknown + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/drmemd/src/driver/drv_cycle.rs b/drmemd/src/driver/drv_cycle.rs index 05f96ee..a177a6d 100644 --- a/drmemd/src/driver/drv_cycle.rs +++ b/drmemd/src/driver/drv_cycle.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::{convert::Infallible, future::Future}; @@ -315,6 +315,8 @@ impl driver::API for Instance { } } +impl ResettableState for Devices {} + #[cfg(test)] mod tests { use super::*; diff --git a/drmemd/src/driver/drv_latch.rs b/drmemd/src/driver/drv_latch.rs index a6486cc..420f944 100644 --- a/drmemd/src/driver/drv_latch.rs +++ b/drmemd/src/driver/drv_latch.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::{convert::Infallible, future::Future}; @@ -197,6 +197,8 @@ impl driver::API for Instance { } } +impl ResettableState for Devices {} + #[cfg(test)] mod tests { use super::*; diff --git a/drmemd/src/driver/drv_map.rs b/drmemd/src/driver/drv_map.rs index d688aa8..e287d73 100644 --- a/drmemd/src/driver/drv_map.rs +++ b/drmemd/src/driver/drv_map.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::{convert::Infallible, future::Future, ops::RangeInclusive}; @@ -270,6 +270,8 @@ impl driver::API for Instance { } } +impl ResettableState for Devices {} + #[cfg(test)] mod tests { use super::{Entry, Instance}; diff --git a/drmemd/src/driver/drv_memory.rs b/drmemd/src/driver/drv_memory.rs index 0886703..39be103 100644 --- a/drmemd/src/driver/drv_memory.rs +++ b/drmemd/src/driver/drv_memory.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::{convert::Infallible, future::Future}; @@ -235,6 +235,8 @@ impl driver::API for Instance { } } +impl ResettableState for Devices {} + #[cfg(test)] mod tests { use super::TypeChecker; diff --git a/drmemd/src/driver/drv_timer.rs b/drmemd/src/driver/drv_timer.rs index 8737eb7..1393b78 100644 --- a/drmemd/src/driver/drv_timer.rs +++ b/drmemd/src/driver/drv_timer.rs @@ -1,6 +1,6 @@ use drmem_api::{ device, - driver::{self, DriverConfig}, + driver::{self, DriverConfig, ResettableState}, Error, Result, }; use std::{convert::Infallible, future::Future}; @@ -299,6 +299,8 @@ impl driver::API for Instance { } } +impl ResettableState for Devices {} + #[cfg(test)] mod tests { use super::*; diff --git a/drmemd/src/driver/mod.rs b/drmemd/src/driver/mod.rs index 9132ba7..64a8d00 100644 --- a/drmemd/src/driver/mod.rs +++ b/drmemd/src/driver/mod.rs @@ -1,5 +1,5 @@ use drmem_api::{ - driver::{self, Registrator, API}, + driver::{self, Registrator, ResettableState, API}, Result, }; use futures::future::Future; @@ -80,6 +80,8 @@ where restart_delay = std::cmp::min(restart_delay * 2, MAX_DELAY); info!("restarting instance of driver"); + + devices.reset_state(); } }