aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2016-09-29 14:23:50 -0700
committermbr0wn <martin.braun@ettus.com>2016-10-13 16:39:54 -0700
commit8d9ae5b37b4f0c5339fffc138332c9afdf65b11d (patch)
treeaa3558edbc8fb028ffa0a6c3fb53086f21f3bba1 /host
parent95c7337c01c53ffab409cd54fc63db1f0d049d64 (diff)
downloaduhd-8d9ae5b37b4f0c5339fffc138332c9afdf65b11d.tar.gz
uhd-8d9ae5b37b4f0c5339fffc138332c9afdf65b11d.tar.bz2
uhd-8d9ae5b37b4f0c5339fffc138332c9afdf65b11d.zip
rfnoc nodes: Disconnect on destruct
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/rfnoc/node_ctrl_base.hpp16
-rw-r--r--host/lib/rfnoc/node_ctrl_base.cpp47
2 files changed, 61 insertions, 2 deletions
diff --git a/host/include/uhd/rfnoc/node_ctrl_base.hpp b/host/include/uhd/rfnoc/node_ctrl_base.hpp
index 82e095b1d..071de803c 100644
--- a/host/include/uhd/rfnoc/node_ctrl_base.hpp
+++ b/host/include/uhd/rfnoc/node_ctrl_base.hpp
@@ -65,6 +65,18 @@ public:
node_map_t list_downstream_nodes() { return _downstream_nodes; };
node_map_t list_upstream_nodes() { return _upstream_nodes; };
+ /*! Disconnect this node from all neighbouring nodes.
+ */
+ void disconnect();
+
+ /*! Identify \p output_port as unconnected
+ */
+ void disconnect_output_port(const size_t output_port);
+
+ /*! Identify \p input_port as unconnected
+ */
+ void disconnect_input_port(const size_t input_port);
+
// TODO we need a more atomic connect procedure, this is too error-prone.
/*! For an existing connection, store the remote port number.
@@ -156,8 +168,8 @@ protected:
/***********************************************************************
* Structors
**********************************************************************/
- node_ctrl_base(void) {};
- virtual ~node_ctrl_base() {};
+ node_ctrl_base(void) {}
+ virtual ~node_ctrl_base() { disconnect(); }
/***********************************************************************
* Protected members
diff --git a/host/lib/rfnoc/node_ctrl_base.cpp b/host/lib/rfnoc/node_ctrl_base.cpp
index 6e19d276a..b4d0a30ff 100644
--- a/host/lib/rfnoc/node_ctrl_base.cpp
+++ b/host/lib/rfnoc/node_ctrl_base.cpp
@@ -17,6 +17,7 @@
#include <uhd/rfnoc/node_ctrl_base.hpp>
#include <uhd/utils/msg.hpp>
+#include <boost/range/adaptor/map.hpp>
using namespace uhd::rfnoc;
@@ -101,3 +102,49 @@ size_t node_ctrl_base::get_upstream_port(const size_t this_port)
return _upstream_ports[this_port];
}
+void node_ctrl_base::disconnect()
+{
+ // Notify neighbours:
+ for (node_map_t::iterator i = _downstream_nodes.begin(); i != _downstream_nodes.end(); ++i) {
+ sptr downstream_node = i->second.lock();
+ if (not downstream_node) {
+ // Actually this is not OK
+ continue;
+ }
+ downstream_node->disconnect_input_port(_downstream_ports[i->first]);
+ }
+ for (node_map_t::iterator i = _upstream_nodes.begin(); i != _upstream_nodes.end(); ++i) {
+ sptr upstream_node = i->second.lock();
+ if (not upstream_node) {
+ // Actually this is not OK
+ continue;
+ }
+ upstream_node->disconnect_output_port(_upstream_ports[i->first]);
+ }
+ // Clear own maps:
+ _downstream_nodes.clear();
+ _downstream_ports.clear();
+ _upstream_nodes.clear();
+ _upstream_ports.clear();
+}
+
+void node_ctrl_base::disconnect_output_port(const size_t output_port)
+{
+ if (_downstream_nodes.count(output_port) == 0 or
+ _downstream_ports.count(output_port) == 0) {
+ throw uhd::assertion_error(str(boost::format("[%s] Attempting to disconnect output port %u, which is not registered as connected!") % unique_id() % output_port));
+ }
+ _downstream_nodes.erase(output_port);
+ _downstream_ports.erase(output_port);
+}
+
+void node_ctrl_base::disconnect_input_port(const size_t input_port)
+{
+ if (_upstream_nodes.count(input_port) == 0 or
+ _upstream_ports.count(input_port) == 0) {
+ throw uhd::assertion_error(str(boost::format("[%s] Attempting to disconnect input port %u, which is not registered as connected!") % unique_id() % input_port));
+ }
+ _upstream_nodes.erase(input_port);
+ _upstream_ports.erase(input_port);
+}
+