Annotation of libelwix/inc/elwix.h, revision 1.1.1.1.2.5

1.1       misho       1: /*************************************************************************
                      2: * (C) 2013 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
                      3: *  by Michael Pounov <misho@elwix.org>
                      4: *
                      5: * $Author: misho $
1.1.1.1.2.5! misho       6: * $Id: elwix.h,v 1.1.1.1.2.4 2013/01/18 10:12:22 misho Exp $
1.1       misho       7: *
                      8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
                     15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
                     16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
                     46: #ifndef __ELWIX_H
                     47: #define __ELWIX_H
                     48: 
                     49: 
                     50: #include <assert.h>
                     51: #include <syslog.h>
                     52: #include <sys/types.h>
                     53: #include <sys/socket.h>
                     54: #include <sys/un.h>
                     55: #include <net/if_dl.h>
                     56: #include <netinet/in.h>
                     57: #include <arpa/inet.h>
                     58: 
                     59: #include <elwix/atree.h>
                     60: #include <elwix/ampool.h>
                     61: #include <elwix/acrc.h>
                     62: #include <elwix/aarray.h>
                     63: #include <elwix/asarr.h>
                     64: #include <elwix/avar.h>
                     65: #include <elwix/astr.h>
                     66: #include <elwix/aregex.h>
1.1.1.1.2.5! misho      67: #include <elwix/aav.h>
1.1       misho      68: #include <elwix/anet.h>
                     69: 
                     70: 
                     71: #ifndef STRSIZ
                     72: #define STRSIZ         256
                     73: #endif
                     74: 
                     75: #ifndef be16toh
                     76: #define be16toh                betoh16
                     77: #endif
                     78: #ifndef be32toh
                     79: #define be32toh                betoh32
                     80: #endif
                     81: #ifndef be64toh
                     82: #define be64toh                betoh64
                     83: #endif
                     84: #ifndef le16toh
                     85: #define le16toh                letoh16
                     86: #endif
                     87: #ifndef le32toh
                     88: #define le32toh                letoh32
                     89: #endif
                     90: #ifndef le64toh
                     91: #define le64toh                letoh64
                     92: #endif
                     93: 
                     94: #define E_ALIGN(x, a)  (((x) + ((a) - 1)) & ~((a) - 1))
                     95: 
                     96: 
                     97: #define ELWIX_SYSM     0
                     98: #define ELWIX_MPOOL    1
                     99: 
                    100: #define VACUUM_LEFT    1
                    101: #define VACUUM_BETWEEN 2
                    102: 
                    103: 
                    104: // elwix_SetProg() Set program memory pool name
                    105: inline void elwix_SetProg(const char *csProgName);
                    106: // elwix_GetProg() Get program memory pool name
                    107: inline const char *elwix_GetProg();
                    108: 
                    109: // elwix_GetErrno() Get error code of last operation
                    110: inline int elwix_GetErrno();
                    111: // elwix_GetError() Get error text of last operation
                    112: inline const char *elwix_GetError();
                    113: 
                    114: 
                    115: // elwix_mm_inuse() Check for memory management model
                    116: inline int elwix_mm_inuse();
                    117: 
                    118: 
                    119: /*
                    120:  * elwixInit() - Init libelwix library memory management
                    121:  *
                    122:  * @mm = memory management (IO_SYSM or IO_MPOOL)
                    123:  * @maxmem = memory limit
                    124:  * return: -1 error or !=-1 used memory management model
                    125:  */
                    126: inline int elwixInit(int mm, unsigned long maxmem);
                    127: /*
                    128:  * elwixFini() - Finish libelwix library memory management
                    129:  *
                    130:  * return: none
                    131:  */
                    132: inline void elwixFini();
                    133: 
                    134: /* memory management hooks */
                    135: extern void *(*e_malloc)(size_t);
                    136: extern void *(*e_calloc)(size_t, size_t);
                    137: extern void *(*e_realloc)(void*, size_t);
                    138: extern char *(*e_strdup)(const char*);
                    139: extern void (*e_free)(void*);
                    140: 
                    141: 
                    142: /* Debug helper macros */
                    143: 
                    144: /* Verbose macros */
                    145: extern int elwix_Verbose;
                    146: #define e_initVerbose(x)       (elwix_Verbose = (x))
                    147: #define e_incVerbose           (elwix_Verbose++)
                    148: #define e_decVerbose           (elwix_Verbose--)
                    149: 
1.1.1.1.2.4  misho     150: #define EVERBS(x)              if ((x) <= elwix_Verbose)
1.1.1.1.2.1  misho     151: #define EVERBOSE(x, fmt, ...)  do { assert((fmt)); \
                    152:                                        if ((x) <= elwix_Verbose) { \
                    153:                                                char str[BUFSIZ] = { 0 }; \
                    154:                                                snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
                    155:                                                syslog(LOG_DEBUG, "Verbose(%d):%s(%d): %s\n", \
                    156:                                                                (x), __func__, __LINE__, str); \
                    157:                                        } \
                    158:                                } while (0)
1.1       misho     159: 
                    160: /* Debug macros */
                    161: extern int elwix_Debug;
                    162: #define ELWIX_DEBUG_OFF                0x0
                    163: #define ELWIX_DEBUG_TRACE      0x1
                    164: #define ELWIX_DEBUG_LOG                0x2
                    165: #define ELWIX_DEBUG_ANY                0xFFFFFFFF
                    166: 
                    167: #define ETRACE(x)              if (elwix_Debug & ELWIX_DEBUG_TRACE) \
                    168:                                           syslog(LOG_DEBUG, "I'm in %s(%d)", __func__, __LINE__)
                    169: #define EDEBUG(x, fmt, ...)    do { assert((fmt)); \
                    170:                                        if ((x) & elwix_Debug) { \
                    171:                                                char str[BUFSIZ] = { 0 }; \
                    172:                                                snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
                    173:                                                syslog(LOG_DEBUG, "Debug(%d):%s(%d): %s\n", \
                    174:                                                                (x), __func__, __LINE__, str); \
                    175:                                        } \
                    176:                                } while (0)
                    177: 
                    178: /* Logger macro */
                    179: #define ELOGGER(x, fmt, ...)   do { assert((fmt)); \
                    180:                                        char str[BUFSIZ] = { 0 }; \
                    181:                                        snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
                    182:                                        syslog((x), "Logger:%s(%d): %s\n", \
                    183:                                                                __func__, __LINE__, str); \
                    184:                                } while (0)
                    185: 
                    186: /* Error state macros */
                    187: #define EERROR(x, fmt, ...)    do { assert((fmt)); \
                    188:                                        char str[BUFSIZ] = { 0 }; \
                    189:                                        snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
                    190:                                        syslog(LOG_ERR, "Error:%s(%d): #%d - %s\n", \
                    191:                                                         __func__, __LINE__, (x), str); \
                    192:                                } while (0)
                    193: #define ESYSERR(x)             do { \
                    194:                                        if (x > 0 || errno) \
                    195:                                                syslog(LOG_ERR, "Error(sys):%s(%d): #%d - %s\n", \
                    196:                                                                __func__, __LINE__, x > 0 ? x : errno, \
                    197:                                                                strerror(x > 0 ? x : errno)); \
                    198:                                } while (0)
                    199: #define ELIBERR(ait)           do { \
                    200:                                        if (ait##_GetErrno()) \
                    201:                                                syslog(LOG_ERR, "Error(lib):%s(%d): #%d - %s\n", \
                    202:                                                                __func__, __LINE__, ait##_GetErrno(), \
                    203:                                                                ait##_GetError()); \
                    204:                                } while (0)
                    205: 
                    206: 
                    207: #endif

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