summaryrefslogtreecommitdiff
path: root/libgdict/gdict-client-context.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@src.gnome.org>2007-09-06 17:05:16 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2007-09-06 17:05:16 +0000
commit7bbe862950ff5b8695fdf1f0e0df1efd1bf8a1e7 (patch)
treed7645a20f34f419869e9494bf28fdb0213c70968 /libgdict/gdict-client-context.c
parent18f7942129dd631ff6955227497ac0641ace9cbe (diff)
downloadgnome-dictionary-7bbe862950ff5b8695fdf1f0e0df1efd1bf8a1e7.tar.gz
Improve GDict debug messages handling
This commit changes the debug messages handling in GDict, using a system similar to the one GLib and GTK+ use. You can either set the GDICT_DEBUG environment variable to a colon-separated or comma-separated list of debug flags, or you can use the --gdict-debug and --gdict-no-debug command line arguments to switch on (and off) the debug flags. The GDICT_NOTE() macro has been added as well, replacing _gdict_debug() for a more comprehensive debug output. The entire debug message system is enabled either by calling the gdict_debug_init() function or by using the GOptionGroup that is returned by gdict_get_option_group(). The debug message system is also depending on whether the GDict library has been compiled with the GDICT_ENABLE_DEBUG flag -- which is the default for development/unstable cycles. svn path=/trunk/; revision=7661
Diffstat (limited to 'libgdict/gdict-client-context.c')
-rw-r--r--libgdict/gdict-client-context.c122
1 files changed, 56 insertions, 66 deletions
diff --git a/libgdict/gdict-client-context.c b/libgdict/gdict-client-context.c
index db8cd29..4528bb8 100644
--- a/libgdict/gdict-client-context.c
+++ b/libgdict/gdict-client-context.c
@@ -55,6 +55,7 @@
#include "gdict-client-context.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
+#include "gdict-debug.h"
#include "gdict-utils.h"
#include "gdict-private.h"
@@ -723,8 +724,9 @@ gdict_client_context_push_command (GdictClientContext *context,
return FALSE;
}
- _gdict_debug ("Pushing command ('%s') into the queue...\n",
- dict_command_strings[command->cmd_type]);
+ GDICT_NOTE (DICT, "Pushing command ('%s') into the queue...",
+ dict_command_strings[command->cmd_type]);
+
g_queue_push_head (priv->commands_queue, command);
return TRUE;
@@ -744,8 +746,8 @@ gdict_client_context_pop_command (GdictClientContext *context)
if (!retval)
return NULL;
- _gdict_debug ("Getting command ('%s') from the queue...\n",
- dict_command_strings[retval->cmd_type]);
+ GDICT_NOTE (DICT, "Getting command ('%s') from the queue...",
+ dict_command_strings[retval->cmd_type]);
return retval;
}
@@ -768,7 +770,7 @@ gdict_client_context_send_command (GdictClientContext *context,
if (!priv->channel)
{
- _gdict_debug ("No connection established\n");
+ GDICT_NOTE (DICT, "No connection established");
g_set_error (error, GDICT_CLIENT_CONTEXT_ERROR,
GDICT_CLIENT_CONTEXT_ERROR_NO_CONNECTION,
@@ -795,8 +797,7 @@ gdict_client_context_send_command (GdictClientContext *context,
/* force flushing of the write buffer */
g_io_channel_flush (priv->channel, NULL);
- _gdict_debug ("Wrote (%d bytes) to the channel\n",
- written_bytes);
+ GDICT_NOTE (DICT, "Wrote %d bytes to the channel", written_bytes);
return TRUE;
}
@@ -819,17 +820,17 @@ gdict_client_context_run_command (GdictClientContext *context,
g_assert (command != NULL);
g_assert (IS_VALID_CMD (command->cmd_type));
- _gdict_debug ("GdictCommand command =\n"
- "{\n"
- " .cmd_type = '%02d' ('%s');\n"
- " .database = '%s';\n"
- " .strategy = '%s';\n"
- " .word = '%s';\n"
- "}\n",
- command->cmd_type, dict_command_strings[command->cmd_type],
- command->database ? command->database : "<none>",
- command->strategy ? command->strategy : "<none>",
- command->word ? command->word : "<none>");
+ GDICT_NOTE (DICT, "GdictCommand command =\n"
+ "{\n"
+ " .cmd_type = '%02d' ('%s');\n"
+ " .database = '%s';\n"
+ " .strategy = '%s';\n"
+ " .word = '%s';\n"
+ "}\n",
+ command->cmd_type, dict_command_strings[command->cmd_type],
+ command->database ? command->database : "<none>",
+ command->strategy ? command->strategy : "<none>",
+ command->word ? command->word : "<none>");
priv = context->priv;
@@ -885,8 +886,8 @@ gdict_client_context_run_command (GdictClientContext *context,
g_assert (command->cmd_string);
- _gdict_debug ("Sending command ('%s') to the server\n",
- dict_command_strings[command->cmd_type]);
+ GDICT_NOTE (DICT, "Sending command ('%s') to the server",
+ dict_command_strings[command->cmd_type]);
send_error = NULL;
res = gdict_client_context_send_command (context, command, &send_error);
@@ -1028,14 +1029,14 @@ gdict_client_context_lookup_server (GdictClientContext *context,
/* clear any previously acquired lookup data */
gdict_client_context_clear_hostinfo (context);
- _gdict_debug ("Looking up hostname '%s'\n", priv->hostname);
+ GDICT_NOTE (DICT, "Looking up hostname '%s'", priv->hostname);
#ifdef ENABLE_IPV6
if (_gdict_has_ipv6 ())
{
struct addrinfo hints, *res;
- _gdict_debug ("Hostname '%s' look-up (using IPv6)\n", priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' look-up (using IPv6)", priv->hostname);
memset (&hints, 0, sizeof (hints));
hints.ai_socktype = SOCK_STREAM;
@@ -1069,8 +1070,8 @@ gdict_client_context_lookup_server (GdictClientContext *context,
priv->sockaddr.ss_family = res->ai_family;
- _gdict_debug ("Hostname '%s' found (using IPv6)\n",
- priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' found (using IPv6)\n",
+ priv->hostname);
priv->last_lookup = time (NULL);
@@ -1093,8 +1094,7 @@ gdict_client_context_lookup_server (GdictClientContext *context,
#endif /* ENABLE_IPV6 */
/* if we don't support IPv6, fallback to usual IPv4 lookup */
- _gdict_debug ("Hostname '%s' look-up (using IPv4)\n",
- priv->hostname);
+ GDICT_NOTE ("Hostname '%s' look-up (using IPv4)", priv->hostname);
((struct sockaddr_in *) &priv->sockaddr)->sin_family = AF_INET;
@@ -1105,8 +1105,8 @@ gdict_client_context_lookup_server (GdictClientContext *context,
priv->hostinfo->h_addr,
priv->hostinfo->h_length);
- _gdict_debug ("Hostname '%s' found (using IPv4)\n",
- priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' found (using IPv4)\n",
+ priv->hostname);
priv->last_lookup = time (NULL);
@@ -1146,7 +1146,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
priv = context->priv;
- _gdict_debug ("parse buffer: '%s'\n", buffer);
+ GDICT_NOTE (DICT, "parse buffer: '%s'", buffer);
/* connection is a special case: we don't have a command, so we just
* make sure that the server replied with the correct code. WARNING:
@@ -1219,7 +1219,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No definitions found for '%s'"),
priv->command->word);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE ("No match: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1234,7 +1234,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Invalid database '%s'"),
priv->command->database);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad DB: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1249,7 +1249,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Invalid strategy '%s'"),
priv->command->strategy);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad strategy: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1264,7 +1264,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Bad command '%s'"),
dict_command_strings[priv->command->cmd_type]);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad command: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1279,7 +1279,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Bad parameters for command '%s'"),
dict_command_strings[priv->command->cmd_type]);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad params: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1294,7 +1294,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No databases found on dictionary server at '%s'"),
priv->hostname);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "No DB: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1309,7 +1309,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No strategies found on dictionary server at '%s'"),
priv->hostname);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "No strategies: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1319,7 +1319,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
priv->command->state = S_FINISH;
break;
default:
- _gdict_debug ("non error code: %d\n", priv->status_code);
+ GDICT_NOTE (DICT, "non-error code: %d", priv->status_code);
break;
}
@@ -1366,10 +1366,10 @@ gdict_client_context_parse_line (GdictClientContext *context,
return TRUE;
}
- _gdict_debug ("check command %d ('%s')[state:%d]\n",
- priv->command->cmd_type,
- dict_command_strings[priv->command->cmd_type],
- priv->command->state);
+ GDICT_NOTE (DICT, "check command %d ('%s')[state:%d]",
+ priv->command->cmd_type,
+ dict_command_strings[priv->command->cmd_type],
+ priv->command->state);
/* check command type */
switch (priv->command->cmd_type)
@@ -1388,9 +1388,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d databases found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d databases found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1425,7 +1424,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
db = _gdict_database_new (name);
db->full_name = g_strdup (full);
- _gdict_debug ("emitting database-found\n");
g_signal_emit_by_name (context, "database-found", db);
gdict_database_unref (db);
@@ -1442,9 +1440,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d strategies found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d strategies found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1476,7 +1473,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
strat = _gdict_strategy_new (name);
strat->description = g_strdup (desc);
- _gdict_debug ("emitting strategy-found\n");
g_signal_emit_by_name (context, "strategy-found", strat);
gdict_strategy_unref (strat);
@@ -1494,14 +1490,13 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d definitions found\n", atoi (p));
-
+ GDICT_NOTE (DICT, "server replied: %d definitions found", atoi (p));
+
def = _gdict_definition_new (atoi (p));
priv->command->data = def;
priv->command->data_destroy = (GDestroyNotify) gdict_definition_unref;
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (priv->status_code == GDICT_STATUS_WORD_DB_NAME)
@@ -1548,11 +1543,11 @@ gdict_client_context_parse_line (GdictClientContext *context,
def = (GdictDefinition *) priv->command->data;
- _gdict_debug ("{ word .= '%s', db_name .= '%s', db_full .= '%s' }\n",
- word,
- db_name,
- db_full);
-
+ GDICT_NOTE (DICT, "{ word = '%s', db_name = '%s', db_full = '%s' }",
+ word,
+ db_name,
+ db_full);
+
def->word = g_strdup (word);
def->database_name = g_strdup (db_name);
def->database_full = g_strdup (db_full);
@@ -1575,8 +1570,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
/* store the numer of definitions */
num = def->total;
-
- _gdict_debug ("emitting definition-found\n");
+
g_signal_emit_by_name (context, "definition-found", def);
gdict_definition_unref (def);
@@ -1593,7 +1587,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (!priv->command->buffer)
priv->command->buffer = g_string_new (NULL);
- _gdict_debug ("appending line:\n %s\n", buffer);
+ GDICT_NOTE (DICT, "appending to buffer:\n %s\n", buffer);
/* TODO - collapse '..' to '.' */
g_string_append_printf (priv->command->buffer, "%s\n", buffer);
@@ -1610,9 +1604,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d matches found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d matches found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1644,7 +1637,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
match = _gdict_match_new (word);
match->database = g_strdup (db_name);
- _gdict_debug ("emitting match-found\n");
g_signal_emit_by_name (context, "match-found", match);
gdict_match_unref (match);
@@ -1811,7 +1803,7 @@ gdict_client_context_io_watch_cb (GIOChannel *channel,
{
priv->status_code = status_code;
- _gdict_debug ("new status = '%d'\n", priv->status_code);
+ GDICT_NOTE (DICT, "new status = '%d'", priv->status_code);
}
else
priv->status_code = GDICT_STATUS_INVALID;
@@ -1825,15 +1817,13 @@ gdict_client_context_io_watch_cb (GIOChannel *channel,
{
g_free (line);
- _gdict_debug ("Parse failed\n");
+ g_warning ("Parsing failed");
gdict_client_context_force_disconnect (context);
return FALSE;
}
- _gdict_debug ("Line parsed\n");
-
g_free (line);
}
@@ -1854,7 +1844,7 @@ check_for_connection (gpointer data)
{
GError *err = NULL;
- _gdict_debug ("Forcing a disconnection due to timeout");
+ GDICT_NOTE (DICT, "Forcing a disconnection due to timeout");
g_set_error (&err, GDICT_CLIENT_CONTEXT_ERROR,
GDICT_CLIENT_CONTEXT_ERROR_SOCKET,