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