00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_DCPS_CONTENTFILTEREDTOPICIMPL_H 00009 #define OPENDDS_DCPS_CONTENTFILTEREDTOPICIMPL_H 00010 00011 #ifndef OPENDDS_NO_CONTENT_FILTERED_TOPIC 00012 00013 #include "dds/DCPS/TopicDescriptionImpl.h" 00014 #include "dds/DCPS/FilterEvaluator.h" 00015 #include "dds/DCPS/PoolAllocator.h" 00016 00017 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00018 #pragma once 00019 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00020 00021 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00022 00023 namespace OpenDDS { 00024 namespace DCPS { 00025 00026 class DataReaderImpl; 00027 00028 class OpenDDS_Dcps_Export ContentFilteredTopicImpl 00029 : public virtual OpenDDS::DCPS::LocalObject<DDS::ContentFilteredTopic> 00030 , public virtual TopicDescriptionImpl { 00031 public: 00032 ContentFilteredTopicImpl(const char* name, DDS::Topic_ptr related_topic, 00033 const char* filter_expression, DomainParticipantImpl* participant); 00034 00035 virtual ~ContentFilteredTopicImpl() {} 00036 00037 char* get_filter_expression(); 00038 00039 DDS::ReturnCode_t get_expression_parameters(DDS::StringSeq& parameters); 00040 00041 DDS::ReturnCode_t set_expression_parameters(const DDS::StringSeq& parameters); 00042 00043 DDS::Topic_ptr get_related_topic(); 00044 00045 template<typename Sample> 00046 bool filter(const Sample& s) const 00047 { 00048 ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, guard, lock_, false); 00049 return filter_eval_.eval(s, expression_parameters_); 00050 } 00051 00052 void add_reader(DataReaderImpl& reader); 00053 void remove_reader(DataReaderImpl& reader); 00054 00055 const char* get_filter_class_name () const 00056 { 00057 return filter_eval_.usesExtendedGrammar () ? "OPENDDSSQL" : "DDSSQL"; 00058 } 00059 00060 private: 00061 OPENDDS_STRING filter_expression_; 00062 FilterEvaluator filter_eval_; 00063 DDS::StringSeq expression_parameters_; 00064 DDS::Topic_var related_topic_; 00065 typedef OPENDDS_VECTOR(WeakRcHandle<DataReaderImpl>) Readers; 00066 Readers readers_; 00067 00068 /// Concurrent access to expression_parameters_ and readers_ 00069 mutable ACE_Recursive_Thread_Mutex lock_; 00070 }; 00071 00072 } // namespace DCPS 00073 } // namespace OpenDDS 00074 00075 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00076 00077 #endif // OPENDDS_NO_CONTENT_FILTERED_TOPIC 00078 00079 #endif