mirror of
https://github.com/boostorg/process.git
synced 2026-01-20 16:52:14 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
248af92cfa |
155
include/boost/process/detail/posix/tuple.hpp
Normal file
155
include/boost/process/detail/posix/tuple.hpp
Normal file
@@ -0,0 +1,155 @@
|
||||
// Copyright (c) 2016 Klemens D. Morgenstern
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_PROCESS_DETAIL_POSIX_TUPLE_HPP_
|
||||
#define BOOST_PROCESS_DETAIL_POSIX_TUPLE_HPP_
|
||||
|
||||
#include <boost/process/detail/windows/handler.hpp>
|
||||
#include <boost/fusion/tuple.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace process
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace windows
|
||||
{
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_setup
|
||||
{
|
||||
Executor & exec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_error
|
||||
{
|
||||
Executor & exec;
|
||||
const std::error_code & ec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_success
|
||||
{
|
||||
Executor & exec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_fork_error
|
||||
{
|
||||
Executor & exec;
|
||||
const std::error_code &ec;
|
||||
|
||||
template<typename T>
|
||||
void operator()(T *t)
|
||||
{
|
||||
t->on_fork_error(exec, ec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_exec_setup
|
||||
{
|
||||
Executor & exec;
|
||||
|
||||
template<typename T>
|
||||
void operator()(T *t)
|
||||
{
|
||||
t->on_exec_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_exec_error
|
||||
{
|
||||
Executor & exec;
|
||||
const std::error_code &ec;
|
||||
|
||||
template<typename T>
|
||||
void operator()(T *t)
|
||||
{
|
||||
t->on_exec_error(exec, ec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ...Args>
|
||||
struct initializer_tuple : Args...
|
||||
{
|
||||
template <class Executor>
|
||||
void on_setup(Executor& exec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template <class Executor>
|
||||
void on_error(Executor& exec, const std::error_code & ec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template <class Executor>
|
||||
void on_success(Executor& exec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template<typename Executor>
|
||||
void on_fork_error (Executor & exec, const std::error_code& ec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_fork_error<Executor> func{exec, ec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template<typename Executor>
|
||||
void on_exec_setup (Executor & exec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_exec_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template<typename Executor>
|
||||
void on_exec_error (Executor & exec, const std::error_code& ec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_exec_error<Executor> func{exec, ec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
91
include/boost/process/detail/windows/tuple.hpp
Normal file
91
include/boost/process/detail/windows/tuple.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2016 Klemens D. Morgenstern
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_PROCESS_DETAIL_WINDOWS_TUPLE_HPP_
|
||||
#define BOOST_PROCESS_DETAIL_WINDOWS_TUPLE_HPP_
|
||||
|
||||
#include <boost/process/detail/windows/handler.hpp>
|
||||
#include <boost/fusion/tuple.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace process
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace windows
|
||||
{
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_setup
|
||||
{
|
||||
Executor & exec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_error
|
||||
{
|
||||
Executor & exec;
|
||||
const std::error_code & ec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Executor>
|
||||
struct tuple_on_success
|
||||
{
|
||||
Executor & exec;
|
||||
template<typename T>
|
||||
void operator()(T *p)
|
||||
{
|
||||
p->on_setup(exec);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ...Args>
|
||||
struct initializer_tuple : Args...
|
||||
{
|
||||
template <class Executor>
|
||||
void on_setup(Executor& exec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template <class Executor>
|
||||
void on_error(Executor& exec, const std::error_code & ec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
|
||||
template <class Executor>
|
||||
void on_success(Executor& exec)
|
||||
{
|
||||
auto tup = boost::fusion::make_tuple(static_cast<Args*>(this)...);
|
||||
tuple_on_setup<Executor> func{exec};
|
||||
boost::fusion::for_each(tup, func);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
20
include/boost/process/options.hpp
Normal file
20
include/boost/process/options.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2016 Klemens D. Morgenstern
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_PROCESS_OPTIONS_HPP_
|
||||
#define BOOST_PROCESS_OPTIONS_HPP_
|
||||
|
||||
#include <boost/process/options/args.hpp>
|
||||
#include <boost/process/options/async.hpp>
|
||||
#include <boost/process/options/cmd.hpp>
|
||||
#include <boost/process/options/env.hpp>
|
||||
#include <boost/process/options/group.hpp>
|
||||
#include <boost/process/options/io.hpp>
|
||||
#include <boost/process/options/posix.hpp>
|
||||
#include <boost/process/options/shell.hpp>
|
||||
#include <boost/process/options/start_dir.hpp>
|
||||
#include <boost/process/options/windows.hpp>
|
||||
|
||||
#endif
|
||||
69
include/boost/process/options/async.hpp
Normal file
69
include/boost/process/options/async.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2016 Klemens D. Morgenstern
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
/** \file boost/process/options/async.hpp
|
||||
|
||||
The header which provides the asynchrounous features for the option style.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_PROCESS_ASYNC_HPP_
|
||||
#define BOOST_PROCESS_ASYNC_HPP_
|
||||
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/process/async.hpp>
|
||||
#include <boost/process/options/make_options.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace process
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<>
|
||||
class options_t<api::on_exit_> : api::async_handler
|
||||
{
|
||||
std::vector<std::function<void(int, const std::error_code&)>> _handlers;
|
||||
public:
|
||||
|
||||
template<typename Executor>
|
||||
std::function<void(int, const std::error_code&)> on_exit_handler(Executor & exec)
|
||||
{
|
||||
return [_handlers](int exit_code, const std::error_code & ec)
|
||||
{
|
||||
for (auto & h : _handlers)
|
||||
h(static_cast<int>(exit_code), ec);
|
||||
};
|
||||
}
|
||||
|
||||
void add_on_exit(const std::function<void(int, const std::error_code&)> &f)
|
||||
{
|
||||
_handlers.push_back(f);
|
||||
}
|
||||
void add_on_exit(std::future<int> &f)
|
||||
{
|
||||
_handlers.push_back(::boost::process::detail::on_exit_from_future(f));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class options_t<api::io_service_ref> : api::io_service_ref
|
||||
{
|
||||
boost::asio::io_service _ios;
|
||||
public:
|
||||
options_t() : api::io_service_ref(_ios) {}
|
||||
|
||||
boost::asio::io_service & get_io_service() {return _ios;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* INCLUDE_BOOST_PROCESS_DETAIL_ASYNC_HPP_ */
|
||||
48
include/boost/process/options/make_options.hpp
Normal file
48
include/boost/process/options/make_options.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2016 Klemens D. Morgenstern
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_PROCESS_OPTIONS_MAKE_OPTIONS_HPP_
|
||||
#define BOOST_PROCESS_OPTIONS_MAKE_OPTIONS_HPP_
|
||||
|
||||
#include <boost/process/detail/config.hpp>
|
||||
|
||||
#if defined(BOOST_WINDOWS_API)
|
||||
#include <boost/process/detail/windows/tuple.hpp>
|
||||
#elif defined(BOOST_POSIX_API)
|
||||
#include <boost/process/detail/posix/tuple.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace process
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct option_t;
|
||||
|
||||
template<typename ... Args>
|
||||
struct options
|
||||
{
|
||||
using needs_io_service = typename needs_io_service<Args...>::type;
|
||||
|
||||
std::conditional<needs_io_service,
|
||||
::boost::process::detail::api::initializer_tuple<api::io_service_ref, option_t<Args>...>,
|
||||
::boost::process::detail::api::initializer_tuple<option_t<Args>>>;
|
||||
};
|
||||
|
||||
template<typename ... Args>
|
||||
using options_t = typename options<Args...>::type;
|
||||
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline detail::options_t<Args...> make_options(const Args & ...) {return {};}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user