From d73655917875981b0c7ccae3b9a016e25ad99ed2 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Wed, 22 Aug 2012 18:22:59 +0300 Subject: [PATCH] telepathy: implement debugging After adding the missing object constructed/finalize functions we actually get to see the first sign of life. Yeah! --- src/telepathy/Makefile.am | 1 + src/telepathy/telepathy-debug.c | 86 +++++++++++++++++++++++++++++++++++++++ src/telepathy/telepathy-main.c | 43 ++++++++++++++++---- src/telepathy/telepathy-private.h | 37 +++++++++++++++++ 4 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 src/telepathy/telepathy-debug.c create mode 100644 src/telepathy/telepathy-private.h diff --git a/src/telepathy/Makefile.am b/src/telepathy/Makefile.am index 333b9c9f..c857ebff 100644 --- a/src/telepathy/Makefile.am +++ b/src/telepathy/Makefile.am @@ -6,6 +6,7 @@ MAINTAINERCLEANFILES = \ libexec_PROGRAMS = telepathy-sipe telepathy_sipe_SOURCES = \ + telepathy-debug.c \ telepathy-main.c AM_CFLAGS = $(st) diff --git a/src/telepathy/telepathy-debug.c b/src/telepathy/telepathy-debug.c new file mode 100644 index 00000000..e8f4eebf --- /dev/null +++ b/src/telepathy/telepathy-debug.c @@ -0,0 +1,86 @@ +/** + * @file telepathy-debug.c + * + * pidgin-sipe + * + * Copyright (C) 2012 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 + +#include "sipe-backend.h" +#include "telepathy-private.h" + +static TpDebugSender *debug; + +void sipe_telepathy_debug_init(void) +{ + debug = tp_debug_sender_dup(); +} + +void sipe_telepathy_debug_finalize(void) +{ + g_object_unref(debug); +} + +static const GLogLevelFlags debug_level_mapping[] = { + G_LOG_LEVEL_INFO, /* SIPE_DEBUG_LEVEL_INFO */ + G_LOG_LEVEL_WARNING, /* SIPE_DEBUG_LEVEL_WARNING */ + G_LOG_LEVEL_CRITICAL, /* SIPE_DEBUG_LEVEL_ERROR */ + G_LOG_LEVEL_ERROR, /* SIPE_DEBUG_LEVEL_FATAL */ +}; + +void sipe_backend_debug_literal(sipe_debug_level level, + const gchar *msg) +{ + GTimeVal now; + g_get_current_time(&now); + tp_debug_sender_add_message(debug, &now, SIPE_TELEPATHY_DOMAIN, + debug_level_mapping[level], msg); +} + +void sipe_backend_debug(sipe_debug_level level, + const gchar *format, + ...) +{ + GTimeVal now; + va_list ap; + + va_start(ap, format); + g_get_current_time(&now); + tp_debug_sender_add_message_vprintf(debug, &now, NULL, + SIPE_TELEPATHY_DOMAIN, + debug_level_mapping[level], + format, ap); + va_end(ap); +} + +gboolean sipe_backend_debug_enabled(void) +{ + return(TRUE); +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ diff --git a/src/telepathy/telepathy-main.c b/src/telepathy/telepathy-main.c index 7d5146ac..2a835ffe 100644 --- a/src/telepathy/telepathy-main.c +++ b/src/telepathy/telepathy-main.c @@ -28,6 +28,9 @@ #include #include +#include "sipe-backend.h" +#include "telepathy-private.h" + G_BEGIN_DECLS /* * Connection manager type - data structures @@ -65,16 +68,28 @@ G_DEFINE_TYPE(SipeConnectionManager, sipe_connection_manager, TP_TYPE_BASE_CONNECTION_MANAGER) +static void sipe_connection_manager_constructed(GObject *object) +{ + /* always chain up to the parent constructor first */ + G_OBJECT_CLASS(sipe_connection_manager_parent_class)->constructed(object); +} + +static void sipe_connection_manager_finalize(GObject *object) +{ + /* always chain up to the parent constructor last */ + G_OBJECT_CLASS(sipe_connection_manager_parent_class)->finalize(object); +} + static void sipe_connection_manager_class_init(SipeConnectionManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); TpBaseConnectionManagerClass *base_class = (TpBaseConnectionManagerClass *)klass; - object_class->constructed = NULL; - object_class->finalize = NULL; + object_class->constructed = sipe_connection_manager_constructed; + object_class->finalize = sipe_connection_manager_finalize; base_class->new_connection = NULL; - base_class->cm_dbus_name = "sipe"; + base_class->cm_dbus_name = SIPE_TELEPATHY_DOMAIN; base_class->protocol_params = NULL; } @@ -91,11 +106,23 @@ static TpBaseConnectionManager *construct_cm(void) int main(int argc, char *argv[]) { - return(tp_run_connection_manager("sipe", - PACKAGE_VERSION, - construct_cm, - argc, - argv)); + int rc; + + g_type_init(); + sipe_telepathy_debug_init(); + + sipe_backend_debug(SIPE_DEBUG_LEVEL_INFO, + "initializing - version %s", + PACKAGE_VERSION); + + rc = tp_run_connection_manager(SIPE_TELEPATHY_DOMAIN, + PACKAGE_VERSION, + construct_cm, + argc, + argv); + + sipe_telepathy_debug_finalize(); + return(rc); } /* diff --git a/src/telepathy/telepathy-private.h b/src/telepathy/telepathy-private.h new file mode 100644 index 00000000..b584a1e9 --- /dev/null +++ b/src/telepathy/telepathy-private.h @@ -0,0 +1,37 @@ +/** + * @file telepathy-private.h + * + * pidgin-sipe + * + * Copyright (C) 2012 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 + */ + +/* constants */ +#define SIPE_TELEPATHY_DOMAIN "sipe" + +/* debugging */ +void sipe_telepathy_debug_init(void); +void sipe_telepathy_debug_finalize(void); + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ -- 2.11.4.GIT