Mercurial > libervia-backend
comparison sat_bridge/DBus.py @ 0:c4bc297b82f0
sat:
- first public release, initial commit
author | goffi@necton2 |
---|---|
date | Sat, 29 Aug 2009 13:34:59 +0200 |
parents | |
children | a06a151fc31f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c4bc297b82f0 |
---|---|
1 #!/usr/bin/python | |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) | |
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 | |
30 class DbusObject(dbus.service.Object): | |
31 | |
32 def __init__(self, bus, path): | |
33 dbus.service.Object.__init__(self, bus, path) | |
34 debug("Init DbusObject...") | |
35 self.cb={} | |
36 | |
37 def register(self, name, cb): | |
38 self.cb[name]=cb | |
39 | |
40 ### signals ### | |
41 | |
42 @dbus.service.signal("org.goffi.SAT.communication", | |
43 signature='sa{ss}as') | |
44 def newContact(self, contact, attributes, groups): | |
45 debug("new contact signal (%s) sended", contact) | |
46 | |
47 @dbus.service.signal("org.goffi.SAT.communication", | |
48 signature='ssss') | |
49 def newMessage(self, from_jid, msg, type='chat', to=''): | |
50 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) | |
51 | |
52 @dbus.service.signal("org.goffi.SAT.communication", | |
53 signature='ssssi') | |
54 def presenceUpdate(self, jid, type, show, status, priority): | |
55 debug("presence update signal (from:%s type: %s show:%s status:\"%s\" priority:%d) sended" , jid, type, show, status, priority) | |
56 | |
57 @dbus.service.signal("org.goffi.SAT.communication", | |
58 signature='sss') | |
59 def paramUpdate(self, name, value, namespace): | |
60 debug("param update signal: %s=%s in namespace %s", name, value, namespace) | |
61 | |
62 @dbus.service.signal("org.goffi.SAT.communication", | |
63 signature='s') | |
64 def contactDeleted(self, jid): | |
65 debug("contact deleted signal: %s", jid) | |
66 | |
67 @dbus.service.signal("org.goffi.SAT.request", | |
68 signature='ssa{ss}') | |
69 def askConfirmation(self, type, id, data): | |
70 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) | |
71 | |
72 | |
73 | |
74 ### methods ### | |
75 | |
76 @dbus.service.method("org.goffi.SAT.communication", | |
77 in_signature='', out_signature='') | |
78 def connect(self): | |
79 info ("Connection asked") | |
80 return self.cb["connect"]() | |
81 | |
82 @dbus.service.method("org.goffi.SAT.communication", | |
83 in_signature='', out_signature='a(sa{ss}as)') | |
84 def getContacts(self): | |
85 debug("getContacts...") | |
86 return self.cb["getContacts"]() | |
87 | |
88 @dbus.service.method("org.goffi.SAT.communication", | |
89 in_signature='', out_signature='a(ssssi)') | |
90 def getPresenceStatus(self): | |
91 debug("getPresenceStatus...") | |
92 return self.cb["getPresenceStatus"]() | |
93 | |
94 @dbus.service.method("org.goffi.SAT.communication", | |
95 in_signature='ss', out_signature='') | |
96 def sendMessage(self, to, message): | |
97 debug("sendMessage...") | |
98 self.cb["sendMessage"](to, message) | |
99 | |
100 @dbus.service.method("org.goffi.SAT.communication", | |
101 in_signature='ss', out_signature='s') | |
102 def sendFile(self, to, path): | |
103 debug("sendFile...") | |
104 return self.cb["sendFile"](to, path) | |
105 | |
106 @dbus.service.method("org.goffi.SAT.communication", | |
107 in_signature='ssssi', out_signature='') | |
108 def setPresence(self, to="", type="", show="", status="", priority=0): | |
109 self.cb["setPresence"](to, type, show, status, priority) | |
110 | |
111 | |
112 @dbus.service.method("org.goffi.SAT.communication", | |
113 in_signature='sss', out_signature='') | |
114 def setParam(self, name, value, namespace="default"): | |
115 self.cb["setParam"](name, str(value), namespace) | |
116 | |
117 @dbus.service.method("org.goffi.SAT.communication", | |
118 in_signature='ss', out_signature='(ss)') | |
119 def getParam(self, name, namespace="default"): | |
120 return self.cb["getParam"](name, namespace) | |
121 | |
122 @dbus.service.method("org.goffi.SAT.communication", | |
123 in_signature='s', out_signature='a(sss)') | |
124 def getParams(self, namespace): | |
125 return self.cb["getParams"](namespace) | |
126 | |
127 @dbus.service.method("org.goffi.SAT.communication", | |
128 in_signature='', out_signature='as') | |
129 def getParamsCategories(self): | |
130 return self.cb["getParamsCategories"]() | |
131 | |
132 @dbus.service.method("org.goffi.SAT.communication", | |
133 in_signature='ssi', out_signature='a{i(ss)}') | |
134 def getHistory(self, from_jid, to_jid, size): | |
135 debug("History asked for %s", to_jid) | |
136 return self.cb["getHistory"](from_jid, to_jid, size) | |
137 | |
138 @dbus.service.method("org.goffi.SAT.communication", | |
139 in_signature='s', out_signature='') | |
140 def addContact(self, jid): | |
141 debug("Subscription asked for %s", jid) | |
142 return self.cb["addContact"](jid) | |
143 | |
144 @dbus.service.method("org.goffi.SAT.communication", | |
145 in_signature='s', out_signature='') | |
146 def delContact(self, jid): | |
147 debug("Unsubscription asked for %s", jid) | |
148 return self.cb["delContact"](jid) | |
149 | |
150 @dbus.service.method("org.goffi.SAT.communication", | |
151 in_signature='', out_signature='b') | |
152 def isConnected(self): | |
153 debug("Connection status requested") | |
154 return self.cb["isConnected"]() | |
155 | |
156 @dbus.service.method("org.goffi.SAT.request", | |
157 in_signature='sba{ss}', out_signature='') | |
158 def confirmationAnswer(self, id, accepted, data): | |
159 debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused") | |
160 return self.cb["confirmationAnswer"](id, accepted, data) | |
161 | |
162 @dbus.service.method("org.goffi.SAT.request", | |
163 in_signature='s', out_signature='a{ss}') | |
164 def getProgress(self, id): | |
165 #debug("Progress asked for %s", id) | |
166 return self.cb["getProgress"](id) | |
167 | |
168 class DBusBridge(Bridge): | |
169 def __init__(self): | |
170 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
171 Bridge.__init__(self) | |
172 info ("Init DBus...") | |
173 self.session_bus = dbus.SessionBus() | |
174 self.dbus_name = dbus.service.BusName("org.goffi.SAT", self.session_bus) | |
175 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') | |
176 | |
177 def newContact(self, contact, attributes, groups): | |
178 self.dbus_bridge.newContact(contact, attributes, groups) | |
179 | |
180 def newMessage(self,from_jid,msg,type='chat', to=''): | |
181 debug("sending message...") | |
182 self.dbus_bridge.newMessage(from_jid, msg, type, to) | |
183 | |
184 def presenceUpdate(self, jid, type, show, status, priority): | |
185 debug("updating presence for %s",jid) | |
186 self.dbus_bridge.presenceUpdate(jid, type, show, status, priority) | |
187 | |
188 def paramUpdate(self, name, value, namespace): | |
189 debug("updating param [%s] %s ", namespace, name) | |
190 self.dbus_bridge.paramUpdate(name, value, namespace) | |
191 | |
192 def contactDeleted(self, jid): | |
193 debug("sending contact deleted signal %s ", jid) | |
194 self.dbus_bridge.contactDeleted(jid) | |
195 | |
196 def askConfirmation(self, type, id, data): | |
197 self.dbus_bridge.askConfirmation(type, id, data) | |
198 | |
199 def register(self, name, callback): | |
200 debug("enregistrement de %s",name) | |
201 self.dbus_bridge.register(name, callback) | |
202 |