GNU Radio 3.6.3.1 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 
155  void gr_block__add_item_tag(
156  unsigned int which_output, const gr_tag_t &tag
157  ){
158  return gr_block::add_item_tag(which_output, tag);
159  }
160 
161  void gr_block__add_item_tag(
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 
193 /*!
194  * Make a new gateway block.
195  * \param handler the swig director object with callback
196  * \param name the name of the block (Ex: "Shirley")
197  * \param in_sig the input signature for this block
198  * \param out_sig the output signature for this block
199  * \param work_type the type of block overload to implement
200  * \param factor the decimation or interpolation factor
201  * \return a new gateway block
202  */
204  gr_feval_ll *handler,
205  const std::string &name,
206  gr_io_signature_sptr in_sig,
207  gr_io_signature_sptr out_sig,
208  const gr_block_gw_work_type work_type,
209  const unsigned factor
210 );
211 
212 #endif /* INCLUDED_GRBLOCK_GATEWAY_H */