GNU Radio 3.5.3.2 C++ API
gr_block_detail.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2009,2010 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more detail.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_BLOCK_DETAIL_H
24 #define INCLUDED_GR_BLOCK_DETAIL_H
25 
26 #include <gr_core_api.h>
27 #include <gr_runtime_types.h>
28 #include <gr_tpb_detail.h>
29 #include <gr_tags.h>
30 #include <stdexcept>
31 
32 /*!
33  * \brief Implementation details to support the signal processing abstraction
34  * \ingroup internal
35  *
36  * This class contains implementation detail that should be "out of sight"
37  * of almost all users of GNU Radio. This decoupling also means that
38  * we can make changes to the guts without having to recompile everything.
39  */
41  public:
42  ~gr_block_detail ();
43 
44  int ninputs () const { return d_ninputs; }
45  int noutputs () const { return d_noutputs; }
46  bool sink_p () const { return d_noutputs == 0; }
47  bool source_p () const { return d_ninputs == 0; }
48 
49  void set_done (bool done);
50  bool done () const { return d_done; }
51 
52  void set_input (unsigned int which, gr_buffer_reader_sptr reader);
53  gr_buffer_reader_sptr input (unsigned int which)
54  {
55  if (which >= d_ninputs)
56  throw std::invalid_argument ("gr_block_detail::input");
57  return d_input[which];
58  }
59 
60  void set_output (unsigned int which, gr_buffer_sptr buffer);
61  gr_buffer_sptr output (unsigned int which)
62  {
63  if (which >= d_noutputs)
64  throw std::invalid_argument ("gr_block_detail::output");
65  return d_output[which];
66  }
67 
68  /*!
69  * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed.
70  */
71  void consume (int which_input, int how_many_items);
72 
73  /*!
74  * \brief Tell the scheduler \p how_many_items were consumed on each input stream.
75  */
76  void consume_each (int how_many_items);
77 
78  /*!
79  * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output.
80  */
81  void produce (int which_output, int how_many_items);
82 
83  /*!
84  * \brief Tell the scheduler \p how_many_items were produced on each output stream.
85  */
86  void produce_each (int how_many_items);
87 
88  /*!
89  * Accept msg, place in queue, arrange for thread to be awakened if it's not already.
90  */
91  void _post(pmt::pmt_t msg);
92 
93  // Return the number of items read on input stream which_input
94  uint64_t nitems_read(unsigned int which_input);
95 
96  // Return the number of items written on output stream which_output
97  uint64_t nitems_written(unsigned int which_output);
98 
99 
100  /*!
101  * \brief Adds a new tag to the given output stream.
102  *
103  * This takes the input parameters and builds a PMT tuple
104  * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t),
105  * which appends the tag onto its deque.
106  *
107  * \param which_output an integer of which output stream to attach the tag
108  * \param tag the tag object to add
109  */
110  void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
111 
112  /*!
113  * \brief Given a [start,end), returns a vector of all tags in the range.
114  *
115  * Pass-through function to gr_buffer_reader to get a vector of tags
116  * in given range. Range of counts is from start to end-1.
117  *
118  * Tags are tuples of:
119  * (item count, source id, key, value)
120  *
121  * \param v a vector reference to return tags into
122  * \param which_input an integer of which input stream to pull from
123  * \param abs_start a uint64 count of the start of the range of interest
124  * \param abs_end a uint64 count of the end of the range of interest
125  */
126  void get_tags_in_range(std::vector<gr_tag_t> &v,
127  unsigned int which_input,
128  uint64_t abs_start,
129  uint64_t abs_end);
130 
131  /*!
132  * \brief Given a [start,end), returns a vector of all tags in the range
133  * with a given key.
134  *
135  * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of
136  * tags from the buffers. This function then provides a secondary filter to
137  * the tags to extract only tags with the given 'key'.
138  *
139  * Tags are tuples of:
140  * (item count, source id, key, value)
141  *
142  * \param v a vector reference to return tags into
143  * \param which_input an integer of which input stream to pull from
144  * \param abs_start a uint64 count of the start of the range of interest
145  * \param abs_end a uint64 count of the end of the range of interest
146  * \param key a PMT symbol to select only tags of this key
147  */
148  void get_tags_in_range(std::vector<gr_tag_t> &v,
149  unsigned int which_input,
150  uint64_t abs_start,
151  uint64_t abs_end,
152  const pmt::pmt_t &key);
153 
154  gr_tpb_detail d_tpb; // used by thread-per-block scheduler
156 
157  // ----------------------------------------------------------------------------
158 
159  private:
160  unsigned int d_ninputs;
161  unsigned int d_noutputs;
162  std::vector<gr_buffer_reader_sptr> d_input;
163  std::vector<gr_buffer_sptr> d_output;
164  bool d_done;
165 
166  gr_block_detail (unsigned int ninputs, unsigned int noutputs);
167 
168  friend struct gr_tpb_detail;
169 
171  gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
172 };
173 
175 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
176 
177 GR_CORE_API long
179 
180 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */