// 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_ */