Mercurial > libervia-backend
annotate src/bridge/DBus.py @ 345:e6047415868d
Bridge: added updateContact method
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 May 2011 20:24:02 +0200 |
parents | 4402ac630712 |
children | 6b5626c37909 |
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 | |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
27 from logging import debug, info |
0 | 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): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
48 pass |
267 | 49 |
50 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, | |
51 signature='ssa{sa{ss}}') | |
52 def actionResultExt(self, answer_type, id, data): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
53 pass |
267 | 54 |
55 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, | |
56 signature='ssa{ss}') | |
57 def askConfirmation(self, conf_type, id, data): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
58 pass |
267 | 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): |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
63 pass |
267 | 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') |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
67 def connectionError(self, error_type, profile): |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
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): |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
73 pass |
267 | 74 |
75 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
76 signature='s') | |
77 def disconnected(self, profile): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
78 pass |
267 | 79 |
80 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
81 signature='ssss') | |
82 def newAlert(self, message, title, alert_type, profile): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
83 pass |
267 | 84 |
85 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
86 signature='sa{ss}ass') | |
87 def newContact(self, contact, attributes, groups, profile): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
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): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
93 pass |
267 | 94 |
95 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
96 signature='ssss') | |
97 def paramUpdate(self, name, value, category, profile): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
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): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
103 pass |
267 | 104 |
105 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
106 signature='sss') | |
107 def subscribe(self, sub_type, entity, profile): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
108 pass |
267 | 109 |
49 | 110 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
111 signature='sa{ss}') | |
112 def updatedValue(self, name, value): | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
113 pass |
267 | 114 |
49 | 115 |
0 | 116 ### methods ### |
267 | 117 |
118 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
119 in_signature='ss', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
120 async_callbacks=None) |
267 | 121 def addContact(self, entity, profile_key="@DEFAULT@"): |
122 return self.cb["addContact"](unicode(entity), unicode(profile_key)) | |
0 | 123 |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
124 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
125 in_signature='s', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
126 async_callbacks=('callback', 'errback')) |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
127 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None): |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
128 return self.cb["asyncConnect"](unicode(profile_key), callback, errback) |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
129 |
267 | 130 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
131 in_signature='ssss', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
132 async_callbacks=None) |
267 | 133 def callMenu(self, category, name, menu_type, profile_key): |
134 return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key)) | |
135 | |
136 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
137 in_signature='sba{ss}', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
138 async_callbacks=None) |
267 | 139 def confirmationAnswer(self, id, accepted, data): |
140 return self.cb["confirmationAnswer"](unicode(id), accepted, data) | |
141 | |
142 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
143 in_signature='s', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
144 async_callbacks=None) |
267 | 145 def connect(self, profile_key="@DEFAULT@"): |
146 return self.cb["connect"](unicode(profile_key)) | |
147 | |
148 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
149 in_signature='s', out_signature='i', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
150 async_callbacks=None) |
267 | 151 def createProfile(self, profile): |
152 return self.cb["createProfile"](unicode(profile)) | |
153 | |
154 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
155 in_signature='ss', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
156 async_callbacks=None) |
267 | 157 def delContact(self, entity, profile_key="@DEFAULT@"): |
158 return self.cb["delContact"](unicode(entity), unicode(profile_key)) | |
159 | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
160 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
161 in_signature='s', out_signature='i', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
162 async_callbacks=None) |
267 | 163 def deleteProfile(self, profile): |
164 return self.cb["deleteProfile"](unicode(profile)) | |
165 | |
166 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
167 in_signature='s', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
168 async_callbacks=None) |
267 | 169 def disconnect(self, profile_key="@DEFAULT@"): |
170 return self.cb["disconnect"](unicode(profile_key)) | |
171 | |
172 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
173 in_signature='s', out_signature='a(sa{ss}as)', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
174 async_callbacks=None) |
267 | 175 def getContacts(self, profile_key="@DEFAULT@"): |
176 return self.cb["getContacts"](unicode(profile_key)) | |
177 | |
178 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
179 in_signature='ssi', out_signature='a{i(ss)}', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
180 async_callbacks=None) |
267 | 181 def getHistory(self, from_jid, to_jid, size): |
182 return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size) | |
183 | |
184 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
185 in_signature='sss', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
186 async_callbacks=None) |
267 | 187 def getMenuHelp(self, category, name, menu_type): |
188 return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type)) | |
189 | |
190 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
191 in_signature='', out_signature='a(sss)', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
192 async_callbacks=None) |
267 | 193 def getMenus(self, ): |
194 return self.cb["getMenus"]() | |
195 | |
196 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
197 in_signature='ssss', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
198 async_callbacks=None) |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
199 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): |
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
200 return self.cb["getParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key)) |
267 | 201 |
202 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
203 in_signature='s', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
204 async_callbacks=None) |
267 | 205 def getParams(self, profile_key="@DEFAULT@"): |
206 return self.cb["getParams"](unicode(profile_key)) | |
207 | |
208 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
209 in_signature='', out_signature='as', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
210 async_callbacks=None) |
267 | 211 def getParamsCategories(self, ): |
212 return self.cb["getParamsCategories"]() | |
213 | |
214 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
215 in_signature='ss', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
216 async_callbacks=None) |
267 | 217 def getParamsForCategory(self, category, profile_key="@DEFAULT@"): |
218 return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key)) | |
219 | |
220 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
221 in_signature='s', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
222 async_callbacks=None) |
267 | 223 def getParamsUI(self, profile_key="@DEFAULT@"): |
224 return self.cb["getParamsUI"](unicode(profile_key)) | |
225 | |
226 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
227 in_signature='s', out_signature='a{sa{s(sia{ss})}}', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
228 async_callbacks=None) |
267 | 229 def getPresenceStatus(self, profile_key="@DEFAULT@"): |
230 return self.cb["getPresenceStatus"](unicode(profile_key)) | |
231 | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
232 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
233 in_signature='s', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
234 async_callbacks=None) |
267 | 235 def getProfileName(self, profile_key="@DEFAULT@"): |
236 return self.cb["getProfileName"](unicode(profile_key)) | |
237 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
238 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
239 in_signature='', out_signature='as', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
240 async_callbacks=None) |
267 | 241 def getProfilesList(self, ): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
242 return self.cb["getProfilesList"]() |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
243 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
244 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
245 in_signature='s', out_signature='a{ss}', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
246 async_callbacks=None) |
267 | 247 def getProgress(self, id): |
248 return self.cb["getProgress"](unicode(id)) | |
68 | 249 |
250 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
251 in_signature='', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
252 async_callbacks=None) |
267 | 253 def getVersion(self, ): |
254 return self.cb["getVersion"]() | |
255 | |
256 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
257 in_signature='s', out_signature='a{ss}', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
258 async_callbacks=None) |
267 | 259 def getWaitingSub(self, profile_key="@DEFAULT@"): |
260 return self.cb["getWaitingSub"](unicode(profile_key)) | |
261 | |
262 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
263 in_signature='s', out_signature='b', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
264 async_callbacks=None) |
267 | 265 def isConnected(self, profile_key="@DEFAULT@"): |
266 return self.cb["isConnected"](unicode(profile_key)) | |
267 | |
268 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
269 in_signature='sa{ss}s', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
270 async_callbacks=None) |
267 | 271 def launchAction(self, action_type, data, profile_key="@DEFAULT@"): |
272 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
|
273 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
274 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
275 in_signature='ssssi', out_signature='s', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
276 async_callbacks=None) |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
277 def registerNewAccount(self, login, password, email, host, port=5222): |
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
278 return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(email), unicode(host), port) |
0 | 279 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
280 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
281 in_signature='sssss', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
282 async_callbacks=None) |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
283 def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"): |
267 | 284 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
|
285 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
286 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
287 in_signature='ssss', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
288 async_callbacks=None) |
267 | 289 def setParam(self, name, value, category, profile_key="@DEFAULT@"): |
290 return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key)) | |
105 | 291 |
292 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
293 in_signature='ssia{ss}s', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
294 async_callbacks=None) |
267 | 295 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): |
296 return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key)) | |
0 | 297 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
298 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
299 in_signature='sss', out_signature='', |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
300 async_callbacks=None) |
267 | 301 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): |
302 return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key)) | |
0 | 303 |
345 | 304 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
305 in_signature='ssass', out_signature='', | |
306 async_callbacks=None) | |
307 def updateContact(self, entity, name, groups, profile_key="@DEFAULT@"): | |
308 return self.cb["updateContact"](unicode(entity), unicode(name), groups, unicode(profile_key)) | |
309 | |
101 | 310 |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
311 def __attributes(self, in_sign): |
267 | 312 """Return arguments to user given a in_sign |
313 @param in_sign: in_sign in the short form (using s,a,i,b etc) | |
314 @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
|
315 i=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
316 idx=0 |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
317 attr=[] |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
318 while i<len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
319 if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']: |
267 | 320 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
|
321 |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
322 attr.append("arg_%i" % idx) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
323 idx+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
324 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
325 if in_sign[i] == 'a': |
73 | 326 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
|
327 if in_sign[i]!='{' and in_sign[i]!='(': #FIXME: must manage tuples out of arrays |
73 | 328 i+=1 |
329 continue #we have a simple type for the array | |
267 | 330 opening_car = in_sign[i] |
331 assert(opening_car in ['{','(']) | |
332 closing_car = '}' if opening_car == '{' else ')' | |
333 opening_count = 1 | |
73 | 334 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
|
335 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
336 if i>=len(in_sign): |
267 | 337 raise ParseError("missing }") |
338 if in_sign[i] == opening_car: | |
339 opening_count+=1 | |
340 if in_sign[i] == closing_car: | |
341 opening_count-=1 | |
342 if opening_count == 0: | |
343 break | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
344 i+=1 |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
345 return attr |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
346 |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
347 def addMethod(self, name, int_suffix, in_sign, out_sign, async=False, doc={}): |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
348 """Dynamically add a method to Dbus Bridge""" |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
349 _attributes = self.__attributes(in_sign) |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
350 |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
351 if async: |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
352 _attributes.extend(['callback','errback']) |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
353 |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
354 attributes = ', '.join(_attributes) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
355 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
356 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
|
357 exec (code) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
358 method = locals()[name] |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
359 async_callbacks = ('callback', 'errback') if async else None |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
360 setattr(DbusObject, name, dbus.service.method( |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
361 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign, |
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
362 async_callbacks=async_callbacks)(method)) |
284
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
363 function = getattr(self, name) |
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
364 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] |
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
365 func_table[function.__name__] = function #Needed for introspection |
73 | 366 |
298
15c8916317d0
dbus bridge: added doc parameter, unmanaged yet
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
367 def addSignal(self, name, int_suffix, signature, doc={}): |
73 | 368 """Dynamically add a signal to Dbus Bridge""" |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
369 attributes = ', '.join(self.__attributes(signature)) |
73 | 370 |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
371 #code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the debug is too annoying with xmllog |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
372 code = compile ('def '+name+' (self,'+attributes+'): pass', '<DBus bridge>','exec') |
73 | 373 exec (code) |
374 signal = locals()[name] | |
375 setattr(DbusObject, name, dbus.service.signal( | |
376 const_INT_PREFIX+int_suffix, signature=signature)(signal)) | |
284
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
377 function = getattr(self, name) |
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
378 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] |
c25371424090
dbus bridge: fixed introspection for dynamically added methods and signals
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
379 func_table[function.__name__] = function #Needed for introspection |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
380 |
0 | 381 class DBusBridge(Bridge): |
382 def __init__(self): | |
383 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
384 Bridge.__init__(self) | |
385 info ("Init DBus...") | |
386 self.session_bus = dbus.SessionBus() | |
10 | 387 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) |
0 | 388 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') |
389 | |
267 | 390 def actionResult(self, answer_type, id, data): |
391 self.dbus_bridge.actionResult(answer_type, id, data) | |
392 | |
393 def actionResultExt(self, answer_type, id, data): | |
394 self.dbus_bridge.actionResultExt(answer_type, id, data) | |
395 | |
396 def askConfirmation(self, conf_type, id, data): | |
397 self.dbus_bridge.askConfirmation(conf_type, id, data) | |
398 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
399 def connected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
400 self.dbus_bridge.connected(profile) |
267 | 401 |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
402 def connectionError(self, error_type, profile): |
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
403 self.dbus_bridge.connectionError(error_type, profile) |
267 | 404 |
405 def contactDeleted(self, entity, profile): | |
406 self.dbus_bridge.contactDeleted(entity, profile) | |
407 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
408 def disconnected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
409 self.dbus_bridge.disconnected(profile) |
267 | 410 |
411 def newAlert(self, message, title, alert_type, profile): | |
412 self.dbus_bridge.newAlert(message, title, alert_type, profile) | |
413 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
414 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
|
415 self.dbus_bridge.newContact(contact, attributes, groups, profile) |
0 | 416 |
267 | 417 def newMessage(self, from_jid, message, mess_type, to_jid, profile): |
418 self.dbus_bridge.newMessage(from_jid, message, mess_type, to_jid, profile) | |
0 | 419 |
267 | 420 def paramUpdate(self, name, value, category, profile): |
421 self.dbus_bridge.paramUpdate(name, value, category, profile) | |
422 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
423 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
|
424 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) |
49 | 425 |
221
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
426 def subscribe(self, sub_type, entity, profile): |
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
427 self.dbus_bridge.subscribe(sub_type, entity, profile) |
0 | 428 |
49 | 429 def updatedValue(self, name, value): |
430 self.dbus_bridge.updatedValue(name, value) | |
431 | |
267 | 432 |
0 | 433 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
|
434 debug("registering DBus bridge method [%s]", name) |
0 | 435 self.dbus_bridge.register(name, callback) |
436 | |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
437 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
438 """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
|
439 print ("Adding method [%s] to DBus bridge" % name) |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
440 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, async, doc) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
441 self.register(name, method) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
442 |
298
15c8916317d0
dbus bridge: added doc parameter, unmanaged yet
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
443 def addSignal(self, name, int_suffix, signature, doc={}): |
300
233e6fce0b49
DBus bridge: using new generated bridge
Goffi <goffi@goffi.org>
parents:
298
diff
changeset
|
444 self.dbus_bridge.addSignal(name, int_suffix, signature, doc) |
74
6e3a06b4dd36
plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
445 setattr(DBusBridge, name, getattr(self.dbus_bridge, name)) |