Apache Mesos
filter.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __PROCESS_FILTER_HPP__
14 #define __PROCESS_FILTER_HPP__
15 
16 #include <process/event.hpp>
17 
18 namespace process {
19 
20 class Filter {
21 public:
22  virtual ~Filter() {}
23  virtual bool filter(const MessageEvent&) { return false; }
24  virtual bool filter(const DispatchEvent&) { return false; }
25  virtual bool filter(const HttpEvent&) { return false; }
26  virtual bool filter(const ExitedEvent&) { return false; }
27 
28  virtual bool filter(Event* event)
29  {
30  bool result = false;
31  struct FilterVisitor : EventVisitor
32  {
33  explicit FilterVisitor(Filter* _filter, bool* _result)
34  : filter(_filter), result(_result) {}
35 
36  virtual void visit(const MessageEvent& event)
37  {
38  *result = filter->filter(event);
39  }
40 
41  virtual void visit(const DispatchEvent& event)
42  {
43  *result = filter->filter(event);
44  }
45 
46  virtual void visit(const HttpEvent& event)
47  {
48  *result = filter->filter(event);
49  }
50 
51  virtual void visit(const ExitedEvent& event)
52  {
53  *result = filter->filter(event);
54  }
55 
56  Filter* filter;
57  bool* result;
58  } visitor(this, &result);
59 
60  event->visit(&visitor);
61 
62  return result;
63  }
64 };
65 
66 
67 // Use the specified filter on messages that get enqueued (note,
68 // however, that you cannot filter timeout messages).
69 void filter(Filter* filter);
70 
71 } // namespace process {
72 
73 #endif // __PROCESS_FILTER_HPP__
Definition: filter.hpp:20
Definition: event.hpp:142
Definition: event.hpp:178
Definition: event.hpp:214
virtual bool filter(const HttpEvent &)
Definition: filter.hpp:25
virtual ~Filter()
Definition: filter.hpp:22
virtual bool filter(Event *event)
Definition: filter.hpp:28
virtual bool filter(const MessageEvent &)
Definition: filter.hpp:23
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: event.hpp:38
Definition: event.hpp:103
virtual bool filter(const DispatchEvent &)
Definition: filter.hpp:24
virtual bool filter(const ExitedEvent &)
Definition: filter.hpp:26
Definition: event.hpp:60
void filter(Filter *filter)