ian@0: // ian@0: // Boost.Process ian@0: // ~~~~~~~~~~~~~ ian@0: // ian@0: // Copyright (c) 2006, 2007 Julio M. Merino Vidal ian@0: // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling ian@0: // Copyright (c) 2009 Boris Schaeling ian@0: // Copyright (c) 2010 Felipe Tanus, Boris Schaeling ian@0: // ian@0: // Distributed under the Boost Software License, Version 1.0. (See accompanying ian@0: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ian@0: // ian@0: ian@0: /** ian@0: * \file boost/process/context.hpp ian@0: * ian@0: * Includes the declaration of the context class. ian@0: */ ian@0: ian@0: #ifndef BOOST_PROCESS_CONTEXT_HPP ian@0: #define BOOST_PROCESS_CONTEXT_HPP ian@0: ian@0: #include ian@0: ian@0: #if defined(BOOST_POSIX_API) ian@0: # include ian@0: #elif defined(BOOST_WINDOWS_API) ian@0: # include ian@0: #endif ian@0: ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: #include ian@0: ian@0: namespace boost { ian@0: namespace process { ian@0: ian@0: /** ian@0: * Context class to define how a child process is created. ian@0: * ian@0: * The context class is used to configure streams, to set the work directory ian@0: * and define environment variables. It is also used to change a process ian@0: * name (the variable commonly known as argv[0]). ian@0: */ ian@0: struct context ian@0: { ian@0: typedef std::map > ian@0: streams_t; ian@0: ian@0: /** ian@0: * Streams. ian@0: * ian@0: * Streams of a child process can be configured through factory functions ian@0: * which return a pair of handles - one handle to use as a stream end ian@0: * in the child process and possibly another handle to use as a stream end ian@0: * in the parent process (if a pipe is setup both processes can communicate ian@0: * with each other). ian@0: */ ian@0: streams_t streams; ian@0: ian@0: /** ian@0: * Process name. ian@0: * ian@0: * The child process can access the process name via a variable ian@0: * commonly known as argv[0]. ian@0: */ ian@0: std::string process_name; ian@0: ian@0: /** ian@0: * Work directory. ian@0: */ ian@0: std::string work_dir; ian@0: ian@0: /** ian@0: * Environment variables. ian@0: */ ian@0: environment env; ian@0: ian@0: /** ian@0: * Constructs a process context. ian@0: * ian@0: * The default behavior of standard streams is to inherit them. The current ian@0: * work directory is also the work directory of the child process. The child ian@0: * process also inherits all environment variables. ian@0: */ ian@0: context() ian@0: : work_dir(self::get_work_dir()), ian@0: env(self::get_environment()) ian@0: { ian@0: #if defined(BOOST_POSIX_API) ian@0: streams[stdin_id] = behavior::inherit(STDIN_FILENO); ian@0: streams[stdout_id] = behavior::inherit(STDOUT_FILENO); ian@0: streams[stderr_id] = behavior::inherit(STDERR_FILENO); ian@0: #elif defined(BOOST_WINDOWS_API) ian@0: streams[stdin_id] = behavior::inherit(GetStdHandle(STD_INPUT_HANDLE)); ian@0: streams[stdout_id] = behavior::inherit(GetStdHandle(STD_OUTPUT_HANDLE)); ian@0: streams[stderr_id] = behavior::inherit(GetStdHandle(STD_ERROR_HANDLE)); ian@0: #endif ian@0: } ian@0: ian@0: #if defined(BOOST_POSIX_API) || defined(BOOST_PROCESS_DOXYGEN) ian@0: /** ian@0: * Setups a child process. ian@0: * ian@0: * This is an extension point to support more configuration options for ian@0: * child processes. You can initialize \a setup with a user-defined function ian@0: * which is called when a child process is created. ian@0: * ian@0: * On POSIX platforms setup() is called in the child process. That's why in ian@0: * a multithreaded application only async-signal-safe functions must be ian@0: * called in the function \a setup is bound to. ian@0: * ian@0: * On Windows platforms setup() is called in the parent process. A ian@0: * reference to a STARTUPINFOA structure is passed as parameter. ian@0: */ ian@0: boost::function setup; ian@0: #elif defined(BOOST_WINDOWS_API) ian@0: boost::function setup; ian@0: #endif ian@0: }; ian@0: ian@0: } ian@0: } ian@0: ian@0: #endif