Ejemplo n.º 1
0
def on_signal(sig, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
        #        print('ON_SIGNAL (added or modified)', sig_props(sig))
        server.send_command("add_signals", [sig_props(sig)])
    elif action == mapper.REMOVED:
        #        print('ON_SIGNAL (removed)', sig_props(sig))
        server.send_command("del_signal", sig_props(sig))
Ejemplo n.º 2
0
def on_link(link, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
        #        print('ON_LINK (added or modified)', link_props(link))
        server.send_command("add_links", [link_props(link)])
    elif action == mapper.REMOVED:
        #        print('ON_LINK (removed)', link_props(link))
        server.send_command("del_link", link_props(link))
Ejemplo n.º 3
0
def on_map(map, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
        #        print('ON_MAP', '(added)' if action == mapper.ADDED else '(modified)', map_props(map))
        server.send_command("add_maps", [map_props(map)])
    elif action == mapper.REMOVED:
        #        print('ON_MAP (removed)', map_props(map))
        server.send_command("del_map", map_props(map))
Ejemplo n.º 4
0
def on_signal(sig, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
#        print 'ON_SIGNAL (added or modified)', sig_props(sig)
        server.send_command("add_signals", [sig_props(sig)])
    elif action == mapper.REMOVED:
#        print 'ON_SIGNAL (removed)', sig_props(sig)
        server.send_command("del_signal", sig_props(sig))
Ejemplo n.º 5
0
def on_link(link, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
#        print 'ON_LINK (added or modified)', link_props(link)
        server.send_command("add_links", [link_props(link)])
    elif action == mapper.REMOVED:
#        print 'ON_LINK (removed)', link_props(link)
        server.send_command("del_link", link_props(link))
Ejemplo n.º 6
0
def on_map(map, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
#        print 'ON_MAP (added or modified)', map_props(map)
        server.send_command("add_maps", [map_props(map)])
    elif action == mapper.REMOVED:
#        print 'ON_MAP (removed)', map_props(map)
        server.send_command("del_map", map_props(map))
Ejemplo n.º 7
0
def select_network(newNetwork):
    global db
    if networkInterfaces['active'] == newNetwork:
        return
    db.flush(0)
    networkInterfaces['active'] = newNetwork
    net = mapper.network(networkInterfaces['active'])
    db = mapper.database(net)
    server.send_command("active_network", newNetwork)
Ejemplo n.º 8
0
def on_device(dev, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
#        print 'ON_DEVICE (added or modified)', dev_props(dev)
        server.send_command("add_devices", [dev_props(dev)])
    elif action == mapper.REMOVED:
#        print 'ON_DEVICE (removed)', dev_props(dev)
        server.send_command("del_device", dev_props(dev))
    elif action == mapper.EXPIRED:
#        print 'ON_DEVICE (expired)', dev_props(dev)
        db.flush()
Ejemplo n.º 9
0
def on_device(dev, action):
    if action == mapper.ADDED or action == mapper.MODIFIED:
        #        print('ON_DEVICE (added or modified)', dev_props(dev))
        server.send_command("add_devices", [dev_props(dev)])
    elif action == mapper.REMOVED:
        #        print('ON_DEVICE (removed)', dev_props(dev))
        server.send_command("del_device", dev_props(dev))
    elif action == mapper.EXPIRED:
        #        print('ON_DEVICE (expired)', dev_props(dev))
        db.flush()
Ejemplo n.º 10
0
def get_networks(arg):
    location = netifaces.AF_INET    # A computer specific integer for internet addresses
    totalInterfaces = netifaces.interfaces() # A list of all possible interfaces
    connectedInterfaces = []
    for i in totalInterfaces:
        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'])
Ejemplo n.º 11
0
def get_networks(arg):
    location = netifaces.AF_INET    # A computer specific integer for internet addresses
    totalInterfaces = netifaces.interfaces() # A list of all possible interfaces
    connectedInterfaces = []
    for i in totalInterfaces:
        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'])
Ejemplo n.º 12
0
def on_connection(con, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_connection", con)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_connection", con)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_connection", con)
Ejemplo n.º 13
0
def on_device(dev, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_device", dev)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_device", dev)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_device", dev)
Ejemplo n.º 14
0
def on_signal(sig, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_signal", sig)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_signal", sig)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_signal", sig)
Ejemplo n.º 15
0
def on_link(link, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_link", link)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_link", link)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_link", link)
Ejemplo n.º 16
0
def on_link(link, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_link", link)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_link", link)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_link", link)
Ejemplo n.º 17
0
def on_device(dev, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_device", dev)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_device", dev)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_device", dev)
Ejemplo n.º 18
0
def on_signal(sig, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_signal", sig)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_signal", sig)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_signal", sig)
Ejemplo n.º 19
0
def on_connection(con, action):
    if action == mapper.MDB_NEW:
        server.send_command("new_connection", con)
    if action == mapper.MDB_MODIFY:
        server.send_command("mod_connection", con)
    if action == mapper.MDB_REMOVE:
        server.send_command("del_connection", con)
Ejemplo n.º 20
0
def init_database(arg):
    global db
    global initialized
    if initialized == False:
        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)
        initialized = True
    else:
        server.send_command("add_devices", map(dev_props, db.devices()))
        server.send_command("add_links", map(link_props, db.links()))
        server.send_command("add_signals", map(sig_props, db.signals()))
        server.send_command("add_maps", map(map_props, db.maps()))
Ejemplo n.º 21
0
def init_database(arg):
    global db
    global initialized
    if initialized == False:
        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)
        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()])
Ejemplo n.º 22
0
def init_graph(arg):
    print('REFRESH!')
    global g

    # remove old callbacks (if they are registered)
    g.remove_callback(on_device)
    g.remove_callback(on_signal)
    g.remove_callback(on_map)

    # register callbacks
    g.add_callback(on_device, mpr.Type.DEVICE)
    g.add_callback(on_signal, mpr.Type.SIGNAL)
    g.add_callback(on_map, mpr.Type.MAP)

    # (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)])
Ejemplo n.º 23
0
def select_network(newNetwork):
    # print 'select_network', newNetwork
    networkInterfaces['active'] = newNetwork
    server.send_command('set_network', newNetwork)
Ejemplo n.º 24
0
def get_active_network(arg):
    print networkInterfaces['active']
    server.send_command("active_network", networkInterfaces['active'])
Ejemplo n.º 25
0
def select_interface(iface):
    print('switching interface to', iface)
    global g
    g.set_interface(iface)
    networkInterfaces['active'] = iface
    server.send_command("active_interface", iface)
Ejemplo n.º 26
0
def poll_and_push():
    global g
    g.poll(50)
    if len(new_devs) > 0:
        server.send_command("add_devices", list(new_devs.values()))
        new_devs.clear()
    if len(del_devs) > 0:
        server.send_command("del_devices", list(del_devs.values()))
        del_devs.clear()
    if len(new_sigs) > 0:
        server.send_command("add_signals", list(new_sigs.values()))
        new_sigs.clear()
    if len(del_sigs) > 0:
        server.send_command("del_signals", list(del_sigs.values()))
        del_sigs.clear()
    if len(new_maps) > 0:
        server.send_command("add_maps", list(new_maps.values()))
        new_maps.clear()
    if len(del_maps) > 0:
        server.send_command("del_maps", list(del_maps.values()))
        del_maps.clear()
Ejemplo n.º 27
0
def select_network(newNetwork):
    # print 'select_network', newNetwork
    networkInterfaces['active'] = newNetwork
    server.send_command('set_network', newNetwork)
Ejemplo n.º 28
0
def get_active_network(arg):
    print networkInterfaces['active']
    server.send_command("active_network", networkInterfaces['active'])