def set_connection(con): if con.has_key('mode'): con['mode'] = {'bypass': mapper.MO_BYPASS, 'linear': mapper.MO_LINEAR, 'calibrate': mapper.MO_CALIBRATE, 'expression': mapper.MO_EXPRESSION}[con['mode']] monitor.modify(con) monitor.db.add_device_callback(on_device) monitor.db.add_signal_callback(on_signal) monitor.db.add_link_callback(on_link) monitor.db.add_mapping_callback(on_connection) server.add_command_handler("all_devices", lambda x: ("all_devices", list(monitor.db.all_devices()))) server.add_command_handler("all_signals", lambda x: ("all_signals", list(monitor.db.all_inputs()) + list(monitor.db.all_outputs()))) server.add_command_handler("all_links", lambda x: ("all_links", list(monitor.db.all_links()))) server.add_command_handler("all_connections", lambda x: ("all_connections", list(monitor.db.all_mappings())))
if con.has_key("mode"): con["mode"] = { "bypass": mapper.MO_BYPASS, "linear": mapper.MO_LINEAR, "calibrate": mapper.MO_CALIBRATE, "expression": mapper.MO_EXPRESSION, }[con["mode"]] monitor.modify(con) monitor.db.add_device_callback(on_device) monitor.db.add_signal_callback(on_signal) monitor.db.add_link_callback(on_link) monitor.db.add_mapping_callback(on_connection) server.add_command_handler("all_devices", lambda x: ("all_devices", list(monitor.db.all_devices()))) server.add_command_handler( "all_signals", lambda x: ("all_signals", list(monitor.db.all_inputs()) + list(monitor.db.all_outputs())) ) server.add_command_handler("all_links", lambda x: ("all_links", list(monitor.db.all_links()))) server.add_command_handler("all_connections", lambda x: ("all_connections", list(monitor.db.all_mappings()))) server.add_command_handler("set_connection", set_connection) server.add_command_handler("link", lambda x: monitor.link(*map(str, x))) server.add_command_handler("unlink", lambda x: monitor.unlink(*map(str, x)))
def on_load(mapping_json): mapperstorage.deserialise(monitor, mapping_json) def init_monitor(): monitor.request_devices() monitor.db.add_device_callback(on_device) monitor.db.add_signal_callback(on_signal) monitor.db.add_link_callback(on_link) monitor.db.add_connection_callback(on_connection) init_monitor() server.add_command_handler( "all_devices", lambda x: ("all_devices", list(monitor.db.all_devices()))) server.add_command_handler( "all_signals", lambda x: ("all_signals", list(monitor.db.all_inputs()) + list(monitor.db.all_outputs()))) server.add_command_handler( "all_links", lambda x: ("all_links", list(monitor.db.all_links()))) server.add_command_handler( "all_connections", lambda x: ("all_connections", list(monitor.db.all_connections()))) server.add_command_handler("set_connection", set_connection) server.add_command_handler("link", lambda x: monitor.link(*map(str, x)))
addrs = netifaces.ifaddresses(i) if location in addrs: # Test to see if the interface is actually connected connectedInterfaces.append(i) server.send_command("available_networks", connectedInterfaces) networkInterfaces['available'] = connectedInterfaces server.send_command("active_network", networkInterfaces['active']) def init_database(arg): global db db.subscribe(mapper.OBJ_DEVICES | mapper.OBJ_LINKS) db.add_device_callback(on_device) db.add_link_callback(on_link) db.add_signal_callback(on_signal) db.add_map_callback(on_map) server.add_command_handler("add_devices", lambda x: ("add_devices", map(dev_props, db.devices()))) def subscribe(device): if device == "all_devices": db.subscribe(mapper.OBJ_DEVICES | mapper.OBJ_LINKS) else: # todo: only subscribe to inputs and outputs as needed dev = db.device(device) if dev: db.subscribe(dev, mapper.OBJ_ALL) def new_map(args): srckeys, dstkey, props = args srcs = [find_sig(k) for k in srckeys] dst = find_sig(dstkey) if not (all(srcs) and dst):
print networkInterfaces['active'] server.send_command("active_network", networkInterfaces['active']) def init_monitor(): monitor.db.add_device_callback(on_device) monitor.db.add_signal_callback(on_signal) monitor.db.add_link_callback(on_link) monitor.db.add_connection_callback(on_connection) monitor.request_devices() monitor.request_links_by_src_device_name("/*") init_monitor() server.add_command_handler("all_devices", lambda x: ("all_devices", list(monitor.db.all_devices()))) def sync_device(name, is_src): device = monitor.db.get_device_by_name(name) if not device: return sigs_reported = 0 sigs_recorded = 0 if is_src: sigs_reported = device["n_outputs"] sigs_recorded = sum(1 for _ in monitor.db.outputs_by_device_name(name)) else: sigs_reported = device["n_inputs"] sigs_recorded = sum(1 for _ in monitor.db.inputs_by_device_name(name)) if sigs_reported != sigs_recorded:
return fn, mapperstorage.serialise(monitor, arg['dev']) def on_load(mapping_json): mapperstorage.deserialise(monitor, mapping_json) def init_monitor(): monitor.request_devices() monitor.db.add_device_callback(on_device) monitor.db.add_signal_callback(on_signal) monitor.db.add_link_callback(on_link) monitor.db.add_connection_callback(on_connection) init_monitor() server.add_command_handler("all_devices", lambda x: ("all_devices", list(monitor.db.all_devices()))) server.add_command_handler("all_signals", lambda x: ("all_signals", list(monitor.db.all_inputs()) + list(monitor.db.all_outputs()))) server.add_command_handler("all_links", lambda x: ("all_links", list(monitor.db.all_links()))) server.add_command_handler("all_connections", lambda x: ("all_connections", list(monitor.db.all_connections())))
db.add_device_callback(on_device) db.add_link_callback(on_link) db.add_signal_callback(on_signal) db.add_map_callback(on_map) initialized = True else: server.send_command("add_devices", [dev_props(d) for d in db.devices()]) server.send_command("add_links", [link_props(l) for l in db.links()]) server.send_command("add_signals", [sig_props(s) for s in db.signals()]) server.send_command("add_maps", [map_props(m) for m in db.maps()]) server.add_command_handler( "add_devices", lambda x: ("add_devices", [dev_props(d) for d in db.devices()])) def subscribe(name): if name == "all_devices": db.subscribe(mapper.OBJ_DEVICES | mapper.OBJ_LINKS) else: # todo: only subscribe to inputs and outputs as needed dev = db.device(name) if dev: db.subscribe(dev, mapper.OBJ_ALL) def new_map(args): srckeys, dstkey, props = args
# (re)subscribe: currently this does nothing but could refresh graph database? g.subscribe(None, mpr.Type.OBJECT, -1) for d in g.devices(): server.send_command("add_devices", [dev_props(d)]) for s in g.signals(): server.send_command("add_signals", [sig_props(s)]) for m in g.maps(): server.send_command("add_maps", [map_props(m)]) init_graph(0) server.add_command_handler( "add_devices", lambda x: ("add_devices", [dev_props(d) for d in g.devices()])) def subscribe(device): if device == 'all_devices': g.subscribe(None, mpr.Type.DEVICE, -1) else: # todo: only subscribe to inputs and outputs as needed dev = g.devices().filter(mpr.Property.NAME, device) if dev: g.subscribe(dev.next(), mpr.Type.OBJECT, -1) else: print("no device matching name", device)