Skip to content

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.

void syn_pubsub_init (
    SYN_PubSubBroker * broker,
    SYN_PubSubSub * sub_array,
    size_t capacity
) 

Parameters:

  • broker Pointer to broker instance.
  • sub_array Pointer to an array of SYN_PubSubSub structures.
  • capacity Number 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:

  • broker Pointer to broker instance.
  • topic Topic ID of the event.
  • payload Pointer to event data.
  • len Size 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:

  • broker Pointer to broker instance.
  • topic Topic ID to listen for, or SYN_PUBSUB_TOPIC_ALL.
  • handler Callback function to invoke.
  • ctx Optional 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:

  • broker Pointer to broker instance.
  • topic Topic ID to unsubscribe from.
  • handler The 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