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_QUERY_CONDITION 11 : #include "QueryConditionImpl.h" 12 : #include "DataReaderImpl.h" 13 : 14 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 15 : 16 : namespace OpenDDS { 17 : namespace DCPS { 18 : 19 0 : QueryConditionImpl::QueryConditionImpl( 20 : DataReaderImpl* dr, DDS::SampleStateMask sample_states, 21 : DDS::ViewStateMask view_states, DDS::InstanceStateMask instance_states, 22 0 : const char* query_expression) 23 : : ReadConditionImpl(dr, sample_states, view_states, instance_states) 24 0 : , query_expression_(query_expression) 25 0 : , evaluator_(query_expression, true) 26 : { 27 0 : if (DCPS_debug_level > 5) { 28 0 : ACE_DEBUG((LM_DEBUG, 29 : ACE_TEXT("(%P|%t) QueryConditionImpl::QueryConditionImpl() - ") 30 : ACE_TEXT("Creating qc with query <%C> which requires <%d> parameters\n"), 31 : query_expression, evaluator_.number_parameters())); 32 : } 33 0 : } 34 : 35 0 : char* QueryConditionImpl::get_query_expression() 36 : { 37 0 : return CORBA::string_dup(query_expression_); 38 : } 39 : 40 : DDS::ReturnCode_t 41 0 : QueryConditionImpl::get_query_parameters(DDS::StringSeq& query_parameters) 42 : { 43 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 44 0 : query_parameters = query_parameters_; 45 0 : return DDS::RETCODE_OK; 46 0 : } 47 : 48 : DDS::ReturnCode_t 49 0 : QueryConditionImpl::set_query_parameters(const DDS::StringSeq& query_parameters) 50 : { 51 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 52 : 53 : // Check sequence of strings that give values to the ‘parameters’ (i.e., "%n" tokens) 54 : // in the query_expression matches the size of the parameter sequence. 55 : // The tokens start with 0 which means that when the maximum number used is 1 we need 56 : // two parameters, (zero and one) 57 0 : if (query_parameters.length() != evaluator_.number_parameters()) { 58 0 : if (DCPS_debug_level > 1) { 59 0 : ACE_ERROR((LM_ERROR, 60 : ACE_TEXT("(%P|%t) QueryConditionImpl::set_expression_parameters() - ") 61 : ACE_TEXT("passed incorrect set of query parameters, expected %d received %d\n"), 62 : evaluator_.number_parameters (), query_parameters.length())); 63 : } 64 0 : return DDS::RETCODE_ERROR; 65 : } 66 : 67 0 : query_parameters_ = query_parameters; 68 0 : return DDS::RETCODE_OK; 69 0 : } 70 : 71 : std::vector<OPENDDS_STRING> 72 0 : QueryConditionImpl::getOrderBys() const 73 : { 74 0 : return evaluator_.getOrderBys(); 75 : } 76 : 77 : bool 78 0 : QueryConditionImpl::hasFilter() const 79 : { 80 0 : return evaluator_.hasFilter(); 81 : } 82 : 83 : CORBA::Boolean 84 0 : QueryConditionImpl::get_trigger_value() 85 : { 86 0 : if (hasFilter()) { 87 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard2, parent_->sample_lock_, false); 88 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 89 0 : return parent_->contains_sample_filtered(sample_states_, view_states_, 90 0 : instance_states_, evaluator_, query_parameters_); 91 0 : } else { 92 0 : return ReadConditionImpl::get_trigger_value(); 93 : } 94 : } 95 : 96 0 : TypeSupportImpl* QueryConditionImpl::get_type_support() const 97 : { 98 0 : DDS::TopicDescription_var td = parent_->get_topicdescription(); 99 0 : TopicDescriptionImpl* const tdi = dynamic_cast<TopicDescriptionImpl*>(td.in()); 100 0 : TypeSupport* const ts = tdi ? tdi->get_type_support() : 0; 101 0 : return dynamic_cast<TypeSupportImpl*>(ts); 102 0 : } 103 : 104 : } // namespace DCPS 105 : } // namespace OpenDDS 106 : 107 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 108 : 109 : #endif // OPENDDS_NO_QUERY_CONDITION