Packets: Fix VariantParser invalid parser access bug
[senf.git] / Utils / Logger / AreaRegistry.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief AreaRegistry non-inline non-template implementation */
25
26 #include "AreaRegistry.hh"
27 #include "AreaRegistry.ih"
28
29 // Custom includes
30 #include "Target.hh"
31
32 //#include "AreaRegistry.mpp"
33 #define prefix_
34 ///////////////////////////////cc.p////////////////////////////////////////
35
36 ///////////////////////////////////////////////////////////////////////////
37 // senf::log::detail::AreaBase
38
39 prefix_ senf::log::detail::AreaBase::~AreaBase()
40 {}
41
42 prefix_ void senf::log::detail::AreaBase::updateRoutingCache(Target & target,
43                                                              StreamBase const & stream,
44                                                              unsigned limit)
45     const
46 {
47     if (stream.index >= routingCache_.size())
48         routingCache_.resize(stream.index+1);
49     unsigned l (limit);
50     Routes::iterator i (routingCache_[stream.index].routes.begin());
51     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
52     for (; i != i_end; ++i) {
53         if (i->target == &target) {
54             i->limit = limit;
55             break;
56         }
57         if (i->limit < l)
58             l = i->limit;
59     }
60     if (i == i_end) 
61         routingCache_[stream.index].routes.push_back(RouteEntry(limit, &target));
62     else
63         for (; i != i_end; ++i)
64             if (i->limit < l)
65                 l = i->limit;
66     routingCache_[stream.index].limit = l;
67 }
68
69 prefix_ void senf::log::detail::AreaBase::removeRoutingCache(Target & target,
70                                                              StreamBase const & stream)
71     const
72 {
73     if (stream.index >= routingCache_.size())
74         return;
75     unsigned l (DISABLED::value);
76     Routes::iterator i (routingCache_[stream.index].routes.begin());
77     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
78     while (i != i_end) {
79         if (i->target == &target)
80             i = routingCache_[stream.index].routes.erase(i);
81         else {
82             if (i->limit < l)
83                 l = i->limit;
84             ++i;
85         }
86     }
87     routingCache_[stream.index].limit = l;
88 }
89
90 prefix_ void senf::log::detail::AreaBase::write(time_type timestamp,
91                                                 StreamBase const & stream, unsigned level,
92                                                 std::string msg)
93     const
94 {
95     if (stream.index >= routingCache_.size())
96         return;
97     Routes::iterator i (routingCache_[stream.index].routes.begin());
98     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
99     for (; i != i_end; ++i)
100         i->target->write(timestamp, stream, *this, level, msg);
101 }
102
103 ///////////////////////////////cc.e////////////////////////////////////////
104 #undef prefix_
105 //#include "AreaRegistry.mpp"
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // fill-column: 100
111 // comment-column: 40
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // End: