[PATCH] addListenerWithMask broken



Hi,

It seems like addListenerWithMask does not quite do as expected, when
more than one event is in the mask. Attached is a patch that fixes the
problem.

/Richard

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.1024
diff -u -b -B -p -r1.1024 ChangeLog
--- ChangeLog	2001/03/30 19:54:48	1.1024
+++ ChangeLog	2001/03/31 18:38:01
@@ -1,3 +1,14 @@
+2001-03-31  Richard Hult  <rhult codefactory se>
+
+	* bonobo/bonobo-event-source.c: Keep a list of event masks instead
+	of a comma separated string.
+	(desc_free): Free the strings and the list.
+	(impl_Bonobo_EventSource_addListenerWithMask): Split the comma
+	separated event mask string and store the masks in a list.
+	(event_match): Try to match with all the events in the list,
+	to make this work like expected.
+	(bonobo_event_source_notify_listeners): Adapt to use the list.
+
 2001-03-30  Darin Adler  <darin eazel com>
 
 	* bonobo/bonobo-control.c: (impl_Bonobo_Control_setWindowId): Use
Index: bonobo/bonobo-event-source.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-event-source.c,v
retrieving revision 1.24
diff -u -b -B -p -r1.24 bonobo-event-source.c
--- bonobo/bonobo-event-source.c	2001/03/20 15:17:04	1.24
+++ bonobo/bonobo-event-source.c	2001/03/31 18:38:02
@@ -30,7 +30,7 @@ struct _BonoboEventSourcePrivate {
 typedef struct {
 	Bonobo_Listener listener;
 	Bonobo_EventSource_ListenerId id;
-	CORBA_char *event_mask; /* send all events if NULL */
+	GSList *event_masks; /* send all events if NULL */
 } ListenerDesc;
 
 /*
@@ -60,8 +60,12 @@ bonobo_event_source_from_servant (Portab
 static void
 desc_free (ListenerDesc *desc, CORBA_Environment *ev)
 {
+	GSList *list;
+
 	if (desc) {
-		CORBA_free (desc->event_mask);
+		for (list = desc->event_masks; list; list = list->next)
+			CORBA_free (list->data);
+		g_slist_free (desc->event_masks);
 		bonobo_object_release_unref (desc->listener, ev);
 		g_free (desc);
 	}
@@ -74,24 +78,38 @@ impl_Bonobo_EventSource_addListenerWithM
 					     CORBA_Environment     *ev)
 {
 	BonoboEventSource *event_source;
-	CORBA_char        *mask_copy = NULL;
 	ListenerDesc      *desc;
+	CORBA_char        *mask_copy;
+	char             **masks;
+	GSList            *list;
+	gint               i;
 
 	g_return_val_if_fail (!CORBA_Object_is_nil (l, ev), 0);
 
 	event_source = bonobo_event_source_from_servant (servant);
 
-	if (event_mask)
-		mask_copy = CORBA_string_dup (event_mask);
-
 	if (event_source->priv->ignore) /* Hook for running context */
 		bonobo_running_context_ignore_object (l);
 
 	desc = g_new0 (ListenerDesc, 1);
 	desc->listener = bonobo_object_dup_ref (l, ev);
 	desc->id = create_listener_id (event_source);
-	desc->event_mask = mask_copy;
 
+	list = NULL;
+	if (event_mask) {
+		masks = g_strsplit (event_mask, ",", 0);
+		
+		i = 0;
+		while (masks[i]) {
+			mask_copy = CORBA_string_dup (masks[i]);
+			list = g_slist_prepend (list, mask_copy);
+			i++;
+		}
+
+		g_strfreev (masks);
+	}
+	desc->event_masks = list;
+
 	event_source->priv->listeners = g_slist_prepend (event_source->priv->listeners, desc);
 
 	return desc->id;
@@ -137,18 +155,25 @@ impl_Bonobo_EventSource_removeListener (
  * if the mask is a prefix of name.
  */
 static gboolean
-event_match (const char *name, const char *mask)
+event_match (const char *name, GSList *masks)
 {
+	GSList *list;
 	int i = 0;
+	char *mask;
 
+	for (list = masks; list; list = list->next) {
+		mask = list->data;
+		
 	if (mask [0] == '=')
-		return !strcmp (name, mask + 1);
+			if (!strcmp (name, mask + 1))
+				return TRUE;
 
 	while (name [i] && mask [i] && name [i] == mask [i])
 		i++;
 
 	if (mask [i] == '\0')
 		return TRUE;
+	}
 
 	return FALSE;
 } 
@@ -188,8 +213,8 @@ bonobo_event_source_notify_listeners (Bo
 	for (l = event_source->priv->listeners; l; l = l->next) {
 		ListenerDesc *desc = (ListenerDesc *) l->data;
 
-		if (desc->event_mask == NULL || 
-		    event_match (event_name, desc->event_mask))
+		if (desc->event_masks == NULL || 
+		    event_match (event_name, desc->event_masks))
 			notify = g_slist_prepend (notify, desc->listener);
 	}
 


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