Back to index

libunity  5.92.0
unity-trace.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical, Ltd.
00003  *
00004  * This library is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License
00006  * version 3.0 as published by the Free Software Foundation.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU Lesser General Public License version 3.0 for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library. If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
00018  */
00019 
00020 /*
00021  * This file contains some special GObject-centric debugging macros that
00022  * can be compiled completely out out of the final binary 
00023  */
00024 
00025 #include <glib.h>
00026 
00027 #ifndef _UNITY_TRACE_LOG_H
00028 #define _UNITY_TRACE_LOG_H
00029 
00030 G_BEGIN_DECLS
00031 
00032 /*
00033  * Make trace() a noop if ENABLE_UNITY_TRACE_LOG is not defined
00034  */
00035 #ifdef ENABLE_UNITY_TRACE_LOG
00036 
00037 void     unity_trace_log_object_va   (void *obj, const gchar *format, va_list args);
00038 void     unity_trace_log_object_real (void *obj, const gchar *format, ...);
00039 
00040 #   ifdef G_HAVE_ISO_VARARGS
00041 #         define unity_trace_log(...) g_log (G_LOG_DOMAIN, \
00042                               G_LOG_LEVEL_DEBUG,  \
00043                               __VA_ARGS__)
00044 #         define unity_trace_log_object(object, ...) unity_trace_log_object_real (object, __VA_ARGS__)
00045 
00046 #   elif defined(G_HAVE_GNUC_VARARGS)
00047 #         define unity_trace_log(format...) g_log (G_LOG_DOMAIN,   \
00048                                     G_LOG_LEVEL_DEBUG,  \
00049                                     format)
00050 #         define unity_trace_log_object(object, format...) unity_trace_log_object_real (object, format)
00051 #   else   /* no varargs macros */
00052 static void
00053 unity_trace_log (const gchar *format,
00054                  ...)
00055 {
00056        va_list args;
00057        va_start (args, format);
00058        g_logv (TRACE_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
00059        va_end (args);
00060 }
00061 
00062 static void
00063 unity_trace_log_object (void        *obj,
00064                         const gchar *format,
00065                         ...)
00066 {
00067        va_list args;
00068        va_start (args, format);
00069        unity_trace_log_object_va (obj, format, args);
00070        va_end (args);
00071 }
00072 #   endif  /* !__GNUC__ */
00073 
00074 #else /* NO TRACE LOGGING OUTPUT */
00075 
00076 #   ifdef G_HAVE_ISO_VARARGS
00077 #         define unity_trace_log(...) G_STMT_START{ (void)0; }G_STMT_END
00078 #         define unity_trace_log_object(object, ...) G_STMT_START{ (void)0; }G_STMT_END
00079 #   elif defined(G_HAVE_GNUC_VARARGS)
00080 #         define unity_trace_log(format...) G_STMT_START{ (void)0; }G_STMT_END
00081 #         define unity_trace_log_object(object, format...) G_STMT_START{ (void)0; }G_STMT_END
00082 #   else   /* no varargs macros */
00083 
00084 static void unity_trace_log (const gchar *format, ...) { ; }
00085 static void unity_trace_log_object (GObject *obj, const gchar *format, ...) { ; }
00086 
00087 #   endif /* !__GNUC__ */
00088 
00089 #endif /* ENABLE_UNITY_TRACE_LOG */
00090 
00091 G_END_DECLS
00092 
00093 #endif /* _UNITY_TRACE_LOG_H */
00094