2003-10-22 20:45:13 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
## common/hub.py
|
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@crans.org>
|
|
|
|
## - Vincent Hanquez <tab@tuxfamily.org>
|
2003-10-23 11:54:19 +02:00
|
|
|
## - David Ferlier <david@yazzy.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:
|
|
|
|
def __init__(self):
|
|
|
|
self.queues = {}
|
|
|
|
""" {event1:[queue1, queue2]} """
|
2003-11-01 20:41:35 +01:00
|
|
|
self.events = {}
|
2003-10-22 20:45:13 +02:00
|
|
|
self.queueIn = self.newQueue('in', 100)
|
|
|
|
# END __init__
|
|
|
|
|
|
|
|
def newQueue(self, name, size):
|
|
|
|
""" Creates a new queue """
|
|
|
|
qu = Queue.Queue(size)
|
|
|
|
self.queues[name] = qu
|
|
|
|
return qu
|
|
|
|
# END newQueue
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def register(self, name, event):
|
|
|
|
""" Records a plugin from an event """
|
|
|
|
qu = self.queues[name]
|
2003-11-01 20:41:35 +01:00
|
|
|
if self.events.has_key(event) :
|
|
|
|
self.events[event].append(qu)
|
|
|
|
else :
|
|
|
|
self.events[event] = [qu]
|
2003-10-22 20:45:13 +02:00
|
|
|
# END register
|
|
|
|
|
|
|
|
def sendPlugin(self, event, data):
|
|
|
|
""" Sends an event to registered plugins
|
|
|
|
NOTIFY : ('NOTIFY', (user, status, message))
|
|
|
|
MSG : ('MSG', (user, msg))
|
2003-10-29 13:58:58 +01:00
|
|
|
ROSTER : ('ROSTER', {jid:{'status':_, 'name':_, 'show':_, 'groups':[], 'online':_, 'ask':_, 'sub':_} ,jid:{}})
|
2003-10-28 20:37:40 +01:00
|
|
|
SUBSCRIBED : ('SUBSCRIBED', {'jid':_, 'nom':_, 'server':_, 'resource':_, 'status':_, 'show':_})"""
|
2003-10-22 20:45:13 +02:00
|
|
|
|
|
|
|
if self.events.has_key(event):
|
|
|
|
for i in self.events[event]:
|
|
|
|
i.put((event, data))
|
|
|
|
# END sendPlugin
|
|
|
|
# END GajimHub
|