nmsg 1.1.1
io.h
1/*
2 * Copyright (c) 2008-2019 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
47typedef 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 */
51} nmsg_io_close_type;
52
56typedef enum {
57 nmsg_io_io_type_input, /*%< close event input */
58 nmsg_io_io_type_output /*%< close event output */
59} nmsg_io_io_type;
60
64typedef enum {
65 nmsg_io_output_mode_stripe, /*%< stripe payloads across output */
66 nmsg_io_output_mode_mirror /*%< mirror payloads across output */
67} nmsg_io_output_mode;
68
104struct nmsg_io_close_event {
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
124typedef void (*nmsg_io_close_fp)(struct nmsg_io_close_event *ce);
125
129typedef void (*nmsg_io_user_fp)(unsigned threadno, void *user);
130
136nmsg_io_t
137nmsg_io_init(void);
138
179nmsg_res
180nmsg_io_add_filter(nmsg_io_t io, nmsg_filter_message_fp fp, void *data);
181
204nmsg_res
205nmsg_io_add_filter_module(nmsg_io_t io, const char *name,
206 const void *param, const size_t len_param);
207
221nmsg_res
222nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user);
223
242nmsg_res
243nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user);
244
260nmsg_res
261nmsg_io_add_input_zmq_channel(nmsg_io_t io, void *zmq_ctx, const char *chan, void *user);
262
282nmsg_res
283nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user);
284
298nmsg_res
299nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user);
300
314nmsg_res
315nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user);
316
335nmsg_res
336nmsg_io_loop(nmsg_io_t io);
337
348void
349nmsg_io_breakloop(nmsg_io_t io);
350
356void
357nmsg_io_destroy(nmsg_io_t *io);
358
364unsigned
365nmsg_io_get_num_inputs(nmsg_io_t io);
366
372unsigned
373nmsg_io_get_num_outputs(nmsg_io_t io);
374
387void
388nmsg_io_set_close_fp(nmsg_io_t io, nmsg_io_close_fp close_fp);
389
400void
401nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
402
413void
414nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
415
433void
434nmsg_io_set_count(nmsg_io_t io, unsigned count);
435
444void
445nmsg_io_set_debug(nmsg_io_t io, int debug);
446
461void
462nmsg_io_set_filter_policy(nmsg_io_t io, const nmsg_filter_message_verdict policy);
463
478void
479nmsg_io_set_interval(nmsg_io_t io, unsigned interval);
480
490void
491nmsg_io_set_interval_randomized(nmsg_io_t io, bool randomized);
492
506void
507nmsg_io_set_output_mode(nmsg_io_t io, nmsg_io_output_mode output_mode);
508
526nmsg_res
527nmsg_io_get_stats(nmsg_io_t io, uint64_t *sum_in, uint64_t *sum_out, uint64_t *container_recvs, uint64_t *container_drops);
528
529
530#endif /* NMSG_IO_H */