diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-20 23:09:51 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-20 23:09:51 -0700 |
| commit | 8a06e8a8aae8c77de1d93833edaeed4d9cb5fb1d (patch) | |
| tree | 838ea975e6c275a8ddacdd872bd7a54ea0633572 | |
| parent | 933bf0a30025cc0d2885cfd7c1eb401dd647b1d1 (diff) | |
make stuff async; open /dev/sysmon
Force-Push: yes Change-Id: I65f91e5e7809226d44bc34c99a563a424321b5e5
| -rw-r--r-- | Cargo.lock | 53 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/error.rs | 6 | ||||
| -rw-r--r-- | src/facility.rs | 6 | ||||
| -rw-r--r-- | src/facility/envsys.rs | 7 | ||||
| -rw-r--r-- | src/main.rs | 6 |
6 files changed, 72 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock index a0f1f1b..12cb36e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,17 @@ dependencies = [ ] [[package]] +name = "async-fs" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + +[[package]] name = "async-io" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -47,12 +58,29 @@ dependencies = [ ] [[package]] +name = "async-lock" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] name = "async-task" version = "4.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] name = "autocfg" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -65,6 +93,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] name = "cfg-if" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -204,6 +245,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] name = "pkg-config" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -275,6 +327,7 @@ version = "1.0.0" dependencies = [ "async-channel", "async-executor", + "async-fs", "async-io", "bitflags", "futures-lite", diff --git a/Cargo.toml b/Cargo.toml index a9d2188..8649fd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] async-channel = "2.0.0" +async-fs = "2.0.0" async-io = "2.1.0" futures-lite = "2.0.0" diff --git a/src/error.rs b/src/error.rs index 8537d2e..d6bde2f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,12 @@ impl Display for Error { } } +impl From<std::io::Error> for Error { + fn from(error: std::io::Error) -> Error { + Error(format!("I/O error: {}", error)) + } +} + impl<T> From<std::sync::PoisonError<T>> for Error { fn from(error: std::sync::PoisonError<T>) -> Error { Error(format!("Lock poisoned: {}", error)) diff --git a/src/facility.rs b/src/facility.rs index 824a864..c156570 100644 --- a/src/facility.rs +++ b/src/facility.rs @@ -48,7 +48,7 @@ pub trait CreatableFacility: Facility + Sized { * As far as why the compiler can't reach that conclusion on its own and * skip it, we have no specific information. */ - fn new() -> Result<Self>; + async fn new() -> Result<Self>; /* The only way to coerce to dyn is to return as it! */ fn as_box<'a>(self) -> Box<dyn Facility + 'a> @@ -68,9 +68,9 @@ bitflags! { } impl FacilityType { - pub fn new<'a>(&self) -> Result<Box<dyn Facility + 'a>> { + pub async fn new(&self) -> Result<Box<dyn Facility>> { match self { - &FacilityType::ENVSYS => Ok(EnvSys::new()?.as_box()), + &FacilityType::ENVSYS => Ok(EnvSys::new().await?.as_box()), _ => todo!() } } diff --git a/src/facility/envsys.rs b/src/facility/envsys.rs index b2f632c..34068cc 100644 --- a/src/facility/envsys.rs +++ b/src/facility/envsys.rs @@ -3,8 +3,11 @@ use crate::facility::{ CreatableFacility, Facility, FacilityType }; use std::any::Any; +use async_fs::File; + pub struct EnvSys { + sysmon: File, } impl Facility for EnvSys { @@ -16,10 +19,12 @@ impl Facility for EnvSys { impl CreatableFacility for EnvSys { const FACILITY_TYPE: FacilityType = FacilityType::ENVSYS; - fn new() -> Result<Self> { + async fn new() -> Result<Self> { println!("loading envsys"); + let sysmon = File::open("/dev/sysmon").await?; Ok(EnvSys { + sysmon }) } diff --git a/src/main.rs b/src/main.rs index cffb6bb..8ea3c48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ fn main() -> ExitCode { async fn async_main(_shutdown_sender: Sender<()>) -> Result<()> { let display = Arc::new(Display::new()?); let configuration = DockConfiguration::new(&display)?; - let dock = Dock::new(Arc::clone(&display), configuration)?; + let dock = Dock::new(Arc::clone(&display), configuration).await?; let (redraw_sender, redraw_receiver) = async_channel::unbounded(); let event_task = EXECUTOR.spawn( @@ -141,7 +141,7 @@ impl DockConfiguration { impl Dock { - fn new(display: Arc<Display>, configuration: DockConfiguration) + async fn new(display: Arc<Display>, configuration: DockConfiguration) -> Result<Arc<Mutex<Dock>>> { let screen = display.screen(); @@ -182,7 +182,7 @@ impl Dock { let mut facilities = FacilityMap::new(); for facility_type in required_facilities.iter() { - facilities.insert(facility_type.clone(), facility_type.new()?); + facilities.insert(facility_type.clone(), facility_type.new().await?); } let mut modules = Vec::new(); |