switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / AreaRegistry.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief AreaRegistry non-inline non-template implementation */
30
31 #include "AreaRegistry.hh"
32 #include "AreaRegistry.ih"
33
34 // Custom includes
35 #include "Target.hh"
36
37 //#include "AreaRegistry.mpp"
38 #define prefix_
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // senf::log::detail::AreaBase
43
44 prefix_ senf::log::detail::AreaBase::AreaBase()
45     : alive_ (true)
46 {}
47
48 prefix_ senf::log::detail::AreaBase::~AreaBase()
49 {
50     alive_ = false;
51 }
52
53 prefix_ void senf::log::detail::AreaBase::updateRoutingCache(Target & target,
54                                                              StreamBase const & stream,
55                                                              unsigned limit)
56     const
57 {
58     if (stream.index >= routingCache_.size())
59         routingCache_.resize(stream.index+1);
60     unsigned l (limit);
61     Routes::iterator i (routingCache_[stream.index].routes.begin());
62     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
63     for (; i != i_end; ++i) {
64         if (i->target == &target) {
65             i->limit = limit;
66             break;
67         }
68         if (i->limit < l)
69             l = i->limit;
70     }
71     if (i == i_end)
72         routingCache_[stream.index].routes.push_back(RouteEntry(limit, &target));
73     else
74         for (; i != i_end; ++i)
75             if (i->limit < l)
76                 l = i->limit;
77     routingCache_[stream.index].limit = l;
78 }
79
80 prefix_ void senf::log::detail::AreaBase::removeRoutingCache(Target & target,
81                                                              StreamBase const & stream)
82     const
83 {
84     if (stream.index >= routingCache_.size())
85         return;
86     unsigned l (DISABLED::value);
87     Routes::iterator i (routingCache_[stream.index].routes.begin());
88     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
89     while (i != i_end) {
90         if (i->target == &target)
91             i = routingCache_[stream.index].routes.erase(i);
92         else {
93             if (i->limit < l)
94                 l = i->limit;
95             ++i;
96         }
97     }
98     routingCache_[stream.index].limit = l;
99 }
100
101 prefix_ void senf::log::detail::AreaBase::write(time_type timestamp,
102                                                 StreamBase const & stream, unsigned level,
103                                                 std::string const & msg)
104     const
105 {
106     if (stream.index >= routingCache_.size())
107         return;
108     Routes::iterator i (routingCache_[stream.index].routes.begin());
109     Routes::iterator const i_end (routingCache_[stream.index].routes.end());
110     for (; i != i_end; ++i)
111         i->target->write(timestamp, stream, *this, level, msg);
112 }
113
114 //-/////////////////////////////////////////////////////////////////////////////////////////////////
115 #undef prefix_
116 //#include "AreaRegistry.mpp"
117
118 \f
119 // Local Variables:
120 // mode: c++
121 // fill-column: 100
122 // comment-column: 40
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // End: