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 "opsysdll.h"
00019 
00020 #include <basis/object_base.h>
00021 
00022 // forward.
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 &parameters);
00033 
00038   stdio_redirecter();
00040 
00041   ~stdio_redirecter();
00043 
00044   outcome reset(const istring &command, const istring &parameters);
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   // internal use only...
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 

Generated on Fri Nov 21 04:29:55 2008 for HOOPLE Libraries by  doxygen 1.5.1