void dcps_delete_builtin_readers (DDS_DomainParticipant dp) { const BuiltinReaderDesc_t *bip; Topic_t *tp; unsigned i; /* Delete builtin topic readers. */ for (i = 0, bip = bi_readers; i < sizeof (bi_readers) / sizeof (BuiltinReaderDesc_t); i++, bip++) if ((tp = topic_lookup (&dp->participant, bip->topic_name)) != NULL) delete_builtin_reader (dp, bip->type, tp); }
DDS_TopicDescription DDS_DomainParticipant_lookup_topicdescription (DDS_DomainParticipant dp, const char *topic_name) { Topic_t *tp; DDS_TopicDescription td; ctrc_begind (DCPS_ID, DCPS_DP_L_TD, &dp, sizeof (dp)); ctrc_contd (topic_name, strlen (topic_name)); ctrc_endd (); /* Get Domain Participant. */ if (!domain_ptr (dp, 1, NULL)) { log_printf (DCPS_ID, 0, "find_topic(): domain participant not found!\r\n"); return (NULL); } if (!topic_name) { log_printf (DCPS_ID, 0, "find_topic(): topic_name is NULL!\r\n"); return (NULL); } tp = topic_lookup (&dp->participant, topic_name); td = (tp != NULL) && (tp->entity.flags & EF_LOCAL) != 0 ? (DDS_TopicDescription) tp : NULL; lock_release (dp->lock); return (td); }
DDS_Topic DDS_DomainParticipant_find_topic (DDS_DomainParticipant dp, const char *topic_name, DDS_Duration_t *timeout) { Topic_t *tp; #ifdef THREADS_USED int ret; struct timespec ts; TopicWait_t *wp, *xp, *prev_wp; #else Ticks_t d, now, end_time; /* *10ms */ #endif ctrc_begind (DCPS_ID, DCPS_DP_F_TOP, &dp, sizeof (dp)); ctrc_contd (topic_name, strlen (topic_name) + 1); ctrc_contd (timeout, sizeof (DDS_Duration_t)); ctrc_endd (); /* Get Domain Participant. */ if (!domain_ptr (dp, 1, NULL)) { log_printf (DCPS_ID, 0, "find_topic(): domain participant not found!\r\n"); return (NULL); } tp = topic_lookup (&dp->participant, topic_name); if (tp) { if (!lock_take (tp->lock)) { tp->entity.flags |= EF_LOCAL; tp->nlrefs++; lock_release (tp->lock); } lock_release (dp->lock); return ((DDS_Topic) tp); } #ifdef THREADS_USED for (wp = dp->topic_wait; wp; wp = wp->next) if (!strcmp (topic_name, wp->name)) break; if (wp) wp->nthreads++; else { wp = mds_pool_alloc (&dcps_mem_blocks [MB_TOPIC_WAIT]); if (!wp) { lock_release (dp->lock); return (NULL); } wp->next = dp->topic_wait; cond_init (wp->condition); wp->name = topic_name; wp->topic = NULL; wp->nthreads = 1; dp->topic_wait = wp; } duration2timespec (timeout, &ts); do { if (ts.tv_sec || ts.tv_nsec) ret = cond_wait_to (wp->condition, dp->lock, ts); else ret = cond_wait (wp->condition, dp->lock); } while (!wp->topic && !ret); tp = wp->topic; if (!--wp->nthreads) { for (xp = dp->topic_wait, prev_wp = NULL; xp != NULL && xp != wp; prev_wp = xp, xp = xp->next) ; if (prev_wp) prev_wp->next = wp->next; else dp->topic_wait = wp->next; cond_destroy (wp->condition); mds_pool_free (&dcps_mem_blocks [MB_TOPIC_WAIT], wp); } lock_release (dp->lock); #else if (dds_listener_state) { lock_release (dp->lock); return (NULL); } /* Wait until timeout elapsed for discovery to add the topic. */ now = sys_getticks (); if (timeout->sec == DDS_DURATION_INFINITE_SEC || timeout->nanosec == DDS_DURATION_INFINITE_NSEC) end_time = now + 0x7ffffffe; else end_time = now + duration2ticks ((Duration_t *) timeout); for (;;) { d = end_time - now; if (d >= 0x7fffffffUL) break; DDS_schedule (d * TMR_UNIT_MS); tp = topic_lookup (&dp->participant, topic_name); if (tp) { tp->entity.flags |= EF_LOCAL; tp->nlrefs++; break; } now = sys_getticks (); } #endif return (tp); }
void sedp_topic_event (Reader_t *rp, NotificationType_t t) { Domain_t *dp = rp->r_subscriber->domain; Participant_t *pp; ChangeData_t change; DiscoveredTopicData *info = NULL, tinfo; Topic_t *tp; InfoType_t type; int error, new_node, valid_data = 0; const char *names [2]; if (t != NT_DATA_AVAILABLE) return; rp->r_status &= ~DDS_DATA_AVAILABLE_STATUS; for (;;) { if (info) { pid_topic_data_cleanup (&info); xfree (info); info = NULL; } /*dtrc_print0 ("SEDP-Topic: get samples ");*/ error = disc_get_data (rp, &change); if (error) { /*dtrc_print0 ("- none\r\n");*/ break; } /*dtrc_print1 ("- valid(%u)\r\n", change.kind);*/ if (change.kind != ALIVE) { /* error = hc_get_key (rp->r_cache, change.h, &tinfo, 0); if (error) continue; */ type = EI_DELETE; hc_inst_free (rp->r_cache, change.h); } else { type = EI_NEW; info = change.data; } pp = entity_participant (change.writer); if (!pp || /* Not found. */ pp == &dp->participant || /* Own sent info. */ entity_ignored (pp->p_flags)) { /* Ignored. */ hc_inst_free (rp->r_cache, change.h); continue; /* Filter out unneeded info. */ } /* Topic from remote participant. */ if (type == EI_DELETE) { /* TBD: Certified not to work correctly. */ tp = topic_lookup (pp, str_ptr (info.name)); if (!tp) { hc_inst_free (rp->r_cache, change.h); continue; /* If doesn't exist - no action. */ } names [0] = str_ptr (tp->name); names [1] = str_ptr (tp->type->type_name); } else { tp = topic_create (pp, NULL, names [0], names [1], &new_node); if (!tp) { hc_inst_free (rp->r_cache, change.h); continue; /* Can't create info -- just ignore. */ } if (!new_node) { if (entity_ignored (tp->entity.flags)) { hc_inst_free (rp->r_cache, change.h); continue; } type = EI_UPDATE; } names [0] = str_ptr (info->name); names [1] = str_ptr (info->type_name); } if (sedp_log) log_printf (SEDP_ID, 0, "SEDP: %s topic (%s/%s) from peer!\r\n", info_type_str [type], names [0], names [1]); sedp_topic_info (pp, tp, info, type); } if (info) { pid_topic_data_cleanup (info); xfree (info); } }
void sedp_publication_event (Reader_t *rp, NotificationType_t t, int cdd, int secure) { Domain_t *dp = rp->r_subscriber->domain; Participant_t *pp; ChangeData_t change; DiscoveredWriterData *info = NULL, tinfo; Topic_t *tp; DiscoveredWriter_t *dwp; Reader_t *mrp; UniQos_t qos; InfoType_t type; GUID_t *guidp; int error; if (t != NT_DATA_AVAILABLE) return; rp->r_status &= ~DDS_DATA_AVAILABLE_STATUS; for (;;) { if (info) { pid_writer_data_cleanup (info); xfree (info); info = NULL; } /*dtrc_print0 ("SEDP-Pub: get samples ");*/ error = disc_get_data (rp, &change); if (error) { /*dtrc_print0 ("- none\r\n");*/ break; } /*dtrc_print1 ("- valid(%u)\r\n", change.kind);*/ if (change.kind != ALIVE) { error = hc_get_key (rp->r_cache, change.h, &tinfo, 0); if (error) continue; guidp = &tinfo.proxy.guid; type = EI_DELETE; hc_inst_free (rp->r_cache, change.h); } else { info = change.data; if (!info->topic_name || !info->type_name) { hc_inst_free (rp->r_cache, change.h); continue; } type = EI_NEW; guidp = &info->proxy.guid; } pp = entity_participant (change.writer); if (!pp || /* Not found. */ pp == &dp->participant || /* Own sent info. */ entity_ignored (pp->p_flags)) { /* Ignored. */ if (pp != &dp->participant && !cdd) warn_printf ("sedp_publication_rx: invalid change.writer field!\r\n"); hc_inst_free (rp->r_cache, change.h); dtrc_print0 ("SEDP-Pub: unneeded!\r\n"); continue; /* Filter out unneeded info. */ } /* Publication from remote participant. */ if (type == EI_DELETE) { dwp = (DiscoveredWriter_t *) endpoint_lookup (pp, &guidp->entity_id); if (!dwp) { dtrc_print0 ("SEDP-Pub: DELETE && doesn't exist!\r\n"); continue; /* If doesn't exist - no action. */ } if (!dwp->dw_topic) { endpoint_delete (pp, &dwp->dw_ep); continue; /* Ignored topic -- only endpoint. */ } if (sedp_log) log_printf (SEDP_ID, 0, "SEDP: Deleted %spublication (%s/%s) from peer!\r\n", (secure) ? "secure " : "", str_ptr (dwp->dw_topic->name), str_ptr (dwp->dw_topic->type->type_name)); disc_publication_remove (pp, dwp); hc_inst_free (rp->r_cache, change.h); continue; } /* Do we know this topic? */ tp = topic_lookup (&dp->participant, str_ptr (info->topic_name)); if (tp && entity_ignored (tp->entity.flags)) { hc_inst_free (rp->r_cache, change.h); dtrc_print1 ("SEDP: ignored topic (%s)!\r\n", str_ptr (info->topic_name)); continue; /* Ignored topic. */ } /* Do we know this endpoint already? */ dwp = (DiscoveredWriter_t *) endpoint_lookup (pp, &guidp->entity_id); if (dwp) { if (entity_ignored (dwp->dw_flags) || cdd) { hc_inst_free (rp->r_cache, change.h); continue; /* Ignored endpoint. */ } dtrc_print1 ("Already exists (%s)!\r\n", str_ptr (info->topic_name)); type = EI_UPDATE; disc_publication_update (pp, dwp, info); if (sedp_log) log_printf (SEDP_ID, 0, "SEDP: Updated %spublication (%s/%s) from peer!\r\n", (secure) ? "secure " : "", str_ptr (info->topic_name), str_ptr (info->type_name)); hc_inst_free (rp->r_cache, change.h); } else { /* Get QoS parameters. */ qos_disc_writer_set (&qos, &info->qos); mrp = NULL; /* Create new endpoint. */ dwp = (DiscoveredWriter_t *) endpoint_create (pp, pp, &guidp->entity_id, NULL); if (!dwp) { dtrc_print1 ("SEDP: Create endpoint (%s) not possible - exit!\r\n", str_ptr (info->topic_name)); hc_inst_free (rp->r_cache, change.h); qos_disc_writer_restore (&info->qos, &qos); continue; /* Can't create -- just ignore. */ } disc_publication_add (pp, dwp, &qos, tp, mrp, info); hc_inst_free (rp->r_cache, change.h); if (sedp_log) log_printf (SEDP_ID, 0, "SEDP: New %spublication (%s/%s) from %s!\r\n", (secure) ? "secure " : "", str_ptr (info->topic_name), str_ptr (info->type_name), (cdd) ? "CDD" : "peer"); } } if (info) { pid_writer_data_cleanup (info); xfree (info); } }