3 * Copyright 2006,2007 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 2, 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.
21 #ifndef INCLUDED_MB_MBLOCK_IMPL_H
22 #define INCLUDED_MB_MBLOCK_IMPL_H
24 #include <mb_mblock.h>
25 #include <mb_connection.h>
26 #include <mb_msg_queue.h>
31 typedef std::map<std::string, mb_port_sptr> mb_port_map_t;
32 typedef std::map<std::string, mb_mblock_sptr> mb_comp_map_t;
36 * \brief The private implementation details of the mblock system.
38 class mb_mblock_impl : boost::noncopyable
40 mb_mblock *d_mb; // pointer to our associated mblock
41 mb_mblock *d_mb_parent; // pointer to our parent
43 std::string d_fullname; // hierarchical name
45 mb_port_map_t d_port_map; // our ports
46 mb_comp_map_t d_comp_map; // our components
47 mb_conn_table d_conn_table; // our connections
49 mb_msg_queue d_msgq; // incoming messages for us
52 mb_mblock_impl(mb_mblock *mb);
56 * \brief Define a port.
58 * EXTERNAL and RELAY ports are part of our peer interface.
59 * INTERNAL ports are used to talk to sub-components.
61 * \param port_name The name of the port (must be unique within this mblock).
62 * \param protocol_class_name The name of the protocol class associated with
63 * this port. It must already be defined.
64 * \param conjugated Are the incoming and outgoing message sets swapped?
65 * \param port_type INTERNAL, EXTERNAL or RELAY.
68 define_port(const std::string &port_name,
69 const std::string &protocol_class_name,
71 mb_port::port_type_t port_type);
74 * \brief Define a subcomponent by name.
76 * Called within the constructor to tell the system the
77 * names and identities of our sub-component mblocks.
79 * \param component_name The name of the sub-component (must be unique with this mblock).
80 * \param component The sub-component instance.
83 define_component(const std::string &component_name,
84 mb_mblock_sptr component);
87 * \brief connect endpoint_1 to endpoint_2
89 * \param comp_name1 component on one end of the connection
90 * \param port_name1 the name of the port on comp1
91 * \param comp_name2 component on the other end of the connection
92 * \param port_name2 the name of the port on comp2
94 * An endpoint is specified by the component's local name (given as
95 * component_name in the call to register_component) and the name of
96 * the port on that component.
98 * To connect an internal or relay port, use "self" as the component name.
101 connect(const std::string &comp_name1, const std::string &port_name1,
102 const std::string &comp_name2, const std::string &port_name2);
105 * \brief disconnect endpoint_1 from endpoint_2
107 * \param comp_name1 component on one end of the connection
108 * \param port_name1 the name of the port on comp1
109 * \param comp_name2 component on the other end of the connection
110 * \param port_name2 the name of the port on comp2
112 * An endpoint is specified by the component's local name (given as
113 * component_name in the call to register_component) and the name of
114 * the port on that component.
116 * To disconnect an internal or relay port, use "self" as the component name.
119 disconnect(const std::string &comp_name1, const std::string &port_name1,
120 const std::string &comp_name2, const std::string &port_name2);
123 * \brief disconnect all connections to specified component
124 * \param component_name component to disconnect
127 disconnect_component(const std::string component_name);
130 * \brief disconnect all connections to all components
136 * \brief Return number of connections (QA mostly)
139 nconnections() const;
142 walk_tree(mb_visitor *visitor, const std::string &path="");
145 make_accepter(const std::string port_name);
148 msgq() { return d_msgq; }
150 //! Return full name of this block
151 std::string fullname() const { return d_fullname; }
153 //! Set the name of this block
154 void set_fullname(const std::string &name);
157 * \brief If bound, store endpoint from the other end of the connection.
159 * \param port [in] port the port that we're searching for.
160 * \param ep [out] the other end point from the matching connection.
162 * \returns true iff there's a matching connection.
165 lookup_other_endpoint(const mb_port *port, mb_endpoint *ep);
169 mblock() const { return d_mb; }
172 mblock_parent() const { return d_mb_parent; }
175 component(const std::string &comp_name);
179 * Our implementation methods
182 //bool port_is_defined(pmt_t name);
183 bool port_is_defined(const std::string &name);
184 //bool comp_is_defined(pmt_t name);
185 bool comp_is_defined(const std::string &name);
188 check_and_resolve_endpoint(const std::string &comp_name,
189 const std::string &port_name);
193 resolve_port(const std::string &comp_name,
194 const std::string &port_name);
197 endpoints_are_compatible(const mb_endpoint &ep0,
198 const mb_endpoint &ep1);
203 #endif /* INCLUDED_MB_MBLOCK_IMPL_H */