Add support for query key extraction
[com/gs-lite.git] / include / fta.h
1 /* ------------------------------------------------
2  Copyright 2014 AT&T Intellectual Property
3  Licensed under the Apache License, Version 2.0 (the "License");
4  you may not use this file except in compliance with the License.
5  You may obtain a copy of the License at
6  
7  http://www.apache.org/licenses/LICENSE-2.0
8  
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14  ------------------------------------------- */
15 /*
16  * fta.h: fta definition for applications
17  */
18 #ifndef FTA_H
19 #define FTA_H
20
21 #include "gslog.h"
22 #include "gsconfig.h"
23
24 typedef struct FTAID {
25     gs_uint32_t ip;  /* identifies the node */
26     gs_uint32_t port; /* identifies a process */
27     gs_uint32_t index;  /* the index identifies a particular FTA in the process */
28     gs_p_t streamid; /* streamid if set identifies an instance */
29 } FTAID;
30
31
32
33 typedef struct PRINTFUNC {
34     gs_sp_t header;
35     gs_sp_t path;
36     gs_sp_t basename;
37     FILE * fa[MAXPRINTFILES];
38     gs_uint32_t nexttime;
39     gs_uint32_t split;
40     gs_uint32_t base;
41     gs_uint32_t itt;
42     gs_uint32_t delta;
43     gs_schemahandle_t schemaid;
44     gs_int32_t split_field;
45     gs_int32_t temporal_field;
46     gs_int32_t in_use;
47 } PRINTFUNC;
48
49 /* the following defines define the FTA commands */
50
51 #define FTA_COMMAND_LOAD_PARAMS 1
52 #define FTA_COMMAND_FLUSH 2
53 #define FTA_COMMAND_GET_TEMP_STATUS 3
54 #define FTA_COMMAND_SET_SAMPLING_RATE 4
55 #define FTA_COMMAND_FILE_DONE 5
56
57 typedef gs_csp_t FTAname;
58
59 typedef gs_csp_t DEVname;
60
61 #define DEFAULTDEV 0
62
63 //      Use gs_param_handle_t defined in gscpv3/include/gstypes.h instead
64 // typedef gs_uint32_t param_handle_t;
65
66 struct FTA {
67     
68     /* reference counts managed by the RTS */
69     gs_uint32_t refcnt;
70     gs_uint32_t runrefcnt;
71     
72     /* the ID gets filled in by the runtime system */
73     FTAID ftaid;
74     
75     /* indicates if the FTA instance can be reused. Set by FTA 0 indicates
76      * that it can not be reused.
77      */
78     gs_uint32_t reusable;
79     
80     /* ftaids the HFTA is subscribed to*/
81     FTAID stream_subscribed[64];
82     
83     /* number of valid entries in stream_subscribe [0..stream_subscribed_cnt-1] */
84     gs_uint32_t stream_subscribed_cnt;
85     
86     /* State needed to print directly to a file out of a HFTA */
87     
88     PRINTFUNC printfunc;
89     
90     /* value of prefilter only used in lftas */
91     gs_uint64_t prefilter;
92     
93     /* allocates and initializes a paramterized instance of a FTA
94      */
95     struct FTA * (*alloc_fta) (FTAID ftaid, gs_uint32_t reusable,
96                                gs_int32_t command, gs_int32_t sz, void * value );
97     
98     /* release all resources associated with FTA (including the FTA) */
99     gs_retval_t (*free_fta) (struct FTA *, gs_uint32_t recursive);
100     
101     /* send control data from host to an instance of an FTA, may return status */
102     gs_retval_t (*control_fta) (struct FTA *, gs_int32_t command, gs_int32_t sz, void * value);
103     
104     /* gets called once every second. Might be delayed until the current thread execution
105      * returns into the run time system. If delayed for more then 1 second then only one
106      * call will be made at the next oportunity.
107      */
108     gs_retval_t (*clock_fta) (struct FTA *);
109     
110     /*
111      * process a packet received on the interface or a tuple received from
112      * another FTA. If ftaid is 0 then packet is of
113      * type struct packet otherwise it is a tuple as defined by the
114      * ftaid.
115      */
116     gs_retval_t (*accept_packet)(struct FTA *, FTAID * f, void * packet, gs_int32_t sz);
117 };
118
119 /* The following definitions are used or provided in automatically generated files */
120
121 typedef  struct FTA * (*alloc_fta) (FTAID ftaid, gs_uint32_t reusable,
122 gs_int32_t command, gs_int32_t sz, void * value ) ;
123
124
125 /* FTA INTERFACE */
126 /* ============== */
127 /* These functions are used by FTAs in addition to the LOW and HIGH
128  * level application interface functions.
129  */
130
131 /* start_service is called to process requests from the message queue
132  which would invoke callback functions registered by fta_register.
133  Number indicates how many seconds should be waited before the
134  function returns. If number < 0 then the function is an endless
135  loop (should be used for HFTA) if the number == 0 all currently
136  outstanding requests are processed before the function returns.
137  */
138 gs_retval_t fta_start_service(gs_int32_t number);
139
140 /* the dev name indicates on which device the FTA is supposed to execute.
141  * HFTA should always use DEFAULTDEV and a snaplen of -1
142  */
143 FTAID fta_register(FTAname name, gs_uint32_t reusable, DEVname device,
144                    alloc_fta fta_alloc_functionptr, gs_csp_t schema,gs_int32_t snaplen,
145                    gs_uint64_t prefilter);
146
147 gs_retval_t fta_unregister(FTAID f);
148
149
150 /*
151  * get the maximum snap length of all ftas registered within the current proccess
152  */
153
154 gs_retval_t fta_max_snaplen();
155
156 /*
157  * Post a tupple back to the clearing house This tuple cannot
158  * use the lfta tuple allocation functions. NOTE: post tuple will
159  * return -1 if at least one ringbuffer for that FTA which is in the atomic
160  * set has not enought space. Otherwise 0 is returned.
161  */
162 gs_retval_t hfta_post_tuple(struct FTA * self, gs_int32_t sz, void *tuple);
163
164 /* the following function fills in the FTAID array r with the FTAIDs of processes receiving
165  * tuplese from the FTA specified in f. The space array indicates how many tuples of tuplesz
166  * can still fit in the ringbuffer corresponding to the FTAID of the process with the same index
167  * in r. The return values indicates how many ring buffers are valid in r. szr indicates the memory
168  * length (in elements) of  r and space. The function will fill at most szr elements into these array.
169  * If the return value is larger then szr it is an indication that not enough memory in r and space
170  * were provided to hold all results. A return value of -1 indicates an error.
171  */
172
173 gs_retval_t hfta_get_ringbuf_space(struct FTA * f, FTAID * r, gs_int32_t* space, gs_int32_t szr, gs_int32_t tuplesz);
174
175
176 /* the following function can be used to put a ringbuffer to a process identified by the FTAID
177  * process into one of the following 3 modes. ATOMIC makes the ringbuffer part of the atomic set.
178  * A post to the atomic set either succeed or fails entirely. BESTEFFORT is the besteffort set
179  * posts to BESTEFFORT ringbuffers might fail quitely. SUSPEND will prevent any tuples of being
180  * posted to that proccess from the specified FTA.
181  */
182
183 #define HFTA_RINGBUF_ATOMIC 1
184 #define HFTA_RINGBUF_BESTEFFORT 2
185 #define HFTA_RINGBUF_SUSPEND 3
186
187 gs_retval_t hfta_set_ringbuf_type(struct FTA * f, FTAID process, gs_int32_t state);
188
189 #endif