cprover
Toggle main menu visibility
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
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
18
#include <vector>
19
20
#define PIPED_PROCESS_INFINITE_TIMEOUT \
21
std::optional<std::size_t> \
22
{ \
23
}
24
25
class
piped_processt
26
{
27
public
:
29
enum class
statet
30
{
31
RUNNING
,
32
ERRORED
33
};
34
36
enum class
send_responset
37
{
38
SUCCEEDED
,
39
FAILED
,
40
ERRORED
41
};
42
46
[[nodiscard]]
send_responset
send
(
const
std::string &message);
49
std::string
receive
();
53
std::string
wait_receive
();
54
57
statet
get_status
();
58
65
bool
can_receive
(std::optional<std::size_t> wait_time);
66
70
bool
can_receive
();
71
76
// of can_receive(0)
77
void
wait_receivable
(
int
wait_time);
78
83
explicit
piped_processt
(
84
const
std::vector<std::string> &commandvec,
85
message_handlert
&message_handler);
86
87
// Deleted due to declaring an explicit destructor and not wanting copy
88
// constructors to be implemented.
89
piped_processt
(
const
piped_processt
&) =
delete
;
90
piped_processt
&
operator=
(
const
piped_processt
&) =
delete
;
91
~piped_processt
();
92
93
protected
:
94
#ifdef _WIN32
95
// Process information handle for Windows
96
std::unique_ptr<PROCESS_INFORMATION> proc_info;
97
// Handles for communication with child process
98
HANDLE child_std_IN_Rd;
99
HANDLE child_std_IN_Wr;
100
HANDLE child_std_OUT_Rd;
101
HANDLE child_std_OUT_Wr;
102
#else
103
// Child process ID.
104
pid_t
child_process_id
;
105
FILE *
command_stream
;
106
// The member fields below are so named from the perspective of the
107
// parent -> child process. So `pipe_input` is where we are feeding
108
// commands to the child process, and `pipe_output` is where we read
109
// the results of execution from.
110
int
pipe_input
[2];
111
int
pipe_output
[2];
112
#endif
113
statet
process_state
;
114
messaget
log
;
115
};
116
117
#endif
// endifndef CPROVER_UTIL_PIPED_PROCESS_H
message_handlert
Definition
message.h:27
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition
message.h:154
piped_processt::child_process_id
pid_t child_process_id
Definition
piped_process.h:104
piped_processt::~piped_processt
~piped_processt()
Definition
piped_process.cpp:335
piped_processt::process_state
statet process_state
Definition
piped_process.h:113
piped_processt::can_receive
bool can_receive()
See if this process can receive data from the other process.
Definition
piped_process.cpp:527
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:532
piped_processt::piped_processt
piped_processt(const piped_processt &)=delete
piped_processt::receive
std::string receive()
Read a string from the child process' output.
Definition
piped_process.cpp:415
piped_processt::send
send_responset send(const std::string &message)
Send a string message (command) to the child process.
Definition
piped_process.cpp:360
piped_processt::command_stream
FILE * command_stream
Definition
piped_process.h:105
piped_processt::log
messaget log
Definition
piped_process.h:114
piped_processt::operator=
piped_processt & operator=(const piped_processt &)=delete
piped_processt::statet
statet
Enumeration to keep track of child process state.
Definition
piped_process.h:30
piped_processt::statet::RUNNING
@ RUNNING
Definition
piped_process.h:31
piped_processt::statet::ERRORED
@ ERRORED
Definition
piped_process.h:32
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::pipe_output
int pipe_output[2]
Definition
piped_process.h:111
piped_processt::pipe_input
int pipe_input[2]
Definition
piped_process.h:110
piped_processt::get_status
statet get_status()
Get child process status.
Definition
piped_process.cpp:459
piped_processt::send_responset
send_responset
Enumeration for send response.
Definition
piped_process.h:37
piped_processt::send_responset::FAILED
@ FAILED
Definition
piped_process.h:39
piped_processt::send_responset::SUCCEEDED
@ SUCCEEDED
Definition
piped_process.h:38
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:451
message.h
statet
unsigned int statet
Definition
trace_automaton.h:24
util
piped_process.h
Generated by
1.17.0