Line data Source code
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 : 21 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 22 : 23 : namespace OpenDDS { 24 : namespace DCPS { 25 : 26 : namespace { 27 0 : TypeSupport_ptr findTypeSupport(DomainParticipantImpl* participant, 28 : const char* type_name) 29 : { 30 0 : TypeSupport_var p = Registered_Data_Types->lookup(participant, type_name); 31 0 : if (!p) { 32 0 : throw std::runtime_error(OPENDDS_STRING("Data type: ") + type_name + 33 0 : " is not registered."); 34 : } 35 0 : return p; 36 0 : } 37 : } 38 : 39 0 : MultiTopicImpl::MultiTopicImpl(const char* name, 40 : const char* type_name, const char* subscription_expression, 41 : const DDS::StringSeq& expression_parameters, 42 0 : DomainParticipantImpl* participant) 43 : : TopicDescriptionImpl(name, type_name, 44 : findTypeSupport(participant, type_name), 45 : participant) 46 0 : , subscription_expression_(subscription_expression) 47 0 : , expression_parameters_(expression_parameters) 48 : { 49 0 : const char* out = subscription_expression 50 0 : + std::strlen(subscription_expression); 51 0 : yard::SimpleTextParser parser(subscription_expression, out); 52 0 : if (!parser.Parse<TopicExpressionGrammar::TopicCompleteInput>()) { 53 0 : reportErrors(parser, subscription_expression); 54 : } 55 : 56 0 : for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter; 57 0 : iter = iter->GetSibling()) { 58 0 : if (iter->TypeMatches<TopicExpressionGrammar::SubjectFieldSpec>()) { 59 0 : AstNode* fieldName = iter->GetFirstChild(); 60 0 : aggregation_.push_back(SubjectFieldSpec(toString(fieldName), 61 0 : toString(fieldName->GetSibling()))); 62 0 : } else if (iter->TypeMatches<TopicExpressionGrammar::TopicName>()) { 63 0 : selection_.push_back(toString(iter)); 64 : } else { 65 0 : filter_eval_.reset(new FilterEvaluator(iter)); 66 : } 67 : } 68 0 : } 69 : 70 0 : MultiTopicImpl::~MultiTopicImpl() 71 : { 72 0 : } 73 : 74 0 : char* MultiTopicImpl::get_subscription_expression() 75 : { 76 0 : return CORBA::string_dup(subscription_expression_.c_str()); 77 : } 78 : 79 : DDS::ReturnCode_t 80 0 : MultiTopicImpl::get_expression_parameters(DDS::StringSeq& params) 81 : { 82 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, 83 : DDS::RETCODE_OUT_OF_RESOURCES); 84 0 : params = expression_parameters_; 85 0 : return DDS::RETCODE_OK; 86 0 : } 87 : 88 : DDS::ReturnCode_t 89 0 : MultiTopicImpl::set_expression_parameters(const DDS::StringSeq& p) 90 : { 91 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, 92 : DDS::RETCODE_OUT_OF_RESOURCES); 93 0 : expression_parameters_ = p; 94 0 : return DDS::RETCODE_OK; 95 0 : } 96 : 97 : 98 : } // namespace DCPS 99 : } // namespace OpenDDS 100 : 101 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 102 : 103 : #endif // OPENDDS_NO_MULTI_TOPIC