-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinydb_pubsub.h
61 lines (46 loc) · 1.1 KB
/
tinydb_pubsub.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __TINY_DB_PUBSUB
#define __TINY_DB_PUBSUB
#include "tinydb_thread_pool.h"
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
typedef struct Subscriber
{
int32_t socket_fd;
struct Subscriber* next;
} Subscriber;
typedef struct Channel
{
char* name;
Subscriber* subscribers;
struct Channel* next;
} Channel;
typedef struct PubSubSystem
{
Channel* channels;
pthread_mutex_t lock;
} PubSubSystem;
typedef struct
{
int32_t socket_fd;
char* message;
} SendMessageArgs;
PubSubSystem*
Create_PubSub_System();
void
Subscribe(PubSubSystem* system, const char* channel_name, int32_t socket_fd);
void
Unsubscribe(PubSubSystem* system, const char* channel_name, int32_t socket_fd);
void
Unsubscribe_All(PubSubSystem* system, int32_t socket_fd);
Channel*
Find_Channel(PubSubSystem* system, const char* channel_name);
void
Remove_Empty_Channel(PubSubSystem* system, const char* channel_name);
void
Publish(PubSubSystem* system, const char* channel_name, const char* message);
void
Send_Message(void* socket_desc);
void
Destroy_PubSub_System(PubSubSystem* system);
#endif // __TINY_DB_PUBSUB