Cypress  1.0
C++ Spiking Neural Network Simulation Framework
process.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Neural Associative Memory Simulator
3  * Copyright (C) 2016 Andreas Stöckel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
28 #ifndef CYPRESS_PROCESS_HPP
29 #define CYPRESS_PROCESS_HPP
30 
31 #include <atomic>
32 #include <iosfwd>
33 #include <memory>
34 #include <string>
35 #include <tuple>
36 #include <vector>
37 
38 namespace cypress {
39 
43 class ProcessImpl;
44 
48 class Process {
49 private:
53  std::unique_ptr<ProcessImpl> impl;
54 
55 public:
63  static void generic_writer(Process &proc, std::istream &input);
64 
72  static void generic_pipe(std::istream &input, std::ostream &output);
73 
83  static void fd_input_pipe(int fd, std::ostream &output,
84  const std::atomic<bool> &done);
85 
94  Process(const std::string &cmd, const std::vector<std::string> &args,
95  bool do_redirect = true);
96 
100  ~Process();
101 
108  std::istream &child_stdout();
109 
116  std::istream &child_stderr();
117 
125  std::ostream &child_stdin();
126 
130  void close_child_stdin();
131 
135  bool running();
136 
147  int exitcode();
148 
153  int wait();
154 
164  bool signal(int signal);
165 
180  static int exec(const std::string &cmd,
181  const std::vector<std::string> &args, std::ostream &cout,
182  std::ostream &cerr,
183  const std::string &input = std::string());
184 
198  static int exec(const std::string &cmd,
199  const std::vector<std::string> &args, std::istream &cin,
200  std::ostream &cout, std::ostream &cerr);
201 
210  static int exec_no_redirect(const std::string &cmd,
211  const std::vector<std::string> &args);
212 
224  static std::tuple<int, std::string, std::string> exec(
225  const std::string &cmd, const std::vector<std::string> &args,
226  const std::string &input = std::string());
227 };
228 }
229 
230 #endif /* CYPRESS_PROCESS_HPP */
static void generic_writer(Process &proc, std::istream &input)
static int exec_no_redirect(const std::string &cmd, const std::vector< std::string > &args)
Definition: process.hpp:48
bool signal(int signal)
std::istream & child_stdout()
static void generic_pipe(std::istream &input, std::ostream &output)
static int exec(const std::string &cmd, const std::vector< std::string > &args, std::ostream &cout, std::ostream &cerr, const std::string &input=std::string())
std::ostream & child_stdin()
Process(const std::string &cmd, const std::vector< std::string > &args, bool do_redirect=true)
Definition: brainscales_lib.hpp:39
std::istream & child_stderr()
static void fd_input_pipe(int fd, std::ostream &output, const std::atomic< bool > &done)
void close_child_stdin()