Mercurial > libervia-backend
annotate src/bridge/DBus.py @ 267:bdcd535e179e
Bridge constructor:
- moved constructor files in src/bridge/bridge_constructor
- frontend side can now be generated
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 24 Jan 2011 21:19:11 +0100 |
parents | c4b84a2d2ad1 |
children | 1d2e0dfe7114 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 from bridge import Bridge | |
24 import dbus | |
25 import dbus.service | |
26 import dbus.mainloop.glib | |
27 from logging import debug, info, error | |
28 | |
10 | 29 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
30 const_COMM_SUFFIX = ".communication" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
31 const_REQ_SUFFIX = ".request" |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
32 |
0 | 33 class DbusObject(dbus.service.Object): |
34 | |
35 def __init__(self, bus, path): | |
36 dbus.service.Object.__init__(self, bus, path) | |
37 debug("Init DbusObject...") | |
38 self.cb={} | |
39 | |
40 def register(self, name, cb): | |
41 self.cb[name]=cb | |
42 | |
43 ### signals ### | |
44 | |
267 | 45 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
46 signature='ssa{ss}') | |
47 def actionResult(self, answer_type, id, data): | |
48 pass | |
49 | |
50 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, | |
51 signature='ssa{sa{ss}}') | |
52 def actionResultExt(self, answer_type, id, data): | |
53 pass | |
54 | |
55 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, | |
56 signature='ssa{ss}') | |
57 def askConfirmation(self, conf_type, id, data): | |
58 pass | |
59 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
60 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
61 signature='s') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
62 def connected(self, profile): |
267 | 63 pass |
64 | |
52 | 65 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
66 signature='ss') |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
67 def connection_error(self, error_type, profile): |
267 | 68 pass |
0 | 69 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
70 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 71 signature='ss') |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
72 def contactDeleted(self, entity, profile): |
267 | 73 pass |
74 | |
75 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
76 signature='s') | |
77 def disconnected(self, profile): | |
78 pass | |
79 | |
80 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
81 signature='ssss') | |
82 def newAlert(self, message, title, alert_type, profile): | |
83 pass | |
84 | |
85 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
86 signature='sa{ss}ass') | |
87 def newContact(self, contact, attributes, groups, profile): | |
88 pass | |
0 | 89 |
267 | 90 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
91 signature='sssss') | |
92 def newMessage(self, from_jid, message, mess_type, to_jid, profile): | |
93 pass | |
94 | |
95 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
96 signature='ssss') | |
97 def paramUpdate(self, name, value, category, profile): | |
98 pass | |
0 | 99 |
267 | 100 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
101 signature='ssia{ss}s') | |
102 def presenceUpdate(self, entity, show, priority, statuses, profile): | |
103 pass | |
104 | |
105 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
106 signature='sss') | |
107 def subscribe(self, sub_type, entity, profile): | |
108 pass | |
109 | |
49 | 110 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
111 signature='sa{ss}') | |
112 def updatedValue(self, name, value): | |
267 | 113 pass |
114 | |
49 | 115 |
0 | 116 ### methods ### |
267 | 117 |
118 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
119 in_signature='ss', out_signature='') | |
120 def addContact(self, entity, profile_key="@DEFAULT@"): | |
121 return self.cb["addContact"](unicode(entity), unicode(profile_key)) | |
0 | 122 |
267 | 123 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
124 in_signature='ssss', out_signature='s') | |
125 def callMenu(self, category, name, menu_type, profile_key): | |
126 return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key)) | |
127 | |
128 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
129 in_signature='sba{ss}', out_signature='') | |
130 def confirmationAnswer(self, id, accepted, data): | |
131 return self.cb["confirmationAnswer"](unicode(id), accepted, data) | |
132 | |
133 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
134 in_signature='s', out_signature='') | |
135 def connect(self, profile_key="@DEFAULT@"): | |
136 return self.cb["connect"](unicode(profile_key)) | |
137 | |
138 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
139 in_signature='s', out_signature='i') | |
140 def createProfile(self, profile): | |
141 return self.cb["createProfile"](unicode(profile)) | |
142 | |
143 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
144 in_signature='ss', out_signature='') | |
145 def delContact(self, entity, profile_key="@DEFAULT@"): | |
146 return self.cb["delContact"](unicode(entity), unicode(profile_key)) | |
147 | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
148 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
267 | 149 in_signature='s', out_signature='i') |
150 def deleteProfile(self, profile): | |
151 return self.cb["deleteProfile"](unicode(profile)) | |
152 | |
153 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
154 in_signature='s', out_signature='') | |
155 def disconnect(self, profile_key="@DEFAULT@"): | |
156 return self.cb["disconnect"](unicode(profile_key)) | |
157 | |
158 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
159 in_signature='s', out_signature='a(sa{ss}as)') | |
160 def getContacts(self, profile_key="@DEFAULT@"): | |
161 return self.cb["getContacts"](unicode(profile_key)) | |
162 | |
163 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
164 in_signature='ssi', out_signature='a{i(ss)}') | |
165 def getHistory(self, from_jid, to_jid, size): | |
166 return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size) | |
167 | |
168 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
169 in_signature='sss', out_signature='s') | |
170 def getMenuHelp(self, category, name, menu_type): | |
171 return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type)) | |
172 | |
173 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
174 in_signature='', out_signature='a(sss)') | |
175 def getMenus(self, ): | |
176 return self.cb["getMenus"]() | |
177 | |
178 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
179 in_signature='sss', out_signature='s') | |
180 def getParamA(self, name, category, profile_key="@DEFAULT@"): | |
181 return self.cb["getParamA"](unicode(name), unicode(category), unicode(profile_key)) | |
182 | |
183 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
184 in_signature='s', out_signature='s') | |
185 def getParams(self, profile_key="@DEFAULT@"): | |
186 return self.cb["getParams"](unicode(profile_key)) | |
187 | |
188 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
189 in_signature='', out_signature='as') | |
190 def getParamsCategories(self, ): | |
191 return self.cb["getParamsCategories"]() | |
192 | |
193 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
194 in_signature='ss', out_signature='s') | |
195 def getParamsForCategory(self, category, profile_key="@DEFAULT@"): | |
196 return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key)) | |
197 | |
198 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
199 in_signature='s', out_signature='s') | |
200 def getParamsUI(self, profile_key="@DEFAULT@"): | |
201 return self.cb["getParamsUI"](unicode(profile_key)) | |
202 | |
203 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
204 in_signature='s', out_signature='a{sa{s(sia{ss})}}') | |
205 def getPresenceStatus(self, profile_key="@DEFAULT@"): | |
206 return self.cb["getPresenceStatus"](unicode(profile_key)) | |
207 | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
208 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
209 in_signature='s', out_signature='s') |
267 | 210 def getProfileName(self, profile_key="@DEFAULT@"): |
211 return self.cb["getProfileName"](unicode(profile_key)) | |
212 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
213 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
214 in_signature='', out_signature='as') |
267 | 215 def getProfilesList(self, ): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
216 return self.cb["getProfilesList"]() |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
217 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
218 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
267 | 219 in_signature='s', out_signature='a{ss}') |
220 def getProgress(self, id): | |
221 return self.cb["getProgress"](unicode(id)) | |
68 | 222 |
223 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
267 | 224 in_signature='', out_signature='s') |
225 def getVersion(self, ): | |
226 return self.cb["getVersion"]() | |
227 | |
228 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
229 in_signature='s', out_signature='a{ss}') | |
230 def getWaitingSub(self, profile_key="@DEFAULT@"): | |
231 return self.cb["getWaitingSub"](unicode(profile_key)) | |
232 | |
233 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
234 in_signature='s', out_signature='b') | |
235 def isConnected(self, profile_key="@DEFAULT@"): | |
236 return self.cb["isConnected"](unicode(profile_key)) | |
237 | |
238 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
239 in_signature='sa{ss}s', out_signature='s') | |
240 def launchAction(self, action_type, data, profile_key="@DEFAULT@"): | |
241 return self.cb["launchAction"](unicode(action_type), data, unicode(profile_key)) | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
242 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
243 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
244 in_signature='sssi', out_signature='s') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
245 def registerNewAccount(self, login, password, host, port=5222): |
267 | 246 return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(host), port) |
0 | 247 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
248 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
260
c8406fe5e81e
Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
249 in_signature='sssss', out_signature='') |
267 | 250 def sendMessage(self, to_jid, message, subject=, mess_type="chat", profile_key="@DEFAULT@"): |
251 return self.cb["sendMessage"](unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), unicode(profile_key)) | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
252 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
253 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
254 in_signature='ssss', out_signature='') |
267 | 255 def setParam(self, name, value, category, profile_key="@DEFAULT@"): |
256 return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key)) | |
105 | 257 |
258 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
267 | 259 in_signature='ssia{ss}s', out_signature='') |
260 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): | |
261 return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key)) | |
0 | 262 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
263 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
267 | 264 in_signature='sss', out_signature='') |
265 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): | |
266 return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key)) | |
0 | 267 |
101 | 268 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
269 def __attribute_string(self, in_sign): |
267 | 270 """Return arguments to user given a in_sign |
271 @param in_sign: in_sign in the short form (using s,a,i,b etc) | |
272 @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
273 i=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
274 idx=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
275 attr_string="" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
276 while i<len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
277 if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']: |
267 | 278 raise ParseError("Unmanaged attribute type [%c]" % in_sign[i]) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
279 |
267 | 280 attr_string += ("" if idx==0 else ", ") + ("arg_%i" % idx) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
281 idx+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
282 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
283 if in_sign[i] == 'a': |
73 | 284 i+=1 |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
285 if in_sign[i]!='{' and in_sign[i]!='(': #FIXME: must manage tuples out of arrays |
73 | 286 i+=1 |
287 continue #we have a simple type for the array | |
267 | 288 opening_car = in_sign[i] |
289 assert(opening_car in ['{','(']) | |
290 closing_car = '}' if opening_car == '{' else ')' | |
291 opening_count = 1 | |
73 | 292 while (True): #we have a dict or a list of tuples |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
293 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
294 if i>=len(in_sign): |
267 | 295 raise ParseError("missing }") |
296 if in_sign[i] == opening_car: | |
297 opening_count+=1 | |
298 if in_sign[i] == closing_car: | |
299 opening_count-=1 | |
300 if opening_count == 0: | |
301 break | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
302 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
303 return attr_string |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
304 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
305 def addMethod(self, name, int_suffix, in_sign, out_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
306 """Dynamically add a method to Dbus Bridge""" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
307 #FIXME: Better way ??? |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
308 attributes = self.__attribute_string(in_sign) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
309 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
310 code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec') |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
311 exec (code) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
312 method = locals()[name] |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
313 setattr(DbusObject, name, dbus.service.method( |
10 | 314 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) |
73 | 315 |
316 def addSignal(self, name, int_suffix, signature): | |
317 """Dynamically add a signal to Dbus Bridge""" | |
318 #FIXME: Better way ??? | |
319 attributes = self.__attribute_string(signature) | |
320 | |
321 code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') | |
322 exec (code) | |
323 signal = locals()[name] | |
324 setattr(DbusObject, name, dbus.service.signal( | |
325 const_INT_PREFIX+int_suffix, signature=signature)(signal)) | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
326 |
0 | 327 class DBusBridge(Bridge): |
328 def __init__(self): | |
329 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
330 Bridge.__init__(self) | |
331 info ("Init DBus...") | |
332 self.session_bus = dbus.SessionBus() | |
10 | 333 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) |
0 | 334 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') |
335 | |
267 | 336 def actionResult(self, answer_type, id, data): |
337 self.dbus_bridge.actionResult(answer_type, id, data) | |
338 | |
339 def actionResultExt(self, answer_type, id, data): | |
340 self.dbus_bridge.actionResultExt(answer_type, id, data) | |
341 | |
342 def askConfirmation(self, conf_type, id, data): | |
343 self.dbus_bridge.askConfirmation(conf_type, id, data) | |
344 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
345 def connected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
346 self.dbus_bridge.connected(profile) |
267 | 347 |
348 def connection_error(self, error_type, profile): | |
349 self.dbus_bridge.connection_error(error_type, profile) | |
350 | |
351 def contactDeleted(self, entity, profile): | |
352 self.dbus_bridge.contactDeleted(entity, profile) | |
353 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
354 def disconnected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
355 self.dbus_bridge.disconnected(profile) |
267 | 356 |
357 def newAlert(self, message, title, alert_type, profile): | |
358 self.dbus_bridge.newAlert(message, title, alert_type, profile) | |
359 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
360 def newContact(self, contact, attributes, groups, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
361 self.dbus_bridge.newContact(contact, attributes, groups, profile) |
0 | 362 |
267 | 363 def newMessage(self, from_jid, message, mess_type, to_jid, profile): |
364 self.dbus_bridge.newMessage(from_jid, message, mess_type, to_jid, profile) | |
0 | 365 |
267 | 366 def paramUpdate(self, name, value, category, profile): |
367 self.dbus_bridge.paramUpdate(name, value, category, profile) | |
368 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
369 def presenceUpdate(self, entity, show, priority, statuses, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
370 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) |
49 | 371 |
221
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
372 def subscribe(self, sub_type, entity, profile): |
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
373 self.dbus_bridge.subscribe(sub_type, entity, profile) |
0 | 374 |
49 | 375 def updatedValue(self, name, value): |
376 self.dbus_bridge.updatedValue(name, value) | |
377 | |
267 | 378 |
0 | 379 def register(self, name, callback): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
380 debug("registering DBus bridge method [%s]", name) |
0 | 381 self.dbus_bridge.register(name, callback) |
382 | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
383 def addMethod(self, name, int_suffix, in_sign, out_sign, method): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
384 """Dynamically add a method to Dbus Bridge""" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
385 print ("Adding method [%s] to DBus bridge" % name) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
386 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
387 self.register(name, method) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
388 |
73 | 389 def addSignal(self, name, int_suffix, signature): |
390 self.dbus_bridge.addSignal(name, int_suffix, signature) | |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
391 setattr(DBusBridge, name, getattr(self.dbus_bridge, name)) |