chiark / gitweb /
eclient integer callbacks now get errors instead of using generic
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 12:06:03 +0000 (13:06 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 12:06:03 +0000 (13:06 +0100)
protocol error callback.

disobedience/queue.c
lib/eclient.c
lib/eclient.h

index 7240417b64283655fc90a32917860e66241a4174..c3d62b00a8fc9a9bcd559dcfcba1253e3cdcfaac 100644 (file)
@@ -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 {
 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 */
     ++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();
 }
 
   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;
 static long getlength(const char *track) {
   char *key;
   const long *value;
-  struct callbackdata *cbd;
   static const long bogus = -1;
 
   D(("getlength %s", track));
   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;
     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;
 }
   }
   return *value;
 }
index d784d413ef05f5b78313386d16b2fcc78e4ec0c1..1fc0bfebea92dd163d2d5f7f9f1b29e153b197d2 100644 (file)
@@ -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) {
 /* 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) {
   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
   } 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 */
 }
 
 /* for commands with no response */
index 3ea8b15fbfc843b119ac8c0f5499d7425eb2a24f..1b47dff9877efbe33a6b12bdd55da1e7ea8f153b 100644 (file)
@@ -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
 /** @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(),
  *
  * @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);
 
                                               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);
 /* completion callback with a integer result */
 
 typedef void disorder_eclient_volume_response(void *v, int l, int r);