File syn_pubsub.c¶
FileList > src > syntropic > util > syn_pubsub.c
Go to the source code of this file
#include "syn_assert.h"#include "syn_pubsub.h"
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 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.
The documentation for this class was generated from the following file src/syntropic/util/syn_pubsub.c