root/branches/gajim_0.2-2/common/hub.py

Revision 196, 2.0 kB (checked in by tab, 4 years ago)

change my mail address

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Line 
1#!/usr/bin/env python
2##      common/hub.py
3##
4## Gajim Team:
5##      - Yann Le Boulanger <asterix@crans.org>
6##      - Vincent Hanquez <tab@snarc.org>
7##
8##      Copyright (C) 2003 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import Queue
21import common.plugin
22import common.thread
23
24""" Hub definitions """
25
26class GajimHub:
27    def __init__(self):
28        self.queues = {}
29        """ {event1:[queue1, queue2]} """
30        self.events = {}
31        self.queueIn = self.newQueue('in', 100)
32    # END __init__
33
34    def newQueue(self, name, size):
35        """ Creates a new queue """
36        qu = Queue.Queue(size)
37        self.queues[name] = qu
38        return qu
39    # END newQueue
40       
41    def newPlugin(self, name):
42        """Creates a new Plugin """
43        qu = self.newQueue(name, 100)
44        pl = common.plugin.GajimPlugin(name, qu, self.queueIn)
45        return pl
46    # END newPlugin
47
48    def register(self, name, event):
49        """ Records a plugin from an event """
50        qu = self.queues[name]
51        if self.events.has_key(event) :
52                self.events[event].append(qu)
53        else :
54                self.events[event] = [qu]
55    # END register
56
57    def sendPlugin(self, event, con, data):
58        """ Sends an event to registered plugins
59                NOTIFY : ('NOTIFY', (user, status, message))
60                MSG : ('MSG', (user, msg))
61                ROSTER : ('ROSTER', {jid:{'status':_, 'name':_, 'show':_, 'groups':[], 'online':_, 'ask':_, 'sub':_} ,jid:{}})
62                SUBSCRIBED : ('SUBSCRIBED', {'jid':_, 'nom':_, 'server':_, 'resource':_, 'status':_, 'show':_})"""
63
64        if self.events.has_key(event):
65            for i in self.events[event]:
66                i.put((event, con, data))
67    # END sendPlugin
68# END GajimHub
Note: See TracBrowser for help on using the browser.