conduit 0.6.0
Modern C++23 header-only event-dispatching / event-transport library
Loading...
Searching...
No Matches
transport.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8#include <commons/prioritized.hpp>
9
10#include <cstdint>
11#include <functional>
12#include <utility>
13
14namespace conduit {
15
16class Bus;
17
21enum class TransportScope : std::uint8_t { Local, Remote };
22
28using InboundSink = std::function<void(const EventEnvelopeView&)>;
29
30class Transport : public comms::Prioritized {
31public:
32 Transport() = default;
33 Transport(const Transport&) = delete;
34 Transport(Transport&&) noexcept = default;
35 Transport& operator=(const Transport&) = delete;
36 Transport& operator=(Transport&&) noexcept = default;
37 ~Transport() override = default;
38
39 [[nodiscard]] virtual TransportScope scope() const noexcept = 0;
40
45 virtual void attach(Bus& bus);
46
50 virtual void attach_with_sink(Bus& bus, InboundSink sink) {
51 bus_ = &bus;
52 inbound_sink_ = std::move(sink);
53 }
54
55 virtual void detach() noexcept {}
56 virtual void dispatch(const EventEnvelopeView&) = 0;
57 virtual void flush() {}
58
59protected:
62 void deliver_inbound(const EventEnvelopeView& v) const {
63 if (inbound_sink_) {
64 inbound_sink_(v);
65 }
66 }
67
68 [[nodiscard]] Bus* bus() const noexcept {
69 return bus_;
70 }
71
72private:
73 Bus* bus_ = nullptr;
74 InboundSink inbound_sink_;
75};
76
77} // namespace conduit
Definition bus.hpp:58
Polymorphic envelope cell.
Definition envelope.hpp:62
Definition transport.hpp:30
virtual void dispatch(const EventEnvelopeView &)=0
Bus * bus() const noexcept
Definition transport.hpp:68
virtual void flush()
Definition transport.hpp:57
virtual TransportScope scope() const noexcept=0
virtual void detach() noexcept
Definition transport.hpp:55
Transport(const Transport &)=delete
virtual void attach(Bus &bus)
Attach to a bus.
Definition bus.hpp:519
virtual void attach_with_sink(Bus &bus, InboundSink sink)
Attach to a bus using a caller-supplied inbound sink.
Definition transport.hpp:50
Transport(Transport &&) noexcept=default
void deliver_inbound(const EventEnvelopeView &v) const
Subclasses call this for inbound delivery instead of touching the bus directly.
Definition transport.hpp:62
EventEnvelope — a parcel cell carrying conduit's envelope metadata plus a polymorphic payload cell.
Definition builder.hpp:22
std::function< void(const EventEnvelopeView &)> InboundSink
Callable installed on a Transport at attach time that receives inbound envelopes the transport pulled...
Definition transport.hpp:28
TransportScope
Distinguishes in-process transports from off-machine ones.
Definition transport.hpp:21