chiark / gitweb /
Start Disobedience switch from _monitor interface to event_ interface.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 19:52:17 +0000 (20:52 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 19:52:17 +0000 (20:52 +0100)
disobedience/log.c
disobedience/queue.c

index 38d83f0..ced5eee 100644 (file)
@@ -162,6 +162,18 @@ static void log_scratched(void attribute((unused)) *v,
                           const char attribute((unused)) *user) {
 }
 
+/** @brief Map from state bits to state change events */
+static const struct {
+  unsigned long bit;
+  const char *event;
+} state_events[] = {
+  { DISORDER_PLAYING_ENABLED, "enabled-changed" },
+  { DISORDER_RANDOM_ENABLED, "random-changed" },
+  { DISORDER_TRACK_PAUSED, "pause-changed" },
+  { DISORDER_PLAYING, "playing-changed" },
+};
+#define NSTATE_EVENTS (sizeof state_events / sizeof *state_events)
+
 /** @brief Called when a state change occurs */
 static void log_state(void attribute((unused)) *v,
                       unsigned long state) {
@@ -179,6 +191,10 @@ static void log_state(void attribute((unused)) *v,
      disorder_eclient_interpret_state(state),
      disorder_eclient_interpret_state(changes)));
   last_state = state;
+  /* Notify interested parties what has changed */
+  for(unsigned n = 0; n < NSTATE_EVENTS; ++n)
+    if(changes & state_events[n].bit)
+      event_raise(state_events[n].event, 0);
   /* Tell anything that cares about the state change */
   for(m = monitors; m; m = m->next) {
     if(changes & m->mask)
index e2c06a4..8ff6b6f 100644 (file)
@@ -1371,8 +1371,10 @@ static struct queue_menuitem queue_menu[] = {
  * We monitor pause/resume as well as whether the track is playing in order to
  * keep the time played so far up to date correctly.  See playing_completed().
  */
-static void playing_update(void attribute((unused)) *v) {
-  D(("playing_update"));
+static void playing_changed(const char attribute((unused)) *event,
+                            void attribute((unused)) *evendata,
+                            void attribute((unused)) *callbackdata) {
+  D(("playing_changed"));
   gtk_label_set_text(GTK_LABEL(report_label), "updating playing track");
   disorder_eclient_playing(client, playing_completed, 0);
 }
@@ -1383,10 +1385,9 @@ GtkWidget *queue_widget(void) {
   /* Arrange periodic update of the so-far played field */
   g_timeout_add(1000/*ms*/, adjust_sofar, 0);
   /* Arrange a callback whenever the playing state changes */ 
-  register_monitor(playing_update, 0, DISORDER_PLAYING|DISORDER_TRACK_PAUSED);
-  event_register("queue-changed",
-                 queue_changed,
-                 0);
+  event_register("playing-changed", playing_changed, 0);
+  event_register("pause-changed", playing_changed, 0);
+  event_register("queue-changed", queue_changed, 0);
   /* We pass choose_update() as our notify function since the choose screen
    * marks tracks that are playing/in the queue. */
   return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu,