GNU Radio 3.6.3 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  // Return the number of items read on input stream which_input
89  uint64_t nitems_read(unsigned int which_input);
90 
91  // Return the number of items written on output stream which_output
92  uint64_t nitems_written(unsigned int which_output);
93 
94 
95  /*!
96  * \brief Adds a new tag to the given output stream.
97  *
98  * This takes the input parameters and builds a PMT tuple
99  * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t),
100  * which appends the tag onto its deque.
101  *
102  * \param which_output an integer of which output stream to attach the tag
103  * \param tag the tag object to add
104  */
105  void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
106 
107  /*!
108  * \brief Given a [start,end), returns a vector of all tags in the range.
109  *
110  * Pass-through function to gr_buffer_reader to get a vector of tags
111  * in given range. Range of counts is from start to end-1.
112  *
113  * Tags are tuples of:
114  * (item count, source id, key, value)
115  *
116  * \param v a vector reference to return tags into
117  * \param which_input an integer of which input stream to pull from
118  * \param abs_start a uint64 count of the start of the range of interest
119  * \param abs_end a uint64 count of the end of the range of interest
120  */
121  void get_tags_in_range(std::vector<gr_tag_t> &v,
122  unsigned int which_input,
123  uint64_t abs_start,
124  uint64_t abs_end);
125 
126  /*!
127  * \brief Given a [start,end), returns a vector of all tags in the range
128  * with a given key.
129  *
130  * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of
131  * tags from the buffers. This function then provides a secondary filter to
132  * the tags to extract only tags with the given 'key'.
133  *
134  * Tags are tuples of:
135  * (item count, source id, key, value)
136  *
137  * \param v a vector reference to return tags into
138  * \param which_input an integer of which input stream to pull from
139  * \param abs_start a uint64 count of the start of the range of interest
140  * \param abs_end a uint64 count of the end of the range of interest
141  * \param key a PMT symbol to select only tags of this key
142  */
143  void get_tags_in_range(std::vector<gr_tag_t> &v,
144  unsigned int which_input,
145  uint64_t abs_start,
146  uint64_t abs_end,
147  const pmt::pmt_t &key);
148 
149  gr_tpb_detail d_tpb; // used by thread-per-block scheduler
151 
152  // ----------------------------------------------------------------------------
153 
154  private:
155  unsigned int d_ninputs;
156  unsigned int d_noutputs;
157  std::vector<gr_buffer_reader_sptr> d_input;
158  std::vector<gr_buffer_sptr> d_output;
159  bool d_done;
160 
161  gr_block_detail (unsigned int ninputs, unsigned int noutputs);
162 
163  friend struct gr_tpb_detail;
164 
166  gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
167 };
168 
170 gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
171 
172 GR_CORE_API long
174 
175 #endif /* INCLUDED_GR_BLOCK_DETAIL_H */