【问题标题】:How to determine that type_name of a deleted DataWriter using RTI DDS如何使用 RTI DDS 确定已删除 DataWriter 的 type_name
【发布时间】:2016-08-15 16:17:43
【问题描述】:

我正在使用 RTI DDS 5.2 在 c++ 中编写一个工具,该工具需要检测何时删除 DataWriter 并知道相关数据的type_name。我正在使用类似于thisthis 的代码。

我正在使用DDSWaitSet,当使用delete_datawriter 删除DataWriter 时会触发它,但SampleInfo 表明数据无效,果然,数据样本type_name 为空。

有没有办法删除 DataWriter 以使内置主题订阅获取type_name?或者是否有我可以设置的 QOS 设置来解决此问题?

【问题讨论】:

    标签: c++ data-distribution-service


    【解决方案1】:

    找到了解决此问题的方法。我仍然不知道如何使数据样本在 DataWriter 消失时有效,但 SampleInfo 确实具有唯一标识作者的字段 instance_state。解决方案是在数据有效时跟踪type_names,在数据无效时仅查找。以下是我用来解决问题的代码要点:

    struct cmp_instance_handle {
        bool operator()(const DDS_InstanceHandle_t& a, const DDS_InstanceHandle_t& b) const {
            return !DDS_InstanceHandle_equals(&a, &b);
        }
    };
    
    void wait_for_data_writer_samples()
    {
        ConditionSeq cs;
        DDSWaitSet* ws = new DDSWaitSet();
        StatusCondition* condition = _publication_dr->get_statuscondition();
        DDS_Duration_t timeout = {DDS_DURATION_INFINITE_SEC, DDS_DURATION_INFINITE_NSEC};
        std::map<DDS_InstanceHandle_t, std::string, cmp_instance_handle> instance_handle_map;
    
        ws->attach_condition(condition);
        condition->set_enabled_statuses(DDS_STATUS_MASK_ALL);
    
        while(true) {
            ws->wait(cs, timeout);
    
            PublicationBuiltinTopicDataSeq data_seq;
            SampleInfoSeq info_seq;
    
            _publication_dr->take(
                data_seq,
                info_seq,
                DDS_LENGTH_UNLIMITED,
                ANY_SAMPLE_STATE,
                ANY_VIEW_STATE,
                ANY_INSTANCE_STATE
            );
    
            int len = data_seq.length();
            for(int i = 0; i < len; ++i) {
                DDS_InstanceHandle_t instance_handle = info_seq[i].instance_handle;
    
                if(info_seq[i].valid_data) {
                    std::string type_name(data_seq[i].type_name);
    
                    // store the type_name in the map for future use
                    instance_handle_map[instance_handle] = type_name;
                    if(info_seq[i].instance_state == DDS_InstanceStateKind::DDS_ALIVE_INSTANCE_STATE) {
                        do_data_writer_alive_callback(type_name);
                    }
                    else {
                        // If the data is valid, but not DDS_ALIVE_INSTANCE_STATE, the DataWriter died *and* we can 
                        // directly access the type_name so we can handle that case here
                        do_data_writer_dead_callback(type_name);
                    }
                }
                else {
                    // If the data is not valid then the DataWriter is definitely not alive but we can't directly access
                    // the type_name. Fortunately we can look it up in our map.
                    do_data_writer_dead_callback(instance_handle_map[instance_handle]);
    
                    // at this point the DataWriter is gone so we remove it from the map.
                    instance_handle_map.erase(instance_handle);
    
                }
            }
            _publication_dr->return_loan(data_seq, info_seq);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 2019-09-29
      • 2018-05-25
      • 1970-01-01
      相关资源
      最近更新 更多