|
yast2-core
|
00001 /* Process.h 00002 * 00003 * ------------------------------------------------------------------------------ 00004 * Copyright (c) 2008 Novell, Inc. All Rights Reserved. 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or modify it under 00008 * the terms of version 2 of the GNU General Public License as published by the 00009 * Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may find 00019 * current contact information at www.novell.com. 00020 * ------------------------------------------------------------------------------ 00021 * 00022 * Class Process 00023 * 00024 * Authors: Ladislav Slezák <lslezak@novell.com> 00025 * 00026 * $Id: Process.h 57029 2009-04-29 11:04:19Z lslezak $ 00027 */ 00028 00029 #ifndef Process_h 00030 #define Process_h 00031 00032 #include <y2util/ExternalProgram.h> 00033 00041 class Process: public ExternalProgram 00042 { 00043 00044 private: 00045 00046 std::string stdout_buffer; // buffer for stdout 00047 std::string stderr_buffer; // buffer for stderr 00048 00049 FILE *stderr_output; 00050 00051 private: 00052 00053 // disable copy ctor and operator= 00054 Process(const Process&); 00055 Process& operator=(const Process&); 00056 00057 // create a pipe for stderr, return the end for writing 00058 int create_stderr_pipes(); 00059 00060 // a helper function 00061 std::string GetLineFromBuffer(std::string &buffer); 00062 00063 // a helper function 00064 // reads the new stdout lines and adds them to stdout buffer 00065 void BufferNewStdoutLines(); 00066 00067 // checks emptines of the stdout buffer 00068 bool IsAnyLineInBuffer(const std::string &buffer); 00069 00070 public: 00071 00080 Process(const std::string &commandline, bool use_pty = false, bool default_locale = false, bool pty_trans = true) 00081 : ExternalProgram(commandline, Stderr_To_FileDesc, 00082 use_pty, create_stderr_pipes(), default_locale, "", pty_trans), stderr_output(NULL) 00083 {} 00084 00091 Process(const char *const *argv, const Environment &environment, bool use_pty = false, bool default_locale = false, bool pty_trans = true) 00092 : ExternalProgram(argv, environment, Stderr_To_FileDesc, 00093 use_pty, create_stderr_pipes(), default_locale, "", pty_trans) 00094 {} 00095 00096 00097 ~Process(); 00098 00102 bool kill(int sig); 00103 00107 bool kill(); 00108 00112 std::string readLine(); 00113 00117 std::string read(); 00118 00122 std::string readErrLine(); 00123 00127 std::string readErr(); 00128 00132 int closeAll(); 00133 00137 void readStdoutToBuffer(); 00138 00142 void readStderrToBuffer(); 00143 00147 bool anyLineInStdout(); 00148 00152 FILE* errorFile(); 00153 00154 }; 00155 00156 #endif // Process_h
1.7.3