def on_discover_participant(match, state):
    """It happens for discovered participants."""
    local_address = parse_guid(state, match[0], match[1])
    full_addr = parse_guid(state, match[0], match[1], match[2])
    full_addr = " ".join(full_addr.split())
    log_process(local_address, "",
                "Discovered new participant (%s)" % full_addr, state)
def on_update_remote_participant(match, state):
    """It happens when updating remote participant."""
    local_address = parse_guid(state, match[0], match[1])
    full_addr = parse_guid(state, match[0], match[1], match[2])
    full_addr = " ".join(full_addr.split())
    part_oid = get_oid(match[3])
    log_process(
        local_address, "",
        "Discovered/Updated participant (%s - %s)" % (full_addr, part_oid),
        state, 1)
 def match_entity(match, state):
     """It happens when a specific entity is matched."""
     entity2_addr = parse_guid(state, match[0], match[1], match[2])
     entity2_oid = get_oid(match[3])
     entity1_oid = get_oid(match[4])
     verb = 1 if is_builtin_entity(match[4]) else 0
     reliable = match[5]  # Best-Effort or Reliable
     log_process(
         entity2_addr, entity1_oid,
         "Discovered %s %s %s %s" % (kind, reliable, entity2, entity2_oid),
         state, verb)
def on_schedule_data(match, state):
    """It happens when a data is asynchronously scheduled."""
    writer_oid = get_oid(match[0])
    seqnum = parse_sn(match[1])
    log_process("", writer_oid, "Scheduled DATA (%d)" % seqnum, state)

    if 'packets_lost' not in state:
        state['packets_lost'] = []
    key = writer_oid + "-" + str(seqnum)
    if key in state['packets_lost']:
        state['packets_lost'].remove(key)
    else:
        state['packets_lost'].append(key)
def on_rejected_data(match, state):
    """It happens when the reader rejects data."""
    seqnum = parse_sn(match[0])
    log_process("", "", "Reader rejected DATA (%d)" % seqnum, state)
    log_warning("A DataReader rejected sample %d" % seqnum, state)
def on_accept_data(match, state):
    """It happens when the reader accepts data."""
    seqnum = parse_sn(match[0])
    log_process("", "", "Reader accepted DATA (%d)" % seqnum, state, 1)
def on_typeobject_received(match, state):
    """It happens for discovered entities when comparing TypeObjects."""
    log_process("", "", "TypeObject %s" % match[0], state, 2)
def on_participant_ignore_itself(match, state):
    """It happens when ignoring itself."""
    log_process("", "", "Participant is ignoring itself", state)
def on_announce_local_subscription(match, state):
    """It happens when announcing a reader."""
    local_addr = parse_guid(state, match[0], match[1], match[2])
    sub_oid = get_oid(match[3])
    log_process(local_addr, "", "Announcing new reader %s" % sub_oid, state)
def on_announce_local_publication(match, state):
    """It happens when announcing a writer."""
    local_addr = parse_guid(state, match[0], match[1], match[2])
    pub_oid = get_oid(match[3])
    log_process(local_addr, "", "Announcing new writer %s" % pub_oid, state)
def on_update_endpoint(match, state):
    """It happens when updating an endpoint."""
    remote_addr = parse_guid(state, match[0], match[1], match[2])
    pub_oid = get_oid(match[3])
    log_process(remote_addr, "", "Discovered/Updated publication %s" % pub_oid,
                state, 1)
def on_discover_publication(match, state):
    """It happens for discovered writers."""
    remote_addr = parse_guid(state, match[0], match[1], match[2])
    pub_oid = get_oid(match[3])
    log_process(remote_addr, "", "Discovered new publication %s" % pub_oid,
                state)