00001
00007 #ifndef INCL_EXECBOX_H
00008 #define INCL_EXECBOX_H 1
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <gtk/gtk.h>
00029
00030 class Exec_box;
00031 class Exec_process;
00032
00033 typedef void (*Exec_done_fun)(int exit_code, Exec_box *box,
00034 gpointer user_data);
00035
00036
00037 #ifndef WIN32
00038
00039
00040
00041
00042
00043 class Exec_process
00044 {
00045 public:
00046
00047
00048
00049 typedef void (*Reader_fun)(char *data, int datalen, int exit_code,
00050 gpointer user_data);
00051 private:
00052
00053 int child_stdin, child_stdout, child_stderr;
00054 int child_pid;
00055 gint stdout_tag, stderr_tag;
00056 Reader_fun reader;
00057 void *reader_data;
00058 public:
00059 Exec_process();
00060 ~Exec_process();
00061 void kill_child();
00062 void read_from_child(int id);
00063
00064 bool exec(const char *file, char *argv[], Reader_fun rfun,
00065 void *udata);
00066 bool check_child(int& exit_code);
00067 };
00068
00069 #else
00070
00071 class Exec_process
00072 {
00073 public:
00074 typedef void (*Reader_fun)(char *data, int datalen, int exit_code,
00075 gpointer user_data);
00076 Exec_process() {}
00077 ~Exec_process() {}
00078 void kill_child() {}
00079 void read_from_child(int id) {}
00080 bool exec(const char *file, char *argv[], Reader_fun rfun,
00081 void *udata) { return false; }
00082 bool check_child(int& exit_code) { return false; }
00083 };
00084
00085 #endif
00086
00087
00088
00089
00090 class Exec_box
00091 {
00092 Exec_process *executor;
00093 GtkTextView *box;
00094 GtkStatusbar *status;
00095 guint status_ctx;
00096 Exec_done_fun done_fun;
00097 gpointer user_data;
00098 public:
00099 Exec_box(GtkTextView *b, GtkStatusbar *s, Exec_done_fun dfun = 0,
00100 gpointer udata = 0);
00101 ~Exec_box();
00102 void show_status(const char *msg);
00103
00104 void read_from_child(char *data, int datalen, int exit_code);
00105 void add_message(const char *txt);
00106
00107 bool exec(const char *file, char *argv[]);
00108 void kill_child();
00109 };
00110
00111 #endif