~ubuntu-branches/ubuntu/precise/libtelepathy/precise

« back to all changes in this revision

Viewing changes to tools/libtp-marshaller-gen.py

  • Committer: Bazaar Package Importer
  • Author(s): Simon McVittie, Laurent Bigonville, Simon McVittie
  • Date: 2007-11-26 11:21:59 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20071126112159-ftf8bitsi2ote4cq
Tags: 0.3.1-1
[ Laurent Bigonville ]
* Use now official Vcs-* field
* Use new Homepage field instead of old pseudo-field

[ Simon McVittie ]
* New upstream release
* Bump shlibs
* Now depends on telepathy-glib and build-depends on python
* Add XS-Dm-Upload-Allowed: yes so I can upload it in future

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys
 
4
import xml.dom.minidom
 
5
from string import ascii_letters, digits
 
6
 
 
7
 
 
8
from libglibcodegen import Signature, type_to_gtype, cmp_by_name
 
9
 
 
10
 
 
11
NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
 
12
 
 
13
class Generator(object):
 
14
 
 
15
    def __init__(self, dom):
 
16
        self.dom = dom
 
17
        self.macros = []
 
18
 
 
19
    def do_signal(self, node_name, iface, signal):
 
20
        marshaller_items = []
 
21
        gtypes = []
 
22
 
 
23
        for i in signal.getElementsByTagName('arg'):
 
24
            name = i.getAttribute('name')
 
25
            type = i.getAttribute('type')
 
26
            info = type_to_gtype(type)
 
27
            # type, GType, STRING, is a pointer
 
28
 
 
29
            marshaller = info[2]
 
30
            if info[1] == 'DBUS_TYPE_G_OBJECT_PATH':
 
31
                # should really be BOXED, but libtelepathy has historically
 
32
                # used OBJECT, and if we're being pedantic, the marshaller
 
33
                # stuff is part of the ABI. The choice doesn't really matter
 
34
                # since in the calling convention they're both pointers.
 
35
                # FIXME: remove this when libtelepathy merges into tp-glib
 
36
                marshaller = 'OBJECT'
 
37
            marshaller_items.append(marshaller)
 
38
 
 
39
            gtype = info[1]
 
40
            if marshaller == 'BOXED':
 
41
                # dbus-glib uses the fundamental type anyway, so all BOXED
 
42
                # subtypes are equivalent
 
43
                gtype = 'G_TYPE_BOXED'
 
44
            gtypes.append(gtype)
 
45
 
 
46
        prefix = 'tp_ifaces_signals_marshal'
 
47
 
 
48
        if (len(marshaller_items) in (0, 1)
 
49
            or marshaller_items == ['UINT', 'POINTER']):
 
50
            # GLib has built-in marshallers for these
 
51
            prefix = 'g_cclosure_marshal'
 
52
        elif node_name == '/Connection':
 
53
            prefix = 'tp_conn_signals_marshal'
 
54
        elif node_name == '/Channel':
 
55
            prefix = 'tp_chan_signals_marshal'
 
56
        elif node_name == '/Connection_Manager':
 
57
            prefix = 'tp_connmgr_signals_marshal'
 
58
 
 
59
        print "/* %s: %s */ \\" % (node_name, signal.getAttribute('name'))
 
60
        print "dbus_g_object_register_marshaller ( \\"
 
61
        print ("    %s_VOID__" % prefix
 
62
                + '_'.join((marshaller_items or ['VOID'])) + ', \\')
 
63
        print '    G_TYPE_NONE, \\'
 
64
        for gtype in gtypes:
 
65
            print '    ' + gtype + ', \\'
 
66
        print '    G_TYPE_INVALID); \\'
 
67
 
 
68
    def __call__(self):
 
69
        ifaces = self.dom.getElementsByTagName('node')
 
70
        ifaces.sort(cmp_by_name)
 
71
 
 
72
        for iface in ifaces:
 
73
            self.do_interface(iface)
 
74
 
 
75
        print '#define REGISTER_ALL_MARSHALLERS G_STMT_START {\\'
 
76
        for macro in self.macros:
 
77
            print '%s; \\' % macro
 
78
        print '} G_STMT_END'
 
79
 
 
80
    def do_interface(self, node):
 
81
        ifaces = node.getElementsByTagName('interface')
 
82
        assert len(ifaces) == 1
 
83
        iface = ifaces[0]
 
84
        name = node.getAttribute('name')
 
85
        self.macros.append('REGISTER_MARSHALLERS_FOR_%s'
 
86
            % name.replace('/', '').upper())
 
87
        print ('#define REGISTER_MARSHALLERS_FOR_%s \\'
 
88
            % name.replace('/', '').upper())
 
89
        print 'G_STMT_START { \\'
 
90
        signals = iface.getElementsByTagName('signal')
 
91
        signals.sort(cmp_by_name)
 
92
 
 
93
        for signal in signals:
 
94
            self.do_signal(name, iface, signal)
 
95
 
 
96
        print '} G_STMT_END'
 
97
        print
 
98
 
 
99
 
 
100
def types_to_gtypes(types):
 
101
    return [type_to_gtype(t)[1] for t in types]
 
102
 
 
103
if __name__ == '__main__':
 
104
    argv = sys.argv[1:]
 
105
    dom = xml.dom.minidom.parse(argv[0])
 
106
 
 
107
    Generator(dom)()