gajim-plural/common/hub.py

65 lines
1.6 KiB
Python
Raw Normal View History

2003-10-22 20:45:13 +02:00
#!/usr/bin/env python
## common/hub.py
##
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
2004-06-18 11:25:15 +02:00
## - Vincent Hanquez <tab@snarc.org>
2003-10-22 20:45:13 +02:00
##
## Copyright (C) 2003 Gajim Team
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import Queue
import common.plugin
import common.thread
""" Hub definitions """
class GajimHub:
2004-07-08 21:56:30 +02:00
def __init__(self):
self.queues = {}
# {event1:[queue1, queue2]}
self.events = {}
self.queueIn = self.newQueue('in', 100)
# END __init__
2003-10-22 20:45:13 +02:00
2004-07-08 21:56:30 +02:00
def newQueue(self, name, size):
""" Creates a new queue """
qu = Queue.Queue(size)
self.queues[name] = qu
return qu
# END newQueue
2003-10-22 20:45:13 +02:00
2004-07-08 21:56:30 +02:00
def newPlugin(self, name):
"""Creates a new Plugin """
qu = self.newQueue(name, 100)
pl = common.plugin.GajimPlugin(name, qu, self.queueIn)
return pl
# END newPlugin
2003-10-22 20:45:13 +02:00
2004-07-08 21:56:30 +02:00
def register(self, name, event):
""" Records a plugin from an event """
qu = self.queues[name]
if self.events.has_key(event) :
if not qu in self.events[event]:
self.events[event].append(qu)
2004-07-08 21:56:30 +02:00
else :
self.events[event] = [qu]
# END register
def sendPlugin(self, event, con, data):
""" Sends an event to registered plugins"""
2004-07-08 21:56:30 +02:00
if self.events.has_key(event):
for i in self.events[event]:
i.put((event, con, data))
# END sendPlugin
2003-10-22 20:45:13 +02:00
# END GajimHub