GNU Radio 3.6.4.2 C++ API
gr_block_gateway.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2012 Free Software Foundation, Inc.
3  *
4  * This file is part of GNU Radio
5  *
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef INCLUDED_GRBLOCK_GATEWAY_H
23 #define INCLUDED_GRBLOCK_GATEWAY_H
24 
25 #include <gr_core_api.h>
26 #include <gr_block.h>
27 #include <gr_feval.h>
28 
29 /*!
30  * The work type enum tells the gateway what kind of block to implement.
31  * The choices are familiar gnuradio block overloads (sync, decim, interp).
32  */
38 };
39 
40 /*!
41  * Shared message structure between python and gateway.
42  * Each action type represents a scheduler-called function.
43  */
46  ACTION_GENERAL_WORK, //dispatch work
47  ACTION_WORK, //dispatch work
48  ACTION_FORECAST, //dispatch forecast
49  ACTION_START, //dispatch start
50  ACTION_STOP, //dispatch stop
51  };
52 
54 
57  std::vector<void *> general_work_args_input_items; //TODO this should be const void*, but swig cant int cast it right
58  std::vector<void *> general_work_args_output_items;
60 
63  std::vector<void *> work_args_input_items; //TODO this should be const void*, but swig cant int cast it right
64  std::vector<void *> work_args_output_items;
66 
69 
71 
73 };
74 
75 /*!
76  * The gateway block which performs all the magic.
77  *
78  * The gateway provides access to all the gr_block routines.
79  * The methods prefixed with gr_block__ are renamed
80  * to class methods without the prefix in python.
81  */
82 class GR_CORE_API gr_block_gateway : virtual public gr_block{
83 public:
84  //! Provide access to the shared message object
85  virtual gr_block_gw_message_type &gr_block_message(void) = 0;
86 
87  long gr_block__unique_id(void) const{
88  return gr_block::unique_id();
89  }
90 
91  std::string gr_block__name(void) const{
92  return gr_block::name();
93  }
94 
95  unsigned gr_block__history(void) const{
96  return gr_block::history();
97  }
98 
99  void gr_block__set_history(unsigned history){
100  return gr_block::set_history(history);
101  }
102 
103  void gr_block__set_fixed_rate(bool fixed_rate){
104  return gr_block::set_fixed_rate(fixed_rate);
105  }
106 
107  bool gr_block__fixed_rate(void) const{
108  return gr_block::fixed_rate();
109  }
110 
111  void gr_block__set_output_multiple(int multiple){
112  return gr_block::set_output_multiple(multiple);
113  }
114 
115  int gr_block__output_multiple(void) const{
116  return gr_block::output_multiple();
117  }
118 
119  void gr_block__consume(int which_input, int how_many_items){
120  return gr_block::consume(which_input, how_many_items);
121  }
122 
123  void gr_block__consume_each(int how_many_items){
124  return gr_block::consume_each(how_many_items);
125  }
126 
127  void gr_block__produce(int which_output, int how_many_items){
128  return gr_block::produce(which_output, how_many_items);
129  }
130 
131  void gr_block__set_relative_rate(double relative_rate){
132  return gr_block::set_relative_rate(relative_rate);
133  }
134 
135  double gr_block__relative_rate(void) const{
136  return gr_block::relative_rate();
137  }
138 
139  uint64_t gr_block__nitems_read(unsigned int which_input){
140  return gr_block::nitems_read(which_input);
141  }
142 
143  uint64_t gr_block__nitems_written(unsigned int which_output){
144  return gr_block::nitems_written(which_output);
145  }
146 
149  }
150 
153  }
154 
156  unsigned int which_output, const gr_tag_t &tag
157  ){
158  return gr_block::add_item_tag(which_output, tag);
159  }
160 
162  unsigned int which_output,
163  uint64_t abs_offset,
164  const pmt::pmt_t &key,
165  const pmt::pmt_t &value,
166  const pmt::pmt_t &srcid=pmt::PMT_F
167  ){
168  return gr_block::add_item_tag(which_output, abs_offset, key, value, srcid);
169  }
170 
171  std::vector<gr_tag_t> gr_block__get_tags_in_range(
172  unsigned int which_input,
173  uint64_t abs_start,
174  uint64_t abs_end
175  ){
176  std::vector<gr_tag_t> tags;
177  gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end);
178  return tags;
179  }
180 
181  std::vector<gr_tag_t> gr_block__get_tags_in_range(
182  unsigned int which_input,
183  uint64_t abs_start,
184  uint64_t abs_end,
185  const pmt::pmt_t &key
186  ){
187  std::vector<gr_tag_t> tags;
188  gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key);
189  return tags;
190  }
191 
192  /* Message passing interface */
195  }
196 
199  }
200 
202  gr_block::message_port_pub(port_id, msg);
203  }
204 
206  gr_block::message_port_sub(port_id, target);
207  }
208 
210  gr_block::message_port_unsub(port_id, target);
211  }
212 
215  }
216 
219  }
220 
221  void set_msg_handler_feval(pmt::pmt_t which_port, gr_feval_p *msg_handler)
222  {
223  if(msg_queue.find(which_port) == msg_queue.end()){
224  throw std::runtime_error("attempt to set_msg_handler_feval() on bad input message port!");
225  }
226  d_msg_handlers_feval[which_port] = msg_handler;
227  }
228 
229 protected:
230  typedef std::map<pmt::pmt_t, gr_feval_p *, pmt::pmt_comperator> msg_handlers_feval_t;
232 
233  void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg){
234  // Is there a handler?
235  if (d_msg_handlers_feval.find(which_port) != d_msg_handlers_feval.end()){
236  d_msg_handlers_feval[which_port]->calleval(msg); // Yes, invoke it.
237  }
238  else {
239  // Pass to generic dispatcher if not found
240  gr_block::dispatch_msg(which_port, msg);
241  }
242  }
243 };
244 
245 /*!
246  * Make a new gateway block.
247  * \param handler the swig director object with callback
248  * \param name the name of the block (Ex: "Shirley")
249  * \param in_sig the input signature for this block
250  * \param out_sig the output signature for this block
251  * \param work_type the type of block overload to implement
252  * \param factor the decimation or interpolation factor
253  * \return a new gateway block
254  */
256  gr_feval_ll *handler,
257  const std::string &name,
258  gr_io_signature_sptr in_sig,
259  gr_io_signature_sptr out_sig,
260  const gr_block_gw_work_type work_type,
261  const unsigned factor
262 );
263 
264 #endif /* INCLUDED_GRBLOCK_GATEWAY_H */
void message_port_register_out(pmt::pmt_t)
Definition: gr_block.h:235
void gr_block__add_item_tag(unsigned int which_output, const gr_tag_t &tag)
Definition: gr_block_gateway.h:155
Definition: gr_block_gateway.h:34
std::string gr_block__name(void) const
Definition: gr_block_gateway.h:91
gr_block_gw_work_type
Definition: gr_block_gateway.h:33
pmt::pmt_t message_ports_out()
Get output message port names.
Definition: gr_block.h:258
bool stop_args_return_value
Definition: gr_block_gateway.h:72
tag_propagation_policy_t
Definition: gr_block.h:193
unsigned history(void) const
long gr_block__unique_id(void) const
Definition: gr_block_gateway.h:87
bool start_args_return_value
Definition: gr_block_gateway.h:70
int general_work_args_return_value
Definition: gr_block_gateway.h:59
GR_CORE_API boost::shared_ptr< gr_block_gateway > gr_make_block_gateway(gr_feval_ll *handler, const std::string &name, gr_io_signature_sptr in_sig, gr_io_signature_sptr out_sig, const gr_block_gw_work_type work_type, const unsigned factor)
uint64_t gr_block__nitems_read(unsigned int which_input)
Definition: gr_block_gateway.h:139
void set_output_multiple(const size_t multiple)
tag_propagation_policy_t tag_propagation_policy(void)
Definition: gr_block_gateway.h:37
std::vector< void * > work_args_input_items
Definition: gr_block_gateway.h:63
GRUEL_API const pmt_t PMT_F
uint64_t nitems_read(const size_t which_input=0)
Get absolute count of all items consumed on the given input port.
Definition: gr_block.h:409
void add_item_tag(const size_t which_output, const gr_tag_t &tag)
void gr_block__set_relative_rate(double relative_rate)
Definition: gr_block_gateway.h:131
Definition: gr_tags.h:28
Definition: gr_block_gateway.h:48
void gr_block__set_fixed_rate(bool fixed_rate)
Definition: gr_block_gateway.h:103
long unique_id(void) const
Definition: gr_block.h:48
gr_block::tag_propagation_policy_t gr_block__tag_propagation_policy(void)
Definition: gr_block_gateway.h:147
std::map< pmt::pmt_t, gr_feval_p *, pmt::pmt_comperator > msg_handlers_feval_t
Definition: gr_block_gateway.h:230
size_t output_multiple(void) const
Get the output multiple setting.
void set_fixed_rate(const bool fixed_rate)
double gr_block__relative_rate(void) const
Definition: gr_block_gateway.h:135
void gr_block__message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target)
Definition: gr_block_gateway.h:209
void gr_block__add_item_tag(unsigned int which_output, uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid=pmt::PMT_F)
Definition: gr_block_gateway.h:161
void set_tag_propagation_policy(tag_propagation_policy_t p)
void gr_block__message_port_register_out(pmt::pmt_t port_id)
Definition: gr_block_gateway.h:197
int forecast_args_noutput_items
Definition: gr_block_gateway.h:67
Definition: gr_block_gateway.h:36
Definition: gr_block.h:37
Definition: gr_block_gateway.h:47
void consume_each(const int how_many_items)
Call during work to consume items.
Definition: gr_block.h:391
void message_port_sub(pmt::pmt_t, pmt::pmt_t)
Definition: gr_block.h:237
void gr_block__set_tag_propagation_policy(gr_block::tag_propagation_policy_t p)
Definition: gr_block_gateway.h:151
pmt::pmt_t gr_block__message_ports_out()
Definition: gr_block_gateway.h:217
void set_history(unsigned history)
Definition: gr_block_gateway.h:50
std::vector< int > general_work_args_ninput_items
Definition: gr_block_gateway.h:56
pmt::pmt_t message_ports_in()
Get input message port names.
Definition: gr_block.h:250
void set_msg_handler_feval(pmt::pmt_t which_port, gr_feval_p *msg_handler)
Definition: gr_block_gateway.h:221
shared_ptr documentation stub
Definition: shared_ptr_docstub.h:15
void gr_block__message_port_register_in(pmt::pmt_t port_id)
Definition: gr_block_gateway.h:193
#define GR_CORE_API
Definition: gr_core_api.h:30
Definition: gr_block_gateway.h:35
void message_port_register_in(pmt::pmt_t)
Definition: gr_block.h:234
unsigned gr_block__history(void) const
Definition: gr_block_gateway.h:95
void gr_block__message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target)
Definition: gr_block_gateway.h:205
void gr_block__set_output_multiple(int multiple)
Definition: gr_block_gateway.h:111
std::vector< gr_tag_t > gr_block__get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt::pmt_t &key)
Definition: gr_block_gateway.h:181
Definition: gr_block_gateway.h:49
int work_args_ninput_items
Definition: gr_block_gateway.h:61
unsigned __int64 uint64_t
Definition: stdint.h:90
pmt::pmt_t gr_block__message_ports_in()
Definition: gr_block_gateway.h:213
void consume(const size_t i, const int how_many_items)
Definition: gr_block.h:397
void get_tags_in_range(std::vector< gr_tag_t > &tags, const size_t which_input, uint64_t abs_start, uint64_t abs_end, const pmt::pmt_t &key=pmt::pmt_t())
int general_work_args_noutput_items
Definition: gr_block_gateway.h:55
Definition: gr_block_gateway.h:44
action_type
Definition: gr_block_gateway.h:45
base class for evaluating a function: long -> longThis class is designed to be subclassed in Python or...
Definition: gr_feval.h:98
void gr_block__consume(int which_input, int how_many_items)
Definition: gr_block_gateway.h:119
int work_args_noutput_items
Definition: gr_block_gateway.h:62
void produce(const size_t o, const int how_many_items)
Definition: gr_block.h:403
void gr_block__message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg)
Definition: gr_block_gateway.h:201
void gr_block__set_history(unsigned history)
Definition: gr_block_gateway.h:99
virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: gr_block.h:315
msg_handlers_feval_t d_msg_handlers_feval
Definition: gr_block_gateway.h:231
std::vector< void * > work_args_output_items
Definition: gr_block_gateway.h:64
base class for evaluating a function: pmt -> voidThis class is designed to be subclassed in Python or ...
Definition: gr_feval.h:154
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
void gr_block__consume_each(int how_many_items)
Definition: gr_block_gateway.h:123
int gr_block__output_multiple(void) const
Definition: gr_block_gateway.h:115
std::vector< int > forecast_args_ninput_items_required
Definition: gr_block_gateway.h:68
std::vector< void * > general_work_args_input_items
Definition: gr_block_gateway.h:57
void set_relative_rate(const double relative_rate)
action_type action
Definition: gr_block_gateway.h:53
void message_port_unsub(pmt::pmt_t, pmt::pmt_t)
Definition: gr_block.h:238
uint64_t nitems_written(const size_t which_output=0)
Get absolute count of all items produced on the given output port.
Definition: gr_block.h:414
bool fixed_rate(void) const
Get the fixed rate setting.
int work_args_return_value
Definition: gr_block_gateway.h:65
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:54
std::vector< void * > general_work_args_output_items
Definition: gr_block_gateway.h:58
bool gr_block__fixed_rate(void) const
Definition: gr_block_gateway.h:107
uint64_t gr_block__nitems_written(unsigned int which_output)
Definition: gr_block_gateway.h:143
double relative_rate(void) const
Get the relative rate setting.
Definition: gr_block_gateway.h:82
void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: gr_block_gateway.h:233
std::vector< gr_tag_t > gr_block__get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
Definition: gr_block_gateway.h:171
void message_port_pub(pmt::pmt_t, pmt::pmt_t)
Definition: gr_block.h:236
void gr_block__produce(int which_output, int how_many_items)
Definition: gr_block_gateway.h:127
Definition: gr_block_gateway.h:46
std::string name(void) const
Definition: gr_block.h:49