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

Added filter func

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1658 b32b6428-25c9-4566-ad07-03861ab6144f
parent 7b63e725
No related branches found
No related tags found
No related merge requests found
......@@ -124,16 +124,26 @@ class Monitor:
class xAAL Monitor:
use this class to monitor a xAAL network
"""
def __init__(self,device):
def __init__(self,device,filter_func=None):
self.dev = device
self.eng = device.engine
self.eng.handle_rx_msg = self.msg_dispatch
self.devices = Devices()
self.filter = filter_func
self.eng.add_timer(self.auto_wash, 10)
self.eng.add_timer(self.send_isalive, 180)
self.eng.add_timer(self.refresh_devices, 5)
def msg_dispatch(self,msg):
if (self.filter==None) or self.filter(msg):
self._msg_dispatch(msg)
# let's engine do the jobs for use
self.eng.handle_request(msg)
def _msg_dispatch(self, msg):
if msg.source not in self.devices:
self.add_device(msg)
#self.refresh_devices()
......@@ -152,8 +162,6 @@ class Monitor:
elif msg.is_get_description_reply():
dev.update_description(msg.body)
# let's engine do the jobs for use
self.eng.handle_request(msg)
def add_device(self,msg):
self.devices.add(msg.source,msg.devtype,msg.version)
......@@ -162,6 +170,7 @@ class Monitor:
self.eng.send_isAlive(self.dev, "any.any")
def auto_wash(self):
"""call the Auto-wash on devices List"""
self.devices.auto_wash()
def refresh_devices(self):
......
......@@ -5,7 +5,7 @@ from xaal.lib import tools,Engine,Device
from xaal.monitor import Monitor
import platform
from bottle import default_app,debug,get,response,redirect
from bottle import default_app,debug,get,response,redirect,static_file
import json
......@@ -14,12 +14,23 @@ from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
# dev-type that don't appear in results
BLACK_LIST=['cli.experimental',]
PACKAGE_NAME = "xaal.rest"
logger = tools.get_logger(PACKAGE_NAME,'DEBUG')
# we use this global variable to share data with greenlet
monitor = None
def monitor_filter(msg):
""" Filter incomming messages. Return False if you don't want to use this device"""
if msg.devtype in BLACK_LIST:
return False
return True
def setup_xaal():
""" setup xAAL Engine & Device. And start it in a Greenlet"""
global monitor
......@@ -34,7 +45,7 @@ def setup_xaal():
dev.info = "%s@%s" % (PACKAGE_NAME,platform.node())
engine.add_device(dev)
monitor = Monitor(dev)
monitor = Monitor(dev,filter_func=monitor_filter)
engine.start()
green_let = Greenlet(xaal_loop, engine)
green_let.start()
......@@ -44,6 +55,11 @@ def xaal_loop(engine):
while 1:
engine.loop()
@get('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root='./static/')
@get('/')
def goto_list():
redirect('/devices/')
......@@ -77,6 +93,7 @@ def get_device(addr):
def run():
""" start the xAAL stack & launch the HTTP stuff"""
setup_xaal()
app = default_app()
debug(True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment