-default_CONFIG = CONFIG_OC_SOLIBS=x
+default_CONFIG = CONFIG_OC_ULUT=y
+default_CONFIG += CONFIG_OC_ULUTRTL=n
+default_CONFIG += CONFIG_OC_SOLIBS=x
-lib_LIBRARIES = ulut
-
-ifeq ($(CONFIG_OC_SOLIBS),y)
-shared_LIBRARIES = ulut
-endif
+ifeq ($(CONFIG_OC_ULUT),y)
include_HEADERS = ul_dbuff.h ul_evcbase.h ul_gavl.h ul_gavlcust.h \
ul_gavlflesint.h ul_gavlrepcust.h ul_gsa.h ul_gsacust.h \
ul_hptree.h ul_htimdefs.h ul_htimer.h ul_itbase.h \
ul_list.h ul_listbase.h ul_utdefs.h ul_utmalloc.h \
- ul_uniqid.h ul_dbufflog.h
+ ul_uniqid.h ul_dbufflog.h ul_log.h ul_logbase.h
+
+lib_LIBRARIES = ulut
+
+ifeq ($(CONFIG_OC_SOLIBS),y)
+shared_LIBRARIES = ulut
+endif
ulut_SOURCES = ul_dbufbase.c ul_dbufmore.c ul_gsa.c ul_gsacust.c \
ul_gavlprim.c ul_gavl.c ul_hptree.c \
ul_htimer.c ul_htimbase.c ul_htimmstime.c \
- ul_evcbase.c ul_uniqid.c
+ ul_evcbase.c ul_uniqid.c ul_dbufflog.c ul_logbase.c
#ulut_SOURCES += ul_dbufflog.c
ul_gsachk_SOURCES = ul_gsachk.c
ul_htimchk_SOURCES = ul_htimchk.c
+endif
+
# RT-Linux version of build
+ifeq ($(CONFIG_OC_ULUTRLT),y)
+
rtlinux_INCLUDES = -DUL_WITH_RTL_MALLOC
rtlinux_LIBRARIES = ulutrtl
$(rtlinux_with_malloc_HEADERS)
ulutkern_SOURCES = ul_gavlprim.c ul_htimer.c ul_htimbase.c
+
+endif
\ No newline at end of file
--- /dev/null
+/*******************************************************************
+ uLan Utilities Library - C library of basic reusable constructions
+
+ ul_log.h - standard logging facility
+
+ (C) Copyright 2005 by Pavel Pisa - Originator
+
+ The uLan utilities library can be used, copied and modified under
+ next licenses
+ - GPL - GNU General Public License
+ - LGPL - GNU Lesser General Public License
+ - MPL - Mozilla Public License
+ - and other licenses added by project originators
+ Code can be modified and re-distributed under any combination
+ of the above listed licenses. If contributor does not agree with
+ some of the licenses, he/she can delete appropriate line.
+ Warning, if you delete all lines, you are not allowed to
+ distribute source code and/or binaries utilizing code.
+
+ See files COPYING and README for details.
+
+ *******************************************************************/
+
+#include <ul_logbase.h>
+
+#define UL_LOG_CUST(log_domain) \
+\
+ul_log_domain_t log_domain; \
+\
+static inline \
+void ul_loglev(int level, const char *format, ...) UL_ATTR_PRINTF (2, 3);\
+static inline \
+void ul_vloglev(int level, const char *format, va_list ap) \
+{ \
+ ul_vlog(&log_domain, level, format, ap); \
+} \
+\
+static inline \
+void ul_loglev(int level, const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(level, format, ap); \
+ va_end(ap); \
+} \
+\
+static inline \
+void ul_logfatal(const char *format, ...) UL_ATTR_PRINTF (1, 2);\
+static inline \
+void ul_logfatal(const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(UL_LOGL_FATAL, format, ap); \
+ va_end(ap); \
+}\
+\
+static inline \
+void ul_logerr(const char *format, ...) UL_ATTR_PRINTF (1, 2);\
+static inline \
+void ul_logerr(const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(UL_LOGL_ERR, format, ap); \
+ va_end(ap); \
+} \
+\
+static inline \
+void ul_logmsg(const char *format, ...) UL_ATTR_PRINTF (1, 2);\
+static inline \
+void ul_logmsg(const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(UL_LOGL_MSG, format, ap); \
+ va_end(ap); \
+} \
+\
+static inline \
+void ul_loginf(const char *format, ...) UL_ATTR_PRINTF (1, 2);\
+static inline \
+void ul_loginf(const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(UL_LOGL_INF, format, ap); \
+ va_end(ap); \
+} \
+\
+static inline \
+void ul_logdeb(const char *format, ...) UL_ATTR_PRINTF (1, 2);\
+static inline \
+void ul_logdeb(const char *format, ...) \
+{ \
+ va_list ap; \
+ va_start(ap, format); \
+ ul_vloglev(UL_LOGL_DEB, format, ap); \
+ va_end(ap); \
+}
--- /dev/null
+/*******************************************************************
+ uLan Utilities Library - C library of basic reusable constructions
+
+ ul_logbase.c - base of standard logging facility
+
+ (C) Copyright 2003 by Pavel Pisa - Originator
+
+ The uLan utilities library can be used, copied and modified under
+ next licenses
+ - GPL - GNU General Public License
+ - LGPL - GNU Lesser General Public License
+ - MPL - Mozilla Public License
+ - and other licenses added by project originators
+ Code can be modified and re-distributed under any combination
+ of the above listed licenses. If contributor does not agree with
+ some of the licenses, he/she can delete appropriate line.
+ Warning, if you delete all lines, you are not allowed to
+ distribute source code and/or binaries utilizing code.
+
+ See files COPYING and README for details.
+
+ *******************************************************************/
+
+#ifndef __RTL__
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdarg.h>
+
+#else /*__RTL__*/
+
+#include <rtl.h>
+#include <string.h>
+#include <signal.h>
+#include <posix/unistd.h>
+
+#endif /*__RTL__*/
+
+#include "ul_utdefs.h"
+#include "ul_logbase.h"
+
+
+int ul_debug_flg;
+int ul_log_cutoff_level;
+
+#ifdef UL_LOG_NOINLINE
+
+int ul_log_cond(ul_log_domain_t *domain, int level)
+{
+ if(!domain || (level > UL_LOGL_MAX))
+ return 0;
+ return level <= domain->level;
+}
+
+void ul_vlog(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ if(!ul_log_cond(domain,level))
+ return;
+ ul_vlog1(domain, level, format, ap);
+}
+
+void ul_log(ul_log_domain_t *domain, int level,
+ const char *format, ...)
+{
+ va_list ap;
+
+ if(!ul_log_cond(domain,level))
+ return;
+ va_start (ap, format);
+ ul_vlog1(domain, level, format, ap);
+ va_end (ap);
+}
+
+#endif /*UL_LOG_NOINLINE*/
+
+
+void
+ul_log_fnc_default(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap);
+
+ul_log_fnc_t *ul_log_output;
+#ifndef __RTL__
+FILE *ul_log_default_file;
+#endif /*__RTL__*/
+
+/**
+ * ul_log - generic logging facility for ULUT library
+ * @domain: pointer to domain of debugging messages
+ * @level: severity level
+ * @format: printf style format followed by arguments
+ *
+ * This functions is used for logging of various events.
+ * If not overridden by application, logged messages goes to the stderr.
+ * Environment variable %UL_LOG_FILENAME can be used to redirect
+ * output to file. Environment variable %UL_DEBUG_FLG can be used
+ * to select different set of logged events through ul_debug_flg.
+ *
+ * Note: There is a global variable %ul_log_cutoff_level.
+ * Only the messages with %level <= %ul_log_cutoff_level will be logged.
+ */
+
+void
+ul_log1(ul_log_domain_t *domain, int level,
+ const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ ul_vlog1(domain,level,format,ap);
+ va_end(ap);
+}
+
+void
+ul_vlog1(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ #ifndef __RTL__
+ char *s;
+ char *log_fname;
+ #endif /*__RTL__*/
+ if(ul_log_cutoff_level) {
+ if((level & UL_LOGL_MASK) > ul_log_cutoff_level) return;
+ }
+ if(ul_log_output==NULL) {
+ ul_log_output=ul_log_fnc_default;
+ #ifndef __RTL__
+ if((log_fname=getenv("UL_LOG_FILENAME"))!=NULL){
+ ul_log_default_file=fopen(log_fname,"a");
+ }
+ if(ul_log_default_file==NULL)
+ ul_log_default_file=stderr;
+ if(!ul_debug_flg&&((s=getenv("UL_DEBUG_FLG"))!=NULL)){
+ ul_debug_flg=atoi(s);
+ }
+ if((s = getenv("UL_LOG_CUTTOFF")) != NULL) {
+ ul_log_cutoff_level = atoi(s);
+ }
+ #endif /*__RTL__*/
+ }
+ (*ul_log_output)(domain,level,format,ap);
+}
+
+/**
+ * ul_log_redir - redirects default log output function
+ * @log_fnc: new log output function. Value NULL resets
+ * to default function
+ * @add_flags: some more flags
+ */
+
+void
+ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags)
+{
+ if(log_fnc==NULL) log_fnc=ul_log_fnc_default;
+ ul_log_output=log_fnc;
+}
+
+#ifndef __RTL__
+void
+ul_log_fnc_default(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ if(!(level&UL_LOGL_CONT)) {
+ level&=UL_LOGL_MASK;
+ if(level)
+ fprintf(ul_log_default_file,"<%d>",level);
+ if(domain && domain->name)
+ fprintf(ul_log_default_file,"%s: ",domain->name);
+ }
+ vfprintf(ul_log_default_file, format, ap);
+ fflush(ul_log_default_file);
+}
+
+
+#else /*__RTL__*/
+void
+ul_log_fnc_default(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ if(!(level&UL_LOGL_CONT)) {
+ level&=UL_LOGL_MASK;
+ if(level)
+ rtl_printf("<%d>",level);
+ if(domain && domain->name)
+ rtl_printf("%s: ",domain->name);
+ }
+ rtl_vprintf(format, ap);
+}
+
+#endif /*__RTL__*/
+
--- /dev/null
+/*******************************************************************
+ uLan Utilities Library - C library of basic reusable constructions
+
+ ul_logbase.h - base of standard logging facility
+
+ (C) Copyright 2005 by Pavel Pisa - Originator
+
+ The uLan utilities library can be used, copied and modified under
+ next licenses
+ - GPL - GNU General Public License
+ - LGPL - GNU Lesser General Public License
+ - MPL - Mozilla Public License
+ - and other licenses added by project originators
+ Code can be modified and re-distributed under any combination
+ of the above listed licenses. If contributor does not agree with
+ some of the licenses, he/she can delete appropriate line.
+ Warning, if you delete all lines, you are not allowed to
+ distribute source code and/or binaries utilizing code.
+
+ See files COPYING and README for details.
+
+ *******************************************************************/
+
+#ifndef _UL_LOGBASE_H
+#define _UL_LOGBASE_H
+
+#include <stdarg.h>
+#include "ul_utdefs.h"
+
+#define UL_LOGL_MASK (0xff)
+#define UL_LOGL_CONT (0x1000)
+
+#define UL_LOGL_FATAL 1
+#define UL_LOGL_ERR 2
+#define UL_LOGL_MSG 3
+#define UL_LOGL_INF 4
+#define UL_LOGL_DEB 5
+#define UL_LOGL_TRASH 6
+
+#ifndef UL_LOGL_MAX
+#define UL_LOGL_MAX 6
+#endif
+
+/**
+ * struct ul_log_domain - Loggomg domain structure
+ * @level: maximal enabled logging level for domain
+ * @name: logging domain name
+ * @flags: logging domain flags
+ */
+typedef struct ul_log_domain {
+ int level;
+ const char *name;
+ int flags;
+} ul_log_domain_t;
+
+typedef void (ul_log_fnc_t)(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap);
+
+void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags);
+
+void ul_vlog1(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap);
+
+void ul_log1(ul_log_domain_t *domain, int level,
+ const char *format, ...) UL_ATTR_PRINTF (3, 4);
+
+#ifdef UL_LOG_NOINLINE
+
+int ul_log_cond(ul_log_domain_t *domain, int level);
+
+void ul_vlog(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap);
+
+void ul_log(ul_log_domain_t *domain, int level,
+ const char *format, ...) UL_ATTR_PRINTF (3, 4);
+
+#else /*UL_LOG_NOINLINE*/
+
+static inline
+int ul_log_cond(ul_log_domain_t *domain, int level)
+{
+ if(!domain || (level > UL_LOGL_MAX))
+ return 0;
+ return level <= domain->level;
+}
+
+static inline
+void ul_vlog(ul_log_domain_t *domain, int level,
+ const char *format, va_list ap)
+{
+ if(!ul_log_cond(domain,level))
+ return;
+ ul_vlog1(domain, level, format, ap);
+}
+
+static inline
+void ul_log(ul_log_domain_t *domain, int level,
+ const char *format, ...) UL_ATTR_PRINTF (3, 4);
+
+static inline
+void ul_log(ul_log_domain_t *domain, int level,
+ const char *format, ...)
+{
+ va_list ap;
+
+ if(!ul_log_cond(domain,level))
+ return;
+ va_start (ap, format);
+ ul_vlog1(domain, level, format, ap);
+ va_end (ap);
+}
+
+#endif /*UL_LOG_NOINLINE*/
+
+#endif /*_UL_LOGBASE_H*/
--- /dev/null
+/*******************************************************************
+ uLan Utilities Library - C library of basic reusable constructions
+
+ ul_logbuf.c - circular log buffer
+
+ (C) Copyright 2006 by Pavel Pisa - Originator
+
+ The uLan utilities library can be used, copied and modified under
+ next licenses
+ - GPL - GNU General Public License
+ - LGPL - GNU Lesser General Public License
+ - MPL - Mozilla Public License
+ - and other licenses added by project originators
+ Code can be modified and re-distributed under any combination
+ of the above listed licenses. If contributor does not agree with
+ some of the licenses, he/she can delete appropriate line.
+ Warning, if you delete all lines, you are not allowed to
+ distribute source code and/or binaries utilizing code.
+
+ See files COPYING and README for details.
+
+ *******************************************************************/
+
+#ifndef __RTL__
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdarg.h>
+
+#else /*__RTL__*/
+
+#include <rtl.h>
+#include <string.h>
+#include <signal.h>
+#include <posix/unistd.h>
+
+#endif /*__RTL__*/
+
+#include "ul_utdefs.h"
+#include "ul_logbase.h"
+
+typedef struct ul_log_buff {
+ unsigned char *buf_beg;
+ unsigned char *buf_end;
+ unsigned char *ip;
+ unsigned char *op;
+} ul_log_buff_t;
+
+
+ul_log_domain_t *domain