Skip to content
Snippets Groups Projects
Commit 47676e59 authored by jkerdreu's avatar jkerdreu
Browse files

rx_handlers are now subscribers

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2712 b32b6428-25c9-4566-ad07-03861ab6144f
parent e5e809ab
Branches
No related tags found
No related merge requests found
......@@ -40,11 +40,10 @@ class Engine(object):
self.running = False # engine is running or not
self.timers = [] # functions to call periodic
self.__last_timer = 0 # last timer check
self.rx_handlers =[self.handle_request] # message receive workflow
self.subscribers =[self.handle_request] # message receive workflow
self.__attributesChange = [] # list of XAALAttributes instances
self.__txFifo = collections.deque() # tx msg fifo
self.__alives = [] # list of alive devices
# start network
self.network = NetworkConnector(address, port, hops)
......@@ -171,7 +170,7 @@ class Engine(object):
self.__attributesChange = [] # empty array
#####################################################
# xAAL messages rx handlers
# xAAL messages subscribers
#####################################################
def receive_msg(self):
"""return new received message or None"""
......@@ -186,17 +185,17 @@ class Engine(object):
result = msg
return result
def add_rx_handler(self,func):
self.rx_handlers.append(func)
def subscribe(self,func):
self.subscribers.append(func)
def remove_rx_hanlder(self,func):
self.rx_handlers.remove(func)
def unsubscribe(self,func):
self.subscribers.remove(func)
def process_rx_msg(self):
def process_subscribers(self):
"""process incomming messages"""
msg = self.receive_msg()
if msg:
for func in self.rx_handlers:
for func in self.subscribers:
func(msg)
self.process_attributesChange()
......@@ -206,7 +205,7 @@ class Engine(object):
cnt = 0
msg = self.receive_msg()
while msg:
for func in self.rx_handlers:
for func in self.subscribers:
func(msg)
self.process_attributesChange()
# only flush some message, to limit rate
......@@ -308,7 +307,7 @@ class Engine(object):
Send msgs from the Tx Buffer
"""
# Process xAAL msg received, filter msg and process request
self.process_rx_msg()
self.process_subscribers()
# Process timers
self.process_timers()
# Process attributes change for devices due to timers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment