[evolution-patches] rework of EComponentListener



Hi

These patches include the rework of EComponentListener to use
ORBit_small_listen_for_broken instead of Bonobo_Unknown_ping'ing the
component every 10 seconds.

Michael, please could you have a look at the e-util patch?

I'll hold on this patch (if approved) a few days to make sure there are
no additional problems. So far, it seems to work ok for me.

cheers
? e-component-listener-orbit-small.c
? e-component-listener-orbit-small.h
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/e-util/ChangeLog,v
retrieving revision 1.390
diff -u -p -r1.390 ChangeLog
--- ChangeLog	16 May 2003 19:20:34 -0000	1.390
+++ ChangeLog	26 May 2003 16:39:00 -0000
@@ -1,3 +1,8 @@
+2003-05-26  Rodrigo Moya <rodrigo ximian com>
+
+	* e-component-listener.[ch]: use ORBit_small_listen/_unlisten instead
+	of Bonobo_Unknown_ping'ing the components.
+
 2003-05-16  Dan Winship  <danw ximian com>
 
 	* e-proxy.c (e_proxy_init): Removing trailing / in key name passed
Index: e-component-listener.c
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-component-listener.c,v
retrieving revision 1.4
diff -u -p -r1.4 e-component-listener.c
--- e-component-listener.c	5 Nov 2002 11:37:58 -0000	1.4
+++ e-component-listener.c	26 May 2003 16:39:00 -0000
@@ -14,12 +14,9 @@
 #include <libgnome/gnome-i18n.h>
 
 #define PARENT_TYPE GTK_TYPE_OBJECT
-#define DEFAULT_PING_DELAY 10000
 
 struct _EComponentListenerPrivate {
 	Bonobo_Unknown component;
-	int ping_delay;
-	int ping_timeout_id;
 };
 
 static void e_component_listener_class_init (EComponentListenerClass *klass);
@@ -27,6 +24,7 @@ static void e_component_listener_init   
 static void e_component_listener_finalize   (GObject *object);
 
 static GObjectClass *parent_class = NULL;
+static GList *watched_connections = NULL;
 
 enum {
 	COMPONENT_DIED,
@@ -36,6 +34,32 @@ enum {
 static guint comp_listener_signals[LAST_SIGNAL];
 
 static void
+connection_listen_cb (gpointer object, EComponentListener *cl)
+{
+	GList *l;
+
+	for (l = watched_connections; l != NULL; l = l->next) {
+		if (cl == l->data) {
+			if (cl->priv->component == CORBA_OBJECT_NIL)
+				return;
+
+			switch (ORBit_small_get_connection_status (cl->priv->component)) {
+			case ORBIT_CONNECTION_DISCONNECTED :
+				watched_connections = g_list_remove (watched_connections, cl);
+
+				g_object_ref (cl);
+				g_signal_emit (cl, comp_listener_signals[COMPONENT_DIED], 0);
+				cl->priv->component = CORBA_OBJECT_NIL;
+				g_object_unref (cl);
+				break;
+			default :
+			}
+			break;
+		}
+	}
+}
+
+static void
 e_component_listener_class_init (EComponentListenerClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -61,8 +85,6 @@ e_component_listener_init (EComponentLis
 	/* allocate internal structure */
 	cl->priv = g_new (EComponentListenerPrivate, 1);
 	cl->priv->component = CORBA_OBJECT_NIL;
-	cl->priv->ping_delay = DEFAULT_PING_DELAY;
-	cl->priv->ping_timeout_id = -1;
 }
 
 static void
@@ -72,12 +94,10 @@ e_component_listener_finalize (GObject *
 
 	g_return_if_fail (E_IS_COMPONENT_LISTENER (cl));
 
-	cl->priv->component = CORBA_OBJECT_NIL;
+	watched_connections = g_list_remove (watched_connections, cl);
 
-	if (cl->priv->ping_timeout_id != -1) {
-		g_source_remove (cl->priv->ping_timeout_id);
-		cl->priv->ping_timeout_id = -1;
-	}
+	if (cl->priv->component != CORBA_OBJECT_NIL)
+		cl->priv->component = CORBA_OBJECT_NIL;
 
 	/* free memory */
 	g_free (cl->priv);
@@ -109,67 +129,9 @@ e_component_listener_get_type (void)
 	return type;
 }
 
-static gboolean
-ping_component_callback (gpointer user_data)
-{
-	gboolean alive;
-	int is_nil;
-	CORBA_Environment ev;
-	EComponentListener *cl = (EComponentListener *) user_data;
-
-	g_return_val_if_fail (E_IS_COMPONENT_LISTENER (cl), FALSE);
-
-	if (cl->priv->component == CORBA_OBJECT_NIL)
-		return FALSE;
-
-	CORBA_exception_init (&ev);
-	is_nil = CORBA_Object_is_nil (cl->priv->component, &ev);
-	if (BONOBO_EX (&ev)) {
-		g_message (_("ping_timeout_callback: could not determine if the "
-			     "CORBA object is nil or not"));
-		goto out;
-	}
-
-	if (is_nil)
-		goto out;
-
-	alive = bonobo_unknown_ping (cl->priv->component, &ev);
-	if (alive) {
-		CORBA_exception_free (&ev);
-		return TRUE;
-	}
-
- out:
-	/* the component has died, so we notify and close the timeout */
-	CORBA_exception_free (&ev);
-
-	/* we ref the object just in case it gets destroyed in the callbacks */
-	g_object_ref (G_OBJECT (cl));
-	g_signal_emit (G_OBJECT (cl), comp_listener_signals[COMPONENT_DIED], 0);
-
-	cl->priv->component = CORBA_OBJECT_NIL;
-	cl->priv->ping_timeout_id = -1;
-
-	g_object_unref (G_OBJECT (cl));
-
-	return FALSE;
-}
-
-static void
-setup_ping_timeout (EComponentListener *cl)
-{
-	if (cl->priv->ping_timeout_id != -1)
-		g_source_remove (cl->priv->ping_timeout_id);
-
-	cl->priv->ping_timeout_id = g_timeout_add (cl->priv->ping_delay,
-						   ping_component_callback,
-						   cl);
-}
-
 /**
  * e_component_listener_new
  * @comp: Component to listen for.
- * @ping_delay: Delay (in ms) for pinging the component.
  *
  * Create a new #EComponentListener object, which allows to listen
  * for a given component and get notified when that component dies.
@@ -177,43 +139,22 @@ setup_ping_timeout (EComponentListener *
  * Returns: a component listener object.
  */
 EComponentListener *
-e_component_listener_new (Bonobo_Unknown comp, int ping_delay)
+e_component_listener_new (Bonobo_Unknown comp)
 {
 	EComponentListener *cl;
 
+	g_return_val_if_fail (comp != NULL, NULL);
+
 	cl = g_object_new (E_COMPONENT_LISTENER_TYPE, NULL);
 	cl->priv->component = comp;
 
-	/* set up the timeout function */
-	cl->priv->ping_delay = ping_delay > 0 ? ping_delay : DEFAULT_PING_DELAY;
-	setup_ping_timeout (cl);
+	/* watch the connection */
+	ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl);
+	watched_connections = g_list_append (watched_connections, cl);
 
 	return cl;
 }
 
-/**
- * e_component_listener_get_ping_delay
- * @cl: A #EComponentListener object.
- *
- * Get the ping delay being used to listen for an object.
- */
-int
-e_component_listener_get_ping_delay (EComponentListener *cl)
-{
-	g_return_val_if_fail (E_IS_COMPONENT_LISTENER (cl), -1);
-	return cl->priv->ping_delay;
-}
-
-void
-e_component_listener_set_ping_delay (EComponentListener *cl, int ping_delay)
-{
-	g_return_if_fail (E_IS_COMPONENT_LISTENER (cl));
-	g_return_if_fail (ping_delay > 0);
-
-	cl->priv->ping_delay = ping_delay;
-	setup_ping_timeout (cl);
-}
-
 Bonobo_Unknown
 e_component_listener_get_component (EComponentListener *cl)
 {
@@ -227,5 +168,5 @@ e_component_listener_set_component (ECom
 	g_return_if_fail (E_IS_COMPONENT_LISTENER (cl));
 
 	cl->priv->component = comp;
-	setup_ping_timeout (cl);
+	ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl);
 }
Index: e-component-listener.h
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-component-listener.h,v
retrieving revision 1.4
diff -u -p -r1.4 e-component-listener.h
--- e-component-listener.h	5 Nov 2002 11:37:58 -0000	1.4
+++ e-component-listener.h	26 May 2003 16:39:00 -0000
@@ -36,10 +36,8 @@ typedef struct {
 } EComponentListenerClass;
 
 GType               e_component_listener_get_type       (void);
-EComponentListener *e_component_listener_new            (Bonobo_Unknown comp, int ping_delay);
+EComponentListener *e_component_listener_new            (Bonobo_Unknown comp);
 
-int                 e_component_listener_get_ping_delay (EComponentListener *cl);
-void                e_component_listener_set_ping_delay (EComponentListener *cl, int ping_delay);
 Bonobo_Unknown      e_component_listener_get_component  (EComponentListener *cl);
 void                e_component_listener_set_component  (EComponentListener *cl,
 							 Bonobo_Unknown comp);
? gui/alarm-notify/alarm-notify.gladep
? gui/dialogs/alarm-options.gladep
? gui/dialogs/alarm-page.gladep
? gui/dialogs/cal-prefs-dialog.gladep
? gui/dialogs/e-delegate-dialog.gladep
? gui/dialogs/event-page.gladep
? gui/dialogs/meeting-page.gladep
? gui/dialogs/recurrence-page.gladep
? gui/dialogs/schedule-page.gladep
? gui/dialogs/task-details-page.gladep
? gui/dialogs/task-page.gladep
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.1784
diff -u -p -r1.1784 ChangeLog
--- ChangeLog	22 May 2003 20:11:21 -0000	1.1784
+++ ChangeLog	26 May 2003 15:52:06 -0000
@@ -1,3 +1,11 @@
+2003-05-26  Rodrigo Moya <rodrigo ximian com>
+
+	* pcs/query.c (start_cached_query_cb): adapted to changes in
+	EComponentListener API.
+	(query_construct): ditto.
+
+	* cal-client/cal-client.c (cal_opened_cb): ditto.
+	
 2003-05-20  JP Rosevear  <jpr ximian com>
  
  	Fixes #43308
Index: cal-client/cal-client.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/cal-client/cal-client.c,v
retrieving revision 1.117
diff -u -p -r1.117 cal-client.c
--- cal-client/cal-client.c	14 May 2003 18:45:54 -0000	1.117
+++ cal-client/cal-client.c	26 May 2003 15:52:07 -0000
@@ -534,7 +534,7 @@ cal_opened_cb (CalListener *listener,
 		client_status = CAL_CLIENT_OPEN_SUCCESS;
 
 		/* setup component listener */
-		priv->comp_listener = e_component_listener_new (priv->cal, 0);
+		priv->comp_listener = e_component_listener_new (priv->cal);
 		g_signal_connect (G_OBJECT (priv->comp_listener), "component_died",
 				  G_CALLBACK (backend_died_cb), client);
 		goto out;
Index: pcs/query.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/pcs/query.c,v
retrieving revision 1.35
diff -u -p -r1.35 query.c
--- pcs/query.c	9 Jan 2003 18:17:52 -0000	1.35
+++ pcs/query.c	26 May 2003 15:52:08 -0000
@@ -1463,7 +1463,7 @@ start_cached_query_cb (gpointer data)
 	    priv->state == QUERY_WAIT_FOR_BACKEND) {
 		priv->listeners = g_list_append (priv->listeners, info->ql);
 
-		cl = e_component_listener_new (info->ql, 0);
+		cl = e_component_listener_new (info->ql);
 		priv->component_listeners = g_list_append (priv->component_listeners, cl);
 		g_signal_connect (G_OBJECT (cl), "component_died",
 				  G_CALLBACK (listener_died_cb), info->query);
@@ -1534,7 +1534,7 @@ start_cached_query_cb (gpointer data)
 		/* setup private data and notify listener that the query ended */
 		priv->listeners = g_list_append (priv->listeners, info->ql);
 
-		cl = e_component_listener_new (info->ql, 0);
+		cl = e_component_listener_new (info->ql);
 		priv->component_listeners = g_list_append (priv->component_listeners, cl);
 		g_signal_connect (G_OBJECT (cl), "component_died",
 				  G_CALLBACK (listener_died_cb), info->query);
@@ -1637,7 +1637,7 @@ query_construct (Query *query,
 	}
 	CORBA_exception_free (&ev);
 
-	cl = e_component_listener_new (ql, 0);
+	cl = e_component_listener_new (ql);
 	priv->component_listeners = g_list_append (priv->component_listeners, cl);
 	g_signal_connect (G_OBJECT (cl), "component_died",
 			  G_CALLBACK (listener_died_cb), query);
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1427
diff -u -p -r1.1427 ChangeLog
--- ChangeLog	19 May 2003 20:30:22 -0000	1.1427
+++ ChangeLog	26 May 2003 15:50:52 -0000
@@ -1,3 +1,8 @@
+2003-05-26  Rodrigo Moya <rodrigo ximian com>
+
+	* backend/ebook/ebook.c (e_book_do_response_open): adapted to
+	changes in EComponentListener API.
+
 2003-05-19  Chris Toshok  <toshok ximian com>
 
 	* backend/pas/pas-backend-ldap.c (func_beginswith): use the more
Index: backend/ebook/e-book.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/backend/ebook/e-book.c,v
retrieving revision 1.73
diff -u -p -r1.73 e-book.c
--- backend/ebook/e-book.c	14 May 2003 18:44:26 -0000	1.73
+++ backend/ebook/e-book.c	26 May 2003 15:50:52 -0000
@@ -426,7 +426,7 @@ e_book_do_response_open (EBook          
 		book->priv->corba_book  = resp->book;
 		book->priv->load_state  = URILoaded;
 
-		book->priv->comp_listener = e_component_listener_new (book->priv->corba_book, 0);
+		book->priv->comp_listener = e_component_listener_new (book->priv->corba_book);
                 book->priv->died_signal = g_signal_connect (book->priv->comp_listener, "component_died",
 							    G_CALLBACK (backend_died_cb), book);
 	}


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