GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
hier_block2.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2006-2009,2013 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 3, 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
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef INCLUDED_GR_RUNTIME_HIER_BLOCK2_H
24#define INCLUDED_GR_RUNTIME_HIER_BLOCK2_H
25
26#include <gnuradio/api.h>
28
29namespace gr {
30
31/*!
32 * \brief public constructor for hier_block2
33 */
34GR_RUNTIME_API hier_block2_sptr make_hier_block2(const std::string& name,
35 gr::io_signature::sptr input_signature,
36 gr::io_signature::sptr output_signature);
37
38class hier_block2_detail;
39
40/*!
41 * \brief Hierarchical container class for gr::block's and gr::hier_block2's
42 * \ingroup container_blk
43 * \ingroup base_blk
44 */
46{
47private:
48 friend class hier_block2_detail;
49 friend GR_RUNTIME_API hier_block2_sptr
50 make_hier_block2(const std::string& name,
51 gr::io_signature::sptr input_signature,
52 gr::io_signature::sptr output_signature);
53
54 /*!
55 * \brief Private implementation details of gr::hier_block2
56 */
57 hier_block2_detail* d_detail;
58
59
60protected:
61 hier_block2(void) {} // allows pure virtual interface sub-classes
62 hier_block2(const std::string& name,
63 gr::io_signature::sptr input_signature,
64 gr::io_signature::sptr output_signature);
65
66public:
67 virtual ~hier_block2();
68
69 /*!
70 * \brief typedef for object returned from self().
71 *
72 * This type is only guaranteed to be passable to connect and
73 * disconnect. No other assumptions should be made about it.
74 */
75 typedef basic_block_sptr opaque_self;
76
77 /*!
78 * \brief Return an object, representing the current block, which
79 * can be passed to connect.
80 *
81 * The returned object may only be used as an argument to connect
82 * or disconnect. Any other use of self() results in unspecified
83 * (erroneous) behavior.
84 */
86
87 /*!
88 * \brief Add a stand-alone (possibly hierarchical) block to
89 * internal graph
90 *
91 * This adds a gr-block or hierarchical block to the internal
92 * graph without wiring it to anything else.
93 */
94 void connect(basic_block_sptr block);
95
96 /*!
97 * \brief Add gr-blocks or hierarchical blocks to internal graph
98 * and wire together
99 *
100 * This adds (if not done earlier by another connect) a pair of
101 * gr-blocks or hierarchical blocks to the internal flowgraph, and
102 * wires the specified output port to the specified input port.
103 */
104 void connect(basic_block_sptr src, int src_port, basic_block_sptr dst, int dst_port);
105
106 /*!
107 * \brief Add gr-blocks or hierarchical blocks to internal graph
108 * and wire together
109 *
110 * This adds (if not done earlier by another connect) a pair of
111 * gr-blocks or hierarchical blocks to the internal message port
112 * subscription
113 */
114 void msg_connect(basic_block_sptr src,
115 pmt::pmt_t srcport,
116 basic_block_sptr dst,
117 pmt::pmt_t dstport);
118 void msg_connect(basic_block_sptr src,
119 std::string srcport,
120 basic_block_sptr dst,
121 std::string dstport);
122 void msg_disconnect(basic_block_sptr src,
123 pmt::pmt_t srcport,
124 basic_block_sptr dst,
125 pmt::pmt_t dstport);
126 void msg_disconnect(basic_block_sptr src,
127 std::string srcport,
128 basic_block_sptr dst,
129 std::string dstport);
130
131 /*!
132 * \brief Remove a gr-block or hierarchical block from the
133 * internal flowgraph.
134 *
135 * This removes a gr-block or hierarchical block from the internal
136 * flowgraph, disconnecting it from other blocks as needed.
137 */
138 void disconnect(basic_block_sptr block);
139
140 /*!
141 * \brief Disconnect a pair of gr-blocks or hierarchical blocks in
142 * internal flowgraph.
143 *
144 * This disconnects the specified input port from the specified
145 * output port of a pair of gr-blocks or hierarchical blocks.
146 */
147 void
148 disconnect(basic_block_sptr src, int src_port, basic_block_sptr dst, int dst_port);
149
150 /*!
151 * \brief Disconnect all connections in the internal flowgraph.
152 *
153 * This call removes all output port to input port connections in
154 * the internal flowgraph.
155 */
157
158 /*!
159 * Lock a flowgraph in preparation for reconfiguration. When an
160 * equal number of calls to lock() and unlock() have occurred, the
161 * flowgraph will be reconfigured.
162 *
163 * N.B. lock() and unlock() may not be called from a flowgraph
164 * thread (E.g., gr::block::work method) or deadlock will occur
165 * when reconfiguration happens.
166 */
167 virtual void lock();
168
169 /*!
170 * Unlock a flowgraph in preparation for reconfiguration. When an
171 * equal number of calls to lock() and unlock() have occurred, the
172 * flowgraph will be reconfigured.
173 *
174 * N.B. lock() and unlock() may not be called from a flowgraph
175 * thread (E.g., gr::block::work method) or deadlock will occur
176 * when reconfiguration happens.
177 */
178 virtual void unlock();
179
180 /*!
181 * \brief Returns max buffer size (itemcount) on output port \p i.
182 */
183 int max_output_buffer(size_t port = 0);
184
185 /*!
186 * \brief Sets max buffer size (itemcount) on all output ports.
187 */
188 void set_max_output_buffer(int max_output_buffer);
189
190 /*!
191 * \brief Sets max buffer size (itemcount) on output port \p port.
192 */
193 void set_max_output_buffer(size_t port, int max_output_buffer);
194
195 /*!
196 * \brief Returns min buffer size (itemcount) on output port \p i.
197 */
198 int min_output_buffer(size_t port = 0);
199
200 /*!
201 * \brief Sets min buffer size (itemcount) on all output ports.
202 */
203 void set_min_output_buffer(int min_output_buffer);
204
205 /*!
206 * \brief Sets min buffer size (itemcount) on output port \p port.
207 */
208 void set_min_output_buffer(size_t port, int min_output_buffer);
209
210
211 // This is a public method for ease of code organization, but should be
212 // ignored by the user.
213 flat_flowgraph_sptr flatten() const;
214
215 hier_block2_sptr to_hier_block2(); // Needed for Python type coercion
216
217 bool has_msg_port(pmt::pmt_t which_port)
218 {
219 return message_port_is_hier(which_port) || basic_block::has_msg_port(which_port);
220 }
221
223 {
224 return message_port_is_hier_in(port_id) || message_port_is_hier_out(port_id);
225 }
226
228 {
229 return pmt::list_has(hier_message_ports_in, port_id);
230 }
231
233 {
234 return pmt::list_has(hier_message_ports_out, port_id);
235 }
236
239
241 {
242 if (pmt::list_has(hier_message_ports_in, port_id))
243 throw std::invalid_argument(
244 "hier msg in port by this name already registered");
245 if (msg_queue.find(port_id) != msg_queue.end())
246 throw std::invalid_argument(
247 "block already has a primitive input port by this name");
248 hier_message_ports_in = pmt::list_add(hier_message_ports_in, port_id);
249 }
250
252 {
253 if (pmt::list_has(hier_message_ports_out, port_id))
254 throw std::invalid_argument(
255 "hier msg out port by this name already registered");
256 if (pmt::dict_has_key(d_message_subscribers, port_id))
257 throw std::invalid_argument(
258 "block already has a primitive output port by this name");
259 hier_message_ports_out = pmt::list_add(hier_message_ports_out, port_id);
260 }
261
262 /*!
263 * \brief Set the affinity of all blocks in hier_block2 to processor core \p n.
264 *
265 * \param mask a vector of ints of the core numbers available to this block.
266 */
267 void set_processor_affinity(const std::vector<int>& mask);
268
269 /*!
270 * \brief Remove processor affinity for all blocks in hier_block2.
271 */
273
274 /*!
275 * \brief Get the current processor affinity.
276 *
277 * \details This returns the processor affinity value for the first
278 * block in the hier_block2's list of blocks with the assumption
279 * that they have always only been set through the hier_block2's
280 * interface. If any block has been individually set, then this
281 * call could be misleading.
282 */
283 std::vector<int> processor_affinity();
284
285 /*!
286 * \brief Get if all block min buffers should be set.
287 *
288 * \details this returns whether all the block min output buffers
289 * should be set or just the block ports connected to the hier ports.
290 */
292
293 /*!
294 * \brief Get if all block max buffers should be set.
295 *
296 * \details this returns whether all the block max output buffers
297 * should be set or just the block ports connected to the hier ports.
298 */
300};
301
302/*!
303 * \brief Return hierarchical block's flow graph represented in dot language
304 */
305GR_RUNTIME_API std::string dot_graph(hier_block2_sptr hierblock2);
306
307inline hier_block2_sptr cast_to_hier_block2_sptr(basic_block_sptr block)
308{
309 return boost::dynamic_pointer_cast<hier_block2, basic_block>(block);
310}
311
312} /* namespace gr */
313
314#endif /* INCLUDED_GR_RUNTIME_HIER_BLOCK2_H */
The abstract base class for all signal processing blocks.
Definition: basic_block.h:60
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:291
The abstract base class for all 'terminal' processing blocks.
Definition: block.h:66
Hierarchical container class for gr::block's and gr::hier_block2's.
Definition: hier_block2.h:46
void set_max_output_buffer(int max_output_buffer)
Sets max buffer size (itemcount) on all output ports.
virtual ~hier_block2()
bool message_port_is_hier(pmt::pmt_t port_id)
Definition: hier_block2.h:222
void set_max_output_buffer(size_t port, int max_output_buffer)
Sets max buffer size (itemcount) on output port port.
void msg_disconnect(basic_block_sptr src, pmt::pmt_t srcport, basic_block_sptr dst, pmt::pmt_t dstport)
void disconnect_all()
Disconnect all connections in the internal flowgraph.
flat_flowgraph_sptr flatten() const
void msg_disconnect(basic_block_sptr src, std::string srcport, basic_block_sptr dst, std::string dstport)
friend GR_RUNTIME_API hier_block2_sptr make_hier_block2(const std::string &name, gr::io_signature::sptr input_signature, gr::io_signature::sptr output_signature)
public constructor for hier_block2
pmt::pmt_t hier_message_ports_out
Definition: hier_block2.h:238
void disconnect(basic_block_sptr block)
Remove a gr-block or hierarchical block from the internal flowgraph.
opaque_self self()
Return an object, representing the current block, which can be passed to connect.
void unset_processor_affinity()
Remove processor affinity for all blocks in hier_block2.
bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: hier_block2.h:227
void set_min_output_buffer(int min_output_buffer)
Sets min buffer size (itemcount) on all output ports.
hier_block2(const std::string &name, gr::io_signature::sptr input_signature, gr::io_signature::sptr output_signature)
std::vector< int > processor_affinity()
Get the current processor affinity.
void set_processor_affinity(const std::vector< int > &mask)
Set the affinity of all blocks in hier_block2 to processor core n.
int max_output_buffer(size_t port=0)
Returns max buffer size (itemcount) on output port i.
void msg_connect(basic_block_sptr src, pmt::pmt_t srcport, basic_block_sptr dst, pmt::pmt_t dstport)
Add gr-blocks or hierarchical blocks to internal graph and wire together.
void connect(basic_block_sptr src, int src_port, basic_block_sptr dst, int dst_port)
Add gr-blocks or hierarchical blocks to internal graph and wire together.
basic_block_sptr opaque_self
typedef for object returned from self().
Definition: hier_block2.h:75
bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: hier_block2.h:232
void disconnect(basic_block_sptr src, int src_port, basic_block_sptr dst, int dst_port)
Disconnect a pair of gr-blocks or hierarchical blocks in internal flowgraph.
hier_block2_sptr to_hier_block2()
void msg_connect(basic_block_sptr src, std::string srcport, basic_block_sptr dst, std::string dstport)
bool all_min_output_buffer_p(void)
Get if all block min buffers should be set.
virtual void lock()
void connect(basic_block_sptr block)
Add a stand-alone (possibly hierarchical) block to internal graph.
void message_port_register_hier_out(pmt::pmt_t port_id)
Definition: hier_block2.h:251
void set_min_output_buffer(size_t port, int min_output_buffer)
Sets min buffer size (itemcount) on output port port.
virtual void unlock()
pmt::pmt_t hier_message_ports_in
Definition: hier_block2.h:237
hier_block2(void)
Definition: hier_block2.h:61
bool all_max_output_buffer_p(void)
Get if all block max buffers should be set.
int min_output_buffer(size_t port=0)
Returns min buffer size (itemcount) on output port i.
bool has_msg_port(pmt::pmt_t which_port)
Definition: hier_block2.h:217
void message_port_register_hier_in(pmt::pmt_t port_id)
Definition: hier_block2.h:240
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:46
thread-safe message queue
Definition: msg_queue.h:37
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
Include this header to use the message passing features.
Definition: basic_block.h:45
GR_RUNTIME_API hier_block2_sptr make_hier_block2(const std::string &name, gr::io_signature::sptr input_signature, gr::io_signature::sptr output_signature)
public constructor for hier_block2
GR_RUNTIME_API std::string dot_graph(hier_block2_sptr hierblock2)
Return hierarchical block's flow graph represented in dot language.
PMT_API bool dict_has_key(const pmt_t &dict, const pmt_t &key)
Return true if key exists in dict.
PMT_API pmt_t list_add(pmt_t list, const pmt_t &item)
Return list with item added to it.
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost....
Definition: pmt.h:56
PMT_API bool list_has(pmt_t list, const pmt_t &item)
Return bool of list contains item.