cgv
Loading...
Searching...
No Matches
cgv::os::queued_input_thread Class Referenceabstract

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>

Inheritance diagram for cgv::os::queued_input_thread:
cgv::os::thread cgv::os::named_pipe_input_thread cgv::os::pipe_input_thread

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
 
- Public Member Functions inherited from cgv::os::thread
 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
 
- Protected Member Functions inherited from cgv::os::thread
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
 
- Protected Attributes inherited from cgv::os::thread
void * thread_ptr
 
bool stop_request
 
bool running
 
bool delete_after_termination
 

Additional Inherited Members

- Static Public Member Functions inherited from cgv::os::thread
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 Protected Member Functions inherited from cgv::os::thread
static void * execute_s (void *args)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ queued_input_thread()

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.

Member Function Documentation

◆ close()

virtual void cgv::os::queued_input_thread::close ( )
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().

◆ connect_to_source()

virtual bool cgv::os::queued_input_thread::connect_to_source ( )
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().

◆ done()

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().

◆ get_nr_blocks()

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.

◆ move_packages_to_data_blocks()

void cgv::os::queued_input_thread::move_packages_to_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().

◆ pop_data_block()

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.

◆ read_package_from_pipe()

virtual size_t cgv::os::queued_input_thread::read_package_from_pipe ( char *  buffer,
size_t  package_size 
)
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().

◆ run()

void cgv::os::queued_input_thread::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().

Member Data Documentation

◆ all_data_received

bool cgv::os::queued_input_thread::all_data_received = false
protected

◆ data_blocks

std::deque<std::vector<char> > cgv::os::queued_input_thread::data_blocks
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().

◆ is_binary

bool cgv::os::queued_input_thread::is_binary
protected

◆ ms_to_wait

unsigned cgv::os::queued_input_thread::ms_to_wait
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().

◆ mutex_data_blocks

std::mutex cgv::os::queued_input_thread::mutex_data_blocks
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().

◆ mutex_packages

std::mutex cgv::os::queued_input_thread::mutex_packages
mutableprotected

◆ package_index

size_t cgv::os::queued_input_thread::package_index
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().

◆ package_size

size_t cgv::os::queued_input_thread::package_size
protected

◆ packages

char* cgv::os::queued_input_thread::packages
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().

◆ packages_per_block

size_t cgv::os::queued_input_thread::packages_per_block
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().


The documentation for this class was generated from the following files: