GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
block_gateway.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Free Software Foundation, Inc.
3 *
4 * This file is part of GNU Radio
5 *
6 * SPDX-License-Identifier: GPL-3.0-or-later
7 *
8 */
9
10#ifndef INCLUDED_BLOCK_GATEWAY_H
11#define INCLUDED_BLOCK_GATEWAY_H
12
13#include <gnuradio/block.h>
15#include <gnuradio/logger.h>
16#include <gnuradio/types.h>
17#include <pmt/pmt.h>
18
19#include <pybind11/pybind11.h>
20
21#include <map>
22#include <memory>
23#include <string>
24
25namespace py = pybind11;
26
27/*!
28 * The gateway block which performs all the magic.
29 *
30 * The gateway provides access to all the gr::block routines.
31 */
32using gw_block_t = enum {
33 GW_BLOCK_GENERAL = 0,
34 GW_BLOCK_SYNC,
35 GW_BLOCK_DECIM,
36 GW_BLOCK_INTERP
37};
38
40{
41public:
42 block_gateway(const py::handle& py_handle,
43 const std::string& name,
46
47 // gr::block_gateway::sptr
48 using sptr = std::shared_ptr<block_gateway>;
49
50 /*!
51 * Make a new gateway block.
52 * \param py_handle the pybind11 object with callback
53 * \param name the name of the block (Ex: "Shirley")
54 * \param in_sig the input signature for this block
55 * \param out_sig the output signature for this block
56 * \return a new gateway block
57 */
58 static sptr make(const py::object& py_handle,
59 const std::string& name,
62
63 /*******************************************************************
64 * Public versions of gr::block protected methods, necessary because
65 * we need public methods for the python bindings
66 ******************************************************************/
67 void _add_item_tag(unsigned int which_output, const gr::tag_t& tag);
68
69 void _add_item_tag(unsigned int which_output,
70 uint64_t abs_offset,
71 const pmt::pmt_t& key,
72 const pmt::pmt_t& value,
73 const pmt::pmt_t& srcid);
74
75 std::vector<gr::tag_t>
76 _get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end);
77
78 std::vector<gr::tag_t> _get_tags_in_range(unsigned int which_input,
79 uint64_t abs_start,
80 uint64_t abs_end,
81 const pmt::pmt_t& key);
82
83 std::vector<gr::tag_t>
84 _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end);
85
86 std::vector<gr::tag_t> _get_tags_in_window(unsigned int which_input,
87 uint64_t rel_start,
88 uint64_t rel_end,
89 const pmt::pmt_t& key);
90
91 /*******************************************************************
92 * Overloads for various scheduler-called functions
93 ******************************************************************/
94 void forecast(int noutput_items, gr_vector_int& ninput_items_required) override;
95
96 int general_work(int noutput_items,
97 gr_vector_int& ninput_items,
98 gr_vector_const_void_star& input_items,
99 gr_vector_void_star& output_items) override;
100
101 bool start() override;
102
103 bool stop() override;
104
105 void set_msg_handler_pybind(const pmt::pmt_t& which_port, std::string& handler_name);
106
107 inline gr::logger_ptr _get_logger() const { return d_logger; }
108
109private:
110 py::handle d_py_handle;
111
112 // Message handlers back into python using pybind API
113 using msg_handlers_pybind_t = std::map<pmt::pmt_t, std::string, pmt::comparator>;
114 msg_handlers_pybind_t d_msg_handlers_pybind;
115
116 bool has_msg_handler(pmt::pmt_t which_port) override;
117
118 void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) override;
119};
120
121#endif /* INCLUDED_BLOCK_GATEWAY_H */
enum { GW_BLOCK_GENERAL=0, GW_BLOCK_SYNC, GW_BLOCK_DECIM, GW_BLOCK_INTERP } gw_block_t
Definition: block_gateway.h:37
Definition: block_gateway.h:40
void set_msg_handler_pybind(const pmt::pmt_t &which_port, std::string &handler_name)
std::vector< gr::tag_t > _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end, const pmt::pmt_t &key)
std::shared_ptr< block_gateway > sptr
Definition: block_gateway.h:48
bool start() override
Called to enable drivers, etc for i/o devices.
std::vector< gr::tag_t > _get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
gr::logger_ptr _get_logger() const
Definition: block_gateway.h:107
void forecast(int noutput_items, gr_vector_int &ninput_items_required) override
Estimate input requirements given output request.
bool stop() override
Called to disable drivers, etc for i/o devices.
block_gateway(const py::handle &py_handle, const std::string &name, gr::io_signature::sptr in_sig, gr::io_signature::sptr out_sig)
static sptr make(const py::object &py_handle, const std::string &name, gr::io_signature::sptr in_sig, gr::io_signature::sptr out_sig)
std::vector< gr::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 > _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end)
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)
void _add_item_tag(unsigned int which_output, const gr::tag_t &tag)
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
compute output items from input items
gr::logger_ptr d_logger
Definition: basic_block.h:96
std::string name() const
Definition: basic_block.h:168
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:63
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:47
GR_RUNTIME_API const pmt::pmt_t msg()
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:83
Definition: tags.h:19
std::vector< const void * > gr_vector_const_void_star
Definition: types.h:28
std::vector< void * > gr_vector_void_star
Definition: types.h:27
std::vector< int > gr_vector_int
Definition: types.h:23