Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/lib/pubsubd.h

118 lines
4.1 KiB
C
Raw Normal View History

2016-06-05 20:48:13 +02:00
#ifndef __PUBSUBD_H__
#define __PUBSUBD_H__
#include "communication.h"
#include "process.h"
#include "queue.h"
2016-06-08 17:57:05 +02:00
#define PUBSUB_TYPE_DISCONNECT 1 << 0
#define PUBSUB_TYPE_INFO 1 << 1
#define PUBSUB_TYPE_DEBUG 1 << 2
#define PUBSUB_TYPE_MESSAGE 1 << 3
2016-06-05 20:48:13 +02:00
#define PUBSUB_SERVICE_NAME "pubsub"
2016-06-07 11:45:21 +02:00
struct channel;
struct channels;
struct app_list_head;
struct app_list_elm;
struct pubsub_msg;
2016-06-05 20:48:13 +02:00
struct pubsub_msg {
unsigned char *chan;
size_t chanlen;
unsigned char *data;
size_t datalen;
unsigned char type; // message type : alert, notification, …
};
void pubsubd_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *len);
void pubsubd_msg_unserialize (struct pubsub_msg *msg, const char *data, size_t len);
void pubsubd_msg_free (struct pubsub_msg *msg);
2016-06-08 17:57:05 +02:00
void pubsubd_msg_print (const struct pubsub_msg *msg);
2016-06-05 20:48:13 +02:00
// parse pubsubd init msg (sent in TMPDIR/<service>)
//
// line fmt : pid index version action chan
// action : quit | pub | sub
2016-06-07 17:44:18 +02:00
int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
2016-06-08 17:57:05 +02:00
, struct channels *chans, struct channel **c);
2016-06-07 11:45:21 +02:00
int pubsubd_msg_read_cb (FILE *f, char ** buf, size_t * msize);
void pubsubd_msg_send (const struct app_list_head *alh, const struct pubsub_msg *m);
void pubsubd_msg_recv (struct process *p, struct pubsub_msg *m);
2016-06-05 20:48:13 +02:00
2016-06-13 09:47:19 +02:00
void pubsub_disconnect (struct process *p);
2016-06-12 14:41:25 +02:00
void pubsub_msg_send (struct process *p, const struct pubsub_msg *msg);
void pubsub_msg_recv (struct process *p, struct pubsub_msg *msg);
2016-06-05 20:48:13 +02:00
// CHANNEL
// head of the list
LIST_HEAD(channels, channel);
// element of the list
2016-06-07 17:44:18 +02:00
// channel : chan name + chan name length + a list of applications
2016-06-05 20:48:13 +02:00
struct channel {
char *chan;
2016-06-05 20:48:13 +02:00
size_t chanlen;
2016-06-07 17:44:18 +02:00
struct app_list_head *alh;
2016-06-05 20:48:13 +02:00
LIST_ENTRY(channel) entries;
};
2016-06-07 17:44:18 +02:00
// simple channel
2016-09-07 23:46:00 +02:00
int pubsubd_channel_new (struct channel *c, const char *name);
2016-06-05 20:48:13 +02:00
struct channel * pubsubd_channel_copy (struct channel *c);
struct channel * pubsubd_channel_get (struct channels *chans, struct channel *c);
void pubsubd_channel_free (struct channel *c);
int pubsubd_channel_eq (const struct channel *c1, const struct channel *c2);
2016-06-07 17:44:18 +02:00
void pubsubd_channel_print (const struct channel *c);
// list of channels
void pubsubd_channels_init (struct channels *chans);
void pubsubd_channels_print (const struct channels *chans);
struct channel * pubsubd_channels_add (struct channels *chans, struct channel *c);
void pubsubd_channels_del (struct channels *chans, struct channel *c);
void pubsubd_channels_del_all (struct channels *chans);
2016-06-05 20:48:13 +02:00
2016-06-13 09:47:19 +02:00
// remove an app_list_elm from the list (msg type DISCONNECT received)
int pubsubd_channels_del_subscriber (struct channels *chans
, struct channel *c);
struct channel *
pubsubd_channels_search_from_app_list_elm (struct channels *chans
, struct app_list_elm *ale);
2016-06-05 20:48:13 +02:00
// APPLICATION
// head of the list
LIST_HEAD(app_list_head, app_list_elm);
enum app_list_elm_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
2016-06-07 17:44:18 +02:00
2016-06-05 20:48:13 +02:00
// element of the list
struct app_list_elm {
struct process *p;
2016-06-07 17:44:18 +02:00
enum app_list_elm_action action;
2016-06-05 20:48:13 +02:00
LIST_ENTRY(app_list_elm) entries;
};
int
pubsubd_subscriber_eq (const struct app_list_elm *, const struct app_list_elm *);
2016-06-07 17:44:18 +02:00
void pubsubd_subscriber_init (struct app_list_head **chans);
void pubsubd_subscriber_add (struct app_list_head *
2016-06-05 20:48:13 +02:00
, const struct app_list_elm *);
struct app_list_elm * pubsubd_subscriber_get (const struct app_list_head *
, const struct app_list_elm *);
2016-06-13 09:47:19 +02:00
int pubsubd_subscriber_del (struct app_list_head *al, struct app_list_elm *p);
2016-06-07 17:44:18 +02:00
void pubsubd_subscriber_del_all (struct app_list_head *alh);
2016-06-05 20:48:13 +02:00
struct app_list_elm * pubsubd_app_list_elm_copy (const struct app_list_elm *ale);
2016-06-05 20:48:13 +02:00
void pubsubd_app_list_elm_create (struct app_list_elm *ale, struct process *p);
void pubsubd_app_list_elm_free (struct app_list_elm *todel);
2016-06-08 17:57:05 +02:00
void pubsub_connection (struct service *srv, struct process *p, enum app_list_elm_action action, const char *channame);
2016-06-13 09:47:19 +02:00
void pubsubd_quit (struct service *srv);
2016-06-08 17:57:05 +02:00
2016-06-05 20:48:13 +02:00
#endif