Cantil 1.0.0
Scalable publish-subscribe implementation.
Loading...
Searching...
No Matches
broker.h
Go to the documentation of this file.
1/*
2BSD 3-Clause License
3
4Copyright (c) 2025, Szymon Turno
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
91. Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
41#ifndef CN_BROKER_H
42#define CN_BROKER_H
43
44#include <stdarg.h>
45#include <stddef.h>
46
80typedef char CnLoad;
81
87struct CnLoadVt {
98 size_t (*size)(void);
99
113 void (*ctor)(CnLoad*, va_list);
114
122 void (*dtor)(CnLoad*);
123};
124
135typedef struct CnBroker CnBroker;
136
143
153typedef struct CnChannel CnChannel;
154
167void cn_publish(CnChannel* ch, ...);
168
177void cn_subscribe(CnSubscriber* sber, const char* topic);
178
195
204
217CnChannel* cn_broker_search(CnBroker* broker, const char* topic);
218
228const char* cn_channel_gettopic(const CnChannel* ch);
229
240
249
266
280
297
308
309#endif /* CN_BROKER_H */
struct CnSubscriber CnSubscriber
The subscriber.
Definition broker.h:142
CnLoad * cn_subscriber_await(CnSubscriber *sber)
Wait for the messages that are wanted by the subscriber.
void cn_subscribe(CnSubscriber *sber, const char *topic)
Subscribe to a topic.
CnChannel * cn_broker_search(CnBroker *broker, const char *topic)
Find the channel that is assigned to the given topic.
void cn_subscriber_unload(CnSubscriber *sber)
Inform the broker that the message can be released for the given subscriber.
void cn_broker_destroy(CnBroker *broker)
Destroy the message broker.
CnBroker * cn_broker_create(const struct CnLoadVt *vp)
Create the message broker.
const char * cn_channel_gettopic(const CnChannel *ch)
Get the topic for the given channel.
void cn_subscriber_destroy(CnSubscriber *sber)
Destroy the subscriber.
CnChannel * cn_load_getchan(const CnLoad *load)
Get the source channel of the message.
struct CnBroker CnBroker
The message broker.
Definition broker.h:135
struct CnChannel CnChannel
The channel for messages.
Definition broker.h:153
CnLoad * cn_subscriber_poll(CnSubscriber *sber)
Poll for the messages that are wanted by the subscriber.
char CnLoad
Opaque data type that represents the message load.
Definition broker.h:80
void cn_publish(CnChannel *ch,...)
Broadcast the message.
CnSubscriber * cn_subscriber_create(CnBroker *broker)
Create the subscriber.
Vtable for message construction.
Definition broker.h:87
size_t(* size)(void)
Callback for obtaining the size of the load.
Definition broker.h:98
void(* ctor)(CnLoad *, va_list)
Constructor callback for the message.
Definition broker.h:113
void(* dtor)(CnLoad *)
Destructor callback for the message.
Definition broker.h:122