From 94a6bbacbe71894fea83976663c9cfd068acabec Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Sun, 16 Jun 2024 19:27:34 -0600 Subject: [PATCH] User ServiceSet --- odilia/src/tower/handlers.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/odilia/src/tower/handlers.rs b/odilia/src/tower/handlers.rs index 0c125201..b811768f 100644 --- a/odilia/src/tower/handlers.rs +++ b/odilia/src/tower/handlers.rs @@ -45,6 +45,23 @@ where } } +#[derive(Clone)] +pub struct GenericHandlers { + handlers: BTreeMap>>, +} +impl GenericHandlers { + pub fn new() -> Self { + GenericHandlers { + handlers: BTreeMap::new(), + } + } + pub fn add_listener(mut self, svc: BoxCloneService, find: Find) -> Self + where Find: Ord { + self.handlers.entry(find).or_default().push(svc); + self + } +} + type Response = Vec; type Request = Event; type Error = OdiliaError; @@ -55,7 +72,7 @@ type CommandHandler = BoxCloneService; pub struct Handlers { state: Arc, atspi: HashMap<(&'static str, &'static str), ServiceSet>, - command: BTreeMap, + command: BTreeMap>, } impl Handlers { @@ -154,7 +171,7 @@ impl Handlers { let try_cmd_service = try_cmd_layer.layer(state_service); let dn = C::CTYPE; let bs = BoxCloneService::new(try_cmd_service); - self.command.entry(dn).or_insert(bs); + self.command.entry(dn).or_default().push(bs); Self { state: self.state, atspi: self.atspi, command: self.command } } pub fn atspi_listener(mut self, handler: H) -> Self