diff options
author | Josh Blum | 2012-08-12 22:32:58 -0700 |
---|---|---|
committer | Josh Blum | 2012-08-26 16:03:50 -0700 |
commit | d9bdc5678c800722c6f83bb4ae35e79b9bca5631 (patch) | |
tree | 50321a0e884627608fb18d1b67d8dea089b38f1c /include | |
parent | 070ba516d25462b464d381d86293cce880452b36 (diff) | |
download | sandhi-d9bdc5678c800722c6f83bb4ae35e79b9bca5631.tar.gz sandhi-d9bdc5678c800722c6f83bb4ae35e79b9bca5631.tar.bz2 sandhi-d9bdc5678c800722c6f83bb4ae35e79b9bca5631.zip |
runtime: more work on the shell stuff
Diffstat (limited to 'include')
-rw-r--r-- | include/gnuradio/block.hpp | 145 | ||||
-rw-r--r-- | include/gnuradio/element.hpp | 42 | ||||
-rw-r--r-- | include/gnuradio/gr_block.h | 62 | ||||
-rw-r--r-- | include/gnuradio/gr_sync_block.h | 0 | ||||
-rw-r--r-- | include/gnuradio/gr_sync_decimator.h | 0 | ||||
-rw-r--r-- | include/gnuradio/gr_sync_interpolator.h | 0 | ||||
-rw-r--r-- | include/gnuradio/hier_block.hpp | 14 | ||||
-rw-r--r-- | include/gnuradio/runtime_api.h | 1 |
8 files changed, 261 insertions, 3 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp index 5011f85..3bddaed 100644 --- a/include/gnuradio/block.hpp +++ b/include/gnuradio/block.hpp @@ -18,14 +18,157 @@ #define INCLUDED_GNURADIO_BLOCK_HPP #include <gnuradio/runtime_api.h> +#include <gnuradio/element.hpp> +#include <gnuradio/tags.hpp> #include <gruel/pmt.h> +#include <vector> namespace gnuradio { -struct GR_RUNTIME_API Block : boost::shared_ptr<ElementImpl> +template <typename PtrType> struct Buffer { + //! get a native pointer type to this buffer + inline PtrType get(void) const + { + return _mem; + } + + //! get a pointer of the desired type to this buffer + template <typename T> inline T cast(void) const + { + return reinterpret_cast<T>(this->get()); + } + + //! get the number of items in this buffer + inline size_t size(void) const + { + return _len; + } + +//private: + PtrType _mem; + size_t _len; +}; + +struct GR_RUNTIME_API Block : Element +{ + enum + { + WORK_CALLED_PRODUCE = -2, + WORK_DONE = -1 + }; + + enum tag_propagation_policy_t + { + TPP_DONT = 0, + TPP_ALL_TO_ALL = 1, + TPP_ONE_TO_ONE = 2 + }; + Block(void); + + /*! + * Set the block's work mode (how it produces and consumes, and the ratio). + * When automatic, consume is automatically called, and forecast handled. + * \param automatic true to call consume and forecast automatically + */ + void set_auto_consume(const bool automatic); + + /******************************************************************* + * Basic routines from basic block + ******************************************************************/ + + long unique_id(void) const; + + std::string name(void) const; + + unsigned history(void) const; + + void set_history(unsigned history); + + void set_output_multiple(int multiple); + + int output_multiple(void) const; + + void consume(int which_input, int how_many_items); + + void consume_each(int how_many_items); + + void produce(int which_output, int how_many_items); + + /*! + * The relative rate can be thought of as interpolation/decimation. + * In other words, relative rate is the ratio of output items to input items. + */ + void set_relative_rate(double relative_rate); + + double relative_rate(void) const; + + /******************************************************************* + * Tag related routines from basic block + ******************************************************************/ + + uint64_t nitems_read(unsigned int which_input); + + uint64_t nitems_written(unsigned int which_output); + + tag_propagation_policy_t tag_propagation_policy(void); + + void set_tag_propagation_policy(tag_propagation_policy_t p); + + void add_item_tag( + unsigned int which_output, const Tag &tag + ); + + void 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 + ); + + void get_tags_in_range( + std::vector<Tag> &tags, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end + ); + + void get_tags_in_range( + std::vector<Tag> &tags, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key + ); + + /******************************************************************* + * Work related routines from basic block + ******************************************************************/ + + //! Called when the flow graph is started, can overload + virtual bool start(void); + + //! Called when the flow graph is stopped, can overload + virtual bool stop(void); + + typedef std::vector<Buffer<const void *> > InputItems; + typedef std::vector<Buffer<void *> > OutputItems; + + //! The official call into the work routine (overload please) + virtual int work( + const InputItems &input_items, + const OutputItems &output_items + ) = 0; + + //! forcast requirements, can be overloaded + virtual void forecast( + int noutput_items, + gr_vector_int &ninput_items_required + ); + }; } //namespace gnuradio diff --git a/include/gnuradio/element.hpp b/include/gnuradio/element.hpp new file mode 100644 index 0000000..15acbd7 --- /dev/null +++ b/include/gnuradio/element.hpp @@ -0,0 +1,42 @@ +// +// 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 io_sig program. If not, see <http://www.gnu.org/licenses/>. + +#ifndef INCLUDED_GNURADIO_ELEMENT_HPP +#define INCLUDED_GNURADIO_ELEMENT_HPP + +#include <gnuradio/runtime_api.h> +#include <gruel/pmt.h> + +namespace gnuradio +{ + +struct GR_RUNTIME_API Element : boost::shared_ptr<ElementImpl> +{ + + //! Create an empty element + Element(void); + + /*! + * Create an element from a shared pointer to an element. + * Good for that factory function/shared ptr paradigm. + */ + Element(const boost::shared_ptr<Element> &elem); + +}; + +} //namespace gnuradio + +#endif /*INCLUDED_GNURADIO_ELEMENT_HPP*/ diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h new file mode 100644 index 0000000..d8e9521 --- /dev/null +++ b/include/gnuradio/gr_block.h @@ -0,0 +1,62 @@ +// +// 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 io_sig program. If not, see <http://www.gnu.org/licenses/>. + +#ifndef INCLUDED_GNURADIO_GR_BLOCK_H +#define INCLUDED_GNURADIO_GR_BLOCK_H + +#include <gnuradio/runtime_api.h> +#include <gnuradio/block.hpp> +#include <gr_io_signature.h> +#include <string> + +struct GR_RUNTIME_API gr_block : gnuradio::Block +{ + + gr_block(void); + + gr_block( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature + ); + + //! implements work -> calls general work + int work( + const InputItems &input_items, + const OutputItems &output_items + ); + + /*! + * \brief compute output items from input items + * + * \param noutput_items number of output items to write on each output stream + * \param ninput_items number of input items available on each input stream + * \param input_items vector of pointers to the input items, one entry per input stream + * \param output_items vector of pointers to the output items, one entry per output stream + * + * \returns number of items actually written to each output stream, or -1 on EOF. + * It is OK to return a value less than noutput_items. -1 <= return value <= noutput_items + * + * general_work must call consume or consume_each to indicate how many items + * were consumed on each input stream. + */ + virtual int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; +}; + +#endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/include/gnuradio/gr_sync_block.h b/include/gnuradio/gr_sync_block.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/include/gnuradio/gr_sync_block.h diff --git a/include/gnuradio/gr_sync_decimator.h b/include/gnuradio/gr_sync_decimator.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/include/gnuradio/gr_sync_decimator.h diff --git a/include/gnuradio/gr_sync_interpolator.h b/include/gnuradio/gr_sync_interpolator.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/include/gnuradio/gr_sync_interpolator.h diff --git a/include/gnuradio/hier_block.hpp b/include/gnuradio/hier_block.hpp index f9633ed..fcb968e 100644 --- a/include/gnuradio/hier_block.hpp +++ b/include/gnuradio/hier_block.hpp @@ -18,15 +18,20 @@ #define INCLUDED_GNURADIO_HIER_BLOCK_HPP #include <gnuradio/runtime_api.h> +#include <gnuradio/element.hpp> #include <gruel/pmt.h> namespace gnuradio { -struct GR_RUNTIME_API HierBlock : boost::shared_ptr<ElementImpl> +struct GR_RUNTIME_API HierBlock : Element { HierBlock(void); + void connect(const Element &elem); + + void disconnect(const Element &elem); + void connect( const Element &src, const size_t src_index, @@ -34,6 +39,13 @@ struct GR_RUNTIME_API HierBlock : boost::shared_ptr<ElementImpl> const size_t sink_index, ); + void disconnect( + const Element &src, + const size_t src_index, + const Element &sink, + const size_t sink_index, + ); + }; } //namespace gnuradio diff --git a/include/gnuradio/runtime_api.h b/include/gnuradio/runtime_api.h index 6f9da05..1f0cc44 100644 --- a/include/gnuradio/runtime_api.h +++ b/include/gnuradio/runtime_api.h @@ -32,7 +32,6 @@ namespace gnuradio { struct ElementImpl; - typedef boost::shared_ptr<ElementImpl> Element; }//namespace gnuradio |