Annotation of embedaddon/libpdel/util/pevent.h, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #ifndef _PDEL_UTIL_PEVENT_H_
        !            42: #define _PDEL_UTIL_PEVENT_H_
        !            43: 
        !            44: /*
        !            45:  * Event-based scheduling
        !            46:  */
        !            47: 
        !            48: struct pevent;
        !            49: struct pevent_ctx;
        !            50: struct mesg_port;
        !            51: 
        !            52: #define PEVENT_MAX_EVENTS              128
        !            53: 
        !            54: /*
        !            55:  * Event handler function type
        !            56:  */
        !            57: typedef void   pevent_handler_t(void *arg);
        !            58: 
        !            59: /*
        !            60:  * Event types
        !            61:  */
        !            62: enum pevent_type {
        !            63:        PEVENT_READ = 1,
        !            64:        PEVENT_WRITE,
        !            65:        PEVENT_TIME,
        !            66:        PEVENT_MESG_PORT,
        !            67:        PEVENT_USER
        !            68: };
        !            69: 
        !            70: /*
        !            71:  * Event info structure filled in by pevent_get_info().
        !            72:  */
        !            73: struct pevent_info {
        !            74:        enum pevent_type        type;   /* event type */
        !            75:        union {
        !            76:            int                 fd;     /* file descriptor (READ, WRITE) */
        !            77:            int                 millis; /* delay in milliseconds (TIME) */
        !            78:            struct mesg_port    *port;  /* mesg_port(3) (MESG_PORT) */
        !            79:        }                       u;
        !            80: };
        !            81: 
        !            82: /*
        !            83:  * Event flags
        !            84:  */
        !            85: #define PEVENT_RECURRING       0x0001
        !            86: #define PEVENT_OWN_THREAD      0x0002
        !            87: 
        !            88: __BEGIN_DECLS
        !            89: 
        !            90: /*
        !            91:  * Create a new event context.
        !            92:  */
        !            93: extern struct  pevent_ctx *pevent_ctx_create(const char *mtype,
        !            94:                        const pthread_attr_t *attr);
        !            95: 
        !            96: /*
        !            97:  * Destroy an event context.
        !            98:  *
        !            99:  * All events are unregistered. This is safe to be called
        !           100:  * from within an event handler.
        !           101:  */
        !           102: extern void    pevent_ctx_destroy(struct pevent_ctx **ctxp);
        !           103: 
        !           104: /*
        !           105:  * Return the number of registered events.
        !           106:  */
        !           107: extern u_int   pevent_ctx_count(struct pevent_ctx *ctx);
        !           108: 
        !           109: /*
        !           110:  * Create a new event.
        !           111:  */
        !           112: extern int     pevent_register(struct pevent_ctx *ctx, struct pevent **peventp,
        !           113:                        int flags, pthread_mutex_t *mutex,
        !           114:                        pevent_handler_t *handler, void *arg,
        !           115:                        enum pevent_type type, ...);
        !           116: 
        !           117: /*
        !           118:  * Trigger a user event.
        !           119:  */
        !           120: extern void    pevent_trigger(struct pevent *pevent);
        !           121: 
        !           122: /*
        !           123:  * Get the type and parameters for an event.
        !           124:  */
        !           125: extern int     pevent_get_info(struct pevent *pevent,
        !           126:                        struct pevent_info *info);
        !           127: 
        !           128: /*
        !           129:  * Destroy an event.
        !           130:  */
        !           131: extern void    pevent_unregister(struct pevent **eventp);
        !           132: 
        !           133: __END_DECLS
        !           134: 
        !           135: #endif /* _PDEL_UTIL_PEVENT_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>