pidgin: b1475c60: Add auto-generated D-Bus signals introsp...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jul 6 01:30:47 EDT 2009


-----------------------------------------------------------------
Revision: b1475c60325500d6977326c16d129edcdb365e77
Ancestor: 6483eba049c6c31818c5aabd0e1d989ae36a7499
Author: qulogic at pidgin.im
Date: 2009-07-05T05:41:00
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b1475c60325500d6977326c16d129edcdb365e77

Added files:
        libpurple/dbus-analyze-signals.py
Modified files:
        ChangeLog.API libpurple/Makefile.am libpurple/dbus-server.c

ChangeLog: 

Add auto-generated D-Bus signals introspection, though parameter names
are not included at the moment.

Closes #3243.

-------------- next part --------------
============================================================
--- libpurple/dbus-analyze-signals.py	ed35e2033a31a0403a4a374c8afe9692d900ab69
+++ libpurple/dbus-analyze-signals.py	ed35e2033a31a0403a4a374c8afe9692d900ab69
@@ -0,0 +1,60 @@
+# This program takes a C source as the input and produces the list of
+# all signals registered.
+#
+# Output is:
+#   <signal name="Changed">
+#       <arg name="new_value" type="b"/>
+#   </signal>
+
+import re
+import sys
+
+# List "excluded" contains signals that shouldn't be exported via
+# DBus.  If you remove a signal from this list, please make sure
+# that it does not break "make" with the configure option
+# "--enable-dbus" turned on.
+
+excluded = [\
+    # purple_dbus_signal_emit_purple prevents our "dbus-method-called"
+    # signal from being propagated to dbus.
+	"dbus-method-called",
+    ]
+
+registerregex = re.compile("purple_signal_register[^;]+\"([\w\-]+)\"[^;]+(purple_marshal_\w+)[^;]+;")
+nameregex = re.compile('[-_][a-z]')
+
+print "/* Generated by %s.  Do not edit! */" % sys.argv[0]
+print "const char *dbus_signals = "
+for match in registerregex.finditer(sys.stdin.read()):
+    signal = match.group(1)
+    marshal = match.group(2)
+    if signal in excluded:
+        continue
+
+    signal = nameregex.sub(lambda x:x.group()[1].upper(), '-'+signal)
+    print "\"<signal name='%s'>\\n\""%signal
+
+    args = marshal.split('_')
+    # ['purple', 'marshal', <return type>, '', args...]
+    if len(args) > 4:
+        for arg in args[4:]:
+            if arg == "POINTER":
+                type = 'p'
+            elif arg == "ENUM":
+                type = 'i'
+            elif arg == "INT":
+                type = 'i'
+            elif arg == "UINT":
+                type = 'u'
+            elif arg == "INT64":
+                type = 'x'
+            elif arg == "UINT64":
+                type = 't'
+            elif arg == "BOOLEAN":
+                type = 'b'
+            print "\"<arg type='%s'/>\\n\""%type
+
+    print "\"</signal>\\n\""
+
+print ";"
+
============================================================
--- ChangeLog.API	53b6db09d0486a2bd52b9632da4d6a4a07dd546a
+++ ChangeLog.API	3133de3815c94c4a048f504ffbab09d94b9ebdcf
@@ -69,6 +69,7 @@ version 2.6.0 (??/??/2009):
 		  emitted), but this signal was not emitted.
 		* Added a client_type field in the get_ui_info core UI op. See
 		  core.h for details.
+		* Added introspection of signals exposed via the D-Bus API.
 
 		Deprecated:
 		* buddy-added and buddy-removed blist signals
============================================================
--- libpurple/Makefile.am	22dfd64715e47d7c86458cd3686d2c7857fce25f
+++ libpurple/Makefile.am	e906bad629bf8f8065f3f897e2528b51581374e6
@@ -1,5 +1,6 @@ EXTRA_DIST = \
 EXTRA_DIST = \
 		dbus-analyze-functions.py \
+		dbus-analyze-signals.py \
 		dbus-analyze-types.py \
 		marshallers.list \
 		purple-notifications-example \
@@ -169,6 +170,7 @@ CLEANFILES = \
 	dbus-bindings.c \
 	dbus-client-binding.c \
 	dbus-client-binding.h \
+	dbus-signals.c \
 	dbus-types.c \
 	dbus-types.h \
 	marshallers.c \
@@ -189,6 +191,10 @@ dbus_build_exported = $(addprefix $(srcd
 purple_build_coreheaders = $(addprefix $(srcdir)/, $(purple_coreheaders)) \
 		$(purple_builtheaders)
 dbus_build_exported = $(addprefix $(srcdir)/, $(dbus_exported))
+# We should probably make this better
+dbus_signals = $(purple_coresources) \
+	protocols/irc/irc.c \
+	protocols/jabber/libxmpp.c
 
 dbus-types.c: dbus-analyze-types.py $(purple_build_coreheaders)
 	cat $(purple_build_coreheaders) | $(PYTHON) $(srcdir)/dbus-analyze-types.py --pattern=PURPLE_DBUS_DEFINE_TYPE\(%s\) > $@
@@ -199,8 +205,11 @@ dbus-bindings.c: dbus-analyze-functions.
 dbus-bindings.c: dbus-analyze-functions.py $(dbus_exported)
 	cat $(dbus_build_exported) | $(PYTHON) $(srcdir)/dbus-analyze-functions.py > $@
 
-dbus-server.$(OBJEXT): dbus-bindings.c dbus-types.c dbus-types.h
-dbus-server.lo: dbus-bindings.c dbus-types.c dbus-types.h
+dbus-signals.c: dbus-analyze-signals.py $(dbus_signals)
+	cat $(dbus_signals) | $(PYTHON) $(srcdir)/dbus-analyze-signals.py > $@
+
+dbus-server.$(OBJEXT): dbus-bindings.c dbus-signals.c dbus-types.c dbus-types.h
+dbus-server.lo: dbus-bindings.c dbus-signals.c dbus-types.c dbus-types.h
 $(libpurple_la_OBJECTS): dbus-types.h
 
 # libpurple-client
@@ -240,9 +249,10 @@ BUILT_SOURCES = $(purple_builtheaders) \
 bin_SCRIPTS = purple-remote purple-send purple-send-async purple-url-handler
 
 BUILT_SOURCES = $(purple_builtheaders) \
+	dbus-bindings.c \
+	dbus-signals.c \
 	dbus-types.c \
 	dbus-types.h \
-	dbus-bindings.c \
 	marshallers.c \
 	marshallers.h \
 	purple-client-bindings.c \
============================================================
--- libpurple/dbus-server.c	928adb74d3405c0d9d1ab5bed9e9fa875371f285
+++ libpurple/dbus-server.c	c51bb82bc269f00e0c8ad4d31a0d5cc3a2bfc867
@@ -421,6 +421,7 @@ purple_dbus_get_connection(void)
 }
 
 #include "dbus-bindings.c"
+#include "dbus-signals.c"
 
 static gboolean
 purple_dbus_dispatch_cb(DBusConnection *connection,
@@ -489,6 +490,9 @@ static DBusMessage *purple_dbus_introspe
 	DBusMessage *reply;
 	GString *str;
 	GList *bindings_list, *node;
+	const char *signals;
+	const char *type;
+	const char *pointer_type;
 
 	str = g_string_sized_new(0x1000); /* TODO: why this size? */
 
@@ -529,6 +533,19 @@ static DBusMessage *purple_dbus_introspe
 		}
 	}
 
+	if (sizeof(int) == sizeof(dbus_int32_t))
+		pointer_type = "type='i'";
+	else
+		pointer_type = "type='x'";
+
+	signals = dbus_signals;
+	while ((type = strstr(signals, "type='p'")) != NULL) {
+		g_string_append_len(str, signals, type - signals);
+		g_string_append(str, pointer_type);
+		signals = type + sizeof("type='p'") - 1;
+	}
+	g_string_append(str, signals);
+
 	g_string_append(str, "</interface>\n</node>\n");
 
 	reply = dbus_message_new_method_return(message);


More information about the Commits mailing list