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

AoiLib merge in progress

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2727 b32b6428-25c9-4566-ad07-03861ab6144f
parent a690423d
No related branches found
No related tags found
No related merge requests found
......@@ -12,14 +12,11 @@ import collections
from decorator import decorator
import asyncio
import uvloop
import aiomonitor
uvloop.install()
import logging
logger = logging.getLogger(__name__)
class Engine(CoreEngine):
def __init__(self,address=config.address,port=config.port,hops=config.hops,key=config.key):
......@@ -27,7 +24,6 @@ class Engine(CoreEngine):
self.state = EngineState.halt
self.timers = [] # functions to call periodic
self.__last_timer = 0 # last timer check
self.subscribers =[self.handle_request] # message receive workflow
self.__attributesChange = [] # list of XAALAttributes instances
......@@ -41,13 +37,7 @@ class Engine(CoreEngine):
async def process_timers(self):
expire_list = []
if len(self.timers)!=0 :
now = time.time()
# little hack to avoid to check timer to often.
# w/ this enable timer precision is bad, but far enougth
if (now - self.__last_timer) < 0.4: return
for t in self.timers:
if t.deadline < now:
try:
......@@ -66,8 +56,6 @@ class Engine(CoreEngine):
for t in expire_list:
self.remove_timer(t)
self.__last_timer = now
async def receive_msg(self):
"""return new received message or None"""
data = await self.network.get_data()
......@@ -96,7 +84,7 @@ class Engine(CoreEngine):
self.process_attributesChange()
async def loop(self):
pass
logger.warning('Never call me')
#await self.process_rx_msg()
# Process attributes change for devices due to timers
#self.process_attributesChange()
......@@ -111,17 +99,17 @@ class Engine(CoreEngine):
return
await asyncio.sleep(0.1)
async def boot(self):
async def boot_task(self):
if self.state == EngineState.run:
return
self.state = EngineState.run
await self.network.connect()
for dev in self.devices:
self.send_alive(dev)
dev.update_alive()
self.state = EngineState.start
async def pull_task(self):
if self.state == EngineState.halt:
await self.boot()
self.state = EngineState.run
await self.wait_running()
while self.state == EngineState.run:
await self.process_rx_msg()
......@@ -134,28 +122,29 @@ class Engine(CoreEngine):
async def timer_task(self):
await self.wait_running()
while self.state == EngineState.run:
await asyncio.sleep(0.1)
await asyncio.sleep(0.2)
await self.process_timers()
self.process_attributesChange()
def start(self):
def start(self,loop=None):
if not loop:
loop = asyncio.get_event_loop()
loop.set_debug(True)
aiomonitor.start_monitor(loop=loop)
loop.create_task(self.boot_task(),name='Boot')
loop.create_task(self.pull_task(),name='Pull')
loop.create_task(self.push_task(),name='Push')
loop.create_task(self.timer_task(),name='Timers')
def stop(self):
self.state = EngineState.halt
self.network
def run(self):
def run(self,loop=None):
if self.state == EngineState.halt:
self.start()
self.start(loop)
loop = asyncio.get_event_loop()
loop.run_forever()
@decorator
async def spawn(func,*args,**kwargs):
def spawn(func,*args,**kwargs):
asyncio.get_event_loop().run_in_executor(None,func,*args,*kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment