OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
event_handler.hpp
Go to the documentation of this file.
1// Copyright (c) 2022 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_RPC_EVENT_HANDLER_H_
7#define OPENCBDC_TX_SRC_RPC_EVENT_HANDLER_H_
8
9#include <cstdint>
10#include <optional>
11#include <vector>
12
13namespace cbdc::rpc {
17 public:
19 enum class event_type {
21 remove,
23 in,
25 out,
27 inout,
28 };
29
30 virtual ~event_handler() = default;
31
34 using event = std::pair<int, bool>;
35
38 virtual auto init() -> bool = 0;
39
42 virtual void set_timeout(long timeout_ms) = 0;
43
47 virtual void register_fd(int fd, event_type et) = 0;
48
53 virtual auto poll() -> std::optional<std::vector<event>> = 0;
54 };
55}
56
57#endif
Event handler interface for tracking events on non-blocking file descriptors.
virtual ~event_handler()=default
virtual auto poll() -> std::optional< std::vector< event > >=0
Wait for events on tracked file descriptors.
event_type
Type of event to register interest in.
@ remove
Remove file descriptor.
@ inout
Read and write events.
virtual void set_timeout(long timeout_ms)=0
Sets the timeout for poll to return even if there are no events.
virtual auto init() -> bool=0
Initializes the event handler.
std::pair< int, bool > event
Type alias for an event.
virtual void register_fd(int fd, event_type et)=0
Registers a file descriptor to track for events.