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/pubsub/app/test-subscribers.c

82 lines
1.7 KiB
C

#include "../lib/pubsubd.h"
#include <stdlib.h>
#include <string.h>
void
ohshit(int rvalue, const char* str) {
fprintf(stderr, "%s\n", str);
exit(rvalue);
}
void usage (char **argv) {
fprintf (stderr, "usage: %s path\n", argv[0]);
exit (1);
}
// // element of the list
// // channel : chan name + chan name length + a list of applications
// struct channel {
// char *chan;
// size_t chanlen;
// struct app_list_head *alh;
// LIST_ENTRY(channel) entries;
// };
// struct process {
// pid_t pid;
// unsigned int version;
// unsigned int index;
// char path_in [PATH_MAX];
// char path_out [PATH_MAX];
// };
void fill_process (struct process *p)
{
p->pid = 10;
p->version = 1;
p->index = 1;
}
// enum app_list_elm_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
// struct app_list_elm {
// struct process *p;
// enum app_list_elm_action action;
// LIST_ENTRY(app_list_elm) entries;
// };
void fill_app_list_elm (struct app_list_elm *ale)
{
ale->p = malloc (sizeof (struct process));
fill_process (ale->p);
ale->action = PUBSUB_PUB;
}
int main(void)
{
struct app_list_head alh;
memset (&alh, 0, sizeof (struct app_list_head));
struct app_list_elm ale;
memset (&ale, 0, sizeof (struct app_list_elm));
fill_app_list_elm (&ale);
struct app_list_head *chans = &alh;
pubsubd_subscriber_init (&chans);
printf ("1 chan, 0 process\n");
pubsubd_subscriber_print (chans);
pubsubd_subscriber_add (&alh, &ale);
printf ("1 chan, 1 process\n");
pubsubd_subscriber_print (chans);
pubsubd_subscriber_del_all (&alh);
printf ("0 chan, 0 process\n");
pubsubd_subscriber_print (chans);
free (ale.p);
return EXIT_SUCCESS;
}