MultiTopicImpl.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 
00010 #ifndef OPENDDS_NO_MULTI_TOPIC
00011 #include "MultiTopicImpl.h"
00012 #include "Registered_Data_Types.h"
00013 #include "DomainParticipantImpl.h"
00014 #include "TopicExpressionGrammar.h"
00015 #include "FilterEvaluator.h"
00016 #include "AstNodeWrapper.h"
00017 
00018 #include <stdexcept>
00019 #include <cstring>
00020 
00021 namespace OpenDDS {
00022 namespace DCPS {
00023 
00024 namespace {
00025   TypeSupport_ptr findTypeSupport(DomainParticipantImpl* participant,
00026     const char* type_name)
00027   {
00028     TypeSupport_var p = Registered_Data_Types->lookup(participant, type_name);
00029     if (!p) {
00030       throw std::runtime_error(OPENDDS_STRING("Data type: ") + type_name +
00031         " is not registered.");
00032     }
00033     return p;
00034   }
00035 }
00036 
00037 MultiTopicImpl::MultiTopicImpl(const char* name,
00038   const char* type_name, const char* subscription_expression,
00039   const DDS::StringSeq& expression_parameters,
00040   DomainParticipantImpl* participant)
00041   : TopicDescriptionImpl(name, type_name,
00042       findTypeSupport(participant, type_name),
00043       participant)
00044   , subscription_expression_(subscription_expression)
00045   , expression_parameters_(expression_parameters)
00046   , filter_eval_(NULL)
00047 {
00048   const char* out = subscription_expression
00049     + std::strlen(subscription_expression);
00050   yard::SimpleTextParser parser(subscription_expression, out);
00051   if (!parser.Parse<TopicExpressionGrammar::TopicCompleteInput>()) {
00052     reportErrors(parser, subscription_expression);
00053   }
00054 
00055   for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter;
00056       iter = iter->GetSibling()) {
00057     if (iter->TypeMatches<TopicExpressionGrammar::SubjectFieldSpec>()) {
00058       AstNode* fieldName = iter->GetFirstChild();
00059       aggregation_.push_back(SubjectFieldSpec(toString(fieldName),
00060         toString(fieldName->GetSibling())));
00061     } else if (iter->TypeMatches<TopicExpressionGrammar::TopicName>()) {
00062       selection_.push_back(toString(iter));
00063     } else {
00064       filter_eval_ = new FilterEvaluator(iter);
00065     }
00066   }
00067 }
00068 
00069 MultiTopicImpl::~MultiTopicImpl()
00070 {
00071   delete filter_eval_;
00072 }
00073 
00074 char* MultiTopicImpl::get_subscription_expression()
00075 {
00076   return CORBA::string_dup(subscription_expression_.c_str());
00077 }
00078 
00079 DDS::ReturnCode_t
00080 MultiTopicImpl::get_expression_parameters(DDS::StringSeq& params)
00081 {
00082   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_,
00083     DDS::RETCODE_OUT_OF_RESOURCES);
00084   params = expression_parameters_;
00085   return DDS::RETCODE_OK;
00086 }
00087 
00088 DDS::ReturnCode_t
00089 MultiTopicImpl::set_expression_parameters(const DDS::StringSeq& p)
00090 {
00091   ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_,
00092     DDS::RETCODE_OUT_OF_RESOURCES);
00093   expression_parameters_ = p;
00094   return DDS::RETCODE_OK;
00095 }
00096 
00097 
00098 } // namespace DCPS
00099 } // namespace OpenDDS
00100 
00101 #endif // OPENDDS_NO_MULTI_TOPIC

Generated on Fri Feb 12 20:05:24 2016 for OpenDDS by  doxygen 1.4.7