OpenDDS  Snapshot(2023/04/28-20:55)
MultiTopicImpl.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
9 
10 #ifndef OPENDDS_NO_MULTI_TOPIC
11 #include "MultiTopicImpl.h"
12 #include "Registered_Data_Types.h"
13 #include "DomainParticipantImpl.h"
14 #include "TopicExpressionGrammar.h"
15 #include "FilterEvaluator.h"
16 #include "AstNodeWrapper.h"
17 
18 #include <stdexcept>
19 #include <cstring>
20 
22 
23 namespace OpenDDS {
24 namespace DCPS {
25 
26 namespace {
27  TypeSupport_ptr findTypeSupport(DomainParticipantImpl* participant,
28  const char* type_name)
29  {
30  TypeSupport_var p = Registered_Data_Types->lookup(participant, type_name);
31  if (!p) {
32  throw std::runtime_error(OPENDDS_STRING("Data type: ") + type_name +
33  " is not registered.");
34  }
35  return p;
36  }
37 }
38 
40  const char* type_name, const char* subscription_expression,
41  const DDS::StringSeq& expression_parameters,
42  DomainParticipantImpl* participant)
43  : TopicDescriptionImpl(name, type_name,
44  findTypeSupport(participant, type_name),
45  participant)
46  , subscription_expression_(subscription_expression)
47  , expression_parameters_(expression_parameters)
48 {
49  const char* out = subscription_expression
50  + std::strlen(subscription_expression);
51  yard::SimpleTextParser parser(subscription_expression, out);
52  if (!parser.Parse<TopicExpressionGrammar::TopicCompleteInput>()) {
53  reportErrors(parser, subscription_expression);
54  }
55 
56  for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter;
57  iter = iter->GetSibling()) {
58  if (iter->TypeMatches<TopicExpressionGrammar::SubjectFieldSpec>()) {
59  AstNode* fieldName = iter->GetFirstChild();
60  aggregation_.push_back(SubjectFieldSpec(toString(fieldName),
61  toString(fieldName->GetSibling())));
62  } else if (iter->TypeMatches<TopicExpressionGrammar::TopicName>()) {
63  selection_.push_back(toString(iter));
64  } else {
65  filter_eval_.reset(new FilterEvaluator(iter));
66  }
67  }
68 }
69 
71 {
72 }
73 
75 {
77 }
78 
81 {
84  params = expression_parameters_;
85  return DDS::RETCODE_OK;
86 }
87 
90 {
94  return DDS::RETCODE_OK;
95 }
96 
97 
98 } // namespace DCPS
99 } // namespace OpenDDS
100 
102 
103 #endif // OPENDDS_NO_MULTI_TOPIC
Implements the OpenDDS::DCPS::DomainParticipant interfaces.
yard::TreeBuildingParser< char >::Node AstNode
unique_ptr< FilterEvaluator > filter_eval_
DDS::ReturnCode_t set_expression_parameters(const DDS::StringSeq &parameters)
ACE_Recursive_Thread_Mutex lock_
Concurrent access to expression_parameters_.
DDS::StringSeq expression_parameters_
MultiTopicImpl(const char *name, const char *type_name, const char *subscription_expression, const DDS::StringSeq &expression_parameters, DomainParticipantImpl *participant)
std::vector< SubjectFieldSpec > aggregation_
OPENDDS_STRING toString(yard::TreeBuildingParser< char >::Node *iter)
OPENDDS_STRING subscription_expression_
#define OPENDDS_STRING
char * string_dup(const char *)
#define Registered_Data_Types
std::vector< OPENDDS_STRING > selection_
#define ACE_GUARD_RETURN(MUTEX, OBJ, LOCK, RETURN)
const ReturnCode_t RETCODE_OUT_OF_RESOURCES
DDS::ReturnCode_t get_expression_parameters(DDS::StringSeq &parameters)
const char *const name
Definition: debug.cpp:60
void reportErrors(yard::SimpleTextParser &parser, const char *input)
called after parsing has failed, throws std::exception with details
Implements the DDS::TopicDescription interface.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
const ReturnCode_t RETCODE_OK
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
sequence< string > StringSeq
Definition: DdsDcpsCore.idl:50