annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 #-*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 from bridge import Bridge
goffi@necton2
parents:
diff changeset
24 import dbus
goffi@necton2
parents:
diff changeset
25 import dbus.service
goffi@necton2
parents:
diff changeset
26 import dbus.mainloop.glib
goffi@necton2
parents:
diff changeset
27 import pdb
goffi@necton2
parents:
diff changeset
28 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
29
goffi@necton2
parents:
diff changeset
30 class DbusObject(dbus.service.Object):
goffi@necton2
parents:
diff changeset
31
goffi@necton2
parents:
diff changeset
32 def __init__(self, bus, path):
goffi@necton2
parents:
diff changeset
33 dbus.service.Object.__init__(self, bus, path)
goffi@necton2
parents:
diff changeset
34 debug("Init DbusObject...")
goffi@necton2
parents:
diff changeset
35 self.cb={}
goffi@necton2
parents:
diff changeset
36
goffi@necton2
parents:
diff changeset
37 def register(self, name, cb):
goffi@necton2
parents:
diff changeset
38 self.cb[name]=cb
goffi@necton2
parents:
diff changeset
39
goffi@necton2
parents:
diff changeset
40 ### signals ###
goffi@necton2
parents:
diff changeset
41
goffi@necton2
parents:
diff changeset
42 @dbus.service.signal("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
43 signature='sa{ss}as')
goffi@necton2
parents:
diff changeset
44 def newContact(self, contact, attributes, groups):
goffi@necton2
parents:
diff changeset
45 debug("new contact signal (%s) sended", contact)
goffi@necton2
parents:
diff changeset
46
goffi@necton2
parents:
diff changeset
47 @dbus.service.signal("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
48 signature='ssss')
goffi@necton2
parents:
diff changeset
49 def newMessage(self, from_jid, msg, type='chat', to=''):
goffi@necton2
parents:
diff changeset
50 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to)
goffi@necton2
parents:
diff changeset
51
goffi@necton2
parents:
diff changeset
52 @dbus.service.signal("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
53 signature='ssssi')
goffi@necton2
parents:
diff changeset
54 def presenceUpdate(self, jid, type, show, status, priority):
goffi@necton2
parents:
diff changeset
55 debug("presence update signal (from:%s type: %s show:%s status:\"%s\" priority:%d) sended" , jid, type, show, status, priority)
goffi@necton2
parents:
diff changeset
56
goffi@necton2
parents:
diff changeset
57 @dbus.service.signal("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
58 signature='sss')
goffi@necton2
parents:
diff changeset
59 def paramUpdate(self, name, value, namespace):
goffi@necton2
parents:
diff changeset
60 debug("param update signal: %s=%s in namespace %s", name, value, namespace)
goffi@necton2
parents:
diff changeset
61
goffi@necton2
parents:
diff changeset
62 @dbus.service.signal("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
63 signature='s')
goffi@necton2
parents:
diff changeset
64 def contactDeleted(self, jid):
goffi@necton2
parents:
diff changeset
65 debug("contact deleted signal: %s", jid)
goffi@necton2
parents:
diff changeset
66
goffi@necton2
parents:
diff changeset
67 @dbus.service.signal("org.goffi.SAT.request",
goffi@necton2
parents:
diff changeset
68 signature='ssa{ss}')
goffi@necton2
parents:
diff changeset
69 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
70 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data)
goffi@necton2
parents:
diff changeset
71
goffi@necton2
parents:
diff changeset
72
goffi@necton2
parents:
diff changeset
73
goffi@necton2
parents:
diff changeset
74 ### methods ###
goffi@necton2
parents:
diff changeset
75
goffi@necton2
parents:
diff changeset
76 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
77 in_signature='', out_signature='')
goffi@necton2
parents:
diff changeset
78 def connect(self):
goffi@necton2
parents:
diff changeset
79 info ("Connection asked")
goffi@necton2
parents:
diff changeset
80 return self.cb["connect"]()
goffi@necton2
parents:
diff changeset
81
goffi@necton2
parents:
diff changeset
82 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
83 in_signature='', out_signature='a(sa{ss}as)')
goffi@necton2
parents:
diff changeset
84 def getContacts(self):
goffi@necton2
parents:
diff changeset
85 debug("getContacts...")
goffi@necton2
parents:
diff changeset
86 return self.cb["getContacts"]()
goffi@necton2
parents:
diff changeset
87
goffi@necton2
parents:
diff changeset
88 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
89 in_signature='', out_signature='a(ssssi)')
goffi@necton2
parents:
diff changeset
90 def getPresenceStatus(self):
goffi@necton2
parents:
diff changeset
91 debug("getPresenceStatus...")
goffi@necton2
parents:
diff changeset
92 return self.cb["getPresenceStatus"]()
goffi@necton2
parents:
diff changeset
93
goffi@necton2
parents:
diff changeset
94 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
95 in_signature='ss', out_signature='')
goffi@necton2
parents:
diff changeset
96 def sendMessage(self, to, message):
goffi@necton2
parents:
diff changeset
97 debug("sendMessage...")
goffi@necton2
parents:
diff changeset
98 self.cb["sendMessage"](to, message)
goffi@necton2
parents:
diff changeset
99
goffi@necton2
parents:
diff changeset
100 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
101 in_signature='ss', out_signature='s')
goffi@necton2
parents:
diff changeset
102 def sendFile(self, to, path):
goffi@necton2
parents:
diff changeset
103 debug("sendFile...")
goffi@necton2
parents:
diff changeset
104 return self.cb["sendFile"](to, path)
goffi@necton2
parents:
diff changeset
105
goffi@necton2
parents:
diff changeset
106 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
107 in_signature='ssssi', out_signature='')
goffi@necton2
parents:
diff changeset
108 def setPresence(self, to="", type="", show="", status="", priority=0):
goffi@necton2
parents:
diff changeset
109 self.cb["setPresence"](to, type, show, status, priority)
goffi@necton2
parents:
diff changeset
110
goffi@necton2
parents:
diff changeset
111
goffi@necton2
parents:
diff changeset
112 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
113 in_signature='sss', out_signature='')
goffi@necton2
parents:
diff changeset
114 def setParam(self, name, value, namespace="default"):
goffi@necton2
parents:
diff changeset
115 self.cb["setParam"](name, str(value), namespace)
goffi@necton2
parents:
diff changeset
116
goffi@necton2
parents:
diff changeset
117 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
118 in_signature='ss', out_signature='(ss)')
goffi@necton2
parents:
diff changeset
119 def getParam(self, name, namespace="default"):
goffi@necton2
parents:
diff changeset
120 return self.cb["getParam"](name, namespace)
goffi@necton2
parents:
diff changeset
121
goffi@necton2
parents:
diff changeset
122 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
123 in_signature='s', out_signature='a(sss)')
goffi@necton2
parents:
diff changeset
124 def getParams(self, namespace):
goffi@necton2
parents:
diff changeset
125 return self.cb["getParams"](namespace)
goffi@necton2
parents:
diff changeset
126
goffi@necton2
parents:
diff changeset
127 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
128 in_signature='', out_signature='as')
goffi@necton2
parents:
diff changeset
129 def getParamsCategories(self):
goffi@necton2
parents:
diff changeset
130 return self.cb["getParamsCategories"]()
goffi@necton2
parents:
diff changeset
131
goffi@necton2
parents:
diff changeset
132 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
133 in_signature='ssi', out_signature='a{i(ss)}')
goffi@necton2
parents:
diff changeset
134 def getHistory(self, from_jid, to_jid, size):
goffi@necton2
parents:
diff changeset
135 debug("History asked for %s", to_jid)
goffi@necton2
parents:
diff changeset
136 return self.cb["getHistory"](from_jid, to_jid, size)
goffi@necton2
parents:
diff changeset
137
goffi@necton2
parents:
diff changeset
138 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
139 in_signature='s', out_signature='')
goffi@necton2
parents:
diff changeset
140 def addContact(self, jid):
goffi@necton2
parents:
diff changeset
141 debug("Subscription asked for %s", jid)
goffi@necton2
parents:
diff changeset
142 return self.cb["addContact"](jid)
goffi@necton2
parents:
diff changeset
143
goffi@necton2
parents:
diff changeset
144 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
145 in_signature='s', out_signature='')
goffi@necton2
parents:
diff changeset
146 def delContact(self, jid):
goffi@necton2
parents:
diff changeset
147 debug("Unsubscription asked for %s", jid)
goffi@necton2
parents:
diff changeset
148 return self.cb["delContact"](jid)
goffi@necton2
parents:
diff changeset
149
goffi@necton2
parents:
diff changeset
150 @dbus.service.method("org.goffi.SAT.communication",
goffi@necton2
parents:
diff changeset
151 in_signature='', out_signature='b')
goffi@necton2
parents:
diff changeset
152 def isConnected(self):
goffi@necton2
parents:
diff changeset
153 debug("Connection status requested")
goffi@necton2
parents:
diff changeset
154 return self.cb["isConnected"]()
goffi@necton2
parents:
diff changeset
155
goffi@necton2
parents:
diff changeset
156 @dbus.service.method("org.goffi.SAT.request",
goffi@necton2
parents:
diff changeset
157 in_signature='sba{ss}', out_signature='')
goffi@necton2
parents:
diff changeset
158 def confirmationAnswer(self, id, accepted, data):
goffi@necton2
parents:
diff changeset
159 debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused")
goffi@necton2
parents:
diff changeset
160 return self.cb["confirmationAnswer"](id, accepted, data)
goffi@necton2
parents:
diff changeset
161
goffi@necton2
parents:
diff changeset
162 @dbus.service.method("org.goffi.SAT.request",
goffi@necton2
parents:
diff changeset
163 in_signature='s', out_signature='a{ss}')
goffi@necton2
parents:
diff changeset
164 def getProgress(self, id):
goffi@necton2
parents:
diff changeset
165 #debug("Progress asked for %s", id)
goffi@necton2
parents:
diff changeset
166 return self.cb["getProgress"](id)
goffi@necton2
parents:
diff changeset
167
goffi@necton2
parents:
diff changeset
168 class DBusBridge(Bridge):
goffi@necton2
parents:
diff changeset
169 def __init__(self):
goffi@necton2
parents:
diff changeset
170 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
goffi@necton2
parents:
diff changeset
171 Bridge.__init__(self)
goffi@necton2
parents:
diff changeset
172 info ("Init DBus...")
goffi@necton2
parents:
diff changeset
173 self.session_bus = dbus.SessionBus()
goffi@necton2
parents:
diff changeset
174 self.dbus_name = dbus.service.BusName("org.goffi.SAT", self.session_bus)
goffi@necton2
parents:
diff changeset
175 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge')
goffi@necton2
parents:
diff changeset
176
goffi@necton2
parents:
diff changeset
177 def newContact(self, contact, attributes, groups):
goffi@necton2
parents:
diff changeset
178 self.dbus_bridge.newContact(contact, attributes, groups)
goffi@necton2
parents:
diff changeset
179
goffi@necton2
parents:
diff changeset
180 def newMessage(self,from_jid,msg,type='chat', to=''):
goffi@necton2
parents:
diff changeset
181 debug("sending message...")
goffi@necton2
parents:
diff changeset
182 self.dbus_bridge.newMessage(from_jid, msg, type, to)
goffi@necton2
parents:
diff changeset
183
goffi@necton2
parents:
diff changeset
184 def presenceUpdate(self, jid, type, show, status, priority):
goffi@necton2
parents:
diff changeset
185 debug("updating presence for %s",jid)
goffi@necton2
parents:
diff changeset
186 self.dbus_bridge.presenceUpdate(jid, type, show, status, priority)
goffi@necton2
parents:
diff changeset
187
goffi@necton2
parents:
diff changeset
188 def paramUpdate(self, name, value, namespace):
goffi@necton2
parents:
diff changeset
189 debug("updating param [%s] %s ", namespace, name)
goffi@necton2
parents:
diff changeset
190 self.dbus_bridge.paramUpdate(name, value, namespace)
goffi@necton2
parents:
diff changeset
191
goffi@necton2
parents:
diff changeset
192 def contactDeleted(self, jid):
goffi@necton2
parents:
diff changeset
193 debug("sending contact deleted signal %s ", jid)
goffi@necton2
parents:
diff changeset
194 self.dbus_bridge.contactDeleted(jid)
goffi@necton2
parents:
diff changeset
195
goffi@necton2
parents:
diff changeset
196 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
197 self.dbus_bridge.askConfirmation(type, id, data)
goffi@necton2
parents:
diff changeset
198
goffi@necton2
parents:
diff changeset
199 def register(self, name, callback):
goffi@necton2
parents:
diff changeset
200 debug("enregistrement de %s",name)
goffi@necton2
parents:
diff changeset
201 self.dbus_bridge.register(name, callback)
goffi@necton2
parents:
diff changeset
202