Skip to content
Browse files

First working plugin commit.

  • Loading branch information...
1 parent d1e71da commit 48794ef1496ec725dc74cae0f882ab1c1de7e2df @theepicsnail committed Mar 6, 2011
Showing with 27 additions and 10 deletions.
  1. +5 −0 Connectors/IRCConnector.py
  2. +3 −1 Core.py
  3. +14 −8 PluginDispatcher.py
  4. +4 −0 PluginManager.py
  5. +1 −1 Plugins/Test.py
View
5 Connectors/IRCConnector.py
@@ -44,7 +44,9 @@ class IRCConnector(protocol.ClientFactory,irc.IRCClient,object):
def HandleResponse(self,eventInfo):
f = getattr(self,eventInfo[0],None)
if f:
+ print eventInfo
f(*eventInfo[1:])
+ self.transport.doWrite()
def SetEventHandler(self,func):
self.EventHandler=func
def buildProtocol(self,addr):
@@ -60,6 +62,9 @@ def handleCommand(self,cmd,prefix,params):
event["target"]=params[0]
if len(params)==2:
event["message"]=params[1]
+ print "Connector is producing ->"
+ print params
+ print event
self.EventHandler(event)
View
4 Core.py
@@ -45,7 +45,9 @@ def HandleEvent(self,event):
print matches
for inst,func,args in matches:
- newEvent = dictJoin(args,{"self":inst,"response":ro})
+
+ newEvent = dictJoin(event,dictJoin(args,{"self":inst,"response":ro}))
+
#service additions would be here
pd.Enqueue((func,newEvent))
View
22 PluginDispatcher.py
@@ -1,28 +1,31 @@
import threading
from Util import call
+from time import sleep
class PluginDispatcherWorkerThread(threading.Thread):
running = True
ID = -1
- pushResponse = None
- def __init__(self,producer,handler,ID):
+ produce = None
+ consume = None
+ def __init__(self,ID):
threading.Thread.__init__(self)
self.ID = ID
- self.pushResponse = handler
- self.getFunc = producer
def run(self):
while True:
- func,args = self.getFunc()
+ while self.produce==None or self.consume==None:
+ sleep(1)
+
+ func,args = self.produce()
if not self.running:
print "WorkerThread",self.ID,"Shuting down"
return
print "WorkerThread",self.ID,func,args
print ""
response = call(func,args)
if response:
- self.pushResponse(response)
+ self.consume(response)
def Stop(self):
self.running = False
@@ -35,12 +38,13 @@ class PluginDispatcher:
ResponseHandler=None
def __init__(self):
for i in xrange(5):
- worker = PluginDispatcherWorkerThread(self.dequeueFunc,self.ResponseHandler,i)
+ worker = PluginDispatcherWorkerThread(i)
#worker.setDaemon(True)
+ worker.produce = self.Dequeue
self.__workerThreads__+=[worker]
worker.start()
- def dequeueFunc(self):
+ def Dequeue(self):
self.__lock__.acquire()
while not self.__queue__:
self.__lock__.wait()
@@ -51,6 +55,8 @@ def dequeueFunc(self):
def SetResponseHandler(self,resp):
self.ResponseHandler = resp
+ for worker in self.__workerThreads__:
+ worker.consume=resp
def Enqueue(self, t):
self.__lock__.acquire()
View
4 PluginManager.py
@@ -86,6 +86,10 @@ def GetMatchingFunctions(self,event):
args = self.tryMatch(func,event)
if args:
+ print "PM: Matched function:"
+ print inst
+ print func
+ print args
matched+=[(inst,func,args)]
return matched
View
2 Plugins/Test.py
@@ -5,7 +5,7 @@ def foo(self,response,nick,message):
return response.msg(nick,message)
- @bindFunction(command="(.*)")
+ @bindFunction(command="(.*)AAA")
def bar(self):
print "BAR"

0 comments on commit 48794ef

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