00001 /* Copyright (c) 2006, Gennady Bystritsky <bystr@mac.com> 00002 * 00003 * Distributed under the MIT Licence. 00004 * This is free software. See 'LICENSE' for details. 00005 * You must read and accept the license prior to use. 00006 */ 00007 00008 #ifndef _SK_SYS_PROCESS_ 00009 #define _SK_SYS_PROCESS_ 00010 00011 #include <sk/util/Object.h> 00012 #include <sk/util/StringArray.h> 00013 #include <sk/util/Holder.hxx> 00014 #include <sk/io/FileDescriptorInputStream.h> 00015 #include <sk/sys/Executable.h> 00016 #include <sk/sys/ProcessListener.h> 00017 #include <sk/rt/Scope.h> 00018 00019 namespace sk { 00020 namespace sys { 00021 class Process 00022 : public virtual sk::sys::Executable, 00023 public virtual sk::sys::ProcessListener 00024 { 00025 public: 00026 Process(sk::io::FileDescriptorInputStream& inputStream, const sk::util::StringArray& cmdline, ProcessListener& listener); 00027 Process(sk::io::FileDescriptorInputStream& inputStream, const sk::util::StringArray& cmdline); 00028 Process(sk::io::FileDescriptorInputStream& inputStream, ProcessListener& listener); 00029 Process(const sk::util::StringArray& cmdline, ProcessListener& listener); 00030 Process(const sk::util::StringArray& cmdline); 00031 Process(ProcessListener& listener); 00032 virtual ~Process(); 00033 00034 // sk::sys::Executable implementation. 00035 void stop(); 00036 void join(); 00037 bool isSuccess() const; 00038 bool isExited() const; 00039 bool isKilled() const; 00040 bool isAlive() const; 00041 int exitStatus() const; 00042 int signal() const; 00043 00044 // sk::util::Object re-implementation. 00045 const sk::util::Class getClass() const; 00046 00047 // sk::sys::ProcessListener implementation. 00048 void processStarting(); 00049 int processStopping(); 00050 void processJoining(); 00051 00052 private: 00053 Process(const Process& other); 00054 Process& operator = (const Process& other); 00055 00056 void start(sk::io::FileDescriptorInputStream& inputStream, const sk::util::StringArray& cmdline); 00057 bool signalUnlessTerminates(int timeout, int signal); 00058 sk::io::FileDescriptorInputStream& defaultInputStream(); 00059 void assertNotAlive() const; 00060 00061 const sk::rt::Scope _scope; 00062 sk::sys::ProcessListener& _listener; 00063 sk::util::Holder<sk::io::FileDescriptorInputStream> _defaultInputStreamHolder; 00064 int _pid; 00065 int _status; 00066 }; 00067 } 00068 } 00069 00070 #endif /* _SK_SYS_PROCESS_ */