RTI Routing Service Version 7.3.0
Query.hpp
1/* $Id$
2
3(c) Copyright, Real-Time Innovations, 2015-2016.
4All rights reserved.
5
6No duplications, whole or partial, manual or electronic, may be made
7without express written permission. Any such copies, or
8revisions thereof, must display this notice unaltered.
9This code contains trade secrets of Real-Time Innovations, Inc.
10
11
12============================================================================= */
13
14#ifndef RTI_ROUTING_PROCESSOR_QUERY_HPP_
15#define RTI_ROUTING_PROCESSOR_QUERY_HPP_
16
17#include "routingservice/routingservice_processor.h"
18
19#include <dds/core/Reference.hpp>
20#include <rti/core/detail/SelfReference.hpp>
21
22
23namespace rti { namespace routing { namespace processor {
24
25class Input;
26
27class QueryHolder : public rti::core::detail::RetainableType<QueryHolder>{
28public:
29
30 QueryHolder() : input_(NULL), query_data_(NULL)
31 {
32 }
33
34 QueryHolder(RTI_RoutingServiceInput *input, const dds::topic::Filter& the_filter)
35 : input_(input),
36 query_data_(NULL)
37 {
38 filter(the_filter);
39 }
40
41 ~QueryHolder()
42 {
43 if (query_data_ != NULL) {
44 /*
45 * Ignore the error. We can't throw in the destructor and this
46 * layer does not log anything
47 */
48 (void) RTI_RoutingServiceInput_delete_content_query(
49 input_,
50 query_data_);
51 }
52 }
53
54 void filter(const dds::topic::Filter& filter)
55 {
56 RTI_RoutingServiceSelectorContent content =
57 RTI_RoutingServiceSelectorContent_INITIALIZER;
58 content.expression = (char *) filter.expression().c_str();
59 rti::core::native_conversions::to_native(
60 content.expression_parameters,
61 filter->parameters());
62 query_data_ = RTI_RoutingServiceInput_create_content_query(
63 input_,
64 query_data_,
65 &content);
66 DDS_StringSeq_finalize(&content.expression_parameters);
67 if (query_data_ == NULL) {
68 throw dds::core::Error("error creating content query from native input");
69 }
70 }
71
72 RTI_RoutingServiceInput *input_;
73 void* query_data_;
74};
75
92class Query : public dds::core::Reference<rti::routing::processor::QueryHolder> {
93public:
94 typedef dds::core::Reference<QueryHolder> Base;
95 OMG_DDS_REF_TYPE_NOTYPENAME(
96 Query,
97 dds::core::Reference,
98 rti::routing::processor::QueryHolder);
99
100 explicit Query(Base::DELEGATE_REF_T reference) : Base(reference)
101 {
102 if (this->delegate()) {
103 this->delegate()->remember_reference(this->delegate());
104 }
105 }
106
116 Query(RTI_RoutingServiceInput *input, const dds::topic::Filter& filter)
117 : Base(new QueryHolder(input, filter))
118 {
119 this->delegate()->remember_reference(this->delegate());
120 }
121
122
130 void filter(const dds::topic::Filter& filter)
131 {
132 this->delegate()->filter(filter);
133 }
134};
135
136} } }
137
138#endif // RTI_ROUTING_PROCESSOR_QUERY_HPP_
Encapsulates a content query to select data from a rti::routing::adapter::StreamReader.
Definition: Query.hpp:92
void filter(const dds::topic::Filter &filter)
Updates the current Query content filter.
Definition: Query.hpp:130
Query(RTI_RoutingServiceInput *input, const dds::topic::Filter &filter)
Creates a Query described by a filter on an input.
Definition: Query.hpp:116