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