Dear Marcus,
Thanks for thorough explanation.
Let me summarize the information, as below.
Correct me if I am wrong.
1). For sink block derived from gr::sync_block, its work() function should return noutput_items,
even though sink block doesn't produce any output.
This is a norm.
2). We could opt to let the above work() function returns 0 instead of noutput_items.
In this case it should call consume_each(noutput_items) before the return.
All other remain the same, this should work.
3). Can we derive a sink block from gr::block ?
In this case we must explicitly call consume_each(noutput_items) in its general_work() function.
Should the general_work() return 0, or return noutput_items, or either one will do?
The forecast() is defined to include
ninput_items_required[0] = noutput_items;
Question 1:
Sink block doesn't produce any output, hence, noutput_items=0.
If this noutput_items has a non-zero value, what does this value means, how is it calculated?
it says that "Sources and sinks are derived from gr::sync_block".
Why should sink block be categorised as sync block?
Sync block is defined as block that has the same number of input items and output items,
but sink block doesn't fulfill this condition (sink block has no output).
Note:
My flow graph is very simple. It consists of only two blocks, namely a source block and a sink block.
The source block sends out a series of integer numbers.
The sink block receives the integers, and print it out (std::cout).
Below is the code of the sink block.
Filename: gr-activecat/lib/integer_sink_impl.cc
namespace gr {
namespace activecat {
integer_sink::sptr integer_sink::make()
{ return gnuradio::get_initial_sptr (new integer_sink_impl()); }
// private constructor
integer_sink_impl::integer_sink_impl()
: gr_sync_block("integer_sink",
gr_make_io_signature( 1, 1, sizeof(int) ),
gr_make_io_signature( 0, 0, 0 ))
{ }
// virtual destructor
integer_sink_impl::~integer_sink_impl()
{ }
int
integer_sink_impl::work( int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const int *in = (const int *) input_items[0];
std::cout << "integer_sink receives: ";
for (int i=0; i < noutput_items; i++)
std::cout << in[i] << ", ";
std::cout << std::endl;
return noutput_items; // Don't return 0, else the flowgraph won't stop even after the source block's work() fucntion return -1
}
} /* namespace activecat */
} /* namespace gr */