Re: listener question

"nshmyrev" <[email protected]> Thu, 4 Dec 2003 14:22:31 +0300 (MSK)
Newsgroups gmane.comp.gnome.components
Message-ID <[email protected]>
Hello, this is patch for notification about registered and unregistered bonobo-activation 
servers. I think, that interface modification and reimplementation of EventSource is too 
problematic, so may be this way can avoid interfaces problem. Bonobo-activation-server 
implements object with Bonobo/EventSource that can be accessed like CosNaming service by 
calling bonobo_activation_activate_from_id function. No dependencies added to bonobo-activation
library.

Test in test/test-activation works for me.

I also think, that CORBA_any argument of event should contain OAFIID if activated server, but 
this can be implemented later.

About _active bug. I think, that simply ignoring cache add for queries with _active substring will be suitable. I'll wrote patch soon.

Shmyrev.
event.patch (application/octet-stream, 10.6 KB)
Index: activation-server/Bonobo_CosNaming_NamingContext.server.in.in
===================================================================
RCS file: /cvs/gnome/libbonobo/activation-server/Bonobo_CosNaming_NamingContext.server.in.in,v
retrieving revision 1.1
diff -u -r1.1 Bonobo_CosNaming_NamingContext.server.in.in
--- activation-server/Bonobo_CosNaming_NamingContext.server.in.in	16 Jul 2002 20:49:35 -0000	1.1
+++ activation-server/Bonobo_CosNaming_NamingContext.server.in.in	4 Dec 2003 11:06:32 -0000
@@ -7,4 +7,12 @@
 		<oaf_attribute name="name" type="string" _value="Name service"/>
 		<oaf_attribute name="description" type="string" _value="CORBA CosNaming service."/>
 	</oaf_server>
+	<oaf_server iid="OAFIID:Bonobo_Activation_EventSource"
+        	    type="exe" location="@LIBEXECDIR@/bonobo-activation-server">
+		<oaf_attribute name="repo_ids" type="stringv">
+		         <item value="IDL:Bonobo/EventSource:1.0"/>
+		</oaf_attribute>
+		<oaf_attribute name="name" type="string" _value="Notification service"/>
+		<oaf_attribute name="description" type="string" _value="Notification service from Bonobo activation."/>
+	</oaf_server>
 </oaf_info>
Index: activation-server/activation-server-main.c
===================================================================
RCS file: /cvs/gnome/libbonobo/activation-server/activation-server-main.c,v
retrieving revision 1.52
diff -u -r1.52 activation-server-main.c
--- activation-server/activation-server-main.c	3 Nov 2003 15:21:32 -0000	1.52
+++ activation-server/activation-server-main.c	4 Dec 2003 11:06:33 -0000
@@ -221,6 +221,7 @@
         CORBA_Object                  naming_service, existing;
         Bonobo_ActivationEnvironment  environment;
         Bonobo_ObjectDirectory        od;
+	Bonobo_EventSource            event_source;
         poptContext                   ctx;
         int                           dev_null_fd;
         struct sigaction              sa;
@@ -273,6 +274,7 @@
         g_string_free (src_dir, TRUE);
 
         od = bonobo_object_directory_get ();
+	event_source = bonobo_object_directory_event_source_get();
 
 	memset (&environment, 0, sizeof (Bonobo_ActivationEnvironment));
 
@@ -287,6 +289,13 @@
 
         Bonobo_ObjectDirectory_register_new 
                 (od, NAMING_CONTEXT_IID, &environment, naming_service, 0, "", &existing, ev);
+        g_assert (ev->_major == CORBA_NO_EXCEPTION);
+
+	if (existing != CORBA_OBJECT_NIL)
+		CORBA_Object_release (existing, NULL);
+
+        Bonobo_ObjectDirectory_register_new 
+                (od, EVENT_SOURCE_IID, &environment, event_source, 0, "", &existing, ev);
         g_assert (ev->_major == CORBA_NO_EXCEPTION);
         
 	if (existing != CORBA_OBJECT_NIL)
Index: activation-server/object-directory-corba.c
===================================================================
RCS file: /cvs/gnome/libbonobo/activation-server/object-directory-corba.c,v
retrieving revision 1.62
diff -u -r1.62 object-directory-corba.c
--- activation-server/object-directory-corba.c	24 Nov 2003 01:04:03 -0000	1.62
+++ activation-server/object-directory-corba.c	4 Dec 2003 11:06:34 -0000
@@ -586,7 +586,7 @@
                                 NULL);
                 }
         } else
-                g_assert (!strcmp (iid, NAMING_CONTEXT_IID));
+                g_assert (!(strcmp (iid, NAMING_CONTEXT_IID) && strcmp(iid, EVENT_SOURCE_IID)));
 
 	servers = g_hash_table_lookup (od->active_server_lists, iid);
 	if (!servers) {
@@ -756,6 +756,8 @@
 #endif
 
         add_active_server (od, iid, environment, obj);
+	
+	bonobo_event_source_notify_listeners (od->event_source, "Bonobo/ObjectDirectory:activation:register",NULL,  ev);
 
 	return Bonobo_ACTIVATION_REG_SUCCESS;
 }
@@ -769,10 +771,14 @@
 {
 	ObjectDirectory *od = OBJECT_DIRECTORY (servant);
 
-        if (!remove_active_server (od, iid, obj))
+        if (!remove_active_server (od, iid, obj)) {
                 CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                                      ex_Bonobo_ObjectDirectory_NotRegistered,
                                      NULL);
+	} else {
+	bonobo_event_source_notify_listeners (od->event_source, "Bonobo/ObjectDirectory:activation:unregister",NULL,  ev);
+	}
+
 }
 
 static Bonobo_DynamicPathLoadResult 
@@ -897,6 +903,15 @@
                 return BONOBO_OBJREF (main_dir);
 }
 
+Bonobo_EventSource
+bonobo_object_directory_event_source_get (void)
+{
+     if (!main_dir)
+    	      return CORBA_OBJECT_NIL;
+     else
+              return BONOBO_OBJREF(main_dir->event_source);
+}
+
 void
 bonobo_object_directory_init (PortableServer_POA poa,
                               const char        *registry_path,
@@ -1012,6 +1027,8 @@
         od->no_servers_timeout = 0;
 
         od->attr_runtime_servers = g_ptr_array_new ();
+	
+	od->event_source = bonobo_event_source_new ();
 }
 
 BONOBO_TYPE_FUNC_FULL (ObjectDirectory,
Index: activation-server/object-directory.h
===================================================================
RCS file: /cvs/gnome/libbonobo/activation-server/object-directory.h,v
retrieving revision 1.3
diff -u -r1.3 object-directory.h
--- activation-server/object-directory.h	24 Nov 2003 01:04:03 -0000	1.3
+++ activation-server/object-directory.h	4 Dec 2003 11:06:34 -0000
@@ -14,6 +14,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-event-source.h>
 #include <bonobo-activation/Bonobo_ObjectDirectory.h>
 
 G_BEGIN_DECLS
@@ -48,6 +49,9 @@
         char           **registry_source_directories;
         time_t           time_did_stat;
         GHashTable      *registry_directory_mtimes;
+	
+	/* Notification source */
+	BonoboEventSource* event_source;
 };
 
 typedef struct {
@@ -63,6 +67,7 @@
 void                   bonobo_object_directory_shutdown    (PortableServer_POA     poa,
                                                             CORBA_Environment     *ev);
 Bonobo_ObjectDirectory bonobo_object_directory_get         (void);
+Bonobo_EventSource     bonobo_object_directory_event_source_get (void);
 CORBA_Object           bonobo_object_directory_re_check_fn (const Bonobo_ActivationEnvironment *environment,
                                                             const char                         *od_iorstr,
                                                             gpointer                            user_data,
Index: activation-server/server.h
===================================================================
RCS file: /cvs/gnome/libbonobo/activation-server/server.h,v
retrieving revision 1.22
diff -u -r1.22 server.h
--- activation-server/server.h	24 Nov 2003 01:04:03 -0000	1.22
+++ activation-server/server.h	4 Dec 2003 11:06:34 -0000
@@ -19,6 +19,7 @@
 #define SERVER_IDLE_QUIT_TIMEOUT 1000
 
 #define NAMING_CONTEXT_IID "OAFIID:Bonobo_CosNaming_NamingContext"
+#define EVENT_SOURCE_IID "OAFIID:Bonobo_Activation_EventSource"
 
 /* object-directory-load.c */
 void bonobo_server_info_load         (char                  **dirs,
Index: tests/test-activation/Makefile.am
===================================================================
RCS file: /cvs/gnome/libbonobo/tests/test-activation/Makefile.am,v
retrieving revision 1.43
diff -u -r1.43 Makefile.am
--- tests/test-activation/Makefile.am	17 Jul 2003 14:56:17 -0000	1.43
+++ tests/test-activation/Makefile.am	4 Dec 2003 11:06:36 -0000
@@ -14,8 +14,9 @@
 	bonobo-activation-test.c	\
 	empty-common.c			\
 	empty.h				\
-	empty-stubs.c
-bonobo_activation_test_LDADD=libtest-plugin.la
+	empty-stubs.c 
+
+bonobo_activation_test_LDADD=libtest-plugin.la ../../bonobo/libbonobo-2.la
 
 
 # Horrible, digusting and atrocious hack to
@@ -76,7 +77,7 @@
 	-DG_DISABLE_DEPRECATED $(LIBBONOBO_CFLAGS)
 
 LDADD = ../../bonobo-activation/libbonobo-activation.la \
-	$(LIBBONOBO_LIBS) $(POPT_LIBS)
+	$(LIBBONOBO_LIBS) $(POPT_LIBS) 
 
 serverfiles=empty.server broken.server plugin.server
 
Index: tests/test-activation/bonobo-activation-test.c
===================================================================
RCS file: /cvs/gnome/libbonobo/tests/test-activation/bonobo-activation-test.c,v
retrieving revision 1.34
diff -u -r1.34 bonobo-activation-test.c
--- tests/test-activation/bonobo-activation-test.c	30 May 2003 15:56:08 -0000	1.34
+++ tests/test-activation/bonobo-activation-test.c	4 Dec 2003 11:06:36 -0000
@@ -11,7 +11,7 @@
 #include "empty.h"
 #include "plugin.h"
 
-#define TOTAL_TEST_SCORE 16
+#define TOTAL_TEST_SCORE 17
 
 CORBA_Object name_service = CORBA_OBJECT_NIL;
 
@@ -181,6 +181,16 @@
                 g_main_context_iteration (NULL, TRUE);
 }
 
+void        listener_cb    (BonoboListener *listener,
+                            const char *event_name,
+                            const CORBA_any *any,
+                            CORBA_Environment *ev,
+                            gpointer user_data)
+{
+ g_message ("Activation callback successfully called on %s", bonobo_event_subtype(event_name));
+}
+
+
 int
 main (int argc, char *argv[])
 {
@@ -192,6 +202,8 @@
         char *query;
         int   i;
         GTimer *timer = g_timer_new ();
+	Bonobo_EventSource event_source;
+	
 
 	CORBA_exception_init (&ev);
 
@@ -199,9 +211,21 @@
                 bonobo_activation_username_get (),
                 bonobo_activation_hostname_get ());
 
-	bonobo_activation_init (argc, argv);
+	bonobo_init (&argc, &argv);
 /*      putenv("Bonobo_BARRIER_INIT=1"); */
 
+
+	event_source = bonobo_activation_activate_from_id("OAFIID:Bonobo_Activation_EventSource", 0, NULL, &ev);
+        if (event_source != CORBA_OBJECT_NIL) {
+		passed++;
+		fprintf (stderr, "PASSED %d of %d: Activation event source okay\n", passed + failed, TOTAL_TEST_SCORE);
+   	        bonobo_event_source_client_add_listener (event_source, listener_cb, "Bonobo/ObjectDirectory",  &ev, NULL);
+        } else {
+		failed++;
+		fprintf (stderr, "FAILED %d of %d: Activation event source not found\n", passed + failed, TOTAL_TEST_SCORE);
+	}
+
+
         race_base_init ();
 
         sort_by[0] = "prefer_by_list_order(iid, ["
@@ -279,6 +303,10 @@
                   ORBIT_CONNECTION_CONNECTED);
 
         race_empty (&ev);
+	
+	
+	
+	
 
 	obj = bonobo_activation_activate_from_id ("OAFIID:Empty:19991025", 0, NULL, &ev);
         if (test_object (obj, &ev, "from id") && test_empty (obj, &ev, "from id")) {
@@ -424,10 +452,16 @@
         if (name_service != CORBA_OBJECT_NIL)
                 CORBA_Object_release (name_service, &ev);
 
+        
+        if (event_source != CORBA_OBJECT_NIL)
+	        {
+		CORBA_Object_release (event_source, &ev);
+		}
+
 	CORBA_exception_free (&ev);
 
         if (passed == TOTAL_TEST_SCORE) {
-                if (bonobo_activation_debug_shutdown ()) {
+                if (bonobo_debug_shutdown ()) {
                         return 0;
                 } else {
                         return 1;