chiark / gitweb /
Report disorder_eclient_volume() errors to the specific callback.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 12:13:17 +0000 (13:13 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 12:13:17 +0000 (13:13 +0100)
(Untested for now.)

disobedience/control.c
lib/eclient.c
lib/eclient.h

index 15c58e9a3a19c50ba950d7a07ae128454a1d5056..9bb7c96620415d45efa41a218b7f0eb8a319555c 100644 (file)
@@ -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);
index 1fc0bfebea92dd163d2d5f7f9f1b29e153b197d2..a753a52de8bf40c40f3cdfb2fb6d9e28d17afd5a 100644 (file)
@@ -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,
index 1b47dff9877efbe33a6b12bdd55da1e7ea8f153b..56ff9e607bc4cc95ac64cfc4898f97a17f62f794 100644 (file)
@@ -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 */