tinyalsa: add mixer_consume_event

mixer_consume_event consumes subscribed events from the mixer
in order to allow monitoring of mixer control value changed.

Test: Implemented UAC2 jack detection, and the jack control
value changes were successfully reported.

Change-Id: I02d09e8c0cb2bb903378ab5dc55dd743448fb5cf
diff --git a/mixer.c b/mixer.c
index 89e2b7b..f3fdb62 100644
--- a/mixer.c
+++ b/mixer.c
@@ -232,9 +232,9 @@
 
     for (n = 0; n < mixer->count; n++)
         if (!strcmp(name, (char*) mixer->elem_info[n].id.name))
-            break;
+            return mixer_get_ctl(mixer, n);
 
-    return mixer_get_ctl(mixer, n);
+    return NULL;
 }
 
 void mixer_ctl_update(struct mixer_ctl *ctl)
@@ -657,3 +657,24 @@
             return 1;
     }
 }
+
+/** Consume a mixer event.
+ * If mixer_subscribe_events has been called,
+ * mixer_wait_event will identify when a control value has changed.
+ * This function will clear a single event from the mixer so that
+ * further events can be alerted.
+ *
+ * @param mixer A mixer handle.
+ * @returns 0 on success.  -errno on failure.
+ * @ingroup libtinyalsa-mixer
+ */
+int mixer_consume_event(struct mixer *mixer) {
+    struct snd_ctl_event ev;
+    ssize_t count = read(mixer->fd, &ev, sizeof(ev));
+    // Exporting the actual event would require exposing snd_ctl_event
+    // via the header file, and all associated structs.
+    // The events generally tell you exactly which value changed,
+    // but reading values you're interested isn't hard and simplifies
+    // the interface greatly.
+    return (count >= 0) ? 0 : -errno;
+}