From: ian Date: Thu, 5 Jun 2008 23:30:29 +0000 (+0000) Subject: evdev-manip improvements X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=72223e1496f1668d9d8e8ae8d58555e5c5e36c6f;p=trains.git evdev-manip improvements --- diff --git a/hostside/Makefile b/hostside/Makefile index cd51b26..f3dc3f1 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -41,10 +41,11 @@ REALTIME_CORE= realtime startup safety trackloc \ nmra encode movpos rtprio \ ../layout/ours.layout-data +LIBOOP_OBJS= __oop-read-copy.o -loop + REALTIME_CORE_OBJS= $(addsuffix .o, $(REALTIME_CORE)) -realtime: $(REALTIME_CORE_OBJS) \ - __oop-read-copy.o -loop -lm +realtime: $(REALTIME_CORE_OBJS) $(LIBOOP_OBJS) -lm $(LINK) proto-expanded: ../cebpic/README.protocol @@ -56,7 +57,7 @@ topology-dump: topology-dump.o utils.o ../layout/ours.layout-data.o gui-plan-bot: gui-plan-%: gui-plan.o utils.o parseutils.o obc.o \ ../layout/ours.dgram-%.plandata.o \ ../layout/ours.layout-data.o \ - __oop-read-copy.o -loop + $(LIBOOP_OBJS) $(LINK) -L/usr/X11R6/lib -lXpm -lX11 auproto-pic.c auproto-pic.h: auproto-%: \ @@ -76,7 +77,7 @@ realtime+dflags.h: debug-extractor $(addsuffix .c, $(REALTIME_CORE)) ./$^ >$@.new cmp $@ $@.new || mv -f $@.new $@ -evdev-manip: evdev-manip.o utils.o +evdev-manip: evdev-manip.o utils.o $(LIBOOP_OBJS) safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o $(LINK) diff --git a/hostside/evdev-manip.c b/hostside/evdev-manip.c index 86aab07..886460a 100644 --- a/hostside/evdev-manip.c +++ b/hostside/evdev-manip.c @@ -7,6 +7,7 @@ #include "common.h" +#include #include #include @@ -20,6 +21,8 @@ typedef struct { typedef struct { void (*event)(Device *d, const struct input_event *ie); + void (*died)(Device *d, int revents, int readr, int readc, int e) + __attribute__((noreturn)); void (*mainloop)(void); } ModeInfo; @@ -91,12 +94,7 @@ static void process_device(Device *d) { remain; p+=r, remain-=r) { r= read(d->fd, &ie, remain); - if (r<0) { - if (errno==EINTR) continue; - diee("%s: error reading", d->path); - } - if (r==0) - die("%s: eof ?!", d->path); + if (r<=0) { mode->died(d, POLLIN, r, -1, errno); abort(); } assert(r <= remain); } if (ie.type == EV_SYN) { @@ -111,6 +109,18 @@ static void process_device(Device *d) { mflushstdout(); } +static void dump_died(Device *d, int revents, int readr, int readc, int e) + __attribute__((noreturn)); +static void dump_died(Device *d, int revents, int readr, int readc, int e) { + printf("device-terminated %s %#x ", d->path, revents); + if (readr<0) printf("err %s", strerror(e)); + else if (readr==0) printf("eof"); + else printf("%#x",readc); + printf("\n"); + mflushstdout(); + exit(0); +} + static void mainloop(void) { struct pollfd *polls; int i, r; @@ -133,16 +143,22 @@ static void mainloop(void) { assert(r>0); for (i=0; idied(&devices[i], polls[i].revents, r, dummy, errno); + abort(); + } if (polls[i].revents) process_device(&devices[i]); } } } -static const ModeInfo mode_dump= { dump_event, mainloop }; +static const ModeInfo mode_dump= { dump_event, dump_died, mainloop }; static void getdevice(const char *path) { int r;