root / gnuradio-core / src / lib / runtime / gr_block_detail.cc @ e3b86688
History | View | Annotate | Download (4.8 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2004,2009 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 | #ifdef HAVE_CONFIG_H
|
| 24 | #include "config.h" |
| 25 | #endif
|
| 26 | |
| 27 | #include <gr_block_detail.h> |
| 28 | #include <gr_buffer.h> |
| 29 | |
| 30 | static long s_ncurrently_allocated = 0; |
| 31 | |
| 32 | long
|
| 33 | gr_block_detail_ncurrently_allocated () |
| 34 | {
|
| 35 | return s_ncurrently_allocated;
|
| 36 | } |
| 37 | |
| 38 | gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) |
| 39 | : d_produce_or(0),
|
| 40 | d_ninputs (ninputs), d_noutputs (noutputs), |
| 41 | d_input (ninputs), d_output (noutputs), |
| 42 | d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0), |
| 43 | d_done (false)
|
| 44 | {
|
| 45 | s_ncurrently_allocated++; |
| 46 | } |
| 47 | |
| 48 | gr_block_detail::~gr_block_detail () |
| 49 | {
|
| 50 | // should take care of itself
|
| 51 | s_ncurrently_allocated--; |
| 52 | } |
| 53 | |
| 54 | void
|
| 55 | gr_block_detail::set_input (unsigned int which, gr_buffer_reader_sptr reader) |
| 56 | {
|
| 57 | if (which >= d_ninputs)
|
| 58 | throw std::invalid_argument ("gr_block_detail::set_input"); |
| 59 | |
| 60 | d_input[which] = reader; |
| 61 | } |
| 62 | |
| 63 | void
|
| 64 | gr_block_detail::set_output (unsigned int which, gr_buffer_sptr buffer) |
| 65 | {
|
| 66 | if (which >= d_noutputs)
|
| 67 | throw std::invalid_argument ("gr_block_detail::set_output"); |
| 68 | |
| 69 | d_output[which] = buffer; |
| 70 | } |
| 71 | |
| 72 | gr_block_detail_sptr |
| 73 | gr_make_block_detail (unsigned int ninputs, unsigned int noutputs) |
| 74 | {
|
| 75 | return gr_block_detail_sptr (new gr_block_detail (ninputs, noutputs)); |
| 76 | } |
| 77 | |
| 78 | void
|
| 79 | gr_block_detail::set_done (bool done)
|
| 80 | {
|
| 81 | d_done = done; |
| 82 | for (unsigned int i = 0; i < d_noutputs; i++) |
| 83 | d_output[i]->set_done (done); |
| 84 | |
| 85 | for (unsigned int i = 0; i < d_ninputs; i++) |
| 86 | d_input[i]->set_done (done); |
| 87 | } |
| 88 | |
| 89 | void
|
| 90 | gr_block_detail::consume (int which_input, int how_many_items) |
| 91 | {
|
| 92 | if (how_many_items > 0) { |
| 93 | input (which_input)->update_read_pointer (how_many_items); |
| 94 | |
| 95 | // Carefull here; we check that which_input exists above
|
| 96 | // is this good enough protection that we don't get here?
|
| 97 | d_n_items_read[which_input] += how_many_items; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | void
|
| 103 | gr_block_detail::consume_each (int how_many_items)
|
| 104 | {
|
| 105 | if (how_many_items > 0) { |
| 106 | for (int i = 0; i < ninputs (); i++) { |
| 107 | d_input[i]->update_read_pointer (how_many_items); |
| 108 | d_n_items_read[i] += how_many_items; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | void
|
| 114 | gr_block_detail::produce (int which_output, int how_many_items) |
| 115 | {
|
| 116 | if (how_many_items > 0){ |
| 117 | d_output[which_output]->update_write_pointer (how_many_items); |
| 118 | d_n_items_written[which_output] += how_many_items; |
| 119 | d_produce_or |= how_many_items; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void
|
| 124 | gr_block_detail::produce_each (int how_many_items)
|
| 125 | {
|
| 126 | if (how_many_items > 0) { |
| 127 | for (int i = 0; i < noutputs (); i++) { |
| 128 | d_output[i]->update_write_pointer (how_many_items); |
| 129 | d_n_items_written[i] += how_many_items; |
| 130 | } |
| 131 | d_produce_or |= how_many_items; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | |
| 136 | void
|
| 137 | gr_block_detail::_post(pmt::pmt_t msg) |
| 138 | {
|
| 139 | d_tpb.insert_tail(msg); |
| 140 | } |
| 141 | |
| 142 | void
|
| 143 | gr_block_detail::add_item_tag(unsigned int which_output, |
| 144 | gr_uint64 offset, |
| 145 | const pmt::pmt_t &key, const pmt::pmt_t &value) |
| 146 | {
|
| 147 | if(pmt::pmt_is_symbol(key) == false) { |
| 148 | throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); |
| 149 | } |
| 150 | else {
|
| 151 | pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); |
| 152 | pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL");
|
| 153 | pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); |
| 154 | d_item_tags.push_back(tuple); |
| 155 | |
| 156 | // need to add prunning routing
|
| 157 | } |
| 158 | } |
| 159 | |
| 160 | std::list<pmt::pmt_t> |
| 161 | gr_block_detail::get_tags_in_range(unsigned int which_output, |
| 162 | gr_uint64 start, gr_uint64 end) |
| 163 | {
|
| 164 | std::list<pmt::pmt_t> found_items; |
| 165 | std::list<pmt::pmt_t>::iterator itr = d_item_tags.begin(); |
| 166 | |
| 167 | gr_uint64 item_time; |
| 168 | while(itr != d_item_tags.end()) {
|
| 169 | item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0));
|
| 170 | |
| 171 | // items are pushed onto list in sequential order; stop if we're past end
|
| 172 | if(item_time > end) {
|
| 173 | break;
|
| 174 | } |
| 175 | |
| 176 | if((item_time > start) && (item_time < end)) {
|
| 177 | found_items.push_back(*itr); |
| 178 | } |
| 179 | |
| 180 | itr++; |
| 181 | } |
| 182 | |
| 183 | return found_items;
|
| 184 | } |
| 185 | |
| 186 | std::list<pmt::pmt_t> |
| 187 | gr_block_detail::get_tags_in_range(unsigned int which_output, |
| 188 | gr_uint64 start, gr_uint64 end, |
| 189 | const pmt::pmt_t &key)
|
| 190 | {
|
| 191 | std::list<pmt::pmt_t> found_items; |
| 192 | std::list<pmt::pmt_t>::iterator itr = d_item_tags.begin(); |
| 193 | |
| 194 | return found_items;
|
| 195 | } |