GNU Radio Manual and C++ API Reference 3.9.4.0
The Free & Open Software Radio Ecosystem
block_gateway.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2011-2013,2017,2020 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_RUNTIME_BLOCK_GATEWAY_H
12#define INCLUDED_RUNTIME_BLOCK_GATEWAY_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/block.h>
16#include <string>
17
18#include <pybind11/pybind11.h> // must be first
19#include <pybind11/stl.h>
20namespace py = pybind11;
21
22namespace gr {
23
24/*!
25 * The gateway block which performs all the magic.
26 *
27 * The gateway provides access to all the gr::block routines.
28 */
29typedef enum {
35
37{
38private:
39 py::handle d_py_handle;
40
41public:
42 // gr::block_gateway::sptr
43 typedef std::shared_ptr<block_gateway> sptr;
44
45 /*!
46 * Make a new gateway block.
47 * \param py_handle the pybind11 object with callback
48 * \param name the name of the block (Ex: "Shirley")
49 * \param in_sig the input signature for this block
50 * \param out_sig the output signature for this block
51 * \return a new gateway block
52 */
53 static sptr make(const py::object& py_handle,
54 const std::string& name,
57
58
59 // Protected members of gr::block trampolined here for python blocks to use
60 void _add_item_tag(unsigned int which_output, const tag_t& tag)
61 {
62 return gr::block::add_item_tag(which_output, tag);
63 }
64
65 void _add_item_tag(unsigned int which_output,
66 uint64_t abs_offset,
67 const pmt::pmt_t& key,
68 const pmt::pmt_t& value,
69 const pmt::pmt_t& srcid = pmt::PMT_F)
70 {
71 return gr::block::add_item_tag(which_output, abs_offset, key, value, srcid);
72 }
73
74
75 std::vector<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> tags;
79 gr::block::get_tags_in_range(tags, which_input, abs_start, abs_end);
80 return tags;
81 }
82
83 std::vector<tag_t> _get_tags_in_range(unsigned int which_input,
84 uint64_t abs_start,
85 uint64_t abs_end,
86 const pmt::pmt_t& key)
87 {
88 std::vector<gr::tag_t> tags;
89 gr::block::get_tags_in_range(tags, which_input, abs_start, abs_end, key);
90 return tags;
91 }
92
93 std::vector<tag_t>
94 _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end)
95 {
96 std::vector<gr::tag_t> tags;
97 gr::block::get_tags_in_window(tags, which_input, rel_start, rel_end);
98 return tags;
99 }
100
101 std::vector<tag_t> _get_tags_in_window(unsigned int which_input,
102 uint64_t rel_start,
103 uint64_t rel_end,
104 const pmt::pmt_t& key)
105 {
106 std::vector<gr::tag_t> tags;
107 gr::block::get_tags_in_window(tags, which_input, rel_start, rel_end, key);
108 return tags;
109 }
110
111 virtual void set_msg_handler_pybind(pmt::pmt_t which_port,
112 std::string& handler_name) = 0;
113
114protected:
115 bool has_msg_handler(pmt::pmt_t which_port) override = 0;
116 void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) override = 0;
117};
118
119} /* namespace gr */
120
121#endif /* INCLUDED_RUNTIME_BLOCK_GATEWAY_H */
Definition: block_gateway.h:37
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)
Definition: block_gateway.h:65
virtual void set_msg_handler_pybind(pmt::pmt_t which_port, std::string &handler_name)=0
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)
Definition: block_gateway.h:101
void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) override=0
void _add_item_tag(unsigned int which_output, const tag_t &tag)
Definition: block_gateway.h:60
std::vector< tag_t > _get_tags_in_range(unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
Definition: block_gateway.h:76
bool has_msg_handler(pmt::pmt_t which_port) override=0
Tests if there is a handler attached to port which_port.
std::shared_ptr< block_gateway > sptr
Definition: block_gateway.h:43
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)
Definition: block_gateway.h:83
std::vector< tag_t > _get_tags_in_window(unsigned int which_input, uint64_t rel_start, uint64_t rel_end)
Definition: block_gateway.h:94
static sptr make(const py::object &py_handle, const std::string &name, gr::io_signature::sptr in_sig, gr::io_signature::sptr out_sig)
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:60
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)
Adds a new tag onto the given output buffer.
Definition: gnuradio-runtime/include/gnuradio/block.h:771
void get_tags_in_range(std::vector< tag_t > &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end)
Given a [start,end), returns a vector of all tags in the range.
void get_tags_in_window(std::vector< tag_t > &v, unsigned int which_input, uint64_t rel_start, uint64_t rel_end)
Gets all tags within the relative window of the current call to work.
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:34
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
gw_block_t
Definition: block_gateway.h:29
@ GW_BLOCK_INTERP
Definition: block_gateway.h:33
@ GW_BLOCK_GENERAL
Definition: block_gateway.h:30
@ GW_BLOCK_DECIM
Definition: block_gateway.h:32
@ GW_BLOCK_SYNC
Definition: block_gateway.h:31
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
#define PMT_F
Definition: pmt.h:124
Definition: tags.h:19