IBR-DTN  1.0.0
BundleFilterTable.cpp
Go to the documentation of this file.
1 /*
2  * BundleFilterTable.cpp
3  *
4  * Copyright (C) 2014 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <jm@m-network.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "core/BundleFilterTable.h"
23 
24 namespace dtn
25 {
26  namespace core
27  {
29  {
30  }
31 
33  {
34  // clean-up filter in chain
35  for (chain::const_iterator it = _chain.begin(); it != _chain.end(); ++it)
36  {
37  delete (*it);
38  }
39  }
40 
42  {
43  _chain.push_back(filter);
44  }
45 
46  void BundleFilterTable::insert(unsigned int position, BundleFilter *filter)
47  {
48  chain::iterator it = _chain.begin();
49 
50  // move iterator to the right position
51  for (unsigned int i = 0; i < position && it != _chain.end(); ++it, ++i);
52 
53  // insert before the position
54  _chain.insert(it, filter);
55  }
56 
58  {
59  // clean-up filter in chain
60  for (chain::const_iterator it = _chain.begin(); it != _chain.end(); ++it)
61  {
62  delete (*it);
63  }
64  _chain.clear();
65  }
66 
68  {
69  for (chain::const_iterator it = _chain.begin(); it != _chain.end(); ++it)
70  {
71  const BundleFilter &f = (**it);
72  const BundleFilter::ACTION ret = f.evaluate(context);
73  if (ret != BundleFilter::PASS && ret != BundleFilter::SKIP) return ret;
74  }
75  return ACCEPT;
76  }
77 
79  {
80  for (chain::const_iterator it = _chain.begin(); it != _chain.end(); ++it)
81  {
82  const BundleFilter &f = (**it);
83  const BundleFilter::ACTION ret = f.filter(context, bundle);
84  if (ret != BundleFilter::PASS && ret != BundleFilter::SKIP) return ret;
85  }
86  return ACCEPT;
87  }
88  } /* namespace core */
89 } /* namespace dtn */
virtual ACTION evaluate(const FilterContext &context) const
virtual ACTION evaluate(const FilterContext &context) const
virtual ACTION filter(const FilterContext &context, dtn::data::Bundle &bundle) const
void append(BundleFilter *filter)
virtual ACTION filter(const FilterContext &context, dtn::data::Bundle &bundle) const
void insert(unsigned int position, BundleFilter *filter)