CBMC
piped_processt Class Reference

#include <piped_process.h>

+ Collaboration diagram for piped_processt:

Public Types

enum class  statet { RUNNING , ERRORED }
 Enumeration to keep track of child process state. More...
 
enum class  send_responset { SUCCEEDED , FAILED , ERRORED }
 Enumeration for send response. More...
 

Public Member Functions

send_responset send (const std::string &message)
 Send a string message (command) to the child process. More...
 
std::string receive ()
 Read a string from the child process' output. More...
 
std::string wait_receive ()
 Wait until a string is available and read a string from the child process' output. More...
 
statet get_status ()
 Get child process status. More...
 
bool can_receive (std::optional< std::size_t > wait_time)
 See if this process can receive data from the other process. More...
 
bool can_receive ()
 See if this process can receive data from the other process. More...
 
void wait_receivable (int wait_time)
 Wait for the pipe to be ready, waiting specified time between checks. More...
 
 piped_processt (const std::vector< std::string > &commandvec, message_handlert &message_handler)
 Initiate a new subprocess with pipes supporting communication between the parent (this process) and the child. More...
 
 piped_processt (const piped_processt &)=delete
 
piped_processtoperator= (const piped_processt &)=delete
 
 ~piped_processt ()
 

Protected Attributes

pid_t child_process_id
 
FILE * command_stream
 
int pipe_input [2]
 
int pipe_output [2]
 
statet process_state
 
messaget log
 

Detailed Description

Definition at line 25 of file piped_process.h.

Member Enumeration Documentation

◆ send_responset

Enumeration for send response.

Enumerator
SUCCEEDED 
FAILED 
ERRORED 

Definition at line 36 of file piped_process.h.

◆ statet

Enumeration to keep track of child process state.

Enumerator
RUNNING 
ERRORED 

Definition at line 29 of file piped_process.h.

Constructor & Destructor Documentation

◆ piped_processt() [1/2]

piped_processt::piped_processt ( const std::vector< std::string > &  commandvec,
message_handlert message_handler 
)
explicit

Initiate a new subprocess with pipes supporting communication between the parent (this process) and the child.

Parameters
commandvecThe command and arguments to create the process
message_handlerOptional message handler for logging debug messages

Definition at line 124 of file piped_process.cpp.

◆ piped_processt() [2/2]

piped_processt::piped_processt ( const piped_processt )
delete

◆ ~piped_processt()

piped_processt::~piped_processt ( )

Definition at line 321 of file piped_process.cpp.

Member Function Documentation

◆ can_receive() [1/2]

bool piped_processt::can_receive ( )

See if this process can receive data from the other process.

Note this calls can_receive(0);

Returns
true if there is data to read from process, false otherwise.

Definition at line 513 of file piped_process.cpp.

◆ can_receive() [2/2]

bool piped_processt::can_receive ( std::optional< std::size_t >  wait_time)

See if this process can receive data from the other process.

Parameters
wait_timeAmount of time to wait before timing out, with:
  • positive integer being wait time in milli-seconds,
  • 0 signifying non-blocking immediate return, and
  • an empty optional representing infinite wait time.
Returns
true is there is data to read from process, false otherwise

Definition at line 450 of file piped_process.cpp.

◆ get_status()

piped_processt::statet piped_processt::get_status ( )

Get child process status.

Returns
a statet representing the status of the child process

Definition at line 445 of file piped_process.cpp.

◆ operator=()

piped_processt& piped_processt::operator= ( const piped_processt )
delete

◆ receive()

std::string piped_processt::receive ( )

Read a string from the child process' output.

Returns
a string containing data from the process, empty string if no data

Definition at line 401 of file piped_process.cpp.

◆ send()

piped_processt::send_responset piped_processt::send ( const std::string &  message)

Send a string message (command) to the child process.

Parameters
messageThe string message to be sent.
Returns

Definition at line 346 of file piped_process.cpp.

◆ wait_receivable()

void piped_processt::wait_receivable ( int  wait_time)

Wait for the pipe to be ready, waiting specified time between checks.

Will return when the pipe is ready or the other process is not in a statet::CREATED state (i.e. error has occured).

Parameters
wait_timeTime spent in usleep() (microseconds) between checks

Definition at line 518 of file piped_process.cpp.

◆ wait_receive()

std::string piped_processt::wait_receive ( )

Wait until a string is available and read a string from the child process' output.

Returns
a string containing data from the process, empty string if no data

Definition at line 437 of file piped_process.cpp.

Member Data Documentation

◆ child_process_id

pid_t piped_processt::child_process_id
protected

Definition at line 104 of file piped_process.h.

◆ command_stream

FILE* piped_processt::command_stream
protected

Definition at line 105 of file piped_process.h.

◆ log

messaget piped_processt::log
protected

Definition at line 114 of file piped_process.h.

◆ pipe_input

int piped_processt::pipe_input[2]
protected

Definition at line 110 of file piped_process.h.

◆ pipe_output

int piped_processt::pipe_output[2]
protected

Definition at line 111 of file piped_process.h.

◆ process_state

statet piped_processt::process_state
protected

Definition at line 113 of file piped_process.h.


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