Changeset View
Changeset View
Standalone View
Standalone View
tools/qt-client-gen.py
Show All 15 Lines | |||||
16 | # You should have received a copy of the GNU Lesser General Public | 16 | # You should have received a copy of the GNU Lesser General Public | ||
17 | # License along with this library; if not, write to the Free Software | 17 | # License along with this library; if not, write to the Free Software | ||
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | 19 | | |||
20 | from sys import argv | 20 | from sys import argv | ||
21 | import xml.dom.minidom | 21 | import xml.dom.minidom | ||
22 | import codecs | 22 | import codecs | ||
23 | from getopt import gnu_getopt | 23 | from getopt import gnu_getopt | ||
24 | import functools | ||||
24 | 25 | | |||
25 | from libtpcodegen import NS_TP, get_descendant_text, get_by_path | 26 | from libtpcodegen import NS_TP, get_descendant_text, get_by_path | ||
26 | from libqtcodegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt_name, qt_identifier_escape, RefRegistry | 27 | from libqtcodegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt_name, qt_identifier_escape, RefRegistry | ||
27 | 28 | | |||
28 | class Generator(object): | 29 | class Generator(object): | ||
29 | def __init__(self, opts): | 30 | def __init__(self, opts): | ||
30 | try: | 31 | try: | ||
31 | self.group = opts.get('--group', '') | 32 | self.group = opts.get('--group', '') | ||
32 | self.headerfile = opts['--headerfile'] | 33 | self.headerfile = opts['--headerfile'] | ||
33 | self.implfile = opts['--implfile'] | 34 | self.implfile = opts['--implfile'] | ||
34 | self.namespace = opts['--namespace'] | 35 | self.namespace = opts['--namespace'] | ||
35 | self.typesnamespace = opts['--typesnamespace'] | 36 | self.typesnamespace = opts['--typesnamespace'] | ||
36 | self.realinclude = opts['--realinclude'] | 37 | self.realinclude = opts['--realinclude'] | ||
37 | self.prettyinclude = opts.get('--prettyinclude') | 38 | self.prettyinclude = opts.get('--prettyinclude') | ||
38 | self.extraincludes = opts.get('--extraincludes', None) | 39 | self.extraincludes = opts.get('--extraincludes', None) | ||
39 | self.mainiface = opts.get('--mainiface', None) | 40 | self.mainiface = opts.get('--mainiface', None) | ||
40 | self.must_define = opts.get('--must-define', None) | 41 | self.must_define = opts.get('--must-define', None) | ||
41 | self.dbus_proxy = opts.get('--dbus-proxy', | 42 | self.dbus_proxy = opts.get('--dbus-proxy', | ||
42 | 'Tp::DBusProxy') | 43 | 'Tp::DBusProxy') | ||
43 | self.visibility = opts.get('--visibility', '') | 44 | self.visibility = opts.get('--visibility', '') | ||
44 | ifacedom = xml.dom.minidom.parse(opts['--ifacexml']) | 45 | ifacedom = xml.dom.minidom.parse(opts['--ifacexml']) | ||
45 | specdom = xml.dom.minidom.parse(opts['--specxml']) | 46 | specdom = xml.dom.minidom.parse(opts['--specxml']) | ||
46 | except KeyError, k: | 47 | except KeyError as k: | ||
47 | assert False, 'Missing required parameter %s' % k.args[0] | 48 | assert False, 'Missing required parameter %s' % k.args[0] | ||
48 | 49 | | |||
49 | self.hs = [] | 50 | self.hs = [] | ||
50 | self.bs = [] | 51 | self.bs = [] | ||
51 | self.ifacenodes = ifacedom.getElementsByTagName('node') | 52 | self.ifacenodes = ifacedom.getElementsByTagName('node') | ||
52 | self.spec, = get_by_path(specdom, "spec") | 53 | self.spec, = get_by_path(specdom, "spec") | ||
53 | self.custom_lists = gather_custom_lists(self.spec, self.typesnamespace) | 54 | self.custom_lists = gather_custom_lists(self.spec, self.typesnamespace) | ||
54 | self.externals = gather_externals(self.spec) | 55 | self.externals = gather_externals(self.spec) | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 107 | """ % self.realinclude) | |||
109 | for ns in self.namespace.split('::'): | 110 | for ns in self.namespace.split('::'): | ||
110 | self.hb("""\ | 111 | self.hb("""\ | ||
111 | namespace %s | 112 | namespace %s | ||
112 | { | 113 | { | ||
113 | """ % ns) | 114 | """ % ns) | ||
114 | 115 | | |||
115 | # Output interface proxies | 116 | # Output interface proxies | ||
116 | def ifacenodecmp(x, y): | 117 | def ifacenodecmp(x, y): | ||
117 | xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in x, y] | 118 | xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in (x, y)] | ||
118 | 119 | | |||
119 | if xname == self.mainiface: | 120 | if xname == self.mainiface: | ||
120 | return -1 | 121 | return -1 | ||
121 | elif yname == self.mainiface: | 122 | elif yname == self.mainiface: | ||
122 | return 1 | 123 | return 1 | ||
123 | else: | 124 | else: | ||
124 | return cmp(xname, yname) | 125 | return (xname > yname) - (xname < yname) | ||
125 | 126 | | |||
126 | self.ifacenodes.sort(cmp=ifacenodecmp) | 127 | self.ifacenodes.sort(key=functools.cmp_to_key(ifacenodecmp)) | ||
127 | for ifacenode in self.ifacenodes: | 128 | for ifacenode in self.ifacenodes: | ||
128 | self.do_ifacenode(ifacenode) | 129 | self.do_ifacenode(ifacenode) | ||
129 | 130 | | |||
130 | # End namespace | 131 | # End namespace | ||
131 | self.hb(''.join(['}\n' for ns in self.namespace.split('::')])) | 132 | self.hb(''.join(['}\n' for ns in self.namespace.split('::')])) | ||
132 | 133 | | |||
133 | # Add metatype declaration - otherwise QTBUG #2151 might be triggered | 134 | # Add metatype declaration - otherwise QTBUG #2151 might be triggered | ||
134 | for ifacenode in self.ifacenodes: | 135 | for ifacenode in self.ifacenodes: | ||
135 | classname = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' | 136 | classname = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' | ||
136 | self.h("Q_DECLARE_METATYPE(" + self.namespace + "::" + classname + "*)\n") | 137 | self.h("Q_DECLARE_METATYPE(" + self.namespace + "::" + classname + "*)\n") | ||
137 | 138 | | |||
138 | # Write output to files | 139 | # Write output to files | ||
139 | (codecs.getwriter('utf-8')(open(self.headerfile, 'w'))).write(''.join(self.hs)) | 140 | (codecs.getwriter('utf-8')(open(self.headerfile, 'wb'))).write(''.join(self.hs)) | ||
140 | (codecs.getwriter('utf-8')(open(self.implfile, 'w'))).write(''.join(self.bs)) | 141 | (codecs.getwriter('utf-8')(open(self.implfile, 'wb'))).write(''.join(self.bs)) | ||
141 | 142 | | |||
142 | def do_ifacenode(self, ifacenode): | 143 | def do_ifacenode(self, ifacenode): | ||
143 | # Extract info | 144 | # Extract info | ||
144 | name = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' | 145 | name = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' | ||
145 | iface, = get_by_path(ifacenode, 'interface') | 146 | iface, = get_by_path(ifacenode, 'interface') | ||
146 | dbusname = iface.getAttribute('name') | 147 | dbusname = iface.getAttribute('name') | ||
147 | 148 | | |||
148 | # Begin class, constructors | 149 | # Begin class, constructors | ||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Line(s) | 403 | def do_method(self, method): | |||
403 | name = method.getAttribute('name') | 404 | name = method.getAttribute('name') | ||
404 | args = get_by_path(method, 'arg') | 405 | args = get_by_path(method, 'arg') | ||
405 | argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, | 406 | argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, | ||
406 | self.externals, self.typesnamespace, self.refs, ' * ') | 407 | self.externals, self.typesnamespace, self.refs, ' * ') | ||
407 | 408 | | |||
408 | inargs = [] | 409 | inargs = [] | ||
409 | outargs = [] | 410 | outargs = [] | ||
410 | 411 | | |||
411 | for i in xrange(len(args)): | 412 | for i in range(len(args)): | ||
412 | if args[i].getAttribute('direction') == 'out': | 413 | if args[i].getAttribute('direction') == 'out': | ||
413 | outargs.append(i) | 414 | outargs.append(i) | ||
414 | else: | 415 | else: | ||
415 | inargs.append(i) | 416 | inargs.append(i) | ||
416 | assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name) | 417 | assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name) | ||
417 | 418 | | |||
418 | rettypes = ', '.join([argbindings[i].val for i in outargs]) | 419 | rettypes = ', '.join([argbindings[i].val for i in outargs]) | ||
419 | params = ', '.join([argbindings[i].inarg + ' ' + argnames[i] for i in inargs]) | 420 | params = ', '.join([argbindings[i].inarg + ' ' + argnames[i] for i in inargs]) | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 488 | argnames, argdocstrings, argbindings = extract_arg_or_member_info(get_by_path(signal, | |||
488 | 'arg'), self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') | 489 | 'arg'), self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') | ||
489 | 490 | | |||
490 | self.h(""" | 491 | self.h(""" | ||
491 | /** | 492 | /** | ||
492 | * Represents the signal \\c %s on the remote object. | 493 | * Represents the signal \\c %s on the remote object. | ||
493 | %s\ | 494 | %s\ | ||
494 | """ % (name, format_docstring(signal, self.refs, ' * '))) | 495 | """ % (name, format_docstring(signal, self.refs, ' * '))) | ||
495 | 496 | | |||
496 | for i in xrange(len(argnames)): | 497 | for i in range(len(argnames)): | ||
497 | assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) | 498 | assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) | ||
498 | if argdocstrings[i]: | 499 | if argdocstrings[i]: | ||
499 | self.h("""\ | 500 | self.h("""\ | ||
500 | * | 501 | * | ||
501 | * \\param %s | 502 | * \\param %s | ||
502 | %s\ | 503 | %s\ | ||
503 | """ % (argnames[i], argdocstrings[i])) | 504 | """ % (argnames[i], argdocstrings[i])) | ||
504 | 505 | | |||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |