3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <mb_connection.h>
29 mb_conn_table::lookup_conn_by_name(const std::string &component_name,
30 const std::string &port_name,
31 mb_conn_iter *itp, int *which_ep)
33 mb_conn_iter end = d_connections.end();
34 for (mb_conn_iter it = d_connections.begin(); it != end; ++it){
36 if (it->d_ep[0].component_name() == component_name
37 && it->d_ep[0].port_name() == port_name){
43 if (it->d_ep[1].component_name() == component_name
44 && it->d_ep[1].port_name() == port_name){
55 mb_conn_table::lookup_conn_by_port(const mb_port *port,
56 mb_conn_iter *itp, int *which_ep)
58 mb_conn_iter end = d_connections.end();
59 for (mb_conn_iter it = d_connections.begin(); it != end; ++it){
60 if (it->d_ep[0].port().get() == port){
65 if (it->d_ep[1].port().get() == port){
76 mb_conn_table::create_conn(const mb_endpoint &ep0, const mb_endpoint &ep1)
78 d_connections.push_back(mb_connection(ep0, ep1));
82 mb_conn_table::disconnect(const std::string &comp_name1, const std::string &port_name1,
83 const std::string &comp_name2, const std::string &port_name2)
88 // look for comp_name1/port_name1
89 bool found = lookup_conn_by_name(comp_name1, port_name1, &it, &which_ep);
91 if (!found) // no error if not found
94 // FIXME if/when we do replicated ports, we may have one-to-many,
95 // or many-to-many bindings. For now, be paranoid
96 assert(it->d_ep[which_ep^1].component_name() == comp_name2);
97 assert(it->d_ep[which_ep^1].port_name() == port_name2);
99 d_connections.erase(it); // Poof!
103 mb_conn_table::disconnect_component(const std::string component_name)
106 mb_conn_iter end = d_connections.end();
107 for (mb_conn_iter it = d_connections.begin(); it != end; it = next){
108 if (it->d_ep[0].component_name() == component_name
109 || it->d_ep[1].component_name() == component_name)
110 next = d_connections.erase(it); // Poof!
117 mb_conn_table::disconnect_all()
119 d_connections.clear(); // All gone!
123 mb_conn_table::nconnections() const
125 return d_connections.size();