Airframe Application Utilities
libairframe 0.7.2 API documentation

Main Page | Data Structures | File List | Data Fields | Globals

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-2007 Carnegie Mellon University. All Rights Reserved.
00007  ** ------------------------------------------------------------------------
00008  ** Authors: Brian Trammell <bht@cert.org>
00009  **          Tony Cebzanov <tonyc@cert.org>
00010  ** ------------------------------------------------------------------------
00011  ** GNU Lesser GPL Rights pursuant to Version 2.1, February 1999 
00012  ** Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013
00013  ** ------------------------------------------------------------------------
00014  */
00015 
00048 /* idem */
00049 #ifndef _AIRFRAME_MIO_H_
00050 #define _AIRFRAME_MIO_H_
00051 #include <airframe/autoinc.h>
00052 
00054 #define MIO_ERROR_DOMAIN        g_quark_from_string("airframeMIO")
00055 
00059 #define MIO_ERROR_MULTIPLE      1
00060 
00064 #define MIO_ERROR_ARGUMENT      2
00065 
00066 #define MIO_ERROR_IO            3
00067 
00068 #define MIO_ERROR_CONN          4
00069 
00070 #define MIO_ERROR_NOINPUT       5
00071 
00072 #define MIO_ERROR_LOCK          6
00073 
00074 #define MIO_ERROR_IMPL          7
00075 
00085 #define MIO_F_CTL_ERROR         0x00000001
00086 
00096 #define MIO_F_CTL_TRANSIENT     0x00000002
00097 
00104 #define MIO_F_CTL_SOURCECLOSE   0x00000004
00105 
00114 #define MIO_F_CTL_SINKCLOSE     0x00000008
00115 
00121 #define MIO_F_CTL_TERMINATE     0x00000010
00122 
00129 #define MIO_F_CTL_POLL          0x00000020
00130 
00137 #define MIO_F_CTL_MASK          0x0000003f
00138 
00149 #define MIO_F_OPT_LOCK          0x00008000
00150 
00161 #define MIO_F_OPT_DAEMON        0x00004000
00162 
00171 #define MIO_F_OPT_SINKLINK      0x00002000
00172 
00179 #define MIO_F_OPT_MASK          0x0000ffc0
00180 
00184 typedef enum _MIOType {
00189     MIO_T_ANY = 0,
00195     MIO_T_APP = 1,
00202     MIO_T_NULL = 2,
00208     MIO_T_FD = 3,
00213     MIO_T_FP = 4,
00219     MIO_T_PCAP = 5,
00224     MIO_T_SOCK_DGRAM = 6,
00229     MIO_T_SOCK_STREAM = 7,
00236     MIO_T_SINKARRAY = 8,
00241     MIO_T_SOCK_TLS = 9,
00242 } MIOType;
00243 
00244 struct _MIOSource;
00251 typedef struct _MIOSource MIOSource;
00252 
00253 struct _MIOSink;
00260 typedef struct _MIOSink MIOSink;
00261 
00266 typedef gboolean        (*MIOSourceFn)(
00267     MIOSource               *source,
00268     uint32_t                *flags,
00269     GError                  **err);
00270 
00276 typedef gboolean        (*MIOAppSourceFn)(
00277     MIOSource               *source,
00278     void                    *vctx,
00279     uint32_t                *flags,
00280     GError                  **err);
00281 
00286 typedef void            (*MIOSourceFreeFn)(
00287     MIOSource               *source);
00288 
00292 typedef gboolean        (*MIOSinkFn)(
00293     MIOSource               *source,
00294     MIOSink                 *sink,
00295     uint32_t                *flags,
00296     GError                  **err);
00297 
00302 typedef void            (*MIOSinkFreeFn)(
00303     MIOSink                 *sink);
00304     
00310 typedef gboolean        (*MIOAppFn)(
00311     MIOSource               *source,
00312     MIOSink                 *sink,
00313     void                    *vctx,
00314     uint32_t                *flags,
00315     GError                  **err);
00316 
00318 struct _MIOSource {
00320     char                    *spec;
00322     char                    *name;
00324     MIOType                 vsp_type;
00326     void                    *vsp;
00328     void                    *cfg;
00330     void                    *ctx;
00332     MIOSourceFn             next_source;
00334     MIOSourceFn             close_source;
00336     MIOSourceFreeFn         free_source;
00338     gboolean                opened;
00340     gboolean                active;
00341 };
00342 
00344 struct _MIOSink {
00346     char                    *spec;
00348     char                    *name;
00350     MIOType                 vsp_type;
00352     void                    *vsp;
00354     void                    *cfg;
00356     void                    *ctx;
00358     MIOSinkFn               next_sink;
00360     MIOSinkFn               close_sink;
00362     MIOSinkFreeFn           free_sink;
00364     gboolean                opened;
00366     gboolean                active;
00372     gboolean                iterative;
00373 };
00374 
00380 typedef struct _MIOAppDriver {
00386     MIOAppSourceFn          app_open_source;
00392     MIOAppFn                app_open_sink;
00398     MIOAppFn                app_process;
00404     MIOAppSourceFn          app_close_source;
00411     MIOAppFn                app_close_sink;
00412 } MIOAppDriver;
00413 
00418 #define mio_fd(_s_) GPOINTER_TO_INT((_s_)->vsp)
00419 
00424 #define mio_fp(_s_) ((FILE *)(_s_)->vsp)
00425 
00454 gboolean                mio_dispatch(
00455     MIOSource               *source,
00456     MIOSink                 *sink,
00457     MIOAppDriver            *app_drv,
00458     void                    *vctx,
00459     uint32_t                *flags,
00460     GError                  **err);
00461     
00489 gboolean                    mio_dispatch_loop(
00490     MIOSource               *source,
00491     MIOSink                 *sink,
00492     MIOAppDriver            *app_drv,
00493     void                    *vctx,
00494     uint32_t                flags,
00495     uint32_t                polltime,
00496         uint32_t                retrybase,
00497     uint32_t                retrymax);
00498 
00505 void mio_source_free(
00506     MIOSource               *source);
00507 
00514 void mio_sink_free(
00515     MIOSink                 *sink);
00516 
00536 gboolean mio_source_init_app(
00537     MIOSource       *source,
00538     const char      *spec,
00539     MIOType         vsp_type,
00540     void            *cfg,
00541     GError          **err);
00542 
00562 gboolean mio_sink_init_app(
00563     MIOSink         *sink,
00564     const char      *spec,
00565     MIOType         vsp_type,
00566     void            *cfg,
00567     GError          **err);
00568 
00569 /* end idem */
00570 #endif