mio.h

Go to the documentation of this file.
00001 /*
00002  ** mio.h
00003  ** Multiple I/O configuration and routing support for file and network daemons
00004  **
00005  ** ------------------------------------------------------------------------
00006  ** Copyright (C) 2006 Carnegie Mellon University. All Rights Reserved.
00007  ** ------------------------------------------------------------------------
00008  ** Authors: Brian Trammell <bht@cert.org>
00009  ** ------------------------------------------------------------------------
00010  ** GNU Lesser GPL Rights pursuant to Version 2.1, February 1999 
00011  ** Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013
00012  ** ------------------------------------------------------------------------
00013  */
00014 
00047 /* idem */
00048 #ifndef _AIRFRAME_MIO_H_
00049 #define _AIRFRAME_MIO_H_
00050 #include <airframe/autoinc.h>
00051 
00053 #define MIO_ERROR_DOMAIN        g_quark_from_string("airframeMIO")
00054 
00058 #define MIO_ERROR_MULTIPLE      1
00059 
00063 #define MIO_ERROR_ARGUMENT      2
00064 
00065 #define MIO_ERROR_IO            3
00066 
00067 #define MIO_ERROR_CONN          4
00068 
00069 #define MIO_ERROR_NOINPUT       5
00070 
00071 #define MIO_ERROR_LOCK          6
00072 
00073 #define MIO_ERROR_IMPL          7
00074 
00084 #define MIO_F_CTL_ERROR         0x00000001
00085 
00095 #define MIO_F_CTL_TRANSIENT     0x00000002
00096 
00103 #define MIO_F_CTL_SOURCECLOSE   0x00000004
00104 
00113 #define MIO_F_CTL_SINKCLOSE     0x00000008
00114 
00120 #define MIO_F_CTL_TERMINATE     0x00000010
00121 
00128 #define MIO_F_CTL_POLL          0x00000020
00129 
00136 #define MIO_F_CTL_MASK          0x0000003f
00137 
00148 #define MIO_F_OPT_LOCK          0x00008000
00149 
00160 #define MIO_F_OPT_DAEMON        0x00004000
00161 
00170 #define MIO_F_OPT_SINKLINK      0x00002000
00171 
00178 #define MIO_F_OPT_MASK          0x0000ffc0
00179 
00183 typedef enum _MIOType {
00188     MIO_T_ANY = 0,
00194     MIO_T_APP = 1,
00201     MIO_T_NULL = 2,
00207     MIO_T_FD = 3,
00212     MIO_T_FP = 4,
00218     MIO_T_PCAP = 5,
00223     MIO_T_SOCK_DGRAM = 6,
00228     MIO_T_SOCK_STREAM = 7,
00235     MIO_T_SINKARRAY = 8,
00236 } MIOType;
00237 
00238 struct _MIOSource;
00245 typedef struct _MIOSource MIOSource;
00246 
00247 struct _MIOSink;
00254 typedef struct _MIOSink MIOSink;
00255 
00260 typedef gboolean        (*MIOSourceFn)(
00261     MIOSource               *source,
00262     uint32_t                *flags,
00263     GError                  **err);
00264 
00270 typedef gboolean        (*MIOAppSourceFn)(
00271     MIOSource               *source,
00272     void                    *vctx,
00273     uint32_t                *flags,
00274     GError                  **err);
00275 
00280 typedef void            (*MIOSourceFreeFn)(
00281     MIOSource               *source);
00282 
00286 typedef gboolean        (*MIOSinkFn)(
00287     MIOSource               *source,
00288     MIOSink                 *sink,
00289     uint32_t                *flags,
00290     GError                  **err);
00291 
00296 typedef void            (*MIOSinkFreeFn)(
00297     MIOSink                 *sink);
00298     
00304 typedef gboolean        (*MIOAppFn)(
00305     MIOSource               *source,
00306     MIOSink                 *sink,
00307     void                    *vctx,
00308     uint32_t                *flags,
00309     GError                  **err);
00310 
00312 struct _MIOSource {
00314     char                    *spec;
00316     char                    *name;
00318     MIOType                 vsp_type;
00320     void                    *vsp;
00322     void                    *cfg;
00324     void                    *ctx;
00326     MIOSourceFn             next_source;
00328     MIOSourceFn             close_source;
00330     MIOSourceFreeFn         free_source;
00332     gboolean                opened;
00334     gboolean                active;
00335 };
00336 
00338 struct _MIOSink {
00340     char                    *spec;
00342     char                    *name;
00344     MIOType                 vsp_type;
00346     void                    *vsp;
00348     void                    *cfg;
00350     void                    *ctx;
00352     MIOSinkFn               next_sink;
00354     MIOSinkFn               close_sink;
00356     MIOSinkFreeFn           free_sink;
00358     gboolean                opened;
00360     gboolean                active;
00366     gboolean                iterative;
00367 };
00368 
00374 typedef struct _MIOAppDriver {
00380     MIOAppSourceFn          app_open_source;
00386     MIOAppFn                app_open_sink;
00392     MIOAppFn                app_process;
00398     MIOAppSourceFn          app_close_source;
00405     MIOAppFn                app_close_sink;
00406 } MIOAppDriver;
00407 
00412 #define mio_fd(_s_) GPOINTER_TO_INT((_s_)->vsp)
00413 
00414 
00418 #define mio_fp(_s_) ((FILE *)(_s_)->vsp)
00419 
00448 gboolean                mio_dispatch(
00449     MIOSource               *source,
00450     MIOSink                 *sink,
00451     MIOAppDriver            *app_drv,
00452     void                    *vctx,
00453     uint32_t                *flags,
00454     GError                  **err);
00455     
00479 void                    mio_dispatch_loop(
00480     MIOSource               *source,
00481     MIOSink                 *sink,
00482     MIOAppDriver            *app_drv,
00483     void                    *vctx,
00484     uint32_t                flags,
00485     uint32_t                polltime);
00486 
00493 void mio_source_free(
00494     MIOSource               *source);
00495 
00502 void mio_sink_free(
00503     MIOSink                 *sink);
00504 
00524 gboolean mio_source_init_app(
00525     MIOSource       *source,
00526     const char      *spec,
00527     MIOType         vsp_type,
00528     void            *cfg,
00529     GError          **err);
00530 
00550 gboolean mio_sink_init_app(
00551     MIOSink         *sink,
00552     const char      *spec,
00553     MIOType         vsp_type,
00554     void            *cfg,
00555     GError          **err);
00556 
00557 /* end idem */
00558 #endif

© 2005-2006 Carnegie Mellon University
Generated Thu Jun 15 10:08:41 2006 for Airframe 0.6.2 by Doxygen 1.4.5.