DDS.TopicQuery and associated elements.
TopicQueries allow a DDS.DataReader to query the sample cache of its matching DDS.DataWriter. A user can create a DDS.TopicQuery with the DDS.DataReader.create_topic_query API. When a DataReader creates a TopicQuery, DDS will propagate it to other DomainParticipants and their DataWriters. When a DataWriter matching with the DataReader that created the TopicQuery receives it, it will send the cached samples that pass the TopicQuery's filter.
To configure how to dispatch a TopicQuery, the DDS.DataWriterQos includes the DDS.TopicQueryDispatchQosPolicy policy. By default, a DataWriter ignores TopicQueries unless they are explicitly enabled using this policy.
The delivery of TopicQuery samples occurs in a separate RTPS channel. This allows DataReaders to receive TopicQuery samples and live samples in parallel. This is a key difference with respect to the Durability QoS policy.
Late-joining DataWriters will also discover existing TopicQueries. To delete a TopicQuery you must use DDS.DataReader.delete_topic_query.
After deleting a TopicQuery, new DataWriters won't discover it and existing DataWriters currently publishing cached samples may stop before delivering all of them.
By default, a TopicQuery queries the samples that were in the DataWriter cache at the time the DataWriter receives the TopicQuery. However a TopicQuery can be created in a "continuous" mode. A DataWriter will continue delivering samples that pass a continuous TopicQuery filter until the DataReader application explicitly deletes it.
The samples received in response to a TopicQuery are stored in the associated DataReader's cache. Any of the read/take operations can retrieve TopicQuery samples. The field DDS.SampleInfo.topic_query_guid associates each sample to its TopicQuery. If the read sample is not in response to a TopicQuery then this field will be DDS_GUID_UNKNOWN. Note that the same data may be received several times, depending on how many TopicQueries the DataReader creates and their TopicQuerySelection.
You can choose to read or take only TopicQuery samples, only live samples, or both. To support this ReadConditions and QueryConditions provide the DDS.DataReader.create_querycondition_w_params and DDS.DataReader.create_readcondition_w_params APIs.
Each TopicQuery is identified by a GUID that can be accessed using the DDS.TopicQuery.get_guid method.
The new built-in DataReader can be retrieved using the built-in subscriber and DDS.Subscriber.lookup_datareader. The topic name is DDS.SERVICE_REQUEST_TOPIC_NAME. Installing a listener with the DDS.DataReaderListener.on_data_available callback implemented will allow a publishing application to be notified whenever a TopicQuery has been received from a subscribing application.
The DDS.ServiceRequest.service_id of a DDS.ServiceRequest corresponding to a DDS.TopicQuery will be DDS.TOPIC_QUERY_SERVICE_REQUEST_ID and the DDS.ServiceRequest.instance_id will be equal to the GUID of the DDS.TopicQuery (see DDS.TopicQuery.get_guid).
The DDS.ServiceRequest.request_body is a sequence of bytes containing more information about the TopcQuery. This information can be retrieved using the DDS.TopicQueryHelper.topic_query_data_from_service_request function. The resulting DDS.TopicQueryData contains the DDS.TopicQuerySelection that the DDS.TopicQuery was created with, the GUID of the original DataReader that created the TopicQuery, and the topic name of that DataReader. Note: When TopicQueries are propagated through one or more Routing Services, the last DataReader that issued the TopicQuery will be a Routing Service DataReader. The DDS.TopicQueryData.original_related_reader_guid, however, will be that of the first DataReader to have created the TopicQuery.