handler.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_DETAIL_HANDLER_HPP_
  6. #define BOOST_PROCESS_DETAIL_HANDLER_HPP_
  7. #include <boost/process/detail/config.hpp>
  8. #if defined(BOOST_POSIX_API)
  9. #include <boost/process/detail/posix/handler.hpp>
  10. #elif defined(BOOST_WINDOWS_API)
  11. #include <boost/process/detail/windows/handler.hpp>
  12. #endif
  13. namespace boost { namespace process { namespace detail {
  14. //extended handler base.
  15. typedef api::handler_base_ext handler;
  16. template <class Handler>
  17. struct on_setup_ : handler
  18. {
  19. explicit on_setup_(Handler handler) : handler_(handler) {}
  20. template <class Executor>
  21. void on_setup(Executor &e)
  22. {
  23. handler_(e);
  24. }
  25. private:
  26. Handler handler_;
  27. };
  28. template <class Handler>
  29. struct on_error_ : handler
  30. {
  31. explicit on_error_(Handler handler) : handler_(handler) {}
  32. template <class Executor>
  33. void on_error(Executor &e, const std::error_code &ec)
  34. {
  35. handler_(e, ec);
  36. }
  37. private:
  38. Handler handler_;
  39. };
  40. template <class Handler>
  41. struct on_success_ : handler
  42. {
  43. explicit on_success_(Handler handler) : handler_(handler) {}
  44. template <class Executor>
  45. void on_success(Executor &e)
  46. {
  47. handler_(e);
  48. }
  49. private:
  50. Handler handler_;
  51. };
  52. }
  53. }}
  54. #endif /* BOOST_PROCESS_DETAIL_HANDLER_HPP_ */