00001 #ifndef STDIO_REDIRECTER_CLASS
00002 #define STDIO_REDIRECTER_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "opsysdll.h"
00019
00020 #include <basis/object_base.h>
00021
00022
00023 class ithread;
00024
00026
00027 class OPSYSTEM_CLASS_STYLE stdio_redirecter
00028 : public virtual object_base
00029 {
00030 public:
00031 stdio_redirecter(const istring &command, const istring ¶meters);
00033
00038 stdio_redirecter();
00040
00041 ~stdio_redirecter();
00043
00044 outcome reset(const istring &command, const istring ¶meters);
00046
00047 IMPLEMENT_CLASS_NAME("stdio_redirecter");
00048
00049 enum outcomes {
00050 OKAY = common::OKAY,
00051 NOT_FOUND = common::NOT_FOUND,
00052 NONE_READY = common::NONE_READY,
00053 PARTIAL = common::PARTIAL,
00054 ACCESS_DENIED = common::ACCESS_DENIED
00055 };
00056
00057 outcome health() const { return _persistent_result; }
00059
00062 bool running();
00064
00066 int exit_value() const { return _exit_value; }
00068
00071 int process_id() const { return _process_id; }
00073
00075 void zap_program();
00077
00079 outcome read(byte_array &received);
00081
00084 outcome write(const byte_array &to_write, int &written);
00086
00090 outcome write(const istring &to_write, int &written);
00092
00093 outcome read_stderr(byte_array &received);
00095
00096 void close_input();
00098
00101
00102
00103 void std_thread_action(bool is_stdout);
00105
00108 private:
00109 #ifdef __UNIX__
00110 int _output_fds[2];
00111 int _input_fds[2];
00112 int _stderr_fds[2];
00113 #endif
00114 #ifdef __WIN32__
00115 void *_child_in, *_child_out, *_child_err;
00116 void *_parent_in, *_parent_out, *_parent_err;
00117 void *_app_handle;
00118 #endif
00119 istring *_command;
00120 istring *_parms;
00121 outcome _persistent_result;
00122 ithread *_stdout_reader;
00123 ithread *_stderr_reader;
00124 byte_array *_stdout_queue;
00125 byte_array *_stderr_queue;
00126 mutex *_lock;
00127 int _process_id;
00128 int _exit_value;
00129
00130 outcome create_pipes();
00132
00133 outcome launch_program(int &new_process_id);
00135 };
00136
00137 #endif
00138