Skip to content
This repository
Browse code

First working plugin commit.

  • Loading branch information...
commit 48794ef1496ec725dc74cae0f882ab1c1de7e2df 1 parent d1e71da
Steven authored
5 Connectors/IRCConnector.py
@@ -44,7 +44,9 @@ class IRCConnector(protocol.ClientFactory,irc.IRCClient,object):
44 44 def HandleResponse(self,eventInfo):
45 45 f = getattr(self,eventInfo[0],None)
46 46 if f:
  47 + print eventInfo
47 48 f(*eventInfo[1:])
  49 + self.transport.doWrite()
48 50 def SetEventHandler(self,func):
49 51 self.EventHandler=func
50 52 def buildProtocol(self,addr):
@@ -60,6 +62,9 @@ def handleCommand(self,cmd,prefix,params):
60 62 event["target"]=params[0]
61 63 if len(params)==2:
62 64 event["message"]=params[1]
  65 + print "Connector is producing ->"
  66 + print params
  67 + print event
63 68 self.EventHandler(event)
64 69
65 70
4 Core.py
@@ -45,7 +45,9 @@ def HandleEvent(self,event):
45 45 print matches
46 46
47 47 for inst,func,args in matches:
48   - newEvent = dictJoin(args,{"self":inst,"response":ro})
  48 +
  49 + newEvent = dictJoin(event,dictJoin(args,{"self":inst,"response":ro}))
  50 +
49 51 #service additions would be here
50 52 pd.Enqueue((func,newEvent))
51 53
22 PluginDispatcher.py
... ... @@ -1,20 +1,23 @@
1 1 import threading
2 2 from Util import call
  3 +from time import sleep
3 4
4 5 class PluginDispatcherWorkerThread(threading.Thread):
5 6 running = True
6 7 ID = -1
7   - pushResponse = None
8   - def __init__(self,producer,handler,ID):
  8 + produce = None
  9 + consume = None
  10 + def __init__(self,ID):
9 11 threading.Thread.__init__(self)
10 12 self.ID = ID
11   - self.pushResponse = handler
12   - self.getFunc = producer
13 13
14 14
15 15 def run(self):
16 16 while True:
17   - func,args = self.getFunc()
  17 + while self.produce==None or self.consume==None:
  18 + sleep(1)
  19 +
  20 + func,args = self.produce()
18 21 if not self.running:
19 22 print "WorkerThread",self.ID,"Shuting down"
20 23 return
@@ -22,7 +25,7 @@ def run(self):
22 25 print ""
23 26 response = call(func,args)
24 27 if response:
25   - self.pushResponse(response)
  28 + self.consume(response)
26 29
27 30 def Stop(self):
28 31 self.running = False
@@ -35,12 +38,13 @@ class PluginDispatcher:
35 38 ResponseHandler=None
36 39 def __init__(self):
37 40 for i in xrange(5):
38   - worker = PluginDispatcherWorkerThread(self.dequeueFunc,self.ResponseHandler,i)
  41 + worker = PluginDispatcherWorkerThread(i)
39 42 #worker.setDaemon(True)
  43 + worker.produce = self.Dequeue
40 44 self.__workerThreads__+=[worker]
41 45 worker.start()
42 46
43   - def dequeueFunc(self):
  47 + def Dequeue(self):
44 48 self.__lock__.acquire()
45 49 while not self.__queue__:
46 50 self.__lock__.wait()
@@ -51,6 +55,8 @@ def dequeueFunc(self):
51 55
52 56 def SetResponseHandler(self,resp):
53 57 self.ResponseHandler = resp
  58 + for worker in self.__workerThreads__:
  59 + worker.consume=resp
54 60
55 61 def Enqueue(self, t):
56 62 self.__lock__.acquire()
4 PluginManager.py
@@ -86,6 +86,10 @@ def GetMatchingFunctions(self,event):
86 86
87 87 args = self.tryMatch(func,event)
88 88 if args:
  89 + print "PM: Matched function:"
  90 + print inst
  91 + print func
  92 + print args
89 93 matched+=[(inst,func,args)]
90 94 return matched
91 95
2  Plugins/Test.py
@@ -5,7 +5,7 @@ def foo(self,response,nick,message):
5 5 return response.msg(nick,message)
6 6
7 7
8   - @bindFunction(command="(.*)")
  8 + @bindFunction(command="(.*)AAA")
9 9 def bar(self):
10 10 print "BAR"
11 11

0 comments on commit 48794ef

Please sign in to comment.
Something went wrong with that request. Please try again.