Added SILC Thread Queue API
[silc.git] / lib / silcutil / silclog.h
index 0b12a2a4c300e021940cff04f8590b6ffdfa8d79..56c58ec345691f9b74964a78ebcc7d541d644d5b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2006 Pekka Riikonen
+  Copyright (C) 1997 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -56,7 +56,7 @@ typedef enum {
  * SYNOPSIS
  *
  *    typedef SilcBool (*SilcLogCb)(SilcLogType type, char *message,
- *                              void *context);
+ *                                  void *context);
  *
  * DESCRIPTION
  *
@@ -67,6 +67,8 @@ typedef enum {
  *    The `message' parameter points to a null-terminated buffer containing
  *    the received message, while `context' is the caller-specified context.
  *    The message must not be modified or freed by the callback function.
+ *    If the function returns TRUE, SilcLog will assume the message was
+ *    handled and won't run its default handler.
  *
  * SEE ALSO
  *    silc_log_set_callback
@@ -79,7 +81,7 @@ typedef SilcBool (*SilcLogCb)(SilcLogType type, char *message, void *context);
  * SYNOPSIS
  *
  *    typedef SilcBool (*SilcLogDebugCb)(char *file, char *function, int line,
- *                                   char *message, void *context);
+ *                                       char *message, void *context);
  *
  * DESCRIPTION
  *
@@ -98,16 +100,17 @@ typedef SilcBool (*SilcLogCb)(SilcLogType type, char *message, void *context);
  *
  ***/
 typedef SilcBool (*SilcLogDebugCb)(char *file, char *function, int line,
-                              char *message, void *context);
+                                  char *message, void *context);
 
 /****f* silcutil/SilcLogAPI/SilcLogHexdumpCb
  *
  * SYNOPSIS
  *
- *    typedef SilcBool (*SilcDebugHexdumpCb)(char *file, char *function, int line,
- *                                       unsigned char *data,
- *                                       SilcUInt32 data_len,
- *                                       char *message, void *context;
+ *    typedef SilcBool
+ *    (*SilcDebugHexdumpCb)(char *file, char *function, int line,
+ *                          unsigned char *data,
+ *                          SilcUInt32 data_len,
+ *                          char *message, void *context;
  *
  * DESCRIPTION
  *
@@ -128,8 +131,8 @@ typedef SilcBool (*SilcLogDebugCb)(char *file, char *function, int line,
  *
  ***/
 typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line,
-                                unsigned char *data, SilcUInt32 data_len,
-                                char *message, void *context);
+                                    unsigned char *data, SilcUInt32 data_len,
+                                    char *message, void *context);
 
 /* Macros */
 
@@ -294,8 +297,8 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line,
  * DESCRIPTION
  *
  *    Assert macro that prints error message to stderr and calls abort()
- *    if the `expression' is is false (ie. compares equal to zero).  If
- *    SILC_DEBUG is not defined this macro as no effect.
+ *    if the `expression' is false (ie. compares equal to zero).  If
+ *    SILC_DEBUG is not defined this macro has no effect.
  *
  * SOURCE
  */
@@ -306,6 +309,36 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line,
 #endif /* SILC_DEBUG */
 /***/
 
+/****d* silcutil/SilcLogAPI/SILC_VERIFY
+ *
+ * NAME
+ *
+ *    #define SILC_VERIFY(experssion)
+ *
+ * DESCRIPTION
+ *
+ *    Verification macro that prints error message to stderr and calls
+ *    abort() if the `expression' is false (ie. compares equal to zero)
+ *    on debug builds (SILC_DEBUG defined), and prints error message to
+ *    stderr on release builds (SILC_DEBUG undefined) but does not abort().
+ *    This macro is always compiled even if debugging (SILC_DEBUG) is not
+ *    defined.
+ *
+ * SOURCE
+ */
+#if defined(SILC_DEBUG)
+#define SILC_VERIFY(expr) assert((expr));
+#else
+#define SILC_VERIFY(expr)                                              \
+  if (silc_unlikely(!(expr))) {                                                \
+    SILC_LOG_ERROR(("SILC_VERIFY %s:%s:%d",                            \
+                   __FILE__, __FUNCTION__, __LINE__));                 \
+    silc_set_errno_reason_nofail(SILC_ERR_ASSERT, "SILC_VERIFY %s:%s:%d", \
+                                __FILE__, __FUNCTION__, __LINE__);     \
+  }
+#endif /* SILC_DEBUG */
+/***/
+
 /* Prototypes */
 
 /****f* silcutil/SilcLogAPI/silc_log_set_file
@@ -313,8 +346,8 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line,
  * SYNOPSIS
  *
  *    SilcBool silc_log_set_file(SilcLogType type, char *filename,
- *                           SilcUInt32 maxsize,
- *                           SilcSchedule scheduler);
+ *                               SilcUInt32 maxsize,
+ *                               SilcSchedule scheduler);
  *
  * DESCRIPTION
  *
@@ -326,7 +359,8 @@ typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line,
  *    You can disable logging for a channel by specifying NULL filename, the
  *    maxsize in this case is not important.  The `scheduler' parameter is
  *    needed by the internal logging to allow buffered output and thus to
- *    save HD activity.
+ *    save HD activity.  If `scheduler' is NULL this will call
+ *    silc_schedule_get_global to try to get global scheduler.
  *
  ***/
 SilcBool silc_log_set_file(SilcLogType type, char *filename,