c5610eddd2216b1a8b2860d99fc028a0c7cf152d
[debian/gnuradio] / mblock / src / lib / mb_mblock_impl.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
20  */
21 #ifndef INCLUDED_MB_MBLOCK_IMPL_H
22 #define INCLUDED_MB_MBLOCK_IMPL_H
23
24 #include <mb_mblock.h>
25 #include <mb_connection.h>
26 #include <list>
27 #include <map>
28
29
30 typedef std::map<std::string, mb_port_sptr>   mb_port_map_t;
31 typedef std::map<std::string, mb_mblock_sptr> mb_comp_map_t;
32
33
34 /*!
35  * \brief The private implementation details of the mblock system.
36  */
37 class mb_mblock_impl : boost::noncopyable
38 {
39   mb_mblock                    *d_mb;           // pointer to our associated mblock
40
41   mb_port_map_t                 d_port_map;     // our ports
42   mb_comp_map_t                 d_comp_map;     // our components
43   mb_conn_table                 d_conn_table;   // our connections
44
45 public:
46   mb_mblock_impl(mb_mblock *mb);
47   ~mb_mblock_impl();
48
49   /*!
50    * \brief Define a port.
51    *
52    * EXTERNAL and RELAY ports are part of our peer interface.
53    * INTERNAL ports are used to talk to sub-components.
54    *
55    * \param port_name    The name of the port (must be unique within this mblock).
56    * \param protocol_class_name The name of the protocol class associated with
57    *                            this port.  It must already be defined.
58    * \param conjugated   Are the incoming and outgoing message sets swapped?
59    * \param port_type    INTERNAL, EXTERNAL or RELAY.
60    */
61   mb_port_sptr
62   define_port(const std::string &port_name,
63               const std::string &protocol_class_name,
64               bool conjugated,
65               mb_port::port_type_t port_type);
66
67   /*!
68    * \brief Define a subcomponent by name.
69    *
70    * Called within the constructor to tell the system the
71    * names and identities of our sub-component mblocks.
72    *
73    * \param component_name  The name of the sub-component (must be unique with this mblock).
74    * \param component       The sub-component instance.
75    */
76   void
77   define_component(const std::string &component_name,
78                    mb_mblock_sptr component);
79
80   /*!
81    * \brief connect endpoint_1 to endpoint_2
82    *
83    * \param comp_name1  component on one of the connection
84    * \param port_name1  the name of the port on comp1
85    * \param comp_name2  component on the other end the connection
86    * \param port_name2  the name of the port on comp2
87    *
88    * An endpoint is specified by the component's local name (given as
89    * component_name in the call to register_component) and the name of
90    * the port on that component.
91    *
92    * To connect an internal or relay port, use "self" as the component name.
93    */
94   void
95   connect(const std::string &comp_name1, const std::string &port_name1,
96           const std::string &comp_name2, const std::string &port_name2);
97
98   /*!
99    * \brief disconnect endpoint_1 from endpoint_2
100    *
101    * \param comp_name1  component on one of the connection
102    * \param port_name1  the name of the port on comp1
103    * \param comp_name2  component on the other end the connection
104    * \param port_name2  the name of the port on comp2
105    *
106    * An endpoint is specified by the component's local name (given as
107    * component_name in the call to register_component) and the name of
108    * the port on that component.
109    *
110    * To disconnect an internal or relay port, use "self" as the component name.
111    */
112   void
113   disconnect(const std::string &comp_name1, const std::string &port_name1,
114              const std::string &comp_name2, const std::string &port_name2);
115
116   /*!
117    * \brief disconnect all connections to specified component
118    * \param component_name component to disconnect
119    */
120   void
121   disconnect_component(const std::string component_name);
122
123   /*!
124    * \brief disconnect all connections to all components
125    */
126   void
127   disconnect_all();
128
129   /*!
130    * \brief Return number of connections (QA mostly)
131    */
132   int
133   nconnections() const;
134
135   bool
136   walk_tree(mb_visitor *visitor, const std::string &path="");
137   
138   /*
139    * Our implementation methods
140    */
141 private:
142   //bool port_is_defined(pmt_t name);
143   bool port_is_defined(const std::string &name);
144   //bool comp_is_defined(pmt_t name);
145   bool comp_is_defined(const std::string &name);
146
147   mb_endpoint 
148   check_and_resolve_endpoint(const std::string &comp_name,
149                              const std::string &port_name);
150
151
152   mb_port_sptr
153   resolve_port(const std::string &comp_name,
154                const std::string &port_name);
155
156   static bool
157   ports_are_compatible(mb_port_sptr p0, mb_port_sptr p1);
158
159 };
160
161
162 #endif /* INCLUDED_MB_MBLOCK_IMPL_H */