4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Target internal header */
31 #ifndef IH_SENF_Utils_Logger_Target_
32 #define IH_SENF_Utils_Logger_Target_ 1
37 #include <boost/type_traits/is_same.hpp>
38 #include <boost/static_assert.hpp>
39 #include <boost/shared_ptr.hpp>
40 #include <senf/Utils/singleton.hh>
41 #include <senf/Utils/mpl.hh>
42 #include <senf/Utils/Console/LazyDirectory.hh>
43 #include <senf/Utils/Console/Parse.hh>
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 namespace console { class DirectoryNode; }
54 struct LogParameters {
55 StreamBase const * stream;
56 AreaBase const * area;
60 static LogParameters defaultParameters();
63 std::ostream & operator<<(std::ostream & os, LogParameters const & pm);
65 void senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & tokens,
68 /** \brief Internal: Target registry */
70 : public senf::singleton<TargetRegistry>
74 VERBOSE = senf::log::VERBOSE::value,
75 NOTICE = senf::log::NOTICE::value,
76 MESSAGE = senf::log::MESSAGE::value,
77 IMPORTANT = senf::log::IMPORTANT::value,
78 CRITICAL = senf::log::CRITICAL::value,
79 FATAL = senf::log::FATAL::value
82 using senf::singleton<TargetRegistry>::instance;
84 void write(StreamBase const & stream, AreaBase const & area, unsigned level,
85 std::string const & msg);
88 bool fallbackRouting();
90 senf::console::ScopedDirectory<> & consoleDir();
92 void dynamicTarget(std::auto_ptr<Target> target);
98 void registerTarget(Target * target, std::string const & name);
99 void unregisterTarget(Target * target);
101 void consoleAreas(std::ostream & os);
102 void consoleStreams(std::ostream & os);
103 void consoleWrite(LogParameters parameters, std::string const & msg);
104 void consoleRemoveTarget(Target * target);
105 boost::shared_ptr<senf::console::DirectoryNode> consoleSelf(std::ostream & os);
107 typedef std::set<Target *> Targets;
110 bool fallbackRouting_;
112 console::LazyDirectory consoleDir_;
114 Targets dynamicTargets_;
116 friend class senf::log::Target;
117 friend class senf::singleton<TargetRegistry>;
120 /** \brief Internal: Write log message */
121 template <class Stream, class Area, class Level>
122 void write(std::string const & msg);
126 // This code takes the routing target template arguments in any order and sorts them
127 // by type (Stream, Area and Level).
129 senf::mpl::rv<0u> RouteParameterCheck_(...);
130 senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
131 senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
132 template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
133 senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
135 // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
136 // no idea why. It works without the scope in 4.1
137 template < class T, class A2, class A1,
138 unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
139 struct RouteParameters
142 template <class A2, class A1>
143 struct RouteParameters<mpl::nil,A2,A1,0u>
144 : public RouteParameters<A2,A1,mpl::nil>
148 static unsigned const value = NONE::value;
152 struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
154 typedef mpl::nil Stream;
155 typedef mpl::nil Area;
156 typedef NilLevel Level;
159 template <class T, class A2, class A1>
160 struct RouteParameters<T,A2,A1,1u>
161 : public RouteParameters<A2,A1,mpl::nil>
163 typedef RouteParameters<A2,A1,mpl::nil> base;
164 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
168 template <class T, class A2, class A1>
169 struct RouteParameters<T,A2,A1,2u>
170 : public RouteParameters<A2,A1,mpl::nil>
172 typedef RouteParameters<A2,A1,mpl::nil> base;
173 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
177 template <class T, class A2, class A1>
178 struct RouteParameters<T,A2,A1,3u>
179 : public RouteParameters<A2,A1,mpl::nil>
181 typedef RouteParameters<A2,A1,mpl::nil> base;
182 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
183 typedef typename T::SENFLogArea Area;
186 template <class T, class A2, class A1>
187 struct RouteParameters<T,A2,A1,4u>
188 : public RouteParameters<A2,A1,mpl::nil>
190 typedef RouteParameters<A2,A1,mpl::nil> base;
191 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
195 template <class T, class RV>
198 static RV * value() { return & T::instance(); }
202 struct InstanceP<mpl::nil, RV>
204 static RV * value() { return 0; }
211 //-/////////////////////////////////////////////////////////////////////////////////////////////////
218 // comment-column: 40
219 // c-file-style: "senf"
220 // indent-tabs-mode: nil
221 // ispell-local-dictionary: "american"
222 // compile-command: "scons -u test"