GNU Radio 3.6.0 C++ API
|
00001 /* 00002 * Copyright 2011-2012 Free Software Foundation, Inc. 00003 * 00004 * This file is part of GNU Radio 00005 * 00006 * GNU Radio is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 3, or (at your option) 00009 * any later version. 00010 * 00011 * GNU Radio is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with GNU Radio; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef INCLUDED_GRBLOCK_GATEWAY_H 00023 #define INCLUDED_GRBLOCK_GATEWAY_H 00024 00025 #include <gnuradio/extras/api.h> 00026 #include <gr_block.h> 00027 #include <stdexcept> 00028 #include <gr_feval.h> 00029 00030 /*! 00031 * The work type enum tells the gateway what kind of block to implement. 00032 * The choices are familiar gnuradio block overloads (sync, decim, interp). 00033 */ 00034 enum gr_block_gw_work_type{ 00035 GR_BLOCK_GW_WORK_GENERAL, 00036 GR_BLOCK_GW_WORK_SYNC, 00037 GR_BLOCK_GW_WORK_DECIM, 00038 GR_BLOCK_GW_WORK_INTERP, 00039 }; 00040 00041 /*! 00042 * Shared message structure between python and gateway. 00043 * Each action type represents a scheduler-called function. 00044 */ 00045 struct gr_block_gw_message_type{ 00046 enum action_type{ 00047 ACTION_GENERAL_WORK, //dispatch work 00048 ACTION_WORK, //dispatch work 00049 ACTION_FORECAST, //dispatch forecast 00050 ACTION_START, //dispatch start 00051 ACTION_STOP, //dispatch stop 00052 }; 00053 00054 action_type action; 00055 00056 int general_work_args_noutput_items; 00057 std::vector<int> general_work_args_ninput_items; 00058 std::vector<void *> general_work_args_input_items; //TODO this should be const void*, but swig cant int cast it right 00059 std::vector<void *> general_work_args_output_items; 00060 int general_work_args_return_value; 00061 00062 int work_args_ninput_items; 00063 int work_args_noutput_items; 00064 std::vector<void *> work_args_input_items; //TODO this should be const void*, but swig cant int cast it right 00065 std::vector<void *> work_args_output_items; 00066 int work_args_return_value; 00067 00068 int forecast_args_noutput_items; 00069 std::vector<int> forecast_args_ninput_items_required; 00070 00071 bool start_args_return_value; 00072 00073 bool stop_args_return_value; 00074 }; 00075 00076 /*! 00077 * The gateway block which performs all the magic. 00078 * 00079 * The gateway provides access to all the gr_block routines. 00080 * The methods prefixed with gr_block__ are renamed 00081 * to class methods without the prefix in python. 00082 */ 00083 class GR_EXTRAS_API block_gateway : virtual public gr_block{ 00084 public: 00085 typedef boost::shared_ptr<block_gateway> sptr; 00086 00087 /*! 00088 * Make a new gateway block. 00089 * \param handler the swig director object with callback 00090 * \param name the name of the block (Ex: "Shirley") 00091 * \param in_sig the input signature for this block 00092 * \param out_sig the output signature for this block 00093 * \param work_type the type of block overload to implement 00094 * \param factor the decimation or interpolation factor 00095 * \return a new gateway block 00096 */ 00097 static sptr make( 00098 gr_feval_ll *handler, 00099 const std::string &name, 00100 gr_io_signature_sptr in_sig, 00101 gr_io_signature_sptr out_sig, 00102 const gr_block_gw_work_type work_type, 00103 const unsigned factor 00104 ); 00105 00106 //! Provide access to the shared message object 00107 virtual gr_block_gw_message_type &gr_block_message(void) = 0; 00108 00109 long gr_block__unique_id(void) const{ 00110 return gr_block::unique_id(); 00111 } 00112 00113 std::string gr_block__name(void) const{ 00114 return gr_block::name(); 00115 } 00116 00117 unsigned gr_block__history(void) const{ 00118 return gr_block::history(); 00119 } 00120 00121 void gr_block__set_history(unsigned history){ 00122 return gr_block::set_history(history); 00123 } 00124 00125 void gr_block__set_fixed_rate(bool fixed_rate){ 00126 return gr_block::set_fixed_rate(fixed_rate); 00127 } 00128 00129 bool gr_block__fixed_rate(void) const{ 00130 return gr_block::fixed_rate(); 00131 } 00132 00133 void gr_block__set_output_multiple(int multiple){ 00134 return gr_block::set_output_multiple(multiple); 00135 } 00136 00137 int gr_block__output_multiple(void) const{ 00138 return gr_block::output_multiple(); 00139 } 00140 00141 void gr_block__consume(int which_input, int how_many_items){ 00142 return gr_block::consume(which_input, how_many_items); 00143 } 00144 00145 void gr_block__consume_each(int how_many_items){ 00146 return gr_block::consume_each(how_many_items); 00147 } 00148 00149 void gr_block__produce(int which_output, int how_many_items){ 00150 return gr_block::produce(which_output, how_many_items); 00151 } 00152 00153 void gr_block__set_relative_rate(double relative_rate){ 00154 return gr_block::set_relative_rate(relative_rate); 00155 } 00156 00157 double gr_block__relative_rate(void) const{ 00158 return gr_block::relative_rate(); 00159 } 00160 00161 uint64_t gr_block__nitems_read(unsigned int which_input){ 00162 return gr_block::nitems_read(which_input); 00163 } 00164 00165 uint64_t gr_block__nitems_written(unsigned int which_output){ 00166 return gr_block::nitems_written(which_output); 00167 } 00168 00169 gr_block::tag_propagation_policy_t gr_block__tag_propagation_policy(void){ 00170 return gr_block::tag_propagation_policy(); 00171 } 00172 00173 void gr_block__set_tag_propagation_policy(gr_block::tag_propagation_policy_t p){ 00174 return gr_block::set_tag_propagation_policy(p); 00175 } 00176 00177 void gr_block__add_item_tag( 00178 unsigned int which_output, const gr_tag_t &tag 00179 ){ 00180 return gr_block::add_item_tag(which_output, tag); 00181 } 00182 00183 void gr_block__add_item_tag( 00184 unsigned int which_output, 00185 uint64_t abs_offset, 00186 const pmt::pmt_t &key, 00187 const pmt::pmt_t &value, 00188 const pmt::pmt_t &srcid=pmt::PMT_F 00189 ){ 00190 return gr_block::add_item_tag(which_output, abs_offset, key, value, srcid); 00191 } 00192 00193 std::vector<gr_tag_t> gr_block__get_tags_in_range( 00194 unsigned int which_input, 00195 uint64_t abs_start, 00196 uint64_t abs_end 00197 ){ 00198 std::vector<gr_tag_t> tags; 00199 gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end); 00200 return tags; 00201 } 00202 00203 std::vector<gr_tag_t> gr_block__get_tags_in_range( 00204 unsigned int which_input, 00205 uint64_t abs_start, 00206 uint64_t abs_end, 00207 const pmt::pmt_t &key 00208 ){ 00209 std::vector<gr_tag_t> tags; 00210 gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key); 00211 return tags; 00212 } 00213 00214 void gr_block__push_msg_queue(const gr_tag_t &msg){ 00215 #ifdef HAVE_MSG_PASSING 00216 return gr_block::push_msg_queue(msg); 00217 #else 00218 throw std::runtime_error("not implemented"); 00219 #endif 00220 } 00221 00222 bool gr_block__check_msg_queue(void){ 00223 #ifdef HAVE_MSG_PASSING 00224 return gr_block::check_msg_queue(); 00225 #else 00226 throw std::runtime_error("not implemented"); 00227 #endif 00228 } 00229 00230 gr_tag_t gr_block__pop_msg_queue(void){ 00231 #ifdef HAVE_MSG_PASSING 00232 return gr_block::pop_msg_queue(); 00233 #else 00234 throw std::runtime_error("not implemented"); 00235 #endif 00236 } 00237 00238 void gr_block__post_msg(const std::string &group, const gr_tag_t &msg){ 00239 #ifdef HAVE_MSG_PASSING 00240 return gr_block::post_msg(group, msg); 00241 #else 00242 throw std::runtime_error("not implemented"); 00243 #endif 00244 } 00245 00246 void gr_block__post_msg( 00247 const std::string &group, 00248 const pmt::pmt_t &key, 00249 const pmt::pmt_t &value, 00250 const pmt::pmt_t &srcid=pmt::PMT_F 00251 ){ 00252 #ifdef HAVE_MSG_PASSING 00253 return gr_block::post_msg(group, key, value, srcid); 00254 #else 00255 throw std::runtime_error("not implemented"); 00256 #endif 00257 } 00258 00259 }; 00260 00261 #endif /* INCLUDED_GRBLOCK_GATEWAY_H */