-1

我将 openDDS 用于以数据为中心的发布订阅模型。发布者不断发送数据,订阅者将收到它。但对于订阅者,它必须根据我给出的条件接收过滤数据。

假设我的发布者和订阅者使用的主题结构是:

module Messenger {

#pragma DCPS_DATA_TYPE "Messenger::ChannelData"
#pragma DCPS_DATA_KEY "Messenger::ChannelData subject_id"

  struct ChannelData {
            string from;
            string subject;
            long subject_id;
            string text;
            long   count;
  };
};

OpenDDS 有一个名为内容过滤主题的概念。我用过的一样。

代码 :

  // Register Type (Messenger::Message)
    Messenger::ChannelDataTypeSupport_var ts =
      new Messenger::ChannelDataTypeSupportImpl();

    if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }

    // Create Topic (Movie Discussion List)
    CORBA::String_var type_name = ts->get_type_name();
    DDS::Topic_var topic =
      participant->create_topic("Movie Discussion List",
                                type_name.in(),
                                TOPIC_QOS_DEFAULT,
                                DDS::TopicListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

 DDS::ContentFilteredTopic_var cft =
         participant->create_contentfilteredtopic("MyTopic-Filtered",
         topic,
         "count <= 0 ",DDS::StringSeq());

但是在上面的代码中,我硬编码了过滤条件count <=0

那么,有没有办法为订阅者提供动态过滤条件以接收过滤数据?

4

1 回答 1

0

Instead of 0 pass %0 and instead of DDS::StringSeq() pass a sequence of length 1 that contains the value that should be used for %0. A quick search on google would have given you several examples!

于 2014-09-16T16:58:51.007 回答