chiark / gitweb /
evdev-manip improvements
authorian <ian>
Thu, 5 Jun 2008 23:30:29 +0000 (23:30 +0000)
committerian <ian>
Thu, 5 Jun 2008 23:30:29 +0000 (23:30 +0000)
hostside/Makefile
hostside/evdev-manip.c

index cd51b261021dd83bab7a6d2ab5b897df0080ed2d..f3dc3f1b929caf85ee62d3612026c2a3f29ea55d 100644 (file)
@@ -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)
index 86aab0720efd70066c09ef6345dd13b787afd5ea..886460a0a324bf8683cf7e5e476cf5a366e1015f 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "common.h"
 
+#include <oop-read.h>
 #include <poll.h>
 #include <sys/fcntl.h>
 
@@ -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; i<ndevices; i++) {
-      if (polls[i].revents & ~POLLIN)
-       die("device %s (fd %d) gave unexpected poll revent %#x",
-           devices[i].path, devices[i].fd, polls[i].revents);
+      if (polls[i].revents & ~POLLIN) {
+       unsigned char dummy;
+       r= oop_fd_nonblock(polls[i].fd, 1);
+       if (r) diee("nonblock %s during poll unepxected %#x",
+                   devices[i].path, polls[i].revents);
+       r= read(polls[i].fd, &dummy,1);
+       mode->died(&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;