r4088 - in trunk/sfi: . tests



Author: timj
Date: 2006-11-20 19:19:43 -0500 (Mon, 20 Nov 2006)
New Revision: 4088

Removed:
   trunk/sfi/sfimsg.c
   trunk/sfi/sfimsg.h
Modified:
   trunk/sfi/ChangeLog
   trunk/sfi/Makefile.am
   trunk/sfi/glib-extra.h
   trunk/sfi/sfi.h
   trunk/sfi/sficomport.c
   trunk/sfi/sficxx.cc
   trunk/sfi/sfiglue.c
   trunk/sfi/sfigluecodec.c
   trunk/sfi/sfiglueproxy.c
   trunk/sfi/sfistore.c
   trunk/sfi/sfiwrapper.cc
   trunk/sfi/sfiwrapper.h
   trunk/sfi/tests/misctests.c
   trunk/sfi/tests/testsfidl.cc
Log:
Mon Nov 20 23:39:31 2006  Tim Janik  <timj gtk org>

        * sfiwrapper.h, sfiwrapper.cc: wrapped C++ Msg API.

        * glib-extra.h: removed g_static_assert(), we now have BIRNET_STATIC_ASSERT().

        * sfimsg.h, sfimsg.c: removed, obsoleted by C++ Msg API wrapper.

        * tests/misctests.c: added some sfi_msg_*() tests, mostly to check
        compilability of the provided macros.

        * tests/testsfidl.cc: fixed compiler warnings.




Modified: trunk/sfi/ChangeLog
===================================================================
--- trunk/sfi/ChangeLog	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/ChangeLog	2006-11-21 00:19:43 UTC (rev 4088)
@@ -1,3 +1,16 @@
+Mon Nov 20 23:39:31 2006  Tim Janik  <timj gtk org>
+
+	* sfiwrapper.h, sfiwrapper.cc: wrapped C++ Msg API.
+
+	* glib-extra.h: removed g_static_assert(), we now have BIRNET_STATIC_ASSERT().
+
+	* sfimsg.h, sfimsg.c: removed, obsoleted by C++ Msg API wrapper.
+
+	* tests/misctests.c: added some sfi_msg_*() tests, mostly to check
+	compilability of the provided macros.
+
+	* tests/testsfidl.cc: fixed compiler warnings.
+
 Wed Nov 15 00:23:44 2006  Tim Janik  <timj gtk org>
 
 	* sfidl-parser.cc (parseParamHints): serialize int parameters with LL

Modified: trunk/sfi/Makefile.am
===================================================================
--- trunk/sfi/Makefile.am	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/Makefile.am	2006-11-21 00:19:43 UTC (rev 4088)
@@ -10,7 +10,7 @@
 
 sfi_public_headers = $(strip \
 	sfistore.h	sficomwire.h	sfifilecrawler.h \
-	glib-extra.h	sfimsg.h	sfiwrapper.h	 \
+	glib-extra.h			sfiwrapper.h	 \
 	sfivmarshal.h	sfiglue.h	sfigluecodec.h	sfiglueproxy.h	\
 	sfinote.h	sfiparams.h	sfiprimitives.h	sfiserial.h	\
 	sfitime.h	sfitypes.h	sfivalues.h	sfiustore.h	\
@@ -19,7 +19,7 @@
 )
 sfi_all_sources = $(strip \
 	sfistore.c	sficomwire.c	sfifilecrawler.c \
-	glib-extra.c	sfimsg.c	sfiwrapper.cc	 \
+	glib-extra.c			sfiwrapper.cc	 \
 	sfivmarshal.c	sfiglue.c	sfigluecodec.c	sfiglueproxy.c	\
 	sfinote.c	sfiparams.c	sfiprimitives.c	sfiserial.c	\
 	sfitime.c	sfitypes.c	sfivalues.c	sfiustore.c	\

Modified: trunk/sfi/glib-extra.h
===================================================================
--- trunk/sfi/glib-extra.h	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/glib-extra.h	2006-11-21 00:19:43 UTC (rev 4088)
@@ -24,11 +24,6 @@
 
 G_BEGIN_DECLS
 
-/* --- macros --- */
-#define G_CPP_PASTE2(a,b)       a ## b
-#define G_CPP_PASTE(a,b)        G_CPP_PASTE2 (a, b)
-#define g_static_assert(expr)   typedef struct { char assertion_failed[(expr) ? 1 : -1]; } G_CPP_PASTE (GLibStaticAssertion_LINE, __LINE__)
-
 #if (GLIB_SIZEOF_LONG > 4)
 #define G_HASH_LONG(l)	((l) + ((l) >> 32))
 #else
@@ -40,7 +35,7 @@
 #define G_HASH_POINTER(p)       ((guint32) (gsize) (p))
 #endif
 /* Provide a string identifying the current function, non-concatenatable */
-#ifndef G_STRFUNC       // GTKFIX: add this to glib
+#ifndef G_STRFUNC
 #  if defined (__GNUC__)
 #    define G_STRFUNC     ((const char*) (__PRETTY_FUNCTION__))
 #  elif defined (G_HAVE_ISO_VARARGS)

Modified: trunk/sfi/sfi.h
===================================================================
--- trunk/sfi/sfi.h	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfi.h	2006-11-21 00:19:43 UTC (rev 4088)
@@ -26,7 +26,6 @@
 #include <sfi/sfigluecodec.h>
 #include <sfi/sfiglueproxy.h>
 #include <sfi/sfimemory.h>
-#include <sfi/sfimsg.h>
 #include <sfi/sfinote.h>
 #include <sfi/sfiparams.h>
 #include <sfi/sfiprimitives.h>

Modified: trunk/sfi/sficomport.c
===================================================================
--- trunk/sfi/sficomport.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sficomport.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -20,7 +20,6 @@
 #include "sfiprimitives.h"
 #include "sfiserial.h"
 #include "sfistore.h"
-#include "sfimsg.h"
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>

Modified: trunk/sfi/sficxx.cc
===================================================================
--- trunk/sfi/sficxx.cc	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sficxx.cc	2006-11-21 00:19:43 UTC (rev 4088)
@@ -26,7 +26,6 @@
 {
   g_type_init ();       /* just in case this hasn't been called already */
 
-  _sfi_init_logging ();
   _sfi_init_values ();
   _sfi_init_params ();
   _sfi_init_time ();

Modified: trunk/sfi/sfiglue.c
===================================================================
--- trunk/sfi/sfiglue.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfiglue.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -20,7 +20,6 @@
 #include "sfiparams.h"
 #include "sfiglueproxy.h"
 #include "sfiustore.h"
-#include "sfimsg.h"
 #include <string.h>
 #include <gobject/gvaluecollector.h>
 

Modified: trunk/sfi/sfigluecodec.c
===================================================================
--- trunk/sfi/sfigluecodec.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfigluecodec.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -20,7 +20,6 @@
 #define	G_LOG_DOMAIN	"SFI-GLUE"
 #include "sfigluecodec.h"
 #include "sfiglueproxy.h"
-#include "sfimsg.h"
 
 
 /* --- prototypes --- */

Modified: trunk/sfi/sfiglueproxy.c
===================================================================
--- trunk/sfi/sfiglueproxy.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfiglueproxy.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -19,7 +19,6 @@
 #include <string.h>
 #include "sfiglueproxy.h"
 #include "sfiglue.h"
-#include "sfimsg.h"
 #include "sfiustore.h"
 #include "sfivmarshal.h"
 #include <gobject/gvaluecollector.h>

Deleted: trunk/sfi/sfimsg.c
===================================================================
--- trunk/sfi/sfimsg.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfimsg.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -1,821 +0,0 @@
-/* SfiMsg
- * Copyright (C) 2002-2006 Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include "sfimsg.h"
-#include "sfiwrapper.h"
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <syslog.h>
-
-#ifndef _ // FIXME
-#define _(x) x
-#endif
-
-typedef struct {
-  gchar            *ident;
-  gchar            *label;
-  SfiMsgType     default_type;
-  SfiMsgLogFlags log_flags : 16;
-  guint             disabled : 1;
-} MsgType;
-
-
-/* --- variables --- */
-static BirnetMutex       logging_mutex;
-static GQuark            quark_log_handler = 0;
-static GQuark            quark_msg_bits = 0;
-static guint             n_msg_types = 0;
-static MsgType          *msg_types = NULL;
-guint8 * volatile        sfi_msg_flags = NULL;
-volatile guint           sfi_msg_flags_max = 0;
-static guint             stdlog_syslog_priority = 0; // LOG_USER | LOG_INFO;
-static bool              stdlog_to_stderr = TRUE;
-static FILE             *stdlog_file = NULL;
-
-/* --- prototypoes --- */
-static void     sfi_log_msg_process     (const SfiMessage *msgp);
-static void     sfi_msg_type_set        (SfiMsgType     mtype,
-                                            SfiMsgLogFlags log_flags,
-                                            bool           enabled);
-
-/* --- functions --- */
-static void
-sfi_msg_type_init_internals (void)
-{
-  static volatile guint initialized = FALSE;
-  if (initialized || !sfi_atomic_uint_cas (&initialized, FALSE, TRUE))
-    return;
-  guint mtype;
-  /* SFI_MSG_NONE (always disabled) */
-  mtype = sfi_msg_type_register ("none", 0, NULL);
-  g_assert (mtype == SFI_MSG_NONE);
-  sfi_msg_type_set (SFI_MSG_NONE, 0, FALSE);
-  /* SFI_MSG_FATAL (always enabled) */
-  mtype = sfi_msg_type_register ("fatal", 1, _("Fatal Error"));
-  g_assert (mtype == SFI_MSG_FATAL);
-  sfi_msg_type_set (SFI_MSG_FATAL, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG | SFI_MSG_TO_HANDLER, TRUE);
-  /* SFI_MSG_ERROR (enabled) */
-  mtype = sfi_msg_type_register ("error", 1, _("Error"));
-  g_assert (mtype == SFI_MSG_ERROR);
-  sfi_msg_type_set (SFI_MSG_ERROR, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG | SFI_MSG_TO_HANDLER, TRUE);
-  /* SFI_MSG_WARNING (enabled) */
-  mtype = sfi_msg_type_register ("warning", 1, _("Warning"));
-  g_assert (mtype == SFI_MSG_WARNING);
-  sfi_msg_type_set (SFI_MSG_WARNING, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG | SFI_MSG_TO_HANDLER, TRUE);
-  /* SFI_MSG_SCRIPT (enabled) */
-  mtype = sfi_msg_type_register ("script", 1, _("Script"));
-  g_assert (mtype == SFI_MSG_SCRIPT);
-  sfi_msg_type_set (SFI_MSG_SCRIPT, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG | SFI_MSG_TO_HANDLER, TRUE);
-  /* SFI_MSG_INFO (enabled) */
-  mtype = sfi_msg_type_register ("info", 1, _("Information"));
-  g_assert (mtype == SFI_MSG_INFO);
-  sfi_msg_type_set (SFI_MSG_INFO, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG | SFI_MSG_TO_HANDLER, TRUE);
-  /* SFI_MSG_DIAG (enabled) */
-  mtype = sfi_msg_type_register ("diag", 1, _("Diagnostic"));
-  g_assert (mtype == SFI_MSG_DIAG);
-  sfi_msg_type_set (SFI_MSG_DIAG, SFI_MSG_TO_STDERR | SFI_MSG_TO_STDLOG, TRUE);
-  /* SFI_MSG_DEBUG (disabled) */
-  mtype = sfi_msg_type_register ("debug", 0, "Debug");
-  g_assert (mtype == SFI_MSG_DEBUG);
-  sfi_msg_type_set (SFI_MSG_DEBUG, SFI_MSG_TO_STDERR, FALSE);
-}
-
-void
-_sfi_init_logging (void)
-{
-  g_assert (quark_log_handler == 0);
-  quark_log_handler = g_quark_from_static_string ("SfiMsgHandler");
-  quark_msg_bits = g_quark_from_static_string ("SfiMsgBit-threadlist");
-  sfi_mutex_init (&logging_mutex);
-  sfi_msg_type_init_internals();
-}
-
-static inline void
-msg_type_set_intern (SfiMsgType     mtype,
-                     SfiMsgLogFlags log_flags,
-                     bool              enabled,
-                     bool              uncouple_default)
-{
-  if (mtype < n_msg_types)
-    {
-      msg_types[mtype].log_flags = log_flags;
-      msg_types[mtype].disabled = !enabled;
-      enabled = msg_types[mtype].log_flags && !msg_types[mtype].disabled;
-      if (enabled)
-        sfi_msg_flags[mtype / 8] |= 1 << mtype % 8;
-      else
-        sfi_msg_flags[mtype / 8] &= ~(1 << mtype % 8);
-      if (uncouple_default)
-        msg_types[mtype].default_type = mtype;
-    }
-}
-
-static void
-sfi_msg_type_set (SfiMsgType     mtype,
-                     SfiMsgLogFlags log_flags,
-                     bool              enabled)
-{
-  msg_type_set_intern (mtype, log_flags, enabled, TRUE);
-  guint i;
-  for (i = mtype + 1; i < n_msg_types; i++)
-    if (msg_types[i].default_type == mtype)
-      msg_type_set_intern (mtype, log_flags, enabled, FALSE);
-}
-
-/**
- * @param ident	message identifier
- * @param default_ouput	an existing SfiMsgType or FALSE or TRUE
- * @param label	a translated version of @a ident
- * @return		message type id
- *
- * Register a new message type with identifier @a ident and user digestible
- * name @a label. If this function is called multiple times with the same
- * identifier, the type id acquired by the first call will be returned
- * and the other arguments are ignored.
- * As long as the new message type isn't configured individually via
- * sfi_msg_enable(), sfi_msg_allow() or their complements, it shares
- * the configuration of @a default_ouput. If FALSE or TRUE is passed as
- * @a default_ouput, this corresponds to SFI_MSG_NONE or SFI_MSG_FATAL
- * respectively which are unconfigrable and always have their output
- * disabled or enabled respectively.
- * As an exception to the rest of the message API, this function may be
- * called before sfi_init(). However note, that MT-safety is only ensured
- * for calls occouring after sfi_init().
- * This function is MT-safe and may be called from any thread.
- */
-SfiMsgType
-sfi_msg_type_register (const gchar   *ident,
-                          SfiMsgType  default_ouput, /* FALSE, TRUE, SFI_MSG_* */
-                          const gchar   *label)
-{
-  /* ensure standard types are registered */
-  sfi_msg_type_init_internals();
-  /* check arguments */
-  g_return_val_if_fail (ident != NULL, 0);
-  if (default_ouput >= n_msg_types)
-    default_ouput = 0;
-  /* support concurrency after _sfi_init_logging() */
-  bool     need_unlock = FALSE;
-  if (quark_log_handler)
-    {
-      sfi_mutex_lock (&logging_mutex);
-      need_unlock = TRUE;
-    }
-  /* allow duplicate registration */
-  guint i;
-  for (i = SFI_MSG_LAST; i < n_msg_types; i++)
-    if (strcmp (ident, msg_types[i].ident) == 0)
-      {
-        /* found duplicate */
-        if (need_unlock)
-          sfi_mutex_unlock (&logging_mutex);
-        return i;
-      }
-  /* add new message type */
-  guint mtype = n_msg_types++;
-  msg_types = g_renew (MsgType, msg_types, n_msg_types);
-  memset (&msg_types[mtype], 0, sizeof (msg_types[mtype]));
-  guint old_flags_size = (mtype + 7) / 8;
-  guint new_flags_size = (n_msg_types + 7) / 8;
-  if (old_flags_size < new_flags_size)
-    {
-      guint8 *msg_flags = g_new (guint8, new_flags_size);
-      memcpy (msg_flags, (guint8*) sfi_msg_flags, sizeof (msg_flags[0]) * old_flags_size);
-      msg_flags[new_flags_size - 1] = 0;
-      guint8 *old_msg_flags = sfi_msg_flags;
-      /* we are holding a lock in the multi-threaded case so no need for compare_and_swap */
-      typedef guint8* X;
-      sfi_atomic_pointer_set ((void*) &sfi_msg_flags, msg_flags);
-      // FIXME: sfi_msg_flags should be registered as hazard pointer so we don't g_free() while other threads read old_msg_flags[*]
-      g_free (old_msg_flags);
-    }
-  msg_types[mtype].ident = g_strdup (ident);
-  msg_types[mtype].label = g_strdup (label);
-  sfi_msg_type_set (mtype, msg_types[default_ouput].log_flags, !msg_types[default_ouput].disabled);
-  msg_types[mtype].default_type = default_ouput;
-  sfi_atomic_uint_set (&sfi_msg_flags_max, mtype); /* only ever grows */
-  /* out of here */
-  if (need_unlock)
-    sfi_mutex_unlock (&logging_mutex);
-  return mtype;
-}
-
-static void
-key_list_change (const char *string,
-                 bool        flag_value)
-{
-  guint i, n;
-  /* ensure all keywords are enclosed in ':' */
-  char *s = g_strconcat (":", string, ":", NULL);
-  /* allow ',' seperation and collapse spaces */
-  for (i = 0, n = 0; s[i]; i++)
-    if (s[i] == ',')
-      s[n++] = ':';
-    else if (s[i] != ' ' && s[i] != '\t' && s[i] != '\n' && s[i] != '\r')
-      s[n++] = s[i];
-  s[n] = 0;
-  /* handle :all: special case */
-  if (strstr (s, ":all:"))
-    {
-      g_free (s);
-      for (i = SFI_MSG_DEBUG; i < n_msg_types; i++)
-        sfi_msg_type_set (i, msg_types[i].log_flags, flag_value);
-      return;
-    }
-  
-  /* walk all kyes */
-  char *k = s + 1;
-  char *p = strchr (k, ':');
-  while (p)
-    {
-      if (k < p)
-	{
-	  *p = 0;
-          for (i = SFI_MSG_DEBUG; i < n_msg_types; i++)
-            if (strcmp (k, msg_types[i].ident) == 0)
-              break;
-          if (i < n_msg_types)
-            sfi_msg_type_set (i, msg_types[i].log_flags, flag_value);
-	}
-      k = p + 1;
-      p = strchr (k, ':');
-    }
-  g_free (s);
-}
-
-void
-sfi_msg_allow (const char *key)
-{
-  sfi_mutex_lock (&logging_mutex);
-  if (key)
-    key_list_change (key, TRUE);
-  sfi_mutex_unlock (&logging_mutex);
-  
-#if 0
-  guint i;
-  for (i = 0; i < n_msg_types; i++)
-    g_printerr ("% 2d) %s: disabled=%d log_flags=0x%x label=%s cache=%d\n", i,
-                msg_types[i].ident, msg_types[i].disabled,
-                msg_types[i].log_flags, msg_types[i].label,
-                sfi_msg_check (i));
-#endif
-}
-
-void
-sfi_msg_deny (const char *key)
-{
-  sfi_mutex_lock (&logging_mutex);
-  if (key)
-    key_list_change (key, FALSE);
-  sfi_mutex_unlock (&logging_mutex);
-}
-
-void
-sfi_msg_enable (SfiMsgType mtype)
-{
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype > 1 && mtype < n_msg_types)
-    sfi_msg_type_set (mtype, msg_types[mtype].log_flags, TRUE);
-  sfi_mutex_unlock (&logging_mutex);
-}
-
-void
-sfi_msg_disable (SfiMsgType mtype)
-{
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype > 1 && mtype < n_msg_types)
-    sfi_msg_type_set (mtype, msg_types[mtype].log_flags, FALSE);
-  sfi_mutex_unlock (&logging_mutex);
-}
-
-void
-sfi_msg_type_configure (SfiMsgType        mtype,
-                           SfiMsgLogFlags    channel_mask,
-                           const gchar         *dummy_filename)
-{
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype > 1 && mtype < n_msg_types)
-    sfi_msg_type_set (mtype, channel_mask, !msg_types[mtype].disabled);
-  sfi_mutex_unlock (&logging_mutex);
-}
-
-void
-sfi_msg_configure_stdlog (bool              stdlog_to_stderr_bool,
-                             const char       *stdlog_filename,
-                             guint             syslog_priority) /* if != 0, stdlog to syslog */
-{
-  sfi_mutex_lock (&logging_mutex);
-  stdlog_to_stderr = stdlog_to_stderr_bool != 0;
-  stdlog_syslog_priority = syslog_priority;
-  if (stdlog_file && stdlog_file != stdout)
-    fclose (stdlog_file);
-  stdlog_file = NULL;
-  if (stdlog_filename && strcmp (stdlog_filename, "-") == 0)
-    stdlog_file = stdout;
-  else if (stdlog_filename)
-    stdlog_file = fopen (stdlog_filename, "a");
-  sfi_mutex_unlock (&logging_mutex);
-}
-
-/**
- * @param type	message type, e.g. SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, etc...
- * @return		message identifier
- *
- * Retrive the string identifying the message type @a type. For invalid
- * (non registered) message types, NULL is returned.
- * This function is MT-safe and may be called from any thread.
- */
-const gchar*
-sfi_msg_type_ident (SfiMsgType mtype)
-{
-  const gchar *string = NULL;
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype >= 0 && mtype < n_msg_types)
-    string = msg_types[mtype].ident;
-  sfi_mutex_unlock (&logging_mutex);
-  return string;
-}
-
-/**
- * @param type	message type, e.g. SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, etc...
- * @return		translated message identifier or NULL
- *
- * Retrive the label identifying the message type @a type. Usually,
- * this is a translated version of sfi_msg_type_ident() or NULL
- * if non was registered with the message type.
- * This function is MT-safe and may be called from any thread.
- */
-const gchar*
-sfi_msg_type_label (SfiMsgType mtype)
-{
-  const gchar *string = NULL;
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype >= 0 && mtype < n_msg_types)
-    string = msg_types[mtype].label;
-  sfi_mutex_unlock (&logging_mutex);
-  return string;
-}
-
-/**
- * @param ident	message identifier, e.g. "error", "warning", "info", etc...
- * @return		corresponding SfiMsgType or 0
- *
- * Find the message type correspondign to @a ident. If no message
- * type was found 0 is returned (note that 0 is also the value of
- * SFI_MSG_NONE).
- * This function is MT-safe and may be called from any thread.
- */
-SfiMsgType
-sfi_msg_type_lookup (const gchar *ident)
-{
-  g_return_val_if_fail (ident != NULL, 0);
-  guint i;
-  sfi_mutex_lock (&logging_mutex);
-  for (i = 0; i < n_msg_types; i++)
-    if (strcmp (ident, msg_types[i].ident) == 0)
-      break;
-  if (i >= n_msg_types)
-    i = 0;
-  sfi_mutex_unlock (&logging_mutex);
-  return i;
-}
-
-/**
- * @param handler	a valid SfiMsgHandler or NULL
- *
- * Set the handler function for messages logged in the current
- * thread. If NULL is specified as handler, the standard handler
- * will be used. For handler implementations that require an extra
- * data argument, see sfi_thread_set_qdata().
- * This function is MT-safe and may be called from any thread.
- */
-void
-sfi_msg_set_thread_handler (SfiMsgHandler handler)
-{
-  sfi_thread_set_qdata (quark_log_handler, handler);
-}
-
-/**
- * @param message	a valid SfiMessage
- *
- * This is the standard message handler, it produces @a message
- * in a prominent way on stderr.
- * This function is MT-safe and may be called from any thread.
- */
-void
-sfi_msg_default_handler (const SfiMessage *msg)
-{
-  const gchar *level_name = sfi_msg_type_label (msg->type);
-  g_printerr ("********************************************************************************\n");
-  if (msg->log_domain)
-    g_printerr ("** %s-%s: %s\n", msg->log_domain, level_name, msg->title ? msg->title : "");
-  else
-    g_printerr ("** %s: %s\n", level_name, msg->title ? msg->title : "");
-  if (msg->primary)
-    g_printerr ("** %s\n", msg->primary);
-  if (msg->secondary)
-    {
-      GString *gstring = g_string_new (msg->secondary);
-      guint i;
-      for (i = 0; i < gstring->len; i++)
-        if (gstring->str[i] == '\n')
-          g_string_insert (gstring, i + 1, "**   ");
-      g_printerr ("**   %s\n", gstring->str);
-      g_string_free (gstring, TRUE);
-    }
-  if (msg->details)
-    {
-      GString *gstring = g_string_new (msg->details);
-      guint i;
-      for (i = 0; i < gstring->len; i++)
-        if (gstring->str[i] == '\n')
-          g_string_insert (gstring, i + 1, "** > ");
-      g_printerr ("** > %s\n", gstring->str);
-      g_string_free (gstring, TRUE);
-    }
-  if (msg->config_check)
-    g_printerr ("** [X] %s\n", msg->config_check);
-  g_printerr ("********************************************************************************\n");
-}
-
-typedef struct LogBit LogBit;
-struct LogBit {
-  SfiMsgBit bit;
-  void    (*data_free) (void*);
-  LogBit   *next;
-};
-
-static void
-free_lbits (LogBit *first)
-{
-  while (first)
-    {
-      LogBit *current = first;
-      first = current->next;
-      if (current->data_free)
-        current->data_free (current->bit.data);
-      g_free (current);
-    }
-}
-
-/**
- * @param log_domain    log domain
- * @param level         one of SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, SFI_MSG_DIAG or SFI_MSG_DEBUG
- * @param format        printf-like format
- * @param ...           printf-like arguments
- *
- * Log a message through SFIs logging mechanism. The current
- * value of errno is preserved around calls to this function.
- * Usually this function isn't used directly, but through one
- * of sfi_debug(), sfi_diag(), sfi_info(), sfi_warn() or sfi_error().
- * The @a log_domain indicates the calling module and relates to
- * G_LOG_DOMAIN as used by g_log().
- * This function is MT-safe and may be called from any thread.
- */
-void
-sfi_msg_log_printf (const char       *log_domain,
-                       SfiMsgType     mtype,
-                       const char       *format,
-                       ...)
-{
-  gint saved_errno = errno;
-  /* construct message */
-  SfiMessage msg = { 0, };
-  msg.type = mtype;
-  msg.log_domain = (char*) log_domain;
-  va_list args;
-  va_start (args, format);
-  msg.primary = g_strdup_vprintf (format, args);
-  va_end (args);
-  msg.config_check = NULL;
-  /* handle message */
-  LogBit *lbit_list = sfi_thread_steal_qdata (quark_msg_bits);
-  sfi_log_msg_process (&msg);
-  g_free (msg.primary);
-  free_lbits (lbit_list); /* purge thread local msg bit list */
-  errno = saved_errno;
-}
-
-/**
- * @param log_domain    log domain
- * @param mtype         one of SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, SFI_MSG_DIAG
- * @param lbit1         msg bit
- * @param lbit2         msg bit
- * @param ...           list of more msg bits, NULL terminated
- *
- * Log a message through SFIs logging mechanism. The current value of errno
- * is preserved around calls to this function. Usually this function isn't
- * used directly, but sfi_log_msg() is called instead which does not require
- * NULL termination of its argument list and automates the @a log_domain argument.
- * The @a log_domain indicates the calling module and relates to G_LOG_DOMAIN
- * as used by g_log().
- * The msg bit arguments passed in form various parts of the log message, the
- * following macro set is provided to construct the parts from printf-style
- * argument lists:
- * - SFI_MSG_TITLE(): format message title
- * - SFI_MSG_TEXT1(): format primary message (also SFI_MSG_PRIMARY())
- * - SFI_MSG_TEXT2(): format secondary message, optional (also SFI_MSG_SECONDARY())
- * - SFI_MSG_TEXT3(): format details of the message, optional (also SFI_MSG_DETAIL())
- * - SFI_MSG_CHECK(): format configuration check statement to enable/disable log messages of this type.
- * This function is MT-safe and may be called from any thread.
- */
-void
-sfi_msg_log_elist (const char     *log_domain,
-                      SfiMsgType   mtype,       /* SFI_MSG_DEBUG is not really useful here */
-                      SfiMsgBit   *lbit1,
-                      SfiMsgBit   *lbit2,
-                      ...)
-{
-  gint saved_errno = errno;
-  guint n = 0;
-  SfiMsgBit **bits = NULL;
-  /* collect msg bits */
-  if (lbit1)
-    {
-      bits = g_renew (SfiMsgBit*, bits, n + 1);
-      bits[n++] = lbit1;
-      SfiMsgBit *lbit = lbit2;
-      va_list args;
-      va_start (args, lbit2);
-      while (lbit)
-        {
-          bits = g_renew (SfiMsgBit*, bits, n + 1);
-          bits[n++] = lbit;
-          lbit = va_arg (args, SfiMsgBit*);
-        }
-      va_end (args);
-    }
-  bits = g_renew (SfiMsgBit*, bits, n + 1);
-  bits[n] = NULL;
-  sfi_msg_log_trampoline (log_domain, mtype, bits, sfi_log_msg_process);
-  g_free (bits);
-  errno = saved_errno;
-}
-
-static inline char*
-log_msg_concat (char       *former,
-                const char *next)
-{
-  if (former && !next)
-    return former;
-  if (!former && next)
-    return g_strdup (next);
-  char *result = g_strconcat (former, "\n", next, NULL);
-  g_free (former);
-  return result;
-}
-
-static inline void
-msg_apply_bit (SfiMessage *msg,
-               SfiMsgBit  *lbit)
-{
-  gsize ltype = (gsize) lbit->owner;
-  if (ltype < 256)
-    {
-      switch (ltype)
-        {
-        case '0': msg->title = log_msg_concat (msg->title, lbit->data);               break;
-        case '1': msg->primary = log_msg_concat (msg->primary, lbit->data);           break;
-        case '2': msg->secondary = log_msg_concat (msg->secondary, lbit->data);       break;
-        case '3': msg->details = log_msg_concat (msg->details, lbit->data);           break;
-        case 'c': msg->config_check = log_msg_concat (msg->config_check, lbit->data); break;
-        }
-    }
-  else
-    {
-      guint i = msg->n_msg_bits++;
-      msg->msg_bits = g_renew (SfiMsgBit*, msg->msg_bits, msg->n_msg_bits);
-      msg->msg_bits[i] = lbit;
-    }
-}
-
-/**
- * @param log_domain	log domain
- * @param mtype	one of SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, SFI_MSG_DIAG
- * @param lbit1	msg bit
- * @param lbit2	msg bit
- * @param lbitargs	va_list list of more msg bits, NULL terminated
- * @param handler	message handler
- * @param vbitlist	NULL terminated array of msg bits
- *
- * Construct a log message from the arguments given and let @a handler process
- * it. This function performs no logging on its own, it is used internally by
- * sfi_log_msg_elist() to collect arguments and construct a message. All logging
- * functionality has to be implemented by @a handler. Note that all thread-local
- * msg bits are deleted after invokation of this funtcion, so all msg bits
- * created in the current thread are invalid after calling this function.
- * Direct use of this function is not recommended except for implementations
- * of logging mechanisms.
- * This function is MT-safe and may be called from any thread.
- */
-void
-sfi_msg_log_trampoline (const char        *log_domain,
-                           SfiMsgType      mtype,       /* SFI_MSG_DEBUG is not really useful here */
-                           SfiMsgBit     **lbits,
-                           SfiMsgHandler   handler)
-{
-  gint saved_errno = errno;
-  /* construct message */
-  SfiMessage msg = { 0, };
-  msg.type = mtype;
-  msg.log_domain = (char*) log_domain;
-  /* apply msg bits */
-  if (lbits)
-    {
-      guint j;
-      for (j = 0; lbits[j]; j++)
-        msg_apply_bit (&msg, lbits[j]);
-    }
-  /* reset thread local msg bit list */
-  LogBit *lbit_list = sfi_thread_steal_qdata (quark_msg_bits);
-  /* handle message */
-  if (!handler)
-    handler = sfi_log_msg_process;
-  handler (&msg);
-  /* clean up */
-  g_free (msg.title);
-  g_free (msg.primary);
-  g_free (msg.secondary);
-  g_free (msg.details);
-  g_free (msg.config_check);
-  g_free (msg.msg_bits);
-  free_lbits (lbit_list);
-  /* restore errno */
-  errno = saved_errno;
-}
-
-SfiMsgBit*
-sfi_msg_bit_appoint (gconstpointer   owner,
-                        gpointer        data,
-                        void          (*data_free) (gpointer))
-{
-  gint saved_errno = errno;
-  LogBit *lbit = g_new0 (LogBit, 1);
-  lbit->bit.owner = owner;
-  lbit->bit.data = data;
-  lbit->data_free = data_free;
-  lbit->next = sfi_thread_steal_qdata (quark_msg_bits);
-  sfi_thread_set_qdata_full (quark_msg_bits, lbit, (GDestroyNotify) free_lbits);
-  errno = saved_errno;
-  return &lbit->bit;
-}
-
-SfiMsgBit*
-sfi_msg_bit_printf (guint8      msg_bit_type,
-                       const char *format,
-                       ...)
-{
-  gint saved_errno = errno;
-  va_list args;
-  va_start (args, format);
-  gchar *string = g_strdup_vprintf (format, args);
-  va_end (args);
-  errno = saved_errno;
-  return sfi_msg_bit_appoint ((void*) (gsize) msg_bit_type, string, g_free);
-}
-
-static const gchar*
-prgname (bool     maystrip)
-{
-  const gchar *pname = g_get_prgname();
-  if (pname && maystrip)
-    {
-      const gchar *p = strrchr (pname, '/');
-      pname = p ? p + 1 : pname;
-    }
-  return pname;
-}
-
-static char*
-log_prefix (const char  *prg_name,
-            guint        pid,
-            const char  *log_domain,
-            const char  *label,
-            const char  *ident)
-{
-  GString *gstring = g_string_new (prg_name);
-  if (pid)
-    g_string_append_printf (gstring, "[%u]", pid);
-  if (gstring->len)
-    g_string_append (gstring, ":");
-  if (log_domain)
-    g_string_append (gstring, log_domain);
-  if (log_domain && label)
-    g_string_append (gstring, "-");
-  if (label)
-    g_string_append (gstring, label);
-  if (ident)
-    {
-      if (log_domain || label)
-        g_string_append_printf (gstring, "(%s)", ident);
-      else
-        g_string_append (gstring, ident);
-    }
-  if (log_domain || label || ident)
-    g_string_append (gstring, ":");
-  /* more components can come here */
-  /* ... */
-  if (gstring->str[gstring->len - 1] == ':') /* strip final ':' */
-    gstring->str[gstring->len - 1] = 0;
-  return g_string_free (gstring, FALSE);
-}
-
-static guint
-sfi_msg_type_actions (SfiMsgType mtype)
-{
-  guint actions = 0;
-  sfi_mutex_lock (&logging_mutex);
-  if (mtype >= 0 && mtype < n_msg_types &&
-      !msg_types[mtype].disabled)
-    actions = msg_types[mtype].log_flags;
-  sfi_mutex_unlock (&logging_mutex);
-  return actions;
-}
-
-static void
-sfi_log_msg_process (const SfiMessage *msgp)
-{
-  const SfiMessage msg = *msgp;
-  /* determine log actions */
-  guint actions = sfi_msg_type_actions (msg.type);
-  const char *ident = sfi_msg_type_ident (msg.type);
-  const char *label = sfi_msg_type_label (msg.type);
-  /* log to syslog */
-  if ((msg.primary || msg.secondary) && stdlog_syslog_priority && (actions & SFI_MSG_TO_STDLOG))
-    {
-      char *prefix = log_prefix (NULL, 0, msg.log_domain, NULL, ident);
-      if (msg.title && FALSE) // skip title in syslog
-        syslog (stdlog_syslog_priority, "%s:0: %s\n", prefix, msg.title);
-      if (msg.primary)
-        syslog (stdlog_syslog_priority, "%s:1: %s\n", prefix, msg.primary);
-      if (msg.secondary)
-        syslog (stdlog_syslog_priority, "%s:2: %s\n", prefix, msg.secondary);
-      if (msg.details && FALSE) // skip details in syslog
-        syslog (stdlog_syslog_priority, "%s:3: %s\n", prefix, msg.details);
-      g_free (prefix);
-    }
-  /* log to stderr */
-  bool tostderr = (actions & SFI_MSG_TO_STDERR) != 0;
-  tostderr |= (actions & SFI_MSG_TO_STDLOG) && stdlog_to_stderr;
-  if ((msg.primary || msg.secondary) && tostderr)
-    {
-      bool   is_debug = msg.type == SFI_MSG_DEBUG, is_diag = msg.type == SFI_MSG_DIAG;
-      gchar *prefix = log_prefix (prgname (is_debug),                                   /* strip prgname path for debugging */
-                                  sfi_thread_self_pid(),                                /* always print pid */
-                                  is_debug ? NULL : msg.log_domain,                     /* print domain except when debugging */
-                                  is_debug || is_diag ? NULL : label,                   /* print translated message type execpt for debug/diagnosis */
-                                  is_debug ? ident : NULL);                             /* print identifier if debugging */
-      if (msg.title)
-        fprintf (stderr, "%s:0: %s\n", prefix, msg.title);
-      if (msg.primary)
-        fprintf (stderr, "%s:1: %s\n", prefix, msg.primary);
-      if (msg.secondary)
-        fprintf (stderr, "%s:2: %s\n", prefix, msg.secondary);
-      if (msg.details)
-        fprintf (stderr, "%s:3: %s\n", prefix, msg.details);
-      g_free (prefix);
-    }
-  /* log to logfile */
-  if (stdlog_file && (actions & SFI_MSG_TO_STDLOG))
-    {
-      char *prefix = log_prefix (prgname (FALSE),                                       /* printf fully qualified program name */
-                                 sfi_thread_self_pid(),                                 /* always print pid */
-                                 msg.log_domain,                                        /* always print log domain */
-                                 NULL,                                                  /* skip translated message type */
-                                 ident);                                                /* print machine readable message type */
-      if (msg.title)
-        fprintf (stdlog_file, "%s:0: %s\n", prefix, msg.title);
-      if (msg.primary)
-        fprintf (stdlog_file, "%s:1: %s\n", prefix, msg.primary);
-      if (msg.secondary)
-        fprintf (stdlog_file, "%s:2: %s\n", prefix, msg.secondary);
-      if (msg.details)
-        fprintf (stdlog_file, "%s:3: %s\n", prefix, msg.details);
-      g_free (prefix);
-    }
-  /* log to log handler */
-  if (actions & SFI_MSG_TO_HANDLER)
-    {
-      SfiMsgHandler log_handler = sfi_thread_get_qdata (quark_log_handler);
-      if (!log_handler)
-        log_handler = sfi_msg_default_handler;
-      log_handler (&msg);
-    }
-}

Deleted: trunk/sfi/sfimsg.h
===================================================================
--- trunk/sfi/sfimsg.h	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfimsg.h	2006-11-21 00:19:43 UTC (rev 4088)
@@ -1,154 +0,0 @@
-/* SfiMsg
- * Copyright (C) 2002-2006 Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __SFI_MSG_H__
-#define __SFI_MSG_H__
-
-#include <sfi/sfitypes.h>
-
-BIRNET_EXTERN_C_BEGIN();
-
-typedef enum {
-  SFI_MSG_NONE = 0,     /* always off */
-  SFI_MSG_FATAL,        /* always on */
-  SFI_MSG_ERROR,
-  SFI_MSG_WARNING,
-  SFI_MSG_SCRIPT,
-  SFI_MSG_INFO,
-  SFI_MSG_DIAG,
-  SFI_MSG_DEBUG,
-  SFI_MSG_LAST
-} SfiMsgType;
-
-/* --- standard logging --- */
-#define sfi_fatal(        ...)          sfi_msg_checked (SFI_LOG_DOMAIN, SFI_MSG_FATAL, __VA_ARGS__)
-#define sfi_error(        ...)          sfi_msg_checked (SFI_LOG_DOMAIN, SFI_MSG_ERROR,   __VA_ARGS__)
-#define sfi_warning(      ...)          sfi_msg_checked (SFI_LOG_DOMAIN, SFI_MSG_WARNING, __VA_ARGS__)
-#define sfi_info(         ...)          sfi_msg_checked (SFI_LOG_DOMAIN, SFI_MSG_INFO, __VA_ARGS__)
-#define sfi_diag(         ...)          sfi_msg_checked (SFI_LOG_DOMAIN, SFI_MSG_DIAG, __VA_ARGS__)
-#define sfi_debug(   lvl, ...)          sfi_msg_checked (SFI_LOG_DOMAIN, lvl, __VA_ARGS__)
-#define sfi_nodebug( lvl, ...)          do { /* nothing */ } while (0)
-
-/* --- user interface messages --- */
-#define sfi_msg_log(level, ...)         sfi_msg_log_elist (SFI_LOG_DOMAIN, level, __VA_ARGS__, NULL)
-#define SFI_MSG_TEXT0(...)              sfi_msg_bit_printf ('0', __VA_ARGS__) /* message title */
-#define SFI_MSG_TEXT1(...)              sfi_msg_bit_printf ('1', __VA_ARGS__) /* primary message */
-#define SFI_MSG_TEXT2(...)              sfi_msg_bit_printf ('2', __VA_ARGS__) /* secondary message */
-#define SFI_MSG_TEXT3(...)              sfi_msg_bit_printf ('3', __VA_ARGS__) /* message details */
-#define SFI_MSG_CHECK(...)              sfi_msg_bit_printf ('c', __VA_ARGS__) /* user switch */
-#define SFI_MSG_TITLE                   SFI_MSG_TEXT0 /* alias */
-#define SFI_MSG_PRIMARY                 SFI_MSG_TEXT1 /* alias */
-#define SFI_MSG_SECONDARY               SFI_MSG_TEXT2 /* alias */
-#define SFI_MSG_DETAIL                  SFI_MSG_TEXT3 /* alias */
-
-/* --- config and handler API --- */
-typedef enum {
-  SFI_MSG_TO_STDERR     = 1,
-  SFI_MSG_TO_STDLOG     = 2,
-  SFI_MSG_TO_HANDLER    = 4,
-} SfiMsgLogFlags;
-typedef struct  SfiMessage                       SfiMessage;
-typedef void  (*SfiMsgHandler)                  (const SfiMessage *message);
-static inline
-bool            sfi_msg_check                   (SfiMsgType        mtype);
-void            sfi_msg_enable                  (SfiMsgType        mtype);
-void            sfi_msg_disable                 (SfiMsgType        mtype);
-void            sfi_msg_allow                   (const gchar      *ident_list);
-void            sfi_msg_deny                    (const gchar      *ident_list);
-void            sfi_msg_set_thread_handler      (SfiMsgHandler     handler);
-void            sfi_msg_default_handler         (const SfiMessage *message);
-SfiMsgType   	sfi_msg_type_lookup             (const gchar      *ident);
-const gchar*    sfi_msg_type_ident              (SfiMsgType        mtype);
-const gchar*    sfi_msg_type_label              (SfiMsgType        mtype);
-void            sfi_msg_type_configure          (SfiMsgType        mtype,
-						 SfiMsgLogFlags     channel_mask,
-						 const gchar       *dummy_filename);
-void            sfi_msg_configure_stdlog        (bool               stdlog_to_stderr,
-						 const char        *stdlog_filename,
-						 guint              syslog_priority); /* if != 0, stdlog to syslog */
-SfiMsgType   	sfi_msg_type_register           (const gchar       *ident,
-						 SfiMsgType         default_ouput, /* FALSE, TRUE, ... */
-						 const gchar       *label);
-/* automatic registration */
-#define SFI_MSG_TYPE_DEFINE(variable, ident, default_ouput, label) SFI_MSG_TYPE__DEF (variable, ident, default_ouput, label)
-
-/* --- logging internals --- */
-typedef struct SfiMsgBit SfiMsgBit;
-struct SfiMessage {
-  gchar         *log_domain;
-  SfiMsgType  type;
-  char          *title;         /* translated */
-  char          *primary;       /* translated */
-  char          *secondary;     /* translated */
-  char          *details;       /* translated */
-  char          *config_check;  /* translated */
-  guint          n_msg_bits;
-  SfiMsgBit **msg_bits;
-};
-struct SfiMsgBit {
-  gconstpointer  owner;
-  gpointer       data;
-};
-
-void            sfi_msg_log_printf              (const char    *log_domain,
-						 SfiMsgType     mtype,
-						 const char    *format,
-						 ...) G_GNUC_PRINTF (3, 4);
-void            sfi_msg_log_elist               (const char    *log_domain,
-						 SfiMsgType     mtype,
-						 SfiMsgBit     *lbit1,
-						 SfiMsgBit     *lbit2,
-						 ...);
-void            sfi_msg_log_trampoline          (const char    *log_domain,
-						 SfiMsgType     mtype,
-						 SfiMsgBit    **lbits,
-						 SfiMsgHandler  handler);
-SfiMsgBit*   sfi_msg_bit_appoint        	(gconstpointer  owner,
-						 gpointer       data,
-						 void         (*data_free) (void*));
-SfiMsgBit*   sfi_msg_bit_printf              	(guint8         msg_bit_type,
-						 const char    *format,
-						 ...) G_GNUC_PRINTF (2, 3);
-void            _sfi_init_logging               (void);
-static inline bool    
-sfi_msg_check (SfiMsgType mtype)
-{
-  extern guint8 * volatile sfi_msg_flags;
-  extern volatile guint    sfi_msg_flags_max;
-  if (mtype >= 0 && (unsigned) mtype <= sfi_msg_flags_max)
-    return 0 != (sfi_msg_flags[mtype / 8] & (1 << mtype % 8));
-  return 0;
-}
-
-/* --- internal macros --- */
-#ifndef SFI_LOG_DOMAIN
-#define SFI_LOG_DOMAIN  G_LOG_DOMAIN
-#endif
-#define sfi_msg_checked( dom, lvl, ...)  \
-  do { SfiMsgType __mt = lvl; if (sfi_msg_check (__mt)) sfi_msg_log_printf (dom, __mt, __VA_ARGS__); } while (0)
-#define SFI_MSG_TYPE__DEF(variable, identifier, default_ouput, label) \
-  SfiMsgType variable = (SfiMsgType) 0; \
-  static void BIRNET_CONSTRUCTOR \
-  BIRNET_CPP_PASTE4 (__sfi_msg_type__init, __LINE__, __, variable) (void) \
-  { variable = sfi_msg_type_register (identifier, default_ouput, label); }
-
-BIRNET_EXTERN_C_END();
-
-#endif /* __SFI_MSG_H__ */
-
-/* vim:set ts=8 sts=2 sw=2: */

Modified: trunk/sfi/sfistore.c
===================================================================
--- trunk/sfi/sfistore.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfistore.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -20,7 +20,6 @@
 #include "sfiprimitives.h"
 #include "sfiserial.h"
 #include "sfiparams.h"
-#include "sfimsg.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>

Modified: trunk/sfi/sfiwrapper.cc
===================================================================
--- trunk/sfi/sfiwrapper.cc	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfiwrapper.cc	2006-11-21 00:19:43 UTC (rev 4088)
@@ -19,6 +19,7 @@
 #include "sfiwrapper.h"
 #undef BIRNET__RUNTIME_PROBLEM
 #include <birnet/birnet.hh>
+#include <errno.h>
 
 /* --- initialization --- */
 void
@@ -86,6 +87,148 @@
   return Birnet::Path::equals (file1 ? file1 : "", file2 ? file2 : "");
 }
 
+/* --- message handling --- */
+SfiMsgType
+sfi_msg_type_register (const gchar *ident,
+                       SfiMsgType   default_ouput,
+                       const gchar *label)
+{
+  BIRNET_STATIC_ASSERT (Birnet::Msg::NONE == (uint) SFI_MSG_NONE);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::ALWAYS == (uint) SFI_MSG_ALWAYS);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::ERROR == (uint) SFI_MSG_ERROR);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::WARNING == (uint) SFI_MSG_WARNING);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::SCRIPT == (uint) SFI_MSG_SCRIPT);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::INFO == (uint) SFI_MSG_INFO);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::DIAG == (uint) SFI_MSG_DIAG);
+  BIRNET_STATIC_ASSERT (Birnet::Msg::DEBUG == (uint) SFI_MSG_DEBUG);
+  return (SfiMsgType) Birnet::Msg::register_type (ident, Birnet::Msg::Type (default_ouput), label);
+}
+
+bool
+sfi_msg_check (SfiMsgType mtype)
+{
+  return Birnet::Msg::check (Birnet::Msg::Type (mtype));
+}
+
+void
+sfi_msg_enable (SfiMsgType mtype)
+{
+  return Birnet::Msg::enable (Birnet::Msg::Type (mtype));
+}
+
+void
+sfi_msg_disable (SfiMsgType mtype)
+{
+  return Birnet::Msg::disable (Birnet::Msg::Type (mtype));
+}
+
+void
+sfi_msg_allow (const gchar *ident_list)
+{
+  return Birnet::Msg::allow_msgs (ident_list);
+}
+
+void
+sfi_msg_deny (const gchar *ident_list)
+{
+  return Birnet::Msg::deny_msgs (ident_list);
+}
+
+const char*
+sfi_msg_type_ident (SfiMsgType mtype)
+{
+  return Birnet::Msg::type_ident (Birnet::Msg::Type (mtype));
+}
+
+const char*
+sfi_msg_type_label (SfiMsgType mtype)
+{
+  return Birnet::Msg::type_label (Birnet::Msg::Type (mtype));
+}
+
+SfiMsgType
+sfi_msg_lookup_type (const char *ident)
+{
+  return (SfiMsgType) Birnet::Msg::lookup_type (ident);
+}
+
+SfiMsgPart*
+sfi_msg_part_printf (uint8          msg_part_id,
+                     const char    *format,
+                     ...)
+{
+  int saved_errno = errno;
+  /* construct message */
+  va_list args;
+  va_start (args, format);
+  char *text = g_strdup_vprintf (format, args);
+  va_end (args);
+  Birnet::Msg::Part *part;
+  switch (msg_part_id)
+    {
+    case '0':   part = new Birnet::Msg::Text0 (Birnet::String (text)); break;
+    case '1':   part = new Birnet::Msg::Text1 (Birnet::String (text)); break;
+    case '2':   part = new Birnet::Msg::Text2 (Birnet::String (text)); break;
+    case '3':   part = new Birnet::Msg::Text3 (Birnet::String (text)); break;
+    case 'c':   part = new Birnet::Msg::Check (Birnet::String (text)); break;
+    default:    part = new Birnet::Msg::Custom (msg_part_id, Birnet::String (text)); break;
+    }
+  g_free (text);
+  errno = saved_errno;
+  return (SfiMsgPart*) part;
+}
+
+void
+sfi_msg_display_parts (const char     *log_domain,
+                       SfiMsgType      mtype,
+                       guint           n_mparts,
+                       SfiMsgPart    **mparts)
+{
+  int saved_errno = errno;
+  std::vector<Birnet::Msg::Part> parts;
+  for (uint i = 0; i < n_mparts; i++)
+    {
+      Birnet::Msg::Part *part = (Birnet::Msg::Part*) mparts[i];
+      parts.push_back (*part);
+      delete part;
+    }
+  Birnet::Msg::display_parts (log_domain, Birnet::Msg::Type (mtype), parts);
+  errno = saved_errno;
+}
+
+/**
+ * @param log_domain    log domain
+ * @param level         one of SFI_MSG_ERROR, SFI_MSG_WARNING, SFI_MSG_INFO, SFI_MSG_DIAG or SFI_MSG_DEBUG
+ * @param format        printf-like format
+ * @param ...           printf-like arguments
+ *
+ * Log a message through SFIs logging mechanism. The current
+ * value of errno is preserved around calls to this function.
+ * Usually this function isn't used directly, but through one
+ * of sfi_debug(), sfi_diag(), sfi_info(), sfi_warn() or sfi_error().
+ * The @a log_domain indicates the calling module and relates to
+ * G_LOG_DOMAIN as used by g_log().
+ * This function is MT-safe and may be called from any thread.
+ */
+void
+sfi_msg_display_printf (const char    *log_domain,
+                        SfiMsgType     mtype,
+                        const char    *format,
+                        ...)
+{
+  int saved_errno = errno;
+  /* construct message */
+  va_list args;
+  va_start (args, format);
+  char *primary = g_strdup_vprintf (format, args);
+  va_end (args);
+  std::vector<Birnet::Msg::Part> parts;
+  parts.push_back (Birnet::Msg::Primary (std::string (primary)));
+  g_free (primary);
+  Birnet::Msg::display_parts (log_domain, Birnet::Msg::Type (mtype), parts);
+  errno = saved_errno;
+}
+
 /* --- url handling --- */
 void
 sfi_url_show (const char *url)

Modified: trunk/sfi/sfiwrapper.h
===================================================================
--- trunk/sfi/sfiwrapper.h	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/sfiwrapper.h	2006-11-21 00:19:43 UTC (rev 4088)
@@ -71,6 +71,77 @@
 bool	birnet_file_equals (const char *file1,
 			    const char *file2);
 
+/* --- messaging --- */
+typedef enum {
+  SFI_MSG_NONE   = 0,   /* always off */
+  SFI_MSG_ALWAYS = 1,   /* always on */
+  SFI_MSG_ERROR,
+  SFI_MSG_WARNING,
+  SFI_MSG_SCRIPT,
+  SFI_MSG_INFO,
+  SFI_MSG_DIAG,
+  SFI_MSG_DEBUG
+} SfiMsgType;
+typedef enum {
+  SFI_MSG_TO_STDERR     = 1,
+  SFI_MSG_TO_STDLOG     = 2,
+  SFI_MSG_TO_HANDLER    = 4,
+} SfiMsgLogFlags;
+#define         sfi_error(...)                   sfi_msg_printf (SFI_MSG_ERROR, __VA_ARGS__)
+#define         sfi_warning(...)                 sfi_msg_printf (SFI_MSG_WARNING, __VA_ARGS__)
+#define         sfi_info(...)                    sfi_msg_printf (SFI_MSG_INFO, __VA_ARGS__)
+#define         sfi_diag(...)                    sfi_msg_printf (SFI_MSG_DIAG, __VA_ARGS__)
+#define         sfi_debug(lvl, ...)              sfi_msg_printf (lvl, __VA_ARGS__)
+#define         sfi_nodebug(lvl, ...)            do { /* nothing */ } while (0)
+bool            sfi_msg_check                   (SfiMsgType      mtype);
+void            sfi_msg_enable                  (SfiMsgType      mtype);
+void            sfi_msg_disable                 (SfiMsgType      mtype);
+void            sfi_msg_allow                   (const char     *ident_list);
+void            sfi_msg_deny                    (const char     *ident_list);
+const char*     sfi_msg_type_ident              (SfiMsgType      mtype);
+const char*     sfi_msg_type_label              (SfiMsgType      mtype);
+SfiMsgType      sfi_msg_lookup_type             (const char     *ident);
+SfiMsgType      sfi_msg_type_register           (const char     *ident,
+                                                 SfiMsgType      default_ouput,
+                                                 const char     *label);
+#define         sfi_msg_printf(level, ...)       SFI_MSG_PRINTF (level, __VA_ARGS__)    /* level, printf_format, ... */
+#define         sfi_msg_display(level, ...)      SFI_MSG_DISPLAY (level, __VA_ARGS__)   /* level, part, part, ... */
+#define         SFI_MSG_TEXT0(...)               sfi_msg_part_printf ('0', __VA_ARGS__) /* message title */
+#define         SFI_MSG_TEXT1(...)               sfi_msg_part_printf ('1', __VA_ARGS__) /* primary message */
+#define         SFI_MSG_TEXT2(...)               sfi_msg_part_printf ('2', __VA_ARGS__) /* secondary message */
+#define         SFI_MSG_TEXT3(...)               sfi_msg_part_printf ('3', __VA_ARGS__) /* message details */
+#define         SFI_MSG_CHECK(...)               sfi_msg_part_printf ('c', __VA_ARGS__) /* user switch */
+#define         SFI_MSG_TITLE                    SFI_MSG_TEXT0 /* alias */
+#define         SFI_MSG_PRIMARY                  SFI_MSG_TEXT1 /* alias */
+#define         SFI_MSG_SECONDARY                SFI_MSG_TEXT2 /* alias */
+#define         SFI_MSG_DETAIL                   SFI_MSG_TEXT3 /* alias */
+#define         SFI_MSG_TYPE_DEFINE(variable, ident, default_ouput, label) SFI_MSG__TYPEDEF (variable, ident, default_ouput, label)
+
+/* --- messaging implementation --- */
+typedef struct SfiMsgPart SfiMsgPart;
+SfiMsgPart*     sfi_msg_part_printf     (uint8          msg_part_id,
+                                         const char    *format,
+                                         ...) G_GNUC_PRINTF (2, 3);
+void            sfi_msg_display_parts   (const char     *log_domain,
+                                         SfiMsgType      mtype,
+                                         guint           n_mparts,
+                                         SfiMsgPart    **mparts);
+void            sfi_msg_display_printf  (const char    *log_domain,
+                                         SfiMsgType     mtype,
+                                         const char    *format,
+                                         ...) G_GNUC_PRINTF (3, 4);
+#define SFI_MSG_PRINTF(lvl, ...)        do { SfiMsgType __mt = lvl; if (sfi_msg_check (__mt)) \
+                                             sfi_msg_display_printf (BIRNET_LOG_DOMAIN, __mt, __VA_ARGS__); } while (0)
+#define SFI_MSG_DISPLAY(lvl, ...)       do { SfiMsgType __mt = lvl; if (sfi_msg_check (__mt)) { \
+                                               SfiMsgPart *__pa[] = { __VA_ARGS__ };            \
+                                               sfi_msg_display_parts (BIRNET_LOG_DOMAIN, __mt,  \
+                                                 BIRNET_ARRAY_SIZE (__pa), __pa); } } while (0)
+#define SFI_MSG__TYPEDEF(variable, identifier, default_ouput, label) \
+  SfiMsgType variable = (SfiMsgType) 0; \
+  static void BIRNET_CONSTRUCTOR \
+  BIRNET_CPP_PASTE4 (__sfi_msg_type__init, __LINE__, __, variable) (void) \
+  { variable = sfi_msg_type_register (identifier, default_ouput, label); }
+
 /* --- url handling --- */
 void sfi_url_show                   	(const char           *url);
 void sfi_url_show_with_cookie       	(const char           *url,
@@ -101,7 +172,7 @@
 #define SFI_THREAD_PAGING       BIRNET_THREAD_PAGING
 #define SFI_THREAD_ZOMBIE       BIRNET_THREAD_ZOMBIE
 #define SFI_THREAD_DEAD         BIRNET_THREAD_DEAD
-SfiThread* sfi_thread_run			(const gchar  *name, /* new + start */
+SfiThread* sfi_thread_run			(const char   *name, /* new + start */
 						 SfiThreadFunc func,
 						 gpointer      user_data);
 #define	SFI_MUTEX_DECLARE_INITIALIZED(name)	SFI_MUTEX__DECLARE_INITIALIZED (name)

Modified: trunk/sfi/tests/misctests.c
===================================================================
--- trunk/sfi/tests/misctests.c	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/tests/misctests.c	2006-11-21 00:19:43 UTC (rev 4088)
@@ -49,6 +49,25 @@
 }
 
 static void
+test_messages (void)
+{
+  TSTART ("Messaging");
+  TASSERT (sfi_msg_check (SFI_MSG_NONE) == false);
+  TASSERT (sfi_msg_check (SFI_MSG_ALWAYS) == true);
+  TDONE();
+  if (0)
+    {
+      /* check compilability */
+      sfi_info ("First info message test.");
+      sfi_info ("Second info message test: %d", 42);
+      sfi_msg_display (SFI_MSG_INFO,
+                       SFI_MSG_TITLE ("Third info message test"),
+                       SFI_MSG_PRIMARY ("Third info primary message."),
+                       SFI_MSG_SECONDARY ("Third info secondary message: %d", 42));
+    }
+}
+
+static void
 test_time (void)
 {
   SfiTime t;
@@ -929,6 +948,7 @@
   test_com_ports ();
   test_threads ();
   test_sfidl_seq ();
+  test_messages();
   test_misc ();
 
   return 0;

Modified: trunk/sfi/tests/testsfidl.cc
===================================================================
--- trunk/sfi/tests/testsfidl.cc	2006-11-21 00:19:25 UTC (rev 4087)
+++ trunk/sfi/tests/testsfidl.cc	2006-11-21 00:19:43 UTC (rev 4088)
@@ -137,12 +137,12 @@
 
   int fake_argc = 6;
   char **fake_argv = g_new0 (gchar*, fake_argc);
-  fake_argv[0] = "testsfidl";
-  fake_argv[1] = "--test";
-  fake_argv[2] = "--one";
-  fake_argv[3] = "1";
-  fake_argv[4] = "--two=2";
-  fake_argv[5] = "--done";
+  fake_argv[0] = (char*) "testsfidl";
+  fake_argv[1] = (char*) "--test";
+  fake_argv[2] = (char*) "--one";
+  fake_argv[3] = (char*) "1";
+  fake_argv[4] = (char*) "--two=2";
+  fake_argv[5] = (char*) "--done";
   options.parse (&fake_argc, &fake_argv, parser);
 
   TSTART ("Testing factory");




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]