예제 #1
0
def subscriber(topic, connect_port):
    node = dps.create_node("/", key_store, None)
    dps.start_node(node, 0, 0)
    print "Subscriber is listening on port %d" % dps.get_port_number(node)
    sub = dps.create_subscription(node, [topic])
    dps.subscribe(sub, on_pub)
    if (connect_port != 0):
        addr = dps.create_address()
        ret = dps.link_to(node, None, connect_port, addr)
        if (ret == dps.OK):
            print "Linked %d to %d" % (dps.get_port_number(node), connect_port)
        dps.destroy_address(addr)
    return node
예제 #2
0
def on_pub(sub, pub, payload):
    print "Received on port %d" % dps.get_port_number(
        dps.subscription_get_node(sub))
    print "Pub %s(%d) matches:" % (dps.publication_get_uuid(pub),
                                   dps.publication_get_sequence_num(pub))
    print "  pub " + " | ".join(dps.publication_get_topics(pub))
    print "  sub " + " | ".join(dps.subscription_get_topics(sub))
    print payload
예제 #3
0
def on_pub(sub, pub, payload):
    print "Pub %s(%d) matches:" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))
    print "  pub " + " | ".join(dps.publication_get_topics(pub))
    print "  sub " + " | ".join(dps.subscription_get_topics(sub))
    print payload
    if dps.publication_is_ack_requested(pub):
        ack_msg = "This is an ACK from %d" % (dps.get_port_number(dps.publication_get_node(pub)))
        print "Sending ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))
        print "    %s" % (ack_msg)
        dps.ack_publication(pub, ack_msg);
예제 #4
0

def on_ack(pub, payload):
    print "Ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub),
                                       dps.publication_get_sequence_num(pub))
    print "    %s" % (payload)


def on_destroy(node):
    print "Destroyed"
    dps.destroy_key_store(key_store)


node = dps.create_node("/", key_store, node_id)
dps.start_node(node, dps.MCAST_PUB_ENABLE_SEND, 0)
print "Publisher is listening on port %d" % (dps.get_port_number(node))
pub = dps.create_publication(node)

dps.init_publication(pub, ['a/b/c'], False, None, on_ack)
dps.publication_add_sub_id(pub, pub_key_id)
dps.publish(pub, "hello")
print "Pub UUID %s(%d)" % (dps.publication_get_uuid(pub),
                           dps.publication_get_sequence_num(pub))
time.sleep(1)
dps.publish(pub, "world")
print "Pub UUID %s(%d)" % (dps.publication_get_uuid(pub),
                           dps.publication_get_sequence_num(pub))
time.sleep(1)

dps.destroy_publication(pub)
dps.destroy_node(node, on_destroy)
예제 #5
0
if args.encryption == 0:
    key_store = dps.create_key_store(on_key_and_id, on_key, on_ephemeral_key, None)
    node_id = None
elif args.encryption == 1:
    key_store = dps.create_key_store(on_key_and_id, on_key, on_ephemeral_key, None)
    node_id = None
elif args.encryption == 2:
    key_store = dps.create_key_store(on_key_and_id, on_key, on_ephemeral_key, on_ca)
    node_id = subscriber_id

def on_pub(sub, pub, payload):
    print "Pub %s(%d) matches:" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))
    print "  pub " + " | ".join(dps.publication_get_topics(pub))
    print "  sub " + " | ".join(dps.subscription_get_topics(sub))
    print payload
    if dps.publication_is_ack_requested(pub):
        ack_msg = "This is an ACK from %d" % (dps.get_port_number(dps.publication_get_node(pub)))
        print "Sending ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))
        print "    %s" % (ack_msg)
        dps.ack_publication(pub, ack_msg);

node = dps.create_node("/", key_store, node_id)
dps.start_node(node, dps.MCAST_PUB_ENABLE_RECV, 0)
print "Subscriber is listening on port %d" % (dps.get_port_number(node))
sub = dps.create_subscription(node, ['a/b/c']);
dps.subscribe(sub, on_pub)

if not sys.flags.interactive:
    while True:
        time.sleep(1)
예제 #6
0
        addr = dps.create_address()
        ret = dps.link_to(node, None, connect_port, addr)
        if (ret == dps.OK):
            print "Linked %d to %d" % (dps.get_port_number(node), connect_port)
        dps.destroy_address(addr)
    return node

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", action='store_true',
                    help="Enable debug ouput if built for debug.")
args = parser.parse_args()
dps.cvar.debug = args.debug

sub1 = subscriber('B/B', 0)
sub2 = subscriber('A/A', dps.get_port_number(sub1))
sub3 = subscriber('C/C', dps.get_port_number(sub1))

sub4 = subscriber('a/b/c', dps.get_port_number(sub2))
sub5 = subscriber('d/e/f', dps.get_port_number(sub2))
sub6 = subscriber('g/h/i', dps.get_port_number(sub2))

sub7 = subscriber('1/2/3', dps.get_port_number(sub3))
sub8 = subscriber('4/5/6', dps.get_port_number(sub3))
sub9 = subscriber('7/8/9', dps.get_port_number(sub3))

time.sleep(15)
sub10 = subscriber('+/#', dps.get_port_number(sub7))

time.sleep(15)
sub11 = subscriber('+/#', dps.get_port_number(sub1))