chiark / gitweb /
remove debugging guff, sorry
[disorder] / disobedience / log.c
index b2e3e6818e7983bf0926dd66ba25ea1481b1d57d..ccb883aae28e7d1013382152567ccf4112aedc1d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "disobedience.h"
 
-/* Functions --------------------------------------------------------------- */
+/* State monitoring -------------------------------------------------------- */
 
 static void log_connected(void *v);
 static void log_completed(void *v, const char *track);
@@ -51,7 +51,14 @@ const disorder_eclient_log_callbacks log_callbacks = {
   log_volume
 };
 
-/* State monitoring -------------------------------------------------------- */
+struct monitor {
+  struct monitor *next;
+  unsigned long mask;
+  monitor_callback *callback;
+  void *u;
+};
+
+static struct monitor *monitors;
 
 void all_update(void) {
   playing_update();
@@ -134,8 +141,16 @@ static void log_scratched(void attribute((unused)) *v,
 
 static void log_state(void attribute((unused)) *v,
                       unsigned long state) {
+  const struct monitor *m;
+  const unsigned long changes = state ^ last_state;
+
+  D(("log_state %s", disorder_eclient_interpret_state(state)));
   last_state = state;
-  control_update();
+  /* Tell anything that cares about the state change */
+  for(m = monitors; m; m = m->next) {
+    if(changes & m->mask)
+      m->callback(m->u);
+  }
   /* If the track is paused or resume then the currently playing track is
    * refetched so that we can continue to correctly calculate the played so-far
    * field */
@@ -151,6 +166,18 @@ static void log_volume(void attribute((unused)) *v,
   }
 }
 
+void register_monitor(monitor_callback *callback,
+                      void *u,
+                      unsigned long mask) {
+  struct monitor *m = xmalloc(sizeof *m);
+
+  m->next = monitors;
+  m->mask = mask;
+  m->callback = callback;
+  m->u = u;
+  monitors = m;
+}
+
 /*
 Local Variables:
 c-basic-offset:2