|
oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
|
RAII wrapper around an oveRTOS MQTT client handle. More...
#include <net_mqtt.hpp>
Public Types | |
| using | MsgFn = void(*)(std::string_view topic, std::string_view payload) |
| Stateless message callback type. | |
Public Member Functions | |
| Client () | |
| Constructs and initialises the MQTT client. | |
| ~Client () noexcept | |
| Destroys the MQTT client, releasing the underlying resource. | |
| Client (const Client &)=delete | |
| Client & | operator= (const Client &)=delete |
| Client (Client &&)=delete | |
| Client & | operator= (Client &&)=delete |
| Result< void > | connect (const Config &cfg, MsgFn on_message=nullptr) noexcept |
| Connects to an MQTT broker. | |
| void | disconnect () |
| Disconnects from the MQTT broker. | |
| Result< void > | publish (const char *topic, const void *payload, size_t len, Qos qos=Qos::AtMostOnce) noexcept |
| Publishes a message (raw pointer + length). | |
| Result< void > | publish (const char *topic, std::string_view payload, Qos qos=Qos::AtMostOnce) noexcept |
| Publishes a message from a string_view. | |
| Result< void > | subscribe (const char *topic, Qos qos=Qos::AtMostOnce) noexcept |
| Subscribes to a topic. | |
| Result< void > | unsubscribe (const char *topic) noexcept |
| Unsubscribes from a topic. | |
| Result< void > | loop (std::chrono::nanoseconds timeout=std::chrono::milliseconds{500}) noexcept |
| Processes incoming packets and sends keep-alive pings. | |
| bool | valid () const |
Returns true if the underlying client handle is non-null. | |
| ove_mqtt_client_t | handle () const |
| Returns the raw oveRTOS MQTT client handle. | |
RAII wrapper around an oveRTOS MQTT client handle.
Constructs the underlying MQTT client on creation and destroys it on destruction. The message callback uses a static trampoline so that no heap-allocated closure is required; this makes the Client inherently per-instance and therefore non-movable even without CONFIG_OVE_ZERO_HEAP.
| using ove::mqtt::Client::MsgFn = void (*)(std::string_view topic, std::string_view payload) |
Stateless message callback type.
Must be a plain function pointer (or a stateless lambda convertible to one). Receives the topic and payload as std::string_view.
|
inline |
Constructs and initialises the MQTT client.
Calls ove_mqtt_client_init (zero-heap) or ove_mqtt_client_create (heap). Asserts at startup if initialisation fails.
|
inlinenoexcept |
Destroys the MQTT client, releasing the underlying resource.
If the handle is null the destructor is a no-op.
|
inlinenoexcept |
Connects to an MQTT broker.
Optionally registers a stateless message callback that is invoked for every incoming PUBLISH. The callback is stored in a static variable and dispatched via an internal trampoline.
| [in] | cfg | Connection configuration. |
| [in] | on_message | Message callback (nullptr to disable). |
Result<void> on success; unexpected Error on failure.
|
inlinenoexcept |
Publishes a message (raw pointer + length).
| [in] | topic | Topic string (NUL-terminated). |
| [in] | payload | Message payload. |
| [in] | len | Payload length in bytes. |
| [in] | qos | QoS level (default: AtMostOnce). |
Result<void> on success; unexpected Error on failure.
|
inlinenoexcept |
Publishes a message from a string_view.
| [in] | topic | Topic string (NUL-terminated). |
| [in] | payload | Message payload as a string_view. |
| [in] | qos | QoS level (default: AtMostOnce). |
|
inlinenoexcept |
Subscribes to a topic.
| [in] | topic | Topic filter (NUL-terminated). |
| [in] | qos | Maximum QoS level (default: AtMostOnce). |
Result<void> on success; unexpected Error on failure.
|
inlinenoexcept |
Unsubscribes from a topic.
| [in] | topic | Topic filter (NUL-terminated). |
Result<void> on success; unexpected Error on failure.
|
inlinenoexcept |
Processes incoming packets and sends keep-alive pings.
Must be called periodically (typically in a loop or timer).
| [in] | timeout | Maximum time to wait for incoming data (any std::chrono::duration unit; defaults to 500 ms). |
Result<void> on success; unexpected Error on failure.
|
inline |
Returns true if the underlying client handle is non-null.
true when the client was successfully initialised.
|
inline |
Returns the raw oveRTOS MQTT client handle.
ove_mqtt_client_t handle.