chiark / gitweb /
new state change notification logic
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 30 Sep 2007 17:46:11 +0000 (18:46 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 30 Sep 2007 17:46:11 +0000 (18:46 +0100)
disobedience/disobedience.h
disobedience/log.c

index 6a68b9ae9eda137bf8c49ac5e9b26216e70a5950..7449e274efe76a5c0fa732ee3fda9584b7e24338 100644 (file)
@@ -91,6 +91,8 @@ extern int choosealpha;                 /* break up choose by letter */
 
 extern const disorder_eclient_log_callbacks log_callbacks;
 
+typedef void monitor_callback(void *u, unsigned long newstate);
+
 /* Functions --------------------------------------------------------------- */
 
 disorder_eclient *gtkclient(void);
@@ -113,6 +115,11 @@ GdkPixbuf *find_image(const char *name);
 void popup_error(const char *msg);
 /* Pop up an error message */
 
+void register_monitor(monitor_callback *callback,
+                      void *u,
+                      unsigned long mask);
+/* Register a state monitor */
+
 void all_update(void);
 /* Update everything */
 
index b2e3e6818e7983bf0926dd66ba25ea1481b1d57d..e170c2ac18a946be8d92a3ef7d52b61f75ac1b0f 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,6 +141,13 @@ static void log_scratched(void attribute((unused)) *v,
 
 static void log_state(void attribute((unused)) *v,
                       unsigned long state) {
+  const struct monitor *m;
+
+  /* Tell anything that cares about the state change */
+  for(m = monitors; m; m = m->next) {
+    if((state ^ last_state) & m->mask)
+      m->callback(m->u, state);
+  }
   last_state = state;
   control_update();
   /* If the track is paused or resume then the currently playing track is
@@ -151,6 +165,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