yast2-core
Process.h
Go to the documentation of this file.
1 /* Process.h
2  *
3  * ------------------------------------------------------------------------------
4  * Copyright (c) 2008 Novell, Inc. All Rights Reserved.
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the
9  * Free Software Foundation; either version 2 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may find
20  * current contact information at www.novell.com.
21  * ------------------------------------------------------------------------------
22  *
23  * Class Process
24  *
25  * Authors: Ladislav Slezák <lslezak@novell.com>
26  *
27  * $Id: Process.h 57029 2009-04-29 11:04:19Z lslezak $
28  */
29 
30 #ifndef Process_h
31 #define Process_h
32 
33 #include <y2util/ExternalProgram.h>
34 
42 class Process: public ExternalProgram
43 {
44 
45 private:
46 
47  std::string stdout_buffer; // buffer for stdout
48  std::string stderr_buffer; // buffer for stderr
49 
51 
52 private:
53 
54  // disable copy ctor and operator=
55  Process(const Process&);
56  Process& operator=(const Process&);
57 
58  // create a pipe for stderr, return the end for writing
59  int create_stderr_pipes();
60 
61  // a helper function
62  std::string GetLineFromBuffer(std::string &buffer);
63 
64  // a helper function
65  // reads the new stdout lines and adds them to stdout buffer
66  void BufferNewStdoutLines();
67 
68  // checks emptines of the stdout buffer
69  bool IsAnyLineInBuffer(const std::string &buffer);
70 
71 public:
72 
81  Process(const std::string &commandline, bool use_pty = false, bool default_locale = false, bool pty_trans = true)
82  : ExternalProgram(commandline, Stderr_To_FileDesc,
83  use_pty, create_stderr_pipes(), default_locale, "", pty_trans), stderr_output(NULL)
84  {}
85 
92  Process(const char *const *argv, const Environment &environment, bool use_pty = false, bool default_locale = false, bool pty_trans = true)
93  : ExternalProgram(argv, environment, Stderr_To_FileDesc,
94  use_pty, create_stderr_pipes(), default_locale, "", pty_trans)
95  {}
96 
97 
98  ~Process();
99 
103  bool kill(int sig);
104 
108  bool kill();
109 
113  std::string readLine();
114 
118  std::string read();
119 
123  std::string readErrLine();
124 
128  std::string readErr();
129 
133  int closeAll();
134 
138  void readStdoutToBuffer();
139 
143  void readStderrToBuffer();
144 
148  bool anyLineInStdout();
149 
153  FILE* errorFile();
154 
155 };
156 
157 #endif // Process_h
std::string readErr()
Definition: Process.cc:177
void BufferNewStdoutLines()
Definition: Process.cc:69
std::string readLine()
Definition: Process.cc:76
bool kill()
Definition: Process.cc:64
std::string readErrLine()
Definition: Process.cc:169
void readStderrToBuffer()
Definition: Process.cc:118
int closeAll()
Definition: Process.cc:234
std::string stderr_buffer
Definition: Process.h:48
std::string stdout_buffer
Definition: Process.h:47
std::map< std::string, std::string > Environment
Definition: ExternalProgram.h:54
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition: ExternalProgram.h:36
FILE * errorFile()
Definition: Process.cc:247
Definition: ExternalProgram.h:48
FILE * stderr_output
Definition: Process.h:50
void readStdoutToBuffer()
Definition: Process.cc:91
bool anyLineInStdout()
Definition: Process.cc:84
bool IsAnyLineInBuffer(const std::string &buffer)
Definition: Process.cc:163
int create_stderr_pipes()
Definition: Process.cc:214
std::string GetLineFromBuffer(std::string &buffer)
Definition: Process.cc:143
Process(const char *const *argv, const Environment &environment, bool use_pty=false, bool default_locale=false, bool pty_trans=true)
Definition: Process.h:92
~Process()
Definition: Process.cc:43
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition: Process.h:42
Process(const std::string &commandline, bool use_pty=false, bool default_locale=false, bool pty_trans=true)
Definition: Process.h:81
Process & operator=(const Process &)
bool use_pty
Definition: ExternalProgram.h:125
std::string read()
Definition: Process.cc:106
Process(const Process &)

Generated on a sunny day for yast2-core by doxygen 1.8.8