summaryrefslogtreecommitdiff
path: root/src/autoplay/child_process.h
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2016-06-01 18:58:58 -0700
committerScott Gasch <[email protected]>2016-06-01 18:58:58 -0700
commit3fd43cd5fcb22bb65bf2a92a25d95d801b11c9e0 (patch)
tree9b6443235d16ba17f094a1a1c7ae53d2bcb9267b /src/autoplay/child_process.h
Initial checkin for typhoon chess engine.
Diffstat (limited to 'src/autoplay/child_process.h')
-rw-r--r--src/autoplay/child_process.h53
1 files changed, 53 insertions, 0 deletions
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 <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <vector>
+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<char *> *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_ */