4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Target internal header */
26 #ifndef IH_SENF_Utils_Logger_Target_
27 #define IH_SENF_Utils_Logger_Target_ 1
31 #include <boost/type_traits/is_same.hpp>
32 #include <boost/static_assert.hpp>
33 #include "../Console/LazyDirectory.hh"
35 ///////////////////////////////ih.p////////////////////////////////////////
41 /** \brief Internal: Target registry */
43 : public senf::singleton<TargetRegistry>
46 using senf::singleton<TargetRegistry>::instance;
48 void write(StreamBase const & stream, AreaBase const & area, unsigned level,
49 std::string const & msg);
52 bool fallbackRouting();
57 void registerTarget(Target * target, std::string const & name);
58 void unregisterTarget(Target * target);
60 typedef std::set<Target *> Targets;
63 bool fallbackRouting_;
65 console::LazyDirectory consoleDir_;
67 friend class senf::log::Target;
68 friend class senf::singleton<TargetRegistry>;
71 /** \brief Internal: Write log message */
72 template <class Stream, class Area, class Level>
73 void write(std::string const & msg);
77 // This code takes the routing target template arguments in any order and sorts them
78 // by type (Stream, Area and Level).
80 senf::mpl::rv<0u> RouteParameterCheck_(...);
81 senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
82 senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
83 template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
84 senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
86 // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
87 // no idea why. It works without the scope in 4.1
88 template < class T, class A2, class A1,
89 unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
90 struct RouteParameters
93 template <class A2, class A1>
94 struct RouteParameters<mpl::nil,A2,A1,0u>
95 : public RouteParameters<A2,A1,mpl::nil>
99 static unsigned const value = NONE::value;
103 struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
105 typedef mpl::nil Stream;
106 typedef mpl::nil Area;
107 typedef NilLevel Level;
110 template <class T, class A2, class A1>
111 struct RouteParameters<T,A2,A1,1u>
112 : public RouteParameters<A2,A1,mpl::nil>
114 typedef RouteParameters<A2,A1,mpl::nil> base;
115 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
119 template <class T, class A2, class A1>
120 struct RouteParameters<T,A2,A1,2u>
121 : public RouteParameters<A2,A1,mpl::nil>
123 typedef RouteParameters<A2,A1,mpl::nil> base;
124 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
128 template <class T, class A2, class A1>
129 struct RouteParameters<T,A2,A1,3u>
130 : public RouteParameters<A2,A1,mpl::nil>
132 typedef RouteParameters<A2,A1,mpl::nil> base;
133 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
134 typedef typename T::SENFLogArea Area;
137 template <class T, class A2, class A1>
138 struct RouteParameters<T,A2,A1,4u>
139 : public RouteParameters<A2,A1,mpl::nil>
141 typedef RouteParameters<A2,A1,mpl::nil> base;
142 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
146 template <class T, class RV>
149 static RV * value() { return & T::instance(); }
153 struct InstanceP<mpl::nil, RV>
155 static RV * value() { return 0; }
162 ///////////////////////////////ih.e////////////////////////////////////////
169 // comment-column: 40
170 // c-file-style: "senf"
171 // indent-tabs-mode: nil
172 // ispell-local-dictionary: "american"
173 // compile-command: "scons -u test"