[gnome-bluetooth] Try to merge killswitch-changed events



commit 564d3cb8c49386c872134d4e5626d2f942441151
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 18 19:28:10 2010 +0100

    Try to merge killswitch-changed events
    
    By reading all the events that are queued up before firing
    the signal.

 lib/bluetooth-killswitch.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/lib/bluetooth-killswitch.c b/lib/bluetooth-killswitch.c
index dd73041..c46c829 100644
--- a/lib/bluetooth-killswitch.c
+++ b/lib/bluetooth-killswitch.c
@@ -304,18 +304,23 @@ event_cb (GIOChannel *source,
 	if (condition & G_IO_IN) {
 		GIOStatus status;
 		struct rfkill_event event;
+		gsize read;
+		gboolean changed = FALSE;
 
 		status = g_io_channel_read_chars (source,
 						  (char *) &event,
 						  sizeof(event),
-						  NULL,
+						  &read,
 						  NULL);
-		if (status == G_IO_STATUS_NORMAL) {
-			print_event (&event);
 
+		while (status == G_IO_STATUS_NORMAL && read == sizeof(event)) {
 			if (event.type != RFKILL_TYPE_BLUETOOTH &&
 			    event.type != RFKILL_TYPE_ALL)
-				return TRUE;
+				goto carry_on;
+
+			print_event (&event);
+
+			changed = TRUE;
 
 			if (event.op == RFKILL_OP_CHANGE) {
 				update_killswitch (killswitch, event.idx, event.soft, event.hard);
@@ -327,10 +332,18 @@ event_cb (GIOChannel *source,
 				add_killswitch (killswitch, event.idx, state);
 			}
 
+carry_on:
+			status = g_io_channel_read_chars (source,
+							  (char *) &event,
+							  sizeof(event),
+							  &read,
+							  NULL);
+		}
+
+		if (changed)
 			g_signal_emit (G_OBJECT (killswitch),
 				       signals[STATE_CHANGED],
 				       0, bluetooth_killswitch_get_state (killswitch));
-		}
 	} else {
 		g_message ("something else happened");
 		return FALSE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]