From f10105c19405e6f4de6c3137e8cbdc3d89d1ba5b Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 14 Mar 2010 01:56:28 +0200 Subject: [PATCH] core cleanup: added backend API for debug output Well, it was the lowest hanging fruit to pick :-) --- src/api/sipe-backend-debug.h | 44 ++++++++++++++++++++++++++++ src/core/Makefile.mingw | 3 +- src/purple/Makefile.am | 1 + src/purple/purple-debug.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ src/purple/purple-plugin.c | 9 +++--- 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 src/api/sipe-backend-debug.h create mode 100644 src/purple/purple-debug.c diff --git a/src/api/sipe-backend-debug.h b/src/api/sipe-backend-debug.h new file mode 100644 index 00000000..c8d007ec --- /dev/null +++ b/src/api/sipe-backend-debug.h @@ -0,0 +1,44 @@ +/** + * @file sipe-backend-debug.h + * + * pidgin-sipe + * + * Copyright (C) 2010 SIPE Project + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +typedef enum { + SIPE_DEBUG_LEVEL_INFO, + SIPE_DEBUG_LEVEL_ERROR, + SIPE_DEBUG_LEVEL_FATAL, +} sipe_debug_level; + +/** + * Output debug information + * + * Shouldn't be used directly. Instead use SIPE_DEBUG_xxx() macros + * + * @param level debug level + * @param format format string. "\n" will be automatically appended. + */ +void sipe_backend_debug(sipe_debug_level level, + const gchar *format, + ...) G_GNUC_PRINTF(2, 3); + +/* Convenience macros */ +#define SIPE_DEBUG_INFO(fmt, ...) sipe_backend_debug(SIPE_DEBUG_LEVEL_INFO, fmt, __VA_ARGS__) +#define SIPE_DEBUG_ERROR(fmt, ...) sipe_backend_debug(SIPE_DEBUG_LEVEL_ERROR, fmt, __VA_ARGS__) +#define SIPE_DEBUG_FATAL(fmt, ...) sipe_backend_debug(SIPE_DEBUG_LEVEL_FATAL, fmt, __VA_ARGS__) diff --git a/src/core/Makefile.mingw b/src/core/Makefile.mingw index a1c2c14b..462c501e 100644 --- a/src/core/Makefile.mingw +++ b/src/core/Makefile.mingw @@ -48,7 +48,8 @@ LIB_PATHS += -L$(GTK_TOP)/lib \ ## ## SOURCES, OBJECTS ## -C_SRC = ../purple/purple-plugin.c \ +C_SRC = ../purple/purple-debug.c \ + ../purple/purple-plugin.c \ sipe.c \ sipe-chat.c \ sipe-conf.c \ diff --git a/src/purple/Makefile.am b/src/purple/Makefile.am index 0718e4b7..f3b2b08b 100644 --- a/src/purple/Makefile.am +++ b/src/purple/Makefile.am @@ -6,6 +6,7 @@ MAINTAINERCLEANFILES = \ Makefile.in libsipe_la_SOURCES = \ + purple-debug.c \ purple-plugin.c AM_CFLAGS = $(st) diff --git a/src/purple/purple-debug.c b/src/purple/purple-debug.c new file mode 100644 index 00000000..7b9e25a7 --- /dev/null +++ b/src/purple/purple-debug.c @@ -0,0 +1,68 @@ +/** + * @file purple-debug.c + * + * pidgin-sipe + * + * Copyright (C) 2010 SIPE Project + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "glib.h" +#include "glib/gprintf.h" +#include "debug.h" + +#include "sipe-backend-debug.h" + +void sipe_backend_debug(sipe_debug_level level, + const gchar *format, + ...) +{ + va_list ap; + + va_start(ap, format); + + if (purple_debug_is_enabled()) { + + /* purple_debug doesn't have a vprintf-like API call :-( */ + gchar *msg = g_strdup_vprintf(format, ap); + + switch (level) { + case SIPE_DEBUG_LEVEL_INFO: + purple_debug_info("sipe", "%s\n", msg); + break; + case SIPE_DEBUG_LEVEL_ERROR: + purple_debug_error("sipe", "%s\n", msg); + break; + case SIPE_DEBUG_LEVEL_FATAL: + purple_debug_fatal("sipe", "%s\n", msg); + break; + } + g_free(msg); + } + + va_end(ap); +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ diff --git a/src/purple/purple-plugin.c b/src/purple/purple-plugin.c index f288dfb0..cb8c7e55 100644 --- a/src/purple/purple-plugin.c +++ b/src/purple/purple-plugin.c @@ -36,7 +36,6 @@ #endif #include "accountopt.h" -#include "debug.h" #include "prpl.h" #include "plugin.h" @@ -44,6 +43,7 @@ #include "sipe-nls.h" #include "sipe-core-api.h" +#include "sipe-backend-debug.h" #include "core-depurple.h" @@ -77,9 +77,10 @@ static void init_plugin(PurplePlugin *plugin) sip_sec_init(); #ifdef ENABLE_NLS - purple_debug_info(PACKAGE_NAME, "bindtextdomain = %s\n", bindtextdomain(PACKAGE_NAME, LOCALEDIR)); - purple_debug_info(PACKAGE_NAME, "bind_textdomain_codeset = %s\n", - bind_textdomain_codeset(PACKAGE_NAME, "UTF-8")); + SIPE_DEBUG_INFO("bindtextdomain = %s", + bindtextdomain(PACKAGE_NAME, LOCALEDIR)); + SIPE_DEBUG_INFO("bind_textdomain_codeset = %s", + bind_textdomain_codeset(PACKAGE_NAME, "UTF-8")); textdomain(PACKAGE_NAME); #endif -- 2.11.4.GIT