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 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 namespace OpenDDS {
00024 namespace DCPS {
00025 
00026 namespace {
00027   TypeSupport_ptr findTypeSupport(DomainParticipantImpl* participant,
00028     const char* type_name)
00029   {
00030     TypeSupport_var p = Registered_Data_Types->lookup(participant, type_name);
00031     if (!p) {
00032       throw std::runtime_error(OPENDDS_STRING("Data type: ") + type_name +
00033         " is not registered.");
00034     }
00035     return p;
00036   }
00037 }
00038 
00039 MultiTopicImpl::MultiTopicImpl(const char* name,
00040   const char* type_name, const char* subscription_expression,
00041   const DDS::StringSeq& expression_parameters,
00042   DomainParticipantImpl* participant)
00043   : TopicDescriptionImpl(name, type_name,
00044       findTypeSupport(participant, type_name),
00045       participant)
00046   , subscription_expression_(subscription_expression)
00047   , expression_parameters_(expression_parameters)
00048 {
00049   const char* out = subscription_expression
00050     + std::strlen(subscription_expression);
00051   yard::SimpleTextParser parser(subscription_expression, out);
00052   if (!parser.Parse<TopicExpressionGrammar::TopicCompleteInput>()) {
00053     reportErrors(parser, subscription_expression);
00054   }
00055 
00056   for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter;
00057       iter = iter->GetSibling()) {
00058     if (iter->TypeMatches<TopicExpressionGrammar::SubjectFieldSpec>()) {
00059       AstNode* fieldName = iter->GetFirstChild();
00060       aggregation_.push_back(SubjectFieldSpec(toString(fieldName),
00061         toString(fieldName->GetSibling())));
00062     } else if (iter->TypeMatches<TopicExpressionGrammar::TopicName>()) {
00063       selection_.push_back(toString(iter));
00064     } else {
00065       filter_eval_.reset(new FilterEvaluator(iter));
00066     }
00067   }
00068 }
00069 
00070 MultiTopicImpl::~MultiTopicImpl()
00071 {
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 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00102 
00103 #endif // OPENDDS_NO_MULTI_TOPIC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1