pubsub wip
This commit is contained in:
parent
99cd9b22de
commit
498b4857e2
59
Makefile
59
Makefile
@ -15,7 +15,7 @@ LDFLAGS :=
|
||||
|
||||
Q := @
|
||||
|
||||
all: libposj init-connection open-read-close-fifo open-write-close-fifo service-test
|
||||
all: libposj init-connection open-read-close-fifo open-write-close-fifo service-test pubsub/pubsubd
|
||||
|
||||
libposj: libposj.so libposj.a
|
||||
@:
|
||||
@ -93,6 +93,23 @@ service-test.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/service-test[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/service-test'
|
||||
|
||||
pubsub/pubsubd: pubsub/list.o pubsub/pubsubd.o
|
||||
@echo '[01;32m [LD] [01;37mpubsub/pubsubd[00m'
|
||||
$(Q)$(CC) -o pubsub/pubsubd $(LDFLAGS) pubsub/list.o pubsub/pubsubd.o libposj.a
|
||||
|
||||
pubsub/pubsubd.install: pubsub/pubsubd
|
||||
@echo '[01;31m [IN] [01;37m$(BINDIR)/pubsubd[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)'
|
||||
$(Q)install -m0755 pubsub/pubsubd $(DESTDIR)$(BINDIR)/pubsubd
|
||||
|
||||
pubsub/pubsubd.clean: pubsub/list.o.clean pubsub/pubsubd.o.clean
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsubd[00m'
|
||||
$(Q)rm -f pubsub/pubsubd
|
||||
|
||||
pubsub/pubsubd.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/pubsubd[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/pubsubd'
|
||||
|
||||
libposj.so: lib/communication.o
|
||||
@echo '[01;32m [LD] [01;37mlibposj.so[00m'
|
||||
$(Q)$(CC) -o libposj.so -shared $(LDFLAGS) lib/communication.o
|
||||
@ -199,6 +216,30 @@ service-test.o.clean:
|
||||
|
||||
service-test.o.uninstall:
|
||||
|
||||
pubsub/list.o: pubsub/list.c pubsub/list.h
|
||||
@echo '[01;34m [CC] [01;37mpubsub/list.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -I lib -c pubsub/list.c -I lib -o pubsub/list.o
|
||||
|
||||
pubsub/list.o.install:
|
||||
|
||||
pubsub/list.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mpubsub/list.o[00m'
|
||||
$(Q)rm -f pubsub/list.o
|
||||
|
||||
pubsub/list.o.uninstall:
|
||||
|
||||
pubsub/pubsubd.o: pubsub/pubsubd.c
|
||||
@echo '[01;34m [CC] [01;37mpubsub/pubsubd.o[00m'
|
||||
$(Q)$(CC) $(CFLAGS) -I lib -c pubsub/pubsubd.c -I lib -o pubsub/pubsubd.o
|
||||
|
||||
pubsub/pubsubd.o.install:
|
||||
|
||||
pubsub/pubsubd.o.clean:
|
||||
@echo '[01;37m [RM] [01;37mpubsub/pubsubd.o[00m'
|
||||
$(Q)rm -f pubsub/pubsubd.o
|
||||
|
||||
pubsub/pubsubd.o.uninstall:
|
||||
|
||||
$(DESTDIR)$(PREFIX):
|
||||
@echo '[01;35m [DIR] [01;37m$(PREFIX)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(PREFIX)
|
||||
@ -214,12 +255,12 @@ $(DESTDIR)$(SHAREDIR):
|
||||
$(DESTDIR)$(INCLUDEDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(INCLUDEDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
install: subdirs.install libposj.install init-connection.install open-read-close-fifo.install open-write-close-fifo.install service-test.install libposj.so.install libposj.a.install init-connection.o.install lib/communication.o.install open-read-close-fifo.o.install lib/communication.o.install open-write-close-fifo.o.install lib/communication.o.install service-test.o.install lib/communication.o.install lib/communication.o.install lib/communication.o.install
|
||||
install: subdirs.install libposj.install init-connection.install open-read-close-fifo.install open-write-close-fifo.install service-test.install pubsub/pubsubd.install libposj.so.install libposj.a.install init-connection.o.install lib/communication.o.install open-read-close-fifo.o.install lib/communication.o.install open-write-close-fifo.o.install lib/communication.o.install service-test.o.install lib/communication.o.install pubsub/list.o.install pubsub/pubsubd.o.install lib/communication.o.install lib/communication.o.install
|
||||
@:
|
||||
|
||||
subdirs.install:
|
||||
|
||||
uninstall: subdirs.uninstall libposj.uninstall init-connection.uninstall open-read-close-fifo.uninstall open-write-close-fifo.uninstall service-test.uninstall libposj.so.uninstall libposj.a.uninstall init-connection.o.uninstall lib/communication.o.uninstall open-read-close-fifo.o.uninstall lib/communication.o.uninstall open-write-close-fifo.o.uninstall lib/communication.o.uninstall service-test.o.uninstall lib/communication.o.uninstall lib/communication.o.uninstall lib/communication.o.uninstall
|
||||
uninstall: subdirs.uninstall libposj.uninstall init-connection.uninstall open-read-close-fifo.uninstall open-write-close-fifo.uninstall service-test.uninstall pubsub/pubsubd.uninstall libposj.so.uninstall libposj.a.uninstall init-connection.o.uninstall lib/communication.o.uninstall open-read-close-fifo.o.uninstall lib/communication.o.uninstall open-write-close-fifo.o.uninstall lib/communication.o.uninstall service-test.o.uninstall lib/communication.o.uninstall pubsub/list.o.uninstall pubsub/pubsubd.o.uninstall lib/communication.o.uninstall lib/communication.o.uninstall
|
||||
@:
|
||||
|
||||
subdirs.uninstall:
|
||||
@ -229,7 +270,7 @@ test: all subdirs subdirs.test
|
||||
|
||||
subdirs.test:
|
||||
|
||||
clean: libposj.clean init-connection.clean open-read-close-fifo.clean open-write-close-fifo.clean service-test.clean libposj.so.clean libposj.a.clean init-connection.o.clean lib/communication.o.clean open-read-close-fifo.o.clean lib/communication.o.clean open-write-close-fifo.o.clean lib/communication.o.clean service-test.o.clean lib/communication.o.clean lib/communication.o.clean lib/communication.o.clean
|
||||
clean: libposj.clean init-connection.clean open-read-close-fifo.clean open-write-close-fifo.clean service-test.clean pubsub/pubsubd.clean libposj.so.clean libposj.a.clean init-connection.o.clean lib/communication.o.clean open-read-close-fifo.o.clean lib/communication.o.clean open-write-close-fifo.o.clean lib/communication.o.clean service-test.o.clean lib/communication.o.clean pubsub/list.o.clean pubsub/pubsubd.o.clean lib/communication.o.clean lib/communication.o.clean
|
||||
|
||||
distclean: clean
|
||||
|
||||
@ -245,11 +286,14 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.gz[00m'
|
||||
$(Q)tar czf $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(PACKAGE)-$(VERSION)/init-connection.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/service-test.c \
|
||||
$(PACKAGE)-$(VERSION)/open-write-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/open-read-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h
|
||||
|
||||
dist-xz: $(PACKAGE)-$(VERSION).tar.xz
|
||||
@ -257,11 +301,14 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.xz[00m'
|
||||
$(Q)tar cJf $(PACKAGE)-$(VERSION).tar.xz \
|
||||
$(PACKAGE)-$(VERSION)/init-connection.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/service-test.c \
|
||||
$(PACKAGE)-$(VERSION)/open-write-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/open-read-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h
|
||||
|
||||
dist-bz2: $(PACKAGE)-$(VERSION).tar.bz2
|
||||
@ -269,11 +316,14 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.bz2[00m'
|
||||
$(Q)tar cjf $(PACKAGE)-$(VERSION).tar.bz2 \
|
||||
$(PACKAGE)-$(VERSION)/init-connection.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.c \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/pubsubd.c \
|
||||
$(PACKAGE)-$(VERSION)/service-test.c \
|
||||
$(PACKAGE)-$(VERSION)/open-write-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/open-read-close-fifo.c \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.c \
|
||||
$(PACKAGE)-$(VERSION)/libposj.a \
|
||||
$(PACKAGE)-$(VERSION)/pubsub/list.h \
|
||||
$(PACKAGE)-$(VERSION)/lib/communication.h
|
||||
|
||||
help:
|
||||
@ -304,6 +354,7 @@ help:
|
||||
@echo ' - [01;33mopen-read-close-fifo[37mbinary[00m'
|
||||
@echo ' - [01;33mopen-write-close-fifo[37mbinary[00m'
|
||||
@echo ' - [01;33mservice-test [37mbinary[00m'
|
||||
@echo ' - [01;33mpubsub/pubsubd[37mbinary[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mMakefile options:[00m'
|
||||
@echo ' - gnu: true'
|
||||
|
@ -16,3 +16,9 @@ for i in *.c; do
|
||||
ldflags[${i%.c}]="libposj.a"
|
||||
done
|
||||
|
||||
targets+=(pubsub/pubsubd)
|
||||
type[pubsub/pubsubd]=binary
|
||||
sources[pubsub/pubsubd]="pubsub/list.c pubsub/pubsubd.c"
|
||||
cflags[pubsub/pubsubd]="-I lib"
|
||||
ldflags[pubsub/pubsubd]="libposj.a"
|
||||
|
||||
|
48
pubsub/list.c
Normal file
48
pubsub/list.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "list.h"
|
||||
|
||||
List*
|
||||
list_new(size_t element_size)
|
||||
{
|
||||
List* l = malloc(sizeof(*l));
|
||||
|
||||
l->element_size = element_size;
|
||||
l->head = NULL;
|
||||
l->tail = NULL;
|
||||
l->length = 0;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void*
|
||||
list_append(List* l)
|
||||
{
|
||||
struct link* link = malloc(sizeof(*link) + l->element_size);
|
||||
|
||||
link->next = l->tail;
|
||||
l->tail = link;
|
||||
|
||||
if (!l->head)
|
||||
l->tail = link;
|
||||
|
||||
l->length++;
|
||||
|
||||
return (void*) link->value;
|
||||
}
|
||||
|
||||
void
|
||||
list_free(List* l)
|
||||
{
|
||||
struct link* next;
|
||||
struct link* link;
|
||||
|
||||
for (link = l->head; link; link = next) {
|
||||
next = link->next;
|
||||
|
||||
free(link);
|
||||
}
|
||||
|
||||
free(l);
|
||||
}
|
||||
|
91
pubsub/pubsubd.c
Normal file
91
pubsub/pubsubd.c
Normal file
@ -0,0 +1,91 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <communication.h>
|
||||
|
||||
#include "list.h"
|
||||
|
||||
typedef struct {
|
||||
int test;
|
||||
} Publisher;
|
||||
|
||||
typedef struct {
|
||||
int test;
|
||||
} Subscriber;
|
||||
|
||||
const char* service_name = "pubsub";
|
||||
|
||||
void
|
||||
ohshit(int rvalue, const char* str) {
|
||||
fprintf(stderr, "%s\n", str);
|
||||
|
||||
exit(rvalue);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
List* subscribers;
|
||||
List* publishers;
|
||||
int r;
|
||||
char s_path[PATH_MAX];
|
||||
int s_pipe;
|
||||
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
service_path(s_path, service_name);
|
||||
|
||||
printf("Listening on %s.\n", s_path);
|
||||
|
||||
if ((r = service_create(s_path)))
|
||||
ohshit(1, "service_create error");
|
||||
|
||||
publishers = list_new(sizeof(Publisher));
|
||||
subscribers = list_new(sizeof(Subscriber));
|
||||
|
||||
if (!publishers && !subscribers)
|
||||
ohshit(1, "out of memory, already...");
|
||||
|
||||
/* ?!?!?!?!? */
|
||||
mkfifo(s_path, S_IRUSR);
|
||||
|
||||
s_pipe = open(s_path, S_IRUSR);
|
||||
|
||||
for (;;) {
|
||||
struct process* proc;
|
||||
int proc_count, i;
|
||||
|
||||
service_get_new_processes(&proc, &proc_count, s_pipe);
|
||||
|
||||
printf("> %i proc\n", proc_count);
|
||||
|
||||
for (i = 0; i < proc_count; i++) {
|
||||
size_t message_size = BUFSIZ;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
process_print(proc + i);
|
||||
|
||||
if ((r = process_read(&proc[i], &buffer, &message_size))) {
|
||||
ohshit(1, "process_read error");
|
||||
}
|
||||
|
||||
printf(": %s\n", buffer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
service_free_processes(&proc, proc_count);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
close(s_pipe);
|
||||
|
||||
list_free(publishers);
|
||||
list_free(subscribers);
|
||||
|
||||
service_close(s_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user