chiark / gitweb /
Doxygen-clean
[disorder] / disobedience / lookup.c
index 2052b30743483db5eca694a6f122533538ac080f..f1605017d87b88fc8f1e1fde6b9b1e5450ffed24 100644 (file)
@@ -2,20 +2,18 @@
  * This file is part of DisOrder
  * Copyright (C) 2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "disobedience.h"
 
@@ -36,10 +34,10 @@ static void namepart_completed_or_failed(void) {
 }
 
 /** @brief Called when a namepart lookup has completed */
-static void namepart_completed(void *v, const char *error, const char *value) {
+static void namepart_completed(void *v, const char *err, const char *value) {
   D(("namepart_completed"));
-  if(error) {
-    gtk_label_set_text(GTK_LABEL(report_label), error);
+  if(err) {
+    gtk_label_set_text(GTK_LABEL(report_label), err);
     value = "?";
   }
   const char *key = v;
@@ -49,10 +47,10 @@ static void namepart_completed(void *v, const char *error, const char *value) {
 }
 
 /** @brief Called when a length lookup has completed */
-static void length_completed(void *v, const char *error, long l) {
+static void length_completed(void *v, const char *err, long l) {
   D(("length_completed"));
-  if(error) {
-    gtk_label_set_text(GTK_LABEL(report_label), error);
+  if(err) {
+    gtk_label_set_text(GTK_LABEL(report_label), err);
     l = -1;
   }
   const char *key = v;
@@ -71,7 +69,6 @@ static void namepart_fill(const char *track,
                           const char *part,
                           const char *key) {
   D(("namepart_fill %s %s %s %s", track, context, part, key));
-  /* We limit the total number of lookups in flight */
   ++namepart_lookups_outstanding;
   D(("namepart_lookups_outstanding -> %d\n", namepart_lookups_outstanding));
   disorder_eclient_namepart(client, namepart_completed,
@@ -82,7 +79,6 @@ static void namepart_fill(const char *track,
  * @param track Track name
  * @param context Context
  * @param part Name part
- * @param lookup If nonzero, will schedule a lookup for unknown values
  *
  * If it is in the cache then just return its value.  If not then look it up
  * and arrange for the queues to be updated when its value is available. */
@@ -137,6 +133,25 @@ long namepart_length(const char *track) {
   return -1;
 }
 
+/** @brief Resolve a track name
+ *
+ * Returns the supplied track name if it doesn't have the answer yet.
+ */
+char *namepart_resolve(const char *track) {
+  char *key;
+
+  byte_xasprintf(&key, "resolve track=%s", track);
+  const char *value = cache_get(&cachetype_string, key);
+  if(!value) {
+    D(("deferring..."));
+    ++namepart_lookups_outstanding;
+    D(("namepart_lookups_outstanding -> %d\n", namepart_lookups_outstanding));
+    disorder_eclient_resolve(client, namepart_completed,
+                             track, (void *)key);
+    value = track;
+  }
+  return xstrdup(value);
+}
 
 /*
 Local Variables: