Mercurial > libervia-backend
annotate sat_bridge/DBus.py @ 57:a5b5fb5fc9fd
updated README and copyright note
- fixed images path in README
- added year 2010 in all copyright notes
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Jan 2010 17:51:56 +1100 |
parents | 6455fb62ff83 |
children | 9764e027ecc0 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
57 | 6 Copyright (C) 2009, 2010 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 import pdb | |
28 from logging import debug, info, error | |
29 | |
10 | 30 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
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 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
46 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
52 | 47 signature='') |
48 def connected(self): | |
49 debug("Connected signal") | |
50 | |
51 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
52 signature='') | |
53 def disconnected(self): | |
54 debug("Disconnected signal") | |
55 | |
56 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
0 | 57 signature='sa{ss}as') |
58 def newContact(self, contact, attributes, groups): | |
59 debug("new contact signal (%s) sended", contact) | |
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, |
0 | 62 signature='ssss') |
63 def newMessage(self, from_jid, msg, type='chat', to=''): | |
64 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) | |
65 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
66 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 67 signature='ssia{ss}') |
68 def presenceUpdate(self, entity, show, priority, statuses): | |
69 debug("presence update signal (from:%s show:%s priority:%d statuses:%s) sended" , entity, show, priority, statuses) | |
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') |
73 def subscribe(self, type, entity): | |
74 debug("subscribe (type: [%s] from:[%s])" , type, entity) | |
75 | |
76 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
0 | 77 signature='sss') |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
78 def paramUpdate(self, name, value, category): |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
79 debug("param update signal: %s=%s in category %s", name, value, category) |
0 | 80 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
81 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 82 signature='s') |
49 | 83 def contactDeleted(self, entity): |
84 debug("contact deleted signal: %s", entity) | |
0 | 85 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
86 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
0 | 87 signature='ssa{ss}') |
88 def askConfirmation(self, type, id, data): | |
89 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) | |
90 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
91 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
92 signature='ssa{ss}') |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
93 def actionResult(self, type, id, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
94 debug("result of action: id = [%s] type = %s data = %s", id, type, data) |
0 | 95 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
96 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
97 signature='ssa{sa{ss}}') |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
98 def actionResultExt(self, type, id, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
99 debug("extended result of action: id = [%s] type = %s data = %s", id, type, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
100 |
49 | 101 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
102 signature='sa{ss}') | |
103 def updatedValue(self, name, value): | |
104 debug("updated value: %s = %s", name, value) | |
105 | |
0 | 106 ### methods ### |
107 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
108 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
109 in_signature='sssi', out_signature='s') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
110 def registerNewAccount(self, login, password, host, port=5222): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
111 info ("New account registration asked") |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
112 return self.cb["registerNewAccount"](login, password, host, port) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
113 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
114 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 115 in_signature='', out_signature='') |
116 def connect(self): | |
117 info ("Connection asked") | |
118 return self.cb["connect"]() | |
119 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
120 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
1 | 121 in_signature='', out_signature='') |
122 def disconnect(self): | |
123 info ("Disconnection asked") | |
124 return self.cb["disconnect"]() | |
125 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
126 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
52 | 127 in_signature='', out_signature='b') |
128 def isConnected(self): | |
129 info ("Connection status asked") | |
130 return self.cb["isConnected"]() | |
131 | |
132 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
0 | 133 in_signature='', out_signature='a(sa{ss}as)') |
134 def getContacts(self): | |
135 debug("getContacts...") | |
136 return self.cb["getContacts"]() | |
137 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
138 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 139 in_signature='', out_signature='a{sa{s(sia{ss})}}') |
0 | 140 def getPresenceStatus(self): |
141 debug("getPresenceStatus...") | |
142 return self.cb["getPresenceStatus"]() | |
143 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
144 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 145 in_signature='', out_signature='a{ss}') |
146 def getWaitingSub(self): | |
147 debug("getWaitingSub...") | |
148 return self.cb["getWaitingSub"]() | |
149 | |
150 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
0 | 151 in_signature='ss', out_signature='') |
152 def sendMessage(self, to, message): | |
153 debug("sendMessage...") | |
154 self.cb["sendMessage"](to, message) | |
155 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
156 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 157 in_signature='ssia{ss}', out_signature='') |
158 def setPresence(self, to="", show="", priority=0, statuses={}): | |
159 self.cb["setPresence"](to, show, priority, statuses) | |
160 | |
161 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
162 in_signature='ss', out_signature='') | |
163 def subscription(self, type, entity): | |
164 self.cb["subscription"](type, entity) | |
0 | 165 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
166 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 167 in_signature='sss', out_signature='') |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
168 def setParam(self, name, value, category): |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
169 self.cb["setParam"](name, str(value), category) |
0 | 170 |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
171 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
172 in_signature='ss', out_signature='s') |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
173 def getParamA(self, name, category="default"): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
174 return self.cb["getParamA"](name, category) |
0 | 175 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
176 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
177 in_signature='', out_signature='s') |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
178 def getParams(self): |
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
179 return self.cb["getParams"]() |
0 | 180 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
181 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
182 in_signature='s', out_signature='s') |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
183 def getParamsForCategory(self, category): |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
184 return self.cb["getParamsForCategory"](category) |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
185 |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
186 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 187 in_signature='', out_signature='as') |
188 def getParamsCategories(self): | |
189 return self.cb["getParamsCategories"]() | |
190 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
191 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 192 in_signature='ssi', out_signature='a{i(ss)}') |
193 def getHistory(self, from_jid, to_jid, size): | |
194 debug("History asked for %s", to_jid) | |
195 return self.cb["getHistory"](from_jid, to_jid, size) | |
196 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
197 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 198 in_signature='s', out_signature='') |
49 | 199 def addContact(self, entity): |
200 debug("Subscription asked for %s", entity) | |
201 return self.cb["addContact"](entity) | |
0 | 202 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
203 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 204 in_signature='s', out_signature='') |
49 | 205 def delContact(self, entity): |
206 debug("Unsubscription asked for %s", entity) | |
207 return self.cb["delContact"](entity) | |
0 | 208 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
209 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
210 in_signature='sa{ss}', out_signature='s') |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
211 def launchAction(self, type, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
212 return self.cb["launchAction"](type, data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
213 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
214 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
0 | 215 in_signature='sba{ss}', out_signature='') |
216 def confirmationAnswer(self, id, accepted, data): | |
217 debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused") | |
218 return self.cb["confirmationAnswer"](id, accepted, data) | |
219 | |
36 | 220 |
221 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
0 | 222 in_signature='s', out_signature='a{ss}') |
223 def getProgress(self, id): | |
224 #debug("Progress asked for %s", id) | |
225 return self.cb["getProgress"](id) | |
226 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
227 def __attribute_string(self, in_sign): |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
228 i=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
229 idx=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
230 attr_string="" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
231 while i<len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
232 if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']: |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
233 raise Exception #FIXME: create an exception here (unmanaged attribute type) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
234 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
235 attr_string += ("" if idx==0 else ",") + ("arg_%i" % idx) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
236 idx+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
237 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
238 if in_sign[i] == 'a': |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
239 while (True): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
240 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
241 if i>=len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
242 raise Exception #FIXME: create an exception here (the '}' is not presend) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
243 if in_sign[i] == '}' or in_sign[i] == ')': |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
244 break |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
245 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
246 return attr_string |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
247 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
248 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
249 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
250 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
|
251 """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
|
252 #FIXME: Better way ??? |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
253 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
|
254 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
255 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
|
256 exec (code) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
257 method = locals()[name] |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
258 setattr(DbusObject, name, dbus.service.method( |
10 | 259 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
260 |
0 | 261 class DBusBridge(Bridge): |
262 def __init__(self): | |
263 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
264 Bridge.__init__(self) | |
265 info ("Init DBus...") | |
266 self.session_bus = dbus.SessionBus() | |
10 | 267 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) |
0 | 268 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') |
269 | |
52 | 270 def connected(self): |
271 self.dbus_bridge.connected() | |
272 | |
273 def disconnected(self): | |
274 self.dbus_bridge.disconnected() | |
275 | |
0 | 276 def newContact(self, contact, attributes, groups): |
277 self.dbus_bridge.newContact(contact, attributes, groups) | |
278 | |
279 def newMessage(self,from_jid,msg,type='chat', to=''): | |
280 debug("sending message...") | |
281 self.dbus_bridge.newMessage(from_jid, msg, type, to) | |
282 | |
49 | 283 def presenceUpdate(self, entity, show, priority, statuses): |
284 debug("updating presence for %s",entity) | |
285 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses) | |
286 | |
287 def subscribe(self, type, entity): | |
288 debug("subscribe request for %s",entity) | |
289 self.dbus_bridge.subscribe(type, entity) | |
0 | 290 |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
291 def paramUpdate(self, name, value, category): |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
292 debug("updating param [%s] %s ", category, name) |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
293 self.dbus_bridge.paramUpdate(name, value, category) |
0 | 294 |
49 | 295 def contactDeleted(self, entity): |
296 debug("sending contact deleted signal %s ", entity) | |
297 self.dbus_bridge.contactDeleted(entity) | |
0 | 298 |
299 def askConfirmation(self, type, id, data): | |
300 self.dbus_bridge.askConfirmation(type, id, data) | |
301 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
302 def actionResult(self, type, id, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
303 self.dbus_bridge.actionResult(type, id, data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
304 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
305 def actionResultExt(self, type, id, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
306 self.dbus_bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
307 |
49 | 308 def updatedValue(self, name, value): |
309 self.dbus_bridge.updatedValue(name, value) | |
310 | |
0 | 311 def register(self, name, callback): |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
312 debug("registering DBus bridge method [%s]",name) |
0 | 313 self.dbus_bridge.register(name, callback) |
314 | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
315 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
|
316 """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
|
317 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
|
318 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
|
319 self.register(name, method) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
320 |