cgv
Loading...
Searching...
No Matches
cgv::os::pipe_input_thread Class Reference
Inheritance diagram for cgv::os::pipe_input_thread:
cgv::os::queued_input_thread cgv::os::thread

Public Member Functions

 pipe_input_thread (const std::string &_cmd, bool is_binary, size_t _package_size, size_t _packages_per_block, unsigned _ms_to_wait)
 
int get_result () const
 
- Public Member Functions inherited from 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
 
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

bool connect_to_source () override
 to be implemented in derived classes
 
size_t read_package_from_pipe (char *buffer, size_t package_size) override
 to be implemented in derived classes
 
void close () override
 to be implemented in derived classes
 
- Protected Member Functions inherited from cgv::os::queued_input_thread
virtual void move_packages_to_data_blocks ()
 combine the packages to a data block and push it to the queue
 
- Protected Member Functions inherited from cgv::os::thread
void execute ()
 executes the run method
 

Protected Attributes

std::string cmd
 
FILE * fp = 0
 
int result = -1
 
- Protected Attributes inherited from cgv::os::queued_input_thread
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

Definition at line 174 of file pipe_thread.h.

Constructor & Destructor Documentation

◆ pipe_input_thread()

cgv::os::pipe_input_thread::pipe_input_thread ( const std::string &  _cmd,
bool  is_binary,
size_t  _package_size,
size_t  _packages_per_block,
unsigned  _ms_to_wait 
)

Definition at line 315 of file pipe_thread.cxx.

Member Function Documentation

◆ close()

void cgv::os::pipe_input_thread::close ( )
overrideprotectedvirtual

to be implemented in derived classes

Implements cgv::os::queued_input_thread.

Definition at line 311 of file pipe_thread.cxx.

◆ connect_to_source()

bool cgv::os::pipe_input_thread::connect_to_source ( )
overrideprotectedvirtual

to be implemented in derived classes

Implements cgv::os::queued_input_thread.

Definition at line 297 of file pipe_thread.cxx.

References cgv::os::queued_input_thread::is_binary.

◆ get_result()

int cgv::os::pipe_input_thread::get_result ( ) const

Definition at line 320 of file pipe_thread.cxx.

◆ read_package_from_pipe()

size_t cgv::os::pipe_input_thread::read_package_from_pipe ( char *  buffer,
size_t  package_size 
)
overrideprotectedvirtual

Member Data Documentation

◆ cmd

std::string cgv::os::pipe_input_thread::cmd
protected

Definition at line 177 of file pipe_thread.h.

◆ fp

FILE* cgv::os::pipe_input_thread::fp = 0
protected

Definition at line 178 of file pipe_thread.h.

◆ result

int cgv::os::pipe_input_thread::result = -1
protected

Definition at line 180 of file pipe_thread.h.


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