1 /* ISC license. */
2 
3 #ifndef FTRIGR_H
4 #define FTRIGR_H
5 
6 #include <sys/types.h>
7 #include <stdint.h>
8 #include <skalibs/config.h>
9 #include <skalibs/tai.h>
10 #include <skalibs/stralloc.h>
11 #include <skalibs/genalloc.h>
12 #include <skalibs/gensetdyn.h>
13 #include <skalibs/textclient.h>
14 #include <s6/config.h>
15 
16 
17  /* Constants */
18 
19 #define FTRIGR_IPCPATH SKALIBS_SPROOT "/run/service/ftrigrd/s"
20 
21 #define FTRIGRD_PROG S6_EXTBINPREFIX "s6-ftrigrd"
22 #define FTRIGR_BANNER1 "ftrigr v1.0 (b)\n"
23 #define FTRIGR_BANNER1_LEN (sizeof FTRIGR_BANNER1 - 1)
24 #define FTRIGR_BANNER2 "ftrigr v1.0 (a)\n"
25 #define FTRIGR_BANNER2_LEN (sizeof FTRIGR_BANNER2 - 1)
26 
27 #define FTRIGR_MAX 1000
28 
29 
30  /* Internals of the ftrigr_t */
31 
32 typedef enum fr1state_e fr1state_t, *fr1state_t_ref ;
33 enum fr1state_e
34 {
35   FR1STATE_WAITACK,
36   FR1STATE_WAITACKDATA,
37   FR1STATE_LISTENING,
38   FR1STATE_ERROR
39 } ;
40 
41 typedef struct ftrigr1_s ftrigr1_t, *ftrigr1_t_ref ;
42 struct ftrigr1_s
43 {
44   uint32_t options ;
45   fr1state_t state ;
46   stralloc what ;
47 } ;
48 #define FTRIGR1_ZERO { .options = 0, .state = FR1STATE_ERROR, .what = STRALLOC_ZERO }
49 extern ftrigr1_t const ftrigr1_zero ;
50 
51 
52  /* The ftrigr_t itself */
53 
54 typedef struct ftrigr_s ftrigr, ftrigr_t, *ftrigr_ref, *ftrigr_t_ref ;
55 struct ftrigr_s
56 {
57   textclient_t connection ;
58   genalloc list ; /* array of uint16_t */
59   size_t head ;
60   gensetdyn data ; /* set of ftrigr1_t */
61 } ;
62 #define FTRIGR_ZERO { .connection = TEXTCLIENT_ZERO, .list = GENALLOC_ZERO, .head = 0, .data = GENSETDYN_INIT(ftrigr1_t, 2, 0, 1) }
63 extern ftrigr_t const ftrigr_zero ;
64 
65 
66  /* Starting and ending a session */
67 
68 extern int ftrigr_start (ftrigr_t *, char const *, tain_t const *, tain_t *) ;
69 #define ftrigr_start_g(a, path, deadline) ftrigr_start(a, path, (deadline), &STAMP)
70 extern int ftrigr_startf (ftrigr_t *, tain_t const *, tain_t *) ;
71 #define ftrigr_startf_g(a, deadline) ftrigr_startf(a, (deadline), &STAMP)
72 extern void ftrigr_end (ftrigr_t *) ;
73 
74 
75  /* Instant primitives for async programming */
76 
77 #define ftrigr_fd(a) textclient_fd(&(a)->connection)
78 extern int ftrigr_updateb (ftrigr_t *) ;
79 extern int ftrigr_update (ftrigr_t *) ;
80 extern int ftrigr_check (ftrigr_t *, uint16_t, char *) ;
81 extern int ftrigr_checksa (ftrigr_t *, uint16_t, stralloc *) ;
82 extern void ftrigr_ack (ftrigr_t *, size_t) ;
83 
84 
85  /* Synchronous functions with timeouts */
86 
87 #define FTRIGR_REPEAT 0x0001
88 
89 extern uint16_t ftrigr_subscribe (ftrigr_t *, char const *, char const *, uint32_t, tain_t const *, tain_t *) ;
90 #define ftrigr_subscribe_g(a, path, re, options, deadline) ftrigr_subscribe(a, path, re, options, (deadline), &STAMP)
91 extern int ftrigr_unsubscribe (ftrigr_t *, uint16_t, tain_t const *, tain_t *) ;
92 #define ftrigr_unsubscribe_g(a, id, deadline) ftrigr_unsubscribe(a, id, (deadline), &STAMP)
93 
94 extern int ftrigr_wait_and (ftrigr_t *, uint16_t const *, unsigned int, tain_t const *, tain_t *) ;
95 #define ftrigr_wait_and_g(a, list, len, deadline) ftrigr_wait_and(a, list, len, (deadline), &STAMP)
96 extern int ftrigr_wait_or  (ftrigr_t *, uint16_t const *, unsigned int, tain_t const *, tain_t *, char *) ;
97 #define ftrigr_wait_or_g(a, list, len, deadline, what) ftrigr_wait_or(a, list, len, deadline, &STAMP, what)
98 
99 #endif
100