Mercurial > libervia-backend
comparison libervia/backend/bridge/bridge_constructor/constructors/dbus-xml/constructor.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/bridge/bridge_constructor/constructors/dbus-xml/constructor.py@524856bd7b19 |
children |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 # Libervia: an XMPP client | |
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from libervia.backend.bridge.bridge_constructor import base_constructor | |
21 from xml.dom import minidom | |
22 import sys | |
23 | |
24 | |
25 class DbusXmlConstructor(base_constructor.Constructor): | |
26 """Constructor for DBus XML syntaxt (used by Qt frontend)""" | |
27 | |
28 def __init__(self, bridge_template, options): | |
29 base_constructor.Constructor.__init__(self, bridge_template, options) | |
30 | |
31 self.template = "dbus_xml_template.xml" | |
32 self.core_dest = "org.libervia.sat.xml" | |
33 self.default_annotation = { | |
34 "a{ss}": "StringDict", | |
35 "a(sa{ss}as)": "QList<Contact>", | |
36 "a{i(ss)}": "HistoryT", | |
37 "a(sss)": "QList<MenuT>", | |
38 "a{sa{s(sia{ss})}}": "PresenceStatusT", | |
39 } | |
40 | |
41 def generate_core_side(self): | |
42 try: | |
43 doc = minidom.parse(self.get_template_path(self.template)) | |
44 interface_elt = doc.getElementsByTagName("interface")[0] | |
45 except IOError: | |
46 print("Can't access template") | |
47 sys.exit(1) | |
48 except IndexError: | |
49 print("Template error") | |
50 sys.exit(1) | |
51 | |
52 sections = self.bridge_template.sections() | |
53 sections.sort() | |
54 for section in sections: | |
55 function = self.getValues(section) | |
56 print(("Adding %s %s" % (section, function["type"]))) | |
57 new_elt = doc.createElement( | |
58 "method" if function["type"] == "method" else "signal" | |
59 ) | |
60 new_elt.setAttribute("name", section) | |
61 | |
62 idx = 0 | |
63 args_doc = self.get_arguments_doc(section) | |
64 for arg in self.arguments_parser(function["sig_in"] or ""): | |
65 arg_elt = doc.createElement("arg") | |
66 arg_elt.setAttribute( | |
67 "name", args_doc[idx][0] if idx in args_doc else "arg_%i" % idx | |
68 ) | |
69 arg_elt.setAttribute("type", arg) | |
70 _direction = "in" if function["type"] == "method" else "out" | |
71 arg_elt.setAttribute("direction", _direction) | |
72 new_elt.appendChild(arg_elt) | |
73 if "annotation" in self.args.flags: | |
74 if arg in self.default_annotation: | |
75 annot_elt = doc.createElement("annotation") | |
76 annot_elt.setAttribute( | |
77 "name", "com.trolltech.QtDBus.QtTypeName.In%d" % idx | |
78 ) | |
79 annot_elt.setAttribute("value", self.default_annotation[arg]) | |
80 new_elt.appendChild(annot_elt) | |
81 idx += 1 | |
82 | |
83 if function["sig_out"]: | |
84 arg_elt = doc.createElement("arg") | |
85 arg_elt.setAttribute("type", function["sig_out"]) | |
86 arg_elt.setAttribute("direction", "out") | |
87 new_elt.appendChild(arg_elt) | |
88 if "annotation" in self.args.flags: | |
89 if function["sig_out"] in self.default_annotation: | |
90 annot_elt = doc.createElement("annotation") | |
91 annot_elt.setAttribute( | |
92 "name", "com.trolltech.QtDBus.QtTypeName.Out0" | |
93 ) | |
94 annot_elt.setAttribute( | |
95 "value", self.default_annotation[function["sig_out"]] | |
96 ) | |
97 new_elt.appendChild(annot_elt) | |
98 | |
99 interface_elt.appendChild(new_elt) | |
100 | |
101 # now we write to final file | |
102 self.final_write(self.core_dest, [doc.toprettyxml()]) |