[Pkg-telepathy-commits] [telepathy-glib-1] 02/212: libglibcodegen: add code to generate GDBusInterfaceInfo from the Tp spec
Simon McVittie
smcv at debian.org
Wed May 14 12:08:44 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository telepathy-glib-1.
commit 434c57f585631f556076c3e33d23d28c2bd25659
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue Mar 11 17:34:23 2014 +0000
libglibcodegen: add code to generate GDBusInterfaceInfo from the Tp spec
I'm not using gdbus-codegen, at least not yet, because our CMs
are pretty heavily dependent on the TpSvc* interfaces, and I would
like the minimum viable port to GDBus to take a finite time.
---
tools/libglibcodegen.py | 203 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 203 insertions(+)
diff --git a/tools/libglibcodegen.py b/tools/libglibcodegen.py
index 33867dd..eb4f461 100644
--- a/tools/libglibcodegen.py
+++ b/tools/libglibcodegen.py
@@ -236,3 +236,206 @@ def value_getter(gtype, marshaller):
return 'g_value_get_double'
else:
raise AssertionError("Don't know how to get %s from a GValue" % marshaller)
+
+class GDBusInterfaceInfo(object):
+ def __init__(self, ugly_name, iface_element, c_name):
+ self.ugly_name = ugly_name
+ self.mixed_name = ugly_name.replace('_', '')
+ self.lc_name = ugly_name.lower()
+ self.uc_name = ugly_name.upper()
+ self.c_name = c_name
+ self.iface_element = iface_element
+
+ self.method_elements = iface_element.getElementsByTagName('method')
+ self.signal_elements = iface_element.getElementsByTagName('signal')
+ self.property_elements = iface_element.getElementsByTagName('property')
+
+ def do_methods(self):
+ method_args = [
+ ]
+ method_in_arg_pointers = [
+ ]
+ method_out_arg_pointers = [
+ ]
+ methods = [
+ ]
+ method_pointers = [
+ 'static const GDBusMethodInfo *const method_pointers_%s[] = {'
+ % self.c_name,
+ ]
+
+ for meth in self.method_elements:
+ lc_name = meth.getAttribute('tp:name-for-bindings')
+ if meth.getAttribute('name') != lc_name.replace('_', ''):
+ raise AssertionError('Method %s tp:name-for-bindings (%s) '
+ 'does not match' %
+ (meth.getAttribute('name'), lc_name))
+ lc_name = lc_name.lower()
+
+ c_name = 'method_%s_%s' % (self.c_name, lc_name)
+
+ method_in_arg_pointers.append('static const GDBusArgInfo *const '
+ 'method_in_arg_pointers_%s_%s[] = {' %
+ (self.c_name, lc_name))
+ method_out_arg_pointers.append('static const GDBusArgInfo *const '
+ 'method_out_arg_pointers_%s_%s[] = {'
+ % (self.c_name, lc_name))
+
+ for i, arg in enumerate(meth.getElementsByTagName('arg')):
+ name = arg.getAttribute('name')
+ if not name:
+ name = 'arg%d' % i
+
+ method_args.append('static const GDBusArgInfo '
+ 'method_arg_%s_%s_%d = {' % (self.c_name, lc_name, i))
+ method_args.append(' -1, /* refcount */')
+ method_args.append(' "%s",' % name)
+ method_args.append(' "%s",' % arg.getAttribute('type'))
+ method_args.append(' NULL /* annotations */')
+ method_args.append('};')
+
+ if arg.getAttribute('direction') == 'out':
+ method_out_arg_pointers.append(' &method_arg_%s_%s_%d,' %
+ (self.c_name, lc_name, i))
+ else:
+ method_in_arg_pointers.append(' &method_arg_%s_%s_%d,' %
+ (self.c_name, lc_name, i))
+
+ method_in_arg_pointers.append(' NULL')
+ method_in_arg_pointers.append('};')
+ method_out_arg_pointers.append(' NULL')
+ method_out_arg_pointers.append('};')
+
+ methods.append('static const GDBusMethodInfo %s = {' % c_name)
+ methods.append(' -1, /* refcount */')
+ methods.append(' "%s",' % meth.getAttribute("name"))
+ methods.append(' (GDBusArgInfo **) method_in_arg_pointers_%s_%s,'
+ % (self.c_name, lc_name))
+ methods.append(' (GDBusArgInfo **) method_out_arg_pointers_%s_%s,'
+ % (self.c_name, lc_name))
+ methods.append(' NULL /* annotations */')
+ methods.append('};')
+
+ method_pointers.append(' &%s,' % c_name)
+
+ method_pointers.append(' NULL')
+ method_pointers.append('};')
+
+ return (method_args + method_in_arg_pointers +
+ method_out_arg_pointers + methods + method_pointers)
+
+ def do_signals(self):
+ signal_args = [
+ ]
+ signal_arg_pointers = [
+ ]
+ signals = [
+ ]
+ signal_pointers = [
+ 'static const GDBusSignalInfo *const signal_pointers_%s[] = {'
+ % self.c_name,
+ ]
+
+ for sig in self.signal_elements:
+ lc_name = sig.getAttribute('tp:name-for-bindings')
+ if sig.getAttribute('name') != lc_name.replace('_', ''):
+ raise AssertionError('Signal %s tp:name-for-bindings (%s) '
+ 'does not match' %
+ (sig.getAttribute('name'), lc_name))
+ lc_name = lc_name.lower()
+
+ c_name = 'signal_%s_%s' % (self.c_name, lc_name)
+
+ signal_arg_pointers.append('static const GDBusArgInfo *const '
+ 'signal_arg_pointers_%s_%s[] = {' % (self.c_name, lc_name))
+
+ for i, arg in enumerate(sig.getElementsByTagName('arg')):
+ name = arg.getAttribute('name')
+ if not name:
+ name = 'arg%d' % i
+
+ signal_args.append('static const GDBusArgInfo '
+ 'signal_arg_%s_%s_%d = {' % (self.c_name, lc_name, i))
+ signal_args.append(' -1, /* refcount */')
+ signal_args.append(' "%s",' % name)
+ signal_args.append(' "%s",' % arg.getAttribute('type'))
+ signal_args.append(' NULL /* annotations */')
+ signal_args.append('};')
+
+ signal_arg_pointers.append(' &signal_arg_%s_%s_%d,' %
+ (self.c_name, lc_name, i))
+
+ signal_arg_pointers.append(' NULL')
+ signal_arg_pointers.append('};')
+
+ signals.append('static const GDBusSignalInfo %s = {' % c_name)
+ signals.append(' -1, /* refcount */')
+ signals.append(' "%s",' % sig.getAttribute("name"))
+ signals.append(' (GDBusArgInfo **) signal_arg_pointers_%s_%s,'
+ % (self.c_name, lc_name))
+ signals.append(' NULL /* annotations */')
+ signals.append('};')
+
+ signal_pointers.append(' &%s,' % c_name)
+
+ signal_pointers.append(' NULL')
+ signal_pointers.append('};')
+
+ return signal_args + signal_arg_pointers + signals + signal_pointers
+
+ def do_properties(self):
+ properties = [
+ ]
+ property_pointers = [
+ 'static const GDBusPropertyInfo *const property_pointers_%s[] = {'
+ % self.c_name,
+ ]
+
+ for prop in self.property_elements:
+ access = prop.getAttribute('access')
+ flags = {
+ 'read': 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE',
+ 'write': 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE',
+ 'readwrite':
+ 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | '
+ 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE',
+ }[access]
+
+ lc_name = prop.getAttribute('tp:name-for-bindings')
+ if prop.getAttribute('name') != lc_name.replace('_', ''):
+ raise AssertionError('Property %s tp:name-for-bindings (%s) '
+ 'does not match' %
+ (prop.getAttribute('name'), lc_name))
+ lc_name = lc_name.lower()
+
+ c_name = 'property_%s_%s' % (self.c_name, lc_name)
+
+ properties.append('static const GDBusPropertyInfo %s = {' % c_name)
+ properties.append(' -1, /* refcount */')
+ properties.append(' "%s",' % prop.getAttribute("name"))
+ properties.append(' "%s",' % prop.getAttribute("type"))
+ properties.append(' %s,' % flags)
+ # FIXME: add annotations?
+ properties.append(' NULL /* annotations */')
+ properties.append('};')
+
+ property_pointers.append(' &%s,' % c_name)
+
+ property_pointers.append(' NULL')
+ property_pointers.append('};')
+
+ return properties + property_pointers
+
+ def to_lines(self, linkage='static'):
+ return (self.do_methods() +
+ self.do_signals() +
+ self.do_properties() + [
+ '%s const GDBusInterfaceInfo %s = {' % (linkage, self.c_name),
+ ' -1, /* refcount */',
+ ' "%s",' % self.iface_element.getAttribute('name'),
+ ' (GDBusMethodInfo **) method_pointers_%s,' % self.c_name,
+ ' (GDBusSignalInfo **) signal_pointers_%s,' % self.c_name,
+ ' (GDBusPropertyInfo **) property_pointers_%s,' % self.c_name,
+ ' NULL /* annotations */',
+ '};'
+ ])
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-glib-1.git
More information about the Pkg-telepathy-commits
mailing list