From: Richard Kettlewell Date: Sun, 8 Jun 2008 12:13:17 +0000 (+0100) Subject: Report disorder_eclient_volume() errors to the specific callback. X-Git-Tag: 4.1~15^2~79 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/699517afce8942f7f43952adfe242d7a0c09f2d0 Report disorder_eclient_volume() errors to the specific callback. (Untested for now.) --- diff --git a/disobedience/control.c b/disobedience/control.c index 15c58e9..9bb7c96 100644 --- a/disobedience/control.c +++ b/disobedience/control.c @@ -445,6 +445,17 @@ static void toggled_menu(GtkCheckMenuItem *menuitem, icons[n].action(client, icon_action_completed, 0); } +/** @brief Called when a volume command completes */ +static void volume_completed(void attribute((unused)) *v, + const char *error, + int attribute((unused)) l, + int attribute((unused)) r) { + if(error) + popup_protocol_error(0, error); + /* We don't set the UI's notion of the volume here, it is set from the log + * regardless of the reason it changed */ +} + /** @brief Called when the volume has been adjusted */ static void volume_adjusted(GtkAdjustment attribute((unused)) *a, gpointer attribute((unused)) user_data) { @@ -465,8 +476,7 @@ static void volume_adjusted(GtkAdjustment attribute((unused)) *a, int l = nearbyint(left(v, b) * 100), r = nearbyint(right(v, b) * 100); mixer_control(DEFAULT_BACKEND, &l, &r, 1); } else - /* We don't want a reply, we'll get the actual new volume from the log. */ - disorder_eclient_volume(client, 0, + disorder_eclient_volume(client, volume_completed, nearbyint(left(v, b) * 100), nearbyint(right(v, b) * 100), 0); diff --git a/lib/eclient.c b/lib/eclient.c index 1fc0bfe..a753a52 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -981,21 +981,20 @@ static void list_response_opcallback(disorder_eclient *c, /* for volume */ static void volume_response_opcallback(disorder_eclient *c, struct operation *op) { + disorder_eclient_volume_response *completed + = (disorder_eclient_volume_response *)op->completed; int l, r; D(("volume_response_callback")); if(c->rc / 100 == 2) { if(op->completed) { if(sscanf(c->line + 4, "%d %d", &l, &r) != 2 || l < 0 || r < 0) - /* TODO don't use protocol_error here */ - protocol_error(c, op, -1, "%s: invalid volume response: %s", - c->ident, c->line); + completed(op->v, "cannot parse volume response", 0, 0); else - ((disorder_eclient_volume_response *)op->completed)(op->v, l, r); + completed(op->v, 0, l, r); } } 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, 0); } static int simple(disorder_eclient *c, diff --git a/lib/eclient.h b/lib/eclient.h index 1b47dff..56ff9e6 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -144,8 +144,7 @@ struct kvp; struct sink; /* Completion callbacks. These provide the result of operations to the caller. - * It is always allowed for these to be null pointers if you don't care about - * the result. */ + * Unlike in earlier releases, these are not allowed to be NULL. */ /** @brief Trivial completion callback * @param v User data @@ -181,10 +180,21 @@ typedef void disorder_eclient_string_response(void *v, 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); -/* completion callback with a pair of integer results */ +/** @brief Volume completion callback + * @param v User data + * @param error Error string or NULL on success + * @param l Left channel volume + * @param r Right channel volume + * + * @p error will be NULL on success. In this case @p l and @p r will be the + * result. + * + * @p error will be non-NULL on failure. In this case @p l and @p r are always + * 0. + */ +typedef void disorder_eclient_volume_response(void *v, + const char *error, + int l, int r); typedef void disorder_eclient_queue_response(void *v, struct queue_entry *q); /* completion callback for queue/recent listing */