diff options
Diffstat (limited to 'gnuradio-runtime/include/gnuradio')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/block.h | 5 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/buffer_double_mapped.h | 21 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/buffer_type.h | 79 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/custom_lock.h | 2 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/host_buffer.h | 11 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/io_signature.h | 3 |
6 files changed, 59 insertions, 62 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h index 5fd1316951..882a0466a8 100644 --- a/gnuradio-runtime/include/gnuradio/block.h +++ b/gnuradio-runtime/include/gnuradio/block.h @@ -540,8 +540,7 @@ public: * that is incompatible with the default buffer type created by this block. * */ - buffer_sptr - replace_buffer(uint32_t src_port, uint32_t dst_port, block_sptr block_owner); + buffer_sptr replace_buffer(size_t src_port, size_t dst_port, block_sptr block_owner); // --------------- Performance counter functions ------------- @@ -943,7 +942,7 @@ protected: * that the downstream max number of items must be passed in to this * function for consideration. */ - buffer_sptr allocate_buffer(int port, + buffer_sptr allocate_buffer(size_t port, int downstream_max_nitems, uint64_t downstream_lcm_nitems, uint32_t downstream_max_out_mult); diff --git a/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h b/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h index d4bfa28ff4..99b85fcc76 100644 --- a/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h +++ b/gnuradio-runtime/include/gnuradio/buffer_double_mapped.h @@ -22,20 +22,6 @@ namespace gr { class vmcircbuf; /*! - * \brief Note this function is only used and really intended to be used in - * qa_buffer.cc for the unit tests of buffer_double_mapped. - * - */ -GR_RUNTIME_API buffer_sptr make_buffer_double_mapped(int nitems, - size_t sizeof_item, - uint64_t downstream_lcm_nitems, - uint32_t downstream_max_out_mult, - block_sptr link = block_sptr(), - block_sptr buf_owner = block_sptr()); - -DEFINE_CUSTOM_BUFFER_TYPE(DEFAULT_NON_CUSTOM, make_buffer_double_mapped); - -/*! * \brief Single writer, multiple reader fifo. * \ingroup internal */ @@ -44,6 +30,13 @@ class GR_RUNTIME_API buffer_double_mapped : public buffer public: static buffer_type type; + static buffer_sptr make_buffer(int nitems, + size_t sizeof_item, + uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, + block_sptr link = block_sptr(), + block_sptr buf_owner = block_sptr()); + gr::logger_ptr d_logger; gr::logger_ptr d_debug_logger; diff --git a/gnuradio-runtime/include/gnuradio/buffer_type.h b/gnuradio-runtime/include/gnuradio/buffer_type.h index b304899750..db8180ead0 100644 --- a/gnuradio-runtime/include/gnuradio/buffer_type.h +++ b/gnuradio-runtime/include/gnuradio/buffer_type.h @@ -18,20 +18,11 @@ #include <functional> #include <mutex> #include <string> +#include <typeinfo> #include <vector> namespace gr { -// This is the function pointer declaration for the factory-like functions -// used to create buffer subclasses -typedef buffer_sptr (*factory_func_ptr)(int nitems, - size_t sizeof_item, - uint64_t downstrea_lcm_nitems, - uint32_t downstream_max_out_mult, - block_sptr link, - block_sptr buf_owner); - - /*! * \brief Base class for describing a buffer's type. */ @@ -45,10 +36,7 @@ public: // Temporarily define copy constructor to work around pybind issue with // default non-copyable function argument - buffer_type_base(buffer_type_base const& other) - : d_name(other.d_name), d_factory(other.d_factory) - { - } + buffer_type_base(buffer_type_base const& other) : d_name(other.d_name) {} void operator=(buffer_type_base const&) = delete; @@ -76,42 +64,55 @@ public: /*! * \brief Make and return a buffer subclass of the corresponding type */ - inline buffer_sptr make_buffer(int nitems, - size_t sizeof_item, - uint64_t downstream_lcm_nitems, - uint32_t downstream_max_out_mult, - block_sptr link, - block_sptr buf_owner) const + virtual buffer_sptr + make_buffer([[maybe_unused]] int nitems, + [[maybe_unused]] size_t sizeof_item, + [[maybe_unused]] uint64_t downstream_lcm_nitems, + [[maybe_unused]] uint32_t downstream_max_out_mult, + [[maybe_unused]] block_sptr link = block_sptr(), + [[maybe_unused]] block_sptr buf_owner = block_sptr()) const { - // Delegate call to factory function - return d_factory(nitems, - sizeof_item, - downstream_lcm_nitems, - downstream_max_out_mult, - link, - buf_owner); + // NOTE: this is *never* intended to be called directly, instead the overridden + // version from a derived class (created from the template below) will be + // called. + return nullptr; } protected: const std::string d_name; - factory_func_ptr d_factory; - // Protected constructor - buffer_type_base(const char* name, factory_func_ptr factory_func) - : d_name(name), d_factory(factory_func) - { - } + buffer_type_base(const std::string name) : d_name(name) {} }; typedef const buffer_type_base& buffer_type; typedef std::vector<std::reference_wrapper<const buffer_type_base>> gr_vector_buffer_type; -#define DEFINE_CUSTOM_BUFFER_TYPE(CLASSNAME, FACTORY_FUNC_PTR) \ - class GR_RUNTIME_API buftype_##CLASSNAME : public buffer_type_base \ - { \ - public: \ - buftype_##CLASSNAME() : buffer_type_base(#CLASSNAME, FACTORY_FUNC_PTR) {} \ - }; +/*! + * \brief Template used to create buffer types. Note that the factory_class parameter + * must contain a static function make_buffer() that matches the signature below + * and will be used to create instances of the corresponding buffer type. + */ +template <typename classname, typename factory_class> +struct buftype : public buffer_type_base { +public: + using factory = factory_class; + buffer_sptr make_buffer(int nitems, + size_t sizeof_item, + uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, + block_sptr link = block_sptr(), + block_sptr buf_owner = block_sptr()) const override + { + return factory::make_buffer(nitems, + sizeof_item, + downstream_lcm_nitems, + downstream_max_out_mult, + link, + buf_owner); + } + + buftype<classname, factory_class>() : buffer_type_base(typeid(classname).name()) {} +}; } // namespace gr diff --git a/gnuradio-runtime/include/gnuradio/custom_lock.h b/gnuradio-runtime/include/gnuradio/custom_lock.h index 5011abe5eb..b8d9ed6d47 100644 --- a/gnuradio-runtime/include/gnuradio/custom_lock.h +++ b/gnuradio-runtime/include/gnuradio/custom_lock.h @@ -67,4 +67,4 @@ private: } /* namespace gr */ -#endif /* INCLUDED_GR_CUSTOM_LOCK_H */
\ No newline at end of file +#endif /* INCLUDED_GR_CUSTOM_LOCK_H */ diff --git a/gnuradio-runtime/include/gnuradio/host_buffer.h b/gnuradio-runtime/include/gnuradio/host_buffer.h index ac09cdfe33..d5b7e2230b 100644 --- a/gnuradio-runtime/include/gnuradio/host_buffer.h +++ b/gnuradio-runtime/include/gnuradio/host_buffer.h @@ -23,6 +23,13 @@ public: static buffer_type type; + static buffer_sptr make_buffer(int nitems, + size_t sizeof_item, + uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, + block_sptr link = block_sptr(), + block_sptr buf_owner = block_sptr()); + virtual ~host_buffer(); /*! @@ -117,10 +124,6 @@ private: block_sptr buf_owner); }; -// See buffer_type.h for details on this macro. It is used here to generate -// compile-time class representing the host_buffer classes "type". -DEFINE_CUSTOM_BUFFER_TYPE(HOST_BUFFER, &host_buffer::make_host_buffer); - } // namespace gr #endif /* INCLUDED_HOST_BUFFER_H */ diff --git a/gnuradio-runtime/include/gnuradio/io_signature.h b/gnuradio-runtime/include/gnuradio/io_signature.h index 60ac798f79..5424e506ff 100644 --- a/gnuradio-runtime/include/gnuradio/io_signature.h +++ b/gnuradio-runtime/include/gnuradio/io_signature.h @@ -123,7 +123,8 @@ public: * * \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 + * infinite) + * \param sizeof_stream_items specify the size of the items in the streams * \param buftypes the type of buffer each stream will should use * * If there are more streams than there are entries in |