mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 22:52:24 +03:00
added event manager
This commit is contained in:
parent
092cb69d43
commit
b4c8608cb4
4 changed files with 51 additions and 0 deletions
|
@ -10,6 +10,7 @@ from base.messaging.MessageReceiver import MessageReceiver
|
|||
from base.messaging.MessageSender import MessageSender
|
||||
from base.registration.Registration import Registration
|
||||
from base.messaging.MessageResponseQueue import MessageResponseQueue
|
||||
from base.event.EventManager import EventManager
|
||||
from base.plugin.PluginManager import PluginManager
|
||||
from base.task.TaskManager import TaskManager
|
||||
from multiprocessing import Process
|
||||
|
@ -20,6 +21,10 @@ import sys,logging,queue,time
|
|||
class AhenkDeamon(BaseDaemon):
|
||||
"""docstring for AhenkDeamon"""
|
||||
|
||||
def reload(self,msg):
|
||||
# reload service here
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print ("merhaba dunya")
|
||||
|
||||
|
@ -39,6 +44,12 @@ class AhenkDeamon(BaseDaemon):
|
|||
logger.info("this is info log")
|
||||
globalscope.setLogger(logger)
|
||||
|
||||
eventManager = EventManager()
|
||||
globalscope.setEventManager(eventManager)
|
||||
|
||||
eventManager.register_event('registration_ok',self.reload)
|
||||
|
||||
|
||||
pluginManager = PluginManager()
|
||||
pluginManager.loadPlugins()
|
||||
globalscope.setPluginManager(pluginManager)
|
||||
|
|
|
@ -17,6 +17,7 @@ class Scope(object):
|
|||
self.pluginManager=None
|
||||
self.taskManager=None
|
||||
self.responseQueue=None
|
||||
self.eventManager=None
|
||||
|
||||
@staticmethod
|
||||
def getInstance():
|
||||
|
@ -71,3 +72,9 @@ class Scope(object):
|
|||
|
||||
def setResponseQueue(self,responseQueue):
|
||||
self.responseQueue=responseQueue
|
||||
|
||||
def getEventManager(self):
|
||||
return self.eventManager
|
||||
|
||||
def setEventManager(self,eventManager):
|
||||
self.eventManager=eventManager
|
||||
|
|
19
opt/ahenk/base/event/EventBase.py
Normal file
19
opt/ahenk/base/event/EventBase.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
class EventBase():
|
||||
listeners = []
|
||||
def __init__(self):
|
||||
self.listeners.append(self)
|
||||
self.listener_events = []
|
||||
def register_event(self, event_name, callback_func):
|
||||
self.listener_events.append({'event_name' : event_name, 'callback_func' : callback_func})
|
||||
|
||||
|
||||
class Event():
|
||||
def __init__(self, event_name, *callback_args):
|
||||
for listener in EventBase.listeners:
|
||||
for listener_cls in listener.listener_events:
|
||||
if listener_cls['event_name'] == event_name:
|
||||
listener_cls['callback_func'](*callback_args)
|
14
opt/ahenk/base/event/EventManager.py
Normal file
14
opt/ahenk/base/event/EventManager.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
from base.event.EventBase import EventBase,Event
|
||||
|
||||
class EventManager(EventBase):
|
||||
"""docstring for EventManager"""
|
||||
def __init__(self):
|
||||
EventBase.__init__(self)
|
||||
|
||||
|
||||
def fireEvent(self,event_name,*args):
|
||||
Event(event_name,*args)
|
Loading…
Reference in a new issue