GNU Radio 3.7.2 C++ API
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>
27 #include <gnuradio/basic_block.h>
28 
29 namespace gr {
30 
31  /*!
32  * \brief public constructor for hier_block2
33  */
34  GR_RUNTIME_API hier_block2_sptr
35  make_hier_block2(const std::string &name,
36  gr::io_signature::sptr input_signature,
37  gr::io_signature::sptr output_signature);
38 
39  class hier_block2_detail;
40 
41  /*!
42  * \brief Hierarchical container class for gr::block's and gr::hier_block2's
43  * \ingroup container_blk
44  * \ingroup base_blk
45  */
47  {
48  private:
49  friend class hier_block2_detail;
51  make_hier_block2(const std::string &name,
52  gr::io_signature::sptr input_signature,
53  gr::io_signature::sptr output_signature);
54 
55  /*!
56  * \brief Private implementation details of gr::hier_block2
57  */
58  hier_block2_detail *d_detail;
59 
60  protected:
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 
66  public:
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  */
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  */
85  opaque_self self();
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,
105  basic_block_sptr dst, int dst_port);
106 
107  /*!
108  * \brief Add gr-blocks or hierarchical blocks to internal graph
109  * and wire together
110  *
111  * This adds (if not done earlier by another connect) a pair of
112  * gr-blocks or hierarchical blocks to the internal message port
113  * subscription
114  */
115  void msg_connect(basic_block_sptr src, pmt::pmt_t srcport,
116  basic_block_sptr dst, pmt::pmt_t dstport);
117  void msg_connect(basic_block_sptr src, std::string srcport,
118  basic_block_sptr dst, std::string dstport);
119  void msg_disconnect(basic_block_sptr src, pmt::pmt_t srcport,
120  basic_block_sptr dst, pmt::pmt_t dstport);
121  void msg_disconnect(basic_block_sptr src, std::string srcport,
122  basic_block_sptr dst, std::string dstport);
123 
124  /*!
125  * \brief Remove a gr-block or hierarchical block from the
126  * internal flowgraph.
127  *
128  * This removes a gr-block or hierarchical block from the internal
129  * flowgraph, disconnecting it from other blocks as needed.
130  */
131  void disconnect(basic_block_sptr block);
132 
133  /*!
134  * \brief Disconnect a pair of gr-blocks or hierarchical blocks in
135  * internal flowgraph.
136  *
137  * This disconnects the specified input port from the specified
138  * output port of a pair of gr-blocks or hierarchical blocks.
139  */
140  void disconnect(basic_block_sptr src, int src_port,
141  basic_block_sptr dst, int dst_port);
142 
143  /*!
144  * \brief Disconnect all connections in the internal flowgraph.
145  *
146  * This call removes all output port to input port connections in
147  * the internal flowgraph.
148  */
149  void disconnect_all();
150 
151  /*!
152  * Lock a flowgraph in preparation for reconfiguration. When an
153  * equal number of calls to lock() and unlock() have occurred, the
154  * flowgraph will be reconfigured.
155  *
156  * N.B. lock() and unlock() may not be called from a flowgraph
157  * thread (E.g., gr::block::work method) or deadlock will occur
158  * when reconfiguration happens.
159  */
160  virtual void lock();
161 
162  /*!
163  * Unlock a flowgraph in preparation for reconfiguration. When an
164  * equal number of calls to lock() and unlock() have occurred, the
165  * flowgraph will be reconfigured.
166  *
167  * N.B. lock() and unlock() may not be called from a flowgraph
168  * thread (E.g., gr::block::work method) or deadlock will occur
169  * when reconfiguration happens.
170  */
171  virtual void unlock();
172 
173  // This is a public method for ease of code organization, but should be
174  // ignored by the user.
175  flat_flowgraph_sptr flatten() const;
176 
177  hier_block2_sptr to_hier_block2(); // Needed for Python type coercion
178 
179  bool has_msg_port(pmt::pmt_t which_port) {
180  return message_port_is_hier(which_port) || basic_block::has_msg_port(which_port);
181  }
182 
184  return message_port_is_hier_in(port_id) || message_port_is_hier_out(port_id);
185  }
186 
188  return pmt::list_has(hier_message_ports_in, port_id);
189  }
190 
192  return pmt::list_has(hier_message_ports_out, port_id);
193  }
194 
197 
199  if(pmt::list_has(hier_message_ports_in, port_id))
200  throw std::invalid_argument("hier msg in port by this name already registered");
201  if(msg_queue.find(port_id) != msg_queue.end())
202  throw std::invalid_argument("block already has a primitive input port by this name");
203  hier_message_ports_in = pmt::list_add(hier_message_ports_in, port_id);
204  }
205 
207  if(pmt::list_has(hier_message_ports_out, port_id))
208  throw std::invalid_argument("hier msg out port by this name already registered");
209  if(pmt::dict_has_key(d_message_subscribers, port_id))
210  throw std::invalid_argument("block already has a primitive output port by this name");
211  hier_message_ports_out = pmt::list_add(hier_message_ports_out, port_id);
212  }
213 
214  /*!
215  * \brief Set the affinity of all blocks in hier_block2 to processor core \p n.
216  *
217  * \param mask a vector of ints of the core numbers available to this block.
218  */
219  void set_processor_affinity(const std::vector<int> &mask);
220 
221  /*!
222  * \brief Remove processor affinity for all blocks in hier_block2.
223  */
224  void unset_processor_affinity();
225 
226  /*!
227  * \brief Get the current processor affinity.
228  *
229  * \details This returns the processor affinity value for the first
230  * block in the hier_block2's list of blocks with the assumption
231  * that they have always only been set through the hier_block2's
232  * interface. If any block has been individually set, then this
233  * call could be misleading.
234  */
235  std::vector<int> processor_affinity();
236  };
237 
238  inline hier_block2_sptr cast_to_hier_block2_sptr(basic_block_sptr block) {
239  return boost::dynamic_pointer_cast<hier_block2, basic_block>(block);
240  }
241 
242 } /* namespace gr */
243 
244 #endif /* INCLUDED_GR_RUNTIME_HIER_BLOCK2_H */
void message_port_register_hier_out(pmt::pmt_t port_id)
Definition: hier_block2.h:206
bool message_port_is_hier(pmt::pmt_t port_id)
Definition: hier_block2.h:183
PMT_API bool list_has(pmt_t list, const pmt_t &item)
Return bool of list contains item.
void message_port_register_hier_in(pmt::pmt_t port_id)
Definition: hier_block2.h:198
bool has_msg_port(pmt::pmt_t which_port)
Definition: hier_block2.h:179
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:242
basic_block_sptr opaque_self
typedef for object returned from self().
Definition: hier_block2.h:75
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
thread-safe message queue
Definition: msg_queue.h:36
The abstract base class for all signal processing blocks.Basic blocks are the bare abstraction of an ...
Definition: basic_block.h:58
bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: hier_block2.h:187
bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: hier_block2.h:191
hier_block2(void)
Definition: hier_block2.h:61
pmt::pmt_t hier_message_ports_in
Definition: hier_block2.h:195
pmt::pmt_t hier_message_ports_out
Definition: hier_block2.h:196
PMT_API pmt_t list_add(pmt_t list, const pmt_t &item)
Return list with item added to it.
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
PMT_API bool dict_has_key(const pmt_t &dict, const pmt_t &key)
Return true if key exists in dict.
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
The abstract base class for all 'terminal' processing blocks.A signal processing flow is constructed ...
Definition: block.h:60
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
Hierarchical container class for gr::block's and gr::hier_block2's.
Definition: hier_block2.h:46