OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
MultiTopic.hpp
Go to the documentation of this file.
1 #ifndef OMG_DDS_TOPIC_DETAIL_MULTI_TOPIC_HPP_
2 #define OMG_DDS_TOPIC_DETAIL_MULTI_TOPIC_HPP_
3 
4 /* Copyright 2010, Object Management Group, Inc.
5  * Copyright 2010, PrismTech, Inc.
6  * Copyright 2010, Real-Time Innovations, Inc.
7  * All rights reserved.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #include <string>
23 #include <vector>
24 
25 #include <dds/core/types.hpp>
28 #include <dds/core/Query.hpp>
29 
30 #ifdef OMG_DDS_MULTI_TOPIC_SUPPORT
31 
32 namespace dds { namespace topic { namespace detail {
33 
34 
35 template <typename T>
36 class MultiTopic : public org::opensplice::topic::TopicDescriptionDelegate
37 {
38 public:
39  MultiTopic(
41  const std::string& name,
42  const std::string expression,
43  const FWDIterator& params_begin,
44  const FWDIterator& params_end)
45  : ::dds::core::Reference< DELEGATE<T> >(
46  new dds::topic::detail::MultiTopic<T>(dp, name, expression, params_begin, params_end))
47  {
48  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
49  // Set the correct (IDL) type_name in the TopicDescription.
50  dds::topic::detail::TopicDescription<T>::myTypeName = org::opensplice::topic::TopicTraits<T>::getTypeName();
51 
52  validate_filter();
53  }
54 
55  virtual ~MultiTopic()
56  {
57  // Assume destructor of Filter attribute cleans up itself.
58  }
59 
60 private:
61  void validate_filter()
62  {
63  q_expr expr = NULL;
64  uint32_t length;
65  std::vector<c_value> params;
66 
67  length = myFilter.parameters_length();
68  if (length < 100) {
69  expr = q_parse(myFilter.expression().c_str());
70  if (!expr ) {
71  ISOCPP_THROW_EXCEPTION(ISOCPP_INVALID_ARGUMENT_ERROR,
72  "filter_expression '%s' is invalid", myFilter.expression().c_str());
73  }
74  } else {
75  ISOCPP_THROW_EXCEPTION(ISOCPP_INVALID_ARGUMENT_ERROR,
76  "Invalid number of filter_parameters '%d', maximum is 99", length);
77  }
78 
79  params = reader_parameters();
80  /* The function below does not exist yet, but probably a function like it will need to be developed. */
81  if (!u_topicMultiExprValidate(dp.delegate()->get_user_handle(), myFilter.expression().c_str(), &params[0], params.size())) {
82  ISOCPP_THROW_EXCEPTION(ISOCPP_INVALID_ARGUMENT_ERROR,
83  "filter_expression '%s' is invalid.", myFilter.expression().c_str());
84  }
85  q_dispose(expr);
86  /* The params can be NULL, but os_free ignores those pesky NULLs. */
87  os_free(params);
88  }
89 
90 public:
91  std::string reader_expression() const
92  {
93  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
94  return myFilter.expression();
95  }
96 
97  c_value *reader_parameters() const
98  {
99  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
100  c_value *params = NULL;
101  uint32_t n, length;
102  org::opensplice::topic::FilterDelegate::const_iterator paramIterator;
103 
104  length = myFilter.parameters_length();
105  if (length != 0) {
106  params = (c_value *)os_malloc(length * sizeof(struct c_value));
107  for (n = 0, paramIterator = myFilter.begin(); n < length; n++, paramIterator++) {
108  params[n] = c_stringValue(const_cast<char *>(paramIterator->c_str()));
109  }
110  }
111  return params;
112  }
113 
114  const std::string expression() const
115  {
116  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
117  return myFilter.expression();
118  }
119 
120  template <typename FWIterator>
121  void expression_parameters(const FWIterator& params_begin, const FWIterator& params_end)
122  {
123  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
124  myFilter.parameters(begin, end);
125  validate_filter();
126  }
127 
128  const dds::core::StringSeq expression_parameters() const
129  {
130  ISOCPP_REPORT_STACK_DELEGATE_BEGIN();
131  return dds::core::StringSeq(myFilter.begin(), myFilter.end());
132  }
133 
134 private:
135  dds::topic::Filter myFilter;
136 };
137 
138 }
139 }
140 }
141 #endif /* OMG_DDS_MULTI_TOPIC_SUPPORT */
142 
143 #endif /* OMG_DDS_TOPIC_DETAIL_MULTI_TOPIC_HPP_ */
Filter objects contain SQL expressions that allow the application to specify a filter on the locally ...
Definition: Filter.hpp:57
A DomainParticipant represents the local membership of the application in a Domain.
Definition: array.hpp:23
std::vector< std::string > StringSeq
Definition: types.hpp:43