class ProtocolFactory(protocol.ServerFactory): protocol = TCPProtocol eventHandler = None def __init__(self): self.clientProtocols = [] def broadcastEvent(self, event): for client in self.clientProtocols: client.sendEvent(event) if __name__ == '__main__': os.chdir(os.path.dirname(__file__)) set_proc_name("snepevtd") ami = AMIWorker(config.get('ambiente', 'ip_sock'), 5038, config.get('ambiente', 'user_sock'), config.get('ambiente', 'pass_sock')) messenger = ProtocolFactory() reactor.listenTCP(5030, messenger) ami.handler = EvtHandler(messenger) messenger.eventHandler = ami.handler reactor.run()
return trunk def findOwner(self, interface): c = Trunks.db.cursor() c.execute("SELECT id, id_regex FROM trunks") haveData = True while haveData: trunk = c.fetchone() if trunk == None: haveData = False else: if re.match(trunk[1], interface, re.IGNORECASE): return self._assemble({'id':trunk[0]}) return None db = DB(config.get('ambiente','db.username'), config.get('ambiente','db.password'), config.get('ambiente','db.dbname')) Extensions.db = db Trunks.db = db def findOwner(interface): t = Trunks() trunk = t.findOwner(interface) if trunk is not None: return trunk else: e = Extensions() return e.findOwner(interface)
def connectionLost(self, reason): log.info("Client Disconnected: %s" % self.transport.client[0]) self.factory.clientProtocols.remove(self) class ProtocolFactory(protocol.ServerFactory): protocol = TCPProtocol eventHandler = None def __init__(self): self.clientProtocols = [] def broadcastEvent(self, event): for client in self.clientProtocols: client.sendEvent(event) if __name__ == '__main__': os.chdir(os.path.dirname(__file__)) set_proc_name("snepevtd") ami = AMIWorker(config.get('ambiente','ip_sock'), 5038, config.get('ambiente','user_sock'), config.get('ambiente','pass_sock')) messenger = ProtocolFactory() reactor.listenTCP(5030,messenger) ami.handler = EvtHandler(messenger) messenger.eventHandler = ami.handler reactor.run()