initializers.hpp
Go to the documentation of this file.
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 /**
11  * \file boost/process/initializers.hpp
12  *
13  * Defines initializers.
14  */
15 
16 #pragma once
17 
18 #include <boost/process/config.hpp>
19 
20 #include BOOST_PROCESS_PLATFORM_PROMOTE_PATH(initializers)
21 BOOST_PROCESS_PLATFORM_PROMOTE_INITIALIZERS_NAMESPACE
22 
23 #if defined(BOOST_PROCESS_DOXYGEN)
24 namespace boost::process::initializers
25 {
26  /**
27  * Binds the standard error stream.
28  */
29  class bind_stderr : public initializer_base
30  {
31  public:
32  /**
33  * Constructor.
34  */
35  explicit bind_stderr(const boost::iostreams::file_descriptor_sink& sink);
36  };
37 
38  /**
39  * Binds the standard input stream.
40  */
41  class bind_stdin : public initializer_base
42  {
43  public:
44  /**
45  * Constructor.
46  */
47  explicit bind_stdin(const boost::iostreams::file_descriptor_source& source);
48  };
49 
50  /**
51  * Binds the standard output stream.
52  */
53  class bind_stdout : public initializer_base
54  {
55  public:
56  /**
57  * Constructor.
58  */
59  explicit bind_stdout(const boost::iostreams::file_descriptor_sink& sink);
60  };
61 
62  /**
63  * Binds a file descriptor.
64  *
65  * \remark <em>POSIX only.</em>
66  */
67  class bind_fd : public initializer_base
68  {
69  public:
70  /**
71  * Constructor.
72  */
73  bind_fd(int id, const boost::iostreams::file_descriptor& fd);
74  };
75 
76  /**
77  * Closes a file descriptor.
78  *
79  * \remark <em>POSIX only.</em>
80  */
81  class close_fd : public initializer_base
82  {
83  /**
84  * Constructor.
85  */
86  explicit close_fd(int fd);
87  };
88 
89  /**
90  * Closes file descriptors.
91  *
92  * \remark <em>POSIX only.</em>
93  */
94  class close_fds : public initializer_base
95  {
96  public:
97  /**
98  * Constructor.
99  *
100  * \c range_type must be an <tt>int</tt>-range.
101  */
102  explicit close_fds(const range_type& fds);
103  };
104 
105  /**
106  * Closes all file descriptors a predicate returns
107  * true for.
108  *
109  * This initializer doesn't close file descriptors
110  * immediately. Instead it sets the \c FD_CLOEXEC
111  * flag. File descriptors are closed when \c execve
112  * is called and the call succeeds.
113  *
114  * \remark <em>POSIX only.</em>
115  */
116  class close_fds_if : public initializer_base
117  {
118  public:
119  /**
120  * Constructor.
121  *
122  * \c predicate_type must be a function or functor with
123  * this signature: <tt>bool(int)</tt>
124  */
125  explicit close_fds_if(const predicate_type& pred);
126  };
127 
128  /**
129  * Closes the standard error stream.
130  */
131  class close_stderr : public initializer_base
132  {
133  /**
134  * Constructor.
135  */
136  close_stderr();
137  };
138 
139  /**
140  * Closes the standard input stream.
141  */
142  class close_stdin : public initializer_base
143  {
144  /**
145  * Constructor.
146  */
147  close_stdin();
148  };
149 
150  /**
151  * Closes the standard output stream.
152  */
153  class close_stdout : public initializer_base
154  {
155  /**
156  * Constructor.
157  */
158  close_stdout();
159  };
160 
161  /**
162  * Hides the console.
163  */
164  class hide_console : public initializer_base
165  {
166  public:
167  /**
168  * Constructor.
169  */
170  hide_console();
171  };
172 
173  /**
174  * Inherits environment variables.
175  */
176  class inherit_env : public initializer_base
177  {
178  public:
179  /**
180  * Constructor.
181  */
182  inherit_env();
183  };
184 
185  /**
186  * Notifies an I/O service object of fork-related events.
187  *
188  * \see boost::asio::io_service::notify_fork
189  *
190  * \remark <em>POSIX only.</em>
191  */
192  class notify_io_service : public initializer_base
193  {
194  public:
195  /**
196  * Constructor.
197  */
198  explicit notify_io_service(boost::asio::io_service& io_service);
199  };
200 
201  /**
202  * Generic initializer to execute any code if \c execve
203  * failed.
204  *
205  * \remark <em>POSIX only.</em>
206  */
207  class on_exec_error : public initializer_base
208  {
209  public:
210  /**
211  * Constructor.
212  *
213  * \c handler_type must be a function or functor with
214  * this signature: <tt>void(executor&)</tt>
215  */
216  explicit on_exec_error(handler_type handler);
217  };
218 
219  /**
220  * Generic initializer to execute any code before \c execve
221  * is called.
222  *
223  * \remark <em>POSIX only.</em>
224  */
225  class on_exec_setup : public initializer_base
226  {
227  public:
228  /**
229  * Constructor.
230  *
231  * \c handler_type must be a function or functor with
232  * this signature: <tt>void(executor&)</tt>
233  */
234  explicit on_exec_setup(handler_type handler);
235  };
236 
237  /**
238  * Generic initializer to execute any code if \c fork
239  * failed.
240  *
241  * \remark <em>POSIX only.</em>
242  */
243  class on_fork_error : public initializer_base
244  {
245  public:
246  /**
247  * Constructor.
248  *
249  * \c handler_type must be a function or functor with
250  * this signature: <tt>void(executor&)</tt>
251  */
252  explicit on_fork_error(handler_type handler);
253  };
254 
255  /**
256  * Generic initializer to execute any code before \c fork
257  * is called.
258  *
259  * \remark <em>POSIX only.</em>
260  */
261  class on_fork_setup : public initializer_base
262  {
263  public:
264  /**
265  * Constructor.
266  *
267  * \c handler_type must be a function or functor with
268  * this signature: <tt>void(executor&)</tt>
269  */
270  explicit on_fork_setup(handler_type handler);
271  };
272 
273  /**
274  * Generic initializer to execute any code in the parent
275  * process after \c fork has been called successfully.
276  *
277  * \remark <em>POSIX only.</em>
278  */
279  class on_fork_success : public initializer_base
280  {
281  public:
282  /**
283  * Constructor.
284  *
285  * \c handler_type must be a function or functor with
286  * this signature: <tt>void(executor&)</tt>
287  */
288  explicit on_fork_success(handler_type handler);
289  };
290 
291  /**
292  * Generic initializer to execute any code if \c CreateProcess
293  * failed.
294  *
295  * \remark <em>Windows only.</em>
296  */
297  class on_CreateProcess_error : public initializer_base
298  {
299  public:
300  /**
301  * Constructor.
302  *
303  * \c handler_type must be a function or functor with
304  * this signature: <tt>void(executor&)</tt>
305  */
306  explicit on_CreateProcess_error(handler_type handler);
307  };
308 
309  /**
310  * Generic initializer to execute any code before \c CreateProcess
311  * is called.
312  *
313  * \remark <em>Windows only.</em>
314  */
315  class on_CreateProcess_setup : public initializer_base
316  {
317  public:
318  /**
319  * Constructor.
320  *
321  * \c handler_type must be a function or functor with
322  * this signature: <tt>void(executor&)</tt>
323  */
324  explicit on_CreateProcess_setup(handler_type handler);
325  };
326 
327  /**
328  * Generic initializer to execute any code after \c CreateProcess
329  * has been called successfully.
330  *
331  * \remark <em>Windows only.</em>
332  */
333  class on_CreateProcess_success : public initializer_base
334  {
335  public:
336  /**
337  * Constructor.
338  *
339  * \c handler_type must be a function or functor with
340  * this signature: <tt>void(executor&)</tt>
341  */
342  explicit on_CreateProcess_success(handler_type handler);
343  };
344 
345  /**
346  * Specifies the executable to start.
347  *
348  * This initializer must always be used. The only exception is
349  * if you use \c set_args or a generic initializer which
350  * specifies the executable.
351  */
352  class run_exe : public initializer_base
353  {
354  public:
355  /**
356  * Constructor.
357  *
358  * On Windows \c string_type must be <tt>const char*</tt>,
359  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
360  * If Unicode is used, \c string_type must be
361  * <tt>const wchar_t*</tt>, <tt>std::wstring</tt> or
362  * <tt>std::filesystem::path</tt>.
363  *
364  * On POSIX \c string_type must be <tt>const char*</tt>,
365  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
366  */
367  explicit run_exe(const string_type& s);
368  };
369 
370  /**
371  * Sets the command line arguments.
372  *
373  * The first argument specifies the executable to start unless
374  * \c run_exe is used.
375  *
376  * Use \c set_cmd_line if you don't want to pass a collection of
377  * command line arguments but set the command line as one string.
378  */
379  class set_args : public initializer_base
380  {
381  public:
382  /**
383  * Constructor.
384  *
385  * On Windows \c range_type must be a <tt>std::string</tt>-range.
386  * If Unicode is used, \c range_type must be a
387  * <tt>std::wstring</tt>-range.
388  *
389  * On POSIX \c range_type must be a <tt>std::string</tt>-range.
390  */
391  explicit set_args(const range_type& r);
392  };
393 
394  /**
395  * Sets the command line.
396  *
397  * Use \c set_args if you don't want to set the command line as
398  * one string but pass a collection of command line arguments.
399  */
400  class set_cmd_line : public initializer_base
401  {
402  public:
403  /**
404  * Constructor.
405  *
406  * On Windows \c string_type must be <tt>const char*</tt>,
407  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
408  * If Unicode is used, \c string_type must be
409  * <tt>const wchar_t*</tt>, <tt>std::wstring</tt> or
410  * <tt>std::filesystem::path</tt>.
411  *
412  * On POSIX \c string_type must be <tt>const char*</tt>,
413  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
414  */
415  explicit set_cmd_line(const string_type& s);
416  };
417 
418  /**
419  * Sets the environment.
420  */
421  class set_env : public initializer_base
422  {
423  public:
424  /**
425  * Constructor.
426  *
427  * On Windows \c range_type must be a <tt>std::string</tt>-range.
428  * If Unicode is used, \c range_type must be a
429  * <tt>std::wstring</tt>-range.
430  *
431  * On POSIX \c range_type must be a <tt>std::string</tt>-range.
432  */
433  explicit set_env(const range_type& r);
434  };
435 
436  /**
437  * Sets an error if a child process can't be created.
438  */
439  class set_on_error : public initializer_base
440  {
441  public:
442  /**
443  * Constructor.
444  */
445  explicit set_on_error(boost::system::error_code& ec);
446  };
447 
448  /**
449  * Sets the flag \c wShowWindow in \c STARTUPINFO.
450  *
451  * \remark <em>Windows only.</em>
452  */
453  class show_window : public initializer_base
454  {
455  public:
456  /**
457  * Constructor.
458  */
459  explicit show_window(WORD flags);
460  };
461 
462  /**
463  * Sets the work directory.
464  */
465  class start_in_dir : public initializer_base
466  {
467  public:
468  /**
469  * Constructor.
470  *
471  * On Windows \c string_type must be <tt>const char*</tt>,
472  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
473  * If Unicode is used, \c string_type must be
474  * <tt>const wchar_t*</tt>, <tt>std::wstring</tt> or
475  * <tt>std::filesystem::path</tt>.
476  *
477  * On POSIX \c string_type must be <tt>const char*</tt>,
478  * <tt>std::string</tt> or <tt>std::filesystem::path</tt>.
479  */
480  explicit start_in_dir(const string_type& s);
481  };
482 
483  /**
484  * Throws an error if a child process can't be created.
485  *
486  * The type of the error thrown is \c boost::system::system_error.
487  */
488  class throw_on_error : public initializer_base
489  {
490  public:
491  };
492 }
493 #endif
494 
boost::process::posix::initializers::on_exec_error
on_exec_error_< Handler > on_exec_error(Handler handler)
Definition: on_exec_error.hpp:35
config.hpp
boost::process::posix::initializers::on_exec_setup
on_exec_setup_< Handler > on_exec_setup(Handler handler)
Definition: on_exec_setup.hpp:35
boost::process::posix::initializers::set_env
set_env_< Range > set_env(const Range &envs)
Definition: set_env.hpp:47
boost::process::windows::initializers::set_cmd_line
set_cmd_line_< std::string > set_cmd_line(const char *s)
Definition: set_cmd_line.hpp:55
boost::process::windows::initializers::on_CreateProcess_setup
on_CreateProcess_setup_< Handler > on_CreateProcess_setup(Handler handler)
Definition: on_CreateProcess_setup.hpp:35
boost::process::windows::initializers::start_in_dir
start_in_dir_< std::string > start_in_dir(const char *s)
Definition: start_in_dir.hpp:51
boost::process::posix::initializers::close_fds
close_fds_< Range > close_fds(const Range &fds)
Definition: close_fds.hpp:36
boost::process::windows::initializers::on_CreateProcess_error
on_CreateProcess_error_< Handler > on_CreateProcess_error(Handler handler)
Definition: on_CreateProcess_error.hpp:35
boost::process::posix::initializers::run_exe
run_exe_ run_exe(const char *s)
Definition: run_exe.hpp:44
boost::process::posix::initializers::notify_io_service
notify_io_service_< IOService > notify_io_service(IOService &io_service)
Definition: notify_io_service.hpp:48
boost::process::windows::initializers::on_CreateProcess_success
on_CreateProcess_success_< Handler > on_CreateProcess_success(Handler handler)
Definition: on_CreateProcess_success.hpp:35
boost::process::posix::initializers::set_args
set_args_< Range > set_args(const Range &range)
Definition: set_args.hpp:52
boost::process::posix::initializers::on_fork_error
on_fork_error_< Handler > on_fork_error(Handler handler)
Definition: on_fork_error.hpp:35
boost::process::posix::initializers::on_fork_setup
on_fork_setup_< Handler > on_fork_setup(Handler handler)
Definition: on_fork_setup.hpp:35
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
boost::process::posix::initializers::on_fork_success
on_fork_success_< Handler > on_fork_success(Handler handler)
Definition: on_fork_success.hpp:35
boost::process::posix::initializers::close_fds_if
close_fds_if_< Predicate > close_fds_if(const Predicate &pred)
Definition: close_fds_if.hpp:76
boost::process::posix::initializers::bind_fd
bind_fd_< FileDescriptor > bind_fd(int id, const FileDescriptor &fd)
Definition: bind_fd.hpp:36
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33