Beispiel #1
0
Topic<T, DELEGATE>::Topic(const dds::domain::DomainParticipant& dp,
                          const std::string& topic_name) :
      ::dds::core::Reference< DELEGATE<T> >(new DELEGATE<T>(
              dp,
              topic_name,
              "",
              dp.is_nil() ? dds::topic::qos::TopicQos() : dp.default_topic_qos(),
              NULL,
              dds::core::status::StatusMask::none()))
{
    ISOCPP_REPORT_STACK_DDS_BEGIN(dp);

    this->delegate()->init(this->impl_);
}
Beispiel #2
0
dds::topic::Topic<T, dds::topic::detail::Topic>
dds::topic::detail::Topic<T>::discover_topic(
        const dds::domain::DomainParticipant& dp,
        const std::string& name,
        const dds::core::Duration& timeout)
{
    u_topic uTopic = dp.delegate()->lookup_topic(name, timeout);

    if (uTopic == NULL) {
        return dds::core::null;
    }

    os_char *uTypename = u_topicTypeName(uTopic);
    std::string type_name = uTypename;
    os_free(uTypename);

    u_topicQos uQos;
    u_result uResult = u_topicGetQos(uTopic, &uQos);
    ISOCPP_U_RESULT_CHECK_AND_THROW(uResult, "Failed to get user layer topic qos");

    qos::TopicQos qos;
    qos.delegate().u_qos(uQos);
    u_topicQosFree(uQos);

    typename dds::topic::Topic<T, dds::topic::detail::Topic>::DELEGATE_REF_T ref(new Topic<T>(dp, name, type_name, qos, uTopic));
    ref->init(ref);

    return dds::topic::Topic<T>(ref);
}
Beispiel #3
0
void
dds::topic::detail::Topic<T>::discover_topics(
        const dds::domain::DomainParticipant& dp,
        std::vector<dds::topic::Topic<T, dds::topic::detail::Topic> >& topics,
        uint32_t max_size)
{
    std::vector<u_topic> uTopics;

    dp.delegate()->lookup_topics(topic_type_name<T>::value(), uTopics, max_size);

    topics.clear();
    topics.reserve(uTopics.size());

    for (std::vector<u_topic>::const_iterator it = uTopics.begin(); it != uTopics.end(); ++it) {
        u_topic uTopic = *it;
        os_char *topic_name = u_topicName(uTopic);
        os_char *type_name = u_topicTypeName(uTopic);

        u_topicQos uQos;
        u_result uResult = u_topicGetQos(uTopic, &uQos);
        ISOCPP_U_RESULT_CHECK_AND_THROW(uResult, "Failed to get user layer topic qos");

        dds::topic::qos::TopicQos qos;
        qos.delegate().u_qos(uQos);
        u_topicQosFree(uQos);

        typename dds::topic::Topic<T, dds::topic::detail::Topic>::DELEGATE_REF_T ref(new Topic<T>(dp, topic_name, type_name, qos, uTopic));
        ref->init(ref);

        os_free(topic_name);
        os_free(type_name);

        topics.push_back(dds::topic::Topic<T>(ref));
    }
}
Beispiel #4
0
    Topic(const dds::domain::DomainParticipant& dp,
          const std::string& name,
          const std::string& type_name)
        : dds::topic::detail::TopicDescription<T>(dp, name, type_name),
          dp_(dp),
          qos_(),
          listener_(0),
          mask_(dds::core::status::StatusMask())
        {
        char* tn = ts_.get_type_name();
        ts_.register_type(dp->dp_.get(), tn);

        qos(dp.default_topic_qos());
        DDS::TopicQos tqos = convertQos(qos_);
        t_ = dp->dp_->create_topic(name.c_str(), tn, tqos, 0,
                                   mask_.to_ulong());

        if (t_ == 0)
            throw dds::core::NullReferenceError(
                        org::opensplice::core::exception_helper(
                            OSPL_CONTEXT_LITERAL(
                                "dds::core::NullReferenceError : Unable to create Topic! "
                                "Nil return from ::create_topic")));

        topic_ = org::opensplice::core::DDS_TOPIC_REF(t_, org::opensplice::core::TopicDeleter(dp->dp_));
    }
Beispiel #5
0
Topic<T, DELEGATE>::Topic(const dds::domain::DomainParticipant& dp,
                          const std::string& topic_name)
    : dds::topic::TopicDescription<T, DELEGATE>(new DELEGATE<T>(dp,
            topic_name,
            topic_type_name<T>::value(),
            dp.default_topic_qos(),
            NULL,
            dds::core::status::StatusMask::all()))
{ }
Beispiel #6
0
TPublisher<DELEGATE>::TPublisher(const dds::domain::DomainParticipant& dp)
    :   ::dds::core::Reference<DELEGATE>(new DELEGATE(dp,
                                                      dp.default_publisher_qos(),
                                                      NULL,
                                                      dds::core::status::StatusMask::none()))
{
    ISOCPP_REPORT_STACK_DDS_BEGIN(dp);
    this->delegate()->init(this->impl_);
}
Beispiel #7
0
dds::topic::TopicDescription
find_topic_description(
    const dds::domain::DomainParticipant& dp,
    const std::string& topic_name)
{
    dds::topic::TopicDescription t = dds::core::null;

    org::opensplice::core::ObjectDelegate::ref_type entity = dp.delegate()->find_topic(topic_name);
    if (!entity) {
        entity = dp.delegate()->find_cfTopic(topic_name);
    }
    if (entity) {
        dds::topic::TopicDescription::DELEGATE_REF_T ref =
                OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<org::opensplice::topic::TopicDescriptionDelegate>(entity);
        t = dds::topic::TopicDescription(ref);
    }

    return t;
}
Beispiel #8
0
TOPIC find(const dds::domain::DomainParticipant& dp, const std::string& topic_name)
{
    (void)dp;
    std::stringstream ss;
    ss << topic_name;
    ss << dp.domain_id();
    TOPIC t =
        org::opensplice::core::EntityRegistry<std::string, TOPIC>::get(ss.str());
    if(t != dds::core::null)
    {
        return t;
    }
    return TOPIC(dds::core::null);
}
Beispiel #9
0
   virtual void run(const dds::domain::DomainParticipant& dp,
         const dds::topic::Topic<T>& topic,
         const Params& params)
   {
      dds::pub::qos::PublisherQos pqos =
            dp.default_publisher_qos() << Partition("ishapes");

      dds::pub::Publisher pub(dp, pqos);

      dds::pub::qos::DataWriterQos dwqos =
            pub.default_datawriter_qos() << Durability::Transient() << Reliability::Reliable();

      dds::pub::DataWriter<T> dw(pub, topic, dwqos);

      const uint32_t period = params.period;
      const uint32_t samples = params.samples;
      uint32_t sleep_time = period * 1000;

      srand(clock());
      const uint32_t x0 = 10;
      const uint32_t y0 = 10;
      const uint32_t r = 200;
      const uint32_t dx = 5;
      const uint32_t dy = 7;

      // AnyDataWriter work just fine...
      AnyDataWriter adw = dw;
      DataWriter<ShapeType> xdw = adw.get<ShapeType>();
      std::cout << "Topic Name = " << xdw.topic().name()
                      << "\tType Name = " << xdw.topic().type_name() << std::endl;

      // ShapeType s = {params.color, x0, y0, params.shape_size};
      ShapeType s = {params.color.c_str(), x0 , y0, params.shape_size};

      std::cout << ">> Writing Data...";
               std::flush(std::cout);
      for (uint32_t i = 0; i < samples; ++i) {
         // Regular write
         dw.write(s);

         // Stream write
         dw << s;

         s.x = (s.x + dx) % r;
         s.y = (s.y + dy) % r;

         exampleSleepMilliseconds(sleep_time); // period is in ms
      }
   }
Beispiel #10
0
dds::topic::AnyTopic
find_any_topic(
    const dds::domain::DomainParticipant& dp,
    const std::string& topic_name)
{
    dds::topic::AnyTopic t = dds::core::null;

    org::opensplice::core::EntityDelegate::ref_type entity = dp.delegate()->find_topic(topic_name);
    if (entity) {
        dds::topic::AnyTopic::DELEGATE_REF_T ref =
                OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<org::opensplice::topic::AnyTopicDelegate>(entity);
        t = dds::topic::AnyTopic(ref);
    }

    return t;
}
Beispiel #11
0
SubscriberDelegate::SubscriberDelegate(
    const dds::domain::DomainParticipant& dp,
    const dds::sub::qos::SubscriberQos& qos,
    dds::sub::SubscriberListener* listener,
    const dds::core::status::StatusMask& event_mask) :
    dp_(dp),
    qos_(qos)
{
    ISOCPP_REPORT_STACK_DDS_BEGIN(dp);

    u_subscriber uSub;
    u_participant uPar;
    u_subscriberQos uQos;

    uPar = u_participant(this->dp_.delegate()->get_user_handle());
    if (!uPar) {
        ISOCPP_THROW_EXCEPTION(ISOCPP_ERROR, "Could not get subscriber participant.");
    }

    qos.delegate().check();
    uQos = qos.delegate().u_qos();
    if (!uQos) {
        ISOCPP_THROW_EXCEPTION(ISOCPP_ERROR, "Could not convert subscriber QoS.");
    }

    std::string name = this->dp_.delegate()->create_child_name("subscriber");
    uSub = u_subscriberNew(uPar, name.c_str(), uQos);
    u_subscriberQosFree (uQos);
    if (!uSub) {
        ISOCPP_THROW_EXCEPTION(ISOCPP_ERROR, "Could not create subscriber.");
    }

    /* ObjectDelegate class will free the userlayer object in its destructor. */
    this->userHandle = u_object(uSub);
    this->listener_set((void*)listener, event_mask);
    set_domain_id(dp.delegate()->get_domain_id());
}