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

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