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  * This function should be called at the end of work() or general_work(), after all processing is finished.
232  */
233  void consume(int which_input, int how_many_items);
234 
235  /*!
236  * \brief Tell the scheduler \p how_many_items were consumed on
237  * each input stream.
238  */
239  void consume_each(int how_many_items);
240 
241  /*!
242  * \brief Tell the scheduler \p how_many_items were produced on
243  * output stream \p which_output.
244  *
245  * If the block's general_work method calls produce, \p
246  * general_work must return WORK_CALLED_PRODUCE.
247  */
248  void produce(int which_output, int how_many_items);
249 
250  /*!
251  * \brief Set the approximate output rate / input rate
252  *
253  * Provide a hint to the buffer allocator and scheduler.
254  * The default relative_rate is 1.0
255  *
256  * decimators have relative_rates < 1.0
257  * interpolators have relative_rates > 1.0
258  */
259  void set_relative_rate(double relative_rate);
260 
261  /*!
262  * \brief return the approximate output rate / input rate
263  */
264  double relative_rate() const { return d_relative_rate; }
265 
266  /*
267  * The following two methods provide special case info to the
268  * scheduler in the event that a block has a fixed input to output
269  * ratio. sync_block, sync_decimator and
270  * sync_interpolator override these. If you're fixed rate,
271  * subclass one of those.
272  */
273  /*!
274  * \brief Given ninput samples, return number of output samples that will be produced.
275  * N.B. this is only defined if fixed_rate returns true.
276  * Generally speaking, you don't need to override this.
277  */
278  virtual int fixed_rate_ninput_to_noutput(int ninput);
279 
280  /*!
281  * \brief Given noutput samples, return number of input samples required to produce noutput.
282  * N.B. this is only defined if fixed_rate returns true.
283  * Generally speaking, you don't need to override this.
284  */
285  virtual int fixed_rate_noutput_to_ninput(int noutput);
286 
287  /*!
288  * \brief Return the number of items read on input stream which_input
289  */
290  uint64_t nitems_read(unsigned int which_input);
291 
292  /*!
293  * \brief Return the number of items written on output stream which_output
294  */
295  uint64_t nitems_written(unsigned int which_output);
296 
297  /*!
298  * \brief Asks for the policy used by the scheduler to moved tags downstream.
299  */
300  tag_propagation_policy_t tag_propagation_policy();
301 
302  /*!
303  * \brief Set the policy by the scheduler to determine how tags are moved downstream.
304  */
305  void set_tag_propagation_policy(tag_propagation_policy_t p);
306 
307  /*!
308  * \brief Return the minimum number of output items this block can
309  * produce during a call to work.
310  *
311  * Should be 0 for most blocks. Useful if we're dealing with
312  * packets and the block produces one packet per call to work.
313  */
314  int min_noutput_items() const { return d_min_noutput_items; }
315 
316  /*!
317  * \brief Set the minimum number of output items this block can
318  * produce during a call to work.
319  *
320  * \param m the minimum noutput_items this block can produce.
321  */
322  void set_min_noutput_items(int m) { d_min_noutput_items = m; }
323 
324  /*!
325  * \brief Return the maximum number of output items this block will
326  * handle during a call to work.
327  */
328  int max_noutput_items();
329 
330  /*!
331  * \brief Set the maximum number of output items this block will
332  * handle during a call to work.
333  *
334  * \param m the maximum noutput_items this block will handle.
335  */
336  void set_max_noutput_items(int m);
337 
338  /*!
339  * \brief Clear the switch for using the max_noutput_items value of this block.
340  *
341  * When is_set_max_noutput_items() returns 'true', the scheduler
342  * will use the value returned by max_noutput_items() to limit the
343  * size of the number of items possible for this block's work
344  * function. If is_set_max_notput_items() returns 'false', then
345  * the scheduler ignores the internal value and uses the value set
346  * globally in the top_block.
347  *
348  * Use this value to clear the 'is_set' flag so the scheduler will
349  * ignore this. Use the set_max_noutput_items(m) call to both set
350  * a new value for max_noutput_items and to re-enable its use in
351  * the scheduler.
352  */
353  void unset_max_noutput_items();
354 
355  /*!
356  * \brief Ask the block if the flag is or is not set to use the
357  * internal value of max_noutput_items during a call to work.
358  */
359  bool is_set_max_noutput_items();
360 
361  /*
362  * Used to expand the vectors that hold the min/max buffer sizes.
363  *
364  * Specifically, when -1 is used, the vectors are just initialized
365  * with 1 value; this is used by the flat_flowgraph to expand when
366  * required to add a new value for new ports on these blocks.
367  */
368  void expand_minmax_buffer(int port);
369 
370  /*!
371  * \brief Returns max buffer size on output port \p i.
372  */
373  long max_output_buffer(size_t i);
374 
375  /*!
376  * \brief Request limit on max buffer size on all output ports.
377  *
378  * \details
379  * This is an advanced feature. Calling this can affect some
380  * fundamental assumptions about the system behavior and
381  * performance.
382  *
383  * The actual buffer size is determined by a number of other
384  * factors from the block and system. This function only provides
385  * a requested maximum. The buffers will always be a multiple of
386  * the system page size, which may be larger than the value asked
387  * for here.
388  *
389  * \param max_output_buffer the requested maximum output size in items.
390  */
391  void set_max_output_buffer(long max_output_buffer);
392 
393  /*!
394  * \brief Request limit on max buffer size on output port \p port.
395  *
396  * \details
397  * This is an advanced feature. Calling this can affect some
398  * fundamental assumptions about the system behavior and
399  * performance.
400  *
401  * The actual buffer size is determined by a number of other
402  * factors from the block and system. This function only provides
403  * a requested maximum. The buffers will always be a multiple of
404  * the system page size, which may be larger than the value asked
405  * for here.
406  *
407  * \param port the output port the request applies to.
408  * \param max_output_buffer the requested maximum output size in items.
409  */
410  void set_max_output_buffer(int port, long max_output_buffer);
411 
412  /*!
413  * \brief Returns min buffer size on output port \p i.
414  */
415  long min_output_buffer(size_t i);
416 
417  /*!
418  * \brief Request limit on the minimum buffer size on all output
419  * ports.
420  *
421  * \details
422  * This is an advanced feature. Calling this can affect some
423  * fundamental assumptions about the system behavior and
424  * performance.
425  *
426  * The actual buffer size is determined by a number of other
427  * factors from the block and system. This function only provides
428  * a requested minimum. The buffers will always be a multiple of
429  * the system page size, which may be larger than the value asked
430  * for here.
431  *
432  * \param min_output_buffer the requested minimum output size in items.
433  */
434  void set_min_output_buffer(long min_output_buffer);
435 
436  /*!
437  * \brief Request limit on min buffer size on output port \p port.
438  *
439  * \details
440  * This is an advanced feature. Calling this can affect some
441  * fundamental assumptions about the system behavior and
442  * performance.
443  *
444  * The actual buffer size is determined by a number of other
445  * factors from the block and system. This function only provides
446  * a requested minimum. The buffers will always be a multiple of
447  * the system page size, which may be larger than the value asked
448  * for here.
449  *
450  * \param port the output port the request applies to.
451  * \param min_output_buffer the requested minimum output size in items.
452  */
453  void set_min_output_buffer(int port, long min_output_buffer);
454 
455  // --------------- Performance counter functions -------------
456 
457  /*!
458  * \brief Gets instantaneous noutput_items performance counter.
459  */
460  float pc_noutput_items();
461 
462  /*!
463  * \brief Gets average noutput_items performance counter.
464  */
465  float pc_noutput_items_avg();
466 
467  /*!
468  * \brief Gets variance of noutput_items performance counter.
469  */
470  float pc_noutput_items_var();
471 
472  /*!
473  * \brief Gets instantaneous num items produced performance counter.
474  */
475  float pc_nproduced();
476 
477  /*!
478  * \brief Gets average num items produced performance counter.
479  */
480  float pc_nproduced_avg();
481 
482  /*!
483  * \brief Gets variance of num items produced performance counter.
484  */
485  float pc_nproduced_var();
486 
487  /*!
488  * \brief Gets instantaneous fullness of \p which input buffer.
489  */
490  float pc_input_buffers_full(int which);
491 
492  /*!
493  * \brief Gets average fullness of \p which input buffer.
494  */
495  float pc_input_buffers_full_avg(int which);
496 
497  /*!
498  * \brief Gets variance of fullness of \p which input buffer.
499  */
500  float pc_input_buffers_full_var(int which);
501 
502  /*!
503  * \brief Gets instantaneous fullness of all input buffers.
504  */
505  std::vector<float> pc_input_buffers_full();
506 
507  /*!
508  * \brief Gets average fullness of all input buffers.
509  */
510  std::vector<float> pc_input_buffers_full_avg();
511 
512  /*!
513  * \brief Gets variance of fullness of all input buffers.
514  */
515  std::vector<float> pc_input_buffers_full_var();
516 
517  /*!
518  * \brief Gets instantaneous fullness of \p which input buffer.
519  */
520  float pc_output_buffers_full(int which);
521 
522  /*!
523  * \brief Gets average fullness of \p which input buffer.
524  */
525  float pc_output_buffers_full_avg(int which);
526 
527  /*!
528  * \brief Gets variance of fullness of \p which input buffer.
529  */
530  float pc_output_buffers_full_var(int which);
531 
532  /*!
533  * \brief Gets instantaneous fullness of all output buffers.
534  */
535  std::vector<float> pc_output_buffers_full();
536 
537  /*!
538  * \brief Gets average fullness of all output buffers.
539  */
540  std::vector<float> pc_output_buffers_full_avg();
541 
542  /*!
543  * \brief Gets variance of fullness of all output buffers.
544  */
545  std::vector<float> pc_output_buffers_full_var();
546 
547  /*!
548  * \brief Gets instantaneous clock cycles spent in work.
549  */
550  float pc_work_time();
551 
552  /*!
553  * \brief Gets average clock cycles spent in work.
554  */
555  float pc_work_time_avg();
556 
557  /*!
558  * \brief Gets average clock cycles spent in work.
559  */
560  float pc_work_time_var();
561 
562  /*!
563  * \brief Gets total clock cycles spent in work.
564  */
565  float pc_work_time_total();
566 
567  /*!
568  * \brief Gets average throughput.
569  */
570  float pc_throughput_avg();
571 
572  /*!
573  * \brief Resets the performance counters
574  */
575  void reset_perf_counters();
576 
577  /*!
578  * \brief Sets up export of perf. counters to ControlPort. Only
579  * called by the scheduler.
580  */
581  void setup_pc_rpc();
582 
583  /*!
584  * \brief Checks if this block is already exporting perf. counters
585  * to ControlPort.
586  */
587  bool is_pc_rpc_set() { return d_pc_rpc_set; }
588 
589  /*!
590  * \brief If the block calls this in its constructor, it's
591  * perf. counters will not be exported.
592  */
593  void no_pc_rpc() { d_pc_rpc_set = true; }
594 
595 
596  // ----------------------------------------------------------------------------
597  // Functions to handle thread affinity
598 
599  /*!
600  * \brief Set the thread's affinity to processor core \p n.
601  *
602  * \param mask a vector of ints of the core numbers available to this block.
603  */
604  void set_processor_affinity(const std::vector<int> &mask);
605 
606  /*!
607  * \brief Remove processor affinity to a specific core.
608  */
609  void unset_processor_affinity();
610 
611  /*!
612  * \brief Get the current processor affinity.
613  */
614  std::vector<int> processor_affinity() { return d_affinity; }
615 
616  /*!
617  * \brief Get the current thread priority in use
618  */
619  int active_thread_priority();
620 
621  /*!
622  * \brief Get the current thread priority stored
623  */
624  int thread_priority();
625 
626  /*!
627  * \brief Set the current thread priority
628  */
629  int set_thread_priority(int priority);
630 
631  bool update_rate() const;
632 
633  // ----------------------------------------------------------------------------
634 
635  /*!
636  * \brief the system message handler
637  */
638  void system_handler(pmt::pmt_t msg);
639 
640  /*!
641  * \brief returns true when execution has completed due to a message connection
642  */
643  bool finished();
644 
645  private:
646  int d_output_multiple;
647  bool d_output_multiple_set;
648  int d_unaligned;
649  bool d_is_unaligned;
650  double d_relative_rate; // approx output_rate / input_rate
651  block_detail_sptr d_detail; // implementation details
652  unsigned d_history;
653  unsigned d_attr_delay; // the block's sample delay
654  bool d_fixed_rate;
655  bool d_max_noutput_items_set; // if d_max_noutput_items is valid
656  int d_max_noutput_items; // value of max_noutput_items for this block
657  int d_min_noutput_items;
658  tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream
659  std::vector<int> d_affinity; // thread affinity proc. mask
660  int d_priority; // thread priority level
661  bool d_pc_rpc_set;
662  bool d_update_rate; // should sched update rel rate?
663  bool d_finished; // true if msg ports think we are finished
664 
665  protected:
666  block(void) {} // allows pure virtual interface sub-classes
667  block(const std::string &name,
668  gr::io_signature::sptr input_signature,
669  gr::io_signature::sptr output_signature);
670 
671  void set_fixed_rate(bool fixed_rate) { d_fixed_rate = fixed_rate; }
672 
673  /*!
674  * \brief Adds a new tag onto the given output buffer.
675  *
676  * \param which_output an integer of which output stream to attach the tag
677  * \param abs_offset a uint64 number of the absolute item number
678  * assicated with the tag. Can get from nitems_written.
679  * \param key the tag key as a PMT symbol
680  * \param value any PMT holding any value for the given key
681  * \param srcid optional source ID specifier; defaults to PMT_F
682  */
683  inline void add_item_tag(unsigned int which_output,
684  uint64_t abs_offset,
685  const pmt::pmt_t &key,
686  const pmt::pmt_t &value,
687  const pmt::pmt_t &srcid=pmt::PMT_F)
688  {
689  tag_t tag;
690  tag.offset = abs_offset;
691  tag.key = key;
692  tag.value = value;
693  tag.srcid = srcid;
694  this->add_item_tag(which_output, tag);
695  }
696 
697  /*!
698  * \brief Adds a new tag onto the given output buffer.
699  *
700  * \param which_output an integer of which output stream to attach the tag
701  * \param tag the tag object to add
702  */
703  void add_item_tag(unsigned int which_output, const tag_t &tag);
704 
705  /*!
706  * \brief DEPRECATED. Will be removed in 3.8.
707  *
708  * \param which_input an integer of which input stream to remove the tag from
709  * \param abs_offset a uint64 number of the absolute item number
710  * assicated with the tag. Can get from nitems_written.
711  * \param key the tag key as a PMT symbol
712  * \param value any PMT holding any value for the given key
713  * \param srcid optional source ID specifier; defaults to PMT_F
714  *
715  * If no such tag is found, does nothing.
716  */
717  inline void remove_item_tag(unsigned int which_input,
718  uint64_t abs_offset,
719  const pmt::pmt_t &key,
720  const pmt::pmt_t &value,
721  const pmt::pmt_t &srcid=pmt::PMT_F)
722  {
723  tag_t tag;
724  tag.offset = abs_offset;
725  tag.key = key;
726  tag.value = value;
727  tag.srcid = srcid;
728  this->remove_item_tag(which_input, tag);
729  }
730 
731  /*!
732  * \brief DEPRECATED. Will be removed in 3.8.
733  *
734  * \param which_input an integer of which input stream to remove the tag from
735  * \param tag the tag object to remove
736  */
737  void remove_item_tag(unsigned int which_input, const tag_t &tag);
738 
739  /*!
740  * \brief Given a [start,end), returns a vector of all tags in the range.
741  *
742  * Range of counts is from start to end-1.
743  *
744  * Tags are tuples of:
745  * (item count, source id, key, value)
746  *
747  * \param v a vector reference to return tags into
748  * \param which_input an integer of which input stream to pull from
749  * \param abs_start a uint64 count of the start of the range of interest
750  * \param abs_end a uint64 count of the end of the range of interest
751  */
752  void get_tags_in_range(std::vector<tag_t> &v,
753  unsigned int which_input,
754  uint64_t abs_start,
755  uint64_t abs_end);
756 
757  /*!
758  * \brief Given a [start,end), returns a vector of all tags in the
759  * range with a given key.
760  *
761  * Range of counts is from start to end-1.
762  *
763  * Tags are tuples of:
764  * (item count, source id, key, value)
765  *
766  * \param v a vector reference to return tags into
767  * \param which_input an integer of which input stream to pull from
768  * \param abs_start a uint64 count of the start of the range of interest
769  * \param abs_end a uint64 count of the end of the range of interest
770  * \param key a PMT symbol key to filter only tags of this key
771  */
772  void get_tags_in_range(std::vector<tag_t> &v,
773  unsigned int which_input,
774  uint64_t abs_start,
775  uint64_t abs_end,
776  const pmt::pmt_t &key);
777 
778  /*!
779  * \brief Gets all tags within the relative window of the current call to work.
780  *
781  * \details
782  *
783  * This opperates much like get_tags_in_range but allows us to
784  * work within the current window of items. Item range is
785  * therefore within the possible range of 0 to
786  * ninput_items[whic_input].
787  *
788  * Range of items counts from \p rel_start to \p rel_end-1 within
789  * current window.
790  *
791  * Tags are tuples of:
792  * (item count, source id, key, value)
793  *
794  * \param v a vector reference to return tags into
795  * \param which_input an integer of which input stream to pull from
796  * \param rel_start a uint64 count of the start of the range of interest
797  * \param rel_end a uint64 count of the end of the range of interest
798  */
799  void get_tags_in_window(std::vector<tag_t> &v,
800  unsigned int which_input,
801  uint64_t rel_start,
802  uint64_t rel_end);
803 
804  /*!
805  * \brief Operates like gr::block::get_tags_in_window with the
806  * ability to only return tags with the specified \p key.
807  *
808  * \details
809  *
810  * \param v a vector reference to return tags into
811  * \param which_input an integer of which input stream to pull from
812  * \param rel_start a uint64 count of the start of the range of interest
813  * \param rel_end a uint64 count of the end of the range of interest
814  * \param key a PMT symbol key to filter only tags of this key
815  */
816  void get_tags_in_window(std::vector<tag_t> &v,
817  unsigned int which_input,
818  uint64_t rel_start,
819  uint64_t rel_end,
820  const pmt::pmt_t &key);
821 
822  void enable_update_rate(bool en);
823 
824  std::vector<long> d_max_output_buffer;
825  std::vector<long> d_min_output_buffer;
826 
827  /*! Used by block's setters and work functions to make
828  * setting/resetting of parameters thread-safe.
829  *
830  * Used by calling gr::thread::scoped_lock l(d_setlock);
831  */
833 
834  /*! Used by blocks to access the logger system.
835  */
838 
839  // These are really only for internal use, but leaving them public avoids
840  // having to work up an ever-varying list of friend GR_RUNTIME_APIs
841 
842  public:
843  block_detail_sptr detail() const { return d_detail; }
844  void set_detail(block_detail_sptr detail) { d_detail = detail; }
845 
846  /*! \brief Tell msg neighbors we are finished
847  */
848  void notify_msg_neighbors();
849 
850  /*! \brief Make sure we dont think we are finished
851  */
852  void clear_finished(){ d_finished = false; }
853 
854  };
855 
856  typedef std::vector<block_sptr> block_vector_t;
857  typedef std::vector<block_sptr>::iterator block_viter_t;
858 
859  inline block_sptr cast_to_block_sptr(basic_block_sptr p)
860  {
861  return boost::dynamic_pointer_cast<block, basic_block>(p);
862  }
863 
864  GR_RUNTIME_API std::ostream&
865  operator << (std::ostream& os, const block *m);
866 
867 } /* namespace gr */
868 
869 #endif /* INCLUDED_GR_RUNTIME_BLOCK_H */
double relative_rate() const
return the approximate output rate / input rate
Definition: block.h:264
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:837
std::vector< int > processor_affinity()
Get the current processor affinity.
Definition: block.h:614
std::vector< block_sptr > block_vector_t
Definition: block.h:856
block_detail_sptr detail() const
Definition: block.h:843
int output_multiple() const
Definition: block.h:200
void set_fixed_rate(bool fixed_rate)
Definition: block.h:671
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:683
Definition: block_gateway.h:48
#define PMT_F
Definition: pmt.h:105
gr::thread::mutex d_setlock
Definition: block.h:832
bool output_multiple_set() const
Definition: block.h:201
gr::logger_ptr d_logger
Definition: block.h:836
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:852
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:825
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:857
std::vector< long > d_max_output_buffer
Definition: block.h:824
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:666
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:322
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:314
bool is_pc_rpc_set()
Checks if this block is already exporting perf. counters to ControlPort.
Definition: block.h:587
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:844
void no_pc_rpc()
If the block calls this in its constructor, it&#39;s perf. counters will not be exported.
Definition: block.h:593
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:717