GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
host_buffer.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2021 BlackLynx Inc.
4 *
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#ifndef INCLUDED_HOST_BUFFER_H
9#define INCLUDED_HOST_BUFFER_H
10
13#include <cstddef>
14
15namespace gr {
16
17
19{
20public:
21 static void* device_memcpy(void* dest, const void* src, std::size_t count);
22 static void* device_memmove(void* dest, const void* src, std::size_t count);
23
25
26 static buffer_sptr make_buffer(int nitems,
27 size_t sizeof_item,
28 uint64_t downstream_lcm_nitems,
29 uint32_t downstream_max_out_mult,
30 block_sptr link = block_sptr(),
31 block_sptr buf_owner = block_sptr());
32
33 ~host_buffer() override;
34
35 /*!
36 * \brief Handles post-general_work() cleanup and data transfer
37 *
38 * Called directly after call to general_work() completes and
39 * is used for data transfer (and perhaps other administrative
40 * activities)
41 *
42 * \param nitems is the number of items produced by the general_work() function.
43 */
44 void post_work(int nitems) override;
45
46 /*!
47 * \brief Do actual buffer allocation. Inherited from buffer_single_mapped.
48 */
49 bool do_allocate_buffer(size_t final_nitems, size_t sizeof_item) override;
50
51 /*!
52 * \brief Return a pointer to the write buffer depending on the context
53 */
54 void* write_pointer() override;
55
56 /*!
57 * \brief return pointer to read buffer depending on the context
58 *
59 * The return value points to at least items_available() items.
60 */
61 const void* _read_pointer(unsigned int read_index) override;
62
63 /*!
64 * \brief Callback function that the scheduler will call when it determines
65 * that the input is blocked. Override this function if needed.
66 */
67 bool input_blocked_callback(int items_required,
68 int items_avail,
69 unsigned read_index) override;
70
71 /*!
72 * \brief Callback function that the scheduler will call when it determines
73 * that the output is blocked
74 */
75 bool output_blocked_callback(int output_multiple, bool force) override;
76
77 /*!
78 * \brief Creates a new host_buffer object
79 *
80 * \param nitems
81 * \param sizeof_item
82 * \param downstream_lcm_nitems
83 * \param downstream_max_out_mult
84 * \param link
85 * \param buf_owner
86 *
87 * \return pointer to buffer base class
88 */
89 static buffer_sptr make_host_buffer(int nitems,
90 std::size_t sizeof_item,
91 uint64_t downstream_lcm_nitems,
92 uint32_t downstream_max_out_mult,
93 block_sptr link,
94 block_sptr buf_owner);
95
96private:
97 // This is the simulated device buffer
98 std::unique_ptr<char[]> d_device_buf;
99 char* d_device_base;
100
101 /*!
102 * \brief constructor is private. Use the static make_host_buffer function
103 * to create instances.
104 *
105 * Allocate a buffer that holds at least \p nitems of size \p sizeof_item.
106 *
107 * \param nitems is the minimum number of items the buffer will hold.
108 * \param sizeof_item is the size of an item in bytes.
109 * \param downstream_lcm_nitems is the least common multiple of the items to
110 * read by downstream blocks
111 * \param downstream_max_out_mult is the maximum output multiple of all
112 * downstream blocks
113 * \param link is the block that writes to this buffer.
114 * \param buf_owner if the block that owns the buffer which may or may not
115 * be the same as the block that writes to this buffer
116 *
117 * The total size of the buffer will be rounded up to a system
118 * dependent boundary. This is typically the system page size, but
119 * under MS windows is 64KB.
120 */
121 host_buffer(int nitems,
122 size_t sizeof_item,
123 uint64_t downstream_lcm_nitems,
124 uint32_t downstream_max_out_mult,
125 block_sptr link,
126 block_sptr buf_owner);
127};
128
129} // namespace gr
130
131#endif /* INCLUDED_HOST_BUFFER_H */
A single mapped buffer where wrapping conditions are handled explicitly via input/output_blocked_call...
Definition: buffer_single_mapped.h:31
Base class for describing a buffer's type.
Definition: buffer_type.h:30
Definition: host_buffer.h:19
static buffer_sptr make_buffer(int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, uint32_t downstream_max_out_mult, block_sptr link=block_sptr(), block_sptr buf_owner=block_sptr())
static void * device_memcpy(void *dest, const void *src, std::size_t count)
bool input_blocked_callback(int items_required, int items_avail, unsigned read_index) override
Callback function that the scheduler will call when it determines that the input is blocked....
~host_buffer() override
void post_work(int nitems) override
Handles post-general_work() cleanup and data transfer.
static buffer_sptr make_host_buffer(int nitems, std::size_t sizeof_item, uint64_t downstream_lcm_nitems, uint32_t downstream_max_out_mult, block_sptr link, block_sptr buf_owner)
Creates a new host_buffer object.
static buffer_type type
Definition: host_buffer.h:24
void * write_pointer() override
Return a pointer to the write buffer depending on the context.
const void * _read_pointer(unsigned int read_index) override
return pointer to read buffer depending on the context
bool output_blocked_callback(int output_multiple, bool force) override
Callback function that the scheduler will call when it determines that the output is blocked.
bool do_allocate_buffer(size_t final_nitems, size_t sizeof_item) override
Do actual buffer allocation. Inherited from buffer_single_mapped.
static void * device_memmove(void *dest, const void *src, std::size_t count)
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29