CBMC
piped_process.h
Go to the documentation of this file.
1 
5 #ifndef CPROVER_UTIL_PIPED_PROCESS_H
6 #define CPROVER_UTIL_PIPED_PROCESS_H
7 
8 #ifdef _WIN32
9 # include <memory>
10 // The below are forward declarations for Windows APIs
11 struct _PROCESS_INFORMATION; // NOLINT
12 typedef struct _PROCESS_INFORMATION PROCESS_INFORMATION; // NOLINT
13 typedef void *HANDLE; // NOLINT
14 #endif
15 
16 #include "message.h"
17 #include "nodiscard.h"
18 #include "optional.h"
19 
20 #include <vector>
21 
22 #define PIPED_PROCESS_INFINITE_TIMEOUT \
23  optionalt<std::size_t> \
24  { \
25  }
26 
28 {
29 public:
31  enum class statet
32  {
33  RUNNING,
34  ERRORED
35  };
36 
38  enum class send_responset
39  {
40  SUCCEEDED,
41  FAILED,
42  ERRORED
43  };
44 
48  NODISCARD send_responset send(const std::string &message);
51  std::string receive();
55  std::string wait_receive();
56 
60 
67  bool can_receive(optionalt<std::size_t> wait_time);
68 
72  bool can_receive();
73 
78  // of can_receive(0)
79  void wait_receivable(int wait_time);
80 
85  explicit piped_processt(
86  const std::vector<std::string> &commandvec,
87  message_handlert &message_handler);
88 
89  // Deleted due to declaring an explicit destructor and not wanting copy
90  // constructors to be implemented.
91  piped_processt(const piped_processt &) = delete;
92  piped_processt &operator=(const piped_processt &) = delete;
94 
95 protected:
96 #ifdef _WIN32
97  // Process information handle for Windows
98  std::unique_ptr<PROCESS_INFORMATION> proc_info;
99  // Handles for communication with child process
100  HANDLE child_std_IN_Rd;
101  HANDLE child_std_IN_Wr;
102  HANDLE child_std_OUT_Rd;
103  HANDLE child_std_OUT_Wr;
104 #else
105  // Child process ID.
108  // The member fields below are so named from the perspective of the
109  // parent -> child process. So `pipe_input` is where we are feeding
110  // commands to the child process, and `pipe_output` is where we read
111  // the results of execution from.
112  int pipe_input[2];
113  int pipe_output[2];
114 #endif
117 };
118 
119 #endif // endifndef CPROVER_UTIL_PIPED_PROCESS_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
piped_processt::statet
statet
Enumeration to keep track of child process state.
Definition: piped_process.h:31
piped_processt::send_responset::FAILED
@ FAILED
NODISCARD
#define NODISCARD
Definition: nodiscard.h:22
optional.h
piped_processt::can_receive
bool can_receive()
See if this process can receive data from the other process.
Definition: piped_process.cpp:516
nodiscard.h
piped_processt::statet::ERRORED
@ ERRORED
piped_processt::operator=
piped_processt & operator=(const piped_processt &)=delete
piped_processt::pipe_input
int pipe_input[2]
Definition: piped_process.h:112
piped_processt::piped_processt
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 t...
Definition: piped_process.cpp:127
piped_processt::~piped_processt
~piped_processt()
Definition: piped_process.cpp:324
piped_processt::wait_receivable
void wait_receivable(int wait_time)
Wait for the pipe to be ready, waiting specified time between checks.
Definition: piped_process.cpp:521
piped_processt::log
messaget log
Definition: piped_process.h:116
message_handlert
Definition: message.h:27
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
piped_processt::send_responset
send_responset
Enumeration for send response.
Definition: piped_process.h:38
piped_processt
Definition: piped_process.h:27
piped_processt::child_process_id
pid_t child_process_id
Definition: piped_process.h:106
piped_processt::process_state
statet process_state
Definition: piped_process.h:115
piped_processt::command_stream
FILE * command_stream
Definition: piped_process.h:107
piped_processt::send
send_responset send(const std::string &message)
Send a string message (command) to the child process.
Definition: piped_process.cpp:349
piped_processt::statet::RUNNING
@ RUNNING
piped_processt::receive
std::string receive()
Read a string from the child process' output.
Definition: piped_process.cpp:404
piped_processt::send_responset::SUCCEEDED
@ SUCCEEDED
piped_processt::wait_receive
std::string wait_receive()
Wait until a string is available and read a string from the child process' output.
Definition: piped_process.cpp:440
piped_processt::get_status
statet get_status()
Get child process status.
Definition: piped_process.cpp:448
message.h
piped_processt::pipe_output
int pipe_output[2]
Definition: piped_process.h:113
piped_processt::send_responset::ERRORED
@ ERRORED
statet
unsigned int statet
Definition: trace_automaton.h:24