comparison sat.tac @ 5:c0c92129a54b

connect and disconnect management
author Goffi <goffi@goffi.org>
date Mon, 19 Oct 2009 23:49:31 +0200
parents c49345fd7737
children 5799493fa548
comparison
equal deleted inserted replaced
4:3c1cefd41186 5:c0c92129a54b
79 self.bridge.register("isConnected", self.isConnected) 79 self.bridge.register("isConnected", self.isConnected)
80 self.bridge.register("confirmationAnswer", self.confirmationAnswer) 80 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
81 self.bridge.register("getProgress", self.getProgress) 81 self.bridge.register("getProgress", self.getProgress)
82 82
83 self._import_plugins() 83 self._import_plugins()
84 self.connect() 84 #self.connect()
85 85
86 86
87 def _import_plugins(self): 87 def _import_plugins(self):
88 """Import all plugins found in plugins directory""" 88 """Import all plugins found in plugins directory"""
89 #TODO: manage dependencies 89 #TODO: manage dependencies
97 info ("importing plugin: %s", plug_info['name']) 97 info ("importing plugin: %s", plug_info['name'])
98 self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self) 98 self.plugins[plug_info['import_name']] = getattr(mod, plug_info['main'])(self)
99 99
100 def connect(self): 100 def connect(self):
101 print "connecting..." 101 print "connecting..."
102 reactor.connectTCP(self.memory.getParamV("Server", "Connection"), 5222, self.factory)
103 self.connectionStatus="online" #TODO: check if connection is OK
104 self.connected=True #TODO: use startedConnecting and clientConnectionLost of XMPPClientFactory
102 105
103 def getService(self): 106 def getService(self):
104 print "GetService !" 107 print "GetService !"
105 """if (self.connected): 108 """if (self.connected):
106 info("already connected !") 109 info("already connected !")
107 return""" 110 return"""
108 info("Getting client...") 111 info("Getting service...")
109 self.me = jid.JID(self.memory.getParamV("JabberID", "Connection")) 112 self.me = jid.JID(self.memory.getParamV("JabberID", "Connection"))
110 self.factory = client.XMPPClientFactory(self.me, self.memory.getParamV("Password", "Connection")) 113 self.factory = client.XMPPClientFactory(self.me, self.memory.getParamV("Password", "Connection"))
111 self.factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,self.authd) 114 self.factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,self.authd)
112 self.factory.addBootstrap(xmlstream.INIT_FAILED_EVENT,self.failed) 115 self.factory.addBootstrap(xmlstream.INIT_FAILED_EVENT,self.failed)
113 self.connectionStatus="online" #TODO: check if connection is OK 116 self.connectionStatus="online" #TODO: check if connection is OK
117 def disconnect(self): 120 def disconnect(self):
118 if (not self.connected): 121 if (not self.connected):
119 info("not connected !") 122 info("not connected !")
120 return 123 return
121 info("Disconnecting...") 124 info("Disconnecting...")
125 self.factory.stopTrying()
126 if self.xmlstream:
127 self.xmlstream.sendFooter()
128 self.connectionStatus="offline" #TODO: check if connection is OK
129 self.connected=False #TODO: use startedConnecting and clientConnectionLost of XMPPClientFactory
122 130
123 def run(self): 131 def run(self):
124 debug("running app") 132 debug("running app")
125 reactor.run() 133 reactor.run()
126 134