Use a Queue in gstnicesrc to avoid multiple read_callbacks overwriting the out buffer
[sipe-libnice.git] / agent / debug.c
bloba7f134044351f95265fbe09a1713be2881861d04
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2008 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2008 Nokia Corporation. All rights reserved.
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
16 * License.
18 * The Original Code is the Nice GLib ICE library.
20 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
21 * Corporation. All Rights Reserved.
23 * Contributors:
24 * Youness Alaoui, Collabora Ltd.
26 * Alternatively, the contents of this file may be used under the terms of the
27 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
28 * case the provisions of LGPL are applicable instead of those above. If you
29 * wish to allow use of your version of this file only under the terms of the
30 * LGPL and not to allow others to use your version of this file under the
31 * MPL, indicate your decision by deleting the provisions above and replace
32 * them with the notice and other provisions required by the LGPL. If you do
33 * not delete the provisions above, a recipient may use your version of this
34 * file under either the MPL or the LGPL.
37 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
41 #include "debug.h"
43 #include "stunagent.h"
44 #include "pseudotcp.h"
46 static int debug_enabled = 0;
48 #define NICE_DEBUG_STUN 1
49 #define NICE_DEBUG_NICE 2
50 #define NICE_DEBUG_PSEUDOTCP 4
51 #define NICE_DEBUG_PSEUDOTCP_VERBOSE 8
53 static const GDebugKey keys[] = {
54 { (gchar *)"stun", NICE_DEBUG_STUN },
55 { (gchar *)"nice", NICE_DEBUG_NICE },
56 { (gchar *)"pseudotcp", NICE_DEBUG_PSEUDOTCP },
57 { (gchar *)"pseudotcp-verbose", NICE_DEBUG_PSEUDOTCP_VERBOSE },
58 { NULL, 0},
62 void nice_debug_init ()
64 static gboolean debug_initialized = FALSE;
65 const gchar *flags_string;
66 guint flags;
68 if (!debug_initialized) {
69 debug_initialized = TRUE;
71 flags_string = g_getenv ("NICE_DEBUG");
73 nice_debug_disable (TRUE);
75 if (flags_string != NULL) {
76 flags = g_parse_debug_string (flags_string, keys, 4);
78 if (flags & NICE_DEBUG_NICE)
79 nice_debug_enable (FALSE);
80 if (flags & NICE_DEBUG_STUN)
81 stun_debug_enable ();
83 /* Set verbose before normal so that if we use 'all', then only
84 normal debug is enabled, we'd need to set pseudotcp-verbose without the
85 pseudotcp flag in order to actually enable verbose pseudotcp */
86 if (flags & NICE_DEBUG_PSEUDOTCP_VERBOSE)
87 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_VERBOSE);
88 if (flags & NICE_DEBUG_PSEUDOTCP)
89 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_NORMAL);
94 void nice_debug_enable (gboolean with_stun)
96 nice_debug_init ();
97 debug_enabled = 1;
98 if (with_stun)
99 stun_debug_enable ();
101 void nice_debug_disable (gboolean with_stun)
103 nice_debug_init ();
104 debug_enabled = 0;
105 if (with_stun)
106 stun_debug_disable ();
109 void nice_debug (const char *fmt, ...)
111 va_list ap;
112 if (debug_enabled) {
113 va_start (ap, fmt);
114 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap);
115 va_end (ap);