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