redirecter.h

Go to the documentation of this file.
00001 #ifndef STDIO_REDIRECTER_CLASS
00002 #define STDIO_REDIRECTER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : stdio_redirecter                                                  *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
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 &parameters);
00031 
00036   stdio_redirecter();
00038 
00039   ~stdio_redirecter();
00041 
00042   basis::outcome reset(const basis::astring &command, const basis::astring &parameters);
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   // internal use only...
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 } //namespace.
00136 
00137 #endif
00138 
Generated on Sat Jan 28 04:22:09 2012 for hoople2 project by  doxygen 1.6.3