cgv
Loading...
Searching...
No Matches
cgv::os::pipe_output_thread Class Reference

queued thread class that manages a child process connecting to its input pipe More...

#include <pipe_thread.h>

Inheritance diagram for cgv::os::pipe_output_thread:
cgv::os::queued_output_thread cgv::os::thread

Public Member Functions

 pipe_output_thread (const std::string &_cmd, bool is_binary=true, unsigned _ms_to_wait=20)
 construct pipe output thread from system command, whether to use binary mode and wait time in ms used when queue is empty
 
int get_result () const
 return the result value returned from child process which is available only after termination of thread
 
- Public Member Functions inherited from cgv::os::queued_output_thread
 queued_output_thread (bool is_binary=true, unsigned _ms_to_wait=20)
 construct queued output thread from flag, whether to use binary mode and wait time in ms used when queue is empty
 
void run ()
 connect to child process and continuously write queue content to pipe; if empty wait in intervals of ms_to_wait miliseconds or close pipe and terminate if done() had been called
 
bool has_connection () const
 returns true as soon as child process has connected to pipe
 
bool send_block (const char *data, size_t count)
 if done() had not been called, insert a data block into the queue; can fail if done() or out of memory
 
size_t get_nr_blocks () const
 returns the number of blocks in the queue of not yet written data
 
size_t get_nr_bytes () const
 returns the number of bytes in the queue of not yet written data, what is more time consuming than get_nr_blocks()
 
void done ()
 call this to announce the all data has been sent
 
- 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_child_process ()
 starts child process and connects to its stdin
 
void write_block_to_pipe (const char *data, size_t count)
 write block to stdin pipe
 
void close ()
 closes stdin pipe and stores result value
 
- Protected Member Functions inherited from cgv::os::thread
void execute ()
 executes the run method
 

Protected Attributes

std::string cmd
 system command to be executed
 
FILE * fp = 0
 file handle of stdin of child process
 
int result = -1
 result value of child process
 
- Protected Attributes inherited from cgv::os::queued_output_thread
bool is_binary
 whether binary mode should be used
 
bool connected = false
 flag that tells whether the pipe has been connected to from the other side
 
cgv::os::mutex m
 mutex used to protect access to blocks
 
std::deque< std::pair< char *, size_t > > blocks
 deque used to queue the data blocks that should be written to the pipe by the thread
 
unsigned ms_to_wait
 time in miliseconds to wait while queue 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

queued thread class that manages a child process connecting to its input pipe

Definition at line 82 of file pipe_thread.h.

Constructor & Destructor Documentation

◆ pipe_output_thread()

cgv::os::pipe_output_thread::pipe_output_thread ( const std::string &  _cmd,
bool  is_binary = true,
unsigned  _ms_to_wait = 20 
)

construct pipe output thread from system command, whether to use binary mode and wait time in ms used when queue is empty

Definition at line 139 of file pipe_thread.cxx.

References cmd.

Member Function Documentation

◆ close()

void cgv::os::pipe_output_thread::close ( )
protectedvirtual

closes stdin pipe and stores result value

Implements cgv::os::queued_output_thread.

Definition at line 153 of file pipe_thread.cxx.

References fp, and result.

◆ connect_to_child_process()

bool cgv::os::pipe_output_thread::connect_to_child_process ( )
protectedvirtual

starts child process and connects to its stdin

Implements cgv::os::queued_output_thread.

Definition at line 144 of file pipe_thread.cxx.

References cmd, fp, and cgv::os::queued_output_thread::is_binary.

◆ get_result()

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

return the result value returned from child process which is available only after termination of thread

Definition at line 157 of file pipe_thread.cxx.

References result.

◆ write_block_to_pipe()

void cgv::os::pipe_output_thread::write_block_to_pipe ( const char *  data,
size_t  count 
)
protectedvirtual

write block to stdin pipe

Implements cgv::os::queued_output_thread.

Definition at line 149 of file pipe_thread.cxx.

References fp.

Member Data Documentation

◆ cmd

std::string cgv::os::pipe_output_thread::cmd
protected

system command to be executed

Definition at line 86 of file pipe_thread.h.

Referenced by connect_to_child_process(), and pipe_output_thread().

◆ fp

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

file handle of stdin of child process

Definition at line 88 of file pipe_thread.h.

Referenced by close(), connect_to_child_process(), and write_block_to_pipe().

◆ result

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

result value of child process

Definition at line 90 of file pipe_thread.h.

Referenced by close(), and get_result().


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