merge conflicts

This commit is contained in:
Volkan Şahin 2016-03-04 19:24:43 +02:00
commit 390d1f3b12
4 changed files with 52 additions and 0 deletions

View file

@ -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)

View file

@ -18,6 +18,8 @@ class Scope(object):
self.taskManager=None
self.responseQueue=None
self.registration=None
self.eventManager=None
@staticmethod
def getInstance():
@ -78,3 +80,9 @@ class Scope(object):
def setRegistration(self,registration):
self.registration=registration
def getEventManager(self):
return self.eventManager
def setEventManager(self,eventManager):
self.eventManager=eventManager

View 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)

View 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)