From 0b8a5ac8c02b3bf1251258cb01265a624304d351 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 30 Jan 2014 13:12:29 +0000 Subject: [PATCH] Remove code-generation machinery Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69600 --- .gitignore | 1 - Makefile.am | 1 - configure.ac | 1 - doc/Makefile.am | 13 - src/Makefile.am | 131 +-- src/gtypes.c | 10 - src/mcd-account-addressing.c | 1 - src/mcd-account-manager.c | 2 - src/mcd-account.c | 4 - src/mcd-channel.c | 2 - src/mcd-connection.c | 2 - src/mcd-misc.c | 3 - src/mcd.xml | 7 - src/request.c | 1 - tools/Makefile.am | 31 - tools/c-constants-generator.xsl | 299 ------- tools/c-interfaces-generator.xsl | 84 -- tools/doc-generator.xsl | 1199 ---------------------------- tools/glib-blocking-client-gen.py | 1014 ------------------------ tools/glib-client-gen.py | 1269 ------------------------------ tools/glib-client-marshaller-gen.py | 60 -- tools/glib-ginterface-gen.py | 838 -------------------- tools/glib-gtypes-generator.py | 304 ------- tools/glib-interfaces-body-generator.xsl | 47 -- tools/glib-interfaces-generator.xsl | 55 -- tools/glib-signals-marshal-gen.py | 55 -- tools/gquark-gen.py | 135 ---- tools/identity.xsl | 7 - tools/libglibcodegen.py | 172 ---- tools/libtpcodegen.py | 227 ------ tools/spec-to-introspect.xsl | 26 - xml/Makefile.am | 28 - xml/all.xml | 35 - xml/generic-types.xml | 214 ----- xml/nmc5.xml | 7 - xml/telepathy-types.xml | 96 --- 36 files changed, 1 insertion(+), 6380 deletions(-) delete mode 100644 src/gtypes.c delete mode 100644 src/mcd.xml delete mode 100644 tools/c-constants-generator.xsl delete mode 100644 tools/c-interfaces-generator.xsl delete mode 100644 tools/doc-generator.xsl delete mode 100644 tools/glib-blocking-client-gen.py delete mode 100644 tools/glib-client-gen.py delete mode 100644 tools/glib-client-marshaller-gen.py delete mode 100644 tools/glib-ginterface-gen.py delete mode 100644 tools/glib-gtypes-generator.py delete mode 100644 tools/glib-interfaces-body-generator.xsl delete mode 100644 tools/glib-interfaces-generator.xsl delete mode 100644 tools/glib-signals-marshal-gen.py delete mode 100644 tools/gquark-gen.py delete mode 100644 tools/identity.xsl delete mode 100644 tools/libglibcodegen.py delete mode 100644 tools/libtpcodegen.py delete mode 100644 tools/spec-to-introspect.xsl delete mode 100644 xml/Makefile.am delete mode 100644 xml/all.xml delete mode 100644 xml/generic-types.xml delete mode 100644 xml/nmc5.xml delete mode 100644 xml/telepathy-types.xml diff --git a/.gitignore b/.gitignore index c3abe8e..23e56bb 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ Android.mk Makefile Makefile.in -_gen/ INSTALL aclocal.m4 autom4te.cache diff --git a/Makefile.am b/Makefile.am index 9d8bfa3..f0ee6f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,6 @@ SUBDIRS = \ data \ m4 \ tools \ - xml \ mission-control-plugins \ plugins \ src \ diff --git a/configure.ac b/configure.ac index 22b7f0a..a428ee6 100644 --- a/configure.ac +++ b/configure.ac @@ -251,7 +251,6 @@ tests/twisted/Makefile \ tests/twisted/tools/Makefile \ tools/Makefile \ util/Makefile \ -xml/Makefile \ ]) echo " diff --git a/doc/Makefile.am b/doc/Makefile.am index 41c97bc..f3ddc22 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,14 +1 @@ SUBDIRS = reference -SPECS = $(top_srcdir)/xml/all.xml -SPECS_DOC = mc-dbus-iface.html - -all-local: $(SPECS_DOC) - -$(SPECS_DOC): $(top_srcdir)/xml/all.xml $(wildcard $(top_srcdir)/xml/*.xml) $(top_srcdir)/tools/doc-generator.xsl - $(XSLTPROC) --xinclude --novalid \ - --param allow-undefined-interfaces "true()" \ - $(top_srcdir)/tools/doc-generator.xsl $< > $@ - -clean-local: - rm -f $(SPECS_DOC) - diff --git a/src/Makefile.am b/src/Makefile.am index 67ba040..7f209d3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,31 +25,17 @@ mc_headers = \ mcd-service.h \ mcd-storage.h -mc_gen_headers = \ - _gen/enums.h \ - _gen/gtypes.h \ - _gen/interfaces.h \ - $(NULL) - nodist_libmcd_convenience_la_SOURCES = \ - _gen/gtypes-body.h \ - _gen/interfaces-body.h \ - _gen/register-dbus-glib-marshallers-body.h \ - _gen/signals-marshal.c \ - _gen/signals-marshal.h \ - _gen/signals-marshal.list \ mcd-enum-types.c \ mcd-enum-types.h \ - $(mc_gen_headers) + $(NULL) BUILT_SOURCES = \ - _gen/mcd.xml \ stamp-mcd-enum-types.h \ $(nodist_libmcd_convenience_la_SOURCES) CLEANFILES = \ $(BUILT_SOURCES) \ - _gen/gtypes-gtk-doc.h \ $(NULL) libmcd_convenience_la_LIBADD = \ @@ -81,7 +67,6 @@ libmcd_convenience_la_SOURCES = \ client-registry.h \ connectivity-monitor.c \ connectivity-monitor.h \ - gtypes.c \ mcd-dbusprop.c \ mcd-dbusprop.h \ mcd-debug.c \ @@ -147,7 +132,6 @@ mcd-enum-types.c: Makefile $(mc_headers) && rm -f xgen-getc EXTRA_DIST = \ - mcd.xml \ stamp-mcd-enum-types.h Android.mk: Makefile.am $(nodist_libmcd_convenience_la_SOURCES) @@ -161,119 +145,6 @@ Android.mk: Makefile.am $(nodist_libmcd_convenience_la_SOURCES) -:LDFLAGS $(libmcd_convenience_la_LIBADD) \ > $@ -# ---- telepathy-glib-style code generation ---- - -tools_dir = $(top_srcdir)/tools - -_gen/mcd.xml: mcd.xml $(wildcard $(top_srcdir)/xml/*.xml) - $(AM_V_at)$(MKDIR_P) _gen - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \ - $< > $@ - -_gen/%.xml: $(top_srcdir)/xml/%.xml $(wildcard $(top_srcdir)/xml/*.xml) - $(AM_V_at)$(MKDIR_P) _gen - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \ - $< > $@ - -# Generated files which can be done for all "classes" at once - -_gen/signals-marshal.list: _gen/mcd.xml \ - $(tools_dir)/glib-signals-marshal-gen.py - $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-signals-marshal-gen.py $< > $@ - -_gen/signals-marshal.h: _gen/signals-marshal.list Makefile.am - $(AM_V_GEN)$(GLIB_GENMARSHAL) --header --prefix=_mcd_ext_marshal $< > $@ - -_gen/signals-marshal.c: _gen/signals-marshal.list Makefile.am - $(AM_V_GEN){ echo '#include "_gen/signals-marshal.h"' && \ - $(GLIB_GENMARSHAL) --body --prefix=_mcd_ext_marshal $<; } \ - > $@ - -_gen/register-dbus-glib-marshallers-body.h: _gen/mcd.xml \ - $(tools_dir)/glib-client-marshaller-gen.py Makefile.am - $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-client-marshaller-gen.py $< \ - _mcd_ext > $@ - -_gen/enums.h: _gen/mcd.xml $(tools_dir)/c-constants-generator.xsl - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) \ - --stringparam mixed-case-prefix mc \ - $(tools_dir)/c-constants-generator.xsl \ - $< > $@ - -_gen/interfaces.h: _gen/mcd.xml \ - $(tools_dir)/glib-interfaces-generator.xsl \ - $(tools_dir)/c-interfaces-generator.xsl - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) \ - --stringparam mixed-case-prefix mc \ - $(tools_dir)/glib-interfaces-generator.xsl \ - $< > $@ - -_gen/interfaces-body.h: _gen/mcd.xml \ - $(tools_dir)/glib-interfaces-body-generator.xsl \ - $(tools_dir)/c-interfaces-generator.xsl - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) \ - --stringparam mixed-case-prefix mc \ - $(tools_dir)/glib-interfaces-body-generator.xsl \ - $< > $@ - -_gen/gtypes.h: _gen/gtypes-gtk-doc.h - @: # generated as a side-effect - -_gen/gtypes-body.h: _gen/gtypes-gtk-doc.h - @: # generated as a side-effect - -_gen/gtypes-gtk-doc.h: _gen/mcd.xml \ - $(top_srcdir)/tools/glib-gtypes-generator.py - $(AM_V_GEN)$(PYTHON) $(top_srcdir)/tools/glib-gtypes-generator.py \ - $< _gen/gtypes mc - - - -# Generated files which must be generated per "class". -# (Currently the only "class" is nmc4, but the new API will need "classes" -# like account, account-manager, ...) - -_gen/%.xml: $(top_srcdir)/xml/%.xml $(wildcard $(top_srcdir)/xml/*.xml) Makefile.am - $(AM_V_at)$(MKDIR_P) _gen - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \ - $< > $@ - -_gen/%.xml: %.xml $(wildcard $(top_srcdir)/xml/*.xml) Makefile.am - $(AM_V_at)$(MKDIR_P) _gen - $(AM_V_GEN)$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \ - $< > $@ - -_gen/cli-%-body.h: _gen/cli-%-gtk-doc.h - @: # generated as a side-effect - -_gen/cli-%.h: _gen/cli-%-gtk-doc.h - @: # generated as a side-effect - -_gen/cli-%-gtk-doc.h: _gen/%.xml \ - $(tools_dir)/glib-client-gen.py Makefile.am - $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-client-gen.py \ - --group=`echo $* | tr x- x_` \ - --iface-quark-prefix=MC_IFACE_QUARK \ - --tp-proxy-api=0.7.6 \ - $< Mc_Cli _gen/cli-$* - -_gen/svc-%.c: _gen/svc-%-gtk-doc.h - @: # generated as a side-effect - -_gen/svc-%.h: _gen/svc-%-gtk-doc.h - @: # generated as a side-effect - -_gen/svc-%-gtk-doc.h: _gen/%.xml \ - $(tools_dir)/glib-ginterface-gen.py Makefile.am - $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-ginterface-gen.py \ - --filename=_gen/svc-$* \ - --signal-marshal-prefix=_mcd_ext \ - --include='' \ - --include='"_gen/signals-marshal.h"' \ - --not-implemented-func='tp_dbus_g_method_return_not_implemented' \ - --allow-unstable \ - $< Mc_Svc_ - include ../tools/header-checks.am check-local: header-decl-macro-check diff --git a/src/gtypes.c b/src/gtypes.c deleted file mode 100644 index 90c4fb1..0000000 --- a/src/gtypes.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "config.h" - -#include - -#include "_gen/gtypes.h" -#include "_gen/gtypes-body.h" - -/* Because I'm too lazy to have a separate file for these. */ -#include "_gen/interfaces.h" -#include "_gen/interfaces-body.h" diff --git a/src/mcd-account-addressing.c b/src/mcd-account-addressing.c index c9740c7..e1a0fb7 100644 --- a/src/mcd-account-addressing.c +++ b/src/mcd-account-addressing.c @@ -30,7 +30,6 @@ #include "mcd-account.h" #include "mcd-account-priv.h" -#include "_gen/interfaces.h" static void addressing_set_uri_scheme_association (TpSvcAccountInterfaceAddressing *iface, diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 5ff7bc9..268205d 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -49,8 +49,6 @@ #include "mission-control-plugins/implementation.h" #include "plugin-loader.h" -#include "_gen/interfaces.h" - #define PARAM_PREFIX "param-" #define WRITE_CONF_DELAY 500 diff --git a/src/mcd-account.c b/src/mcd-account.c index 948b5fb..5b3af05 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -44,10 +44,6 @@ #include "mcd-master-priv.h" #include "mcd-dbusprop.h" -#include "_gen/interfaces.h" -#include "_gen/enums.h" -#include "_gen/gtypes.h" - #define MC_OLD_AVATAR_FILENAME "avatar.bin" #define MCD_ACCOUNT_PRIV(account) (MCD_ACCOUNT (account)->priv) diff --git a/src/mcd-channel.c b/src/mcd-channel.c index eed88ae..a0d0a95 100644 --- a/src/mcd-channel.c +++ b/src/mcd-channel.c @@ -48,8 +48,6 @@ #include "mcd-enum-types.h" #include "request.h" -#include "_gen/interfaces.h" - #define MCD_CHANNEL_PRIV(channel) (MCD_CHANNEL (channel)->priv) G_DEFINE_TYPE (McdChannel, mcd_channel, MCD_TYPE_MISSION) diff --git a/src/mcd-connection.c b/src/mcd-connection.c index de2a6f5..190beec 100644 --- a/src/mcd-connection.c +++ b/src/mcd-connection.c @@ -1837,8 +1837,6 @@ mcd_connection_class_init (McdConnectionClass * klass) object_class->set_property = _mcd_connection_set_property; object_class->get_property = _mcd_connection_get_property; - _mcd_ext_register_dbus_glib_marshallers (); - tp_connection_init_known_interfaces (); /* Properties */ diff --git a/src/mcd-misc.c b/src/mcd-misc.c index 58b2f66..14fb905 100644 --- a/src/mcd-misc.c +++ b/src/mcd-misc.c @@ -37,9 +37,6 @@ #include "mcd-debug.h" -#include "_gen/signals-marshal.h" -#include "_gen/register-dbus-glib-marshallers-body.h" - #include #include diff --git a/src/mcd.xml b/src/mcd.xml deleted file mode 100644 index 29157ac..0000000 --- a/src/mcd.xml +++ /dev/null @@ -1,7 +0,0 @@ - - -Copyright (C) 2008 Nokia Corporation - - diff --git a/src/request.c b/src/request.c index ce91440..e59ec4c 100644 --- a/src/request.c +++ b/src/request.c @@ -34,7 +34,6 @@ #include "mcd-misc.h" #include "plugin-loader.h" #include "plugin-request.h" -#include "_gen/interfaces.h" enum { PROP_0, diff --git a/tools/Makefile.am b/tools/Makefile.am index befd266..563b9ff 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,39 +1,8 @@ EXTRA_DIST = \ - c-constants-generator.xsl \ - c-interfaces-generator.xsl \ - doc-generator.xsl \ - glib-client-gen.py \ - glib-blocking-client-gen.py \ - glib-client-marshaller-gen.py \ - glib-interfaces-generator.xsl \ - glib-interfaces-body-generator.xsl \ - glib-ginterface-gen.py \ - glib-gtypes-generator.py \ - glib-signals-marshal-gen.py \ - gquark-gen.py \ - identity.xsl \ lcov.am \ - libtpcodegen.py \ - libglibcodegen.py \ run_and_bt.gdb \ - spec-to-introspect.xsl \ telepathy.am -CLEANFILES = libglibcodegen.pyc libglibcodegen.pyo - -all: $(EXTRA_DIST) - -libglibcodegen.py: libtpcodegen.py - $(AM_V_GEN)test -e ${srcdir}/$@ && touch ${srcdir}/$@ -glib-client-marshaller-gen.py: libglibcodegen.py - $(AM_V_GEN)test -e ${srcdir}/$@ && touch ${srcdir}/$@ -glib-ginterface-gen.py: libglibcodegen.py - $(AM_V_GEN)test -e ${srcdir}/$@ && touch ${srcdir}/$@ -glib-gtypes-generator.py: libglibcodegen.py - $(AM_V_GEN)test -e ${srcdir}/$@ && touch ${srcdir}/$@ -glib-signals-marshal-gen.py: libglibcodegen.py - $(AM_V_GEN)test -e ${srcdir}/$@ && touch ${srcdir}/$@ - TELEPATHY_GLIB_SRCDIR = $(top_srcdir)/../telepathy-glib maintainer-update-from-telepathy-glib: set -e && cd $(srcdir) && \ diff --git a/tools/c-constants-generator.xsl b/tools/c-constants-generator.xsl deleted file mode 100644 index 18b2e49..0000000 --- a/tools/c-constants-generator.xsl +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * - - : - - - - * - - * <![CDATA[ - - ]]> - * - - * Bitfield/set of flags generated from the Telepathy specification. - */ - typedef enum { - - - - } - - ; - - - - - - - - * @ - - : <![CDATA[ - - ]]> - - - - - * @ - - : <![CDATA[ - - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - s - - - - /** - * - - : - - - - * - - * <![CDATA[ - - ]]> - * - - * Bitfield/set of flags generated from the Telepathy specification. - */ - typedef enum { - - - - } - - ; - - /** - * NUM_ - - : - * - * 1 higher than the highest valid value of # - - . - */ - #define NUM_ - - ( - - +1) - - - - - - - - - - - - - - - - - - - - Flag name - - != suffix - - - - - - - = - - , - - - - - - - - - - - - - - - - - - - Enumvalue name - - != suffix - - - - - - - - Enum values must be in ascending numeric order, but - - is less than the previous value - - - - - - = - - , - - - - tp:flag found outside tp:flags - - - - tp:enumvalue found outside tp:enum - - - - - - - - mixed-case-prefix param must be set - - - - /* Generated from - - - , version - - - - - - - - - - - - - */ - - #ifdef __cplusplus - extern "C" { - #endif - - - - #ifdef __cplusplus - } - #endif - - - - - diff --git a/tools/c-interfaces-generator.xsl b/tools/c-interfaces-generator.xsl deleted file mode 100644 index f965a70..0000000 --- a/tools/c-interfaces-generator.xsl +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - /** * - - _IFACE_ - - : * * The interface name " - - " */ #define - - _IFACE_ - - \ " - - " - - - - - - - - mixed-case-prefix param must be set - - - - /* Generated from: - - - version - - - - - - - - - - - */ - - - - - - diff --git a/tools/doc-generator.xsl b/tools/doc-generator.xsl deleted file mode 100644 index 76fc969..0000000 --- a/tools/doc-generator.xsl +++ /dev/null @@ -1,1199 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - . - - - - - - - - - - - - - - - - - - - - - ERR: cannot find D-Bus interface, method, - signal or property called ' - - ' - - - - - - - - - - - - - ERR: Cannot use tp:member-ref when not in an - <interface> - - - - - - - - - - ERR: interface - - has no signal/method/property called - - - - - - - - - - - - - - - - - - - - - - -

Added in - version . -

-
- - - - -

Changed in - version : -

-
- -

Changed in version -

-
-
-
- - -

Deprecated - since version . -

-
- - -
- -
-
- - -

Errors

- -
- - -

Generic types

- -
- - - -

Simple types

- -
- - -

Enumerated types:

- -
- - -

Sets of flags:

- -
- - -

Structure types

- -
- - -

Mapping types

- -
- - -

Types defined elsewhere

-
-
-
- - -

- - - - -
- - -
- -
-
- -
- -
-
- - - - - -

- - -

- This interface is - and is likely to cause havoc to your API/ABI if bindings are generated. - Don't include it in libraries that care about compatibility. -

-
- - -

Implementations of this interface must also implement:

-
    - -
  • -
    -
-
- - - - - - - - -

Methods:

- -
- -

Interface has no methods.

-
-
- - - -

Signals:

- -
- -

Interface has no signals.

-
-
- - - -

Telepathy Properties:

-

Accessed using the - Telepathy - Properties interface.

-
- -
-
- -

Interface has no Telepathy - properties.

-
-
- - - -

D-Bus core Properties:

-

Accessed using the - org.freedesktop.DBus.Properties interface.

-
- -
-
- -

Interface has no D-Bus core - properties.

-
-
- - - -
- - - - - - ERR: missing @name on a tp:flags type - - - - - - ERR: missing @type on tp:flags type - - - - - -

- - - -

- - - - -
- - - - - - - - - - - -
=
- - -
- - - - -
-
- -
(Undocumented)
-
-
-
-
-
- - - - - - ERR: missing @name on a tp:enum type - - - - - - ERR: missing @type on tp:enum type - - - - - -

- - - -

- - - - -
- - - - - - - - - - - -
=
- - -
- - - - -
-
- -
(Undocumented)
-
-
-
-
-
- - - - - - ERR: property - - does not have an interface as parent - - - - - - ERR: missing @name on a property of - - - - - - - - ERR: missing @type on property - - : ' - - ' - - - -
- - - - - - - , - - - read-only - - - write-only - - - read/write - - - - ERR: unknown or missing value for - @access on property - - : ' - - ' - - - -
-
- - - - -
-
- - -
- - − - - -
-
- - - - -
-
- - -
-

- - - − a{ - - - : - - - - } -

-
- - -

In bindings that need a separate name, arrays of - should be called - .

-
-
-
-

Members

-
- -
-
-
-
- - - - - − - - - - - - - ERR: missing @name on a tp:simple-type - - - - - - ERR: missing @type on tp:simple-type - - - - - -
-

- - - -

-
- - - - -
-
-
- - - - - - ERR: missing @name on a tp:external-type - - - - - - ERR: missing @type on tp:external-type - - - - - -
-
- - - -
-
Defined by:
-
-
- - - − ( - - , - ) - - - - − a{ - - - } - - - -
-

- - - − ( - - - : - - , - - ) -

-
- - - - -
- - -

In bindings that need a separate name, arrays of - should be called - .

-
- -

Arrays of don't generally - make sense.

-
-
-
-

Members

-
- -
-
-
-
- - - - - - ERR: method - - does not have an interface as parent - - - - - - ERR: missing @name on a method of - - - - - - - - - ERR: an arg of method - - has no type - - - - - - - ERR: an 'in' arg of method - - has no name - - - - - - - - - ERR: an arg of method - - has direction neither 'in' nor 'out' - - - - - -
-

- - - ( - - : - , - - ) → - - - - - , - - - nothing - -

-
- - - - -
- - -
-

Parameters

-
- -
-
-
- - -
-

Returns

-
- -
-
-
- - -
-

Possible errors

-
- -
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - ( - - - - ) - - - - - - - - - a{ - - - - } - - - - - - - ERR: Unable to find type ' - - ' - - - - - - - - ERR: tp:type ' - - ' has D-Bus type ' - - ' but has been used with type=' - - ' - - - - - - - - - - ( - - - - - ) - - - - -
- − - - -
-
- - - - - - (undocumented) - - -
-
- - -
- − - - -
-
- -
-
- - -
- - − - - - -
-
- -
-
- - -
- -
-
- - - - - - - (generic description) - - - (Undocumented.) - - -
-
- - - - - - ERR: signal - - does not have an interface as parent - - - - - - ERR: missing @name on a signal of - - - - - - - - - ERR: an arg of signal - - has no type - - - - - ERR: an arg of signal - - has no name - - - - - - - INFO: an arg of signal - - has unnecessary direction 'in' - - - - - ERR: an arg of signal - - has direction other than 'in' - - - - - -
-

- - - ( - - : - , - - )

- -
- - - - -
- - -
-

Parameters

-
- -
-
-
-
-
- - - - - - - - <xsl:value-of select="tp:title"/> - <xsl:if test="tp:version"> - <xsl:text> version </xsl:text> - <xsl:value-of select="tp:version"/> - </xsl:if> - - - - -

- -

- -

Version

-
- - - - -

Interfaces

-
    - -
  • -
    -
- - - - - -

Index

-

Index of interfaces

-
    - -
  • -
    -
-

Index of types

-
    - - -
  • - - - - - - -
  • -
    -
- - -
- - - - - - - - - Stray text: {{{ - - }}} - - - - - - - Unrecognised element: { - - } - - - - -
- - diff --git a/tools/glib-blocking-client-gen.py b/tools/glib-blocking-client-gen.py deleted file mode 100644 index c20dcd4..0000000 --- a/tools/glib-blocking-client-gen.py +++ /dev/null @@ -1,1014 +0,0 @@ -#!/usr/bin/python - -# glib-client-gen.py: "I Can't Believe It's Not dbus-binding-tool" -# -# Generate GLib client wrappers from the Telepathy specification. -# The master copy of this program is in the telepathy-glib repository - -# please make any changes there. -# -# Copyright (C) 2006-2008 Collabora Ltd. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import os.path -import xml.dom.minidom -from getopt import gnu_getopt - -from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \ - camelcase_to_lower, get_docstring - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -class Generator(object): - - def __init__(self, dom, prefix, basename, opts): - self.dom = dom - self.__header = [] - self.__body = [] - - self.prefix_lc = prefix.lower() - self.prefix_uc = prefix.upper() - self.prefix_mc = prefix.replace('_', '') - self.basename = basename - self.group = opts.get('--group', None) - self.iface_quark_prefix = opts.get('--iface-quark-prefix', None) - self.proxy_cls = opts.get('--subclass', 'TpProxy') + ' *' - self.proxy_arg = opts.get('--subclass', 'void') + ' *' - self.proxy_assert = opts.get('--subclass-assert', 'TP_IS_PROXY') - self.proxy_doc = ('A #%s or subclass' - % opts.get('--subclass', 'TpProxy')) - if self.proxy_arg == 'void *': - self.proxy_arg = 'gpointer ' - - def h(self, s): - self.__header.append(s) - - def b(self, s): - self.__body.append(s) - - def get_iface_quark(self): - assert self.iface_dbus is not None - assert self.iface_uc is not None - if self.iface_quark_prefix is None: - return 'g_quark_from_static_string (\"%s\")' % self.iface_dbus - else: - return '%s_%s' % (self.iface_quark_prefix, self.iface_uc) - - def do_signal(self, iface, signal): - iface_lc = iface.lower() - - member = signal.getAttribute('name') - member_lc = camelcase_to_lower(member) - member_uc = member_lc.upper() - - arg_count = 0 - args = [] - out_args = [] - - for arg in signal.getElementsByTagName('arg'): - name = arg.getAttribute('name') - type = arg.getAttribute('type') - tp_type = arg.getAttribute('tp:type') - - if not name: - name = 'arg%u' % arg_count - arg_count += 1 - else: - name = 'arg_%s' % name - - info = type_to_gtype(type) - args.append((name, info, tp_type, arg)) - - callback_name = ('%s_%s_signal_callback_%s' - % (self.prefix_lc, iface_lc, member_lc)) - collect_name = ('_%s_%s_collect_args_of_%s' - % (self.prefix_lc, iface_lc, member_lc)) - invoke_name = ('_%s_%s_invoke_callback_for_%s' - % (self.prefix_lc, iface_lc, member_lc)) - - # Example: - # - # typedef void (*tp_cli_connection_signal_callback_new_channel) - # (TpConnection *proxy, const gchar *arg_object_path, - # const gchar *arg_channel_type, guint arg_handle_type, - # guint arg_handle, gboolean arg_suppress_handler, - # gpointer user_data, GObject *weak_object); - - self.b('/**') - self.b(' * %s:' % callback_name) - self.b(' * @proxy: The proxy on which %s_%s_connect_to_%s ()' - % (self.prefix_lc, iface_lc, member_lc)) - self.b(' * was called') - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' * @%s: ' % (name, - get_docstring(elt) or '(Undocumented)')) - - self.b(' * @user_data: User-supplied data') - self.b(' * @weak_object: User-supplied weakly referenced object') - self.b(' *') - self.b(' * Represents the signature of a callback for the signal %s.' - % member) - self.b(' */') - self.h('typedef void (*%s) (%sproxy,' - % (callback_name, self.proxy_cls)) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - - self.h(' gpointer user_data, GObject *weak_object);') - - if args: - self.b('static void') - self.b('%s (DBusGProxy *proxy,' % collect_name) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s%s%s,' % (const, ctype, name)) - - self.b(' TpProxySignalConnection *sc)') - self.b('{') - self.b(' GValueArray *args = g_value_array_new (%d);' % len(args)) - self.b(' GValue blank = { 0 };') - self.b(' guint i;') - self.b('') - self.b(' g_value_init (&blank, G_TYPE_INT);') - self.b('') - self.b(' for (i = 0; i < %d; i++)' % len(args)) - self.b(' g_value_array_append (args, &blank);') - self.b('') - - for i, arg in enumerate(args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' g_value_unset (args->values + %d);' % i) - self.b(' g_value_init (args->values + %d, %s);' % (i, gtype)) - - if gtype == 'G_TYPE_STRING': - self.b(' g_value_set_string (args->values + %d, %s);' - % (i, name)) - elif marshaller == 'BOXED': - self.b(' g_value_set_boxed (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_set_uchar (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_set_boolean (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_set_double (args->values + %d, %s);' - % (i, name)) - else: - assert False, ("Don't know how to put %s in a GValue" - % gtype) - self.b('') - - self.b(' tp_proxy_signal_connection_v0_take_results (sc, args);') - self.b('}') - - self.b('static void') - self.b('%s (TpProxy *tpproxy,' % invoke_name) - self.b(' GError *error,') - self.b(' GValueArray *args,') - self.b(' GCallback generic_callback,') - self.b(' gpointer user_data,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' %s callback =' % callback_name) - self.b(' (%s) generic_callback;' % callback_name) - self.b('') - self.b(' if (callback != NULL)') - self.b(' callback (g_object_ref (tpproxy),') - - # FIXME: factor out into a function - for i, arg in enumerate(args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED': - self.b(' g_value_get_boxed (args->values + %d),' % i) - elif gtype == 'G_TYPE_STRING': - self.b(' g_value_get_string (args->values + %d),' % i) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_get_uchar (args->values + %d),' % i) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_get_boolean (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_get_uint (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_get_int (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_get_uint64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_get_int64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_get_double (args->values + %d),' % i) - else: - assert False, "Don't know how to get %s from a GValue" % gtype - - self.b(' user_data,') - self.b(' weak_object);') - self.b('') - - if len(args) > 0: - self.b(' g_value_array_free (args);') - else: - self.b(' if (args != NULL)') - self.b(' g_value_array_free (args);') - self.b('') - - self.b(' g_object_unref (tpproxy);') - self.b('}') - - # Example: - # - # TpProxySignalConnection * - # tp_cli_connection_connect_to_new_channel - # (TpConnection *proxy, - # tp_cli_connection_signal_callback_new_channel callback, - # gpointer user_data, - # GDestroyNotify destroy); - # - # destroy is invoked when the signal becomes disconnected. This - # is either because the signal has been disconnected explicitly - # by the user, because the TpProxy has become invalid and - # emitted the 'invalidated' signal, or because the weakly referenced - # object has gone away. - - self.b('/**') - self.b(' * %s_%s_connect_to_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.b(' * @proxy: %s' % self.proxy_doc) - self.b(' * @callback: Callback to be called when the signal is') - self.b(' * received') - self.b(' * @user_data: User-supplied data for the callback') - self.b(' * @destroy: Destructor for the user-supplied data, which') - self.b(' * will be called when this signal is disconnected, or') - self.b(' * before this function returns %NULL') - self.b(' * @weak_object: A #GObject which will be weakly referenced; ') - self.b(' * if it is destroyed, this callback will automatically be') - self.b(' * disconnected') - self.b(' * @error: If not %NULL, used to raise an error if %NULL is') - self.b(' * returned') - self.b(' *') - self.b(' * Connect a handler to the signal %s.' % member) - self.b(' *') - self.b(' * ' - % (get_docstring(signal) or '(Undocumented)')) - self.b(' *') - self.b(' * Returns: a #TpProxySignalConnection containing all of the') - self.b(' * above, which can be used to disconnect the signal; or') - self.b(' * %NULL if the proxy does not have the desired interface') - self.b(' * or has become invalid.') - self.b(' */') - self.h('TpProxySignalConnection *%s_%s_connect_to_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.h(' %s callback,' % callback_name) - self.h(' gpointer user_data,') - self.h(' GDestroyNotify destroy,') - self.h(' GObject *weak_object,') - self.h(' GError **error);') - - self.b('TpProxySignalConnection *') - self.b('%s_%s_connect_to_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.b(' %s callback,' % callback_name) - self.b(' gpointer user_data,') - self.b(' GDestroyNotify destroy,') - self.b(' GObject *weak_object,') - self.b(' GError **error)') - self.b('{') - self.b(' GType expected_types[%d] = {' % (len(args) + 1)) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s,' % gtype) - - self.b(' G_TYPE_INVALID };') - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), NULL);' - % self.proxy_assert) - self.b(' g_return_val_if_fail (callback != NULL, NULL);') - self.b('') - self.b(' return tp_proxy_signal_connection_v0_new ((TpProxy *) proxy,') - self.b(' %s, \"%s\",' % (self.get_iface_quark(), member)) - self.b(' expected_types,') - - if args: - self.b(' G_CALLBACK (%s),' % collect_name) - else: - self.b(' NULL, /* no args => no collector function */') - - self.b(' %s,' % invoke_name) - self.b(' G_CALLBACK (callback), user_data, destroy,') - self.b(' weak_object, error);') - self.b('}') - self.b('') - - self.h('') - - def do_method(self, iface, method): - iface_lc = iface.lower() - - member = method.getAttribute('name') - member_lc = camelcase_to_lower(member) - member_uc = member_lc.upper() - - in_count = 0 - ret_count = 0 - in_args = [] - out_args = [] - - for arg in method.getElementsByTagName('arg'): - name = arg.getAttribute('name') - direction = arg.getAttribute('direction') - type = arg.getAttribute('type') - tp_type = arg.getAttribute('tp:type') - - if direction != 'out': - if not name: - name = 'in%u' % in_count - in_count += 1 - else: - name = 'in_%s' % name - else: - if not name: - name = 'out%u' % ret_count - ret_count += 1 - else: - name = 'out_%s' % name - - info = type_to_gtype(type) - if direction != 'out': - in_args.append((name, info, tp_type, arg)) - else: - out_args.append((name, info, tp_type, arg)) - - # Async reply callback type - - # Example: - # void (*tp_cli_properties_interface_callback_for_get_properties) - # (TpProxy *proxy, - # const GPtrArray *out0, - # const GError *error, - # gpointer user_data, - # GObject *weak_object); - - self.b('/**') - self.b(' * %s_%s_callback_for_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.b(' * @proxy: the proxy on which the call was made') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' * @%s: Used to return an \'out\' argument if @error is ' - '%%NULL: ' - % (name, get_docstring(elt) or '(Undocumented)')) - - self.b(' * @error: %NULL on success, or an error on failure') - self.b(' * @user_data: user-supplied data') - self.b(' * @weak_object: user-supplied object') - self.b(' *') - self.b(' * Signature of the callback called when a %s method call' - % member) - self.b(' * succeeds or fails.') - self.b(' */') - - callback_name = '%s_%s_callback_for_%s' % (self.prefix_lc, iface_lc, - member_lc) - - self.h('typedef void (*%s) (%sproxy,' - % (callback_name, self.proxy_cls)) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - - self.h(' const GError *error, gpointer user_data,') - self.h(' GObject *weak_object);') - self.h('') - - # Async callback implementation - - invoke_callback = '_%s_%s_invoke_callback_%s' % (self.prefix_lc, - iface_lc, - member_lc) - - collect_callback = '_%s_%s_collect_callback_%s' % (self.prefix_lc, - iface_lc, - member_lc) - - # The callback called by dbus-glib; this ends the call and collects - # the results into a GValueArray. - self.b('static void') - self.b('%s (DBusGProxy *proxy,' % collect_callback) - self.b(' DBusGProxyCall *call,') - self.b(' gpointer user_data)') - self.b('{') - self.b(' GError *error = NULL;') - - if len(out_args) > 0: - self.b(' GValueArray *args;') - self.b(' GValue blank = { 0 };') - self.b(' guint i;') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s%s;' % (ctype, name)) - - self.b('') - self.b(' dbus_g_proxy_end_call (proxy, call, &error,') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s, &%s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID);') - - if len(out_args) == 0: - self.b(' tp_proxy_pending_call_v0_take_results (user_data, error,' - 'NULL);') - else: - self.b('') - self.b(' if (error != NULL)') - self.b(' {') - self.b(' tp_proxy_pending_call_v0_take_results (user_data, error,') - self.b(' NULL);') - self.b(' return;') - self.b(' }') - self.b('') - self.b(' args = g_value_array_new (%d);' % len(out_args)) - self.b(' g_value_init (&blank, G_TYPE_INT);') - self.b('') - self.b(' for (i = 0; i < %d; i++)' % len(out_args)) - self.b(' g_value_array_append (args, &blank);') - - for i, arg in enumerate(out_args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b('') - self.b(' g_value_unset (args->values + %d);' % i) - self.b(' g_value_init (args->values + %d, %s);' % (i, gtype)) - - if gtype == 'G_TYPE_STRING': - self.b(' g_value_take_string (args->values + %d, %s);' - % (i, name)) - elif marshaller == 'BOXED': - self.b(' g_value_take_boxed (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_set_uchar (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_set_boolean (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_set_double (args->values + %d, %s);' - % (i, name)) - else: - assert False, ("Don't know how to put %s in a GValue" - % gtype) - - self.b(' tp_proxy_pending_call_v0_take_results (user_data, ' - 'NULL, args);') - - self.b('}') - - self.b('static void') - self.b('%s (TpProxy *self,' % invoke_callback) - self.b(' GError *error,') - self.b(' GValueArray *args,') - self.b(' GCallback generic_callback,') - self.b(' gpointer user_data,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' %s callback = (%s) generic_callback;' - % (callback_name, callback_name)) - self.b('') - self.b(' if (error != NULL)') - self.b(' {') - self.b(' callback ((%s) self,' % self.proxy_cls) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED' or pointer: - self.b(' NULL,') - elif gtype == 'G_TYPE_DOUBLE': - self.b(' 0.0,') - else: - self.b(' 0,') - - self.b(' error, user_data, weak_object);') - self.b(' g_error_free (error);') - self.b(' return;') - self.b(' }') - - self.b(' callback ((%s) self,' % self.proxy_cls) - - # FIXME: factor out into a function - for i, arg in enumerate(out_args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED': - self.b(' g_value_get_boxed (args->values + %d),' % i) - elif gtype == 'G_TYPE_STRING': - self.b(' g_value_get_string (args->values + %d),' % i) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_get_uchar (args->values + %d),' % i) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_get_boolean (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_get_uint (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_get_int (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_get_uint64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_get_int64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_get_double (args->values + %d),' % i) - else: - assert False, "Don't know how to get %s from a GValue" % gtype - - self.b(' error, user_data, weak_object);') - self.b('') - - if len(out_args) > 0: - self.b(' g_value_array_free (args);') - else: - self.b(' if (args != NULL)') - self.b(' g_value_array_free (args);') - - self.b('}') - self.b('') - - # Async stub - - # Example: - # TpProxyPendingCall * - # tp_cli_properties_interface_call_get_properties - # (gpointer proxy, - # gint timeout_ms, - # const GArray *in_properties, - # tp_cli_properties_interface_callback_for_get_properties callback, - # gpointer user_data, - # GDestroyNotify *destructor); - - self.h('TpProxyPendingCall *%s_%s_call_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.h(' gint timeout_ms,') - - self.b('/**') - self.b(' * %s_%s_call_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.b(' * @proxy: the #TpProxy') - self.b(' * @timeout_ms: the timeout in milliseconds, or -1 to use the') - self.b(' * default') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' * @%s: Used to pass an \'in\' argument: ' - % (name, get_docstring(elt) or '(Undocumented)')) - - self.b(' * @callback: called when the method call succeeds or fails') - self.b(' * @user_data: user-supplied data passed to the callback') - self.b(' * @destroy: called with the user_data as argument, after the') - self.b(' * call has succeeded, failed or been cancelled') - self.b(' * @weak_object: A #GObject which will be weakly referenced; ') - self.b(' * if it is destroyed, this callback will automatically be') - self.b(' * disconnected') - self.b(' *') - self.b(' * Start a %s method call.' % member) - self.b(' *') - self.b(' * ' - % (get_docstring(method) or '(Undocumented)')) - self.b(' *') - self.b(' * Returns: a #TpProxyPendingCall representing the call in') - self.b(' * progress. It is borrowed from the object, and will become') - self.b(' * invalid when the callback is called, the call is') - self.b(' * cancelled or the #TpProxy becomes invalid.') - self.b(' */') - self.b('TpProxyPendingCall *\n%s_%s_call_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.b(' gint timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - self.b(' %s%s%s,' % (const, ctype, name)) - - self.h(' %s callback,' % callback_name) - self.h(' gpointer user_data,') - self.h(' GDestroyNotify destroy,') - self.h(' GObject *weak_object);') - self.h('') - - self.b(' %s callback,' % callback_name) - self.b(' gpointer user_data,') - self.b(' GDestroyNotify destroy,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' GError *error = NULL;') - self.b(' GQuark interface = %s;' % self.get_iface_quark()) - self.b(' DBusGProxy *iface;') - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), NULL);' - % self.proxy_assert) - self.b('') - self.b(' iface = tp_proxy_borrow_interface_by_id (') - self.b(' (TpProxy *) proxy,') - self.b(' interface, &error);') - self.b('') - self.b(' if (iface == NULL)') - self.b(' {') - self.b(' if (callback != NULL)') - self.b(' callback (proxy,') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if pointer: - self.b(' NULL,') - else: - self.b(' 0,') - - self.b(' error, user_data, weak_object);') - self.b(' g_error_free (error);') - self.b(' return NULL;') - self.b(' }') - self.b('') - self.b(' if (callback == NULL)') - self.b(' {') - self.b(' dbus_g_proxy_call_no_reply (iface, "%s",' % member) - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID);') - self.b(' return NULL;') - self.b(' }') - self.b(' else') - self.b(' {') - self.b(' TpProxyPendingCall *data;') - self.b('') - self.b(' data = tp_proxy_pending_call_v0_new ((TpProxy *) proxy,') - self.b(' interface, "%s", iface,' % member) - self.b(' %s,' % invoke_callback) - self.b(' G_CALLBACK (callback), user_data, destroy,') - self.b(' weak_object, FALSE);') - self.b(' tp_proxy_pending_call_v0_take_pending_call (data,') - self.b(' dbus_g_proxy_begin_call_with_timeout (iface,') - self.b(' "%s",' % member) - self.b(' %s,' % collect_callback) - self.b(' data,') - self.b(' tp_proxy_pending_call_v0_completed,') - self.b(' timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID));') - self.b('') - self.b(' return data;') - self.b(' }') - self.b('}') - self.b('') - - # Non reentrant blocking calls - # Example: - # gboolean tp_cli_properties_interface_do_get_properties - # (gpointer proxy, - # gint timeout_ms, - # const GArray *in_properties, - # GPtrArray **out0, - # GError **error); - - self.h('gboolean %s_%s_do_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.h(' gint timeout_ms,') - - self.b('/**') - self.b(' * %s_%s_do_%s:' % (self.prefix_lc, iface_lc, member_lc)) - self.b(' * @proxy: %s' % self.proxy_doc) - self.b(' * @timeout_ms: Timeout in milliseconds, or -1 for default') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' * @%s: Used to pass an \'in\' argument: ' - % (name, get_docstring(elt) or '(Undocumented)')) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' * @%s: Used to return an \'out\' argument if %%TRUE is ' - 'returned: ' - % (name, get_docstring(elt) or '(Undocumented)')) - - self.b(' * @error: If not %NULL, used to return errors if %FALSE ') - self.b(' * is returned') - self.b(' *') - self.b(' * Call the method %s and block' % member) - self.b(' * until it returns.') - self.b(' *') - self.b(' * ' - % (get_docstring(method) or '(Undocumented)')) - self.b(' *') - self.b(' * Returns: TRUE on success, FALSE and sets @error on error') - self.b(' */') - self.b('gboolean\n%s_%s_do_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.b(' gint timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - self.b(' %s%s%s,' % (const, ctype, name)) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.h(' %s*%s,' % (ctype, name)) - self.b(' %s*%s,' % (ctype, name)) - - self.h(' GError **error);') - self.h('') - - self.b(' GError **error)') - self.b('{') - self.b(' DBusGProxy *iface;') - self.b(' GQuark interface = %s;' % self.get_iface_quark()) - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %si_%s;' % (ctype, name)) - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), FALSE);' - % self.proxy_assert) - self.b('') - self.b(' iface = tp_proxy_borrow_interface_by_id') - self.b(' ((TpProxy *) proxy, interface, error);') - self.b('') - self.b(' if (iface == NULL)') - self.b(' return FALSE;') - self.b('') - self.b(' if (dbus_g_proxy_call_with_timeout (iface,') - self.b(' "%s",' % member) - self.b(' timeout_ms,') - self.b(' error,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID,') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s, &i_%s,' % (gtype, name)) - self.b(' G_TYPE_INVALID))') - self.b(' {') - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' *%s = i_%s;' % (name, name)) - self.b(' return TRUE;') - self.b(' }') - self.b(' else') - self.b(' return FALSE;') - self.b('}') - self.b('') - - # leave a gap for the end of the method - self.b('') - self.h('') - - def do_signal_add(self, signal): - marshaller_items = [] - gtypes = [] - - for i in signal.getElementsByTagName('arg'): - name = i.getAttribute('name') - type = i.getAttribute('type') - info = type_to_gtype(type) - # type, GType, STRING, is a pointer - gtypes.append(info[1]) - - self.b(' dbus_g_proxy_add_signal (proxy, "%s",' - % signal.getAttribute('name')) - for gtype in gtypes: - self.b(' %s,' % gtype) - self.b(' G_TYPE_INVALID);') - - def do_interface(self, node): - ifaces = node.getElementsByTagName('interface') - assert len(ifaces) == 1 - iface = ifaces[0] - name = node.getAttribute('name').replace('/', '') - - self.iface = name - self.iface_lc = name.lower() - self.iface_uc = name.upper() - self.iface_mc = name.replace('_', '') - self.iface_dbus = iface.getAttribute('name') - - signals = node.getElementsByTagName('signal') - methods = node.getElementsByTagName('method') - - self.b('static inline void') - self.b('%s_add_signals_for_%s (DBusGProxy *proxy)' - % (self.prefix_lc, name.lower())) - self.b('{') - - for signal in signals: - self.do_signal_add(signal) - - self.b('}') - self.b('') - self.b('') - - for signal in signals: - self.do_signal(name, signal) - - for method in methods: - self.do_method(name, method) - - self.iface_dbus = None - - def __call__(self): - - self.h('G_BEGIN_DECLS') - self.h('') - - self.b('/* We don\'t want gtkdoc scanning this file, it\'ll get') - self.b(' * confused by seeing function definitions, so mark it as: */') - self.b('/**/') - self.b('') - - nodes = self.dom.getElementsByTagName('node') - nodes.sort(cmp_by_name) - - for node in nodes: - self.do_interface(node) - - if self.group is not None: - - self.b('/*') - self.b(' * %s_%s_add_signals:' % (self.prefix_lc, self.group)) - self.b(' * @self: the #TpProxy') - self.b(' * @quark: a quark whose string value is the interface') - self.b(' * name whose signals should be added') - self.b(' * @proxy: the D-Bus proxy to which to add the signals') - self.b(' * @unused: not used for anything') - self.b(' *') - self.b(' * Tell dbus-glib that @proxy has the signatures of all') - self.b(' * signals on the given interface, if it\'s one we') - self.b(' * support.') - self.b(' *') - self.b(' * This function should be used as a signal handler for') - self.b(' * #TpProxy::interface-added.') - self.b(' */') - self.b('static void') - self.b('%s_%s_add_signals (TpProxy *self,' - % (self.prefix_lc, self.group)) - self.b(' guint quark,') - self.b(' DBusGProxy *proxy,') - self.b(' gpointer unused)') - - self.b('{') - - for node in nodes: - iface = node.getElementsByTagName('interface')[0] - self.iface_dbus = iface.getAttribute('name') - name = node.getAttribute('name').replace('/', '').lower() - self.iface_uc = name.upper() - self.b(' if (quark == %s)' % self.get_iface_quark()) - self.b(' %s_add_signals_for_%s (proxy);' - % (self.prefix_lc, name)) - - self.b('}') - self.b('') - - self.h('G_END_DECLS') - self.h('') - - open(self.basename + '.h', 'w').write('\n'.join(self.__header)) - open(self.basename + '-body.h', 'w').write('\n'.join(self.__body)) - - -def types_to_gtypes(types): - return [type_to_gtype(t)[1] for t in types] - - -if __name__ == '__main__': - options, argv = gnu_getopt(sys.argv[1:], '', - ['group=', 'subclass=', 'subclass-assert=', - 'iface-quark-prefix=']) - - opts = {} - - for option, value in options: - opts[option] = value - - dom = xml.dom.minidom.parse(argv[0]) - - Generator(dom, argv[1], argv[2], opts)() diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py deleted file mode 100644 index f8465a6..0000000 --- a/tools/glib-client-gen.py +++ /dev/null @@ -1,1269 +0,0 @@ -#!/usr/bin/python - -# glib-client-gen.py: "I Can't Believe It's Not dbus-binding-tool" -# -# Generate GLib client wrappers from the Telepathy specification. -# The master copy of this program is in the telepathy-glib repository - -# please make any changes there. -# -# Copyright (C) 2006-2008 Collabora Ltd. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import os.path -import xml.dom.minidom -from getopt import gnu_getopt - -from libtpcodegen import file_set_contents -from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \ - get_docstring, xml_escape, get_deprecated - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -class Generator(object): - - def __init__(self, dom, prefix, basename, opts): - self.dom = dom - self.__header = [] - self.__body = [] - self.__docs = [] - - self.prefix_lc = prefix.lower() - self.prefix_uc = prefix.upper() - self.prefix_mc = prefix.replace('_', '') - self.basename = basename - self.group = opts.get('--group', None) - self.iface_quark_prefix = opts.get('--iface-quark-prefix', None) - self.tp_proxy_api = tuple(map(int, - opts.get('--tp-proxy-api', '0').split('.'))) - self.proxy_cls = opts.get('--subclass', 'TpProxy') + ' *' - self.proxy_arg = opts.get('--subclass', 'void') + ' *' - self.proxy_assert = opts.get('--subclass-assert', 'TP_IS_PROXY') - self.proxy_doc = ('A #%s or subclass' - % opts.get('--subclass', 'TpProxy')) - if self.proxy_arg == 'void *': - self.proxy_arg = 'gpointer ' - - self.reentrant_symbols = set() - try: - filename = opts['--generate-reentrant'] - with open(filename, 'r') as f: - for line in f.readlines(): - self.reentrant_symbols.add(line.strip()) - except KeyError: - pass - - self.deprecate_reentrant = opts.get('--deprecate-reentrant', None) - self.deprecation_attribute = opts.get('--deprecation-attribute', - 'G_GNUC_DEPRECATED') - - self.guard = opts.get('--guard', None) - - def h(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__header.append(s) - - def b(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__body.append(s) - - def d(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__docs.append(s) - - def get_iface_quark(self): - assert self.iface_dbus is not None - assert self.iface_uc is not None - if self.iface_quark_prefix is None: - return 'g_quark_from_static_string (\"%s\")' % self.iface_dbus - else: - return '%s_%s' % (self.iface_quark_prefix, self.iface_uc) - - def do_signal(self, iface, signal): - iface_lc = iface.lower() - - member = signal.getAttribute('name') - member_lc = signal.getAttribute('tp:name-for-bindings') - if member != member_lc.replace('_', ''): - raise AssertionError('Signal %s tp:name-for-bindings (%s) does ' - 'not match' % (member, member_lc)) - member_lc = member_lc.lower() - member_uc = member_lc.upper() - - arg_count = 0 - args = [] - out_args = [] - - for arg in signal.getElementsByTagName('arg'): - name = arg.getAttribute('name') - type = arg.getAttribute('type') - tp_type = arg.getAttribute('tp:type') - - if not name: - name = 'arg%u' % arg_count - arg_count += 1 - else: - name = 'arg_%s' % name - - info = type_to_gtype(type) - args.append((name, info, tp_type, arg)) - - callback_name = ('%s_%s_signal_callback_%s' - % (self.prefix_lc, iface_lc, member_lc)) - collect_name = ('_%s_%s_collect_args_of_%s' - % (self.prefix_lc, iface_lc, member_lc)) - invoke_name = ('_%s_%s_invoke_callback_for_%s' - % (self.prefix_lc, iface_lc, member_lc)) - - # Example: - # - # typedef void (*tp_cli_connection_signal_callback_new_channel) - # (TpConnection *proxy, const gchar *arg_object_path, - # const gchar *arg_channel_type, guint arg_handle_type, - # guint arg_handle, gboolean arg_suppress_handler, - # gpointer user_data, GObject *weak_object); - - self.d('/**') - self.d(' * %s:' % callback_name) - self.d(' * @proxy: The proxy on which %s_%s_connect_to_%s ()' - % (self.prefix_lc, iface_lc, member_lc)) - self.d(' * was called') - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - docs = get_docstring(elt) or '(Undocumented)' - - if ctype == 'guint ' and tp_type != '': - docs += ' (#%s)' % ('Tp' + tp_type.replace('_', '')) - - self.d(' * @%s: %s' % (name, xml_escape(docs))) - - self.d(' * @user_data: User-supplied data') - self.d(' * @weak_object: User-supplied weakly referenced object') - self.d(' *') - self.d(' * Represents the signature of a callback for the signal %s.' - % member) - self.d(' */') - self.d('') - - self.h('typedef void (*%s) (%sproxy,' - % (callback_name, self.proxy_cls)) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - - self.h(' gpointer user_data, GObject *weak_object);') - - if args: - self.b('static void') - self.b('%s (DBusGProxy *proxy G_GNUC_UNUSED,' % collect_name) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s%s%s,' % (const, ctype, name)) - - self.b(' TpProxySignalConnection *sc)') - self.b('{') - self.b(' GValueArray *args = g_value_array_new (%d);' % len(args)) - self.b(' GValue blank = { 0 };') - self.b(' guint i;') - self.b('') - self.b(' g_value_init (&blank, G_TYPE_INT);') - self.b('') - self.b(' for (i = 0; i < %d; i++)' % len(args)) - self.b(' g_value_array_append (args, &blank);') - self.b('') - - for i, arg in enumerate(args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' g_value_unset (args->values + %d);' % i) - self.b(' g_value_init (args->values + %d, %s);' % (i, gtype)) - - if gtype == 'G_TYPE_STRING': - self.b(' g_value_set_string (args->values + %d, %s);' - % (i, name)) - elif marshaller == 'BOXED': - self.b(' g_value_set_boxed (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_set_uchar (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_set_boolean (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_set_uint64 (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_set_double (args->values + %d, %s);' - % (i, name)) - else: - assert False, ("Don't know how to put %s in a GValue" - % gtype) - self.b('') - - self.b(' tp_proxy_signal_connection_v0_take_results (sc, args);') - self.b('}') - - self.b('static void') - self.b('%s (TpProxy *tpproxy,' % invoke_name) - self.b(' GError *error G_GNUC_UNUSED,') - self.b(' GValueArray *args,') - self.b(' GCallback generic_callback,') - self.b(' gpointer user_data,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' %s callback =' % callback_name) - self.b(' (%s) generic_callback;' % callback_name) - self.b('') - self.b(' if (callback != NULL)') - self.b(' callback (g_object_ref (tpproxy),') - - # FIXME: factor out into a function - for i, arg in enumerate(args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED': - self.b(' g_value_get_boxed (args->values + %d),' % i) - elif gtype == 'G_TYPE_STRING': - self.b(' g_value_get_string (args->values + %d),' % i) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_get_uchar (args->values + %d),' % i) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_get_boolean (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_get_uint (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_get_int (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_get_uint64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_get_int64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_get_double (args->values + %d),' % i) - else: - assert False, "Don't know how to get %s from a GValue" % gtype - - self.b(' user_data,') - self.b(' weak_object);') - self.b('') - - if len(args) > 0: - self.b(' g_value_array_free (args);') - else: - self.b(' if (args != NULL)') - self.b(' g_value_array_free (args);') - self.b('') - - self.b(' g_object_unref (tpproxy);') - self.b('}') - - # Example: - # - # TpProxySignalConnection * - # tp_cli_connection_connect_to_new_channel - # (TpConnection *proxy, - # tp_cli_connection_signal_callback_new_channel callback, - # gpointer user_data, - # GDestroyNotify destroy); - # - # destroy is invoked when the signal becomes disconnected. This - # is either because the signal has been disconnected explicitly - # by the user, because the TpProxy has become invalid and - # emitted the 'invalidated' signal, or because the weakly referenced - # object has gone away. - - self.d('/**') - self.d(' * %s_%s_connect_to_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.d(' * @proxy: %s' % self.proxy_doc) - self.d(' * @callback: Callback to be called when the signal is') - self.d(' * received') - self.d(' * @user_data: User-supplied data for the callback') - self.d(' * @destroy: Destructor for the user-supplied data, which') - self.d(' * will be called when this signal is disconnected, or') - self.d(' * before this function returns %NULL') - self.d(' * @weak_object: A #GObject which will be weakly referenced; ') - self.d(' * if it is destroyed, this callback will automatically be') - self.d(' * disconnected') - self.d(' * @error: If not %NULL, used to raise an error if %NULL is') - self.d(' * returned') - self.d(' *') - self.d(' * Connect a handler to the signal %s.' % member) - self.d(' *') - self.d(' * %s' % xml_escape(get_docstring(signal) or '(Undocumented)')) - self.d(' *') - self.d(' * Returns: a #TpProxySignalConnection containing all of the') - self.d(' * above, which can be used to disconnect the signal; or') - self.d(' * %NULL if the proxy does not have the desired interface') - self.d(' * or has become invalid.') - self.d(' */') - self.d('') - - self.h('TpProxySignalConnection *%s_%s_connect_to_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.h(' %s callback,' % callback_name) - self.h(' gpointer user_data,') - self.h(' GDestroyNotify destroy,') - self.h(' GObject *weak_object,') - self.h(' GError **error);') - self.h('') - - self.b('TpProxySignalConnection *') - self.b('%s_%s_connect_to_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.b(' %s callback,' % callback_name) - self.b(' gpointer user_data,') - self.b(' GDestroyNotify destroy,') - self.b(' GObject *weak_object,') - self.b(' GError **error)') - self.b('{') - self.b(' GType expected_types[%d] = {' % (len(args) + 1)) - - for arg in args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s,' % gtype) - - self.b(' G_TYPE_INVALID };') - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), NULL);' - % self.proxy_assert) - self.b(' g_return_val_if_fail (callback != NULL, NULL);') - self.b('') - self.b(' return tp_proxy_signal_connection_v0_new ((TpProxy *) proxy,') - self.b(' %s, \"%s\",' % (self.get_iface_quark(), member)) - self.b(' expected_types,') - - if args: - self.b(' G_CALLBACK (%s),' % collect_name) - else: - self.b(' NULL, /* no args => no collector function */') - - self.b(' %s,' % invoke_name) - self.b(' G_CALLBACK (callback), user_data, destroy,') - self.b(' weak_object, error);') - self.b('}') - self.b('') - - def do_method(self, iface, method): - iface_lc = iface.lower() - - member = method.getAttribute('name') - member_lc = method.getAttribute('tp:name-for-bindings') - if member != member_lc.replace('_', ''): - raise AssertionError('Method %s tp:name-for-bindings (%s) does ' - 'not match' % (member, member_lc)) - member_lc = member_lc.lower() - member_uc = member_lc.upper() - - in_count = 0 - ret_count = 0 - in_args = [] - out_args = [] - - for arg in method.getElementsByTagName('arg'): - name = arg.getAttribute('name') - direction = arg.getAttribute('direction') - type = arg.getAttribute('type') - tp_type = arg.getAttribute('tp:type') - - if direction != 'out': - if not name: - name = 'in%u' % in_count - in_count += 1 - else: - name = 'in_%s' % name - else: - if not name: - name = 'out%u' % ret_count - ret_count += 1 - else: - name = 'out_%s' % name - - info = type_to_gtype(type) - if direction != 'out': - in_args.append((name, info, tp_type, arg)) - else: - out_args.append((name, info, tp_type, arg)) - - # Async reply callback type - - # Example: - # void (*tp_cli_properties_interface_callback_for_get_properties) - # (TpProxy *proxy, - # const GPtrArray *out0, - # const GError *error, - # gpointer user_data, - # GObject *weak_object); - - self.d('/**') - self.d(' * %s_%s_callback_for_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.d(' * @proxy: the proxy on which the call was made') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - docs = xml_escape(get_docstring(elt) or '(Undocumented)') - - if ctype == 'guint ' and tp_type != '': - docs += ' (#%s)' % ('Tp' + tp_type.replace('_', '')) - - self.d(' * @%s: Used to return an \'out\' argument if @error is ' - '%%NULL: %s' - % (name, docs)) - - self.d(' * @error: %NULL on success, or an error on failure') - self.d(' * @user_data: user-supplied data') - self.d(' * @weak_object: user-supplied object') - self.d(' *') - self.d(' * Signature of the callback called when a %s method call' - % member) - self.d(' * succeeds or fails.') - - deprecated = method.getElementsByTagName('tp:deprecated') - if deprecated: - d = deprecated[0] - self.d(' *') - self.d(' * Deprecated: %s' % xml_escape(get_deprecated(d))) - - self.d(' */') - self.d('') - - callback_name = '%s_%s_callback_for_%s' % (self.prefix_lc, iface_lc, - member_lc) - - self.h('typedef void (*%s) (%sproxy,' - % (callback_name, self.proxy_cls)) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - - self.h(' const GError *error, gpointer user_data,') - self.h(' GObject *weak_object);') - self.h('') - - # Async callback implementation - - invoke_callback = '_%s_%s_invoke_callback_%s' % (self.prefix_lc, - iface_lc, - member_lc) - - collect_callback = '_%s_%s_collect_callback_%s' % (self.prefix_lc, - iface_lc, - member_lc) - - # The callback called by dbus-glib; this ends the call and collects - # the results into a GValueArray. - self.b('static void') - self.b('%s (DBusGProxy *proxy,' % collect_callback) - self.b(' DBusGProxyCall *call,') - self.b(' gpointer user_data)') - self.b('{') - self.b(' GError *error = NULL;') - - if len(out_args) > 0: - self.b(' GValueArray *args;') - self.b(' GValue blank = { 0 };') - self.b(' guint i;') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - # "We handle variants specially; the caller is expected to - # have already allocated storage for them". Thanks, - # dbus-glib... - if gtype == 'G_TYPE_VALUE': - self.b(' GValue *%s = g_new0 (GValue, 1);' % name) - else: - self.b(' %s%s;' % (ctype, name)) - - self.b('') - self.b(' dbus_g_proxy_end_call (proxy, call, &error,') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if gtype == 'G_TYPE_VALUE': - self.b(' %s, %s,' % (gtype, name)) - else: - self.b(' %s, &%s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID);') - - if len(out_args) == 0: - self.b(' tp_proxy_pending_call_v0_take_results (user_data, error,' - 'NULL);') - else: - self.b('') - self.b(' if (error != NULL)') - self.b(' {') - self.b(' tp_proxy_pending_call_v0_take_results (user_data, error,') - self.b(' NULL);') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - if gtype == 'G_TYPE_VALUE': - self.b(' g_free (%s);' % name) - - self.b(' return;') - self.b(' }') - self.b('') - self.b(' args = g_value_array_new (%d);' % len(out_args)) - self.b(' g_value_init (&blank, G_TYPE_INT);') - self.b('') - self.b(' for (i = 0; i < %d; i++)' % len(out_args)) - self.b(' g_value_array_append (args, &blank);') - - for i, arg in enumerate(out_args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b('') - self.b(' g_value_unset (args->values + %d);' % i) - self.b(' g_value_init (args->values + %d, %s);' % (i, gtype)) - - if gtype == 'G_TYPE_STRING': - self.b(' g_value_take_string (args->values + %d, %s);' - % (i, name)) - elif marshaller == 'BOXED': - self.b(' g_value_take_boxed (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_set_uchar (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_set_boolean (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_set_int (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_set_uint (args->values + %d, %s);' - % (i, name)) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_set_double (args->values + %d, %s);' - % (i, name)) - else: - assert False, ("Don't know how to put %s in a GValue" - % gtype) - - self.b(' tp_proxy_pending_call_v0_take_results (user_data, ' - 'NULL, args);') - - self.b('}') - - self.b('static void') - self.b('%s (TpProxy *self,' % invoke_callback) - self.b(' GError *error,') - self.b(' GValueArray *args,') - self.b(' GCallback generic_callback,') - self.b(' gpointer user_data,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' %s callback = (%s) generic_callback;' - % (callback_name, callback_name)) - self.b('') - self.b(' if (error != NULL)') - self.b(' {') - self.b(' callback ((%s) self,' % self.proxy_cls) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED' or pointer: - self.b(' NULL,') - elif gtype == 'G_TYPE_DOUBLE': - self.b(' 0.0,') - else: - self.b(' 0,') - - self.b(' error, user_data, weak_object);') - self.b(' g_error_free (error);') - self.b(' return;') - self.b(' }') - - self.b(' callback ((%s) self,' % self.proxy_cls) - - # FIXME: factor out into a function - for i, arg in enumerate(out_args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if marshaller == 'BOXED': - self.b(' g_value_get_boxed (args->values + %d),' % i) - elif gtype == 'G_TYPE_STRING': - self.b(' g_value_get_string (args->values + %d),' % i) - elif gtype == 'G_TYPE_UCHAR': - self.b(' g_value_get_uchar (args->values + %d),' % i) - elif gtype == 'G_TYPE_BOOLEAN': - self.b(' g_value_get_boolean (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT': - self.b(' g_value_get_uint (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT': - self.b(' g_value_get_int (args->values + %d),' % i) - elif gtype == 'G_TYPE_UINT64': - self.b(' g_value_get_uint64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_INT64': - self.b(' g_value_get_int64 (args->values + %d),' % i) - elif gtype == 'G_TYPE_DOUBLE': - self.b(' g_value_get_double (args->values + %d),' % i) - else: - assert False, "Don't know how to get %s from a GValue" % gtype - - self.b(' error, user_data, weak_object);') - self.b('') - - if len(out_args) > 0: - self.b(' g_value_array_free (args);') - else: - self.b(' if (args != NULL)') - self.b(' g_value_array_free (args);') - - self.b('}') - self.b('') - - # Async stub - - # Example: - # TpProxyPendingCall * - # tp_cli_properties_interface_call_get_properties - # (gpointer proxy, - # gint timeout_ms, - # const GArray *in_properties, - # tp_cli_properties_interface_callback_for_get_properties callback, - # gpointer user_data, - # GDestroyNotify *destructor); - - self.h('TpProxyPendingCall *%s_%s_call_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.h(' gint timeout_ms,') - - self.d('/**') - self.d(' * %s_%s_call_%s:' - % (self.prefix_lc, iface_lc, member_lc)) - self.d(' * @proxy: the #TpProxy') - self.d(' * @timeout_ms: the timeout in milliseconds, or -1 to use the') - self.d(' * default') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - docs = xml_escape(get_docstring(elt) or '(Undocumented)') - - if ctype == 'guint ' and tp_type != '': - docs += ' (#%s)' % ('Tp' + tp_type.replace('_', '')) - - self.d(' * @%s: Used to pass an \'in\' argument: %s' - % (name, docs)) - - self.d(' * @callback: called when the method call succeeds or fails;') - self.d(' * may be %NULL to make a "fire and forget" call with no ') - self.d(' * reply tracking') - self.d(' * @user_data: user-supplied data passed to the callback;') - self.d(' * must be %NULL if @callback is %NULL') - self.d(' * @destroy: called with the user_data as argument, after the') - self.d(' * call has succeeded, failed or been cancelled;') - self.d(' * must be %NULL if @callback is %NULL') - self.d(' * @weak_object: If not %NULL, a #GObject which will be ') - self.d(' * weakly referenced; if it is destroyed, this call ') - self.d(' * will automatically be cancelled. Must be %NULL if ') - self.d(' * @callback is %NULL') - self.d(' *') - self.d(' * Start a %s method call.' % member) - self.d(' *') - self.d(' * %s' % xml_escape(get_docstring(method) or '(Undocumented)')) - self.d(' *') - self.d(' * Returns: a #TpProxyPendingCall representing the call in') - self.d(' * progress. It is borrowed from the object, and will become') - self.d(' * invalid when the callback is called, the call is') - self.d(' * cancelled or the #TpProxy becomes invalid.') - - deprecated = method.getElementsByTagName('tp:deprecated') - if deprecated: - d = deprecated[0] - self.d(' *') - self.d(' * Deprecated: %s' % xml_escape(get_deprecated(d))) - - self.d(' */') - self.d('') - - self.b('TpProxyPendingCall *\n%s_%s_call_%s (%sproxy,' - % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg)) - self.b(' gint timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - self.b(' %s%s%s,' % (const, ctype, name)) - - self.h(' %s callback,' % callback_name) - self.h(' gpointer user_data,') - self.h(' GDestroyNotify destroy,') - self.h(' GObject *weak_object);') - self.h('') - - self.b(' %s callback,' % callback_name) - self.b(' gpointer user_data,') - self.b(' GDestroyNotify destroy,') - self.b(' GObject *weak_object)') - self.b('{') - self.b(' GError *error = NULL;') - self.b(' GQuark interface = %s;' % self.get_iface_quark()) - self.b(' DBusGProxy *iface;') - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), NULL);' - % self.proxy_assert) - self.b(' g_return_val_if_fail (callback != NULL || ' - 'user_data == NULL, NULL);') - self.b(' g_return_val_if_fail (callback != NULL || ' - 'destroy == NULL, NULL);') - self.b(' g_return_val_if_fail (callback != NULL || ' - 'weak_object == NULL, NULL);') - self.b('') - self.b(' G_GNUC_BEGIN_IGNORE_DEPRECATIONS') - self.b(' iface = tp_proxy_borrow_interface_by_id (') - self.b(' (TpProxy *) proxy,') - self.b(' interface, &error);') - self.b(' G_GNUC_END_IGNORE_DEPRECATIONS') - self.b('') - self.b(' if (iface == NULL)') - self.b(' {') - self.b(' if (callback != NULL)') - self.b(' callback (proxy,') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - if pointer: - self.b(' NULL,') - else: - self.b(' 0,') - - self.b(' error, user_data, weak_object);') - self.b('') - self.b(' if (destroy != NULL)') - self.b(' destroy (user_data);') - self.b('') - self.b(' g_error_free (error);') - self.b(' return NULL;') - self.b(' }') - self.b('') - self.b(' if (callback == NULL)') - self.b(' {') - self.b(' dbus_g_proxy_call_no_reply (iface, "%s",' % member) - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID);') - self.b(' return NULL;') - self.b(' }') - self.b(' else') - self.b(' {') - self.b(' TpProxyPendingCall *data;') - self.b('') - self.b(' data = tp_proxy_pending_call_v0_new ((TpProxy *) proxy,') - self.b(' interface, "%s", iface,' % member) - self.b(' %s,' % invoke_callback) - self.b(' G_CALLBACK (callback), user_data, destroy,') - self.b(' weak_object, FALSE);') - self.b(' tp_proxy_pending_call_v0_take_pending_call (data,') - self.b(' dbus_g_proxy_begin_call_with_timeout (iface,') - self.b(' "%s",' % member) - self.b(' %s,' % collect_callback) - self.b(' data,') - self.b(' tp_proxy_pending_call_v0_completed,') - self.b(' timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID));') - self.b('') - self.b(' return data;') - self.b(' }') - self.b('}') - self.b('') - - self.do_method_reentrant(method, iface_lc, member, member_lc, - in_args, out_args, collect_callback) - - # leave a gap for the end of the method - self.d('') - self.b('') - self.h('') - - def do_method_reentrant(self, method, iface_lc, member, member_lc, in_args, - out_args, collect_callback): - # Reentrant blocking calls - # Example: - # gboolean tp_cli_properties_interface_run_get_properties - # (gpointer proxy, - # gint timeout_ms, - # const GArray *in_properties, - # GPtrArray **out0, - # GError **error, - # GMainLoop **loop); - - run_method_name = '%s_%s_run_%s' % (self.prefix_lc, iface_lc, member_lc) - if run_method_name not in self.reentrant_symbols: - return - - self.b('typedef struct {') - self.b(' GMainLoop *loop;') - self.b(' GError **error;') - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' %s*%s;' % (ctype, name)) - - self.b(' unsigned success:1;') - self.b(' unsigned completed:1;') - self.b('} _%s_%s_run_state_%s;' - % (self.prefix_lc, iface_lc, member_lc)) - - reentrant_invoke = '_%s_%s_finish_running_%s' % (self.prefix_lc, - iface_lc, - member_lc) - - self.b('static void') - self.b('%s (TpProxy *self G_GNUC_UNUSED,' % reentrant_invoke) - self.b(' GError *error,') - self.b(' GValueArray *args,') - self.b(' GCallback unused G_GNUC_UNUSED,') - self.b(' gpointer user_data G_GNUC_UNUSED,') - self.b(' GObject *unused2 G_GNUC_UNUSED)') - self.b('{') - self.b(' _%s_%s_run_state_%s *state = user_data;' - % (self.prefix_lc, iface_lc, member_lc)) - self.b('') - self.b(' state->success = (error == NULL);') - self.b(' state->completed = TRUE;') - self.b(' g_main_loop_quit (state->loop);') - self.b('') - self.b(' if (error != NULL)') - self.b(' {') - self.b(' if (state->error != NULL)') - self.b(' *state->error = error;') - self.b(' else') - self.b(' g_error_free (error);') - self.b('') - self.b(' return;') - self.b(' }') - self.b('') - - for i, arg in enumerate(out_args): - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.b(' if (state->%s != NULL)' % name) - if marshaller == 'BOXED': - self.b(' *state->%s = g_value_dup_boxed (' - 'args->values + %d);' % (name, i)) - elif marshaller == 'STRING': - self.b(' *state->%s = g_value_dup_string ' - '(args->values + %d);' % (name, i)) - elif marshaller in ('UCHAR', 'BOOLEAN', 'INT', 'UINT', - 'INT64', 'UINT64', 'DOUBLE'): - self.b(' *state->%s = g_value_get_%s (args->values + %d);' - % (name, marshaller.lower(), i)) - else: - assert False, "Don't know how to copy %s" % gtype - - self.b('') - - if len(out_args) > 0: - self.b(' g_value_array_free (args);') - else: - self.b(' if (args != NULL)') - self.b(' g_value_array_free (args);') - - self.b('}') - self.b('') - - if self.deprecate_reentrant: - self.h('#ifndef %s' % self.deprecate_reentrant) - - self.h('gboolean %s (%sproxy,' - % (run_method_name, self.proxy_arg)) - self.h(' gint timeout_ms,') - - self.d('/**') - self.d(' * %s:' % run_method_name) - self.d(' * @proxy: %s' % self.proxy_doc) - self.d(' * @timeout_ms: Timeout in milliseconds, or -1 for default') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - docs = xml_escape(get_docstring(elt) or '(Undocumented)') - - if ctype == 'guint ' and tp_type != '': - docs += ' (#%s)' % ('Tp' + tp_type.replace('_', '')) - - self.d(' * @%s: Used to pass an \'in\' argument: %s' - % (name, docs)) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.d(' * @%s: Used to return an \'out\' argument if %%TRUE is ' - 'returned: %s' - % (name, xml_escape(get_docstring(elt) or '(Undocumented)'))) - - self.d(' * @error: If not %NULL, used to return errors if %FALSE ') - self.d(' * is returned') - self.d(' * @loop: If not %NULL, set before re-entering ') - self.d(' * the main loop, to point to a #GMainLoop ') - self.d(' * which can be used to cancel this call with ') - self.d(' * g_main_loop_quit(), causing a return of ') - self.d(' * %FALSE with @error set to %TP_DBUS_ERROR_CANCELLED') - self.d(' *') - self.d(' * Call the method %s and run the main loop' % member) - self.d(' * until it returns. Before calling this method, you must') - self.d(' * add a reference to any borrowed objects you need to keep,') - self.d(' * and generally ensure that everything is in a consistent') - self.d(' * state.') - self.d(' *') - self.d(' * %s' % xml_escape(get_docstring(method) or '(Undocumented)')) - self.d(' *') - self.d(' * Returns: TRUE on success, FALSE and sets @error on error') - - deprecated = method.getElementsByTagName('tp:deprecated') - if deprecated: - d = deprecated[0] - self.d(' *') - self.d(' * Deprecated: %s' % xml_escape(get_deprecated(d))) - - self.d(' */') - self.d('') - - self.b('gboolean\n%s (%sproxy,' - % (run_method_name, self.proxy_arg)) - self.b(' gint timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.h(' %s%s%s,' % (const, ctype, name)) - self.b(' %s%s%s,' % (const, ctype, name)) - - for arg in out_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - self.h(' %s*%s,' % (ctype, name)) - self.b(' %s*%s,' % (ctype, name)) - - self.h(' GError **error,') - - if self.deprecate_reentrant: - self.h(' GMainLoop **loop) %s;' % self.deprecation_attribute) - self.h('#endif /* not %s */' % self.deprecate_reentrant) - else: - self.h(' GMainLoop **loop);') - - self.h('') - - self.b(' GError **error,') - self.b(' GMainLoop **loop)') - self.b('{') - self.b(' DBusGProxy *iface;') - self.b(' GQuark interface = %s;' % self.get_iface_quark()) - self.b(' TpProxyPendingCall *pc;') - self.b(' _%s_%s_run_state_%s state = {' - % (self.prefix_lc, iface_lc, member_lc)) - self.b(' NULL /* loop */, error,') - - for arg in out_args: - name, info, tp_type, elt = arg - - self.b(' %s,' % name) - - self.b(' FALSE /* completed */, FALSE /* success */ };') - self.b('') - self.b(' g_return_val_if_fail (%s (proxy), FALSE);' - % self.proxy_assert) - self.b('') - self.b(' G_GNUC_BEGIN_IGNORE_DEPRECATIONS') - self.b(' iface = tp_proxy_borrow_interface_by_id') - self.b(' ((TpProxy *) proxy, interface, error);') - self.b(' G_GNUC_END_IGNORE_DEPRECATIONS') - self.b('') - self.b(' if (iface == NULL)') - self.b(' return FALSE;') - self.b('') - self.b(' state.loop = g_main_loop_new (NULL, FALSE);') - self.b('') - self.b(' pc = tp_proxy_pending_call_v0_new ((TpProxy *) proxy,') - self.b(' interface, "%s", iface,' % member) - self.b(' %s,' % reentrant_invoke) - self.b(' NULL, &state, NULL, NULL, TRUE);') - self.b('') - self.b(' if (loop != NULL)') - self.b(' *loop = state.loop;') - self.b('') - self.b(' tp_proxy_pending_call_v0_take_pending_call (pc,') - self.b(' dbus_g_proxy_begin_call_with_timeout (iface,') - self.b(' "%s",' % member) - self.b(' %s,' % collect_callback) - self.b(' pc,') - self.b(' tp_proxy_pending_call_v0_completed,') - self.b(' timeout_ms,') - - for arg in in_args: - name, info, tp_type, elt = arg - ctype, gtype, marshaller, pointer = info - - const = pointer and 'const ' or '' - - self.b(' %s, %s,' % (gtype, name)) - - self.b(' G_TYPE_INVALID));') - self.b('') - self.b(' if (!state.completed)') - self.b(' g_main_loop_run (state.loop);') - self.b('') - self.b(' if (!state.completed)') - self.b(' tp_proxy_pending_call_cancel (pc);') - self.b('') - self.b(' if (loop != NULL)') - self.b(' *loop = NULL;') - self.b('') - self.b(' g_main_loop_unref (state.loop);') - self.b('') - self.b(' return state.success;') - self.b('}') - self.b('') - - def do_signal_add(self, signal): - marshaller_items = [] - gtypes = [] - - for i in signal.getElementsByTagName('arg'): - name = i.getAttribute('name') - type = i.getAttribute('type') - info = type_to_gtype(type) - # type, GType, STRING, is a pointer - gtypes.append(info[1]) - - self.b(' dbus_g_proxy_add_signal (proxy, "%s",' - % signal.getAttribute('name')) - for gtype in gtypes: - self.b(' %s,' % gtype) - self.b(' G_TYPE_INVALID);') - - def do_interface(self, node): - ifaces = node.getElementsByTagName('interface') - assert len(ifaces) == 1 - iface = ifaces[0] - name = node.getAttribute('name').replace('/', '') - - self.iface = name - self.iface_lc = name.lower() - self.iface_uc = name.upper() - self.iface_mc = name.replace('_', '') - self.iface_dbus = iface.getAttribute('name') - - signals = node.getElementsByTagName('signal') - methods = node.getElementsByTagName('method') - - if signals: - self.b('static inline void') - self.b('%s_add_signals_for_%s (DBusGProxy *proxy)' - % (self.prefix_lc, name.lower())) - self.b('{') - - if self.tp_proxy_api >= (0, 7, 6): - self.b(' if (!tp_proxy_dbus_g_proxy_claim_for_signal_adding ' - '(proxy))') - self.b(' return;') - - for signal in signals: - self.do_signal_add(signal) - - self.b('}') - self.b('') - self.b('') - - for signal in signals: - self.do_signal(name, signal) - - for method in methods: - self.do_method(name, method) - - self.iface_dbus = None - - def __call__(self): - - if self.guard is not None: - self.h('#ifndef %s' % self.guard) - self.h('#define %s' % self.guard) - self.h('') - - self.h('G_BEGIN_DECLS') - self.h('') - - self.b('/* We don\'t want gtkdoc scanning this file, it\'ll get') - self.b(' * confused by seeing function definitions, so mark it as: */') - self.b('/**/') - self.b('') - - nodes = self.dom.getElementsByTagName('node') - nodes.sort(cmp_by_name) - - for node in nodes: - self.do_interface(node) - - if self.group is not None: - - self.b('/*') - self.b(' * %s_%s_add_signals:' % (self.prefix_lc, self.group)) - self.b(' * @self: the #TpProxy') - self.b(' * @quark: a quark whose string value is the interface') - self.b(' * name whose signals should be added') - self.b(' * @proxy: the D-Bus proxy to which to add the signals') - self.b(' * @unused: not used for anything') - self.b(' *') - self.b(' * Tell dbus-glib that @proxy has the signatures of all') - self.b(' * signals on the given interface, if it\'s one we') - self.b(' * support.') - self.b(' *') - self.b(' * This function should be used as a signal handler for') - self.b(' * #TpProxy::interface-added.') - self.b(' */') - self.b('static void') - self.b('%s_%s_add_signals (TpProxy *self G_GNUC_UNUSED,' - % (self.prefix_lc, self.group)) - self.b(' guint quark,') - self.b(' DBusGProxy *proxy,') - self.b(' gpointer unused G_GNUC_UNUSED)') - - self.b('{') - - for node in nodes: - iface = node.getElementsByTagName('interface')[0] - self.iface_dbus = iface.getAttribute('name') - signals = node.getElementsByTagName('signal') - if not signals: - continue - name = node.getAttribute('name').replace('/', '').lower() - self.iface_uc = name.upper() - self.b(' if (quark == %s)' % self.get_iface_quark()) - self.b(' %s_add_signals_for_%s (proxy);' - % (self.prefix_lc, name)) - - self.b('}') - self.b('') - - self.h('G_END_DECLS') - self.h('') - - if self.guard is not None: - self.h('#endif /* defined (%s) */' % self.guard) - self.h('') - - file_set_contents(self.basename + '.h', '\n'.join(self.__header)) - file_set_contents(self.basename + '-body.h', '\n'.join(self.__body)) - file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) - -def types_to_gtypes(types): - return [type_to_gtype(t)[1] for t in types] - - -if __name__ == '__main__': - options, argv = gnu_getopt(sys.argv[1:], '', - ['group=', 'subclass=', 'subclass-assert=', - 'iface-quark-prefix=', 'tp-proxy-api=', - 'generate-reentrant=', 'deprecate-reentrant=', - 'deprecation-attribute=', 'guard=']) - - opts = {} - - for option, value in options: - opts[option] = value - - dom = xml.dom.minidom.parse(argv[0]) - - Generator(dom, argv[1], argv[2], opts)() diff --git a/tools/glib-client-marshaller-gen.py b/tools/glib-client-marshaller-gen.py deleted file mode 100644 index cb27d63..0000000 --- a/tools/glib-client-marshaller-gen.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python - -import sys -import xml.dom.minidom -from string import ascii_letters, digits - - -from libglibcodegen import signal_to_marshal_name - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -class Generator(object): - - def __init__(self, dom, prefix): - self.dom = dom - self.marshallers = {} - self.prefix = prefix - - def do_signal(self, signal): - marshaller = signal_to_marshal_name(signal, self.prefix) - - assert '__' in marshaller - rhs = marshaller.split('__', 1)[1].split('_') - - self.marshallers[marshaller] = rhs - - def __call__(self): - signals = self.dom.getElementsByTagName('signal') - - for signal in signals: - self.do_signal(signal) - - print 'void' - print '%s_register_dbus_glib_marshallers (void)' % self.prefix - print '{' - - all = self.marshallers.keys() - all.sort() - for marshaller in all: - rhs = self.marshallers[marshaller] - - print ' dbus_g_object_register_marshaller (' - print ' g_cclosure_marshal_generic,' - print ' G_TYPE_NONE, /* return */' - for type in rhs: - print ' G_TYPE_%s,' % type.replace('VOID', 'NONE') - print ' G_TYPE_INVALID);' - - print '}' - - -def types_to_gtypes(types): - return [type_to_gtype(t)[1] for t in types] - -if __name__ == '__main__': - argv = sys.argv[1:] - dom = xml.dom.minidom.parse(argv[0]) - - Generator(dom, argv[1])() diff --git a/tools/glib-ginterface-gen.py b/tools/glib-ginterface-gen.py deleted file mode 100644 index 6fec0d3..0000000 --- a/tools/glib-ginterface-gen.py +++ /dev/null @@ -1,838 +0,0 @@ -#!/usr/bin/python - -# glib-ginterface-gen.py: service-side interface generator -# -# Generate dbus-glib 0.x service GInterfaces from the Telepathy specification. -# The master copy of this program is in the telepathy-glib repository - -# please make any changes there. -# -# Copyright (C) 2006, 2007 Collabora Limited -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import os.path -import xml.dom.minidom - -from libtpcodegen import file_set_contents -from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \ - NS_TP, dbus_gutils_wincaps_to_uscore - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -def get_emits_changed(node): - try: - return [ - annotation.getAttribute('value') - for annotation in node.getElementsByTagName('annotation') - if annotation.getAttribute('name') == 'org.freedesktop.DBus.Property.EmitsChangedSignal' - ][0] - except IndexError: - return None - -class Generator(object): - - def __init__(self, dom, prefix, basename, signal_marshal_prefix, - headers, end_headers, not_implemented_func, - allow_havoc): - self.dom = dom - self.__header = [] - self.__body = [] - self.__docs = [] - - assert prefix.endswith('_') - assert not signal_marshal_prefix.endswith('_') - - # The main_prefix, sub_prefix thing is to get: - # FOO_ -> (FOO_, _) - # FOO_SVC_ -> (FOO_, _SVC_) - # but - # FOO_BAR/ -> (FOO_BAR_, _) - # FOO_BAR/SVC_ -> (FOO_BAR_, _SVC_) - - if '/' in prefix: - main_prefix, sub_prefix = prefix.upper().split('/', 1) - prefix = prefix.replace('/', '_') - else: - main_prefix, sub_prefix = prefix.upper().split('_', 1) - - self.MAIN_PREFIX_ = main_prefix + '_' - self._SUB_PREFIX_ = '_' + sub_prefix - - self.Prefix_ = prefix - self.Prefix = prefix.replace('_', '') - self.prefix_ = prefix.lower() - self.PREFIX_ = prefix.upper() - - self.basename = basename - self.signal_marshal_prefix = signal_marshal_prefix - self.headers = headers - self.end_headers = end_headers - self.not_implemented_func = not_implemented_func - self.allow_havoc = allow_havoc - - def h(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__header.append(s) - - def b(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__body.append(s) - - def d(self, s): - if isinstance(s, unicode): - s = s.encode('utf-8') - self.__docs.append(s) - - def do_node(self, node): - node_name = node.getAttribute('name').replace('/', '') - node_name_mixed = self.node_name_mixed = node_name.replace('_', '') - node_name_lc = self.node_name_lc = node_name.lower() - node_name_uc = self.node_name_uc = node_name.upper() - - interfaces = node.getElementsByTagName('interface') - assert len(interfaces) == 1, interfaces - interface = interfaces[0] - self.iface_name = interface.getAttribute('name') - - tmp = interface.getAttribute('tp:implement-service') - if tmp == "no": - return - - tmp = interface.getAttribute('tp:causes-havoc') - if tmp and not self.allow_havoc: - raise AssertionError('%s is %s' % (self.iface_name, tmp)) - - iface_emits_changed = get_emits_changed(interface) - - self.b('static const DBusGObjectInfo _%s%s_object_info;' - % (self.prefix_, node_name_lc)) - self.b('') - - methods = interface.getElementsByTagName('method') - signals = interface.getElementsByTagName('signal') - properties = interface.getElementsByTagName('property') - # Don't put properties in dbus-glib glue - glue_properties = [] - - self.b('struct _%s%sClass {' % (self.Prefix, node_name_mixed)) - self.b(' GTypeInterface parent_class;') - for method in methods: - self.b(' %s %s;' % self.get_method_impl_names(method)) - self.b('};') - self.b('') - - if signals: - self.b('enum {') - for signal in signals: - self.b(' %s,' % self.get_signal_const_entry(signal)) - self.b(' N_%s_SIGNALS' % node_name_uc) - self.b('};') - self.b('static guint %s_signals[N_%s_SIGNALS] = {0};' - % (node_name_lc, node_name_uc)) - self.b('') - - self.b('static void %s%s_base_init (gpointer klass);' - % (self.prefix_, node_name_lc)) - self.b('') - - self.b('GType') - self.b('%s%s_get_type (void)' - % (self.prefix_, node_name_lc)) - self.b('{') - self.b(' static GType type = 0;') - self.b('') - self.b(' if (G_UNLIKELY (type == 0))') - self.b(' {') - self.b(' static const GTypeInfo info = {') - self.b(' sizeof (%s%sClass),' % (self.Prefix, node_name_mixed)) - self.b(' %s%s_base_init, /* base_init */' - % (self.prefix_, node_name_lc)) - self.b(' NULL, /* base_finalize */') - self.b(' NULL, /* class_init */') - self.b(' NULL, /* class_finalize */') - self.b(' NULL, /* class_data */') - self.b(' 0,') - self.b(' 0, /* n_preallocs */') - self.b(' NULL /* instance_init */') - self.b(' };') - self.b('') - self.b(' type = g_type_register_static (G_TYPE_INTERFACE,') - self.b(' "%s%s", &info, 0);' % (self.Prefix, node_name_mixed)) - self.b(' }') - self.b('') - self.b(' return type;') - self.b('}') - self.b('') - - self.d('/**') - self.d(' * %s%s:' % (self.Prefix, node_name_mixed)) - self.d(' *') - self.d(' * Dummy typedef representing any implementation of this ' - 'interface.') - self.d(' */') - - self.h('typedef struct _%s%s %s%s;' - % (self.Prefix, node_name_mixed, self.Prefix, node_name_mixed)) - self.h('') - - self.d('/**') - self.d(' * %s%sClass:' % (self.Prefix, node_name_mixed)) - self.d(' *') - self.d(' * The class of %s%s.' % (self.Prefix, node_name_mixed)) - - if methods: - self.d(' *') - self.d(' * In a full implementation of this interface (i.e. all') - self.d(' * methods implemented), the interface initialization') - self.d(' * function used in G_IMPLEMENT_INTERFACE() would') - self.d(' * typically look like this:') - self.d(' *') - self.d(' * ') - self.d(' * static void') - self.d(' * implement_%s (gpointer klass,' % self.node_name_lc) - self.d(' * gpointer unused G_GNUC_UNUSED)') - self.d(' * {') - self.d(' * #define IMPLEMENT(x) %s%s_implement_##x (\\' - % (self.prefix_, self.node_name_lc)) - self.d(' * klass, my_object_##x)') - - for method in methods: - class_member_name = method.getAttribute('tp:name-for-bindings') - class_member_name = class_member_name.lower() - self.d(' * IMPLEMENT (%s);' % class_member_name) - - self.d(' * #undef IMPLEMENT') - self.d(' * }') - self.d(' * ') - else: - self.d(' * This interface has no D-Bus methods, so an') - self.d(' * implementation can typically pass %NULL to') - self.d(' * G_IMPLEMENT_INTERFACE() as the interface') - self.d(' * initialization function.') - - self.d(' */') - self.d('') - - self.h('typedef struct _%s%sClass %s%sClass;' - % (self.Prefix, node_name_mixed, self.Prefix, node_name_mixed)) - self.h('') - self.h('GType %s%s_get_type (void);' - % (self.prefix_, node_name_lc)) - - gtype = self.current_gtype = \ - self.MAIN_PREFIX_ + 'TYPE' + self._SUB_PREFIX_ + node_name_uc - classname = self.Prefix + node_name_mixed - - self.h('#define %s \\\n (%s%s_get_type ())' - % (gtype, self.prefix_, node_name_lc)) - self.h('#define %s%s(obj) \\\n' - ' (G_TYPE_CHECK_INSTANCE_CAST((obj), %s, %s))' - % (self.PREFIX_, node_name_uc, gtype, classname)) - self.h('#define %sIS%s%s(obj) \\\n' - ' (G_TYPE_CHECK_INSTANCE_TYPE((obj), %s))' - % (self.MAIN_PREFIX_, self._SUB_PREFIX_, node_name_uc, gtype)) - self.h('#define %s%s_GET_CLASS(obj) \\\n' - ' (G_TYPE_INSTANCE_GET_INTERFACE((obj), %s, %sClass))' - % (self.PREFIX_, node_name_uc, gtype, classname)) - self.h('') - self.h('') - - base_init_code = [] - - for method in methods: - self.do_method(method) - - for signal in signals: - base_init_code.extend(self.do_signal(signal)) - - self.b('static inline void') - self.b('%s%s_base_init_once (gpointer klass G_GNUC_UNUSED)' - % (self.prefix_, node_name_lc)) - self.b('{') - - if properties: - self.b(' static TpDBusPropertiesMixinPropInfo properties[%d] = {' - % (len(properties) + 1)) - - for m in properties: - access = m.getAttribute('access') - assert access in ('read', 'write', 'readwrite') - - if access == 'read': - flags = 'TP_DBUS_PROPERTIES_MIXIN_FLAG_READ' - elif access == 'write': - flags = 'TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE' - else: - flags = ('TP_DBUS_PROPERTIES_MIXIN_FLAG_READ | ' - 'TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE') - - prop_emits_changed = get_emits_changed(m) - - if prop_emits_changed is None: - prop_emits_changed = iface_emits_changed - - if prop_emits_changed == 'true': - flags += ' | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_CHANGED' - elif prop_emits_changed == 'invalidates': - flags += ' | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_INVALIDATED' - - self.b(' { 0, %s, "%s", 0, NULL, NULL }, /* %s */' - % (flags, m.getAttribute('type'), m.getAttribute('name'))) - - self.b(' { 0, 0, NULL, 0, NULL, NULL }') - self.b(' };') - self.b(' static TpDBusPropertiesMixinIfaceInfo interface =') - self.b(' { 0, properties, NULL, NULL };') - self.b('') - - - self.b(' dbus_g_object_type_install_info (%s%s_get_type (),' - % (self.prefix_, node_name_lc)) - self.b(' &_%s%s_object_info);' - % (self.prefix_, node_name_lc)) - self.b('') - - if properties: - self.b(' interface.dbus_interface = g_quark_from_static_string ' - '("%s");' % self.iface_name) - - for i, m in enumerate(properties): - self.b(' properties[%d].name = g_quark_from_static_string ("%s");' - % (i, m.getAttribute('name'))) - self.b(' properties[%d].type = %s;' - % (i, type_to_gtype(m.getAttribute('type'))[1])) - - self.b(' tp_svc_interface_set_dbus_properties_info (%s, &interface);' - % self.current_gtype) - - self.b('') - - for s in base_init_code: - self.b(s) - self.b('}') - - self.b('static void') - self.b('%s%s_base_init (gpointer klass)' - % (self.prefix_, node_name_lc)) - self.b('{') - self.b(' static gboolean initialized = FALSE;') - self.b('') - self.b(' if (!initialized)') - self.b(' {') - self.b(' initialized = TRUE;') - self.b(' %s%s_base_init_once (klass);' - % (self.prefix_, node_name_lc)) - self.b(' }') - # insert anything we need to do per implementation here - self.b('}') - - self.h('') - - self.b('static const DBusGMethodInfo _%s%s_methods[] = {' - % (self.prefix_, node_name_lc)) - - method_blob, offsets = self.get_method_glue(methods) - - for method, offset in zip(methods, offsets): - self.do_method_glue(method, offset) - - if len(methods) == 0: - # empty arrays are a gcc extension, so put in a dummy member - self.b(" { NULL, NULL, 0 }") - - self.b('};') - self.b('') - - self.b('static const DBusGObjectInfo _%s%s_object_info = {' - % (self.prefix_, node_name_lc)) - self.b(' 0,') # version - self.b(' _%s%s_methods,' % (self.prefix_, node_name_lc)) - self.b(' %d,' % len(methods)) - self.b('"' + method_blob.replace('\0', '\\0') + '",') - self.b('"' + self.get_signal_glue(signals).replace('\0', '\\0') + '",') - self.b('"' + - self.get_property_glue(glue_properties).replace('\0', '\\0') + - '",') - self.b('};') - self.b('') - - self.node_name_mixed = None - self.node_name_lc = None - self.node_name_uc = None - - def get_method_glue(self, methods): - info = [] - offsets = [] - - for method in methods: - offsets.append(len(''.join(info))) - - info.append(self.iface_name + '\0') - info.append(method.getAttribute('name') + '\0') - - info.append('A\0') # async - - counter = 0 - for arg in method.getElementsByTagName('arg'): - out = arg.getAttribute('direction') == 'out' - - name = arg.getAttribute('name') - if not name: - assert out - name = 'arg%u' % counter - counter += 1 - - info.append(name + '\0') - - if out: - info.append('O\0') - else: - info.append('I\0') - - if out: - info.append('F\0') # not const - info.append('N\0') # not error or return - info.append(arg.getAttribute('type') + '\0') - - info.append('\0') - - return ''.join(info) + '\0', offsets - - def do_method_glue(self, method, offset): - lc_name = method.getAttribute('tp:name-for-bindings') - if method.getAttribute('name') != lc_name.replace('_', ''): - raise AssertionError('Method %s tp:name-for-bindings (%s) does ' - 'not match' % (method.getAttribute('name'), lc_name)) - lc_name = lc_name.lower() - - marshaller = 'g_cclosure_marshal_generic' - wrapper = self.prefix_ + self.node_name_lc + '_' + lc_name - - self.b(" { (GCallback) %s, %s, %d }," % (wrapper, marshaller, offset)) - - def get_signal_glue(self, signals): - info = [] - - for signal in signals: - info.append(self.iface_name) - info.append(signal.getAttribute('name')) - - return '\0'.join(info) + '\0\0' - - # the implementation can be the same - get_property_glue = get_signal_glue - - def get_method_impl_names(self, method): - dbus_method_name = method.getAttribute('name') - - class_member_name = method.getAttribute('tp:name-for-bindings') - if dbus_method_name != class_member_name.replace('_', ''): - raise AssertionError('Method %s tp:name-for-bindings (%s) does ' - 'not match' % (dbus_method_name, class_member_name)) - class_member_name = class_member_name.lower() - - stub_name = (self.prefix_ + self.node_name_lc + '_' + - class_member_name) - return (stub_name + '_impl', class_member_name + '_cb') - - def do_method(self, method): - assert self.node_name_mixed is not None - - in_class = [] - - # Examples refer to Thing.DoStuff (su) -> ii - - # DoStuff - dbus_method_name = method.getAttribute('name') - # do_stuff - class_member_name = method.getAttribute('tp:name-for-bindings') - if dbus_method_name != class_member_name.replace('_', ''): - raise AssertionError('Method %s tp:name-for-bindings (%s) does ' - 'not match' % (dbus_method_name, class_member_name)) - class_member_name = class_member_name.lower() - - # void tp_svc_thing_do_stuff (TpSvcThing *, const char *, guint, - # DBusGMethodInvocation *); - stub_name = (self.prefix_ + self.node_name_lc + '_' + - class_member_name) - # typedef void (*tp_svc_thing_do_stuff_impl) (TpSvcThing *, - # const char *, guint, DBusGMethodInvocation); - impl_name = stub_name + '_impl' - # void tp_svc_thing_return_from_do_stuff (DBusGMethodInvocation *, - # gint, gint); - ret_name = (self.prefix_ + self.node_name_lc + '_return_from_' + - class_member_name) - - # Gather arguments - in_args = [] - out_args = [] - for i in method.getElementsByTagName('arg'): - name = i.getAttribute('name') - direction = i.getAttribute('direction') or 'in' - dtype = i.getAttribute('type') - - assert direction in ('in', 'out') - - if name: - name = direction + '_' + name - elif direction == 'in': - name = direction + str(len(in_args)) - else: - name = direction + str(len(out_args)) - - ctype, gtype, marshaller, pointer = type_to_gtype(dtype) - - if pointer: - ctype = 'const ' + ctype - - struct = (ctype, name) - - if direction == 'in': - in_args.append(struct) - else: - out_args.append(struct) - - # Implementation type declaration (in header, docs separated) - self.d('/**') - self.d(' * %s:' % impl_name) - self.d(' * @self: The object implementing this interface') - for (ctype, name) in in_args: - self.d(' * @%s: %s (FIXME, generate documentation)' - % (name, ctype)) - self.d(' * @context: Used to return values or throw an error') - self.d(' *') - self.d(' * The signature of an implementation of the D-Bus method') - self.d(' * %s on interface %s.' % (dbus_method_name, self.iface_name)) - self.d(' */') - - self.h('typedef void (*%s) (%s%s *self,' - % (impl_name, self.Prefix, self.node_name_mixed)) - for (ctype, name) in in_args: - self.h(' %s%s,' % (ctype, name)) - self.h(' DBusGMethodInvocation *context);') - - # Class member (in class definition) - in_class.append(' %s %s;' % (impl_name, class_member_name)) - - # Stub definition (in body only - it's static) - self.b('static void') - self.b('%s (%s%s *self,' - % (stub_name, self.Prefix, self.node_name_mixed)) - for (ctype, name) in in_args: - self.b(' %s%s,' % (ctype, name)) - self.b(' DBusGMethodInvocation *context)') - self.b('{') - self.b(' %s impl = (%s%s_GET_CLASS (self)->%s_cb);' - % (impl_name, self.PREFIX_, self.node_name_uc, class_member_name)) - self.b('') - self.b(' if (impl != NULL)') - tmp = ['self'] + [name for (ctype, name) in in_args] + ['context'] - self.b(' {') - self.b(' (impl) (%s);' % ',\n '.join(tmp)) - self.b(' }') - self.b(' else') - self.b(' {') - if self.not_implemented_func: - self.b(' %s (context);' % self.not_implemented_func) - else: - self.b(' GError e = { DBUS_GERROR, ') - self.b(' DBUS_GERROR_UNKNOWN_METHOD,') - self.b(' "Method not implemented" };') - self.b('') - self.b(' dbus_g_method_return_error (context, &e);') - self.b(' }') - self.b('}') - self.b('') - - # Implementation registration (in both header and body) - self.h('void %s%s_implement_%s (%s%sClass *klass, %s impl);' - % (self.prefix_, self.node_name_lc, class_member_name, - self.Prefix, self.node_name_mixed, impl_name)) - - self.d('/**') - self.d(' * %s%s_implement_%s:' - % (self.prefix_, self.node_name_lc, class_member_name)) - self.d(' * @klass: A class whose instances implement this interface') - self.d(' * @impl: A callback used to implement the %s D-Bus method' - % dbus_method_name) - self.d(' *') - self.d(' * Register an implementation for the %s method in the vtable' - % dbus_method_name) - self.d(' * of an implementation of this interface. To be called from') - self.d(' * the interface init function.') - self.d(' */') - - self.b('void') - self.b('%s%s_implement_%s (%s%sClass *klass, %s impl)' - % (self.prefix_, self.node_name_lc, class_member_name, - self.Prefix, self.node_name_mixed, impl_name)) - self.b('{') - self.b(' klass->%s_cb = impl;' % class_member_name) - self.b('}') - self.b('') - - # Return convenience function (static inline, in header) - self.d('/**') - self.d(' * %s:' % ret_name) - self.d(' * @context: The D-Bus method invocation context') - for (ctype, name) in out_args: - self.d(' * @%s: %s (FIXME, generate documentation)' - % (name, ctype)) - self.d(' *') - self.d(' * Return successfully by calling dbus_g_method_return().') - self.d(' * This inline function exists only to provide type-safety.') - self.d(' */') - self.d('') - - tmp = (['DBusGMethodInvocation *context'] + - [ctype + name for (ctype, name) in out_args]) - self.h('static inline') - self.h('/* this comment is to stop gtkdoc realising this is static */') - self.h(('void %s (' % ret_name) + (',\n '.join(tmp)) + ');') - self.h('static inline void') - self.h(('%s (' % ret_name) + (',\n '.join(tmp)) + ')') - self.h('{') - tmp = ['context'] + [name for (ctype, name) in out_args] - self.h(' dbus_g_method_return (' + ',\n '.join(tmp) + ');') - self.h('}') - self.h('') - - return in_class - - def get_signal_const_entry(self, signal): - assert self.node_name_uc is not None - return ('SIGNAL_%s_%s' - % (self.node_name_uc, signal.getAttribute('name'))) - - def do_signal(self, signal): - assert self.node_name_mixed is not None - - in_base_init = [] - - # for signal: Thing::StuffHappened (s, u) - # we want to emit: - # void tp_svc_thing_emit_stuff_happened (gpointer instance, - # const char *arg0, guint arg1); - - dbus_name = signal.getAttribute('name') - - ugly_name = signal.getAttribute('tp:name-for-bindings') - if dbus_name != ugly_name.replace('_', ''): - raise AssertionError('Signal %s tp:name-for-bindings (%s) does ' - 'not match' % (dbus_name, ugly_name)) - - stub_name = (self.prefix_ + self.node_name_lc + '_emit_' + - ugly_name.lower()) - - const_name = self.get_signal_const_entry(signal) - - # Gather arguments - args = [] - for i in signal.getElementsByTagName('arg'): - name = i.getAttribute('name') - dtype = i.getAttribute('type') - tp_type = i.getAttribute('tp:type') - - if name: - name = 'arg_' + name - else: - name = 'arg' + str(len(args)) - - ctype, gtype, marshaller, pointer = type_to_gtype(dtype) - - if pointer: - ctype = 'const ' + ctype - - struct = (ctype, name, gtype) - args.append(struct) - - tmp = (['gpointer instance'] + - [ctype + name for (ctype, name, gtype) in args]) - - self.h(('void %s (' % stub_name) + (',\n '.join(tmp)) + ');') - - # FIXME: emit docs - - self.d('/**') - self.d(' * %s:' % stub_name) - self.d(' * @instance: The object implementing this interface') - for (ctype, name, gtype) in args: - self.d(' * @%s: %s (FIXME, generate documentation)' - % (name, ctype)) - self.d(' *') - self.d(' * Type-safe wrapper around g_signal_emit to emit the') - self.d(' * %s signal on interface %s.' - % (dbus_name, self.iface_name)) - self.d(' */') - - self.b('void') - self.b(('%s (' % stub_name) + (',\n '.join(tmp)) + ')') - self.b('{') - self.b(' g_assert (instance != NULL);') - self.b(' g_assert (G_TYPE_CHECK_INSTANCE_TYPE (instance, %s));' - % (self.current_gtype)) - tmp = (['instance', '%s_signals[%s]' % (self.node_name_lc, const_name), - '0'] + [name for (ctype, name, gtype) in args]) - self.b(' g_signal_emit (' + ',\n '.join(tmp) + ');') - self.b('}') - self.b('') - - signal_name = dbus_gutils_wincaps_to_uscore(dbus_name).replace('_', - '-') - - self.d('/**') - self.d(' * %s%s::%s:' - % (self.Prefix, self.node_name_mixed, signal_name)) - self.d(' * @self: an object') - for (ctype, name, gtype) in args: - self.d(' * @%s: %s (FIXME, generate documentation)' - % (name, ctype)) - self.d(' *') - self.d(' * The %s D-Bus signal is emitted whenever ' - 'this GObject signal is.' % dbus_name) - self.d(' */') - self.d('') - - in_base_init.append(' %s_signals[%s] =' - % (self.node_name_lc, const_name)) - in_base_init.append(' g_signal_new ("%s",' % signal_name) - in_base_init.append(' G_OBJECT_CLASS_TYPE (klass),') - in_base_init.append(' G_SIGNAL_RUN_LAST|G_SIGNAL_DETAILED,') - in_base_init.append(' 0,') - in_base_init.append(' NULL, NULL,') - in_base_init.append(' g_cclosure_marshal_generic,') - in_base_init.append(' G_TYPE_NONE,') - tmp = ['%d' % len(args)] + [gtype for (ctype, name, gtype) in args] - in_base_init.append(' %s);' % ',\n '.join(tmp)) - in_base_init.append('') - - return in_base_init - - def have_properties(self, nodes): - for node in nodes: - interface = node.getElementsByTagName('interface')[0] - if interface.getElementsByTagName('property'): - return True - return False - - def __call__(self): - nodes = self.dom.getElementsByTagName('node') - nodes.sort(cmp_by_name) - - self.h('#include ') - self.h('#include ') - - for header in self.headers: - self.h('#include %s' % header) - self.h('') - - self.h('') - self.h('G_BEGIN_DECLS') - self.h('') - - self.b('#include "%s.h"' % self.basename) - self.b('') - - for node in nodes: - self.do_node(node) - - self.h('') - self.h('G_END_DECLS') - - self.b('') - for header in self.end_headers: - self.b('#include %s' % header) - - self.h('') - self.b('') - file_set_contents(self.basename + '.h', '\n'.join(self.__header)) - file_set_contents(self.basename + '.c', '\n'.join(self.__body)) - file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) - -def cmdline_error(): - print """\ -usage: - gen-ginterface [OPTIONS] xmlfile Prefix_ -options: - --include='' (may be repeated) - --include='"header.h"' (ditto) - --include-end='"header.h"' (ditto) - Include extra headers in the generated .c file - --signal-marshal-prefix='prefix' - Use the given prefix on generated signal marshallers (default is - prefix.lower()). - --filename='BASENAME' - Set the basename for the output files (default is prefix.lower() - + 'ginterfaces') - --not-implemented-func='symbol' - Set action when methods not implemented in the interface vtable are - called. symbol must have signature - void symbol (DBusGMethodInvocation *context) - and return some sort of "not implemented" error via - dbus_g_method_return_error (context, ...) -""" - sys.exit(1) - - -if __name__ == '__main__': - from getopt import gnu_getopt - - options, argv = gnu_getopt(sys.argv[1:], '', - ['filename=', 'signal-marshal-prefix=', - 'include=', 'include-end=', - 'allow-unstable', - 'not-implemented-func=']) - - try: - prefix = argv[1] - except IndexError: - cmdline_error() - - basename = prefix.lower() + 'ginterfaces' - signal_marshal_prefix = prefix.lower().rstrip('_') - headers = [] - end_headers = [] - not_implemented_func = '' - allow_havoc = False - - for option, value in options: - if option == '--filename': - basename = value - elif option == '--signal-marshal-prefix': - signal_marshal_prefix = value - elif option == '--include': - if value[0] not in '<"': - value = '"%s"' % value - headers.append(value) - elif option == '--include-end': - if value[0] not in '<"': - value = '"%s"' % value - end_headers.append(value) - elif option == '--not-implemented-func': - not_implemented_func = value - elif option == '--allow-unstable': - allow_havoc = True - - try: - dom = xml.dom.minidom.parse(argv[0]) - except IndexError: - cmdline_error() - - Generator(dom, prefix, basename, signal_marshal_prefix, headers, - end_headers, not_implemented_func, allow_havoc)() diff --git a/tools/glib-gtypes-generator.py b/tools/glib-gtypes-generator.py deleted file mode 100644 index 21dfc6a..0000000 --- a/tools/glib-gtypes-generator.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/python - -# Generate GLib GInterfaces from the Telepathy specification. -# The master copy of this program is in the telepathy-glib repository - -# please make any changes there. -# -# Copyright (C) 2006, 2007 Collabora Limited -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import xml.dom.minidom - -from libtpcodegen import file_set_contents -from libglibcodegen import escape_as_identifier, \ - get_docstring, \ - NS_TP, \ - Signature, \ - type_to_gtype, \ - xml_escape - - -def types_to_gtypes(types): - return [type_to_gtype(t)[1] for t in types] - - -class GTypesGenerator(object): - def __init__(self, dom, output, mixed_case_prefix): - self.dom = dom - self.Prefix = mixed_case_prefix - self.PREFIX_ = self.Prefix.upper() + '_' - self.prefix_ = self.Prefix.lower() + '_' - - self.header = [] - self.body = [] - self.docs = [] - self.output = output - - for f in (self.header, self.body, self.docs): - f.append('/* Auto-generated, do not edit.\n *\n' - ' * This file may be distributed under the same terms\n' - ' * as the specification from which it was generated.\n' - ' */\n\n') - - # keys are e.g. 'sv', values are the key escaped - self.need_mappings = {} - # keys are the contents of the struct (e.g. 'sssu'), values are the - # key escaped - self.need_structs = {} - # keys are the contents of the struct (e.g. 'sssu'), values are the - # key escaped - self.need_struct_arrays = {} - - # keys are the contents of the array (unlike need_struct_arrays!), - # values are the key escaped - self.need_other_arrays = {} - - def h(self, code): - self.header.append(code.encode("utf-8")) - - def c(self, code): - self.body.append(code.encode("utf-8")) - - def d(self, code): - self.docs.append(code.encode('utf-8')) - - def do_mapping_header(self, mapping): - members = mapping.getElementsByTagNameNS(NS_TP, 'member') - assert len(members) == 2 - - impl_sig = ''.join([elt.getAttribute('type') - for elt in members]) - - esc_impl_sig = escape_as_identifier(impl_sig) - - name = (self.PREFIX_ + 'HASH_TYPE_' + - mapping.getAttribute('name').upper()) - impl = self.prefix_ + 'type_dbus_hash_' + esc_impl_sig - - docstring = get_docstring(mapping) or '(Undocumented)' - - self.d('/**\n * %s:\n *\n' % name.strip()) - self.d(' * %s\n' % xml_escape(docstring)) - self.d(' *\n') - self.d(' * This macro expands to a call to a function\n') - self.d(' * that returns the #GType of a #GHashTable\n') - self.d(' * appropriate for representing a D-Bus\n') - self.d(' * dictionary of signature\n') - self.d(' * a{%s}.\n' % impl_sig) - self.d(' *\n') - - key, value = members - - self.d(' * Keys (D-Bus type %s,\n' - % key.getAttribute('type')) - tp_type = key.getAttributeNS(NS_TP, 'type') - if tp_type: - self.d(' * type %s,\n' % tp_type) - self.d(' * named %s):\n' - % key.getAttribute('name')) - docstring = get_docstring(key) or '(Undocumented)' - self.d(' * %s\n' % xml_escape(docstring)) - self.d(' *\n') - - self.d(' * Values (D-Bus type %s,\n' - % value.getAttribute('type')) - tp_type = value.getAttributeNS(NS_TP, 'type') - if tp_type: - self.d(' * type %s,\n' % tp_type) - self.d(' * named %s):\n' - % value.getAttribute('name')) - docstring = get_docstring(value) or '(Undocumented)' - self.d(' * %s\n' % xml_escape(docstring)) - self.d(' *\n') - - self.d(' */\n') - - self.h('#define %s (%s ())\n\n' % (name, impl)) - self.need_mappings[impl_sig] = esc_impl_sig - - array_name = mapping.getAttribute('array-name') - if array_name: - gtype_name = self.PREFIX_ + 'ARRAY_TYPE_' + array_name.upper() - contents_sig = 'a{' + impl_sig + '}' - esc_contents_sig = escape_as_identifier(contents_sig) - impl = self.prefix_ + 'type_dbus_array_of_' + esc_contents_sig - self.d('/**\n * %s:\n\n' % gtype_name) - self.d(' * Expands to a call to a function\n') - self.d(' * that returns the #GType of a #GPtrArray\n') - self.d(' * of #%s.\n' % name) - self.d(' */\n\n') - - self.h('#define %s (%s ())\n\n' % (gtype_name, impl)) - self.need_other_arrays[contents_sig] = esc_contents_sig - - def do_struct_header(self, struct): - members = struct.getElementsByTagNameNS(NS_TP, 'member') - impl_sig = ''.join([elt.getAttribute('type') for elt in members]) - esc_impl_sig = escape_as_identifier(impl_sig) - - name = (self.PREFIX_ + 'STRUCT_TYPE_' + - struct.getAttribute('name').upper()) - impl = self.prefix_ + 'type_dbus_struct_' + esc_impl_sig - docstring = struct.getElementsByTagNameNS(NS_TP, 'docstring') - if docstring: - docstring = docstring[0].toprettyxml() - if docstring.startswith(''): - docstring = docstring[14:] - if docstring.endswith('\n'): - docstring = docstring[:-16] - if docstring.strip() in ('', ''): - docstring = '(Undocumented)' - else: - docstring = '(Undocumented)' - self.d('/**\n * %s:\n\n' % name) - self.d(' * %s\n' % xml_escape(docstring)) - self.d(' *\n') - self.d(' * This macro expands to a call to a function\n') - self.d(' * that returns the #GType of a #GValueArray\n') - self.d(' * appropriate for representing a D-Bus struct\n') - self.d(' * with signature (%s).\n' - % impl_sig) - self.d(' *\n') - - for i, member in enumerate(members): - self.d(' * Member %d (D-Bus type ' - '%s,\n' - % (i, member.getAttribute('type'))) - tp_type = member.getAttributeNS(NS_TP, 'type') - if tp_type: - self.d(' * type %s,\n' % tp_type) - self.d(' * named %s):\n' - % member.getAttribute('name')) - docstring = get_docstring(member) or '(Undocumented)' - self.d(' * %s\n' % xml_escape(docstring)) - self.d(' *\n') - - self.d(' */\n\n') - - self.h('#define %s (%s ())\n\n' % (name, impl)) - - array_name = struct.getAttribute('array-name') - if array_name != '': - array_name = (self.PREFIX_ + 'ARRAY_TYPE_' + array_name.upper()) - impl = self.prefix_ + 'type_dbus_array_' + esc_impl_sig - self.d('/**\n * %s:\n\n' % array_name) - self.d(' * Expands to a call to a function\n') - self.d(' * that returns the #GType of a #GPtrArray\n') - self.d(' * of #%s.\n' % name) - self.d(' */\n\n') - - self.h('#define %s (%s ())\n\n' % (array_name, impl)) - self.need_struct_arrays[impl_sig] = esc_impl_sig - - self.need_structs[impl_sig] = esc_impl_sig - - def __call__(self): - mappings = self.dom.getElementsByTagNameNS(NS_TP, 'mapping') - structs = self.dom.getElementsByTagNameNS(NS_TP, 'struct') - - for mapping in mappings: - self.do_mapping_header(mapping) - - for sig in self.need_mappings: - self.h('GType %stype_dbus_hash_%s (void);\n\n' % - (self.prefix_, self.need_mappings[sig])) - self.c('GType\n%stype_dbus_hash_%s (void)\n{\n' % - (self.prefix_, self.need_mappings[sig])) - self.c(' static GType t = 0;\n\n') - self.c(' if (G_UNLIKELY (t == 0))\n') - # FIXME: translate sig into two GTypes - items = tuple(Signature(sig)) - gtypes = types_to_gtypes(items) - self.c(' t = dbus_g_type_get_map ("GHashTable", ' - '%s, %s);\n' % (gtypes[0], gtypes[1])) - self.c(' return t;\n') - self.c('}\n\n') - - for struct in structs: - self.do_struct_header(struct) - - for sig in self.need_structs: - self.h('GType %stype_dbus_struct_%s (void);\n\n' % - (self.prefix_, self.need_structs[sig])) - self.c('GType\n%stype_dbus_struct_%s (void)\n{\n' % - (self.prefix_, self.need_structs[sig])) - self.c(' static GType t = 0;\n\n') - self.c(' if (G_UNLIKELY (t == 0))\n') - self.c(' t = dbus_g_type_get_struct ("GValueArray",\n') - items = tuple(Signature(sig)) - gtypes = types_to_gtypes(items) - for gtype in gtypes: - self.c(' %s,\n' % gtype) - self.c(' G_TYPE_INVALID);\n') - self.c(' return t;\n') - self.c('}\n\n') - - for sig in self.need_struct_arrays: - self.h('GType %stype_dbus_array_%s (void);\n\n' % - (self.prefix_, self.need_struct_arrays[sig])) - self.c('GType\n%stype_dbus_array_%s (void)\n{\n' % - (self.prefix_, self.need_struct_arrays[sig])) - self.c(' static GType t = 0;\n\n') - self.c(' if (G_UNLIKELY (t == 0))\n') - self.c(' t = dbus_g_type_get_collection ("GPtrArray", ' - '%stype_dbus_struct_%s ());\n' % - (self.prefix_, self.need_struct_arrays[sig])) - self.c(' return t;\n') - self.c('}\n\n') - - for sig in self.need_other_arrays: - self.h('GType %stype_dbus_array_of_%s (void);\n\n' % - (self.prefix_, self.need_other_arrays[sig])) - self.c('GType\n%stype_dbus_array_of_%s (void)\n{\n' % - (self.prefix_, self.need_other_arrays[sig])) - self.c(' static GType t = 0;\n\n') - self.c(' if (G_UNLIKELY (t == 0))\n') - - if sig[:2] == 'a{' and sig[-1:] == '}': - # array of mappings - self.c(' t = dbus_g_type_get_collection (' - '"GPtrArray", ' - '%stype_dbus_hash_%s ());\n' % - (self.prefix_, escape_as_identifier(sig[2:-1]))) - elif sig[:2] == 'a(' and sig[-1:] == ')': - # array of arrays of struct - self.c(' t = dbus_g_type_get_collection (' - '"GPtrArray", ' - '%stype_dbus_array_%s ());\n' % - (self.prefix_, escape_as_identifier(sig[2:-1]))) - elif sig[:1] == 'a': - # array of arrays of non-struct - self.c(' t = dbus_g_type_get_collection (' - '"GPtrArray", ' - '%stype_dbus_array_of_%s ());\n' % - (self.prefix_, escape_as_identifier(sig[1:]))) - else: - raise AssertionError("array of '%s' not supported" % sig) - - self.c(' return t;\n') - self.c('}\n\n') - - file_set_contents(self.output + '.h', ''.join(self.header)) - file_set_contents(self.output + '-body.h', ''.join(self.body)) - file_set_contents(self.output + '-gtk-doc.h', ''.join(self.docs)) - -if __name__ == '__main__': - argv = sys.argv[1:] - - dom = xml.dom.minidom.parse(argv[0]) - - GTypesGenerator(dom, argv[1], argv[2])() diff --git a/tools/glib-interfaces-body-generator.xsl b/tools/glib-interfaces-body-generator.xsl deleted file mode 100644 index caff891..0000000 --- a/tools/glib-interfaces-body-generator.xsl +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - GQuark - - _iface_quark_ - - (void) { - static GQuark quark = 0; - if (G_UNLIKELY (quark == 0)) - { - quark = g_quark_from_static_string (" - - "); - } - return quark; - } - - - - - diff --git a/tools/glib-interfaces-generator.xsl b/tools/glib-interfaces-generator.xsl deleted file mode 100644 index e703c40..0000000 --- a/tools/glib-interfaces-generator.xsl +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - /** * - - _IFACE_QUARK_ - - : * * Expands to a call to a function that - returns a quark for the interface name " - - " */ #define - - _IFACE_QUARK_ - - \ ( - - _iface_quark_ - - ()) GQuark - - _iface_quark_ - - (void); - - - - - diff --git a/tools/glib-signals-marshal-gen.py b/tools/glib-signals-marshal-gen.py deleted file mode 100644 index 0d02c13..0000000 --- a/tools/glib-signals-marshal-gen.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python - -import sys -import xml.dom.minidom -from string import ascii_letters, digits - - -from libglibcodegen import signal_to_marshal_name, method_to_glue_marshal_name - - -class Generator(object): - - def __init__(self, dom): - self.dom = dom - self.marshallers = {} - - def do_method(self, method): - marshaller = method_to_glue_marshal_name(method, 'PREFIX') - - assert '__' in marshaller - rhs = marshaller.split('__', 1)[1].split('_') - - self.marshallers[marshaller] = rhs - - def do_signal(self, signal): - marshaller = signal_to_marshal_name(signal, 'PREFIX') - - assert '__' in marshaller - rhs = marshaller.split('__', 1)[1].split('_') - - self.marshallers[marshaller] = rhs - - def __call__(self): - methods = self.dom.getElementsByTagName('method') - - for method in methods: - self.do_method(method) - - signals = self.dom.getElementsByTagName('signal') - - for signal in signals: - self.do_signal(signal) - - all = self.marshallers.keys() - all.sort() - for marshaller in all: - rhs = self.marshallers[marshaller] - if not marshaller.startswith('g_cclosure'): - print 'VOID:' + ','.join(rhs) - -if __name__ == '__main__': - argv = sys.argv[1:] - dom = xml.dom.minidom.parse(argv[0]) - - Generator(dom)() diff --git a/tools/gquark-gen.py b/tools/gquark-gen.py deleted file mode 100644 index 37d19e0..0000000 --- a/tools/gquark-gen.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/python - -# glib-client-gen.py: "I Can't Believe It's Not dbus-binding-tool" -# -# Generate GLib client wrappers from the Telepathy specification. -# The master copy of this program is in the telepathy-glib repository - -# please make any changes there. -# -# Copyright (C) 2006-2008 Collabora Ltd. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import os.path -from getopt import gnu_getopt - -from libglibcodegen import Signature, type_to_gtype, cmp_by_name, get_docstring - -def camelcase_to_lower(s): - out =""; - out += s[0].lower() - last_upper=False - if s[0].isupper(): - last_upper=True - for i in range(1,len(s)): - if s[i].isupper(): - if last_upper: - if (i+1) < len(s) and s[i+1].islower(): - out += "_" + s[i].lower() - else: - out += s[i].lower() - else: - out += "_" + s[i].lower() - last_upper=True - else: - out += s[i] - last_upper=False - return out - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -class Generator(object): - - def __init__(self, quark_list, prefix, basename, opts): - self.__header = [] - self.__body = [] - - self.prefix_lc = prefix.lower() - self.prefix_uc = prefix.upper() - self.basename = basename - self.quark_prefix = opts.get('--quark-prefix', None) - - self.quark_list = [ l.split(None, 2) for l in quark_list ] - - - def h(self, s): - self.__header.append(s) - - def b(self, s): - self.__body.append(s) - - def do_quark(self, quark): - (qname, qstring) = quark - - self.b('GQuark') - self.b('%s_%s (void)' - % (self.prefix_lc, qname.lower())) - self.b('{') - self.b(' static GQuark quark = 0;') - self.b('') - self.b(' if (G_UNLIKELY (quark == 0))') - self.b(' quark = g_quark_from_static_string ("%s");' - % (qstring, )) - self.b(' return quark;') - self.b('}') - self.b('') - self.b('') - - self.h('#define %s_%s %s_%s()' % - (self.prefix_uc, qname.upper(), - self.prefix_lc, qname.lower())) - self.h('GQuark %s_%s(void);' % (self.prefix_lc, qname.lower())) - self.h('') - - def __call__(self): - - self.b('#include "%s.h"' % (self.basename)) - self.b('') - - self.h('#include ') - self.h('') - self.h('G_BEGIN_DECLS') - self.h('') - - for quark in self.quark_list: - self.do_quark(quark) - - - self.h('G_END_DECLS') - self.h('') - - open(self.basename + '.h', 'w').write('\n'.join(self.__header)) - open(self.basename + '.c', 'w').write('\n'.join(self.__body)) - - -def types_to_gtypes(types): - return [type_to_gtype(t)[1] for t in types] - - -if __name__ == '__main__': - options, argv = gnu_getopt(sys.argv[1:], '', - ['quark-prefix=']) - - opts = {} - - for option, value in options: - opts[option] = value - - quark_list_file = file(argv[0]) - quark_list = quark_list_file.readlines() - quark_list_file.close() - Generator(quark_list, argv[1], argv[2], opts)() diff --git a/tools/identity.xsl b/tools/identity.xsl deleted file mode 100644 index 6630f84..0000000 --- a/tools/identity.xsl +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/tools/libglibcodegen.py b/tools/libglibcodegen.py deleted file mode 100644 index 6a9d214..0000000 --- a/tools/libglibcodegen.py +++ /dev/null @@ -1,172 +0,0 @@ -"""Library code for GLib/D-Bus-related code generation. - -The master copy of this library is in the telepathy-glib repository - -please make any changes there. -""" - -# Copyright (C) 2006-2008 Collabora Limited -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -from libtpcodegen import NS_TP, \ - Signature, \ - cmp_by_name, \ - escape_as_identifier, \ - get_by_path, \ - get_descendant_text, \ - get_docstring, \ - xml_escape, \ - get_deprecated - -def dbus_gutils_wincaps_to_uscore(s): - """Bug-for-bug compatible Python port of _dbus_gutils_wincaps_to_uscore - which gets sequences of capital letters wrong in the same way. - (e.g. in Telepathy, SendDTMF -> send_dt_mf) - """ - ret = '' - for c in s: - if c >= 'A' and c <= 'Z': - length = len(ret) - if length > 0 and (length < 2 or ret[length-2] != '_'): - ret += '_' - ret += c.lower() - else: - ret += c - return ret - - -def signal_to_marshal_type(signal): - """ - return a list of strings indicating the marshalling type for this signal. - """ - - mtype=[] - for i in signal.getElementsByTagName("arg"): - name =i.getAttribute("name") - type = i.getAttribute("type") - mtype.append(type_to_gtype(type)[2]) - - return mtype - - -_glib_marshallers = ['VOID', 'BOOLEAN', 'CHAR', 'UCHAR', 'INT', - 'STRING', 'UINT', 'LONG', 'ULONG', 'ENUM', 'FLAGS', 'FLOAT', - 'DOUBLE', 'STRING', 'PARAM', 'BOXED', 'POINTER', 'OBJECT', - 'UINT_POINTER'] - - -def signal_to_marshal_name(signal, prefix): - - mtype = signal_to_marshal_type(signal) - if len(mtype): - name = '_'.join(mtype) - else: - name = 'VOID' - - if name in _glib_marshallers: - return 'g_cclosure_marshal_VOID__' + name - else: - return prefix + '_marshal_VOID__' + name - - -def method_to_glue_marshal_name(method, prefix): - - mtype = [] - for i in method.getElementsByTagName("arg"): - if i.getAttribute("direction") != "out": - type = i.getAttribute("type") - mtype.append(type_to_gtype(type)[2]) - - mtype.append('POINTER') - - name = '_'.join(mtype) - - if name in _glib_marshallers: - return 'g_cclosure_marshal_VOID__' + name - else: - return prefix + '_marshal_VOID__' + name - - -def type_to_gtype(s): - if s == 'y': #byte - return ("guchar ", "G_TYPE_UCHAR","UCHAR", False) - elif s == 'b': #boolean - return ("gboolean ", "G_TYPE_BOOLEAN","BOOLEAN", False) - elif s == 'n': #int16 - return ("gint ", "G_TYPE_INT","INT", False) - elif s == 'q': #uint16 - return ("guint ", "G_TYPE_UINT","UINT", False) - elif s == 'i': #int32 - return ("gint ", "G_TYPE_INT","INT", False) - elif s == 'u': #uint32 - return ("guint ", "G_TYPE_UINT","UINT", False) - elif s == 'x': #int64 - return ("gint64 ", "G_TYPE_INT64","INT64", False) - elif s == 't': #uint64 - return ("guint64 ", "G_TYPE_UINT64","UINT64", False) - elif s == 'd': #double - return ("gdouble ", "G_TYPE_DOUBLE","DOUBLE", False) - elif s == 's': #string - return ("gchar *", "G_TYPE_STRING", "STRING", True) - elif s == 'g': #signature - FIXME - return ("gchar *", "DBUS_TYPE_G_SIGNATURE", "STRING", True) - elif s == 'o': #object path - return ("gchar *", "DBUS_TYPE_G_OBJECT_PATH", "BOXED", True) - elif s == 'v': #variant - return ("GValue *", "G_TYPE_VALUE", "BOXED", True) - elif s == 'as': #array of strings - return ("gchar **", "G_TYPE_STRV", "BOXED", True) - elif s == 'ay': #byte array - return ("GArray *", - "dbus_g_type_get_collection (\"GArray\", G_TYPE_UCHAR)", "BOXED", - True) - elif s == 'au': #uint array - return ("GArray *", "DBUS_TYPE_G_UINT_ARRAY", "BOXED", True) - elif s == 'ai': #int array - return ("GArray *", "DBUS_TYPE_G_INT_ARRAY", "BOXED", True) - elif s == 'ax': #int64 array - return ("GArray *", "DBUS_TYPE_G_INT64_ARRAY", "BOXED", True) - elif s == 'at': #uint64 array - return ("GArray *", "DBUS_TYPE_G_UINT64_ARRAY", "BOXED", True) - elif s == 'ad': #double array - return ("GArray *", "DBUS_TYPE_G_DOUBLE_ARRAY", "BOXED", True) - elif s == 'ab': #boolean array - return ("GArray *", "DBUS_TYPE_G_BOOLEAN_ARRAY", "BOXED", True) - elif s == 'ao': #object path array - return ("GPtrArray *", - 'dbus_g_type_get_collection ("GPtrArray",' - ' DBUS_TYPE_G_OBJECT_PATH)', - "BOXED", True) - elif s == 'a{ss}': #hash table of string to string - return ("GHashTable *", "DBUS_TYPE_G_STRING_STRING_HASHTABLE", "BOXED", False) - elif s[:2] == 'a{': #some arbitrary hash tables - if s[2] not in ('y', 'b', 'n', 'q', 'i', 'u', 's', 'o', 'g'): - raise Exception, "can't index a hashtable off non-basic type " + s - first = type_to_gtype(s[2]) - second = type_to_gtype(s[3:-1]) - return ("GHashTable *", "(dbus_g_type_get_map (\"GHashTable\", " + first[1] + ", " + second[1] + "))", "BOXED", False) - elif s[:2] in ('a(', 'aa'): # array of structs or arrays, recurse - gtype = type_to_gtype(s[1:])[1] - return ("GPtrArray *", "(dbus_g_type_get_collection (\"GPtrArray\", "+gtype+"))", "BOXED", True) - elif s[:1] == '(': #struct - gtype = "(dbus_g_type_get_struct (\"GValueArray\", " - for subsig in Signature(s[1:-1]): - gtype = gtype + type_to_gtype(subsig)[1] + ", " - gtype = gtype + "G_TYPE_INVALID))" - return ("GValueArray *", gtype, "BOXED", True) - - # we just don't know .. - raise Exception, "don't know the GType for " + s diff --git a/tools/libtpcodegen.py b/tools/libtpcodegen.py deleted file mode 100644 index 7e9eb9a..0000000 --- a/tools/libtpcodegen.py +++ /dev/null @@ -1,227 +0,0 @@ -"""Library code for language-independent D-Bus-related code generation. - -The master copy of this library is in the telepathy-glib repository - -please make any changes there. -""" - -# Copyright (C) 2006-2008 Collabora Limited -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import os -from string import ascii_letters, digits - - -NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - -_ASCII_ALNUM = ascii_letters + digits - -def file_set_contents(filename, contents): - try: - os.remove(filename) - except OSError: - pass - try: - os.remove(filename + '.tmp') - except OSError: - pass - - open(filename + '.tmp', 'w').write(contents) - os.rename(filename + '.tmp', filename) - -def cmp_by_name(node1, node2): - return cmp(node1.getAttributeNode("name").nodeValue, - node2.getAttributeNode("name").nodeValue) - - -def escape_as_identifier(identifier): - """Escape the given string to be a valid D-Bus object path or service - name component, using a reversible encoding to ensure uniqueness. - - The reversible encoding is as follows: - - * The empty string becomes '_' - * Otherwise, each non-alphanumeric character is replaced by '_' plus - two lower-case hex digits; the same replacement is carried out on - the first character, if it's a digit - """ - # '' -> '_' - if not identifier: - return '_' - - # A bit of a fast path for strings which are already OK. - # We deliberately omit '_' because, for reversibility, that must also - # be escaped. - if (identifier.strip(_ASCII_ALNUM) == '' and - identifier[0] in ascii_letters): - return identifier - - # The first character may not be a digit - if identifier[0] not in ascii_letters: - ret = ['_%02x' % ord(identifier[0])] - else: - ret = [identifier[0]] - - # Subsequent characters may be digits or ASCII letters - for c in identifier[1:]: - if c in _ASCII_ALNUM: - ret.append(c) - else: - ret.append('_%02x' % ord(c)) - - return ''.join(ret) - - -def get_by_path(element, path): - branches = path.split('/') - branch = branches[0] - - # Is the current branch an attribute, if so, return the attribute value - if branch[0] == '@': - return element.getAttribute(branch[1:]) - - # Find matching children for the branch - children = [] - if branch == '..': - children.append(element.parentNode) - else: - for x in element.childNodes: - if x.localName == branch: - children.append(x) - - ret = [] - # If this is not the last path element, recursively gather results from - # children - if len(branches) > 1: - for x in children: - add = get_by_path(x, '/'.join(branches[1:])) - if isinstance(add, list): - ret += add - else: - return add - else: - ret = children - - return ret - - -def get_docstring(element): - docstring = None - for x in element.childNodes: - if x.namespaceURI == NS_TP and x.localName == 'docstring': - docstring = x - if docstring is not None: - docstring = docstring.toxml().replace('\n', ' ').strip() - if docstring.startswith(''): - docstring = docstring[14:].lstrip() - if docstring.endswith(''): - docstring = docstring[:-15].rstrip() - if docstring in ('', ''): - docstring = '' - return docstring - -def get_deprecated(element): - text = [] - for x in element.childNodes: - if hasattr(x, 'data'): - text.append(x.data.replace('\n', ' ').strip()) - else: - # This caters for tp:dbus-ref elements, but little else. - if x.childNodes and hasattr(x.childNodes[0], 'data'): - text.append(x.childNodes[0].data.replace('\n', ' ').strip()) - return ' '.join(text) - -def get_descendant_text(element_or_elements): - if not element_or_elements: - return '' - if isinstance(element_or_elements, list): - return ''.join(map(get_descendant_text, element_or_elements)) - parts = [] - for x in element_or_elements.childNodes: - if x.nodeType == x.TEXT_NODE: - parts.append(x.nodeValue) - elif x.nodeType == x.ELEMENT_NODE: - parts.append(get_descendant_text(x)) - else: - pass - return ''.join(parts) - - -class _SignatureIter: - """Iterator over a D-Bus signature. Copied from dbus-python 0.71 so we - can run genginterface in a limited environment with only Python - (like Scratchbox). - """ - def __init__(self, string): - self.remaining = string - - def next(self): - if self.remaining == '': - raise StopIteration - - signature = self.remaining - block_depth = 0 - block_type = None - end = len(signature) - - for marker in range(0, end): - cur_sig = signature[marker] - - if cur_sig == 'a': - pass - elif cur_sig == '{' or cur_sig == '(': - if block_type == None: - block_type = cur_sig - - if block_type == cur_sig: - block_depth = block_depth + 1 - - elif cur_sig == '}': - if block_type == '{': - block_depth = block_depth - 1 - - if block_depth == 0: - end = marker - break - - elif cur_sig == ')': - if block_type == '(': - block_depth = block_depth - 1 - - if block_depth == 0: - end = marker - break - - else: - if block_depth == 0: - end = marker - break - - end = end + 1 - self.remaining = signature[end:] - return Signature(signature[0:end]) - - -class Signature(str): - """A string, iteration over which is by D-Bus single complete types - rather than characters. - """ - def __iter__(self): - return _SignatureIter(self) - - -def xml_escape(s): - s = s.replace('&', '&').replace("'", ''').replace('"', '"') - return s.replace('<', '<').replace('>', '>') diff --git a/tools/spec-to-introspect.xsl b/tools/spec-to-introspect.xsl deleted file mode 100644 index 992efc7..0000000 --- a/tools/spec-to-introspect.xsl +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/xml/Makefile.am b/xml/Makefile.am deleted file mode 100644 index b43d81c..0000000 --- a/xml/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -tools_dir = $(top_srcdir)/tools - -XSLTFLAGS = --nonet --novalid -DROP_NAMESPACE = sed -e 's@xmlns:tp="http://telepathy\.freedesktop\.org/wiki/DbusSpec.extensions-v0"@@g' -DROP_TPTYPE = sed -e 's@tp:type="[^"]*"@@g' - -SPECS = \ - $(NULL) - - -SPECS_GEN = ${SPECS:%.xml=_gen/introspect-%.xml} - -all-local: $(SPECS_GEN) - -_gen/introspect-%.xml: %.xml $(tools_dir)/spec-to-introspect.xsl - $(AM_V_at)$(mkdir_p) _gen - $(AM_V_GEN)$(XSLTPROC) $(XSLTFLAGS) $(tools_dir)/spec-to-introspect.xsl $< \ - | $(DROP_NAMESPACE) > $@ - -clean-local: - rm -f $(SPECS_GEN) - -EXTRA_DIST = \ - all.xml \ - nmc5.xml \ - generic-types.xml \ - telepathy-types.xml \ - $(SPECS) diff --git a/xml/all.xml b/xml/all.xml deleted file mode 100644 index cb7661f..0000000 --- a/xml/all.xml +++ /dev/null @@ -1,35 +0,0 @@ - - -Copyright (C) 2008 Nokia Corporation - - - - - - - - - - - - - - - - - - - - diff --git a/xml/generic-types.xml b/xml/generic-types.xml deleted file mode 100644 index 5b0d6ab..0000000 --- a/xml/generic-types.xml +++ /dev/null @@ -1,214 +0,0 @@ - - - - An unsigned 32-bit integer representing time as the number - of seconds elapsed since the Unix epoch - (1970-01-01T00:00:00Z) - - - - An signed 64-bit integer representing time as the number - of seconds elapsed since the Unix epoch - (1970-01-01T00:00:00Z); negative for times before the epoch - - The Text interface is the only user of Unix_Timestamp so - far, and we'd like to be Y2038 compatible in future - interfaces. - - - - A string representing a D-Bus bus name - either a well-known - name like "org.freedesktop.Telepathy.MissionControl" or a unique name - like ":1.123" - - - - A string representing a D-Bus well-known - name like "org.freedesktop.Telepathy.MissionControl". - - - - A string representing a D-Bus unique name, such as - ":1.123" - - - - An ASCII string representing a D-Bus interface - two or more - elements separated by dots, where each element is a non-empty - string of ASCII letters, digits and underscores, not starting with - a digit. The maximum total length is 255 characters. For example, - "org.freedesktop.DBus.Peer". - - - - An ASCII string representing a D-Bus error. This is - syntactically the same as a DBus_Interface, but the - meaning is different. - - - - A string representing a D-Bus signature - (the 'g' type isn't used because of poor interoperability, particularly - with dbus-glib) - - - - An ASCII string representing a D-Bus method, signal - or property name - a non-empty string of ASCII letters, digits and - underscores, not starting with a digit, with a maximum length of 255 - characters. For example, "Ping". - - - - A string representing the full name of a D-Bus method, - signal or property, consisting of a DBus_Interface, followed by - a dot, followed by a DBus_Member. For example, - "org.freedesktop.DBus.Peer.Ping". - - - - A mapping from strings representing D-Bus - properties (by their namespaced names) to their values. - - - A D-Bus interface name, followed by a dot and a D-Bus property name. - - - - - The value of the property. - - - - - - A mapping from strings to variants representing extra - key-value pairs. - - - - - - A mapping from strings to strings representing extra - key-value pairs. - - - - - - An IP address and port. - - Either a dotted-quad IPv4 address literal as for - Socket_Address_IPv4, or an RFC2373 IPv6 address - as for Socket_Address_IPv6. - - - - The TCP or UDP port number. - - - - - An IPv4 address and port. - - A dotted-quad IPv4 address literal: four ASCII decimal - numbers, each between 0 and 255 inclusive, e.g. - "192.168.0.1". - - - The TCP or UDP port number. - - - - - An IPv6 address and port. - - An IPv6 address literal as specified by RFC2373 - section 2.2, e.g. "2001:DB8::8:800:200C:4171". - - - The TCP or UDP port number. - - - - - An IPv4 network or subnet. - - A dotted-quad IPv4 address literal: four ASCII decimal - numbers, each between 0 and 255 inclusive, e.g. - "192.168.0.1". - - - The number of leading bits of the address that must - match, for this netmask to be considered to match an - address. - - - - - An IPv6 network or subnet. - - An IPv6 address literal as specified by RFC2373 - section 2.2, e.g. "2001:DB8::8:800:200C:4171". - - - The number of leading bits of the address that must - match, for this netmask to be considered to match an - address. - - - - - -

The time at which an user action occurred. This type has the 2 - following special values:

- -

0: the action doesn't involve any user action. Clients - SHOULD avoid stealing focus when presenting the channel.

- -

MAX_INT64: clients SHOULD behave as though the user action happened - at the current time, e.g. a client MAY request that its window gains - focus. -

- - -

This can be used by clients that can't know the X server time like - command line applications for example.

-
- -

For all the other values it corresponds to the time of the user - action. Clients SHOULD use this for focus-stealing prevention, - if applicable. - Note that the time is dependant on the local - environment and so is not necessarily a wall-clock time. - For example in an X environment it's expected to be the X timestamp - of events. - This corresponds to the _NET_WM_USER_TIME property in - EWMH.

-
-
- - - A mapping from object path to the immutable properties of - the object. - - - The object path of an object - - - - - The immutable properties of the object - - - - -
diff --git a/xml/nmc5.xml b/xml/nmc5.xml deleted file mode 100644 index 29157ac..0000000 --- a/xml/nmc5.xml +++ /dev/null @@ -1,7 +0,0 @@ - - -Copyright (C) 2008 Nokia Corporation - - diff --git a/xml/telepathy-types.xml b/xml/telepathy-types.xml deleted file mode 100644 index 8225aa0..0000000 --- a/xml/telepathy-types.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - -

Mapping representing a class of channels that can be requested - from a connection manager, can be handled by a user interface, - are supported by a contact, etc.

- -

Classes of channel are identified by the fixed values of - a subset of their properties.

- -

Channel classes SHOULD always include the keys - org.freedesktop.Telepathy.Channel.ChannelType - and - org.freedesktop.Telepathy.Channel.TargetHandleType. -

-
- - - - A D-Bus interface name, followed by a dot and a D-Bus property name. - - - - - - The value of the property. - - -
- - - (as stable API) - - - Enough details of a channel that clients can work out how to dispatch - or handle it. - - - - - The object path of the channel. - - - - - -

Properties of the channel.

- -

Connection managers MUST NOT include properties in this mapping - if their values can change. Clients MUST ignore properties - that appear in this mapping if their values can change.

- - -

If properties that could change were included, the following - race condition would be likely to exist in some cases:

- -
    -
  • NewChannels or Get("Channels") includes a property P with - value V1
  • -
  • Client creates a proxy object for the channel
  • -
  • The value of P changes to V2
  • -
  • Client connects to PChanged signal
  • -
  • Client should call Get("P") or GetAll here, to avoid the - race, but client's author has forgotten to do so
  • -
  • Proxy object thinks P == V1, but actually P == V2
  • -
- -

We've taken the opportunity to make the API encourage the - client author to get it right. Where possible, we intend that - properties whose value will be used in channel dispatching - or other "early" processing will be defined so that they are - immutable (can never change).

-
- -

Each dictionary MUST contain the keys - org.freedesktop.Telepathy.Channel.ChannelType, - org.freedesktop.Telepathy.Channel.TargetHandleType, - org.freedesktop.Telepathy.Channel.TargetHandle - and - org.freedesktop.Telepathy.Channel.TargetID. -

- - - -

We expect these to be crucial to the channel-dispatching - process.

-
-
-
-
- -
-- 1.9.rc1