libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Subprocess.hpp
Go to the documentation of this file.
1 #ifndef SCLANUCHER_HPP
2 #define SCLANUCHER_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <string>
22 #ifdef __unix__
23 
24 #else
25  #include <windows.h>
26 #endif
27 #include "Utilities.hpp"
28 
29 namespace AlgAudio{
30 
31 namespace Exceptions{
32 struct Subprocess : public Exception{
33  Subprocess(std::string t) : Exception(t) {}
34 };
35 } // namespace Exceptions
36 
37 /* A universal class for launching and terminating subprocesses, as well as
38  * communicating with them via stdio.
39  */
40 class Subprocess{
41 public:
42  Subprocess(std::string command);
43  Subprocess(const Subprocess&) = delete;
44  ~Subprocess();
45  Subprocess operator=(const Subprocess&) = delete;
46  void SendData(const std::string&);
47  std::string ReadData();
48 private:
49  std::string command;
50  #ifdef __unix__
51  int pipe_child_stdout_fd[2];
52  int pipe_child_stdin_fd[2];
53  int pid;
54  // This pipe is used to notify parent proces about execve success or
55  // failure. See http://stackoverflow.com/questions/1584956/how-to-handle-execvp-errors-after-fork
56  int pipe_child_exec_status[2];
57  #else
58  PROCESS_INFORMATION piProcInfo;
59  HANDLE g_hChildStd_IN_Rd = NULL;
60  HANDLE g_hChildStd_IN_Wr = NULL;
61  HANDLE g_hChildStd_OUT_Rd = NULL;
62  HANDLE g_hChildStd_OUT_Wr = NULL;
63  static HANDLE job; // = NULL
64  #endif
65 };
66 
67 } // namespace AlgAudio
68 
69 #endif // SCLANUCHER_HPP
Subprocess(std::string command)
void SendData(const std::string &)
Definition: Subprocess.hpp:40
Subprocess operator=(const Subprocess &)=delete
Definition: Alertable.hpp:26
Definition: Subprocess.hpp:32
Subprocess(std::string t)
Definition: Subprocess.hpp:33
Definition: Exception.hpp:29
std::string ReadData()