diff options
author | Josh Blum | 2013-02-23 01:50:10 -0800 |
---|---|---|
committer | Josh Blum | 2013-02-23 01:50:10 -0800 |
commit | eb05abff6d3ba1f593e3f33fe2eb455d0824a7a4 (patch) | |
tree | ce2468a4013c2038e64a1013ad0f23ad9056619f /gnuradio-core | |
parent | ed4a675c651ebb74904d2e1d4297cdfac0e4f214 (diff) | |
download | gnuradio-eb05abff6d3ba1f593e3f33fe2eb455d0824a7a4.tar.gz gnuradio-eb05abff6d3ba1f593e3f33fe2eb455d0824a7a4.tar.bz2 gnuradio-eb05abff6d3ba1f593e3f33fe2eb455d0824a7a4.zip |
gras: implement io sig ontop of set/get size api
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_vector_map.i | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.cc | 28 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 7 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 20 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_hier_block2.h | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_io_signature.h | 201 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_types.h | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/runtime.i | 31 |
9 files changed, 196 insertions, 103 deletions
diff --git a/gnuradio-core/src/lib/general/gr_vector_map.i b/gnuradio-core/src/lib/general/gr_vector_map.i index e9fa3f27e..5791ce7ae 100644 --- a/gnuradio-core/src/lib/general/gr_vector_map.i +++ b/gnuradio-core/src/lib/general/gr_vector_map.i @@ -23,6 +23,7 @@ GR_SWIG_BLOCK_MAGIC(gr, vector_map); %template() std::vector<size_t>; +%template() std::vector< std::vector<size_t> >; %template() std::vector< std::vector< std::vector<size_t> > >; %include "gr_vector_map.h" diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 6092c4f4e..5f2c317c4 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -60,7 +60,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc - #${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index ed390e71f..bac395a20 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -43,6 +43,34 @@ gr_block::gr_block( this->set_output_signature(output_signature); } +gr_io_signature_sptr gr_block::input_signature(void) const +{ + return _in_sig; +} + +gr_io_signature_sptr gr_block::output_signature(void) const +{ + return _out_sig; +} + +void gr_block::set_input_signature(gr_io_signature_sptr sig) +{ + for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) + { + this->set_input_size(i, sig->sizeof_stream_items().at(i)); + } + _in_sig = sig; +} + +void gr_block::set_output_signature(gr_io_signature_sptr sig) +{ + for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) + { + this->set_output_size(i, sig->sizeof_stream_items().at(i)); + } + _out_sig = sig; +} + gr_block::~gr_block(void) { //NOP diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 0004f887b..6c6480eb4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -54,6 +54,12 @@ struct GR_CORE_API gr_block : gras::Block virtual ~gr_block(void); + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; + + void set_input_signature(gr_io_signature_sptr sig); + void set_output_signature(gr_io_signature_sptr sig); + virtual bool check_topology(int ninputs, int noutputs); //! Overload me! I am the forecast @@ -304,6 +310,7 @@ struct GR_CORE_API gr_block : gras::Block size_t _input_history_items; tag_propagation_policy_t _tag_prop_policy; size_t _interp, _decim; + gr_io_signature_sptr _in_sig, _out_sig; ///////////////// the Block overloads ////////////////////// diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index c43f903a3..2f92d8c6b 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -50,3 +50,23 @@ gr_hier_block2_sptr gr_make_hier_block2( ){ return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } + +gr_io_signature_sptr gr_hier_block2::input_signature(void) const +{ + return _in_sig; +} + +gr_io_signature_sptr gr_hier_block2::output_signature(void) const +{ + return _out_sig; +} + +void gr_hier_block2::set_input_signature(gr_io_signature_sptr sig) +{ + _in_sig = sig; +} + +void gr_hier_block2::set_output_signature(gr_io_signature_sptr sig) +{ + _out_sig = sig; +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 2ab04ac6f..01cecfaf6 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -36,6 +36,14 @@ struct GR_CORE_API gr_hier_block2 : gras::HierBlock { return *this; } + + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; + + void set_input_signature(gr_io_signature_sptr sig); + void set_output_signature(gr_io_signature_sptr sig); + + gr_io_signature_sptr _in_sig, _out_sig; }; typedef boost::shared_ptr<gr_hier_block2> gr_hier_block2_sptr; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 4c1eec4e8..fd1825797 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,84 +1,117 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. - -#ifndef INCLUDED_GNURADIO_GR_IO_SIGNATURE_H -#define INCLUDED_GNURADIO_GR_IO_SIGNATURE_H - -#include <gras/io_signature.hpp> -#include <vector> - -typedef gras::IOSignature gr_io_signature; -typedef gr_io_signature gr_io_signature_sptr; - -inline gr_io_signature_sptr gr_make_io_signature( - int min_streams, - int max_streams, - int sizeof_stream_item -){ - gr_io_signature io_sig(min_streams, max_streams); - - if (io_sig.max_streams() != gr_io_signature::IO_INFINITE) - { - io_sig.resize(io_sig.max_streams(), sizeof_stream_item); - } - else - { - io_sig.resize(1, sizeof_stream_item); - } - - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signature2( - int min_streams, - int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2 -){ - gr_io_signature io_sig(min_streams, max_streams); - io_sig.push_back(sizeof_stream_item1); - io_sig.push_back(sizeof_stream_item2); - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signature3( - int min_streams, - int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2, - int sizeof_stream_item3 -){ - gr_io_signature io_sig(min_streams, max_streams); - io_sig.push_back(sizeof_stream_item1); - io_sig.push_back(sizeof_stream_item2); - io_sig.push_back(sizeof_stream_item3); - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signaturev( - int min_streams, - int max_streams, - const std::vector<int> &sizeof_stream_items -){ - gr_io_signature io_sig(min_streams, max_streams); - for (unsigned i = 0; i < sizeof_stream_items.size(); i++) - { - io_sig.push_back(sizeof_stream_items[i]); - } - return io_sig; -} - -#endif /*INCLUDED_GNURADIO_GR_IO_SIGNATURE_H*/ +/* -*- c++ -*- */ +/* + * Copyright 2004,2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_IO_SIGNATURE_H +#define INCLUDED_IO_SIGNATURE_H + +#include <gr_core_api.h> +#include <gr_runtime_types.h> + +/*! + * \brief Create an i/o signature + * + * \ingroup internal + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item specify the size of the items in each stream + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second stream + * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_items specify the size of the items in the streams + * + * If there are more streams than there are entries in sizeof_stream_items, the + * value of the last entry in sizeof_stream_items is used for the missing values. + * sizeof_stream_items must contain at least 1 entry. + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items); + + +/*! + * \brief i/o signature for input and output ports. + * \brief misc + */ +class GR_CORE_API gr_io_signature { + int d_min_streams; + int d_max_streams; + std::vector<int> d_sizeof_stream_item; + + gr_io_signature(int min_streams, int max_streams, + const std::vector<int> &sizeof_stream_items); + + friend GR_CORE_API gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector<int> &sizeof_stream_items); + + public: + + static const int IO_INFINITE = -1; + + ~gr_io_signature (); + + int min_streams () const { return d_min_streams; } + int max_streams () const { return d_max_streams; } + int sizeof_stream_item (int index) const; + std::vector<int> sizeof_stream_items() const; +}; + + +#endif /* INCLUDED_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index 7b25a6811..a698226bf 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -19,7 +19,6 @@ // this section is to satisfy swig includes for gras.i // since gras.i includes gr_types.h, we only have to edit this file -#include <gras/io_signature.hpp> #include <gras/element.hpp> #include <gras/block.hpp> #include <gras/top_block.hpp> diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 4dff7fabe..29900bdf7 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -26,8 +26,6 @@ #include <gras/block.hpp> #include <gras/hier_block.hpp> #include <gras/top_block.hpp> -#include <gras/io_signature.hpp> -#include <gr_io_signature.h> #include <gr_block.h> #include <gr_top_block.h> #include <gr_hier_block2.h> @@ -40,19 +38,6 @@ %} -%rename(io_signature) gr_make_io_signature; -%rename(io_signature2) gr_make_io_signature2; -%rename(io_signature3) gr_make_io_signature3; -%rename(io_signaturev) gr_make_io_signaturev; - -%include <gr_message.i> -%include <gr_msg_handler.i> -%include <gr_msg_queue.i> -%include <gr_swig_block_magic.i> -%include <gr_io_signature.h> - -#ifdef SW_RUNTIME - //const size types used by blocks in python %constant int sizeof_char = sizeof(char); %constant int sizeof_short = sizeof(short); @@ -61,8 +46,16 @@ %constant int sizeof_double = sizeof(double); %constant int sizeof_gr_complex = sizeof(gr_complex); +%include <gr_message.i> +%include <gr_msg_handler.i> +%include <gr_msg_queue.i> +%include <gr_swig_block_magic.i> +%include <gr_io_signature.i> + +#ifdef SW_RUNTIME + %import <gras/block.i> -%include <gr_io_signature.h> +%include <gr_io_signature.i> %include <gr_block.h> %include <gr_hier_block2.h> %include <gr_top_block.h> @@ -81,7 +74,11 @@ namespace gras struct HierBlock : gras::Element{}; } struct gr_hier_block2 : gras::HierBlock{}; -struct gr_block : gras::Block{}; +struct gr_block : gras::Block +{ + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; +}; struct gr_sync_block : gr_block{}; struct gr_sync_interpolator : gr_sync_block{}; struct gr_sync_decimator : gr_sync_block{}; |