Back to index

nordugrid-arc-nox  1.1.0~rc6
Run.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_RUN_H__
00004 #define __ARC_RUN_H__
00005 
00006 #include <glibmm.h>
00007 
00008 namespace Arc {
00009 
00010   class RunPump;
00011   class Pid;
00012 
00016   class Run {
00017     friend class RunPump;
00018   private:
00019     Run(const Run&);
00020     Run& operator=(Run&);
00021   protected:
00022     // working directory
00023     std::string working_directory;
00024     // Handles
00025     int stdout_;
00026     int stderr_;
00027     int stdin_;
00028     // Associated string containers
00029     std::string *stdout_str_;
00030     std::string *stderr_str_;
00031     std::string *stdin_str_;
00032     //
00033     bool stdout_keep_;
00034     bool stderr_keep_;
00035     bool stdin_keep_;
00036     // Signal connections
00037     sigc::connection stdout_conn_;
00038     sigc::connection stderr_conn_;
00039     sigc::connection stdin_conn_;
00040     sigc::connection child_conn_;
00041     // PID of child
00042     Pid *pid_;
00043     // Arguments to execute
00044     Glib::ArrayHandle<std::string> argv_;
00045     void (*initializer_func_)(void*);
00046     void *initializer_arg_;
00047     void (*kicker_func_)(void*);
00048     void *kicker_arg_;
00049     // IO handlers
00050     bool stdout_handler(Glib::IOCondition cond);
00051     bool stderr_handler(Glib::IOCondition cond);
00052     bool stdin_handler(Glib::IOCondition cond);
00053     // Child exit handler
00054     void child_handler(Glib::Pid pid, int result);
00055     bool started_;
00056     bool running_;
00057     bool abandoned_;
00058     int result_;
00059     Glib::Mutex lock_;
00060     Glib::Cond cond_;
00061   public:
00063     Run(const std::string& cmdline);
00065     Run(const std::list<std::string>& argv);
00067     ~Run(void);
00069     operator bool(void) {
00070       return argv_.size() != 0;
00071     }
00073     bool operator!(void) {
00074       return argv_.size() == 0;
00075     }
00078     bool Start(void);
00081     bool Wait(int timeout);
00083     bool Wait(void);
00085     int Result(void) {
00086       return result_;
00087     }
00089     bool Running(void);
00096     int ReadStdout(int timeout, char *buf, int size);
00103     int ReadStderr(int timeout, char *buf, int size);
00110     int WriteStdin(int timeout, const char *buf, int size);
00114     void AssignStdout(std::string& str);
00118     void AssignStderr(std::string& str);
00122     void AssignStdin(std::string& str);
00124     void KeepStdout(bool keep = true);
00126     void KeepStderr(bool keep = true);
00128     void KeepStdin(bool keep = true);
00130     void CloseStdout(void);
00132     void CloseStderr(void);
00134     void CloseStdin(void);
00135     //void DumpStdout(void);
00136     //void DumpStderr(void);
00137     void AssignInitializer(void (*initializer_func)(void*), void *initializer_arg);
00138     void AssignKicker(void (*kicker_func)(void*), void *kicker_arg);
00140     void AssignWorkingDirectory(std::string& wd) {
00141       working_directory = wd;
00142     }
00147     void Kill(int timeout);
00151     void Abandon(void);
00152   };
00153 
00154 }
00155 
00156 #endif // __ARC_RUN_H__