ardour
system_exec.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3  Copyright (C) 2010-2014 Robin Gareus <robin@gareus.org>
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 2 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, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 #ifndef _libpbd_system_exec_h_
21 #define _libpbd_system_exec_h_
22 
23 #ifndef STDIN_FILENO
24 #define STDIN_FILENO 0
25 #endif
26 #ifndef STDOUT_FILENO
27 #define STDOUT_FILENO 1
28 #endif
29 #ifndef STDERR_FILENO
30 #define STDERR_FILENO 2
31 #endif
32 
33 #ifdef PLATFORM_WINDOWS
34 #include <windows.h>
35 
36 #ifdef interface
37 #undef interface // VKamyshniy: to avoid "include/giomm-2.4/giomm/dbusmessage.h:270:94: error: expected ',' or '...' before 'struct'"
38 #endif
39 
40 #endif
41 
42 #include <string>
43 #include <pthread.h>
44 #include <signal.h>
45 #include <map>
46 
47 #ifdef NOPBD /* unit-test outside ardour */
48 #include <sigc++/bind.h>
49 #include <sigc++/signal.h>
50 #else
51 #include "pbd/signals.h"
52 #endif
53 
54 namespace PBD {
55 
71 {
72  public:
86  SystemExec (std::string c, std::string a = "");
98  SystemExec (std::string c, char ** a);
99 
114  SystemExec (std::string command, const std::map<char, std::string> subs);
115 
116  virtual ~SystemExec ();
117 
129  int start (int stderr_mode, const char *_vfork_exec_wrapper);
135  void terminate ();
142  bool is_running ();
153  int wait (int options=0);
160  void close_stdin ();
167  int write_to_stdin (std::string d, size_t len=0);
168 
173 #ifdef NOPBD /* outside ardour */
174  sigc::signal<void, std::string,size_t> ReadStdout;
175 #else
176  PBD::Signal2<void, std::string,size_t> ReadStdout;
177 #endif
178 
180 #ifdef NOPBD /* outside ardour */
181  sigc::signal<void> Terminated;
182 #else
183  PBD::Signal0<void> Terminated;
184 #endif
185 
197  void output_interposer ();
198 
199  protected:
200  std::string cmd;
201  int nicelevel;
202 
203  void make_argp(std::string);
204  void make_argp_escaped(std::string command, const std::map<char, std::string> subs);
205  void make_envp();
206 
207  char **argp;
208  char **envp;
209 
210  private:
211 #ifdef PLATFORM_WINDOWS
212  PROCESS_INFORMATION *pid;
213  HANDLE stdinP[2];
214  HANDLE stdoutP[2];
215  HANDLE stderrP[2];
216  char *w_args;
217  void make_wargs(char **);
218 #else
219  pid_t pid;
220 #endif
221  void init ();
222  pthread_mutex_t write_lock;
223 
224  int pok[2];
225  int pin[2];
226  int pout[2];
227 
228  pthread_t thread_id_tt;
230 
231 }; /* end class */
232 
233 }; /* end namespace */
234 
235 #endif /* _libpbd_system_exec_h_ */
#define LIBPBD_API
PBD::Signal0< void > Terminated
Definition: system_exec.h:183
pthread_t thread_id_tt
Definition: system_exec.h:228
std::string cmd
path to command - set when creating the class
Definition: system_exec.h:200
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
pthread_mutex_t write_lock
Definition: system_exec.h:222
LIBPBD_API bool init()
Definition: pbd.cc:66
int nicelevel
process nice level - defaults to 0
Definition: system_exec.h:201
execute an external command
Definition: system_exec.h:70
Definition: debug.h:30
PBD::Signal2< void, std::string, size_t > ReadStdout
Definition: system_exec.h:176