/************************************************************************* * (C) 2013 AITNET ltd - Sofia/Bulgaria - * by Michael Pounov * * $Author: misho $ * $Id: elwix.h,v 1.1 2013/01/17 10:05:35 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Michael Pounov ELWIX - Embedded LightWeight unIX and its contributors. 4. Neither the name of AITNET nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __ELWIX_H #define __ELWIX_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef STRSIZ #define STRSIZ 256 #endif #ifndef be16toh #define be16toh betoh16 #endif #ifndef be32toh #define be32toh betoh32 #endif #ifndef be64toh #define be64toh betoh64 #endif #ifndef le16toh #define le16toh letoh16 #endif #ifndef le32toh #define le32toh letoh32 #endif #ifndef le64toh #define le64toh letoh64 #endif #define E_ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1)) #define ELWIX_SYSM 0 #define ELWIX_MPOOL 1 #define VACUUM_LEFT 1 #define VACUUM_BETWEEN 2 // elwix_SetProg() Set program memory pool name inline void elwix_SetProg(const char *csProgName); // elwix_GetProg() Get program memory pool name inline const char *elwix_GetProg(); // elwix_GetErrno() Get error code of last operation inline int elwix_GetErrno(); // elwix_GetError() Get error text of last operation inline const char *elwix_GetError(); // elwix_mm_inuse() Check for memory management model inline int elwix_mm_inuse(); /* * elwixInit() - Init libelwix library memory management * * @mm = memory management (IO_SYSM or IO_MPOOL) * @maxmem = memory limit * return: -1 error or !=-1 used memory management model */ inline int elwixInit(int mm, unsigned long maxmem); /* * elwixFini() - Finish libelwix library memory management * * return: none */ inline void elwixFini(); /* memory management hooks */ extern void *(*e_malloc)(size_t); extern void *(*e_calloc)(size_t, size_t); extern void *(*e_realloc)(void*, size_t); extern char *(*e_strdup)(const char*); extern void (*e_free)(void*); /* Debug helper macros */ /* Verbose macros */ extern int elwix_Verbose; #define e_initVerbose(x) (elwix_Verbose = (x)) #define e_incVerbose (elwix_Verbose++) #define e_decVerbose (elwix_Verbose--) #define EVERBOSE(x) if ((x) <= elwix_Verbose) /* Debug macros */ extern int elwix_Debug; #define ELWIX_DEBUG_OFF 0x0 #define ELWIX_DEBUG_TRACE 0x1 #define ELWIX_DEBUG_LOG 0x2 #define ELWIX_DEBUG_ANY 0xFFFFFFFF #define ETRACE(x) if (elwix_Debug & ELWIX_DEBUG_TRACE) \ syslog(LOG_DEBUG, "I'm in %s(%d)", __func__, __LINE__) #define EDEBUG(x, fmt, ...) do { assert((fmt)); \ if ((x) & elwix_Debug) { \ char str[BUFSIZ] = { 0 }; \ snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \ syslog(LOG_DEBUG, "Debug(%d):%s(%d): %s\n", \ (x), __func__, __LINE__, str); \ } \ } while (0) /* Logger macro */ #define ELOGGER(x, fmt, ...) do { assert((fmt)); \ char str[BUFSIZ] = { 0 }; \ snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \ syslog((x), "Logger:%s(%d): %s\n", \ __func__, __LINE__, str); \ } while (0) /* Error state macros */ #define EERROR(x, fmt, ...) do { assert((fmt)); \ char str[BUFSIZ] = { 0 }; \ snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \ syslog(LOG_ERR, "Error:%s(%d): #%d - %s\n", \ __func__, __LINE__, (x), str); \ } while (0) #define ESYSERR(x) do { \ if (x > 0 || errno) \ syslog(LOG_ERR, "Error(sys):%s(%d): #%d - %s\n", \ __func__, __LINE__, x > 0 ? x : errno, \ strerror(x > 0 ? x : errno)); \ } while (0) #define ELIBERR(ait) do { \ if (ait##_GetErrno()) \ syslog(LOG_ERR, "Error(lib):%s(%d): #%d - %s\n", \ __func__, __LINE__, ait##_GetErrno(), \ ait##_GetError()); \ } while (0) #endif