From 46889d86d0a0bd08c0dc898278ae1e18aea75716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 22 Feb 2022 11:41:55 +0100 Subject: [PATCH] node: provide an API to fetch port by name Retrieve the port from a node by its name. --- src/graphmanager/node.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/graphmanager/node.rs b/src/graphmanager/node.rs index 0dbea8b..7e12f89 100644 --- a/src/graphmanager/node.rs +++ b/src/graphmanager/node.rs @@ -196,6 +196,19 @@ impl Node { private.ports.borrow().get(&id).cloned() } + /// Get the port with the specified port name inside the node. + /// + /// Returns `None` if the node is not in the graphview. + pub fn port_by_name(&self, name: &str) -> Option { + let private = imp::Node::from_obj(self); + for port in private.ports.borrow().values() { + if port.name() == name { + return Some(port.clone()); + } + } + None + } + /// Check if we can remove a port dependending on PortPrensence attribute /// pub fn can_remove_port(&self, id: u32) -> bool { @@ -239,14 +252,14 @@ impl Node { /// Retrieves the unique name composed with the node name and its id /// pub fn unique_name(&self) -> String { - let private = imp::Node::from_instance(self); + let private = imp::Node::from_obj(self); private.unique_name.borrow().clone() } /// Update the unique name /// pub fn set_unique_name(&self, unique_name: &str) { - let private = imp::Node::from_instance(self); + let private = imp::Node::from_obj(self); private.unique_name.replace(unique_name.to_string()); }