diff options
m--------- | grextras | 0 | ||||
-rw-r--r-- | include/gras/block.hpp | 18 | ||||
-rw-r--r-- | lib/block.cpp | 20 |
3 files changed, 25 insertions, 13 deletions
diff --git a/grextras b/grextras -Subproject 88a6f7aa85baa2d6050ebbc14ada79fb21d6498 +Subproject b36697d1d9f5bc498e696bd1368f1ddeb797cfe diff --git a/include/gras/block.hpp b/include/gras/block.hpp index 1acc532..c33f7f9 100644 --- a/include/gras/block.hpp +++ b/include/gras/block.hpp @@ -264,21 +264,31 @@ struct GRAS_API Block : Element * Use this function to implement passive work-flows. * * \param which_input the input port index - * \return a const reference to the buffer + * \return a reference counted copy of the buffer */ - const SBuffer &get_input_buffer(const size_t which_input) const; + SBuffer get_input_buffer(const size_t which_input) const; /*! * Get access to the underlying reference counted output buffer. * This is the same buffer pointed to by output_items[which]. * This function must be called during the call to work(). * Use this to get a pool of buffers for datagram message ports. - * This function removes the output buffer from the internal queue. * * \param which_output the output port index * \return a reference counted copy of the buffer */ - SBuffer pop_output_buffer(const size_t which_output); + SBuffer get_output_buffer(const size_t which_output) const; + + /*! + * Remove a given number of bytes from the output buffer queue. + * This call is intended to be used with get_output_buffer(). + * If pop_output_buffer() is not called after get_output_buffer(), + * The full-size of the buffer will be automatically popped. + * + * \param which_output the output port index + * \param num_bytes bytes to pop from the output buffer queue + */ + void pop_output_buffer(const size_t which_output, const size_t num_bytes); /*! * Post the given output buffer to the downstream. diff --git a/lib/block.cpp b/lib/block.cpp index 21e2d36..716873b 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -229,23 +229,25 @@ void Block::mark_done(void) (*this)->block->mark_done(); } -const SBuffer &Block::get_input_buffer(const size_t which_input) const +SBuffer Block::get_input_buffer(const size_t which_input) const { return (*this)->block->input_queues.front(which_input); } -SBuffer Block::pop_output_buffer(const size_t which_output) +SBuffer Block::get_output_buffer(const size_t which_output) const { - SBuffer buff = (*this)->block->output_queues.front(which_output); - //set the offset on the buffer to be popped so that something will be removed - //TODO this basically addresses popping on the circ buff, - //but perhaps there is a better API for output buffer access. - //like using get_output_buffer() + pop(some length) - (*this)->block->output_queues.front(which_output).offset = buff.get_actual_length(); - (*this)->block->output_queues.pop(which_output); + SBuffer &buff = (*this)->block->output_queues.front(which_output); + //increment length to auto pop full buffer size, + //when user doesnt call pop_output_buffer() + buff.length = buff.get_actual_length(); return buff; } +void Block::pop_output_buffer(const size_t which_output, const size_t num_bytes) +{ + (*this)->block->output_queues.front(which_output).length = num_bytes; +} + void Block::post_output_buffer(const size_t which_output, const SBuffer &buffer) { (*this)->block->produce_buffer(which_output, buffer); |