File syn_pubsub.h¶
FileList > src > syntropic > util > syn_pubsub.h
Go to the source code of this file
Synchronous publish/subscribe event broker. More...
#include "../common/syn_defs.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_PubSubBroker PubSub broker instance — subscription array + count. |
| struct | SYN_PubSubSub A single subscription record. |
Public Types¶
| Type | Name |
|---|---|
| typedef void(* | SYN_PubSubHandler Event callback function signature. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_pubsub_init (SYN_PubSubBroker * broker, SYN_PubSubSub * sub_array, size_t capacity) Initialize a pubsub broker. |
| void | syn_pubsub_publish (SYN_PubSubBroker * broker, uint16_t topic, const void * payload, size_t len) Publish an event to all subscribers of a topic. |
| bool | syn_pubsub_subscribe (SYN_PubSubBroker * broker, uint16_t topic, SYN_PubSubHandler handler, void * ctx) Subscribe to a topic. |
| bool | syn_pubsub_unsubscribe (SYN_PubSubBroker * broker, uint16_t topic, SYN_PubSubHandler handler) Unsubscribe from a topic. |
Public Static Functions¶
| Type | Name |
|---|---|
| size_t | syn_pubsub_count (const SYN_PubSubBroker * broker) Get current number of active subscriptions. |
| void | syn_pubsub_reset (SYN_PubSubBroker * broker) Reset the broker, removing all subscriptions. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_PUBSUB_TOPIC_ALL 0xFFFF |
Detailed Description¶
Provides a decoupled event system. Modules can subscribe to specific topics and receive callbacks when events are published.
Uses a static caller-provided array for storing subscriptions (zero allocation).
Public Types Documentation¶
typedef SYN_PubSubHandler¶
Event callback function signature.
Parameters:
topicThe topic ID that triggered this callback.payloadPointer to the event data (can be NULL).lenSize of the event data in bytes (can be 0).ctxUser context pointer provided at subscription.
Public Functions Documentation¶
function syn_pubsub_init¶
Initialize a pubsub broker.
Parameters:
brokerPointer to broker instance.sub_arrayPointer to an array of SYN_PubSubSub structures.capacityNumber of elements in sub_array.
function syn_pubsub_publish¶
Publish an event to all subscribers of a topic.
void syn_pubsub_publish (
SYN_PubSubBroker * broker,
uint16_t topic,
const void * payload,
size_t len
)
Parameters:
brokerPointer to broker instance.topicTopic ID of the event.payloadPointer to event data.lenSize of event data in bytes.
function syn_pubsub_subscribe¶
Subscribe to a topic.
bool syn_pubsub_subscribe (
SYN_PubSubBroker * broker,
uint16_t topic,
SYN_PubSubHandler handler,
void * ctx
)
Parameters:
brokerPointer to broker instance.topicTopic ID to listen for, or SYN_PUBSUB_TOPIC_ALL.handlerCallback function to invoke.ctxOptional user context pointer.
Returns:
true if subscribed successfully, false if broker is full.
function syn_pubsub_unsubscribe¶
Unsubscribe from a topic.
bool syn_pubsub_unsubscribe (
SYN_PubSubBroker * broker,
uint16_t topic,
SYN_PubSubHandler handler
)
Parameters:
brokerPointer to broker instance.topicTopic ID to unsubscribe from.handlerThe specific callback function to remove.
Returns:
true if removed, false if not found.
Public Static Functions Documentation¶
function syn_pubsub_count¶
Get current number of active subscriptions.
Parameters:
brokerBroker.
Returns:
Subscription count.
function syn_pubsub_reset¶
Reset the broker, removing all subscriptions.
Parameters:
brokerBroker.
Macro Definition Documentation¶
define SYN_PUBSUB_TOPIC_ALL¶
Special topic ID used to subscribe to ALL events.
The documentation for this class was generated from the following file src/syntropic/util/syn_pubsub.h