From 3fd43cd5fcb22bb65bf2a92a25d95d801b11c9e0 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Wed, 1 Jun 2016 18:58:58 -0700 Subject: Initial checkin for typhoon chess engine. --- src/autoplay/child_process.h | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/autoplay/child_process.h (limited to 'src/autoplay/child_process.h') diff --git a/src/autoplay/child_process.h b/src/autoplay/child_process.h new file mode 100644 index 0000000..6c03ecd --- /dev/null +++ b/src/autoplay/child_process.h @@ -0,0 +1,53 @@ +// child_process.h -- description + +#ifndef _CHILD_PROCESS_H_ +#define _CHILD_PROCESS_H_ + +#include +#include +#include +#include +#include +using namespace std; + +namespace util { + +class ChildProcess { + public: + explicit ChildProcess(const char *commandline) + : commandline_(strdup(commandline)), + name_(NULL), + running_(false), + pid_(-1), + to_(NULL), + from_(NULL), + child_ready_(false) {} + virtual ~ChildProcess() { + Stop(); + free(commandline_); + commandline_ = NULL; + } + + virtual void Start(); + virtual void Stop(); + void Send(char *line); + void Receive(char *line, int size); + bool Poll(); + void Flush(); + + private: + void ParseCommandline(vector *args); + char *commandline_; + char *name_; + bool running_; + pid_t pid_; + int write_pipe_[2]; + int read_pipe_[2]; + FILE *to_; + FILE *from_; + volatile bool child_ready_; +}; + +} // namespace + +#endif /* _CHILD_PROCESS_H_ */ -- cgit v1.3