m2etis  0.4
NullFilter.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_PUBSUB_FILTER_NULLFILTER_H__
23 #define __M2ETIS_PUBSUB_FILTER_NULLFILTER_H__
24 
25 #include <string>
26 
29 
30 #include "boost/shared_ptr.hpp"
31 
32 namespace m2etis {
33 namespace pubsub {
34 namespace filter {
35 
36  // registering a filter means to get the same number of events or more than before
37  // deregistering a filter means to get the same number of events or less than before
38 
39  template<typename EventType, typename NetworkType>
40  class NullFilter {
41  public:
42  typedef boost::shared_ptr<EventType> PayloadPtr;
44 
45  enum { size = 0 };
46 
47  // return type for getUnsubscribePayload:
48  enum FilterUnsubscribeInformation { // TODO: (Roland) maybe move to BaseFiltering base class
50  UNSUBSCRIBEFROMTREE, // if last filter has been deregistered, unsubscribe from the tree
51  CANCELUNSUBSCRIBE // filter has been deregsitered, but a subscriber of this node has registered
52  // the same filter, so the unsubscribe message must not be forwarded (if the filter strategy can detect this,
53  // otherweise forward unsubscribe message with an appropriate filter info
54  };
55 
57  virtual ~NullFilter() {}
58 
59  void getSubscribePayload(boost::shared_ptr<FilterExp<EventType>>, bool, typename message::FilterInfo::Ptr) { // return boost::make_shared<m2etis::pubsub::filter::FilterExp<EventType> > (m2etis::pubsub::filter::TruePredicate<EventType>()); // return the predicate, it must be sent "up" and save it yourself
60  return;
61  }
62 
63  void getUnsubscribePayload(typename message::FilterInfo::Ptr filterInfo) {
64  // perhaps send it "up" that it can be removed?
65  // return boost::make_shared<m2etis::pubsub::filter::FilterExp<EventType> > ();
66  }
67 
69  return FORWARDUNSUBSCRIBE;
70  }
71 
72  std::string getPublishPayload(const PayloadPtr message_text) const {
73  return ""; // prefilter or preprocess the message and give other nodes a hint
74  }
75 
76  std::string processSubscribePayload(const typename NetworkType::Key &, typename message::FilterInfo::Ptr) {
77  return ""; // from sender, comes that filterinfo (maybe a predicate)
78  }
79 
80  bool processUnsubscribePayload(const typename NetworkType::Key &, typename message::FilterInfo::Ptr) {
81  return ""; // from sender, comes that filterinfo (maybe a predicate)
82  }
83 
84  // called by routing strategy:
85  void processRoutingStrategyUnsubscribeNotification(const typename NetworkType::Key) {
86  }
87 
88  bool match(const typename NetworkType::Key &, typename message::FilterInfo::Ptr, PayloadPtr) const {
89  return true; // Given the filterinfo (from getPublishPayload), the message and the recipient decide if he need's that message
90  }
91 
92  // function matching against own dynamic_filters before delivering to application:
93  bool match(PayloadPtr) const {
94  return true;
95  }
96 
97  void setSelf(const typename NetworkType::Key &) {}
98 
99  private:
100  typename FilterInfoType::Ptr cast(typename message::FilterInfo::Ptr ptr) const {
101  typename FilterInfoType::Ptr ret = boost::dynamic_pointer_cast<FilterInfoType>(ptr);
102  if (!ret) {
103  M2ETIS_LOG_ERROR("Filter Strategy", "Downcast error of filterInfo");
104  }
105  return ret;
106  }
107  };
108 
109 } /* namespace filter */
110 } /* namespace pubsub */
111 } /* namespace m2etis */
112 
113 #endif /* __M2ETIS_PUBSUB_FILTER_NULLFILTER_H__ */
114 
std::string getPublishPayload(const PayloadPtr message_text) const
Definition: NullFilter.h:72
boost::shared_ptr< NullFilterInfo< EventType > > Ptr
boost::shared_ptr< EventType > PayloadPtr
Definition: NullFilter.h:42
void setSelf(const typename NetworkType::Key &)
Definition: NullFilter.h:97
void getUnsubscribePayload(typename message::FilterInfo::Ptr filterInfo)
Definition: NullFilter.h:63
message::NullFilterInfo< EventType > FilterInfoType
Definition: NullFilter.h:43
bool match(const typename NetworkType::Key &, typename message::FilterInfo::Ptr, PayloadPtr) const
Definition: NullFilter.h:88
void getSubscribePayload(boost::shared_ptr< FilterExp< EventType >>, bool, typename message::FilterInfo::Ptr)
Definition: NullFilter.h:59
boost::shared_ptr< FilterInfo > Ptr
Definition: FilterInfo.h:35
#define M2ETIS_LOG_ERROR(module, message)
Definition: Logger.h:59
bool processUnsubscribePayload(const typename NetworkType::Key &, typename message::FilterInfo::Ptr)
Definition: NullFilter.h:80
void processRoutingStrategyUnsubscribeNotification(const typename NetworkType::Key)
Definition: NullFilter.h:85
FilterUnsubscribeInformation getUnsubscribePayload(typename message::FilterInfo::Ptr, boost::shared_ptr< FilterExp< EventType >>)
Definition: NullFilter.h:68
std::string processSubscribePayload(const typename NetworkType::Key &, typename message::FilterInfo::Ptr)
Definition: NullFilter.h:76
bool match(PayloadPtr) const
Definition: NullFilter.h:93