GNU Radio 3.6.0 C++ API
|
00001 /* 00002 * Copyright 2011 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 <gr_core_api.h> 00026 #include <gr_block.h> 00027 00028 /*! 00029 * This handler combined with swig directors allows C++ to call into python. 00030 * The handle() routine must be overloaded in python. 00031 * The call_handle() routine is called from C++. 00032 */ 00033 class GR_CORE_API gr_block_gw_handler{ 00034 protected: 00035 virtual void handle(void); 00036 00037 public: 00038 gr_block_gw_handler(void); 00039 virtual ~gr_block_gw_handler(void); 00040 00041 virtual void call_handle(void); 00042 }; 00043 00044 /*! 00045 * The work type enum tells the gateway what kind of block to implement. 00046 * The choices are familiar gnuradio block overloads (sync, decim, interp). 00047 */ 00048 enum gr_block_gw_work_type{ 00049 GR_BLOCK_GW_WORK_GENERAL, 00050 GR_BLOCK_GW_WORK_SYNC, 00051 GR_BLOCK_GW_WORK_DECIM, 00052 GR_BLOCK_GW_WORK_INTERP, 00053 }; 00054 00055 /*! 00056 * Shared message structure between python and gateway. 00057 * Each action type represents a scheduler-called function. 00058 */ 00059 struct gr_block_gw_message_type{ 00060 enum action_type{ 00061 ACTION_GENERAL_WORK, //dispatch work 00062 ACTION_WORK, //dispatch work 00063 ACTION_FORECAST, //dispatch forecast 00064 ACTION_START, //dispatch start 00065 ACTION_STOP, //dispatch stop 00066 }; 00067 00068 action_type action; 00069 00070 int general_work_args_noutput_items; 00071 std::vector<int> general_work_args_ninput_items; 00072 std::vector<void *> general_work_args_input_items; //TODO this should be const void*, but swig cant int cast it right 00073 std::vector<void *> general_work_args_output_items; 00074 int general_work_args_return_value; 00075 00076 int work_args_ninput_items; 00077 int work_args_noutput_items; 00078 std::vector<void *> work_args_input_items; //TODO this should be const void*, but swig cant int cast it right 00079 std::vector<void *> work_args_output_items; 00080 int work_args_return_value; 00081 00082 int forecast_args_noutput_items; 00083 std::vector<int> forecast_args_ninput_items_required; 00084 00085 bool start_args_return_value; 00086 00087 bool stop_args_return_value; 00088 }; 00089 00090 /*! 00091 * The gateway block which performs all the magic. 00092 * 00093 * The gateway provides access to all the gr_block routines. 00094 * The methods prefixed with gr_block__ are renamed 00095 * to class methods without the prefix in python. 00096 */ 00097 class GR_CORE_API gr_block_gateway : virtual public gr_block{ 00098 public: 00099 //! Provide access to the shared message object 00100 virtual gr_block_gw_message_type &gr_block_message(void) = 0; 00101 00102 long gr_block__unique_id(void) const{ 00103 return gr_block::unique_id(); 00104 } 00105 00106 std::string gr_block__name(void) const{ 00107 return gr_block::name(); 00108 } 00109 00110 unsigned gr_block__history(void) const{ 00111 return gr_block::history(); 00112 } 00113 00114 void gr_block__set_history(unsigned history){ 00115 return gr_block::set_history(history); 00116 } 00117 00118 void gr_block__set_fixed_rate(bool fixed_rate){ 00119 return gr_block::set_fixed_rate(fixed_rate); 00120 } 00121 00122 bool gr_block__fixed_rate(void) const{ 00123 return gr_block::fixed_rate(); 00124 } 00125 00126 void gr_block__set_output_multiple(int multiple){ 00127 return gr_block::set_output_multiple(multiple); 00128 } 00129 00130 int gr_block__output_multiple(void) const{ 00131 return gr_block::output_multiple(); 00132 } 00133 00134 void gr_block__consume(int which_input, int how_many_items){ 00135 return gr_block::consume(which_input, how_many_items); 00136 } 00137 00138 void gr_block__consume_each(int how_many_items){ 00139 return gr_block::consume_each(how_many_items); 00140 } 00141 00142 void gr_block__produce(int which_output, int how_many_items){ 00143 return gr_block::produce(which_output, how_many_items); 00144 } 00145 00146 void gr_block__set_relative_rate(double relative_rate){ 00147 return gr_block::set_relative_rate(relative_rate); 00148 } 00149 00150 double gr_block__relative_rate(void) const{ 00151 return gr_block::relative_rate(); 00152 } 00153 00154 uint64_t gr_block__nitems_read(unsigned int which_input){ 00155 return gr_block::nitems_read(which_input); 00156 } 00157 00158 uint64_t gr_block__nitems_written(unsigned int which_output){ 00159 return gr_block::nitems_written(which_output); 00160 } 00161 00162 gr_block::tag_propagation_policy_t gr_block__tag_propagation_policy(void){ 00163 return gr_block::tag_propagation_policy(); 00164 } 00165 00166 void gr_block__set_tag_propagation_policy(gr_block::tag_propagation_policy_t p){ 00167 return gr_block::set_tag_propagation_policy(p); 00168 } 00169 00170 void gr_block__add_item_tag( 00171 unsigned int which_output, const gr_tag_t &tag 00172 ){ 00173 return gr_block::add_item_tag(which_output, tag); 00174 } 00175 00176 void gr_block__add_item_tag( 00177 unsigned int which_output, 00178 uint64_t abs_offset, 00179 const pmt::pmt_t &key, 00180 const pmt::pmt_t &value, 00181 const pmt::pmt_t &srcid=pmt::PMT_F 00182 ){ 00183 return gr_block::add_item_tag(which_output, abs_offset, key, value, srcid); 00184 } 00185 00186 std::vector<gr_tag_t> gr_block__get_tags_in_range( 00187 unsigned int which_input, 00188 uint64_t abs_start, 00189 uint64_t abs_end 00190 ){ 00191 std::vector<gr_tag_t> tags; 00192 gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end); 00193 return tags; 00194 } 00195 00196 std::vector<gr_tag_t> gr_block__get_tags_in_range( 00197 unsigned int which_input, 00198 uint64_t abs_start, 00199 uint64_t abs_end, 00200 const pmt::pmt_t &key 00201 ){ 00202 std::vector<gr_tag_t> tags; 00203 gr_block::get_tags_in_range(tags, which_input, abs_start, abs_end, key); 00204 return tags; 00205 } 00206 00207 void gr_block__push_msg_queue(const gr_tag_t &msg){ 00208 return gr_block::push_msg_queue(msg); 00209 } 00210 00211 bool gr_block__check_msg_queue(void){ 00212 return gr_block::check_msg_queue(); 00213 } 00214 00215 gr_tag_t gr_block__pop_msg_queue(void){ 00216 return gr_block::pop_msg_queue(); 00217 } 00218 00219 void gr_block__post_msg(const std::string &group, const gr_tag_t &msg){ 00220 return gr_block::post_msg(group, msg); 00221 } 00222 00223 void gr_block__post_msg( 00224 const std::string &group, 00225 const pmt::pmt_t &key, 00226 const pmt::pmt_t &value, 00227 const pmt::pmt_t &srcid=pmt::PMT_F 00228 ){ 00229 return gr_block::post_msg(group, key, value, srcid); 00230 } 00231 00232 }; 00233 00234 /*! 00235 * Make a new gateway block. 00236 * \param handler the swig director object with callback 00237 * \param name the name of the block (Ex: "Shirley") 00238 * \param in_sig the input signature for this block 00239 * \param out_sig the output signature for this block 00240 * \param work_type the type of block overload to implement 00241 * \param factor the decimation or interpolation factor 00242 * \return a new gateway block 00243 */ 00244 GR_CORE_API boost::shared_ptr<gr_block_gateway> gr_make_block_gateway( 00245 gr_block_gw_handler *handler, 00246 const std::string &name, 00247 gr_io_signature_sptr in_sig, 00248 gr_io_signature_sptr out_sig, 00249 const gr_block_gw_work_type work_type, 00250 const unsigned factor 00251 ); 00252 00253 #endif /* INCLUDED_GRBLOCK_GATEWAY_H */