diff options
| -rw-r--r-- | src/facility.rs | 48 | ||||
| -rw-r--r-- | src/facility/envsys.rs | 7 | ||||
| -rw-r--r-- | src/main.rs | 9 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/facility.rs b/src/facility.rs index c156570..dcc252c 100644 --- a/src/facility.rs +++ b/src/facility.rs @@ -21,6 +21,11 @@ pub trait Facility: Any { */ #[allow(dead_code)] fn as_any_mut(&mut self) -> &mut dyn Any; + + /* Frustratingly, this can't be async because that wouldn't be + * dyn-compatible. + */ + fn update(&mut self) -> Result<()>; } /* In order to keep Facility dyn-compatible, we put everything that isn't in @@ -106,5 +111,48 @@ impl FacilityMap { (*facility).as_mut().as_any_mut().downcast_mut() } else { None } } + + pub fn iter(&self) -> impl Iterator<Item=&Box<dyn Facility>> { + let btree_iterator = self.facilities.iter(); + + Iter { btree_iterator } + } + + pub fn iter_mut(&mut self) -> impl Iterator<Item=&mut Box<dyn Facility>> { + let btree_iterator = self.facilities.iter_mut(); + + IterMut { btree_iterator } + } +} + + +struct Iter<'a> { + btree_iterator: std::collections::btree_map + ::Iter<'a, FacilityType, Box<dyn Facility>>, +} + +impl<'a> Iterator for Iter<'a> { + type Item = &'a Box<dyn Facility>; + + fn next(&mut self) -> Option<Self::Item> { + if let Some((_, value)) = self.btree_iterator.next() { + Some(value) + } else { None } + } +} + +struct IterMut<'a> { + btree_iterator: std::collections::btree_map + ::IterMut<'a, FacilityType, Box<dyn Facility>>, +} + +impl<'a> Iterator for IterMut<'a> { + type Item = &'a mut Box<dyn Facility>; + + fn next(&mut self) -> Option<Self::Item> { + if let Some((_, value)) = self.btree_iterator.next() { + Some(value) + } else { None } + } } diff --git a/src/facility/envsys.rs b/src/facility/envsys.rs index 1409cf4..0f5582b 100644 --- a/src/facility/envsys.rs +++ b/src/facility/envsys.rs @@ -7,6 +7,7 @@ use std::ffi::c_void; use std::slice::from_raw_parts; use async_fs::File; +use futures_lite::future; use rustix::ioctl::{ ioctl, Opcode, Getter }; use rustix::ioctl::opcode::read_write; use rustix::mm::munmap; @@ -30,6 +31,12 @@ impl Facility for EnvSys { fn as_any_mut(&mut self) -> &mut dyn Any { self } + + fn update(&mut self) -> Result<()> { + future::block_on(self.refresh_dictionary())?; + + Ok(()) + } } impl CreatableFacility for EnvSys { diff --git a/src/main.rs b/src/main.rs index d7710c7..fa97c35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,6 +344,15 @@ impl Dock { { let mut facilities = self.facilities.lock()?; + /* Before we handle any modules, we update all the facilities. This is + * the easy way to make sure each facility gets updated exactly once per + * frame; making it the modules' responsibility would be more + * bookkeeping, to no purpose. + */ + for facility in facilities.iter_mut() { + facility.update()?; + } + for (module, framing) in &self.modules { let text = { let mut module = module.lock()?; |