User interface and server message handler
Created by: meguiraun
Extend the existing messaging system to the web. Flask-socketIO (websockets) can be used to send the pydispatcher’s signals to Javascript functions. It is also possible to define different namespaces over a single websocket. Flask-SocketIO transparently downgrades itself for older browsers that don’t have WebSocket, SocketIO emulates the connection using one of the older solutions, the best one available for each given client.
Two kind of signals:
- Signal from HO to HO (hidden for the user, so no action is required)
- Signals from HO to User interface
In any case, whenever a signal is intercepted for sending to the ui, it must fulfill a generic structure (to be defined), in order to ease the data retrieval in the web interface.
Code example:
from flask.ext.socketio import emit
#generic and unfiltered callback, it just will send all messages to the web interface
def signalCallback(signal, sender, *args):
socketio.emit('test',{'data':'A signal', 'signal': signal, \
'sender':str(sender.__class__).split('.')[0]}, \
namespace='/test')
#in the init code of the resolution hardware object (as example) we link the 'DeviceReady' message with the callback function
self.resolution.connect(self.resolution,'deviceReady', signalCallback)
We need to add self.someHO.connect(hw_obj, 'aSignal', 'aCallback')
for each message we want to propagate to the user interface. For that, we need the lists of messages for each hw_obj, such as the following:
MaxLabMicrodiff_signals = ['diffractometerMoved', 'minidiffReady', 'minidiffNotReady',
'phiMotorStateChanged' ......]
BL9113MultiCollect_signals = ['collectReady', 'collectImageTaken', 'collectReady',
'collectStarted', ....]
And add these lists to a config.py (or config/messages.py or whatever)