redirecter.h
Go to the documentation of this file.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 <basis/contracts.h>
00019 #include <basis/mutex.h>
00020 #include <processes/ethread.h>
00021
00022 namespace application {
00023
00025
00026 class stdio_redirecter : public virtual basis::root_object
00027 {
00028 public:
00029 stdio_redirecter(const basis::astring &command, const basis::astring ¶meters);
00031
00036 stdio_redirecter();
00038
00039 ~stdio_redirecter();
00041
00042 basis::outcome reset(const basis::astring &command, const basis::astring ¶meters);
00044
00045 DEFINE_CLASS_NAME("stdio_redirecter");
00046
00047 enum outcomes {
00048 OKAY = basis::common::OKAY,
00049 NOT_FOUND = basis::common::NOT_FOUND,
00050 NONE_READY = basis::common::NONE_READY,
00051 PARTIAL = basis::common::PARTIAL,
00052 ACCESS_DENIED = basis::common::ACCESS_DENIED
00053 };
00054
00055 basis::outcome health() const { return _persistent_result; }
00057
00060 bool running();
00062
00064 int exit_value() const { return _exit_value; }
00066
00069 int process_id() const { return _process_id; }
00071
00073 void zap_program();
00075
00077 basis::outcome read(basis::byte_array &received);
00079
00082 basis::outcome write(const basis::byte_array &to_write, int &written);
00084
00088 basis::outcome write(const basis::astring &to_write, int &written);
00090
00091 basis::outcome read_stderr(basis::byte_array &received);
00093
00094 void close_input();
00096
00099
00100
00101 void std_thread_action(bool is_stdout);
00103
00106 private:
00107 #ifdef __UNIX__
00108 int _output_fds[2];
00109 int _input_fds[2];
00110 int _stderr_fds[2];
00111 #endif
00112 #ifdef __WIN32__
00113 void *_child_in, *_child_out, *_child_err;
00114 void *_parent_in, *_parent_out, *_parent_err;
00115 void *_app_handle;
00116 #endif
00117 basis::astring *_command;
00118 basis::astring *_parms;
00119 basis::outcome _persistent_result;
00120 processes::ethread *_stdout_reader;
00121 processes::ethread *_stderr_reader;
00122 basis::byte_array *_stdout_queue;
00123 basis::byte_array *_stderr_queue;
00124 basis::mutex *_lock;
00125 int _process_id;
00126 int _exit_value;
00127
00128 basis::outcome create_pipes();
00130
00131 basis::outcome launch_program(int &new_process_id);
00133 };
00134
00135 }
00136
00137 #endif
00138