chiark / gitweb /
reorganised to be nicer and ready to add stuff
[trains.git] / hostside / hostside.c
1 /**/
2
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <errno.h>
6 #include <string.h>
7 #include <stdarg.h>
8
9 #include "../layout/dlist.h"
10 #include "hostside.h"
11
12 oop_source *events;
13 FILE *dump_stream= 0;
14
15 static void serial_error(OutBufferChain *ch, const char *e1, const char *e2) {
16   abort();
17 }
18
19 static OutBufferChain serial_ochain= { (char*)"serial", -1, serial_error };
20
21 static void *serial_exception(oop_source *evts, int fd,
22                               oop_event evt, void *cl_v) {
23   die("serial port - exception");
24 }
25
26 static void *serial_readable(oop_source *evts, int fd,
27                              oop_event evt, void *u0) {
28   abort();
29 }
30
31 const char *device;
32
33 int main(int argc, const char **argv) {
34   oop_source_sys *sys_events;
35   int r;
36
37   device= argv[1];
38   if (!device) device= "/dev/ttyS0";
39
40   sys_events= oop_sys_new();  if (!sys_events) diee("oop_sys_new");
41   events= oop_sys_source(sys_events);  assert(events);
42   
43   serial_open(device);
44   r= oop_fd_nonblock(serial_fd, 1);  if (r) diee("nonblock(serial_fd,1)");
45   serial_ochain.fd= serial_fd;
46
47   stdin_client();
48
49   events->on_fd(events, serial_fd, OOP_READ, serial_readable, 0);
50   events->on_fd(events, serial_fd, OOP_EXCEPTION, serial_exception, 0);
51   oop_sys_run(sys_events);
52   abort();
53 }