From 658c8a359409a339d71910f68452bfaa751734c0 Mon Sep 17 00:00:00 2001 Message-Id: <658c8a359409a339d71910f68452bfaa751734c0.1714918330.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 8 Jun 2008 13:06:03 +0100 Subject: [PATCH] eclient integer callbacks now get errors instead of using generic protocol error callback. Organization: Straylight/Edgeware From: Richard Kettlewell --- disobedience/queue.c | 44 ++++++++++++++++++-------------------------- lib/eclient.c | 17 ++++++++++++----- lib/eclient.h | 15 +++++++++++++-- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/disobedience/queue.c b/disobedience/queue.c index 7240417..c3d62b0 100644 --- a/disobedience/queue.c +++ b/disobedience/queue.c @@ -272,37 +272,33 @@ static void namepart_completed_or_failed(void) { } } -/** @brief Called when A namepart lookup has completed */ +/** @brief Called when a namepart lookup has completed */ static void namepart_completed(void *v, const char *error, const char *value) { if(error) { gtk_label_set_text(GTK_LABEL(report_label), error); } else { - cache_put(&cachetype_string, v, value); + const char *key = v; + + cache_put(&cachetype_string, key, value); ++namepart_completions_deferred; } namepart_completed_or_failed(); } /** @brief Called when a length lookup has completed */ -static void length_completed(void *v, long l) { - struct callbackdata *cbd = v; - long *value; - - D(("namepart_completed")); - value = xmalloc(sizeof *value); - *value = l; - cache_put(&cachetype_integer, cbd->u.key, value); - ++namepart_completions_deferred; - namepart_completed_or_failed(); -} - -/** @brief Called when a length or namepart lookup has failed */ -static void namepart_protocol_error( - struct callbackdata attribute((unused)) *cbd, - int attribute((unused)) code, - const char *msg) { - D(("namepart_protocol_error")); - gtk_label_set_text(GTK_LABEL(report_label), msg); +static void length_completed(void *v, const char *error, long l) { + if(error) + gtk_label_set_text(GTK_LABEL(report_label), error); + else { + const char *key = v; + long *value; + + D(("namepart_completed")); + value = xmalloc(sizeof *value); + *value = l; + cache_put(&cachetype_integer, key, value); + ++namepart_completions_deferred; + } namepart_completed_or_failed(); } @@ -360,7 +356,6 @@ void namepart_update(const char *track, static long getlength(const char *track) { char *key; const long *value; - struct callbackdata *cbd; static const long bogus = -1; D(("getlength %s", track)); @@ -370,10 +365,7 @@ static long getlength(const char *track) { D(("deferring..."));; cache_put(&cachetype_integer, key, value = &bogus); ++namepart_lookups_outstanding; - cbd = xmalloc(sizeof *cbd); - cbd->onerror = namepart_protocol_error; - cbd->u.key = key; - disorder_eclient_length(client, length_completed, track, cbd); + disorder_eclient_length(client, length_completed, track, key); } return *value; } diff --git a/lib/eclient.c b/lib/eclient.c index d784d41..1fc0bfe 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -871,14 +871,21 @@ static void string_response_opcallback(disorder_eclient *c, /* for commands with a simple integer response */ static void integer_response_opcallback(disorder_eclient *c, struct operation *op) { + disorder_eclient_integer_response *completed + = (disorder_eclient_integer_response *)op->completed; + D(("string_response_callback")); if(c->rc / 100 == 2) { - if(op->completed) - ((disorder_eclient_integer_response *)op->completed) - (op->v, strtol(c->line + 4, 0, 10)); + long n; + int e; + + e = xstrtol(&n, c->line + 4, 0, 10); + if(e) + completed(op->v, strerror(e), 0); + else + completed(op->v, 0, n); } else - /* TODO don't use protocol_error here */ - protocol_error(c, op, c->rc, "%s: %s", c->ident, c->line); + completed(op->v, errorstring(c), 0); } /* for commands with no response */ diff --git a/lib/eclient.h b/lib/eclient.h index 3ea8b15..1b47dff 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -157,7 +157,7 @@ typedef void disorder_eclient_no_response(void *v, /** @brief String result completion callback * @param v User data * @param error Error string or NULL on succes - * @param value or NULL if not found + * @param value Result or NULL * * @p error will be NULL on success. In this case @p value will be the result * (which might be NULL for disorder_eclient_get(), @@ -169,7 +169,18 @@ typedef void disorder_eclient_string_response(void *v, const char *error, const char *value); -typedef void disorder_eclient_integer_response(void *v, long value); +/** @brief String result completion callback + * @param v User data + * @param error Error string or NULL on succes + * @param value Result or 0 + * + * @p error will be NULL on success. In this case @p value will be the result. + * + * @p error will be non-NULL on failure. In this case @p value is always 0. + */ +typedef void disorder_eclient_integer_response(void *v, + const char *error, + long value); /* completion callback with a integer result */ typedef void disorder_eclient_volume_response(void *v, int l, int r); -- [mdw]