nmsg  0.13.2
io.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015 by Farsight Security, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NMSG_IO_H
18 #define NMSG_IO_H
19 
20 #include <nmsg/input.h>
21 #include <nmsg/output.h>
22 
47 typedef enum {
48  nmsg_io_close_type_eof, /*%< end of file */
49  nmsg_io_close_type_count, /*%< payload count reached */
50  nmsg_io_close_type_interval /*%< interval elapsed */
52 
56 typedef enum {
57  nmsg_io_io_type_input, /*%< close event input */
58  nmsg_io_io_type_output /*%< close event output */
60 
64 typedef enum {
65  nmsg_io_output_mode_stripe, /*%< stripe payloads across output */
66  nmsg_io_output_mode_mirror /*%< mirror payloads across output */
68 
105  union {
106  nmsg_input_t *input; /*%< pointer to input stream */
107  nmsg_output_t *output; /*%< pointer to output stream */
108  };
109  union {
110  nmsg_input_type input_type; /*%< type of 'input' field */
111  nmsg_output_type output_type; /*%< type of 'output' field */
112  };
113  nmsg_io_t io; /*%< this nmsg_io loop */
114  nmsg_io_io_type io_type; /*%< whether 'input' or 'output' */
115  nmsg_io_close_type close_type; /*%< why the stream was closed */
116  void *user; /*%< caller-provided user pointer */
117 };
118 
124 typedef void (*nmsg_io_close_fp)(struct nmsg_io_close_event *ce);
125 
129 typedef void (*nmsg_io_user_fp)(unsigned threadno, void *user);
130 
136 nmsg_io_t
137 nmsg_io_init(void);
138 
179 nmsg_res
180 nmsg_io_add_filter(nmsg_io_t io, nmsg_filter_message_fp fp, void *data);
181 
204 nmsg_res
205 nmsg_io_add_filter_module(nmsg_io_t io, const char *name,
206  const void *param, const size_t len_param);
207 
221 nmsg_res
222 nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user);
223 
242 nmsg_res
243 nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user);
244 
260 nmsg_res
261 nmsg_io_add_input_xs_channel(nmsg_io_t io, void *xs_ctx, const char *chan, void *user);
262 
282 nmsg_res
283 nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user);
284 
298 nmsg_res
299 nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user);
300 
314 nmsg_res
315 nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user);
316 
335 nmsg_res
336 nmsg_io_loop(nmsg_io_t io);
337 
348 void
349 nmsg_io_breakloop(nmsg_io_t io);
350 
356 void
357 nmsg_io_destroy(nmsg_io_t *io);
358 
364 unsigned
365 nmsg_io_get_num_inputs(nmsg_io_t io);
366 
372 unsigned
373 nmsg_io_get_num_outputs(nmsg_io_t io);
374 
387 void
388 nmsg_io_set_close_fp(nmsg_io_t io, nmsg_io_close_fp close_fp);
389 
400 void
401 nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
402 
413 void
414 nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
415 
428 void
429 nmsg_io_set_count(nmsg_io_t io, unsigned count);
430 
439 void
440 nmsg_io_set_debug(nmsg_io_t io, int debug);
441 
456 void
458 
471 void
472 nmsg_io_set_interval(nmsg_io_t io, unsigned interval);
473 
483 void
484 nmsg_io_set_interval_randomized(nmsg_io_t io, bool randomized);
485 
499 void
500 nmsg_io_set_output_mode(nmsg_io_t io, nmsg_io_output_mode output_mode);
501 
502 #endif /* NMSG_IO_H */