|
Sturk 1.1.0
Publish-subscribe C implementation.
|
Message broker. More...
#include <stdarg.h>#include <stddef.h>

Go to the source code of this file.
Data Structures | |
| struct | StMessageVt |
| Vtable for message construction. More... | |
Typedefs | |
| typedef struct StBroker | StBroker |
| The message broker. | |
| typedef struct StSubscriber | StSubscriber |
| The subscriber. | |
| typedef struct StChannel | StChannel |
| The channel for messages. | |
Functions | |
| void | st_publish (StChannel *ch,...) |
| Broadcast the message. | |
| void | st_subscribe (StSubscriber *sber, const char *topic) |
| Subscribe to a topic. | |
| StBroker * | st_broker_create (const struct StMessageVt *vp) |
| Create the message broker. | |
| void | st_broker_destroy (StBroker *broker) |
| Destroy the message broker. | |
| StChannel * | st_broker_search (StBroker *broker, const char *topic) |
| Find the channel that is assigned to the given topic. | |
| const char * | st_channel_gettopic (const StChannel *ch) |
| Get the topic for the given channel. | |
| StSubscriber * | st_subscriber_create (StBroker *broker) |
| Create the subscriber. | |
| void | st_subscriber_destroy (StSubscriber *sber) |
| Destroy the subscriber. | |
| void * | st_subscriber_await (StSubscriber *sber) |
| Wait for the messages that are wanted by the subscriber. | |
| void * | st_subscriber_poll (StSubscriber *sber) |
| Poll for the messages that are wanted by the subscriber. | |
| void | st_subscriber_unload (StSubscriber *sber) |
| Inform the broker that the message can be released for the given subscriber. | |
Message broker.
This header file provides data types and functions that implement the publish-subscribe messaging pattern.
The message broker.
The broker holds the list of all subscribers (StSubscriber) in usage and a dictionary of channels (StChannel). All the messaging done through channels created by the same broker will also use the same API for message construction (StMessageVt).
The channel for messages.
| StBroker * st_broker_create | ( | const struct StMessageVt * | vp | ) |
Create the message broker.
| [in] | vp | The pointer to the vtable for the StMessage. |
The chosen vtable will influence the behaviour of the functions that are responsible for constructing and receiving the messages:
| void st_broker_destroy | ( | StBroker * | broker | ) |
Destroy the message broker.
| [in] | broker | The pointer to the broker. |
Find the channel that is assigned to the given topic.
| [in,out] | broker | The message broker. |
| [in] | topic | The topic. It is also used as the key for the channel's dictionary. |
This function also creates the channel if none is found.
| const char * st_channel_gettopic | ( | const StChannel * | ch | ) |
Get the topic for the given channel.
| [in] | ch | The channel. |
| void st_publish | ( | StChannel * | ch, |
| ... | |||
| ) |
Broadcast the message.
| [in,out] | ch | The channel to which the message is sent. |
| [in] | ... | The list of arguments passed to the StMessageVt::ctor. |
| void st_subscribe | ( | StSubscriber * | sber, |
| const char * | topic | ||
| ) |
Subscribe to a topic.
| [in,out] | sber | The subscriber that expresses the interest in the topic. |
| [in] | topic | The topic to which the subscription will be made. |
| StMessage * st_subscriber_await | ( | StSubscriber * | sber | ) |
Wait for the messages that are wanted by the subscriber.
| [in,out] | sber | The pointer to the subscriber. |
This function will return the message immediately, if there are any messages in the subscriber's queue. If the subscriber's queue is empty, with multithreading enabled, this will block the thread that has called this function until some other thread publishes to topic that the given subscriber is interested in. With a single thread application, the blocking is not supported.
| StSubscriber * st_subscriber_create | ( | StBroker * | broker | ) |
Create the subscriber.
| [in,out] | broker | The message broker. |
| void st_subscriber_destroy | ( | StSubscriber * | sber | ) |
Destroy the subscriber.
| [in,out] | sber | The pointer to the subscriber. |
| void * st_subscriber_poll | ( | StSubscriber * | sber | ) |
Poll for the messages that are wanted by the subscriber.
| [in,out] | sber | The pointer to the subscriber. |
This function will return the message, if there are any messages in the subscriber's queue. If the subscriber's queue is empty, it will return NULL.
| void st_subscriber_unload | ( | StSubscriber * | sber | ) |
Inform the broker that the message can be released for the given subscriber.
| [in,out] | sber | The pointer to the subscriber. |
Release the last message received by the subscriber - decrement the subscribers counter for the message. When the counter hits 0, the message is returned to the memory pool.