metaproxy  1.21.0
router_chain.cpp
Go to the documentation of this file.
1 /* This file is part of Metaproxy.
2  Copyright (C) Index Data
3 
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <metaproxy/router_chain.hpp>
20 #include <metaproxy/filter.hpp>
21 
22 #include <list>
23 
24 namespace mp = metaproxy_1;
25 
26 namespace metaproxy_1
27 {
28  class ChainPos;
29 
31  friend class RouterChain;
32  friend class RouterChain::Pos;
33  std::list<const filter::Base *> m_filter_list;
34  };
35  class RouterChain::Pos : public RoutePos {
36  public:
37  virtual const filter::Base *move(const char *route);
38  virtual RoutePos *clone();
39  virtual ~Pos();
40  std::list<const filter::Base *>::const_iterator it;
41  mp::RouterChain::Rep *m_p;
42  };
43 }
44 
45 mp::RouterChain::RouterChain() : m_p(new mp::RouterChain::Rep)
46 {
47 }
48 
49 mp::RouterChain::~RouterChain()
50 {
51 }
52 
53 void mp::RouterChain::start()
54 {
55  std::list<const filter::Base *>::const_iterator it;
56 
57  for (it = m_p->m_filter_list.begin(); it != m_p->m_filter_list.end(); it++)
58  (*it)->start();
59 }
60 
61 void mp::RouterChain::stop(int signo)
62 {
63  std::list<const filter::Base *>::const_iterator it;
64 
65  for (it = m_p->m_filter_list.begin(); it != m_p->m_filter_list.end(); it++)
66  (*it)->stop(signo);
67 }
68 
69 const mp::filter::Base *mp::RouterChain::Pos::move(const char *route)
70 {
71  if (it == m_p->m_filter_list.end())
72  return 0;
73  const mp::filter::Base *f = *it;
74  it++;
75  return f;
76 }
77 
78 mp::RoutePos *mp::RouterChain::createpos() const
79 {
80  mp::RouterChain::Pos *p = new mp::RouterChain::Pos;
81  p->it = m_p->m_filter_list.begin();
82  p->m_p = m_p.get();
83  return p;
84 }
85 
86 mp::RoutePos *mp::RouterChain::Pos::clone()
87 {
88  mp::RouterChain::Pos *p = new mp::RouterChain::Pos;
89  p->it = it;
90  p->m_p = m_p;
91  return p;
92 }
93 
94 mp::RouterChain::Pos::~Pos()
95 {
96 }
97 
98 mp::RouterChain & mp::RouterChain::append(const filter::Base &filter)
99 {
100  m_p->m_filter_list.push_back(&filter);
101  return *this;
102 }
103 
104 
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * c-file-style: "Stroustrup"
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113 
std::list< const filter::Base * >::const_iterator it
mp::RouterChain::Rep * m_p
virtual RoutePos * clone()
virtual const filter::Base * move(const char *route)
std::list< const filter::Base * > m_filter_list