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