cgv
|
Base class for system command output pipe or named pipe threads including a queue of data blocks, a vector storing smaller data packages and a separate thread. More...
#include <pipe_thread.h>
Public Member Functions | |
queued_input_thread (bool _is_binary, size_t _package_size, size_t _packeges_per_block, unsigned _ms_to_wait) | |
construct queued input thread with binary mode flag and wait time in ms used when pipe is empty | |
void | run () |
continuously read from pipe and store in queue; if empty, wait in intervals of ms_to_wait milliseconds | |
bool | pop_data_block (char *buffer) |
if done() had not been called, read a data block from the queue; can fail if no data or done() was called | |
size_t | get_nr_blocks () const |
returns the number of blocks in the queue of not yet read data | |
void | done () |
call this to indicate no more data will come | |
![]() | |
thread () | |
create the thread | |
virtual | ~thread () |
standard destructor (a running thread will be killed) | |
void | start (bool _delete_after_termination=false) |
start the implemented run() method (asynchronly) and destruct the thread object | |
void | stop () |
try to stop the thread execution via indicating a stop request. | |
void | kill () |
kill a running thread | |
void | wait_for_completion () |
the thread is interpreted as a slave thread and started from another master thread. | |
bool | is_running () |
return true if thread is running | |
bool | have_stop_request () |
check if there is a stop request | |
thread_id_type | get_id () const |
return id of this thread | |
Protected Member Functions | |
virtual bool | connect_to_source ()=0 |
to be implemented in derived classes | |
virtual size_t | read_package_from_pipe (char *buffer, size_t package_size)=0 |
to be implemented in derived classes | |
virtual void | move_packages_to_data_blocks () |
combine the packages to a data block and push it to the queue | |
virtual void | close ()=0 |
to be implemented in derived classes | |
![]() | |
void | execute () |
executes the run method | |
Protected Attributes | |
bool | all_data_received = false |
flag to mark end of data stream | |
bool | is_binary |
whether binary mode should be used | |
size_t | package_size |
size of an indiviual package | |
size_t | package_index |
index of the next package to be read | |
size_t | packages_per_block |
amount of packeges needed to form one data block | |
std::mutex | mutex_packages |
mutex used to protect access to packages | |
std::mutex | mutex_data_blocks |
mutex used to protect access to data_blocks | |
char * | packages |
allocated memory for smaller data packages | |
std::deque< std::vector< char > > | data_blocks |
deque to store data blocks that are formed by packages | |
unsigned | ms_to_wait |
time in milliseconds to wait while pipe is empty | |
![]() | |
void * | thread_ptr |
bool | stop_request |
bool | running |
bool | delete_after_termination |
Additional Inherited Members | |
![]() | |
static void | wait_for_signal (condition_mutex &cm) |
sleep till the signal from the given condition_mutex is sent, lock the mutex first and unlock after waiting | |
static void | wait_for_signal_with_lock (condition_mutex &cm) |
prefered approach to wait for signal and implemented as { cm.lock(); wait_for_signal(cm); cm.unlock(); } | |
static bool | wait_for_signal_or_timeout (condition_mutex &cm, unsigned millisec) |
sleep till the signal from the given condition_mutex is sent or the timeout is reached, lock the mutex first and unlock after waiting | |
static bool | wait_for_signal_or_timeout_with_lock (condition_mutex &cm, unsigned millisec) |
prefered approach to wait for signal or the timeout is reached and implemented as { cm.lock(); wait_for_signal_or_timeout(cm,millisec); cm.unlock(); } | |
static void | wait (unsigned millisec) |
wait the given number of milliseconds | |
static thread_id_type | get_current_thread_id () |
return the id of the currently executed thread | |
![]() | |
static void * | execute_s (void *args) |
Base class for system command output pipe or named pipe threads including a queue of data blocks, a vector storing smaller data packages and a separate thread.
Definition at line 109 of file pipe_thread.h.
cgv::os::queued_input_thread::queued_input_thread | ( | bool | _is_binary, |
size_t | _package_size, | ||
size_t | _packeges_per_block, | ||
unsigned | _ms_to_wait | ||
) |
construct queued input thread with binary mode flag and wait time in ms used when pipe is empty
Definition at line 162 of file pipe_thread.cxx.
References is_binary, ms_to_wait, package_index, package_size, packages, and packages_per_block.
|
protectedpure virtual |
to be implemented in derived classes
Implemented in cgv::os::named_pipe_input_thread, and cgv::os::pipe_input_thread.
Referenced by run().
|
protectedpure virtual |
to be implemented in derived classes
Implemented in cgv::os::named_pipe_input_thread, and cgv::os::pipe_input_thread.
Referenced by run().
void cgv::os::queued_input_thread::done | ( | ) |
call this to indicate no more data will come
Definition at line 253 of file pipe_thread.cxx.
References all_data_received, and mutex_packages.
Referenced by run().
size_t cgv::os::queued_input_thread::get_nr_blocks | ( | ) | const |
returns the number of blocks in the queue of not yet read data
Definition at line 245 of file pipe_thread.cxx.
References data_blocks, and mutex_data_blocks.
|
protectedvirtual |
combine the packages to a data block and push it to the queue
Definition at line 213 of file pipe_thread.cxx.
References data_blocks, mutex_data_blocks, mutex_packages, package_index, package_size, packages, and packages_per_block.
Referenced by run().
bool cgv::os::queued_input_thread::pop_data_block | ( | char * | buffer | ) |
if done() had not been called, read a data block from the queue; can fail if no data or done() was called
Definition at line 230 of file pipe_thread.cxx.
References data_blocks, mutex_data_blocks, package_size, and packages_per_block.
|
protectedpure virtual |
to be implemented in derived classes
Implemented in cgv::os::named_pipe_input_thread, and cgv::os::pipe_input_thread.
Referenced by run().
|
virtual |
continuously read from pipe and store in queue; if empty, wait in intervals of ms_to_wait milliseconds
Implements cgv::os::thread.
Definition at line 174 of file pipe_thread.cxx.
References all_data_received, close(), connect_to_source(), done(), cgv::os::thread::have_stop_request(), move_packages_to_data_blocks(), ms_to_wait, mutex_packages, package_index, package_size, packages, packages_per_block, read_package_from_pipe(), and cgv::os::thread::wait().
|
protected |
flag to mark end of data stream
Definition at line 113 of file pipe_thread.h.
Referenced by done(), cgv::os::named_pipe_input_thread::read_package_from_pipe(), cgv::os::pipe_input_thread::read_package_from_pipe(), and run().
|
protected |
deque to store data blocks that are formed by packages
Definition at line 129 of file pipe_thread.h.
Referenced by get_nr_blocks(), move_packages_to_data_blocks(), and pop_data_block().
|
protected |
whether binary mode should be used
Definition at line 115 of file pipe_thread.h.
Referenced by cgv::os::named_pipe_input_thread::connect_to_source(), cgv::os::pipe_input_thread::connect_to_source(), and queued_input_thread().
|
protected |
time in milliseconds to wait while pipe is empty
Definition at line 132 of file pipe_thread.h.
Referenced by queued_input_thread(), and run().
|
mutableprotected |
mutex used to protect access to data_blocks
Definition at line 125 of file pipe_thread.h.
Referenced by get_nr_blocks(), move_packages_to_data_blocks(), and pop_data_block().
|
mutableprotected |
mutex used to protect access to packages
Definition at line 123 of file pipe_thread.h.
Referenced by done(), move_packages_to_data_blocks(), cgv::os::named_pipe_input_thread::read_package_from_pipe(), cgv::os::pipe_input_thread::read_package_from_pipe(), and run().
|
protected |
index of the next package to be read
Definition at line 119 of file pipe_thread.h.
Referenced by move_packages_to_data_blocks(), queued_input_thread(), and run().
|
protected |
size of an indiviual package
Definition at line 117 of file pipe_thread.h.
Referenced by move_packages_to_data_blocks(), pop_data_block(), queued_input_thread(), cgv::os::named_pipe_input_thread::read_package_from_pipe(), cgv::os::pipe_input_thread::read_package_from_pipe(), and run().
|
protected |
allocated memory for smaller data packages
Definition at line 127 of file pipe_thread.h.
Referenced by move_packages_to_data_blocks(), queued_input_thread(), and run().
|
protected |
amount of packeges needed to form one data block
Definition at line 121 of file pipe_thread.h.
Referenced by move_packages_to_data_blocks(), pop_data_block(), queued_input_thread(), and run().