annotate sat.tac @ 13:bd9e9997d540

wokkel integration (not finished yet)
author Goffi <goffi@goffi.org>
date Fri, 30 Oct 2009 17:38:27 +0100
parents ef8060d365cb
children a62d7d453f22
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
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
23 from twisted.application import internet, service
12
ef8060d365cb whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire)
Goffi <goffi@goffi.org>
parents: 6
diff changeset
24 from twisted.internet import glib2reactor, protocol, task
0
goffi@necton2
parents:
diff changeset
25 glib2reactor.install()
goffi@necton2
parents:
diff changeset
26
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
27 from twisted.words.protocols.jabber import jid, xmlstream, error
0
goffi@necton2
parents:
diff changeset
28 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
29
goffi@necton2
parents:
diff changeset
30 from twisted.internet import reactor
goffi@necton2
parents:
diff changeset
31 import pdb
goffi@necton2
parents:
diff changeset
32
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
33 from wokkel import client, disco, xmppim
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
34
0
goffi@necton2
parents:
diff changeset
35 from sat_bridge.DBus import DBusBridge
goffi@necton2
parents:
diff changeset
36 import logging
goffi@necton2
parents:
diff changeset
37 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
38
goffi@necton2
parents:
diff changeset
39 import signal, sys
goffi@necton2
parents:
diff changeset
40 import os.path
goffi@necton2
parents:
diff changeset
41
goffi@necton2
parents:
diff changeset
42 from tools.memory import Memory
goffi@necton2
parents:
diff changeset
43 from glob import glob
goffi@necton2
parents:
diff changeset
44
goffi@necton2
parents:
diff changeset
45
goffi@necton2
parents:
diff changeset
46 ### logging configuration FIXME: put this elsewhere ###
goffi@necton2
parents:
diff changeset
47 logging.basicConfig(level=logging.DEBUG,
goffi@necton2
parents:
diff changeset
48 format='%(message)s')
goffi@necton2
parents:
diff changeset
49 ###
goffi@necton2
parents:
diff changeset
50
goffi@necton2
parents:
diff changeset
51
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
52 class SatXMPPClient(client.XMPPClient):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
53
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
54 def __init__(self, jid, password, host=None, port=5222):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
55 client.XMPPClient.__init__(self, jid, password, host, port)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
56 self.factory.clientConnectionLost = self.connectionLost
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
57 self.__connected=False
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
58
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
59 def _authd(self, xmlstream):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
60 print "SatXMPPClient"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
61 client.XMPPClient._authd(self, xmlstream)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
62 self.__connected=True
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
63 print "********** CONNECTED **********"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
64 self.streamInitialized()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
65
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
66 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
67 """Called after _authd"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
68 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
69 self.keep_alife.start(180)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
70
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
71 def isConnected(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
72 return self.__connected
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
73
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
74 def connectionLost(self, connector, unused_reason):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
75 print "********** DISCONNECTED **********"
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
76 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
77 self.keep_alife.stop()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
78 except AttributeError:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
79 debug("No keep_alife")
0
goffi@necton2
parents:
diff changeset
80
goffi@necton2
parents:
diff changeset
81
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
82 class SatMessageProtocol(xmppim.MessageProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
83
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
84 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
85 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
86 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
87
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
88 def onMessage(self, message):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
89 debug (u"got_message from: %s", message["from"])
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
90 for e in message.elements():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
91 if e.name == "body":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
92 self.host.bridge.newMessage(message["from"], e.children[0])
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
93 self.host.memory.addToHistory(self.host.me, jid.JID(message["from"]), self.host.me, "chat", e.children[0])
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
94 break
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
95
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
96 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
97
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
98 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
99 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
100 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
101
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
102 def rosterCb(self, roster):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
103 for jid, item in roster.iteritems():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
104 info ("new contact in roster list: %s", jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
105 #FIXME: fill attributes
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
106 self.host.memory.addContact(jid, {}, item.groups)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
107 self.host.bridge.newContact(jid, {}, item.groups)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
108
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
109 def requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
110 """ ask the server for Roster list """
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
111 debug("requestRoster")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
112 self.getRoster().addCallback(self.rosterCb)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
113
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
114 def removeItem(self, to):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
115 """Remove a contact from roster list"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
116 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
117 xmppim.RosterClientProtocol.removeItem(self, to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
118 #TODO: check IQ result
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
119
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
120 def addItem(self, to):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
121 """Add a contact to roster list"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
122 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
123 xmppim.RosterClientProtocol.addItem(self, to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
124 #TODO: check IQ result
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
125
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
126 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
127
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
128 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
129 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
130 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
131
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
132 def availableReceived(self, entity, show=None, statuses=None, priority=0):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
133 info ("presence update for [%s]", entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
134
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
135 ### we check if the status is not about subscription ###
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
136 #FIXME: type is not needed anymore
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
137 #TODO: management of differents statuses (differents languages)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
138 status = statuses.values()[0] if len(statuses) else ""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
139 self.host.memory.addPresenceStatus(entity.full(), "", show or "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
140 status or "", int(priority))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
141
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
142 #now it's time to notify frontends
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
143 pdb.set_trace()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
144 self.host.bridge.presenceUpdate(entity.full(), "", show or "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
145 status or "", int(priority))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
146
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
147 def unavailableReceived(self, entity, statuses=None):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
148 #TODO: management of differents statuses (differents languages)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
149 status = statuses.values()[0] if len(statuses) else ""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
150 self.host.memory.addPresenceStatus(entity.full(), "unavailable", "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
151 status or "", 0)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
152
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
153 #now it's time to notify frontends
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
154 self.host.bridge.presenceUpdate(entity.full(), "unavailable", "",
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
155 status or "", 0)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
156
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
157
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
158 def subscribedReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
159 debug ("subscription approved for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
160
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
161 def unsubscribedReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
162 debug ("unsubscription confirmed for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
163
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
164 def subscribeReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
165 #FIXME: auto answer for subscribe request, must be checked !
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
166 debug ("subscription request for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
167 self.subscribed(entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
168
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
169 def unsubscribeReceived(self, entity):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
170 debug ("unsubscription asked for [%s]" % entity)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
171
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
172 class SAT(service.Service):
0
goffi@necton2
parents:
diff changeset
173
goffi@necton2
parents:
diff changeset
174 def __init__(self):
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
175 #self.reactor=reactor
0
goffi@necton2
parents:
diff changeset
176 self.memory=Memory()
goffi@necton2
parents:
diff changeset
177 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
goffi@necton2
parents:
diff changeset
178
goffi@necton2
parents:
diff changeset
179 self._iq_cb_map = {} #callback called when ns is found on IQ
goffi@necton2
parents:
diff changeset
180 self._waiting_conf = {} #callback called when a confirmation is received
goffi@necton2
parents:
diff changeset
181 self._progress_cb_map = {} #callback called when a progress is requested (key = progress id)
goffi@necton2
parents:
diff changeset
182 self.plugins = {}
goffi@necton2
parents:
diff changeset
183
goffi@necton2
parents:
diff changeset
184 self.bridge=DBusBridge()
goffi@necton2
parents:
diff changeset
185 self.bridge.register("connect", self.connect)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
186 self.bridge.register("disconnect", self.disconnect)
0
goffi@necton2
parents:
diff changeset
187 self.bridge.register("getContacts", self.memory.getContacts)
goffi@necton2
parents:
diff changeset
188 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
goffi@necton2
parents:
diff changeset
189 self.bridge.register("sendMessage", self.sendMessage)
goffi@necton2
parents:
diff changeset
190 self.bridge.register("setParam", self.setParam)
goffi@necton2
parents:
diff changeset
191 self.bridge.register("getParam", self.memory.getParam)
goffi@necton2
parents:
diff changeset
192 self.bridge.register("getParams", self.memory.getParams)
goffi@necton2
parents:
diff changeset
193 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
goffi@necton2
parents:
diff changeset
194 self.bridge.register("getHistory", self.memory.getHistory)
goffi@necton2
parents:
diff changeset
195 self.bridge.register("setPresence", self.setPresence)
goffi@necton2
parents:
diff changeset
196 self.bridge.register("addContact", self.addContact)
goffi@necton2
parents:
diff changeset
197 self.bridge.register("delContact", self.delContact)
goffi@necton2
parents:
diff changeset
198 self.bridge.register("isConnected", self.isConnected)
goffi@necton2
parents:
diff changeset
199 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
goffi@necton2
parents:
diff changeset
200 self.bridge.register("getProgress", self.getProgress)
goffi@necton2
parents:
diff changeset
201
goffi@necton2
parents:
diff changeset
202 self._import_plugins()
5
c0c92129a54b connect and disconnect management
Goffi <goffi@goffi.org>
parents: 2
diff changeset
203 #self.connect()
0
goffi@necton2
parents:
diff changeset
204
goffi@necton2
parents:
diff changeset
205
goffi@necton2
parents:
diff changeset
206 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
207 """Import all plugins found in plugins directory"""
goffi@necton2
parents:
diff changeset
208 #TODO: manage dependencies
goffi@necton2
parents:
diff changeset
209 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob ("plugins/plugin*.py"))]
goffi@necton2
parents:
diff changeset
210
goffi@necton2
parents:
diff changeset
211 for plug in plug_lst:
goffi@necton2
parents:
diff changeset
212 plug_path = 'plugins.'+plug
goffi@necton2
parents:
diff changeset
213 __import__(plug_path)
goffi@necton2
parents:
diff changeset
214 mod = sys.modules[plug_path]
goffi@necton2
parents:
diff changeset
215 plug_info = mod.PLUGIN_INFO
goffi@necton2
parents:
diff changeset
216 info ("importing plugin: %s", plug_info['name'])
goffi@necton2
parents:
diff changeset
217 self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self)
goffi@necton2
parents:
diff changeset
218
goffi@necton2
parents:
diff changeset
219 def connect(self):
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
220 if (self.isConnected()):
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
221 info("already connected !")
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
222 return
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
223 print "connecting..."
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
224 self.me = jid.JID(self.memory.getParamV("JabberID", "Connection"))
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
225 self.xmppclient = SatXMPPClient(self.me, self.memory.getParamV("Password", "Connection"),
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
226 self.memory.getParamV("Server", "Connection"), 5222)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
227 self.xmppclient.streamInitialized = self.streamInitialized
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
228
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
229 self.messageProt = SatMessageProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
230 self.messageProt.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
231
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
232 self.roster = SatRosterProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
233 self.roster.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
234
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
235 self.presence = SatPresenceProtocol(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
236 self.presence.setHandlerParent(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
237
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
238 self.xmppclient.startService()
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
239
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
240 def disconnect(self):
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
241 if (not self.isConnected()):
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
242 info("not connected !")
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
243 return
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
244 info("Disconnecting...")
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
245 self.xmppclient.stopService()
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
246
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
247 def startService(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
248 info("Salut à toi ô mon frère !")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
249 self.connect()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
250
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
251 def stopService(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
252 info("Salut aussi à Rantanplan")
0
goffi@necton2
parents:
diff changeset
253
goffi@necton2
parents:
diff changeset
254 def run(self):
goffi@necton2
parents:
diff changeset
255 debug("running app")
goffi@necton2
parents:
diff changeset
256 reactor.run()
goffi@necton2
parents:
diff changeset
257
goffi@necton2
parents:
diff changeset
258 def stop(self):
goffi@necton2
parents:
diff changeset
259 debug("stopping app")
goffi@necton2
parents:
diff changeset
260 reactor.stop()
goffi@necton2
parents:
diff changeset
261
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
262 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
263 """Called when xmlstream is OK"""
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
264 SatXMPPClient.streamInitialized(self.xmppclient)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
265 debug ("XML stream is initialized")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
266 self.xmlstream = self.xmppclient.xmlstream
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
267 self.me = self.xmppclient.jid #in case of the ressource has changed
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
268
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
269 self.roster.requestRoster()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
270
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
271 self.presence.available()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
272
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
273 #FIXME:tmp
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
274 self.xmlstream.addObserver("/iq[@type='set' or @type='get']", self.iqCb)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
275 """
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
276 ###FIXME: tmp disco ###
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
277 #self.discoHandler = disco.discoHandler()
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
278 self.memory.registerFeature("http://jabber.org/protocol/disco#info")
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
279 self.disco(self.memory.getParamV("Server", "Connection"), self.serverDisco)
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
280 #we now send our presence status
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
281
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
282 # add a callback for the messages
12
ef8060d365cb whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire)
Goffi <goffi@goffi.org>
parents: 6
diff changeset
283
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
284 #reactor.callLater(2,self.sendFile,"goffi2@jabber.goffi.int/Psi", "/tmp/fakefile")
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
285 """
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
286
0
goffi@necton2
parents:
diff changeset
287
goffi@necton2
parents:
diff changeset
288 def sendMessage(self,to,msg,type='chat'):
goffi@necton2
parents:
diff changeset
289 #FIXME: check validity of recipient
goffi@necton2
parents:
diff changeset
290 debug("Sending jabber message to %s...", to)
goffi@necton2
parents:
diff changeset
291 message = domish.Element(('jabber:client','message'))
goffi@necton2
parents:
diff changeset
292 message["to"] = jid.JID(to).full()
goffi@necton2
parents:
diff changeset
293 message["from"] = self.me.full()
goffi@necton2
parents:
diff changeset
294 message["type"] = type
goffi@necton2
parents:
diff changeset
295 message.addElement("body", "jabber:client", msg)
goffi@necton2
parents:
diff changeset
296 self.xmlstream.send(message)
goffi@necton2
parents:
diff changeset
297 self.memory.addToHistory(self.me, self.me, jid.JID(to), message["type"], unicode(msg))
goffi@necton2
parents:
diff changeset
298 self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it
goffi@necton2
parents:
diff changeset
299
goffi@necton2
parents:
diff changeset
300 def setParam(self, name, value, namespace):
goffi@necton2
parents:
diff changeset
301 """set wanted paramater and notice observers"""
goffi@necton2
parents:
diff changeset
302 info ("setting param: %s=%s in namespace %s", name, value, namespace)
goffi@necton2
parents:
diff changeset
303 self.memory.setParam(name, value, namespace)
goffi@necton2
parents:
diff changeset
304 self.bridge.paramUpdate(name, value, namespace)
goffi@necton2
parents:
diff changeset
305
goffi@necton2
parents:
diff changeset
306 def failed(self,xmlstream):
goffi@necton2
parents:
diff changeset
307 debug("failed: %s", xmlstream.getErrorMessage())
goffi@necton2
parents:
diff changeset
308 debug("failed: %s", dir(xmlstream))
goffi@necton2
parents:
diff changeset
309
goffi@necton2
parents:
diff changeset
310 def isConnected(self):
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
311 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
312 if self.xmppclient.isConnected():
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
313 return True
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
314 except AttributeError:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
315 #xmppclient not available
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
316 pass
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
317 return False
0
goffi@necton2
parents:
diff changeset
318
goffi@necton2
parents:
diff changeset
319 ## jabber methods ##
goffi@necton2
parents:
diff changeset
320
goffi@necton2
parents:
diff changeset
321 def disco (self, item, callback, node=None):
goffi@necton2
parents:
diff changeset
322 """XEP-0030 Service discovery Feature."""
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
323 """disco=client.IQ(self.xmlstream,'get')
0
goffi@necton2
parents:
diff changeset
324 disco["from"]=self.me.full()
goffi@necton2
parents:
diff changeset
325 disco["to"]=item
goffi@necton2
parents:
diff changeset
326 disco.addElement(('http://jabber.org/protocol/disco#info', 'query'))
goffi@necton2
parents:
diff changeset
327 disco.addCallback(callback)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
328 disco.send()"""
0
goffi@necton2
parents:
diff changeset
329
goffi@necton2
parents:
diff changeset
330
goffi@necton2
parents:
diff changeset
331 def setPresence(self, to="", type="", show="", status="", priority=0):
goffi@necton2
parents:
diff changeset
332 """Send our presence information"""
goffi@necton2
parents:
diff changeset
333 if not type in ["", "unavailable", "subscribed", "subscribe",
goffi@necton2
parents:
diff changeset
334 "unsubscribe", "unsubscribed", "prob", "error"]:
goffi@necton2
parents:
diff changeset
335 error("Type error !")
goffi@necton2
parents:
diff changeset
336 #TODO: throw an error
goffi@necton2
parents:
diff changeset
337 return
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
338 to_jid=jid.JID(to)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
339 #TODO: refactor subscription bridge API
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
340 if type=="":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
341 self.presence.available(to_jid, show, status, priority)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
342 elif type=="subscribe":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
343 self.presence.subscribe(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
344 elif type=="subscribed":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
345 self.presence.subscribed(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
346 elif type=="unsubscribe":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
347 self.presence.unsubscribe(to_jid)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
348 elif type=="unsubscribed":
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
349 self.presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
350
goffi@necton2
parents:
diff changeset
351
goffi@necton2
parents:
diff changeset
352 def addContact(self, to):
goffi@necton2
parents:
diff changeset
353 """Add a contact in roster list"""
goffi@necton2
parents:
diff changeset
354 to_jid=jid.JID(to)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
355 self.roster.addItem(to_jid.userhost())
0
goffi@necton2
parents:
diff changeset
356 self.setPresence(to_jid.userhost(), "subscribe")
goffi@necton2
parents:
diff changeset
357
goffi@necton2
parents:
diff changeset
358 def delContact(self, to):
goffi@necton2
parents:
diff changeset
359 """Remove contact from roster list"""
goffi@necton2
parents:
diff changeset
360 to_jid=jid.JID(to)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
361 self.roster.removeItem(to_jid.userhost())
0
goffi@necton2
parents:
diff changeset
362 self.bridge.contactDeleted(to)
goffi@necton2
parents:
diff changeset
363
goffi@necton2
parents:
diff changeset
364
goffi@necton2
parents:
diff changeset
365 ## callbacks ##
goffi@necton2
parents:
diff changeset
366
goffi@necton2
parents:
diff changeset
367 def add_IQ_cb(self, ns, cb):
goffi@necton2
parents:
diff changeset
368 """Add an IQ callback on namespace ns"""
goffi@necton2
parents:
diff changeset
369 debug ("Registered callback for namespace %s", ns)
goffi@necton2
parents:
diff changeset
370 self._iq_cb_map[ns]=cb
goffi@necton2
parents:
diff changeset
371
goffi@necton2
parents:
diff changeset
372 def iqCb(self, stanza):
goffi@necton2
parents:
diff changeset
373 info ("iqCb")
goffi@necton2
parents:
diff changeset
374 debug ("="*20)
goffi@necton2
parents:
diff changeset
375 debug ("DEBUG:\n")
goffi@necton2
parents:
diff changeset
376 debug (stanza.toXml().encode('utf-8'))
goffi@necton2
parents:
diff changeset
377 debug ("="*20)
goffi@necton2
parents:
diff changeset
378 #FIXME: temporary ugly code
goffi@necton2
parents:
diff changeset
379 uri = stanza.firstChildElement().uri
goffi@necton2
parents:
diff changeset
380 if self._iq_cb_map.has_key(uri):
goffi@necton2
parents:
diff changeset
381 self._iq_cb_map[uri](stanza)
goffi@necton2
parents:
diff changeset
382 #TODO: manage errors stanza
goffi@necton2
parents:
diff changeset
383
goffi@necton2
parents:
diff changeset
384
goffi@necton2
parents:
diff changeset
385
goffi@necton2
parents:
diff changeset
386 def serverDisco(self, disco):
goffi@necton2
parents:
diff changeset
387 """xep-0030 Discovery Protocol."""
goffi@necton2
parents:
diff changeset
388 for element in disco.firstChildElement().elements():
goffi@necton2
parents:
diff changeset
389 if element.name=="feature":
goffi@necton2
parents:
diff changeset
390 debug ("Feature dectetee: %s",element["var"])
goffi@necton2
parents:
diff changeset
391 self.server_features.append(element["var"])
goffi@necton2
parents:
diff changeset
392 elif element.name=="identity":
goffi@necton2
parents:
diff changeset
393 debug ("categorie= %s",element["category"])
goffi@necton2
parents:
diff changeset
394 debug ("features= %s",self.server_features)
goffi@necton2
parents:
diff changeset
395
goffi@necton2
parents:
diff changeset
396 ## Generic HMI ##
goffi@necton2
parents:
diff changeset
397
goffi@necton2
parents:
diff changeset
398 def askConfirmation(self, id, type, data, cb):
goffi@necton2
parents:
diff changeset
399 """Add a confirmation callback"""
goffi@necton2
parents:
diff changeset
400 if self._waiting_conf.has_key(id):
goffi@necton2
parents:
diff changeset
401 error ("Attempt to register two callbacks for the same confirmation")
goffi@necton2
parents:
diff changeset
402 else:
goffi@necton2
parents:
diff changeset
403 self._waiting_conf[id] = cb
goffi@necton2
parents:
diff changeset
404 self.bridge.askConfirmation(type, id, data)
goffi@necton2
parents:
diff changeset
405
goffi@necton2
parents:
diff changeset
406
goffi@necton2
parents:
diff changeset
407 def confirmationAnswer(self, id, accepted, data):
goffi@necton2
parents:
diff changeset
408 """Called by frontends to answer confirmation requests"""
goffi@necton2
parents:
diff changeset
409 debug ("Received confirmation answer for id [%s]: %s", id, "accepted" if accepted else "refused")
goffi@necton2
parents:
diff changeset
410 if not self._waiting_conf.has_key(id):
goffi@necton2
parents:
diff changeset
411 error ("Received an unknown confirmation")
goffi@necton2
parents:
diff changeset
412 else:
goffi@necton2
parents:
diff changeset
413 cb = self._waiting_conf[id]
goffi@necton2
parents:
diff changeset
414 del self._waiting_conf[id]
goffi@necton2
parents:
diff changeset
415 cb(id, accepted, data)
goffi@necton2
parents:
diff changeset
416
goffi@necton2
parents:
diff changeset
417 def registerProgressCB(self, id, CB):
goffi@necton2
parents:
diff changeset
418 """Register a callback called when progress is requested for id"""
goffi@necton2
parents:
diff changeset
419 self._progress_cb_map[id] = CB
goffi@necton2
parents:
diff changeset
420
goffi@necton2
parents:
diff changeset
421 def removeProgressCB(self, id):
goffi@necton2
parents:
diff changeset
422 """Remove a progress callback"""
goffi@necton2
parents:
diff changeset
423 if not self._progress_cb_map.has_key(id):
goffi@necton2
parents:
diff changeset
424 error ("Trying to remove an unknow progress callback")
goffi@necton2
parents:
diff changeset
425 else:
goffi@necton2
parents:
diff changeset
426 del self._progress_cb_map[id]
goffi@necton2
parents:
diff changeset
427
goffi@necton2
parents:
diff changeset
428 def getProgress(self, id):
goffi@necton2
parents:
diff changeset
429 """Return a dict with progress information
goffi@necton2
parents:
diff changeset
430 data['position'] : current possition
goffi@necton2
parents:
diff changeset
431 data['size'] : end_position
goffi@necton2
parents:
diff changeset
432 """
goffi@necton2
parents:
diff changeset
433 data = {}
goffi@necton2
parents:
diff changeset
434 try:
goffi@necton2
parents:
diff changeset
435 self._progress_cb_map[id](data)
goffi@necton2
parents:
diff changeset
436 except KeyError:
goffi@necton2
parents:
diff changeset
437 pass
goffi@necton2
parents:
diff changeset
438 #debug("Requested progress for unknown id")
goffi@necton2
parents:
diff changeset
439 return data
goffi@necton2
parents:
diff changeset
440
goffi@necton2
parents:
diff changeset
441
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
442 application = service.Application('SàT')
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
443 service = SAT()
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
444 service.setServiceParent(application)
0
goffi@necton2
parents:
diff changeset
445
2
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
446
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
447 #app.memory.save() #FIXME: not the best place
c49345fd7737 refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents: 1
diff changeset
448 #debug("Good Bye")