diff --git a/zbus/src/object_server/mod.rs b/zbus/src/object_server/mod.rs index 0fee5ca3f..49cd8783b 100644 --- a/zbus/src/object_server/mod.rs +++ b/zbus/src/object_server/mod.rs @@ -194,9 +194,9 @@ impl Node { path, ..Default::default() }; - node.at(Peer::name(), || ArcInterface::new(Peer)); - node.at(Introspectable::name(), || ArcInterface::new(Introspectable)); - node.at(Properties::name(), || ArcInterface::new(Properties)); + debug_assert!(node.add_interface(Peer)); + debug_assert!(node.add_interface(Introspectable)); + debug_assert!(node.add_interface(Properties)); node } @@ -277,6 +277,23 @@ impl Node { self.children.remove(node).is_some() } + fn add_arc_interface(&mut self, name: InterfaceName<'static>, arc_iface: ArcInterface) -> bool { + match self.interfaces.entry(name) { + Entry::Vacant(e) => { + e.insert(arc_iface); + true + } + Entry::Occupied(_) => false, + } + } + + fn add_interface(&mut self, iface: I) -> bool + where + I: Interface, + { + self.add_arc_interface(I::name(), ArcInterface::new(iface)) + } + // Takes a closure so caller can avoid having to create an Arc & RwLock in case interface was // already added. fn at(&mut self, name: InterfaceName<'static>, iface_creator: F) -> bool