~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/client/android/JavaJNI2CJNI_Load.py

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import getopt, sys
 
3
import re
 
4
from string import Template
 
5
 
 
6
def type_to_signature(itype):
 
7
        if len(itype) > 2:
 
8
                if itype[-2:] == '[]':
 
9
                        return "[%s" % type_to_signature(itype[:-2])
 
10
        if itype == "int":
 
11
                return "I"
 
12
        if itype == "long":
 
13
                return "J"
 
14
        if itype == "void":
 
15
                return "V"
 
16
        if itype == "boolean":
 
17
                return "Z"
 
18
        if itype == "byte":
 
19
                return "B"
 
20
        if itype == "char":
 
21
                return "C"
 
22
        if itype == "short":
 
23
                return "S"
 
24
        if itype == "float":
 
25
                return "F"
 
26
        if itype == "double":
 
27
                return "D"
 
28
        if itype == "String":
 
29
                return "Ljava/lang/String;"
 
30
        if itype == "Object":
 
31
                return "Ljava/lang/Object;"
 
32
        return "Lorg/sflphone/service/%s;" % itype
 
33
 
 
34
def parse_java_file(input_stream, package, module):
 
35
        outputs = []
 
36
        package_prefix = "Java_%s_%sJNI" % (package.replace(".", "_"), module)
 
37
        for line in input_stream:
 
38
                definition = re.match(r'.*public final static native ([^\( ]*) ([^\)]*)\(([^)]*)\).*',line)
 
39
                if definition is not None:
 
40
                        retour = definition.group(1)
 
41
                        name = definition.group(2)
 
42
                        args = definition.group(3)
 
43
                        args_sigs = []
 
44
                        args_frags = args.split(',')
 
45
                        for args_frag in args_frags:
 
46
                                argf = re.match(r'(\b)?([^ ]+) .*', args_frag.strip())
 
47
                                if argf is not None:
 
48
                                        args_sigs.append(type_to_signature(argf.group(2)))
 
49
                        sig = "(%s)%s" % (''.join(args_sigs), type_to_signature(retour))
 
50
                        outputs.append("{\"%s\", \"%s\", (void*)& %s_%s}" % (name, sig, package_prefix, name.replace('_', '_1')))
 
51
        return outputs
 
52
 
 
53
def render_to_template(defs, template_string):
 
54
        template = Template(template_string)
 
55
        return template.substitute(defs= ",\r\n".join(defs) )
 
56
 
 
57
 
 
58
if __name__ == "__main__":
 
59
        try:
 
60
                opts, args = getopt.getopt(sys.argv[1:], "i:o:t:m:p:", ["input=", "output=", "template=", "module=", "package="])
 
61
        except getopt.GetoptError, err:
 
62
                # print help information and exit:
 
63
                print str(err) # will print something like "option -a not recognized"
 
64
                sys.exit(2)
 
65
        input_stream = None
 
66
        output_file = None
 
67
        template_string = None
 
68
        package = ""
 
69
        module = ""
 
70
        for o, a in opts:
 
71
                if o in ("-i", "--input"):
 
72
                        input_stream = open(a)
 
73
                if o in ("-o", "--output"):
 
74
                        output_file = open(a, "w")
 
75
                if o in ("-t", "--template"):
 
76
                        template_string = open(a).read()
 
77
                if o in ("-m", "--module"):
 
78
                        module = a
 
79
                if o in ("-p", "--package"):
 
80
                        package = a
 
81
 
 
82
        defs = parse_java_file(input_stream, package, module)
 
83
        output_file.write(render_to_template(defs, template_string))
 
84
        output_file.close()
 
85
        input_stream.close()