chiark / gitweb /
Complete Disobedience transition to event_ from _monitor.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 21:17:25 +0000 (22:17 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 8 Jun 2008 21:17:25 +0000 (22:17 +0100)
disobedience/control.c
disobedience/disobedience.c
disobedience/disobedience.h
disobedience/log.c

index c84f51d15f673cbef8efce083e9a5ea68d955485..8e10d4f63cffe79cd8407f48f86c2ab809db4c9c 100644 (file)
@@ -216,11 +216,13 @@ static GtkWidget *volume_widget;
 static GtkWidget *balance_widget;
 
 /** @brief Called whenever last_state changes in any way */
-void control_monitor(void attribute((unused)) *u) {
+static void control_changed(const char attribute((unused)) *event,
+                            void attribute((unused)) *evendata,
+                            void attribute((unused)) *callbackdata) {
   int n;
   gboolean volume_supported;
 
-  D(("control_monitor"));
+  D(("control_changed"));
   for(n = 0; n < NICONS; ++n)
     icons[n].update(&icons[n]);
   /* Only display volume/balance controls if they will work */
@@ -306,7 +308,11 @@ GtkWidget *control_widget(void) {
                    G_CALLBACK(format_volume), 0);
   g_signal_connect(G_OBJECT(balance_widget), "format-value",
                    G_CALLBACK(format_balance), 0);
-  register_monitor(control_monitor, 0, -1UL);
+  event_register("enabled-changed", control_changed, 0);
+  event_register("random-changed", control_changed, 0);
+  event_register("pause-changed", control_changed, 0);
+  event_register("playing-changed", control_changed, 0);
+  event_register("rtp-changed", control_changed, 0);
   event_register("volume-changed", volume_changed, 0);
   return hbox;
 }
index 76ea604a87766140dd46278362a32da81b74d8e9..ac5f4e8b5b297fbfc8538e11bc8abaa0c7a95dbc 100644 (file)
@@ -342,10 +342,10 @@ static gboolean maybe_send_nop(gpointer attribute((unused)) data) {
     disorder_eclient_nop(client, nop_completed, 0);
   }
   if(rtp_supported) {
-    const int old_state = rtp_is_running;
+    const int rtp_was_running = rtp_is_running;
     rtp_is_running = rtp_running();
-    if(old_state != rtp_is_running)
-      control_monitor(0);
+    if(rtp_was_running != rtp_is_running)
+      event_raise("rtp-changed", 0);
   }
   return TRUE;                          /* keep call me please */
 }
@@ -355,6 +355,8 @@ static void got_rtp_address(void attribute((unused)) *v,
                             const char *error,
                             int attribute((unused)) nvec,
                             char attribute((unused)) **vec) {
+  const int rtp_was_running = rtp_is_running;
+
   ++suppress_actions;
   rtp_address_in_flight = 0;
   if(error) {
@@ -364,9 +366,9 @@ static void got_rtp_address(void attribute((unused)) *v,
   } else {
     rtp_supported = 1;
     rtp_is_running = rtp_running();
-    control_monitor(0);
   }
-  control_monitor(0);
+  if(rtp_is_running != rtp_was_running)
+    event_raise("rtp-changed", 0);
   --suppress_actions;
 }
 
index 9049d674a1ea456f1ef179733bed43f1d31aa912..452526d9fd8f26ca818070dcc70e227db7d4bdd2 100644 (file)
@@ -122,8 +122,6 @@ extern GtkItemFactory *mainmenufactory;
 
 extern const disorder_eclient_log_callbacks log_callbacks;
 
-typedef void monitor_callback(void *u);
-
 /* Functions --------------------------------------------------------------- */
 
 disorder_eclient *gtkclient(void);
@@ -168,11 +166,6 @@ GtkWidget *create_buttons_box(struct button *buttons,
                               size_t nbuttons,
                               GtkWidget *box);
 
-void register_monitor(monitor_callback *callback,
-                      void *u,
-                      unsigned long mask);
-/* Register a state monitor */
-
 /** @brief Type signature for a reset callback */
 typedef void reset_callback(void);
 
@@ -200,8 +193,6 @@ void users_set_sensitive(int sensitive);
 GtkWidget *control_widget(void);
 /* Make the controls widget */
 
-void control_monitor(void *u);
-
 extern int suppress_actions;
 
 /* Queue/Recent/Added */
index ced5eee66b902bed84698d9a1d1e356d371fb793..f0ea7d16bc59387ba4eb8fd43ebefa5e9228ff17 100644 (file)
@@ -60,27 +60,6 @@ const disorder_eclient_log_callbacks log_callbacks = {
   log_rescanned
 };
 
-/** @brief State monitor
- *
- * We keep a linked list of everything that is interested in state changes.
- */
-struct monitor {
-  /** @brief Next monitor */
-  struct monitor *next;
-
-  /** @brief State bits of interest */
-  unsigned long mask;
-
-  /** @brief Function to call if any of @c mask change */
-  monitor_callback *callback;
-
-  /** @brief User data for callback */
-  void *u;
-};
-
-/** @brief List of monitors */
-static struct monitor *monitors;
-
 /** @brief Update everything */
 void all_update(void) {
   ++suppress_actions;
@@ -96,8 +75,6 @@ void all_update(void) {
  * Depending on server and network state the TCP connection to the server may
  * go up or down many times during the lifetime of Disobedience.  This function
  * is called whenever it connects.
- *
- * The intent is to use the monitor logic to achieve this in future.
  */
 static void log_connected(void attribute((unused)) *v) {
   /* Don't know what we might have missed while disconnected so update
@@ -177,7 +154,6 @@ static const struct {
 /** @brief Called when a state change occurs */
 static void log_state(void attribute((unused)) *v,
                       unsigned long state) {
-  const struct monitor *m;
   unsigned long changes = state ^ last_state;
   static int first = 1;
 
@@ -195,11 +171,6 @@ static void log_state(void attribute((unused)) *v,
   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)
-      m->callback(m->u);
-  }
   --suppress_actions;
 }
 
@@ -220,25 +191,6 @@ static void log_rescanned(void attribute((unused)) *v) {
   event_raise("added-changed", 0);
 }
 
-/** @brief Add a monitor to the list
- * @param callback Function to call
- * @param u User data to pass to @p callback
- * @param mask Mask of flags that @p callback cares about
- *
- * Pass @p mask as -1UL to match all flags.
- */
-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