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