aboutsummaryrefslogtreecommitdiffstats
path: root/tools/glib-client-gen.py
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-09-17 16:26:43 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-09-17 16:44:06 +0800
commit8750c21d6838bd83065f735470fb96de867ed31f (patch)
tree3ff8457567480e3fc6dbca285c3559b19acec2c4 /tools/glib-client-gen.py
parentf9a38137925ff6f712afe21961614a1efb3b35ea (diff)
downloadgsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar.gz
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar.bz2
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar.lz
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar.xz
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.tar.zst
gsoc2013-empathy-8750c21d6838bd83065f735470fb96de867ed31f.zip
sync tools/* with tp-glib master
Fix extensions/Makefile.am to build with the new tools.
Diffstat (limited to 'tools/glib-client-gen.py')
-rw-r--r--tools/glib-client-gen.py85
1 files changed, 65 insertions, 20 deletions
diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py
index 6b0bdeba1..f8465a62b 100644
--- a/tools/glib-client-gen.py
+++ b/tools/glib-client-gen.py
@@ -27,6 +27,7 @@ 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
@@ -56,12 +57,22 @@ class Generator(object):
% opts.get('--subclass', 'TpProxy'))
if self.proxy_arg == 'void *':
self.proxy_arg = 'gpointer '
- self.generate_reentrant = ('--generate-reentrant' in opts or
- '--deprecate-reentrant' in opts)
+
+ 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')
@@ -139,8 +150,12 @@ class Generator(object):
name, info, tp_type, elt = arg
ctype, gtype, marshaller, pointer = info
- self.d(' * @%s: %s' % (name,
- xml_escape(get_docstring(elt) or '(Undocumented)')))
+ 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')
@@ -432,9 +447,14 @@ class Generator(object):
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, xml_escape(get_docstring(elt) or '(Undocumented)')))
+ % (name, docs))
self.d(' * @error: %NULL on success, or an error on failure')
self.d(' * @user_data: user-supplied data')
@@ -687,8 +707,13 @@ class Generator(object):
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, xml_escape(get_docstring(elt) or '(Undocumented)')))
+ % (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 ')
@@ -758,9 +783,11 @@ class Generator(object):
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(' {')
@@ -832,9 +859,8 @@ class Generator(object):
self.b('}')
self.b('')
- if self.generate_reentrant:
- self.do_method_reentrant(method, iface_lc, member, member_lc,
- in_args, out_args, collect_callback)
+ 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('')
@@ -853,6 +879,10 @@ class Generator(object):
# 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;')
@@ -930,12 +960,12 @@ class Generator(object):
if self.deprecate_reentrant:
self.h('#ifndef %s' % self.deprecate_reentrant)
- self.h('gboolean %s_%s_run_%s (%sproxy,'
- % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg))
+ self.h('gboolean %s (%sproxy,'
+ % (run_method_name, self.proxy_arg))
self.h(' gint timeout_ms,')
self.d('/**')
- self.d(' * %s_%s_run_%s:' % (self.prefix_lc, iface_lc, member_lc))
+ self.d(' * %s:' % run_method_name)
self.d(' * @proxy: %s' % self.proxy_doc)
self.d(' * @timeout_ms: Timeout in milliseconds, or -1 for default')
@@ -943,8 +973,13 @@ class Generator(object):
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, xml_escape(get_docstring(elt) or '(Undocumented)')))
+ % (name, docs))
for arg in out_args:
name, info, tp_type, elt = arg
@@ -981,8 +1016,8 @@ class Generator(object):
self.d(' */')
self.d('')
- self.b('gboolean\n%s_%s_run_%s (%sproxy,'
- % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg))
+ self.b('gboolean\n%s (%sproxy,'
+ % (run_method_name, self.proxy_arg))
self.b(' gint timeout_ms,')
for arg in in_args:
@@ -1031,8 +1066,10 @@ class Generator(object):
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;')
@@ -1140,6 +1177,11 @@ class Generator(object):
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('')
@@ -1198,10 +1240,13 @@ class Generator(object):
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))
- open(self.basename + '-gtk-doc.h', 'w').write('\n'.join(self.__docs))
+ 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]
@@ -1211,8 +1256,8 @@ 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='])
+ 'generate-reentrant=', 'deprecate-reentrant=',
+ 'deprecation-attribute=', 'guard='])
opts = {}