Exemplo n.º 1
0
void Destroy_Connection(CONNECTION_ID_TYPE connection_id,
                        RETURN_CODE_TYPE& return_code)
{
    Entities& entities = *Entities::instance();
    std::map<CONNECTION_ID_TYPE, ::DDS::DataWriter_var>& writers = entities.writers_;
    std::map<CONNECTION_ID_TYPE, ::DDS::DataReader_var>& readers = entities.readers_;

    ::DDS::DomainParticipant_var dp;
    if (writers.count(connection_id)) {
        const ::DDS::Publisher_var pub = writers[connection_id]->get_publisher();
        writers.erase(connection_id);
        dp = pub->get_participant();

    } else if (readers.count(connection_id)) {
        const ::DDS::Subscriber_var sub = readers[connection_id]->get_subscriber();
        readers.erase(connection_id);
        dp = sub->get_participant();
    }

    if (!dp) {
        return_code = INVALID_PARAM;
        return;
    }

    dp->delete_contained_entities();
    const ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactory;
    dpf->delete_participant(dp);

    entities.connections_.erase(connection_id);
    return_code = RC_NO_ERROR;
}
Exemplo n.º 2
0
typename OpenDDS::DCPS::DDSTraits<MessageType>::DataWriterType::_var_type
create_writer(const DDS::Publisher_var& pub, const char* topicName,
  const DDS::DataWriterQos& qos = DATAWRITER_QOS_DEFAULT,
  const DDS::DataWriterListener_var& listener = 0,
  const DDS::StatusMask& mask = OpenDDS::DCPS::DEFAULT_STATUS_MASK)
{
  const DDS::TypeSupport_var ts = new ::OpenDDS::DCPS::TypeSupportImpl_T<MessageType>();
  const DDS::DomainParticipant_var dp = pub->get_participant();
  const CORBA::String_var typeName = ts->get_type_name();
  (void) ts->register_type(dp, typeName); // may have been registered before

  const DDS::Topic_var topic =
    dp->create_topic(topicName, typeName, TOPIC_QOS_DEFAULT, 0, 0);
  if (!topic) return 0;

  const DDS::DataWriter_var dw =
    pub->create_datawriter(topic, qos, listener, mask);
  return OpenDDS::DCPS::DDSTraits<MessageType>::DataWriterType::_narrow(dw);
}