Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #ifndef OPENDDS_DCPS_CONTENTFILTEREDTOPICIMPL_H 9 : #define OPENDDS_DCPS_CONTENTFILTEREDTOPICIMPL_H 10 : 11 : #ifndef OPENDDS_NO_CONTENT_FILTERED_TOPIC 12 : 13 : #include "TopicDescriptionImpl.h" 14 : #include "FilterEvaluator.h" 15 : #include "PoolAllocator.h" 16 : #include "TypeSupportImpl.h" 17 : 18 : #if !defined (ACE_LACKS_PRAGMA_ONCE) 19 : #pragma once 20 : #endif /* ACE_LACKS_PRAGMA_ONCE */ 21 : 22 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 23 : 24 : namespace OpenDDS { 25 : namespace DCPS { 26 : 27 : class DataReaderImpl; 28 : 29 : class OpenDDS_Dcps_Export ContentFilteredTopicImpl 30 : : public virtual OpenDDS::DCPS::LocalObject<DDS::ContentFilteredTopic> 31 : , public virtual TopicDescriptionImpl { 32 : public: 33 : ContentFilteredTopicImpl(const char* name, DDS::Topic_ptr related_topic, 34 : const char* filter_expression, DomainParticipantImpl* participant); 35 : 36 0 : virtual ~ContentFilteredTopicImpl() {} 37 : 38 : char* get_filter_expression(); 39 : 40 : DDS::ReturnCode_t get_expression_parameters(DDS::StringSeq& parameters); 41 : 42 : DDS::ReturnCode_t set_expression_parameters(const DDS::StringSeq& parameters); 43 : 44 : DDS::Topic_ptr get_related_topic(); 45 : 46 : /** 47 : * Returns true if the sample matches the filter. 48 : */ 49 : template<typename Sample> 50 0 : bool filter(const Sample& s, bool sample_only_has_key_fields) const 51 : { 52 0 : ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 53 : /* 54 : * Omit the sample from results if the filter references non-key fields 55 : * and the sample only has key fields. 56 : */ 57 0 : TypeSupportImpl* const ts = dynamic_cast<TypeSupportImpl*>(type_support_.in()); 58 0 : if (!ts || (sample_only_has_key_fields && filter_eval_.has_non_key_fields(*ts))) { 59 0 : return false; 60 : } 61 0 : return filter_eval_.eval(s, expression_parameters_); 62 0 : } 63 : 64 : void add_reader(DataReaderImpl& reader); 65 : void remove_reader(DataReaderImpl& reader); 66 : 67 0 : const char* get_filter_class_name () const 68 : { 69 0 : return filter_eval_.usesExtendedGrammar () ? "OPENDDSSQL" : "DDSSQL"; 70 : } 71 : 72 : private: 73 : OPENDDS_STRING filter_expression_; 74 : FilterEvaluator filter_eval_; 75 : DDS::StringSeq expression_parameters_; 76 : DDS::Topic_var related_topic_; 77 : typedef OPENDDS_VECTOR(WeakRcHandle<DataReaderImpl>) Readers; 78 : Readers readers_; 79 : 80 : /// Concurrent access to expression_parameters_ and readers_ 81 : mutable ACE_Recursive_Thread_Mutex lock_; 82 : }; 83 : 84 : } // namespace DCPS 85 : } // namespace OpenDDS 86 : 87 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 88 : 89 : #endif // OPENDDS_NO_CONTENT_FILTERED_TOPIC 90 : 91 : #endif