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
6#include <conduit/bus.hpp>
11#include <conduit/transport.hpp>
12
13#include <chrono>
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <string>
18
19namespace conduit::mqtt {
20
23public:
24 using conduit::TransportError::TransportError;
25};
26
28enum class Format : std::uint8_t { Json, Cbor };
29
30struct TlsConfig {
31 std::string ca_file;
32 std::optional<std::string> cert_file;
33 std::optional<std::string> key_file;
34 bool verify_peer = true;
35};
36
37struct Config {
38 std::string url; // "tcp://host:1883" or "ssl://host:8883"
39 std::string client_id; // empty -> generated from ULID
40 std::optional<std::string> username;
41 std::optional<std::string> password;
42 std::optional<TlsConfig> tls;
43 int qos = 1; // 0/1/2
44 bool clean_session = true;
45 std::chrono::seconds keep_alive{60};
46 std::chrono::seconds connect_timeout{10};
47
53 std::string topic = "conduit/envelope";
54
57};
58
64public:
68 explicit Transport(Config config, std::shared_ptr<EventRegistry> registry = {});
69
70 Transport(const Transport&) = delete;
71 Transport& operator=(const Transport&) = delete;
72 Transport(Transport&&) = delete;
74
75 ~Transport() override;
76
77 [[nodiscard]] TransportScope scope() const noexcept override {
79 }
80
81 // Overrides `attach_with_sink`; the base `attach(Bus&)` default builds a
82 // bus-default sink and delegates here, so wrapping with FilteredTransport
83 // (which calls `attach_with_sink` directly) works without any extra glue.
84 void attach_with_sink(Bus& bus, InboundSink sink) override;
85 void detach() noexcept override;
86
87 void dispatch(const EventEnvelopeView& v) override;
88 void flush() override;
89
90 [[nodiscard]] bool is_connected() const noexcept;
91
92private:
93 struct Impl;
94 std::unique_ptr<Impl> impl_;
95};
96
97} // namespace conduit::mqtt
Bus — owns transports, middleware, listeners; dispatches envelopes.
Definition bus.hpp:58
Polymorphic envelope cell.
Definition envelope.hpp:62
Operational/runtime failure inside a transport adapter (connect, subscribe, publish,...
Definition exception.hpp:48
Definition transport.hpp:30
Bus * bus() const noexcept
Definition transport.hpp:68
Operational/runtime failure inside the MQTT transport adapter.
Definition transport.hpp:22
MQTT pipe — one instance binds to a single MQTT topic and carries traffic in both directions: outboun...
Definition transport.hpp:63
void detach() noexcept override
TransportScope scope() const noexcept override
Definition transport.hpp:77
void dispatch(const EventEnvelopeView &v) override
Transport(Config config, std::shared_ptr< EventRegistry > registry={})
Construct an MQTT pipe.
Transport & operator=(const Transport &)=delete
Transport & operator=(Transport &&)=delete
void flush() override
bool is_connected() const noexcept
Transport(Transport &&)=delete
Transport(const Transport &)=delete
void attach_with_sink(Bus &bus, InboundSink sink) override
Attach to a bus using a caller-supplied inbound sink.
EventEnvelope — a parcel cell carrying conduit's envelope metadata plus a polymorphic payload cell.
Root exception hierarchy for the conduit library.
Transport interface and the local/remote scope enum used for flag-based filtering.
Listener / Subscription / Subscriber primitives.
Definition transport.hpp:19
Format
Wire format used for encoded envelopes.
Definition transport.hpp:28
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
Thin EventRegistry wrapper around parcel::ParcelRegistry, plus envelope encode/decode helpers for JSO...
Definition transport.hpp:37
std::string topic
Topic this transport binds to.
Definition transport.hpp:53
std::string client_id
Definition transport.hpp:39
Format format
Wire format used for both outbound publishes and inbound decoding.
Definition transport.hpp:56
std::optional< std::string > password
Definition transport.hpp:41
std::optional< TlsConfig > tls
Definition transport.hpp:42
std::string url
Definition transport.hpp:38
std::chrono::seconds keep_alive
Definition transport.hpp:45
std::optional< std::string > username
Definition transport.hpp:40
bool clean_session
Definition transport.hpp:44
std::chrono::seconds connect_timeout
Definition transport.hpp:46
int qos
Definition transport.hpp:43
Definition transport.hpp:30
std::optional< std::string > key_file
Definition transport.hpp:33
bool verify_peer
Definition transport.hpp:34
std::optional< std::string > cert_file
Definition transport.hpp:32
std::string ca_file
Definition transport.hpp:31