nmsg  0.9.0
io.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009 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 
41 #include <nmsg/input.h>
42 #include <nmsg/output.h>
43 #include <nmsg.h>
44 
48 typedef enum {
49  nmsg_io_close_type_eof, /*%< end of file */
50  nmsg_io_close_type_count, /*%< payload count reached */
51  nmsg_io_close_type_interval /*%< interval elapsed */
53 
57 typedef enum {
58  nmsg_io_io_type_input, /*%< close event input */
59  nmsg_io_io_type_output /*%< close event output */
61 
65 typedef enum {
66  nmsg_io_output_mode_stripe, /*%< stripe payloads across output */
67  nmsg_io_output_mode_mirror /*%< mirror payloads across output */
69 
106  union {
107  nmsg_input_t *input; /*%< pointer to input stream */
108  nmsg_output_t *output; /*%< pointer to output stream */
109  };
110  union {
111  nmsg_input_type input_type; /*%< type of 'input' field */
112  nmsg_output_type output_type; /*%< type of 'output' field */
113  };
114  nmsg_io_t io; /*%< this nmsg_io loop */
115  nmsg_io_io_type io_type; /*%< whether 'input' or 'output' */
116  nmsg_io_close_type close_type; /*%< why the stream was closed */
117  void *user; /*%< caller-provided user pointer */
118 };
119 
125 typedef void (*nmsg_io_close_fp)(struct nmsg_io_close_event *ce);
126 
130 typedef void (*nmsg_io_user_fp)(unsigned threadno, void *user);
131 
137 nmsg_io_t
138 nmsg_io_init(void);
139 
153 nmsg_res
154 nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user);
155 
174 nmsg_res
175 nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user);
176 
192 nmsg_res
193 nmsg_io_add_input_xs_channel(nmsg_io_t io, void *xs_ctx, const char *chan, void *user);
194 
214 nmsg_res
215 nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user);
216 
230 nmsg_res
231 nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user);
232 
246 nmsg_res
247 nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user);
248 
267 nmsg_res
268 nmsg_io_loop(nmsg_io_t io);
269 
280 void
281 nmsg_io_breakloop(nmsg_io_t io);
282 
288 void
289 nmsg_io_destroy(nmsg_io_t *io);
290 
296 unsigned
297 nmsg_io_get_num_inputs(nmsg_io_t io);
298 
304 unsigned
305 nmsg_io_get_num_outputs(nmsg_io_t io);
306 
319 void
320 nmsg_io_set_close_fp(nmsg_io_t io, nmsg_io_close_fp close_fp);
321 
332 void
333 nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
334 
345 void
346 nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
347 
360 void
361 nmsg_io_set_count(nmsg_io_t io, unsigned count);
362 
371 void
372 nmsg_io_set_debug(nmsg_io_t io, int debug);
373 
386 void
387 nmsg_io_set_interval(nmsg_io_t io, unsigned interval);
388 
402 void
403 nmsg_io_set_output_mode(nmsg_io_t io, nmsg_io_output_mode output_mode);
404 
405 #endif /* NMSG_IO_H */
nmsg_input_type
An enum identifying the underlying implementation of an nmsg_input_t object.
Definition: input.h:56
void nmsg_io_breakloop(nmsg_io_t io)
Force a currently executing nmsg_io_loop() to stop looping and return.
Definition: io.c:108
nmsg_io_t io
this nmsg_io loop
Definition: io.h:114
nmsg_res
nmsg result code
Definition: res.h:25
unsigned nmsg_io_get_num_outputs(nmsg_io_t io)
Get the number of outputs bound to the nmsg_io_t object.
Definition: io.c:487
void(* nmsg_io_close_fp)(struct nmsg_io_close_event *ce)
Function for handling close event notifications.
Definition: io.h:125
void nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user)
Set a user-specified function to be called in each thread before the thread exits.
Definition: io.c:503
Write nmsg containers to output streams.
Convert input streams to nmsg format.
nmsg_res nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user)
Add an nmsg input to an nmsg_io_t object.
Definition: io.c:240
payload count reached
Definition: io.h:50
close event output
Definition: io.h:59
void nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user)
Set a user-specified function to be called in each thread after the thread starts.
Definition: io.c:497
nmsg_input_type input_type
type of 'input' field
Definition: io.h:111
Base nmsg support header.
nmsg_input_t * input
pointer to input stream
Definition: io.h:107
nmsg_io_output_mode
Output behavior when multiple outputs are present.
Definition: io.h:65
mirror payloads across output
Definition: io.h:67
nmsg_res nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user)
Add an NMSG file to an nmsg_io_t object.
Definition: io.c:461
close event input
Definition: io.h:58
nmsg_res nmsg_io_add_input_xs_channel(nmsg_io_t io, void *xs_ctx, const char *chan, void *user)
Add an nmsg XS input channel to an nmsg_io_t object.
void nmsg_io_set_interval(nmsg_io_t io, unsigned interval)
Configure the nmsg_io_t object to close inputs after processing for a set amount of time...
Definition: io.c:519
void nmsg_io_set_close_fp(nmsg_io_t io, nmsg_io_close_fp close_fp)
Set the close event notification function associated with an nmsg_io_t object.
Definition: io.c:492
void nmsg_io_set_debug(nmsg_io_t io, int debug)
Set the debug level for an nmsg_io_t object.
Definition: io.c:514
nmsg_io_io_type io_type
whether 'input' or 'output'
Definition: io.h:115
Structure for passing information about a close event between the nmsg_io processing loop and the ori...
Definition: io.h:105
nmsg_res nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user)
Add an nmsg input channel to an nmsg_io_t object.
Definition: io.c:348
void nmsg_io_set_count(nmsg_io_t io, unsigned count)
Configure the nmsg_io_t object to close inputs after processing a certain non-zero number of payloads...
Definition: io.c:509
void * user
caller-provided user pointer
Definition: io.h:117
nmsg_io_close_type
Type of a close event notification.
Definition: io.h:48
nmsg_res nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user)
Add an nmsg input sockspec to an nmsg_io_t object.
Definition: io.c:437
nmsg_io_io_type
Type of the stream associated with a close event.
Definition: io.h:57
nmsg_res nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user)
Add an nmsg output to an nmsg_io_t object.
Definition: io.c:265
nmsg_io_t nmsg_io_init(void)
Initialize a new nmsg_io_t object.
Definition: io.c:94
end of file
Definition: io.h:49
nmsg_io_close_type close_type
why the stream was closed
Definition: io.h:116
nmsg_output_type
An enum identifying the underlying implementation of an nmsg_output_t object.
Definition: output.h:40
void(* nmsg_io_user_fp)(unsigned threadno, void *user)
Optional user-specified function to be run at thread start or thread stop.
Definition: io.h:130
stripe payloads across output
Definition: io.h:66
void nmsg_io_set_output_mode(nmsg_io_t io, nmsg_io_output_mode output_mode)
Set the output mode behavior for an nmsg_io_t object.
Definition: io.c:524
nmsg_output_t * output
pointer to output stream
Definition: io.h:108
nmsg_output_type output_type
type of 'output' field
Definition: io.h:112
void nmsg_io_destroy(nmsg_io_t *io)
Deallocate the resources associated with an nmsg_io_t object.
Definition: io.c:179
nmsg_res nmsg_io_loop(nmsg_io_t io)
Begin processing the data specified by the configured inputs and outputs.
Definition: io.c:127
unsigned nmsg_io_get_num_inputs(nmsg_io_t io)
Get the number of inputs bound to the nmsg_io_t object.
Definition: io.c:482
interval elapsed
Definition: io.h:51