summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
authorTom Rondeau2010-10-19 16:33:40 -0400
committerTom Rondeau2010-10-19 16:33:40 -0400
commit2c544567f5f9322b51b26a32bdb6280ee12f16de (patch)
treec0f4b0b3646f1795764771ff61fe553d6e66ff92 /gnuradio-core/src/lib
parent068aa7f5b2591f7cc06e4495c89600101bd19b6b (diff)
downloadgnuradio-2c544567f5f9322b51b26a32bdb6280ee12f16de.tar.gz
gnuradio-2c544567f5f9322b51b26a32bdb6280ee12f16de.tar.bz2
gnuradio-2c544567f5f9322b51b26a32bdb6280ee12f16de.zip
Adding vectors to gr_block_detail that keep track of the number of samples read and written from each block's input. Accessor functions allow query of values through gr_block.
Had to add gr_uint64 typedef to SWIG for it to understand how to handle the type.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.cc10
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.h6
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.i3
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block_detail.cc23
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block_detail.h16
-rw-r--r--gnuradio-core/src/lib/swig/gnuradio.i1
6 files changed, 54 insertions, 5 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index 8915f3360..83cc58738 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -117,6 +117,16 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput)
throw std::runtime_error("Unimplemented");
}
+gr_uint64
+gr_block::n_items_read(unsigned int which_input) {
+ return d_detail->n_items_read(which_input);
+}
+
+gr_uint64
+gr_block::n_items_written(unsigned int which_output) {
+ return d_detail->n_items_written(which_output);
+}
+
std::ostream&
operator << (std::ostream& os, const gr_block *m)
{
diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h
index b6f724dde..22e60da57 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.h
+++ b/gnuradio-core/src/lib/runtime/gr_block.h
@@ -198,6 +198,12 @@ class gr_block : public gr_basic_block {
*/
virtual int fixed_rate_noutput_to_ninput(int noutput);
+ // Return the number of items read on input stream which_input
+ gr_uint64 n_items_read(unsigned int which_input);
+
+ // Return the number of items written on output stream which_output
+ gr_uint64 n_items_written(unsigned int which_output);
+
// ----------------------------------------------------------------------------
private:
diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i
index c2e2aa4b8..d70a5854a 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.i
+++ b/gnuradio-core/src/lib/runtime/gr_block.i
@@ -49,6 +49,9 @@ class gr_block : public gr_basic_block {
bool start();
bool stop();
+ gr_uint64 n_items_read(unsigned int which_input);
+ gr_uint64 n_items_written(unsigned int which_output);
+
// internal use
gr_block_detail_sptr detail () const { return d_detail; }
void set_detail (gr_block_detail_sptr detail) { d_detail = detail; }
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
index 38d4a13ca..1f80fe2d4 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
@@ -39,6 +39,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs)
: d_produce_or(0),
d_ninputs (ninputs), d_noutputs (noutputs),
d_input (ninputs), d_output (noutputs),
+ d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0),
d_done (false)
{
s_ncurrently_allocated++;
@@ -88,16 +89,25 @@ gr_block_detail::set_done (bool done)
void
gr_block_detail::consume (int which_input, int how_many_items)
{
- if (how_many_items > 0)
+ if (how_many_items > 0) {
input (which_input)->update_read_pointer (how_many_items);
+
+ // Carefull here; we check that which_input exists above
+ // is this good enough protection that we don't get here?
+ d_n_items_read[which_input] += how_many_items;
+ }
}
+
void
gr_block_detail::consume_each (int how_many_items)
{
- if (how_many_items > 0)
- for (int i = 0; i < ninputs (); i++)
+ if (how_many_items > 0) {
+ for (int i = 0; i < ninputs (); i++) {
d_input[i]->update_read_pointer (how_many_items);
+ d_n_items_read[i] += how_many_items;
+ }
+ }
}
void
@@ -105,6 +115,7 @@ gr_block_detail::produce (int which_output, int how_many_items)
{
if (how_many_items > 0){
d_output[which_output]->update_write_pointer (how_many_items);
+ d_n_items_written[which_output] += how_many_items;
d_produce_or |= how_many_items;
}
}
@@ -112,9 +123,11 @@ gr_block_detail::produce (int which_output, int how_many_items)
void
gr_block_detail::produce_each (int how_many_items)
{
- if (how_many_items > 0){
- for (int i = 0; i < noutputs (); i++)
+ if (how_many_items > 0) {
+ for (int i = 0; i < noutputs (); i++) {
d_output[i]->update_write_pointer (how_many_items);
+ d_n_items_written[i] += how_many_items;
+ }
d_produce_or |= how_many_items;
}
}
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h
index c5787a5ad..e830ddd47 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.h
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h
@@ -88,6 +88,20 @@ class gr_block_detail {
*/
void _post(pmt::pmt_t msg);
+ // Return the number of items read on input stream which_input
+ gr_uint64 n_items_read(unsigned int which_input) {
+ if(which_input >= d_ninputs)
+ throw std::invalid_argument ("gr_block_detail::n_input_items");
+ return d_n_items_read[which_input];
+ }
+
+ // Return the number of items written on output stream which_output
+ gr_uint64 n_items_written(unsigned int which_output) {
+ if(which_output >= d_noutputs)
+ throw std::invalid_argument ("gr_block_detail::n_output_items");
+ return d_n_items_written[which_output];
+ }
+
gr_tpb_detail d_tpb; // used by thread-per-block scheduler
int d_produce_or;
@@ -98,6 +112,8 @@ class gr_block_detail {
unsigned int d_noutputs;
std::vector<gr_buffer_reader_sptr> d_input;
std::vector<gr_buffer_sptr> d_output;
+ std::vector<uint64_t> d_n_items_read;
+ std::vector<uint64_t> d_n_items_written;
bool d_done;
diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i
index 7d0241f1c..60cbf0d58 100644
--- a/gnuradio-core/src/lib/swig/gnuradio.i
+++ b/gnuradio-core/src/lib/swig/gnuradio.i
@@ -46,6 +46,7 @@
typedef std::complex<float> gr_complex;
typedef std::complex<double> gr_complexd;
+typedef unsigned long long gr_uint64;
// instantiate the required template specializations