3 * Copyright 2006,2007,2008 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.
21 #ifndef INCLUDED_MB_MBLOCK_IMPL_H
22 #define INCLUDED_MB_MBLOCK_IMPL_H
24 #include <mblock/mblock.h>
25 #include <mb_runtime_base.h>
26 #include <mb_connection.h>
27 #include <mblock/msg_queue.h>
32 typedef std::map<std::string, mb_port_sptr> mb_port_map_t;
33 typedef std::map<std::string, mb_mblock_sptr> mb_comp_map_t;
37 * \brief The private implementation details of the mblock system.
39 class mb_mblock_impl : boost::noncopyable
41 mb_runtime_base *d_runtime; // pointer to runtime
42 mb_mblock *d_mb; // pointer to our associated mblock
43 mb_mblock *d_mb_parent; // pointer to our parent
45 std::string d_instance_name; // hierarchical name
46 std::string d_class_name; // name of this (derived) class
48 mb_port_map_t d_port_map; // our ports
49 mb_comp_map_t d_comp_map; // our components
50 mb_conn_table d_conn_table; // our connections
52 mb_msg_queue d_msgq; // incoming messages for us
55 mb_mblock_impl(mb_runtime_base *runtime, mb_mblock *mb,
56 const std::string &instance_name);
60 * \brief Define a port.
62 * EXTERNAL and RELAY ports are part of our peer interface.
63 * INTERNAL ports are used to talk to sub-components.
65 * \param port_name The name of the port (must be unique within this mblock).
66 * \param protocol_class_name The name of the protocol class associated with
67 * this port. It must already be defined.
68 * \param conjugated Are the incoming and outgoing message sets swapped?
69 * \param port_type INTERNAL, EXTERNAL or RELAY.
72 define_port(const std::string &port_name,
73 const std::string &protocol_class_name,
75 mb_port::port_type_t port_type);
78 * \brief Define a subcomponent by name.
80 * Called within the constructor to tell the system the
81 * names and identities of our sub-component mblocks.
83 * \param component_name The name of the sub-component (must be unique with this mblock).
84 * \param class_name The class of the instance that is to be created.
85 * \param user_arg The argument to pass to the constructor of the component.
88 define_component(const std::string &component_name,
89 const std::string &class_name,
93 * \brief connect endpoint_1 to endpoint_2
95 * \param comp_name1 component on one end of the connection
96 * \param port_name1 the name of the port on comp1
97 * \param comp_name2 component on the other end of the connection
98 * \param port_name2 the name of the port on comp2
100 * An endpoint is specified by the component's local name (given as
101 * component_name in the call to register_component) and the name of
102 * the port on that component.
104 * To connect an internal or relay port, use "self" as the component name.
107 connect(const std::string &comp_name1, const std::string &port_name1,
108 const std::string &comp_name2, const std::string &port_name2);
111 * \brief disconnect endpoint_1 from endpoint_2
113 * \param comp_name1 component on one end of the connection
114 * \param port_name1 the name of the port on comp1
115 * \param comp_name2 component on the other end of the connection
116 * \param port_name2 the name of the port on comp2
118 * An endpoint is specified by the component's local name (given as
119 * component_name in the call to register_component) and the name of
120 * the port on that component.
122 * To disconnect an internal or relay port, use "self" as the component name.
125 disconnect(const std::string &comp_name1, const std::string &port_name1,
126 const std::string &comp_name2, const std::string &port_name2);
129 * \brief disconnect all connections to specified component
130 * \param component_name component to disconnect
133 disconnect_component(const std::string component_name);
136 * \brief disconnect all connections to all components
142 * \brief Return number of connections (QA mostly)
148 walk_tree(mb_visitor *visitor);
151 make_accepter(pmt_t port_name);
154 msgq() { return d_msgq; }
156 //! Return instance name of this block
157 std::string instance_name() const { return d_instance_name; }
159 //! Set the instance name of this block
160 void set_instance_name(const std::string &name);
162 //! Return the class name of this block
163 std::string class_name() const { return d_class_name; }
165 //! Set the class name
166 void set_class_name(const std::string &name);
169 * \brief If bound, store endpoint from the other end of the connection.
171 * \param port [in] port the port that we're searching for.
172 * \param ep [out] the other end point from the matching connection.
174 * \returns true iff there's a matching connection.
177 lookup_other_endpoint(const mb_port *port, mb_endpoint *ep);
180 //! Return point to associated mblock
181 mb_mblock *mblock() const { return d_mb; }
183 //! Return pointer to the parent of our mblock
184 mb_mblock *mblock_parent() const { return d_mb_parent; }
186 //! Lookup a component by name
187 mb_mblock_sptr component(const std::string &comp_name);
189 //! Return the runtime instance
190 mb_runtime_base *runtime() { return d_runtime; }
192 //! Set the runtime instance
193 void set_runtime(mb_runtime_base *runtime) { d_runtime = runtime; }
196 * Our implementation methods
199 //bool port_is_defined(pmt_t name);
200 bool port_is_defined(const std::string &name);
201 //bool comp_is_defined(pmt_t name);
202 bool comp_is_defined(const std::string &name);
205 check_and_resolve_endpoint(const std::string &comp_name,
206 const std::string &port_name);
210 resolve_port(const std::string &comp_name,
211 const std::string &port_name);
214 endpoints_are_compatible(const mb_endpoint &ep0,
215 const mb_endpoint &ep1);
218 * \brief walk mblock tree and invalidate all port resolution caches.
222 invalidate_all_port_caches();
226 #endif /* INCLUDED_MB_MBLOCK_IMPL_H */