summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc
diff options
context:
space:
mode:
authorJosh Morman <mormjb@gmail.com>2020-04-23 07:51:39 -0400
committerJosh Morman <mormjb@gmail.com>2020-06-04 10:05:47 -0400
commitba16fdf0a0e9052163a5dd00b5927b2eccc0683f (patch)
tree59c7f11883e221287bb05802bb37c155549b605d /gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc
parent42fe41b9f2224e09fde9f00426cc6b10ba7b6416 (diff)
runtime: add pybind11 bindings
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc')
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc146
1 files changed, 146 insertions, 0 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc
new file mode 100644
index 0000000000..37ec9e61c8
--- /dev/null
+++ b/gnuradio-runtime/python/gnuradio/gr/bindings/top_block_python.cc
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2020 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+/* This file is automatically generated using bindtool */
+
+#include <pybind11/complex.h>
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+
+namespace py = pybind11;
+
+#include <gnuradio/runtime_types.h>
+#include <gnuradio/top_block.h>
+// pydoc.h is automatically generated in the build directory
+#include <top_block_pydoc.h>
+
+#define GR_PYTHON_BLOCKING_CODE(code) \
+ { \
+ PyThreadState* _save; \
+ _save = PyEval_SaveThread(); \
+ try { \
+ code \
+ } catch (...) { \
+ PyEval_RestoreThread(_save); \
+ throw; \
+ } \
+ PyEval_RestoreThread(_save); \
+ }
+
+
+void top_block_run_unlocked(gr::top_block_sptr r) noexcept(false)
+{
+ GR_PYTHON_BLOCKING_CODE(r->run();)
+}
+
+void top_block_start_unlocked(gr::top_block_sptr r, int max_noutput_items) noexcept(false)
+{
+ GR_PYTHON_BLOCKING_CODE(r->start(max_noutput_items);)
+}
+
+void top_block_wait_unlocked(gr::top_block_sptr r) noexcept(false)
+{
+ GR_PYTHON_BLOCKING_CODE(r->wait();)
+}
+
+void top_block_stop_unlocked(gr::top_block_sptr r) noexcept(false)
+{
+ GR_PYTHON_BLOCKING_CODE(r->stop();)
+}
+
+void top_block_unlock_unlocked(gr::top_block_sptr r) noexcept(false)
+{
+ GR_PYTHON_BLOCKING_CODE(r->unlock();)
+}
+
+
+void bind_top_block(py::module& m)
+{
+ using top_block = gr::top_block;
+
+
+ py::class_<top_block, gr::hier_block2, gr::basic_block, std::shared_ptr<top_block>>(
+ m, "top_block_pb", D(top_block))
+
+
+ .def(py::init(&gr::make_top_block),
+ py::arg("name"),
+ py::arg("catch_exceptions") = false)
+
+ .def("run",
+ &top_block::run,
+ py::arg("max_noutput_items") = 100000000,
+ D(top_block, run))
+
+
+ .def("start",
+ &top_block::start,
+ py::arg("max_noutput_items") = 100000000,
+ D(top_block, start))
+
+
+ .def("stop", &top_block::stop, D(top_block, stop))
+
+
+ .def("wait", &top_block::wait, D(top_block, wait))
+
+
+ .def("lock", &top_block::lock, D(top_block, lock))
+
+
+ .def("unlock", &top_block::unlock, D(top_block, unlock))
+
+
+ .def("edge_list", &top_block::edge_list, D(top_block, edge_list))
+
+
+ .def("msg_edge_list", &top_block::msg_edge_list, D(top_block, msg_edge_list))
+
+
+ .def("dump", &top_block::dump, D(top_block, dump))
+
+
+ .def("max_noutput_items",
+ &top_block::max_noutput_items,
+ D(top_block, max_noutput_items))
+
+
+ .def("set_max_noutput_items",
+ &top_block::set_max_noutput_items,
+ py::arg("nmax"),
+ D(top_block, set_max_noutput_items))
+
+
+ .def("to_top_block", &top_block::to_top_block, D(top_block, to_top_block))
+
+
+ .def("setup_rpc", &top_block::setup_rpc, D(top_block, setup_rpc))
+
+ ;
+
+
+ m.def("make_top_block",
+ &::gr::make_top_block,
+ py::arg("name"),
+ py::arg("catch_exceptions") = true,
+ D(make_top_block));
+
+
+ m.def("cast_to_top_block_sptr",
+ &::gr::cast_to_top_block_sptr,
+ py::arg("block"),
+ D(cast_to_top_block_sptr));
+
+
+ m.def("top_block_run_unlocked", &top_block_run_unlocked);
+ m.def("top_block_start_unlocked", &top_block_start_unlocked);
+ m.def("top_block_wait_unlocked", &top_block_wait_unlocked);
+ m.def("top_block_stop_unlocked", &top_block_stop_unlocked);
+ m.def("top_block_unlock_unlocked", &top_block_unlock_unlocked);
+}