Skip to content
Snippets Groups Projects
Commit 5c20cddf authored by ptangu01's avatar ptangu01
Browse files

work on alive management for device, add list of current alives devices

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1337 b32b6428-25c9-4566-ad07-03861ab6144f
parent aac8465d
Branches
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ class Engine:
self.__run = True
self.__attributesChange = [] # list of XAALAttributes instances
self.__txFifo = deque() # tx msg fifo
self.__alives = [] # list of alive devices
#####################################################
# Attributes
......@@ -67,10 +68,16 @@ class Engine:
if dev not in self.__devices:
self.__devices.append(dev)
dev.setEngine(self)
# Add tuple (dev,nextAlive) to alives list
nextAlive = time.time() + dev.getAlivePeriod()
self.__alives.append((dev,nextAlive))
def unregisterDevice(self,dev):
dev.setEngine(None)
# Remove dev from devices list
self.__devices.remove(dev)
# Remove dev from alives list
self.delAlive(dev)
# Fifo for msg to send
def queue(self,msg):
......@@ -113,6 +120,26 @@ class Engine:
#####################################################
# Alive messages
#####################################################
def delAlive(self,dev):
"""remove dev from the alives list of tuples (dev,alives)
:param dev: instance of xAAL device
:type dev: Device"""
for i, (d, t) in enumerate(self.__alives):
if d == dev:
del self.__alives[i]
break
def upAlive(self,dev):
"""update alive for device dev from the alives list of tuples (dev,aliveTimeout)
:param dev: instance of xAAL device
:type dev: Device"""
for i, (d, t) in enumerate(self.__alives):
if d == dev:
nextAlive = time.time() + dev.getAlivePeriod()
self.__alives[i]=(dev,nextAlive)
break
def sendAlive(self,dev):
""" send a Alive message for a given device """
timeout = dev.getTimeout()
......@@ -128,11 +155,12 @@ class Engine:
def processAlives(self):
""" periodic sending alive messages """
currentTime = time.time()
for dev in self.getDevices():
if dev.getAliveTimeout() < currentTime:
now = time.time()
for i,(dev,t) in enumerate(self.__alives):
if t < now:
self.sendAlive(dev)
dev.updateAliveTimeout()
nextAlive = now + dev.getAlivePeriod()
self.__alives[i]=(dev,nextAlive)
#####################################################
# Attributes changes
......@@ -242,7 +270,7 @@ class Engine:
def start(self):
for dev in self.getDevices():
self.sendAlive(dev)
dev.updateAliveTimeout()
self.upAlive(dev)
def stop(self):
self.__run=False
......@@ -323,4 +351,3 @@ def getArgumentsForMethod(method):
pass
return args.args
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment