summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/include/gnuradio
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/include/gnuradio')
-rw-r--r--gnuradio-runtime/include/gnuradio/CMakeLists.txt2
-rw-r--r--gnuradio-runtime/include/gnuradio/basic_block.h4
-rw-r--r--gnuradio-runtime/include/gnuradio/block.h2
-rw-r--r--gnuradio-runtime/include/gnuradio/block_gateway.h311
-rw-r--r--gnuradio-runtime/include/gnuradio/feval.h175
-rw-r--r--gnuradio-runtime/include/gnuradio/logger.h5
-rw-r--r--gnuradio-runtime/include/gnuradio/py_feval.h86
7 files changed, 48 insertions, 537 deletions
diff --git a/gnuradio-runtime/include/gnuradio/CMakeLists.txt b/gnuradio-runtime/include/gnuradio/CMakeLists.txt
index 056af5d6f4..d8e9c193ee 100644
--- a/gnuradio-runtime/include/gnuradio/CMakeLists.txt
+++ b/gnuradio-runtime/include/gnuradio/CMakeLists.txt
@@ -23,7 +23,6 @@ install(FILES
constants.h
endianness.h
expj.h
- feval.h
flowgraph.h
fxpt.h
fxpt_nco.h
@@ -42,7 +41,6 @@ install(FILES
msg_queue.h
nco.h
prefs.h
- py_feval.h
pycallback_object.h
random.h
realtime.h
diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h b/gnuradio-runtime/include/gnuradio/basic_block.h
index 651fda2136..47d939a5bc 100644
--- a/gnuradio-runtime/include/gnuradio/basic_block.h
+++ b/gnuradio-runtime/include/gnuradio/basic_block.h
@@ -18,9 +18,9 @@
#include <gnuradio/runtime_types.h>
#include <gnuradio/sptr_magic.h>
#include <gnuradio/thread/thread.h>
-#include <boost/function.hpp>
#include <boost/thread/condition_variable.hpp>
#include <deque>
+#include <functional>
#include <map>
#include <string>
@@ -42,7 +42,7 @@ namespace gr {
class GR_RUNTIME_API basic_block : public msg_accepter,
public std::enable_shared_from_this<basic_block>
{
- typedef boost::function<void(pmt::pmt_t)> msg_handler_t;
+ typedef std::function<void(pmt::pmt_t)> msg_handler_t;
private:
typedef std::map<pmt::pmt_t, msg_handler_t, pmt::comparator> d_msg_handlers_t;
diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h
index 2a47a05715..4f4bfb6953 100644
--- a/gnuradio-runtime/include/gnuradio/block.h
+++ b/gnuradio-runtime/include/gnuradio/block.h
@@ -60,7 +60,7 @@ class GR_RUNTIME_API block : public basic_block
{
public:
//! Magic return values from general_work
- enum { WORK_CALLED_PRODUCE = -2, WORK_DONE = -1 };
+ enum work_return_t { WORK_CALLED_PRODUCE = -2, WORK_DONE = -1 };
/*!
* \brief enum to represent different tag propagation policies.
diff --git a/gnuradio-runtime/include/gnuradio/block_gateway.h b/gnuradio-runtime/include/gnuradio/block_gateway.h
index bcf3a7b27d..d42dfbb620 100644
--- a/gnuradio-runtime/include/gnuradio/block_gateway.h
+++ b/gnuradio-runtime/include/gnuradio/block_gateway.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2011-2013,2017 Free Software Foundation, Inc.
+ * Copyright 2011-2013,2017,2020 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -13,332 +13,107 @@
#include <gnuradio/api.h>
#include <gnuradio/block.h>
-#include <gnuradio/feval.h>
+#include <string>
-namespace gr {
-
-/*!
- * The work type enum tells the gateway what kind of block to
- * implement. The choices are familiar gnuradio block overloads
- * (sync, decim, interp).
- */
-enum block_gw_work_type {
- GR_BLOCK_GW_WORK_GENERAL,
- GR_BLOCK_GW_WORK_SYNC,
- GR_BLOCK_GW_WORK_DECIM,
- GR_BLOCK_GW_WORK_INTERP,
-};
-
-//! Magic return values from general_work, \ref gr::block::WORK_CALLED_PRODUCE
-enum block_gw_work_return_type { 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,
- TPP_CUSTOM = 3
-};
-
-/*!
- * Shared message structure between python and gateway.
- * Each action type represents a scheduler-called function.
- */
-struct block_gw_message_type {
- enum action_type {
- ACTION_GENERAL_WORK, // dispatch work
- ACTION_WORK, // dispatch work
- ACTION_FORECAST, // dispatch forecast
- ACTION_START, // dispatch start
- ACTION_STOP, // dispatch stop
- };
-
- action_type action;
-
- int general_work_args_noutput_items;
- std::vector<int> general_work_args_ninput_items;
- std::vector<void*> general_work_args_input_items; // TODO this should be const void*,
- // but swig can't int cast it right
- std::vector<void*> general_work_args_output_items;
- int general_work_args_return_value;
-
- int work_args_ninput_items;
- int work_args_noutput_items;
- std::vector<void*> work_args_input_items; // TODO this should be const void*, but swig
- // can't int cast it right
- std::vector<void*> work_args_output_items;
- int work_args_return_value;
-
- int forecast_args_noutput_items;
- std::vector<int> forecast_args_ninput_items_required;
-
- bool start_args_return_value;
+#include <pybind11/pybind11.h> // must be first
+#include <pybind11/stl.h>
+namespace py = pybind11;
- bool stop_args_return_value;
-};
+namespace gr {
/*!
* The gateway block which performs all the magic.
*
* The gateway provides access to all the gr::block routines.
- * The methods prefixed with gr::block__ are renamed
- * to class methods without the prefix in python.
*/
+typedef enum {
+ GW_BLOCK_GENERAL = 0,
+ GW_BLOCK_SYNC,
+ GW_BLOCK_DECIM,
+ GW_BLOCK_INTERP
+} gw_block_t;
+
class GR_RUNTIME_API block_gateway : virtual public gr::block
{
+private:
+ py::handle d_py_handle;
+
public:
// gr::block_gateway::sptr
typedef std::shared_ptr<block_gateway> sptr;
/*!
* Make a new gateway block.
- * \param handler the swig director object with callback
+ * \param py_object the pybind11 object with callback
* \param name the name of the block (Ex: "Shirley")
* \param in_sig the input signature for this block
* \param out_sig the output signature for this block
- * \param work_type the type of block overload to implement
- * \param factor the decimation or interpolation factor
* \return a new gateway block
*/
- static sptr make(gr::feval_ll* handler,
+ static sptr make(const py::object& py_handle,
const std::string& name,
gr::io_signature::sptr in_sig,
- gr::io_signature::sptr out_sig,
- const block_gw_work_type work_type,
- const unsigned factor);
-
- //! Provide access to the shared message object
- virtual block_gw_message_type& block_message(void) = 0;
-
- long block__unique_id(void) const { return gr::block::unique_id(); }
-
- std::string block__name(void) const { return gr::block::name(); }
+ gr::io_signature::sptr out_sig);
- unsigned block__history(void) const { return gr::block::history(); }
-
- void block__set_history(unsigned history) { return gr::block::set_history(history); }
-
- void block__set_block_alias(std::string alias)
- {
- return gr::block::set_block_alias(alias);
- }
-
- std::string block__alias(void) const { return gr::block::alias(); }
-
- void block__set_processor_affinity(std::vector<int> mask)
- {
- return gr::block::set_processor_affinity(mask);
- }
-
- void block__set_fixed_rate(bool fixed_rate)
- {
- return gr::block::set_fixed_rate(fixed_rate);
- }
-
- bool block__fixed_rate(void) const { return gr::block::fixed_rate(); }
-
- void block__set_output_multiple(int multiple)
- {
- return gr::block::set_output_multiple(multiple);
- }
-
- void block__set_min_output_buffer(int port, long size)
- {
- return gr::block::set_min_output_buffer(port, size);
- }
-
- void block__set_min_output_buffer(long size)
- {
- return gr::block::set_min_output_buffer(size);
- }
-
- long block__max_output_buffer(size_t i) { return gr::block::max_output_buffer(i); }
-
- void block__set_max_output_buffer(long max_output_buffer)
- {
- gr::block::set_max_output_buffer(max_output_buffer);
- }
-
- void block__set_max_output_buffer(int port, long max_output_buffer)
- {
- gr::block::set_max_output_buffer(port, max_output_buffer);
- }
-
- int block__output_multiple(void) const { return gr::block::output_multiple(); }
-
- void block__consume(int which_input, int how_many_items)
- {
- return gr::block::consume(which_input, how_many_items);
- }
-
- void block__consume_each(int how_many_items)
- {
- return gr::block::consume_each(how_many_items);
- }
- void block__produce(int which_output, int how_many_items)
- {
- return gr::block::produce(which_output, how_many_items);
- }
-
- void block__set_relative_rate(double relative_rate)
- {
- return gr::block::set_relative_rate(relative_rate);
- }
-
- void block__set_inverse_relative_rate(double inverse_relative_rate)
- {
- return gr::block::set_inverse_relative_rate(inverse_relative_rate);
- }
-
- void block__set_relative_rate(uint64_t interpolation, uint64_t decimation)
- {
- return gr::block::set_relative_rate(interpolation, decimation);
- }
-
- double block__relative_rate(void) const { return gr::block::relative_rate(); }
-
- uint64_t block__relative_rate_i(void) const { return gr::block::relative_rate_i(); }
-
- uint64_t block__relative_rate_d(void) const { return gr::block::relative_rate_d(); }
-
- uint64_t block__nitems_read(unsigned int which_input)
- {
- return gr::block::nitems_read(which_input);
- }
-
- uint64_t block__nitems_written(unsigned int which_output)
- {
- return gr::block::nitems_written(which_output);
- }
-
- block::tag_propagation_policy_t block__tag_propagation_policy(void)
- {
- return gr::block::tag_propagation_policy();
- }
-
- void block__set_tag_propagation_policy(block::tag_propagation_policy_t p)
- {
- return gr::block::set_tag_propagation_policy(p);
- }
-
- void block__add_item_tag(unsigned int which_output, const tag_t& tag)
+ // Protected members of gr::block trampolined here for python blocks to use
+ void _add_item_tag(unsigned int which_output, const tag_t& tag)
{
return gr::block::add_item_tag(which_output, tag);
}
- void block__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 _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)
{
return gr::block::add_item_tag(which_output, abs_offset, key, value, srcid);
}
- std::vector<tag_t> block__get_tags_in_range(unsigned int which_input,
- uint64_t abs_start,
- uint64_t abs_end)
+
+ std::vector<tag_t>
+ _get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
{
std::vector<gr::tag_t> tags;
gr::block::get_tags_in_range(tags, which_input, abs_start, abs_end);
return tags;
}
- std::vector<tag_t> block__get_tags_in_range(unsigned int which_input,
- uint64_t abs_start,
- uint64_t abs_end,
- const pmt::pmt_t& key)
+ std::vector<tag_t> _get_tags_in_range(unsigned int which_input,
+ uint64_t abs_start,
+ uint64_t abs_end,
+ const pmt::pmt_t& key)
{
std::vector<gr::tag_t> tags;
gr::block::get_tags_in_range(tags, which_input, abs_start, abs_end, key);
return tags;
}
- std::vector<tag_t> block__get_tags_in_window(unsigned int which_input,
- uint64_t rel_start,
- uint64_t rel_end)
+ std::vector<tag_t>
+ _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end)
{
std::vector<gr::tag_t> tags;
gr::block::get_tags_in_window(tags, which_input, rel_start, rel_end);
return tags;
}
- std::vector<tag_t> block__get_tags_in_window(unsigned int which_input,
- uint64_t rel_start,
- uint64_t rel_end,
- const pmt::pmt_t& key)
+ std::vector<tag_t> _get_tags_in_window(unsigned int which_input,
+ uint64_t rel_start,
+ uint64_t rel_end,
+ const pmt::pmt_t& key)
{
std::vector<gr::tag_t> tags;
gr::block::get_tags_in_window(tags, which_input, rel_start, rel_end, key);
return tags;
}
- /* Message passing interface */
- void block__message_port_register_in(pmt::pmt_t port_id)
- {
- gr::basic_block::message_port_register_in(port_id);
- }
-
- void block__message_port_register_out(pmt::pmt_t port_id)
- {
- gr::basic_block::message_port_register_out(port_id);
- }
-
- void block__message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg)
- {
- gr::basic_block::message_port_pub(port_id, msg);
- }
-
- void block__message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target)
- {
- gr::basic_block::message_port_sub(port_id, target);
- }
-
- void block__message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target)
- {
- gr::basic_block::message_port_unsub(port_id, target);
- }
-
- pmt::pmt_t block__message_subscribers(pmt::pmt_t which_port)
- {
- return gr::basic_block::message_subscribers(which_port);
- }
-
- pmt::pmt_t block__message_ports_in() { return gr::basic_block::message_ports_in(); }
-
- pmt::pmt_t block__message_ports_out() { return gr::basic_block::message_ports_out(); }
-
- void set_msg_handler_feval(pmt::pmt_t which_port, gr::feval_p* msg_handler)
- {
- if (msg_queue.find(which_port) == msg_queue.end()) {
- throw std::runtime_error(
- "attempt to set_msg_handler_feval() on bad input message port!");
- }
- d_msg_handlers_feval[which_port] = msg_handler;
- }
+ virtual void set_msg_handler_pybind(pmt::pmt_t which_port,
+ std::string& handler_name) = 0;
protected:
- typedef std::map<pmt::pmt_t, feval_p*, pmt::comparator> msg_handlers_feval_t;
- msg_handlers_feval_t d_msg_handlers_feval;
-
- bool has_msg_handler(pmt::pmt_t which_port)
- {
- if (d_msg_handlers_feval.find(which_port) != d_msg_handlers_feval.end()) {
- return true;
- } else {
- return gr::basic_block::has_msg_handler(which_port);
- }
- }
-
- void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
- {
- // Is there a handler?
- if (d_msg_handlers_feval.find(which_port) != d_msg_handlers_feval.end()) {
- d_msg_handlers_feval[which_port]->calleval(msg); // Yes, invoke it.
- } else {
- // Pass to generic dispatcher if not found
- gr::basic_block::dispatch_msg(which_port, msg);
- }
- }
+ virtual bool has_msg_handler(pmt::pmt_t which_port) = 0;
+ virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) = 0;
};
} /* namespace gr */
diff --git a/gnuradio-runtime/include/gnuradio/feval.h b/gnuradio-runtime/include/gnuradio/feval.h
deleted file mode 100644
index 0148aea89c..0000000000
--- a/gnuradio-runtime/include/gnuradio/feval.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2006,2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_GR_FEVAL_H
-#define INCLUDED_GR_FEVAL_H
-
-#include <gnuradio/api.h>
-#include <gnuradio/gr_complex.h>
-#include <pmt/pmt.h>
-
-namespace gr {
-
-/*!
- * \brief base class for evaluating a function: double -> double
- * \ingroup misc
- *
- * This class is designed to be subclassed in Python or C++ and is
- * callable from both places. It uses SWIG's "director" feature to
- * implement the magic.
- *
- * It's slow. Don't use it in a performance critical path.
- *
- * Override eval to define the behavior.
- * Use calleval to invoke eval (this kludge is required to allow a
- * python specific "shim" to be inserted.
- */
-class GR_RUNTIME_API feval_dd
-{
-protected:
- /*!
- * \brief override this to define the function
- */
- virtual double eval(double x);
-
-public:
- feval_dd() {}
- virtual ~feval_dd();
-
- virtual double calleval(double x); // invoke "eval"
-};
-
-/*!
- * \brief base class for evaluating a function: complex -> complex
- * \ingroup misc
- *
- * This class is designed to be subclassed in Python or C++ and is
- * callable from both places. It uses SWIG's "director" feature to
- * implement the magic.
- *
- * It's slow. Don't use it in a performance critical path.
- *
- * Override eval to define the behavior.
- * Use calleval to invoke eval (this kludge is required to allow a
- * python specific "shim" to be inserted.
- */
-class GR_RUNTIME_API feval_cc
-{
-protected:
- /*!
- * \brief override this to define the function
- */
- virtual gr_complex eval(gr_complex x);
-
-public:
- feval_cc() {}
- virtual ~feval_cc();
-
- virtual gr_complex calleval(gr_complex x); // invoke "eval"
-};
-
-/*!
- * \brief base class for evaluating a function: long -> long
- * \ingroup misc
- *
- * This class is designed to be subclassed in Python or C++ and is
- * callable from both places. It uses SWIG's "director" feature to
- * implement the magic.
- *
- * It's slow. Don't use it in a performance critical path.
- *
- * Override eval to define the behavior.
- * Use calleval to invoke eval (this kludge is required to allow a
- * python specific "shim" to be inserted.
- */
-class GR_RUNTIME_API feval_ll
-{
-protected:
- /*!
- * \brief override this to define the function
- */
- virtual long eval(long x);
-
-public:
- feval_ll() {}
- virtual ~feval_ll();
-
- virtual long calleval(long x); // invoke "eval"
-};
-
-/*!
- * \brief base class for evaluating a function: void -> void
- * \ingroup misc
- *
- * This class is designed to be subclassed in Python or C++ and is
- * callable from both places. It uses SWIG's "director" feature to
- * implement the magic.
- *
- * It's slow. Don't use it in a performance critical path.
- *
- * Override eval to define the behavior.
- * Use calleval to invoke eval (this kludge is required to allow a
- * python specific "shim" to be inserted.
- */
-class GR_RUNTIME_API feval
-{
-protected:
- /*!
- * \brief override this to define the function
- */
- virtual void eval();
-
-public:
- feval() {}
- virtual ~feval();
-
- virtual void calleval(); // invoke "eval"
-};
-
-/*!
- * \brief base class for evaluating a function: pmt -> void
- * \ingroup misc
- *
- * This class is designed to be subclassed in Python or C++ and is
- * callable from both places. It uses SWIG's "director" feature to
- * implement the magic.
- *
- * It's slow. Don't use it in a performance critical path.
- *
- * Override eval to define the behavior.
- * Use calleval to invoke eval (this kludge is required to allow a
- * python specific "shim" to be inserted.
- */
-class GR_RUNTIME_API feval_p
-{
-protected:
- /*!
- * \brief override this to define the function
- */
- virtual void eval(pmt::pmt_t x);
-
-public:
- feval_p() {}
- virtual ~feval_p();
-
- virtual void calleval(pmt::pmt_t x); // invoke "eval"
-};
-
-/*!
- * \brief trivial examples / test cases showing C++ calling Python code
- */
-GR_RUNTIME_API double feval_dd_example(feval_dd* f, double x);
-GR_RUNTIME_API gr_complex feval_cc_example(feval_cc* f, gr_complex x);
-GR_RUNTIME_API long feval_ll_example(feval_ll* f, long x);
-GR_RUNTIME_API void feval_example(feval* f);
-
-} /* namespace gr */
-
-#endif /* INCLUDED_GR_FEVAL_H */
diff --git a/gnuradio-runtime/include/gnuradio/logger.h b/gnuradio-runtime/include/gnuradio/logger.h
index f2d053c084..2fa0bd6eef 100644
--- a/gnuradio-runtime/include/gnuradio/logger.h
+++ b/gnuradio-runtime/include/gnuradio/logger.h
@@ -352,13 +352,12 @@ private:
void set_config4rpc(std::string set) { printf("Set string was:%s\n", set.c_str()); }
- /*! \brief destructor stops watch thread before exits */
- ~logger_config() { stop_watch(); }
-
/*! \brief Instance getter for singleton. Only used by class. */
static logger_config& get_instance(void);
public:
+ /*! \brief destructor stops watch thread before exits */
+ ~logger_config() { stop_watch(); }
/*! \brief Getter for config filename */
static std::string get_filename();
/*! \brief Getter for watch period */
diff --git a/gnuradio-runtime/include/gnuradio/py_feval.h b/gnuradio-runtime/include/gnuradio/py_feval.h
deleted file mode 100644
index 50af37ec03..0000000000
--- a/gnuradio-runtime/include/gnuradio/py_feval.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2006,2013 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef INCLUDED_GR_PY_FEVAL_H
-#define INCLUDED_GR_PY_FEVAL_H
-
-#include <gnuradio/feval.h>
-#include <Python.h>
-#include <pmt/pmt.h>
-
-class ensure_py_gil_state
-{
- PyGILState_STATE d_gstate;
-
-public:
- ensure_py_gil_state() { d_gstate = PyGILState_Ensure(); }
- ~ensure_py_gil_state() { PyGILState_Release(d_gstate); }
-};
-
-namespace gr {
-
-class GR_RUNTIME_API py_feval_dd : public feval_dd
-{
-public:
- double calleval(double x)
- {
- ensure_py_gil_state _lock;
- return eval(x);
- }
- virtual ~py_feval_dd(){};
-};
-
-class GR_RUNTIME_API py_feval_cc : public feval_cc
-{
-public:
- gr_complex calleval(gr_complex x)
- {
- ensure_py_gil_state _lock;
- return eval(x);
- }
- virtual ~py_feval_cc(){};
-};
-
-class GR_RUNTIME_API py_feval_ll : public feval_ll
-{
-public:
- long calleval(long x)
- {
- ensure_py_gil_state _lock;
- return eval(x);
- }
- virtual ~py_feval_ll(){};
-};
-
-class GR_RUNTIME_API py_feval : public feval
-{
-public:
- void calleval()
- {
- ensure_py_gil_state _lock;
- eval();
- }
- virtual ~py_feval(){};
-};
-
-class GR_RUNTIME_API py_feval_p : public feval_p
-{
-public:
- void calleval(pmt::pmt_t x)
- {
- ensure_py_gil_state _lock;
- eval(x);
- }
- virtual ~py_feval_p(){};
-};
-
-} /* namespace gr */
-
-#endif /* INCLUDED_GR_PY_FEVAL_H */