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