12#include <memory_resource>
13#include <system_error>
90 detail::handler_service *m_srv_ptr;
118template <ev::detail::EventHandler HandlerTy, ::co_usb::detail::ErrorProtocol<ev::context> ErrorTy,
120inline auto make_context (boost::capy::executor_ref exec, std::pmr::memory_resource *memres,
121 ErrorTy &&errp, Args &&...args) -> ev::context
123 boost::capy::execution_context &exec_ctx = exec.context();
125 auto &srv = exec_ctx.use_service<ev::detail::handler_service>();
126 std::error_code ec = srv.init_context();
129 return errp.template with_error<ev::context>(ec);
131 srv.emplace_handler<HandlerTy>(std::forward<Args>(args)..., memres);
148template <ev::detail::EventHandler HandlerTy,
typename... Args>
149inline auto make_context (boost::capy::executor_ref exec, std::pmr::memory_resource *memres,
150 Args &&...args) -> ev::context
152 return make_context<HandlerTy, detail::as_exception_t, Args...>(exec, memres,
as_exception(),
153 std::forward<Args>(args)...);
168template <ev::detail::EventHandler HandlerTy, ::co_usb::detail::ErrorProtocol<ev::context> ErrorTy,
170inline auto make_context (boost::capy::executor_ref exec, ErrorTy &&errp, Args &&...args)
173 return make_context<HandlerTy, ErrorTy, Args...>(exec, std::pmr::get_default_resource(),
174 std::forward<ErrorTy>(errp),
175 std::forward<Args>(args)...);
190template <ev::detail::EventHandler HandlerTy,
typename... Args>
191inline auto make_context (boost::capy::executor_ref exec, Args &&...args) -> ev::context
193 return make_context<HandlerTy, detail::as_exception_t, Args...>(
194 exec, std::pmr::get_default_resource(),
as_exception(), std::forward<Args>(args)...);
209template <ev::detail::EventHandler HandlerTy, ::co_usb::detail::ErrorProtocol<ev::context> ErrorTy,
211inline auto make_context_with_options (boost::capy::executor_ref exec,
212 std::span<const libusb_init_option> options,
213 std::pmr::memory_resource *memres, ErrorTy &&errp,
214 Args &&...args) -> ev::context
216 boost::capy::execution_context &exec_ctx = exec.context();
218 auto &srv = exec_ctx.use_service<ev::detail::handler_service>();
219 std::error_code ec = srv.init_context(options);
222 return errp.template with_error<ev::context>(ec);
224 srv.emplace_handler<HandlerTy>(std::forward<Args>(args)..., memres);
242template <ev::detail::EventHandler HandlerTy,
typename... Args>
243inline auto make_context_with_options (boost::capy::executor_ref exec,
244 std::span<const libusb_init_option> options,
245 std::pmr::memory_resource *memres, Args &&...args)
248 return make_context_with_options<HandlerTy, detail::as_exception_t, Args...>(
249 exec, options, memres,
as_exception(), std::forward<Args>(args)...);
265template <ev::detail::EventHandler HandlerTy, ::co_usb::detail::ErrorProtocol<ev::context> ErrorTy,
267inline auto make_context_with_options (boost::capy::executor_ref exec,
268 std::span<const libusb_init_option> options, ErrorTy &&errp,
269 Args &&...args) -> ev::context
271 return make_context_with_options<HandlerTy, ErrorTy, Args...>(
272 exec, options, std::pmr::get_default_resource(), std::forward<ErrorTy>(errp),
273 std::forward<Args>(args)...);
276template <ev::detail::EventHandler HandlerTy,
typename... Args>
291inline auto make_context_with_options (boost::capy::executor_ref exec,
292 std::span<const libusb_init_option> options, Args &&...args)
295 return make_context_with_options<HandlerTy, detail::as_exception_t, Args...>(
296 exec, options, std::pmr::get_default_resource(),
as_exception(),
297 std::forward<Args>(args)...);
Utilities for creating error protocols.
Capy execution_context service wrapping a libusb event handler.
Definition flag_type.hpp:6
auto raw_context(::co_usb::ev::detail::handler_service *srv)
Proxy accessor to context ctor.
Definition context.hpp:101
Definition any_event_handler.hpp:15
Definition flag_type.hpp:6
constexpr auto as_exception() noexcept -> detail::as_exception_t
Definition error_protocol.hpp:13
A co_usb context referencing event handler service.
Definition context.hpp:62
auto handler() -> event_handler_ref
Definition context.hpp:73
auto request_stop()
Definition context.hpp:68
auto get_token() const noexcept
Definition context.hpp:63
auto usb_context() -> libusb_context *
Definition context.hpp:78
Execution context service that owns a libusb context and an event handler.
Definition handler_service.hpp:74
auto get_token() const noexcept -> std::stop_token
Get the stop token used for coordinating shutdown.
Definition handler_service.hpp:180
auto handler() -> event_handler_ref
Get a reference to the stored event handler.
Definition handler_service.hpp:201
auto usb_context() -> libusb_context *
Access the underlying libusb context.
Definition handler_service.hpp:230
auto request_stop()
Request stop for the event handler.
Definition handler_service.hpp:191
Type-erased reference to any event handler.
Definition event_handler_ref.hpp:34