GNU Radio C++ API Reference: buffer_reader.h Source File

| GNU Radio C++ API Reference 3.10.12.0 The Free & Open Software Radio Ecosystem |

Loading...
Searching...
No Matches
buffer_reader.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2004,2009-2011,2013 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_GR_RUNTIME_BUFFER_READER_H
12#define INCLUDED_GR_RUNTIME_BUFFER_READER_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/buffer.h>
16#include <gnuradio/logger.h>
17#include <gnuradio/runtime_types.h>
18#include <gnuradio/tags.h>
19#include <gnuradio/thread/thread.h>
20#include <memory>
21
22namespace gr {
23
24class buffer_reader_sm;
25
26/*!
27 * \brief Create a new gr::buffer_reader and attach it to buffer \p buf
28 * \param buf is the buffer the \p gr::buffer_reader reads from.
29 * \param nzero_preload -- number of zero items to "preload" into buffer.
30 * \param link is the block that reads from the buffer using this gr::buffer_reader.
31 * \param delay Optional setting to declare the buffer's sample delay.
32 */
33 GR_RUNTIME_API buffer_reader_sptr buffer_add_reader(buffer_sptr buf,
34 int nzero_preload,
35 block_sptr link = block_sptr(),
36 int delay = 0);
37
38//! returns # of buffers currently allocated
39 GR_RUNTIME_API long buffer_ncurrently_allocated();
40
41
42// ---------------------------------------------------------------------------
43
44/*!
45 * \brief How we keep track of the readers of a gr::buffer.
46 * \ingroup internal
47 */
48 class GR_RUNTIME_API buffer_reader
49{
50public:
51#ifdef BUFFER_DEBUG
52 gr::logger_ptr d_logger;
53 gr::logger_ptr d_debug_logger;
54#endif
55
56 virtual ~buffer_reader();
57
58 /*!
59 * Declares the sample delay for this reader.
60 *
61 * See gr::block::declare_sample_delay for details.
62 *
63 * \param delay The new sample delay
64 */
65 void declare_sample_delay(unsigned delay);
66
67 /*!
68 * Gets the sample delay for this reader.
69 *
70 * See gr::block::sample_delay for details.
71 */
72 unsigned sample_delay() const;
73
74 /*!
75 * \brief Return number of items available for reading.
76 */
77 virtual int items_available() const;
78
79 /*!
80 * \brief Return buffer this reader reads from.
81 */
82 buffer_sptr buffer() const { return d_buffer; }
83
84 /*!
85 * \brief Return maximum number of items that could ever be available for reading.
86 * This is used as a sanity check in the scheduler to avoid looping forever.
87 */
88 int max_possible_items_available() const { return d_buffer->bufsize() - 1; }
89
90 /*!
91 * \brief return pointer to read buffer.
92 *
93 * The return value points to items_available() number of items
94 */
95 const void* read_pointer();
96
97 /*
98 * \brief tell buffer we read \p items from it
99 */
100 void update_read_pointer(int nitems);
101
102 void set_done(bool done) { d_buffer->set_done(done); }
103 bool done() const { return d_buffer->done(); }
104
105 gr::thread::mutex* mutex() { return d_buffer->mutex(); }
106
107 uint64_t nitems_read() const { return d_abs_read_offset; }
108
109 void reset_nitem_counter()
110 {
111 d_read_index = 0;
112 d_abs_read_offset = 0;
113 }
114
115 size_t get_sizeof_item() { return d_buffer->get_sizeof_item(); }
116
117 /*!
118 * \brief Return the block that reads via this reader.
119 *
120 */
121 block_sptr link() const { return block_sptr(d_link); }
122
123 /*!
124 * \brief Given a [start,end), returns a vector all tags in the range.
125 *
126 * Get a vector of tags in given range. Range of counts is from start to end-1.
127 *
128 * Tags are tuples of:
129 * (item count, source id, key, value)
130 *
131 * \param v a vector reference to return tags into
132 * \param abs_start a uint64 count of the start of the range of interest
133 * \param abs_end a uint64 count of the end of the range of interest
134 * \param id the unique ID of the block to make sure already deleted tags
135 * are not returned
136 */
137 void get_tags_in_range(std::vector<tag_t>& v,
138 uint64_t abs_start,
139 uint64_t abs_end,
140 long id);
141
142 /*!
143 * \brief Returns true when the current thread is ready to call the callback,
144 * false otherwise. Delegate calls to buffer class's input_blkd_cb_ready().
145 * Note if input_blocked_callback is overridden then this function should
146 * also be overridden.
147 */
148 virtual bool input_blkd_cb_ready(int items_required) const { return false; }
149
150 /*!
151 * \brief Callback function that the scheduler will call when it determines
152 * that the input is blocked. Delegate calls to buffer class's
153 * input_blocked_callback(). Override this function if needed.
154 */
155 virtual bool input_blocked_callback(int items_required, int items_avail)
156 {
157 return false;
158 }
159
160 // -------------------------------------------------------------------------
161 unsigned int get_read_index() const { return d_read_index; }
162 uint64_t get_abs_read_offset() const { return d_abs_read_offset; }
163
164protected:
165 friend class buffer;
166 friend class buffer_double_mapped;
167 friend class buffer_single_mapped;
168 friend class buffer_reader_sm;
169
170 friend GR_RUNTIME_API buffer_reader_sptr buffer_add_reader(buffer_sptr buf,
171 int nzero_preload,
172 block_sptr link,
173 int delay);
174
175 buffer_sptr d_buffer;
176 unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) ** see NB
177 uint64_t d_abs_read_offset; // num items seen since the start ** see NB
178 std::weak_ptr<block> d_link; // block that reads via this buffer reader
179 unsigned d_attr_delay; // sample delay attribute for tag propagation
180 // ** NB: buffer::d_mutex protects d_read_index and d_abs_read_offset
181
182 //! constructor is private. Use gr::buffer::add_reader to create instances
183 buffer_reader(buffer_sptr buffer, unsigned int read_index, block_sptr link);
184};
185
186//! returns # of buffer_readers currently allocated
187 GR_RUNTIME_API long buffer_reader_ncurrently_allocated();
188
189} /* namespace gr */
190
191#endif /* INCLUDED_GR_RUNTIME_BUFFER_READER_H */
buffer.h
gr::buffer_reader_sm
Definition buffer_reader_sm.h:22
gr::buffer_reader::nitems_read
uint64_t nitems_read() const
Definition buffer_reader.h:107
gr::buffer_reader::~buffer_reader
virtual ~buffer_reader()
gr::buffer_reader::sample_delay
unsigned sample_delay() const
gr::buffer_reader::get_read_index
unsigned int get_read_index() const
Definition buffer_reader.h:161
gr::buffer_reader::d_abs_read_offset
uint64_t d_abs_read_offset
Definition buffer_reader.h:177
gr::buffer_reader::d_link
std::weak_ptr< block > d_link
Definition buffer_reader.h:178
gr::buffer_reader::link
block_sptr link() const
Return the block that reads via this reader.
Definition buffer_reader.h:121
gr::buffer_reader::read_pointer
const void * read_pointer()
return pointer to read buffer.
gr::buffer_reader::d_buffer
buffer_sptr d_buffer
Definition buffer_reader.h:175
gr::buffer_reader::get_sizeof_item
size_t get_sizeof_item()
Definition buffer_reader.h:115
gr::buffer_reader::buffer_double_mapped
friend class buffer_double_mapped
Definition buffer_reader.h:166
gr::buffer_reader::set_done
void set_done(bool done)
Definition buffer_reader.h:102
gr::buffer_reader::buffer_single_mapped
friend class buffer_single_mapped
Definition buffer_reader.h:167
gr::buffer_reader::items_available
virtual int items_available() const
Return number of items available for reading.
gr::buffer_reader::declare_sample_delay
void declare_sample_delay(unsigned delay)
gr::buffer_reader::done
bool done() const
Definition buffer_reader.h:103
gr::buffer_reader::buffer
buffer_sptr buffer() const
Return buffer this reader reads from.
Definition buffer_reader.h:82
gr::buffer_reader::buffer_add_reader
friend GR_RUNTIME_API buffer_reader_sptr buffer_add_reader(buffer_sptr buf, int nzero_preload, block_sptr link, int delay)
Create a new gr::buffer_reader and attach it to buffer buf.
gr::buffer_reader::get_abs_read_offset
uint64_t get_abs_read_offset() const
Definition buffer_reader.h:162
gr::buffer_reader::get_tags_in_range
void get_tags_in_range(std::vector< tag_t > &v, uint64_t abs_start, uint64_t abs_end, long id)
Given a [start,end), returns a vector all tags in the range.
gr::buffer_reader::d_attr_delay
unsigned d_attr_delay
Definition buffer_reader.h:179
gr::buffer_reader::d_read_index
unsigned int d_read_index
Definition buffer_reader.h:176
gr::buffer_reader::update_read_pointer
void update_read_pointer(int nitems)
gr::buffer_reader::buffer_reader_sm
friend class buffer_reader_sm
Definition buffer_reader.h:168
gr::buffer_reader::buffer_reader
buffer_reader(buffer_sptr buffer, unsigned int read_index, block_sptr link)
constructor is private. Use gr::buffer::add_reader to create instances
gr::buffer_reader::mutex
gr::thread::mutex * mutex()
Definition buffer_reader.h:105
gr::buffer_reader::reset_nitem_counter
void reset_nitem_counter()
Definition buffer_reader.h:109
gr::buffer_reader::input_blkd_cb_ready
virtual bool input_blkd_cb_ready(int items_required) const
Returns true when the current thread is ready to call the callback, false otherwise....
Definition buffer_reader.h:148
gr::buffer_reader::max_possible_items_available
int max_possible_items_available() const
Return maximum number of items that could ever be available for reading. This is used as a sanity che...
Definition buffer_reader.h:88
gr::buffer_reader::input_blocked_callback
virtual bool input_blocked_callback(int items_required, int items_avail)
Callback function that the scheduler will call when it determines that the input is blocked....
Definition buffer_reader.h:155
gr::buffer_reader::buffer
friend class buffer
Definition buffer_reader.h:165
api.h
GR_RUNTIME_API
#define GR_RUNTIME_API
Definition gnuradio-runtime/include/gnuradio/api.h:18
logger.h
gr::thread::mutex
boost::mutex mutex
Definition thread.h:37
gr
GNU Radio logging wrapper.
Definition basic_block.h:29
gr::logger_ptr
std::shared_ptr< logger > logger_ptr
Definition logger.h:250
gr::buffer_reader_ncurrently_allocated
GR_RUNTIME_API long buffer_reader_ncurrently_allocated()
returns # of buffer_readers currently allocated
gr::buffer_add_reader
GR_RUNTIME_API buffer_reader_sptr buffer_add_reader(buffer_sptr buf, int nzero_preload, block_sptr link=block_sptr(), int delay=0)
Create a new gr::buffer_reader and attach it to buffer buf.
gr::buffer_ncurrently_allocated
GR_RUNTIME_API long buffer_ncurrently_allocated()
returns # of buffers currently allocated
runtime_types.h
v
Definition cc_common.h:35
tags.h
thread.h