Update codebase to remove clang warnings (and a couple of legit errors
[typhoon.git] / src / autoplay / child_process.h
1 // child_process.h -- description
2
3 #ifndef _CHILD_PROCESS_H_
4 #define _CHILD_PROCESS_H_
5
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <vector>
11 using namespace std;
12
13 namespace util {
14
15 class ChildProcess {
16  public:
17   explicit ChildProcess(const char *commandline)
18     : commandline_(strdup(commandline)),
19       name_(NULL),
20       running_(false),
21       pid_(-1),
22       to_(NULL),
23       from_(NULL),
24       child_ready_(false) {}
25   virtual ~ChildProcess() {
26     Stop();
27     free(commandline_);
28     commandline_ = NULL;
29   }
30
31   virtual void Start();
32   virtual void Stop();
33   void Send(char *line);
34   void Receive(char *line, int size);
35   bool Poll();
36   void Flush();
37
38  private:
39   void ParseCommandline(vector<char *> *args);
40   char *commandline_;
41   char *name_;
42   bool running_;
43   pid_t pid_;
44   int write_pipe_[2];
45   int read_pipe_[2];
46   FILE *to_;
47   FILE *from_;
48   volatile bool child_ready_;
49 };
50
51 }  // namespace
52
53 #endif /* _CHILD_PROCESS_H_ */