GNU Radio Manual and C++ API Reference  3.7.13.4
The Free & Open Software Radio Ecosystem
block.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2007,2009,2010,2013,2017 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 details.
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_RUNTIME_BLOCK_H
24 #define INCLUDED_GR_RUNTIME_BLOCK_H
25 
26 #include <gnuradio/api.h>
27 #include <gnuradio/basic_block.h>
28 #include <gnuradio/tags.h>
29 #include <gnuradio/logger.h>
30 
31 namespace gr {
32 
33  /*!
34  * \brief The abstract base class for all 'terminal' processing blocks.
35  * \ingroup base_blk
36  *
37  * A signal processing flow is constructed by creating a tree of
38  * hierarchical blocks, which at any level may also contain terminal
39  * nodes that actually implement signal processing functions. This
40  * is the base class for all such leaf nodes.
41  *
42  * Blocks have a set of input streams and output streams. The
43  * input_signature and output_signature define the number of input
44  * streams and output streams respectively, and the type of the data
45  * items in each stream.
46  *
47  * Blocks report the number of items consumed on each input in
48  * general_work(), using consume() or consume_each().
49  *
50  * If the same number of items is produced on each output, the block
51  * returns that number from general_work(). Otherwise, the block
52  * calls produce() for each output, then returns
53  * WORK_CALLED_PRODUCE. The input and output rates are not required
54  * to be related.
55  *
56  * User derived blocks override two methods, forecast and
57  * general_work, to implement their signal processing
58  * behavior. forecast is called by the system scheduler to determine
59  * how many items are required on each input stream in order to
60  * produce a given number of output items.
61  *
62  * general_work is called to perform the signal processing in the
63  * block. It reads the input items and writes the output items.
64  */
66  {
67  public:
68 
69  //! Magic return values from general_work
70  enum {
72  WORK_DONE = -1
73  };
74 
75  /*!
76  * \brief enum to represent different tag propagation policies.
77  */
79  TPP_DONT = 0, /*!< Scheduler doesn't propagate tags from in- to output. The block itself is free to insert tags as it wants. */
80  TPP_ALL_TO_ALL = 1, /*!< Propagate tags from all in- to all outputs. The scheduler takes care of that. */
81  TPP_ONE_TO_ONE = 2, /*!< Propagate tags from n. input to n. output. Requires same number of in- and outputs */
82  TPP_CUSTOM = 3 /*!< Like TPP_DONT, but signals the block it should implement application-specific forwarding behaviour. */
83  };
84 
85  virtual ~block();
86 
87  /*!
88  * Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...)
89  * History is the number of x_i's that are examined to produce one y_i.
90  * This comes in handy for FIR filters, where we use history to
91  * ensure that our input contains the appropriate "history" for the
92  * filter. History should be equal to the number of filter taps. First
93  * history samples (when there are no previous samples) are
94  * initialized with zeroes.
95  */
96  unsigned history() const;
97  void set_history(unsigned history);
98 
99  /*!
100  * Declares the block's delay in samples. Since the delay of
101  * blocks like filters is derived from the taps and not the block
102  * itself, we cannot automatically calculate this value and so
103  * leave it as a user-defined property. It defaults to 0 is not
104  * set.
105  *
106  * This does not actively set the delay; it just tells the
107  * scheduler what the delay is.
108  *
109  * This delay is mostly used to adjust the placement of the tags
110  * and is not currently used for any signal processing. When a tag
111  * is passed through a block with internal delay, its location
112  * should be moved based on the delay of the block. This interface
113  * allows us to tell the scheduler this value.
114  *
115  * \param which The buffer on which to set the delay.
116  * \param delay The sample delay of the data stream.
117  */
118  void declare_sample_delay(int which, unsigned delay);
119 
120  /*!
121  * Convenience wrapper to gr::block::declare_delay(int which, unsigned delay)
122  * to set all ports to the same delay.
123  */
124  void declare_sample_delay(unsigned delay);
125 
126  /*!
127  * Gets the delay of the block. Since the delay of blocks like
128  * filters is derived from the taps and not the block itself, we
129  * cannot automatically calculate this value and so leave it as a
130  * user-defined property. It defaults to 0 is not set.
131  *
132  * \param which Which port from which to get the sample delay.
133  */
134  unsigned sample_delay(int which) const;
135 
136  /*!
137  * \brief Return true if this block has a fixed input to output rate.
138  *
139  * If true, then fixed_rate_in_to_out and fixed_rate_out_to_in may be called.
140  */
141  bool fixed_rate() const { return d_fixed_rate; }
142 
143  // ----------------------------------------------------------------
144  // override these to define your behavior
145  // ----------------------------------------------------------------
146 
147  /*!
148  * \brief Estimate input requirements given output request
149  *
150  * \param noutput_items number of output items to produce
151  * \param ninput_items_required number of input items required on each input stream
152  *
153  * Given a request to product \p noutput_items, estimate the
154  * number of data items required on each input stream. The
155  * estimate doesn't have to be exact, but should be close.
156  */
157  virtual void forecast(int noutput_items,
158  gr_vector_int &ninput_items_required);
159 
160  /*!
161  * \brief compute output items from input items
162  *
163  * \param noutput_items number of output items to write on each output stream
164  * \param ninput_items number of input items available on each input stream
165  * \param input_items vector of pointers to the input items, one entry per input stream
166  * \param output_items vector of pointers to the output items, one entry per output stream
167  *
168  * \returns number of items actually written to each output stream
169  * or WORK_CALLED_PRODUCE or WORK_DONE. It is OK to return a
170  * value less than noutput_items.
171  *
172  * WORK_CALLED_PRODUCE is used where not all outputs produce the
173  * same number of items. general_work must call produce() for each
174  * output to indicate the numer of items actually produced.
175  *
176  * WORK_DONE indicates that no more data will be produced by this block.
177  *
178  * general_work must call consume or consume_each to indicate how
179  * many items were consumed on each input stream.
180  */
181  virtual int general_work(int noutput_items,
182  gr_vector_int &ninput_items,
183  gr_vector_const_void_star &input_items,
184  gr_vector_void_star &output_items);
185 
186  /*!
187  * \brief Called to enable drivers, etc for i/o devices.
188  *
189  * This allows a block to enable an associated driver to begin
190  * transferring data just before we start to execute the scheduler.
191  * The end result is that this reduces latency in the pipeline
192  * when dealing with audio devices, usrps, etc.
193  */
194  virtual bool start();
195 
196  /*!
197  * \brief Called to disable drivers, etc for i/o devices.
198  */
199  virtual bool stop();
200 
201  // ----------------------------------------------------------------
202 
203  /*!
204  * \brief Constrain the noutput_items argument passed to forecast and general_work
205  *
206  * set_output_multiple causes the scheduler to ensure that the
207  * noutput_items argument passed to forecast and general_work will
208  * be an integer multiple of \param multiple The default value of
209  * output multiple is 1.
210  */
211  void set_output_multiple(int multiple);
212  int output_multiple() const { return d_output_multiple; }
213  bool output_multiple_set() const { return d_output_multiple_set; }
214 
215  /*!
216  * \brief Constrains buffers to work on a set item alignment (for SIMD)
217  *
218  * set_alignment_multiple causes the scheduler to ensure that the
219  * noutput_items argument passed to forecast and general_work will
220  * be an integer multiple of \param multiple The default value is
221  * 1.
222  *
223  * This control is similar to the output_multiple setting, except
224  * that if the number of items passed to the block is less than
225  * the output_multiple, this value is ignored and the block can
226  * produce like normal. The d_unaligned value is set to the number
227  * of items the block is off by. In the next call to general_work,
228  * the noutput_items is set to d_unaligned or less until
229  * d_unaligned==0. The buffers are now aligned again and the
230  * aligned calls can be performed again.
231  */
232  void set_alignment(int multiple);
233  int alignment() const { return d_output_multiple; }
234 
235  void set_unaligned(int na);
236  int unaligned() const { return d_unaligned; }
237  void set_is_unaligned(bool u);
238  bool is_unaligned() const { return d_is_unaligned; }
239 
240  /*!
241  * \brief Tell the scheduler \p how_many_items of input stream \p
242  * which_input were consumed.
243  *
244  * This function should be used in general_work() to tell the scheduler the
245  * number of input items processed. Calling consume() multiple times in the
246  * same general_work() call is safe. Every invocation of consume() updates
247  * the values returned by nitems_read().
248  */
249  void consume(int which_input, int how_many_items);
250 
251  /*!
252  * \brief Tell the scheduler \p how_many_items were consumed on
253  * each input stream.
254  *
255  * Also see notes on consume().
256  */
257  void consume_each(int how_many_items);
258 
259  /*!
260  * \brief Tell the scheduler \p how_many_items were produced on
261  * output stream \p which_output.
262  *
263  * This function should be used in general_work() to tell the scheduler the
264  * number of output items produced. If produce() is called in
265  * general_work(), general_work() must return \p WORK_CALLED_PRODUCE.
266  * Calling produce() multiple times in the same general_work() call is safe.
267  * Every invocation of produce() updates the values returned by
268  * nitems_written().
269  */
270  void produce(int which_output, int how_many_items);
271 
272  /*!
273  * \brief Set the approximate output rate / input rate
274  *
275  * Provide a hint to the buffer allocator and scheduler.
276  * The default relative_rate is 1.0
277  *
278  * decimators have relative_rates < 1.0
279  * interpolators have relative_rates > 1.0
280  */
281  void set_relative_rate(double relative_rate);
282 
283  /*!
284  * \brief return the approximate output rate / input rate
285  */
286  double relative_rate() const { return d_relative_rate; }
287 
288  /*
289  * The following two methods provide special case info to the
290  * scheduler in the event that a block has a fixed input to output
291  * ratio. sync_block, sync_decimator and
292  * sync_interpolator override these. If you're fixed rate,
293  * subclass one of those.
294  */
295  /*!
296  * \brief Given ninput samples, return number of output samples that will be produced.
297  * N.B. this is only defined if fixed_rate returns true.
298  * Generally speaking, you don't need to override this.
299  */
300  virtual int fixed_rate_ninput_to_noutput(int ninput);
301 
302  /*!
303  * \brief Given noutput samples, return number of input samples required to produce noutput.
304  * N.B. this is only defined if fixed_rate returns true.
305  * Generally speaking, you don't need to override this.
306  */
307  virtual int fixed_rate_noutput_to_ninput(int noutput);
308 
309  /*!
310  * \brief Return the number of items read on input stream which_input
311  */
312  uint64_t nitems_read(unsigned int which_input);
313 
314  /*!
315  * \brief Return the number of items written on output stream which_output
316  */
317  uint64_t nitems_written(unsigned int which_output);
318 
319  /*!
320  * \brief Asks for the policy used by the scheduler to moved tags downstream.
321  */
322  tag_propagation_policy_t tag_propagation_policy();
323 
324  /*!
325  * \brief Set the policy by the scheduler to determine how tags are moved downstream.
326  */
327  void set_tag_propagation_policy(tag_propagation_policy_t p);
328 
329  /*!
330  * \brief Return the minimum number of output items this block can
331  * produce during a call to work.
332  *
333  * Should be 0 for most blocks. Useful if we're dealing with
334  * packets and the block produces one packet per call to work.
335  */
336  int min_noutput_items() const { return d_min_noutput_items; }
337 
338  /*!
339  * \brief Set the minimum number of output items this block can
340  * produce during a call to work.
341  *
342  * \param m the minimum noutput_items this block can produce.
343  */
344  void set_min_noutput_items(int m) { d_min_noutput_items = m; }
345 
346  /*!
347  * \brief Return the maximum number of output items this block will
348  * handle during a call to work.
349  */
350  int max_noutput_items();
351 
352  /*!
353  * \brief Set the maximum number of output items this block will
354  * handle during a call to work.
355  *
356  * \param m the maximum noutput_items this block will handle.
357  */
358  void set_max_noutput_items(int m);
359 
360  /*!
361  * \brief Clear the switch for using the max_noutput_items value of this block.
362  *
363  * When is_set_max_noutput_items() returns 'true', the scheduler
364  * will use the value returned by max_noutput_items() to limit the
365  * size of the number of items possible for this block's work
366  * function. If is_set_max_notput_items() returns 'false', then
367  * the scheduler ignores the internal value and uses the value set
368  * globally in the top_block.
369  *
370  * Use this value to clear the 'is_set' flag so the scheduler will
371  * ignore this. Use the set_max_noutput_items(m) call to both set
372  * a new value for max_noutput_items and to re-enable its use in
373  * the scheduler.
374  */
375  void unset_max_noutput_items();
376 
377  /*!
378  * \brief Ask the block if the flag is or is not set to use the
379  * internal value of max_noutput_items during a call to work.
380  */
381  bool is_set_max_noutput_items();
382 
383  /*
384  * Used to expand the vectors that hold the min/max buffer sizes.
385  *
386  * Specifically, when -1 is used, the vectors are just initialized
387  * with 1 value; this is used by the flat_flowgraph to expand when
388  * required to add a new value for new ports on these blocks.
389  */
390  void expand_minmax_buffer(int port);
391 
392  /*!
393  * \brief Returns max buffer size on output port \p i.
394  */
395  long max_output_buffer(size_t i);
396 
397  /*!
398  * \brief Request limit on max buffer size on all output ports.
399  *
400  * \details
401  * This is an advanced feature. Calling this can affect some
402  * fundamental assumptions about the system behavior and
403  * performance.
404  *
405  * The actual buffer size is determined by a number of other
406  * factors from the block and system. This function only provides
407  * a requested maximum. The buffers will always be a multiple of
408  * the system page size, which may be larger than the value asked
409  * for here.
410  *
411  * \param max_output_buffer the requested maximum output size in items.
412  */
413  void set_max_output_buffer(long max_output_buffer);
414 
415  /*!
416  * \brief Request limit on max buffer size on output port \p port.
417  *
418  * \details
419  * This is an advanced feature. Calling this can affect some
420  * fundamental assumptions about the system behavior and
421  * performance.
422  *
423  * The actual buffer size is determined by a number of other
424  * factors from the block and system. This function only provides
425  * a requested maximum. The buffers will always be a multiple of
426  * the system page size, which may be larger than the value asked
427  * for here.
428  *
429  * \param port the output port the request applies to.
430  * \param max_output_buffer the requested maximum output size in items.
431  */
432  void set_max_output_buffer(int port, long max_output_buffer);
433 
434  /*!
435  * \brief Returns min buffer size on output port \p i.
436  */
437  long min_output_buffer(size_t i);
438 
439  /*!
440  * \brief Request limit on the minimum buffer size on all output
441  * ports.
442  *
443  * \details
444  * This is an advanced feature. Calling this can affect some
445  * fundamental assumptions about the system behavior and
446  * performance.
447  *
448  * The actual buffer size is determined by a number of other
449  * factors from the block and system. This function only provides
450  * a requested minimum. The buffers will always be a multiple of
451  * the system page size, which may be larger than the value asked
452  * for here.
453  *
454  * \param min_output_buffer the requested minimum output size in items.
455  */
456  void set_min_output_buffer(long min_output_buffer);
457 
458  /*!
459  * \brief Request limit on min buffer size on output port \p port.
460  *
461  * \details
462  * This is an advanced feature. Calling this can affect some
463  * fundamental assumptions about the system behavior and
464  * performance.
465  *
466  * The actual buffer size is determined by a number of other
467  * factors from the block and system. This function only provides
468  * a requested minimum. The buffers will always be a multiple of
469  * the system page size, which may be larger than the value asked
470  * for here.
471  *
472  * \param port the output port the request applies to.
473  * \param min_output_buffer the requested minimum output size in items.
474  */
475  void set_min_output_buffer(int port, long min_output_buffer);
476 
477  // --------------- Performance counter functions -------------
478 
479  /*!
480  * \brief Gets instantaneous noutput_items performance counter.
481  */
482  float pc_noutput_items();
483 
484  /*!
485  * \brief Gets average noutput_items performance counter.
486  */
487  float pc_noutput_items_avg();
488 
489  /*!
490  * \brief Gets variance of noutput_items performance counter.
491  */
492  float pc_noutput_items_var();
493 
494  /*!
495  * \brief Gets instantaneous num items produced performance counter.
496  */
497  float pc_nproduced();
498 
499  /*!
500  * \brief Gets average num items produced performance counter.
501  */
502  float pc_nproduced_avg();
503 
504  /*!
505  * \brief Gets variance of num items produced performance counter.
506  */
507  float pc_nproduced_var();
508 
509  /*!
510  * \brief Gets instantaneous fullness of \p which input buffer.
511  */
512  float pc_input_buffers_full(int which);
513 
514  /*!
515  * \brief Gets average fullness of \p which input buffer.
516  */
517  float pc_input_buffers_full_avg(int which);
518 
519  /*!
520  * \brief Gets variance of fullness of \p which input buffer.
521  */
522  float pc_input_buffers_full_var(int which);
523 
524  /*!
525  * \brief Gets instantaneous fullness of all input buffers.
526  */
527  std::vector<float> pc_input_buffers_full();
528 
529  /*!
530  * \brief Gets average fullness of all input buffers.
531  */
532  std::vector<float> pc_input_buffers_full_avg();
533 
534  /*!
535  * \brief Gets variance of fullness of all input buffers.
536  */
537  std::vector<float> pc_input_buffers_full_var();
538 
539  /*!
540  * \brief Gets instantaneous fullness of \p which input buffer.
541  */
542  float pc_output_buffers_full(int which);
543 
544  /*!
545  * \brief Gets average fullness of \p which input buffer.
546  */
547  float pc_output_buffers_full_avg(int which);
548 
549  /*!
550  * \brief Gets variance of fullness of \p which input buffer.
551  */
552  float pc_output_buffers_full_var(int which);
553 
554  /*!
555  * \brief Gets instantaneous fullness of all output buffers.
556  */
557  std::vector<float> pc_output_buffers_full();
558 
559  /*!
560  * \brief Gets average fullness of all output buffers.
561  */
562  std::vector<float> pc_output_buffers_full_avg();
563 
564  /*!
565  * \brief Gets variance of fullness of all output buffers.
566  */
567  std::vector<float> pc_output_buffers_full_var();
568 
569  /*!
570  * \brief Gets instantaneous clock cycles spent in work.
571  */
572  float pc_work_time();
573 
574  /*!
575  * \brief Gets average clock cycles spent in work.
576  */
577  float pc_work_time_avg();
578 
579  /*!
580  * \brief Gets average clock cycles spent in work.
581  */
582  float pc_work_time_var();
583 
584  /*!
585  * \brief Gets total clock cycles spent in work.
586  */
587  float pc_work_time_total();
588 
589  /*!
590  * \brief Gets average throughput.
591  */
592  float pc_throughput_avg();
593 
594  /*!
595  * \brief Resets the performance counters
596  */
597  void reset_perf_counters();
598 
599  /*!
600  * \brief Sets up export of perf. counters to ControlPort. Only
601  * called by the scheduler.
602  */
603  void setup_pc_rpc();
604 
605  /*!
606  * \brief Checks if this block is already exporting perf. counters
607  * to ControlPort.
608  */
609  bool is_pc_rpc_set() { return d_pc_rpc_set; }
610 
611  /*!
612  * \brief If the block calls this in its constructor, it's
613  * perf. counters will not be exported.
614  */
615  void no_pc_rpc() { d_pc_rpc_set = true; }
616 
617 
618  // ----------------------------------------------------------------------------
619  // Functions to handle thread affinity
620 
621  /*!
622  * \brief Set the thread's affinity to processor core \p n.
623  *
624  * \param mask a vector of ints of the core numbers available to this block.
625  */
626  void set_processor_affinity(const std::vector<int> &mask);
627 
628  /*!
629  * \brief Remove processor affinity to a specific core.
630  */
631  void unset_processor_affinity();
632 
633  /*!
634  * \brief Get the current processor affinity.
635  */
636  std::vector<int> processor_affinity() { return d_affinity; }
637 
638  /*!
639  * \brief Get the current thread priority in use
640  */
641  int active_thread_priority();
642 
643  /*!
644  * \brief Get the current thread priority stored
645  */
646  int thread_priority();
647 
648  /*!
649  * \brief Set the current thread priority
650  */
651  int set_thread_priority(int priority);
652 
653  bool update_rate() const;
654 
655  // ----------------------------------------------------------------------------
656 
657  /*!
658  * \brief the system message handler
659  */
660  void system_handler(pmt::pmt_t msg);
661 
662  /*!
663  * \brief returns true when execution has completed due to a message connection
664  */
665  bool finished();
666 
667  private:
668  int d_output_multiple;
669  bool d_output_multiple_set;
670  int d_unaligned;
671  bool d_is_unaligned;
672  double d_relative_rate; // approx output_rate / input_rate
673  block_detail_sptr d_detail; // implementation details
674  unsigned d_history;
675  unsigned d_attr_delay; // the block's sample delay
676  bool d_fixed_rate;
677  bool d_max_noutput_items_set; // if d_max_noutput_items is valid
678  int d_max_noutput_items; // value of max_noutput_items for this block
679  int d_min_noutput_items;
680  tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream
681  std::vector<int> d_affinity; // thread affinity proc. mask
682  int d_priority; // thread priority level
683  bool d_pc_rpc_set;
684  bool d_update_rate; // should sched update rel rate?
685  bool d_finished; // true if msg ports think we are finished
686 
687  protected:
688  block(void) {} // allows pure virtual interface sub-classes
689  block(const std::string &name,
690  gr::io_signature::sptr input_signature,
691  gr::io_signature::sptr output_signature);
692 
693  void set_fixed_rate(bool fixed_rate) { d_fixed_rate = fixed_rate; }
694 
695  /*!
696  * \brief Adds a new tag onto the given output buffer.
697  *
698  * \param which_output an integer of which output stream to attach the tag
699  * \param abs_offset a uint64 number of the absolute item number
700  * assicated with the tag. Can get from nitems_written.
701  * \param key the tag key as a PMT symbol
702  * \param value any PMT holding any value for the given key
703  * \param srcid optional source ID specifier; defaults to PMT_F
704  */
705  inline void add_item_tag(unsigned int which_output,
706  uint64_t abs_offset,
707  const pmt::pmt_t &key,
708  const pmt::pmt_t &value,
709  const pmt::pmt_t &srcid=pmt::PMT_F)
710  {
711  tag_t tag;
712  tag.offset = abs_offset;
713  tag.key = key;
714  tag.value = value;
715  tag.srcid = srcid;
716  this->add_item_tag(which_output, tag);
717  }
718 
719  /*!
720  * \brief Adds a new tag onto the given output buffer.
721  *
722  * \param which_output an integer of which output stream to attach the tag
723  * \param tag the tag object to add
724  */
725  void add_item_tag(unsigned int which_output, const tag_t &tag);
726 
727  /*!
728  * \brief DEPRECATED. Will be removed in 3.8.
729  *
730  * \param which_input an integer of which input stream to remove the tag from
731  * \param abs_offset a uint64 number of the absolute item number
732  * assicated with the tag. Can get from nitems_written.
733  * \param key the tag key as a PMT symbol
734  * \param value any PMT holding any value for the given key
735  * \param srcid optional source ID specifier; defaults to PMT_F
736  *
737  * If no such tag is found, does nothing.
738  */
739  inline void remove_item_tag(unsigned int which_input,
740  uint64_t abs_offset,
741  const pmt::pmt_t &key,
742  const pmt::pmt_t &value,
743  const pmt::pmt_t &srcid=pmt::PMT_F)
744  {
745  tag_t tag;
746  tag.offset = abs_offset;
747  tag.key = key;
748  tag.value = value;
749  tag.srcid = srcid;
750  this->remove_item_tag(which_input, tag);
751  }
752 
753  /*!
754  * \brief DEPRECATED. Will be removed in 3.8.
755  *
756  * \param which_input an integer of which input stream to remove the tag from
757  * \param tag the tag object to remove
758  */
759  void remove_item_tag(unsigned int which_input, const tag_t &tag);
760 
761  /*!
762  * \brief Given a [start,end), returns a vector of all tags in the range.
763  *
764  * Range of counts is from start to end-1.
765  *
766  * Tags are tuples of:
767  * (item count, source id, key, value)
768  *
769  * \param v a vector reference to return tags into
770  * \param which_input an integer of which input stream to pull from
771  * \param abs_start a uint64 count of the start of the range of interest
772  * \param abs_end a uint64 count of the end of the range of interest
773  */
774  void get_tags_in_range(std::vector<tag_t> &v,
775  unsigned int which_input,
776  uint64_t abs_start,
777  uint64_t abs_end);
778 
779  /*!
780  * \brief Given a [start,end), returns a vector of all tags in the
781  * range with a given key.
782  *
783  * Range of counts is from start to end-1.
784  *
785  * Tags are tuples of:
786  * (item count, source id, key, value)
787  *
788  * \param v a vector reference to return tags into
789  * \param which_input an integer of which input stream to pull from
790  * \param abs_start a uint64 count of the start of the range of interest
791  * \param abs_end a uint64 count of the end of the range of interest
792  * \param key a PMT symbol key to filter only tags of this key
793  */
794  void get_tags_in_range(std::vector<tag_t> &v,
795  unsigned int which_input,
796  uint64_t abs_start,
797  uint64_t abs_end,
798  const pmt::pmt_t &key);
799 
800  /*!
801  * \brief Gets all tags within the relative window of the current call to work.
802  *
803  * \details
804  *
805  * This opperates much like get_tags_in_range but allows us to
806  * work within the current window of items. Item range is
807  * therefore within the possible range of 0 to
808  * ninput_items[whic_input].
809  *
810  * Range of items counts from \p rel_start to \p rel_end-1 within
811  * current window.
812  *
813  * Tags are tuples of:
814  * (item count, source id, key, value)
815  *
816  * \param v a vector reference to return tags into
817  * \param which_input an integer of which input stream to pull from
818  * \param rel_start a uint64 count of the start of the range of interest
819  * \param rel_end a uint64 count of the end of the range of interest
820  */
821  void get_tags_in_window(std::vector<tag_t> &v,
822  unsigned int which_input,
823  uint64_t rel_start,
824  uint64_t rel_end);
825 
826  /*!
827  * \brief Operates like gr::block::get_tags_in_window with the
828  * ability to only return tags with the specified \p key.
829  *
830  * \details
831  *
832  * \param v a vector reference to return tags into
833  * \param which_input an integer of which input stream to pull from
834  * \param rel_start a uint64 count of the start of the range of interest
835  * \param rel_end a uint64 count of the end of the range of interest
836  * \param key a PMT symbol key to filter only tags of this key
837  */
838  void get_tags_in_window(std::vector<tag_t> &v,
839  unsigned int which_input,
840  uint64_t rel_start,
841  uint64_t rel_end,
842  const pmt::pmt_t &key);
843 
844  void enable_update_rate(bool en);
845 
846  std::vector<long> d_max_output_buffer;
847  std::vector<long> d_min_output_buffer;
848 
849  /*! Used by block's setters and work functions to make
850  * setting/resetting of parameters thread-safe.
851  *
852  * Used by calling gr::thread::scoped_lock l(d_setlock);
853  */
855 
856  /*! Used by blocks to access the logger system.
857  */
860 
861  // These are really only for internal use, but leaving them public avoids
862  // having to work up an ever-varying list of friend GR_RUNTIME_APIs
863 
864  /*! PMT Symbol for "hey, we're done here"
865  */
867 
868  /*! PMT Symbol of the system port, `pmt::mp("system")`
869  */
871 
872  public:
873  block_detail_sptr detail() const { return d_detail; }
874  void set_detail(block_detail_sptr detail) { d_detail = detail; }
875 
876  /*! \brief Tell msg neighbors we are finished
877  */
878  void notify_msg_neighbors();
879 
880  /*! \brief Make sure we don't think we are finished
881  */
882  void clear_finished(){ d_finished = false; }
883 
884  };
885 
886  typedef std::vector<block_sptr> block_vector_t;
887  typedef std::vector<block_sptr>::iterator block_viter_t;
888 
889  inline block_sptr cast_to_block_sptr(basic_block_sptr p)
890  {
891  return boost::dynamic_pointer_cast<block, basic_block>(p);
892  }
893 
894  GR_RUNTIME_API std::ostream&
895  operator << (std::ostream& os, const block *m);
896 
897 } /* namespace gr */
898 
899 #endif /* INCLUDED_GR_RUNTIME_BLOCK_H */
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:45
pmt::pmt_t value
the value of tag (as a PMT)
Definition: tags.h:40
Definition: tags.h:31
uint64_t offset
the item tag occurred at (as a uint64_t)
Definition: tags.h:34
gr::logger_ptr d_debug_logger
Definition: block.h:859
std::vector< int > processor_affinity()
Get the current processor affinity.
Definition: block.h:636
std::vector< block_sptr > block_vector_t
Definition: block.h:886
const pmt::pmt_t d_system_port
Definition: block.h:870
block_detail_sptr detail() const
Definition: block.h:873
void set_fixed_rate(bool fixed_rate)
Definition: block.h:693
void add_item_tag(unsigned int which_output, uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid=pmt::PMT_F)
Adds a new tag onto the given output buffer.
Definition: block.h:705
Definition: block_gateway.h:53
bool output_multiple_set() const
Definition: block.h:213
#define PMT_F
Definition: pmt.h:105
gr::thread::mutex d_setlock
Definition: block.h:854
gr::logger_ptr d_logger
Definition: block.h:858
std::vector< const void * > gr_vector_const_void_star
Definition: gnuradio-runtime/include/gnuradio/types.h:40
Definition: cc_common.h:45
int unaligned() const
Definition: block.h:236
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
int min_noutput_items() const
Return the minimum number of output items this block can produce during a call to work...
Definition: block.h:336
void clear_finished()
Make sure we don&#39;t think we are finished.
Definition: block.h:882
Definition: block_gateway.h:46
Definition: block_gateway.h:47
GR_RUNTIME_API int set_thread_priority(gr_thread_t thread, int priority)
set current thread priority for a given thread ID
std::vector< long > d_min_output_buffer
Definition: block.h:847
std::vector< void * > gr_vector_void_star
Definition: gnuradio-runtime/include/gnuradio/types.h:39
Definition: block_gateway.h:51
std::vector< int > gr_vector_int
Definition: gnuradio-runtime/include/gnuradio/types.h:35
std::vector< block_sptr >::iterator block_viter_t
Definition: block.h:887
std::vector< long > d_max_output_buffer
Definition: block.h:846
Include this header to use the message passing features.
Definition: logger.h:695
void * logger_ptr
Definition: logger.h:696
The abstract base class for all signal processing blocks.Basic blocks are the bare abstraction of an ...
Definition: basic_block.h:58
bool fixed_rate() const
Return true if this block has a fixed input to output rate.
Definition: block.h:141
block(void)
Definition: block.h:688
void set_min_noutput_items(int m)
Set the minimum number of output items this block can produce during a call to work.
Definition: block.h:344
GR_RUNTIME_API int thread_priority(gr_thread_t thread)
get current thread priority for a given thread ID
tag_propagation_policy_t
enum to represent different tag propagation policies.
Definition: block.h:78
bool is_pc_rpc_set()
Checks if this block is already exporting perf. counters to ControlPort.
Definition: block.h:609
pmt::pmt_t key
the key of tag (as a PMT symbol)
Definition: tags.h:37
Definition: block_gateway.h:50
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:399
bool is_unaligned() const
Definition: block.h:238
boost::mutex mutex
Definition: thread.h:48
Definition: block_gateway.h:52
double relative_rate() const
return the approximate output rate / input rate
Definition: block.h:286
pmt::pmt_t srcid
the source ID of tag (as a PMT)
Definition: tags.h:43
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
The abstract base class for all &#39;terminal&#39; processing blocks.A signal processing flow is constructed ...
Definition: block.h:65
const pmt::pmt_t d_pmt_done
Definition: block.h:866
void set_detail(block_detail_sptr detail)
Definition: block.h:874
int alignment() const
Definition: block.h:233
void no_pc_rpc()
If the block calls this in its constructor, it&#39;s perf. counters will not be exported.
Definition: block.h:615
void remove_item_tag(unsigned int which_input, uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid=pmt::PMT_F)
DEPRECATED. Will be removed in 3.8.
Definition: block.h:739
int output_multiple() const
Definition: block.h:212