~ubuntu-branches/ubuntu/trusty/gnuradio/trusty-updates

« back to all changes in this revision

Viewing changes to gnuradio-core/src/lib/runtime/gr_block_detail.cc

  • Committer: Package Import Robot
  • Author(s): A. Maitland Bottoms
  • Date: 2012-02-26 21:26:16 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120226212616-vsfkbi1158xshdql
Tags: 3.5.1-1
* new upstream version, re-packaged from scratch with modern tools
    closes: #642716, #645332, #394849, #616832, #590048, #642580,
    #647018, #557050, #559640, #631863
* CMake build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- c++ -*- */
2
2
/*
3
 
 * Copyright 2004 Free Software Foundation, Inc.
 
3
 * Copyright 2004,2009,2010 Free Software Foundation, Inc.
4
4
 * 
5
5
 * This file is part of GNU Radio
6
6
 * 
27
27
#include <gr_block_detail.h>
28
28
#include <gr_buffer.h>
29
29
 
 
30
using namespace pmt;
 
31
 
30
32
static long s_ncurrently_allocated = 0;
31
33
 
32
34
long
36
38
}
37
39
 
38
40
gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs)
39
 
  : d_ninputs (ninputs), d_noutputs (noutputs),
 
41
  : d_produce_or(0),
 
42
    d_ninputs (ninputs), d_noutputs (noutputs),
40
43
    d_input (ninputs), d_output (noutputs),
41
44
    d_done (false)
42
45
{
87
90
void 
88
91
gr_block_detail::consume (int which_input, int how_many_items)
89
92
{
90
 
  if (how_many_items > 0)
 
93
  if (how_many_items > 0) {
91
94
    input (which_input)->update_read_pointer (how_many_items);
 
95
  }
92
96
}
93
97
 
 
98
 
94
99
void
95
100
gr_block_detail::consume_each (int how_many_items)
96
101
{
97
 
  if (how_many_items > 0)
98
 
    for (int i = 0; i < ninputs (); i++)
 
102
  if (how_many_items > 0) {
 
103
    for (int i = 0; i < ninputs (); i++) {
99
104
      d_input[i]->update_read_pointer (how_many_items);
 
105
    }
 
106
  }
 
107
}
 
108
 
 
109
void
 
110
gr_block_detail::produce (int which_output, int how_many_items)
 
111
{
 
112
  if (how_many_items > 0){
 
113
    d_output[which_output]->update_write_pointer (how_many_items);
 
114
    d_produce_or |= how_many_items;
 
115
  }
100
116
}
101
117
 
102
118
void
103
119
gr_block_detail::produce_each (int how_many_items)
104
120
{
105
 
  if (how_many_items > 0)
106
 
    for (int i = 0; i < noutputs (); i++)
 
121
  if (how_many_items > 0) {
 
122
    for (int i = 0; i < noutputs (); i++) {
107
123
      d_output[i]->update_write_pointer (how_many_items);
 
124
    }
 
125
    d_produce_or |= how_many_items;
 
126
  }
 
127
}
 
128
 
 
129
 
 
130
void
 
131
gr_block_detail::_post(pmt_t msg)
 
132
{
 
133
  d_tpb.insert_tail(msg);
 
134
}
 
135
 
 
136
uint64_t
 
137
gr_block_detail::nitems_read(unsigned int which_input) 
 
138
{
 
139
  if(which_input >= d_ninputs)
 
140
    throw std::invalid_argument ("gr_block_detail::n_input_items");
 
141
  return d_input[which_input]->nitems_read();
 
142
}
 
143
 
 
144
uint64_t
 
145
gr_block_detail::nitems_written(unsigned int which_output) 
 
146
{
 
147
  if(which_output >= d_noutputs)
 
148
    throw std::invalid_argument ("gr_block_detail::n_output_items");
 
149
  return d_output[which_output]->nitems_written();
 
150
}
 
151
 
 
152
void
 
153
gr_block_detail::add_item_tag(unsigned int which_output, const gr_tag_t &tag)
 
154
{
 
155
  if(!pmt_is_symbol(tag.key)) {
 
156
    throw pmt_wrong_type("gr_block_detail::add_item_tag key", tag.key);
 
157
  }
 
158
  else {
 
159
    // Add tag to gr_buffer's deque tags
 
160
    d_output[which_output]->add_item_tag(tag);
 
161
  }
 
162
}
 
163
 
 
164
void
 
165
gr_block_detail::get_tags_in_range(std::vector<gr_tag_t> &v,
 
166
                                   unsigned int which_input,
 
167
                                   uint64_t abs_start,
 
168
                                   uint64_t abs_end)
 
169
{
 
170
  // get from gr_buffer_reader's deque of tags
 
171
  d_input[which_input]->get_tags_in_range(v, abs_start, abs_end);
 
172
}
 
173
 
 
174
void
 
175
gr_block_detail::get_tags_in_range(std::vector<gr_tag_t> &v,
 
176
                                   unsigned int which_input,
 
177
                                   uint64_t abs_start,
 
178
                                   uint64_t abs_end,
 
179
                                   const pmt_t &key)
 
180
{
 
181
  std::vector<gr_tag_t> found_items;
 
182
  
 
183
  v.resize(0);
 
184
 
 
185
  // get from gr_buffer_reader's deque of tags
 
186
  d_input[which_input]->get_tags_in_range(found_items, abs_start, abs_end);
 
187
 
 
188
  // Filter further by key name
 
189
  pmt_t itemkey;
 
190
  std::vector<gr_tag_t>::iterator itr;
 
191
  for(itr = found_items.begin(); itr != found_items.end(); itr++) {
 
192
    itemkey = (*itr).key;
 
193
    if(pmt_eqv(key, itemkey)) {
 
194
      v.push_back(*itr);
 
195
    }
 
196
  }
108
197
}