telepathygabble/src/debug.c
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /*
       
     2  * debug.c 
       
     3  * Copyright (C) 2006 Collabora Ltd.
       
     4  * 
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2.1 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this library; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    18  */
       
    19 #include <stdarg.h>
       
    20 #include <stdio.h> // bsr 
       
    21 #include <glib.h>
       
    22 
       
    23 #include "debug.h"
       
    24 
       
    25 /*#ifdef ENABLE_DEBUG*/
       
    26 
       
    27 #ifdef EMULATOR
       
    28 #include "libgabble_wsd_solution.h"
       
    29 
       
    30 	GET_STATIC_VAR_FROM_TLS(flags,gabble_debug,GabbleDebugFlags)
       
    31 	#define flags (*GET_WSD_VAR_NAME(flags,gabble_debug,s)())
       
    32 
       
    33 	GET_STATIC_VAR_FROM_TLS(log_handler,gabble_debug,guint)
       
    34 	#define log_handler (*GET_WSD_VAR_NAME(log_handler,gabble_debug,s)())
       
    35 	
       
    36 	GET_STATIC_ARRAY_FROM_TLS(keys,gabble_debug,GDebugKey)
       
    37 	#define keys (GET_WSD_VAR_NAME(keys,gabble_debug, s)())	
       
    38 
       
    39 
       
    40 #else
       
    41 	static GabbleDebugFlags flags = 0;
       
    42 	static guint log_handler; // bsr
       
    43 	GDebugKey keys[] = {
       
    44   { "presence",      GABBLE_DEBUG_PRESENCE },
       
    45   { "groups",        GABBLE_DEBUG_GROUPS },
       
    46   { "roster",        GABBLE_DEBUG_ROSTER },
       
    47   { "disco",         GABBLE_DEBUG_DISCO },
       
    48   { "properties",    GABBLE_DEBUG_PROPERTIES },
       
    49   { "roomlist",      GABBLE_DEBUG_ROOMLIST },
       
    50   { "media-channel", GABBLE_DEBUG_MEDIA },
       
    51   { "muc",           GABBLE_DEBUG_MUC },
       
    52   { "connection",    GABBLE_DEBUG_CONNECTION },
       
    53   { "persist",       GABBLE_DEBUG_PERSIST },
       
    54   { "vcard",         GABBLE_DEBUG_VCARD },
       
    55   { 0, },
       
    56 };
       
    57 
       
    58 	
       
    59 #endif
       
    60 
       
    61 /* bsr added new */
       
    62 static void
       
    63 debug_log_handler1 (const gchar    *log_domain,
       
    64 		   GLogLevelFlags  log_level,
       
    65 		   const gchar    *message,
       
    66 		   gpointer        user_data)
       
    67 {
       
    68 	#ifdef _DEBUG
       
    69 	
       
    70    FILE* fp;
       
    71 	
       
    72 			fp = fopen("c:\\gabblelogs.txt","a");
       
    73 	if(fp)
       
    74 	{
       
    75 		fprintf(fp,message);
       
    76 		fprintf(fp,"\n");
       
    77 		fclose(fp);
       
    78 	}
       
    79 	#endif //_DEBUG
       
    80 }
       
    81 
       
    82 #ifdef SYMBIAN
       
    83 EXPORT_C
       
    84 #endif
       
    85 void gabble_debug_set_flags_from_env ()
       
    86 {
       
    87   guint nkeys;
       
    88   const gchar *flags_string;
       
    89 
       
    90   for (nkeys = 0; keys[nkeys].value; nkeys++);
       
    91 
       
    92   flags_string = g_getenv ("GABBLE_DEBUG");
       
    93 
       
    94   if (flags_string)
       
    95     gabble_debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
       
    96     
       
    97   // bsr
       
    98   	log_handler = g_log_set_handler (NULL, 0xFF, 
       
    99 			   debug_log_handler1, NULL);    
       
   100 }
       
   101 
       
   102 #ifdef SYMBIAN
       
   103 EXPORT_C
       
   104 #endif
       
   105 void gabble_debug_set_flags (GabbleDebugFlags new_flags)
       
   106 {
       
   107   flags |= new_flags;
       
   108 }
       
   109 
       
   110 
       
   111 gboolean gabble_debug_flag_is_set (GabbleDebugFlags flag)
       
   112 {
       
   113   return flag & flags;
       
   114 }
       
   115 
       
   116 void gabble_debug (GabbleDebugFlags flag,
       
   117                    const gchar *format,
       
   118                    ...)
       
   119 {
       
   120   if (flag & flags)
       
   121     {
       
   122       va_list args;
       
   123       va_start (args, format);
       
   124       g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
       
   125       va_end (args);
       
   126     }
       
   127 }
       
   128 
       
   129 /*#endif /* ENABLE_DEBUG */
       
   130