cprover
Loading...
Searching...
No Matches
piped_process.h
Go to the documentation of this file.
1
4
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
11struct _PROCESS_INFORMATION; // NOLINT
12typedef struct _PROCESS_INFORMATION PROCESS_INFORMATION; // NOLINT
13typedef 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{
29public:
31 enum class statet
32 {
33 RUNNING,
35 };
36
38 enum class send_responset
39 {
41 FAILED,
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;
94
95protected:
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.
114#endif
117};
118
119#endif // endifndef CPROVER_UTIL_PIPED_PROCESS_H
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:155
bool can_receive()
See if this process can receive data from the other process.
void wait_receivable(int wait_time)
Wait for the pipe to be ready, waiting specified time between checks.
piped_processt(const piped_processt &)=delete
std::string receive()
Read a string from the child process' output.
send_responset send(const std::string &message)
Send a string message (command) to the child process.
piped_processt & operator=(const piped_processt &)=delete
statet
Enumeration to keep track of child process state.
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...
statet get_status()
Get child process status.
send_responset
Enumeration for send response.
std::string wait_receive()
Wait until a string is available and read a string from the child process' output.
#define NODISCARD
Definition nodiscard.h:22
nonstd::optional< T > optionalt
Definition optional.h:35
unsigned int statet