Mercurial > hg > gpsynth
comparison third_party/boost/process/context.hpp @ 0:add35537fdbb tip
Initial import
| author | irh <ian.r.hobson@gmail.com> |
|---|---|
| date | Thu, 25 Aug 2011 11:05:55 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:add35537fdbb |
|---|---|
| 1 // | |
| 2 // Boost.Process | |
| 3 // ~~~~~~~~~~~~~ | |
| 4 // | |
| 5 // Copyright (c) 2006, 2007 Julio M. Merino Vidal | |
| 6 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling | |
| 7 // Copyright (c) 2009 Boris Schaeling | |
| 8 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling | |
| 9 // | |
| 10 // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 11 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 12 // | |
| 13 | |
| 14 /** | |
| 15 * \file boost/process/context.hpp | |
| 16 * | |
| 17 * Includes the declaration of the context class. | |
| 18 */ | |
| 19 | |
| 20 #ifndef BOOST_PROCESS_CONTEXT_HPP | |
| 21 #define BOOST_PROCESS_CONTEXT_HPP | |
| 22 | |
| 23 #include <boost/process/config.hpp> | |
| 24 | |
| 25 #if defined(BOOST_POSIX_API) | |
| 26 # include <unistd.h> | |
| 27 #elif defined(BOOST_WINDOWS_API) | |
| 28 # include <windows.h> | |
| 29 #endif | |
| 30 | |
| 31 #include <boost/process/stream_id.hpp> | |
| 32 #include <boost/process/stream_ends.hpp> | |
| 33 #include <boost/process/stream_type.hpp> | |
| 34 #include <boost/process/environment.hpp> | |
| 35 #include <boost/process/self.hpp> | |
| 36 #include <boost/process/stream_behavior.hpp> | |
| 37 #include <boost/function.hpp> | |
| 38 #include <string> | |
| 39 #include <map> | |
| 40 | |
| 41 namespace boost { | |
| 42 namespace process { | |
| 43 | |
| 44 /** | |
| 45 * Context class to define how a child process is created. | |
| 46 * | |
| 47 * The context class is used to configure streams, to set the work directory | |
| 48 * and define environment variables. It is also used to change a process | |
| 49 * name (the variable commonly known as argv[0]). | |
| 50 */ | |
| 51 struct context | |
| 52 { | |
| 53 typedef std::map<stream_id, boost::function<stream_ends (stream_type)> > | |
| 54 streams_t; | |
| 55 | |
| 56 /** | |
| 57 * Streams. | |
| 58 * | |
| 59 * Streams of a child process can be configured through factory functions | |
| 60 * which return a pair of handles - one handle to use as a stream end | |
| 61 * in the child process and possibly another handle to use as a stream end | |
| 62 * in the parent process (if a pipe is setup both processes can communicate | |
| 63 * with each other). | |
| 64 */ | |
| 65 streams_t streams; | |
| 66 | |
| 67 /** | |
| 68 * Process name. | |
| 69 * | |
| 70 * The child process can access the process name via a variable | |
| 71 * commonly known as argv[0]. | |
| 72 */ | |
| 73 std::string process_name; | |
| 74 | |
| 75 /** | |
| 76 * Work directory. | |
| 77 */ | |
| 78 std::string work_dir; | |
| 79 | |
| 80 /** | |
| 81 * Environment variables. | |
| 82 */ | |
| 83 environment env; | |
| 84 | |
| 85 /** | |
| 86 * Constructs a process context. | |
| 87 * | |
| 88 * The default behavior of standard streams is to inherit them. The current | |
| 89 * work directory is also the work directory of the child process. The child | |
| 90 * process also inherits all environment variables. | |
| 91 */ | |
| 92 context() | |
| 93 : work_dir(self::get_work_dir()), | |
| 94 env(self::get_environment()) | |
| 95 { | |
| 96 #if defined(BOOST_POSIX_API) | |
| 97 streams[stdin_id] = behavior::inherit(STDIN_FILENO); | |
| 98 streams[stdout_id] = behavior::inherit(STDOUT_FILENO); | |
| 99 streams[stderr_id] = behavior::inherit(STDERR_FILENO); | |
| 100 #elif defined(BOOST_WINDOWS_API) | |
| 101 streams[stdin_id] = behavior::inherit(GetStdHandle(STD_INPUT_HANDLE)); | |
| 102 streams[stdout_id] = behavior::inherit(GetStdHandle(STD_OUTPUT_HANDLE)); | |
| 103 streams[stderr_id] = behavior::inherit(GetStdHandle(STD_ERROR_HANDLE)); | |
| 104 #endif | |
| 105 } | |
| 106 | |
| 107 #if defined(BOOST_POSIX_API) || defined(BOOST_PROCESS_DOXYGEN) | |
| 108 /** | |
| 109 * Setups a child process. | |
| 110 * | |
| 111 * This is an extension point to support more configuration options for | |
| 112 * child processes. You can initialize \a setup with a user-defined function | |
| 113 * which is called when a child process is created. | |
| 114 * | |
| 115 * On POSIX platforms setup() is called in the child process. That's why in | |
| 116 * a multithreaded application only async-signal-safe functions must be | |
| 117 * called in the function \a setup is bound to. | |
| 118 * | |
| 119 * On Windows platforms setup() is called in the parent process. A | |
| 120 * reference to a STARTUPINFOA structure is passed as parameter. | |
| 121 */ | |
| 122 boost::function<void ()> setup; | |
| 123 #elif defined(BOOST_WINDOWS_API) | |
| 124 boost::function<void (STARTUPINFOA&)> setup; | |
| 125 #endif | |
| 126 }; | |
| 127 | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 #endif |
