on_exit.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2016 Klemens D. Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_
  6. #define BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_
  7. #include <boost/process/detail/config.hpp>
  8. #include <boost/process/detail/handler_base.hpp>
  9. #include <boost/process/detail/windows/async_handler.hpp>
  10. #include <system_error>
  11. #include <functional>
  12. namespace boost { namespace process { namespace detail { namespace windows {
  13. struct on_exit_ : boost::process::detail::windows::async_handler
  14. {
  15. std::function<void(int, const std::error_code&)> handler;
  16. on_exit_(const std::function<void(int, const std::error_code&)> & handler) : handler(handler)
  17. {
  18. }
  19. template<typename Executor>
  20. std::function<void(int, const std::error_code&)> on_exit_handler(Executor&)
  21. {
  22. auto handler_ = this->handler;
  23. return [handler_](int exit_code, const std::error_code & ec)
  24. {
  25. handler_(static_cast<int>(exit_code), ec);
  26. };
  27. }
  28. };
  29. }}}}
  30. #endif /* INCLUDE_BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_ */