|
| | handler_service (boost::capy::execution_context &exec_ctx) |
| | Construct the handler service.
|
| |
| | ~handler_service () override |
| | Destructor that stops the handler and releases the libusb context.
|
| |
| auto | init_context () noexcept -> std::error_code |
| | Initializes libusb context without options.
|
| |
| auto | init_context (std::span< const libusb_init_option > options) noexcept -> std::error_code |
| | Initializes libusb context with given options.
|
| |
template<detail::EventHandler HandlerTy, typename... Args>
requires (!std::same_as<HandlerTy, any_event_handler> && !std::same_as<HandlerTy, event_handler_ref> && std::constructible_from<HandlerTy, Args...>) |
| auto | emplace_handler (Args &&...args, std::pmr::memory_resource *memres=std::pmr::get_default_resource()) -> event_handler_ref |
| | Emplace a concrete event handler and return a reference wrapper.
|
| |
| auto | get_token () const noexcept -> std::stop_token |
| | Get the stop token used for coordinating shutdown.
|
| |
| auto | request_stop () |
| | Request stop for the event handler.
|
| |
| auto | handler () -> event_handler_ref |
| | Get a reference to the stored event handler.
|
| |
| auto | start () -> bool |
| | Start the stored event handler.
|
| |
| auto | shutdown () -> void override |
| | Shutdown hook invoked by the base service.
|
| |
| auto | usb_context () -> libusb_context * |
| | Access the underlying libusb context.
|
| |
Execution context service that owns a libusb context and an event handler.
A service to run an co_usb::ev::details::EventHandler responsible for storing libusb context, the handler itself and the stop source for the service.
- Why not an executor?
An executor at its essence is a driver for executing ready coroutines. A libusb event handler is just about handling libusb-specific events not necesserily bound to a coroutine. Making the event handler logic bound to a specific library-provided executor would lock the executor choice on a single one which may not be the most effecient one. A separate service on the other hand provides flexibility in executor choice and does not limit the user in the choice of a specific handler.
- Creating the service
- Unlike in
usb_asio library, the service will not be automatically created with the creation of any object that may require it. This is because co_usb does not have a default event handler, on purpose. Choice of a handler is fully placed on the user of the library via co_usb::ev::context and co_usb::make_context.
int main (int argc, char **argv)
{
boost::capy::thread_pool;
}
A co_usb context referencing event handler service.
Definition context.hpp:62
Attempts to use any of co_usb features that require a handler or a context will result in immedeate std::runtime_error exception.
- Switching the event handler
Switching the handler is allowed via emplace_handler method and is well-defined. Doing so will request stop for the currently active handler and block until it is stopped. The stop source will be reset and the new handler will not start until start is called again.