Utils/Logger: Complete route caching
[senf.git] / Utils / Logger / Target.cci
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 Target inline non-template implementation */
25
26 //#include "Target.ih"
27
28 // Custom includes
29 #include <algorithm>
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::log::Target
36
37 prefix_ void senf::log::Target::route(std::string const & stream, action_t action)
38 {
39     detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
40     if (!s)
41         throw InvalidStreamException();
42     route(s, 0, NONE::value, action);
43 }
44
45 prefix_ void senf::log::Target::route(std::string const & stream, std::string const & area,
46                                       action_t action)
47 {
48     detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
49     if (!s)
50         throw InvalidStreamException();
51     detail::AreaBase const * a (AreaRegistry::instance().lookup(area));
52     if (!a)
53         throw InvalidAreaException();
54     route(s, a, NONE::value, action);
55 }
56
57 prefix_ void senf::log::Target::route(std::string const & stream, unsigned level, action_t action)
58 {
59     detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
60     if (!s)
61         throw InvalidStreamException();
62     route(s, 0, level, action);
63 }
64
65 prefix_ void senf::log::Target::route(std::string const & stream, std::string const & area,
66                                       unsigned level, action_t action)
67 {
68     detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
69     if (!s)
70         throw InvalidStreamException();
71     detail::AreaBase const * a (AreaRegistry::instance().lookup(area));
72     if (!a)
73         throw InvalidAreaException();
74     route(s, a, level, action);
75 }
76
77 ////////////////////////////////////////
78 // private members
79
80 prefix_ void senf::log::Target::route(detail::StreamBase const * stream,
81                                       detail::AreaBase const * area, unsigned level,
82                                       action_t action)
83 {
84     rib_.push_back(RoutingEntry(stream, area, level, action));
85     if (action == ACCEPT)
86         updateRoutingCache(stream, area);
87 }
88
89 prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream,
90                                         detail::AreaBase const * area, unsigned level, 
91                                         action_t action)
92 {
93     rib_.erase(std::remove(rib_.begin(), rib_.end(), RoutingEntry(stream, area, level, action)),
94                rib_.end());
95     if (action == ACCEPT)
96         updateRoutingCache(stream, area);
97 }
98
99 ///////////////////////////////////////////////////////////////////////////
100 // senf::log::Target::RoutingEntry
101
102 prefix_ senf::log::Target::RoutingEntry::RoutingEntry(detail::StreamBase const * stream_,
103                                                       detail::AreaBase const * area_,
104                                                       unsigned level_, action_t action_)
105     : stream(stream_), area(area_), level(level_), action(action_) 
106 {}
107
108 prefix_ senf::log::Target::RoutingEntry::RoutingEntry()
109     : stream(0), area(0), level(0), action(ACCEPT) 
110 {}
111
112 prefix_ bool senf::log::Target::RoutingEntry::operator==(RoutingEntry const & other)
113
114     return 
115         stream == other.stream && 
116         area == other.area && 
117         level == other.level &&
118         action == other.action; 
119 }
120
121 ///////////////////////////////////////////////////////////////////////////
122 // senf::log::TargetRegistry
123
124 prefix_ void senf::log::TargetRegistry::registerTarget(Target * target)
125 {
126     targets_.insert(target);
127 }
128
129 prefix_ void senf::log::TargetRegistry::unregisterTarget(Target * target)
130 {
131     targets_.erase(target);
132 }
133
134 /////////////////////////////cci.e///////////////////////////////////////
135 #undef prefix_
136
137 \f
138 // Local Variables:
139 // mode: c++
140 // fill-column: 100
141 // comment-column: 40
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // End: