00001 #include <sys/types.h> // for pid_t 00002 00003 #include "sue_sel.hpp" 00004 00005 00006 class SUEChildWaitAgent; 00007 00009 00025 class SUEChildHandler { 00026 int status; 00027 pid_t pid; 00028 public: 00030 SUEChildHandler(pid_t a_pid, SUEChildWaitAgent *a_agent); 00032 virtual ~SUEChildHandler() {} 00033 00035 00043 virtual void ChildHandle() {} 00044 00045 protected: 00046 pid_t GetPid() const { return pid; } 00048 00049 bool IfExited() const; 00051 00054 int ExitCode() const; 00056 00057 bool IfSignaled() const; 00059 00062 int TermSig() const; 00063 00064 private: 00065 friend SUEChildWaitAgent; 00066 void AgentsHandler(int a_status) { 00067 status = a_status; 00068 ChildHandle(); 00069 pid = 0; 00070 delete this; 00071 } 00072 }; 00073 00075 00088 class SUEChildWaitAgent : public SUESignalHandler { 00089 struct ChildListItem { 00090 ChildListItem *next; 00091 SUEChildHandler *handler; 00092 } *first; 00093 SUEEventSelector *the_selector; 00094 public: 00096 SUEChildWaitAgent(); 00098 virtual ~SUEChildWaitAgent(); 00099 00101 void Register(SUEEventSelector *a_selector); 00103 void Unregister(); 00104 00106 00110 void RegisterChildHandler(SUEChildHandler *h); 00112 00119 void RemoveChildHandler(SUEChildHandler *h); 00120 private: 00121 virtual void SignalHandle(); 00122 }; 00123 00124