chiark / gitweb /
simulation - compiles but not yet tested
[trains.git] / hostside / daemons.h
1 /*
2  * declarations common to
3  *  - realtime daemon
4  *  - multiplexer daemon
5  */
6
7 #ifndef DAEMONS_H
8 #define DAEMONS_H
9
10 #include <oop.h>
11 #include <oop-read.h>
12
13 #include "common.h"
14
15 typedef struct CommandInput CommandInput;
16
17 /*---------- from obc.c ----------*/
18
19 typedef struct OutBuffer OutBuffer;
20 typedef struct OutBufferChain OutBufferChain;
21 typedef void OutBufferError(OutBufferChain*, const char *e1, const char *e2
22                             /* on error: both e1 and e2 non-0. say `$e1: $e2'
23                              * on eof: both e1 and e2 =0. */);
24
25 struct OutBufferChain {
26   /* set by user: */
27   char *desc;
28   int fd;
29   int limit; /* 0 means obc_init will set a default */
30   OutBufferError *error;
31   /* set/used by obc_..., oprintf, etc., only */
32   int done_of_head, total;
33   struct { OutBuffer *head, *tail; } obs;
34 };
35
36 void obc_init(OutBufferChain *ch);
37 void obc_init_core(OutBufferChain *ch); /* doesn't mess with fd */
38 int obc_tryflush(OutBufferChain *ch);
39  /* returns 0 for all flushed or errno, including particularly EWOULDBLOCK */
40
41 void ovprintf(OutBufferChain *ch, const char *fmt, va_list al)
42      __attribute__((format(printf,2,0)));
43 void oprintf(OutBufferChain *ch, const char *msg, ...)
44      __attribute__((format(printf,2,3)));
45 void owrite(OutBufferChain *ch, const char *data, int l);
46 void voerror(OutBufferChain *ch, const char *fmt, va_list al)
47      __attribute__((format(printf,2,0)));
48
49 /*---------- from cmdinput.c ----------*/
50
51 extern oop_source *events;
52
53 typedef void CommandInputCallback(ParseState *ps, CommandInput *cmdi);
54
55 struct CommandInput {
56   OutBufferChain out;
57   CommandInputCallback *doline;
58   oop_read *rd;
59 };
60
61 void cmdin_new(CommandInput *cmdi, int readfd);
62   /* fill in cmdi->out's `set by user' fields before calling cmdin_new,
63    * as cmdin_new will call obc_init and will use cmdi->out->fd. */
64
65 #endif /*DAEMONS_H*/