summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wimaxll/Makefile.am4
-rw-r--r--include/wimaxll/Makefile.in2
-rw-r--r--include/wimaxll/log.h116
-rw-r--r--lib/Makefile.am8
-rw-r--r--lib/Makefile.in31
-rw-r--r--lib/log.c201
6 files changed, 348 insertions, 14 deletions
diff --git a/include/wimaxll/Makefile.am b/include/wimaxll/Makefile.am
index 23b517a..fcef043 100644
--- a/include/wimaxll/Makefile.am
+++ b/include/wimaxll/Makefile.am
@@ -1,3 +1,5 @@
wimaxllincludedir = @includedir@/wimaxll
-wimaxllinclude_HEADERS = \
+wimaxllinclude_HEADERS = \
+ cmd.h \
+ log.h \
version.h
diff --git a/include/wimaxll/Makefile.in b/include/wimaxll/Makefile.in
index 3ce3f9b..72f35e2 100644
--- a/include/wimaxll/Makefile.in
+++ b/include/wimaxll/Makefile.in
@@ -175,6 +175,8 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
wimaxllincludedir = @includedir@/wimaxll
wimaxllinclude_HEADERS = \
+ cmd.h \
+ log.h \
version.h
all: all-am
diff --git a/include/wimaxll/log.h b/include/wimaxll/log.h
new file mode 100644
index 0000000..bb955b3
--- /dev/null
+++ b/include/wimaxll/log.h
@@ -0,0 +1,116 @@
+/*
+ * Linux WiMax
+ * Simple log helpers
+ *
+ *
+ * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
+ * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Intel Corporation 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 THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ */
+/**
+ *
+ * \defgroup helper_log Set of simple log helpers
+ *
+ * Log messages to stdout/stderr, with simple log level management.
+ *
+ * If the log level is W_PRINT, we assume is a normal message that the
+ * user wants to see and send it to stdout. If it is any other,
+ * evaluate if it should be printed based on the current level and
+ * then print it to stderr.
+ *
+ * Before including, W_VERBOSITY must be defined to something that
+ * yields a numeric value out of of \e { enum w_levels }. When any of
+ * the w_*() functions/macros is called, if the level it is called
+ * with is less or equal than the current level defied by W_VERBOSITY,
+ * it'll be ran, if not, it'll be ignored:
+ *
+ * @code
+ *
+ * #define W_VERBOSITY W_INFO (or myglobalstruct.verbosity)
+ * #include <wimaxll/log.h>
+ *
+ * somefunc()
+ * {
+ * ...
+ * w_d1("debug message\n");
+ * ...
+ * }
+ *
+ * @endcode
+ */
+
+#ifndef __wimaxll__log_h__
+#define __wimaxll__log_h__
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifndef W_VERBOSITY
+#error Please #define W_VERBOSITY before including this file
+#endif
+
+/* Logging / printing */
+enum w_levels {
+ W_ERROR,
+ W_WARN,
+ W_INFO,
+ W_PRINT,
+ W_D0,
+ W_D1,
+ W_D2,
+ W_D3,
+ W_D4,
+ W_D5,
+ W_D6,
+ W_D7,
+};
+
+void __w_vmsg(unsigned level, unsigned current_level,
+ const char *tag, unsigned line,
+ const char *fmt, va_list vargs);
+
+void __w_msg(unsigned level, unsigned current_level,
+ const char *tag, unsigned line,
+ const char *fmt, ...);
+
+void w_abort(int result, const char *fmt, ...);
+
+#define w_error(fmt...) __w_msg(W_ERROR, W_VERBOSITY, __func__, __LINE__, "E: " fmt)
+#define w_warn(fmt...) __w_msg(W_WARN, W_VERBOSITY, __func__, __LINE__, "W: " fmt)
+#define w_info(fmt...) __w_msg(W_INFO, W_VERBOSITY, __func__, __LINE__, "I: " fmt)
+#define w_print(fmt...) __w_msg(W_PRINT, W_VERBOSITY, __func__, __LINE__, fmt)
+#define w_d0(fmt...) __w_msg(W_D0, W_VERBOSITY, __func__, __LINE__, "D0: " fmt)
+#define w_d1(fmt...) __w_msg(W_D1, W_VERBOSITY, __func__, __LINE__, "D1: " fmt)
+#define w_d2(fmt...) __w_msg(W_D2, W_VERBOSITY, __func__, __LINE__, "D2: " fmt)
+#define w_d3(fmt...) __w_msg(W_D3, W_VERBOSITY, __func__, __LINE__, "D3: " fmt)
+#define w_d4(fmt...) __w_msg(W_D4, W_VERBOSITY, __func__, __LINE__, "D4: " fmt)
+#define w_d5(fmt...) __w_msg(W_D5, W_VERBOSITY, __func__, __LINE__, "D5: " fmt)
+#define w_d6(fmt...) __w_msg(W_D6, W_VERBOSITY, __func__, __LINE__, "D6: " fmt)
+#define w_d7(fmt...) __w_msg(W_D7, W_VERBOSITY, __func__, __LINE__, "D7: " fmt)
+
+#endif /* #define __wimaxll__log_h__ */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 235604b..272c8d5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -6,10 +6,9 @@ INCLUDES = \
noinst_HEADERS = debug.h internal.h
-lib_LTLIBRARIES = libwimaxll.la
-lib_LIBRARIES = libwimaxll.a
libwimaxll_sources = \
genl.c \
+ log.c \
misc.c \
op-open.c \
op-msg.c \
@@ -26,9 +25,12 @@ libwimaxll_la_CFLAGS = $(AM_CFLAGS)
# REVISION: inc for changes that do not affect the external interface
# AGE: inc for added interfaces
# set to zero if removed existing interfaces
-libwimaxll_la_LDFLAGS = -version-info 1:0:0 $(LIBNL1_LIBS)
+libwimaxll_la_LDFLAGS = -version-info 1:0:1 $(LIBNL1_LIBS)
libwimaxll_a_SOURCES = $(libwimaxll_sources)
+lib_LTLIBRARIES = libwimaxll.la
+lib_LIBRARIES = libwimaxll.a
+
BUILT_SOURCES = names-vals.h
enum_names = \
diff --git a/lib/Makefile.in b/lib/Makefile.in
index a66d010..e238c6c 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -57,18 +57,19 @@ LIBRARIES = $(lib_LIBRARIES)
ARFLAGS = cru
libwimaxll_a_AR = $(AR) $(ARFLAGS)
libwimaxll_a_LIBADD =
-am__objects_1 = genl.$(OBJEXT) misc.$(OBJEXT) op-open.$(OBJEXT) \
- op-msg.$(OBJEXT) op-reset.$(OBJEXT) op-rfkill.$(OBJEXT) \
- re-state-change.$(OBJEXT) wimax.$(OBJEXT)
+am__objects_1 = genl.$(OBJEXT) log.$(OBJEXT) misc.$(OBJEXT) \
+ op-open.$(OBJEXT) op-msg.$(OBJEXT) op-reset.$(OBJEXT) \
+ op-rfkill.$(OBJEXT) re-state-change.$(OBJEXT) wimax.$(OBJEXT)
am_libwimaxll_a_OBJECTS = $(am__objects_1)
libwimaxll_a_OBJECTS = $(am_libwimaxll_a_OBJECTS)
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libwimaxll_la_LIBADD =
-am__objects_2 = libwimaxll_la-genl.lo libwimaxll_la-misc.lo \
- libwimaxll_la-op-open.lo libwimaxll_la-op-msg.lo \
- libwimaxll_la-op-reset.lo libwimaxll_la-op-rfkill.lo \
- libwimaxll_la-re-state-change.lo libwimaxll_la-wimax.lo
+am__objects_2 = libwimaxll_la-genl.lo libwimaxll_la-log.lo \
+ libwimaxll_la-misc.lo libwimaxll_la-op-open.lo \
+ libwimaxll_la-op-msg.lo libwimaxll_la-op-reset.lo \
+ libwimaxll_la-op-rfkill.lo libwimaxll_la-re-state-change.lo \
+ libwimaxll_la-wimax.lo
am_libwimaxll_la_OBJECTS = $(am__objects_2)
libwimaxll_la_OBJECTS = $(am_libwimaxll_la_OBJECTS)
libwimaxll_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -216,10 +217,9 @@ INCLUDES = \
$(I2400M_INCLUDES)
noinst_HEADERS = debug.h internal.h
-lib_LTLIBRARIES = libwimaxll.la
-lib_LIBRARIES = libwimaxll.a
libwimaxll_sources = \
genl.c \
+ log.c \
misc.c \
op-open.c \
op-msg.c \
@@ -236,8 +236,10 @@ libwimaxll_la_CFLAGS = $(AM_CFLAGS)
# REVISION: inc for changes that do not affect the external interface
# AGE: inc for added interfaces
# set to zero if removed existing interfaces
-libwimaxll_la_LDFLAGS = -version-info 1:0:0 $(LIBNL1_LIBS)
+libwimaxll_la_LDFLAGS = -version-info 1:0:1 $(LIBNL1_LIBS)
libwimaxll_a_SOURCES = $(libwimaxll_sources)
+lib_LTLIBRARIES = libwimaxll.la
+lib_LIBRARIES = libwimaxll.a
BUILT_SOURCES = names-vals.h
enum_names = \
wimax_st
@@ -350,6 +352,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-genl.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-log.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-misc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-op-msg.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-op-open.Plo@am__quote@
@@ -357,6 +360,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-op-rfkill.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-re-state-change.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libwimaxll_la-wimax.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/op-msg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/op-open.Po@am__quote@
@@ -393,6 +397,13 @@ libwimaxll_la-genl.lo: genl.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libwimaxll_la_CFLAGS) $(CFLAGS) -c -o libwimaxll_la-genl.lo `test -f 'genl.c' || echo '$(srcdir)/'`genl.c
+libwimaxll_la-log.lo: log.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libwimaxll_la_CFLAGS) $(CFLAGS) -MT libwimaxll_la-log.lo -MD -MP -MF $(DEPDIR)/libwimaxll_la-log.Tpo -c -o libwimaxll_la-log.lo `test -f 'log.c' || echo '$(srcdir)/'`log.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libwimaxll_la-log.Tpo $(DEPDIR)/libwimaxll_la-log.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='log.c' object='libwimaxll_la-log.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libwimaxll_la_CFLAGS) $(CFLAGS) -c -o libwimaxll_la-log.lo `test -f 'log.c' || echo '$(srcdir)/'`log.c
+
libwimaxll_la-misc.lo: misc.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libwimaxll_la_CFLAGS) $(CFLAGS) -MT libwimaxll_la-misc.lo -MD -MP -MF $(DEPDIR)/libwimaxll_la-misc.Tpo -c -o libwimaxll_la-misc.lo `test -f 'misc.c' || echo '$(srcdir)/'`misc.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libwimaxll_la-misc.Tpo $(DEPDIR)/libwimaxll_la-misc.Plo
diff --git a/lib/log.c b/lib/log.c
new file mode 100644
index 0000000..29463c8
--- /dev/null
+++ b/lib/log.c
@@ -0,0 +1,201 @@
+/*
+ * Linux WiMax
+ * log helpers
+ *
+ *
+ * Copyright (C) 2009 Intel Corporation. All rights reserved.
+ * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Intel Corporation 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 THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ */
+#include <stdlib.h>
+#define W_VERBOSITY W_ERROR
+#include <wimaxll/log.h>
+
+
+/**
+ * Log a message to (varargs version) if log level allows it
+ *
+ * \param level level of the messagve
+ * \param current_level current logging level
+ * \param tag a str to print along with \e line (if not NULL, its
+ * not printed).
+ * \param line an integer to print along with \e tag (if \e tag is not
+ * NULL)
+ * \param fmt printf-like format string
+ * \param vargs arguments to \e fmt
+ *
+ * \internal
+ *
+ * Use w_*() functions only
+ *
+ * @ingroup: helper_log
+ */
+void __w_vmsg(unsigned level, unsigned current_level,
+ const char *tag, unsigned line,
+ const char *fmt, va_list vargs)
+{
+ FILE *f;
+ f = level != W_PRINT? stderr : stdout;
+ if (level <= current_level || level == W_PRINT) {
+ if (tag)
+ fprintf(f, "%s:%u: ", tag, line);
+ vfprintf(f, fmt, vargs);
+ }
+}
+
+
+/**
+ * Log a message to if log level allows it
+ *
+ * \param level level of the messagve
+ * \param current_level current logging level
+ * \param tag a str to print along with \e line (if not NULL, its
+ * not printed).
+ * \param line an integer to print along with \e tag (if \e tag is not
+ * NULL)
+ * \param fmt printf-like format string, plus their arguments
+ *
+ * \internal
+ *
+ * Use w_*() functions only
+ *
+ * @ingroup: helper_log
+ */
+void __w_msg(unsigned level, unsigned current_level,
+ const char *tag, unsigned line,
+ const char *fmt, ...)
+{
+ va_list vargs;
+ va_start(vargs, fmt);
+ __w_vmsg(level, current_level, tag, line, fmt, vargs);
+ va_end(vargs);
+}
+
+
+/**
+ * Log an error message to stderr and abort
+ *
+ * \param result exit code to abort with
+ * \param fmt: printf-like format string and its arguments
+ *
+ * @ingroup: helper_log
+ */
+void w_abort(int result, const char *fmt, ...)
+{
+ va_list vargs;
+ va_start(vargs, fmt);
+ __w_vmsg(W_ERROR, W_ERROR, __FILE__, __LINE__, fmt, vargs);
+ va_end(vargs);
+ exit(result);
+}
+
+/* These are defined in the header file */
+
+/**
+ * Log a printf-like error message to stderr
+ *
+ * @fn w_error(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like warning message to stderr
+ *
+ * @fn w_warn(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like error message to stderr
+ *
+ * @fn w_info(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like error message to stdout
+ *
+ * @fn w_print(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 0)
+ *
+ * @fn w_d0(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 1)
+ *
+ * @fn w_d1(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 2)
+ *
+ * @fn w_d2(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 3)
+ *
+ * @fn w_d3(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 4)
+ *
+ * @fn w_d4(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 5)
+ *
+ * @fn w_d5(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 6)
+ *
+ * @fn w_d6(fmt...)
+ * @ingroup helper_log
+ */
+
+/**
+ * Log a printf-like debug message (level 7)
+ *
+ * @fn w_d7(fmt...)
+ * @ingroup helper_log
+ */