summaryrefslogtreecommitdiff
path: root/libpurple
diff options
context:
space:
mode:
authorElliott Sales de Andrade <qulogic@pidgin.im>2009-07-05 05:41:00 +0000
committerElliott Sales de Andrade <qulogic@pidgin.im>2009-07-05 05:41:00 +0000
commit18bc4c3242338712c39732f670c09dffef019d97 (patch)
tree76a4cefa92f360e4ab70ca04e7063da5c13a24eb /libpurple
parentc0e15f5cdf15dc13afd822794ae483bd1c131b20 (diff)
downloadpidgin-18bc4c3242338712c39732f670c09dffef019d97.tar.gz
Add auto-generated D-Bus signals introspection, though parameter names
are not included at the moment. Closes #3243.
Diffstat (limited to 'libpurple')
-rw-r--r--libpurple/Makefile.am16
-rw-r--r--libpurple/dbus-analyze-signals.py60
-rw-r--r--libpurple/dbus-server.c17
3 files changed, 90 insertions, 3 deletions
diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
index da4008b9a3..3f3894d0ba 100644
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -1,5 +1,6 @@
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_exported = dbus-useful.h dbus-define-api.h account.h blist.h buddyicon.h \
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-types.h: dbus-analyze-types.py $(purple_build_coreheaders)
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 @@ purple-client-example.$(OBJEXT): purple-client-bindings.h
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 \
diff --git a/libpurple/dbus-analyze-signals.py b/libpurple/dbus-analyze-signals.py
new file mode 100644
index 0000000000..c60c46dc8b
--- /dev/null
+++ b/libpurple/dbus-analyze-signals.py
@@ -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 ";"
+
diff --git a/libpurple/dbus-server.c b/libpurple/dbus-server.c
index 930a2a591a..efe59770f2 100644
--- a/libpurple/dbus-server.c
+++ b/libpurple/dbus-server.c
@@ -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_introspect(DBusMessage *message)
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_introspect(DBusMessage *message)
}
}
+ 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);