X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FLogger%2FDefinitions.ih;fp=senf%2FUtils%2FLogger%2FDefinitions.ih;h=b22229389adfde109aafe5edf9f5717c1f23727b;hb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;hp=0000000000000000000000000000000000000000;hpb=164fe477094d42463722584e527a02379ab5d985;p=senf.git diff --git a/senf/Utils/Logger/Definitions.ih b/senf/Utils/Logger/Definitions.ih new file mode 100644 index 0000000..b222293 --- /dev/null +++ b/senf/Utils/Logger/Definitions.ih @@ -0,0 +1,101 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Definitions internal header */ + +#ifndef IH_SENF_Utils_Logger_Definitions_ +#define IH_SENF_Utils_Logger_Definitions_ 1 + +// Custom includes + +///////////////////////////////ih.p//////////////////////////////////////// + +// Implementation details concerning SENF_LOG_CLASS_AREA +// +// The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of +// course, we cannot make the containing class into an area. Therefor we need to trick around a bit: +// +// We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that +// it's name() member will return the name of the containing class (which is simple: just cut of the +// last couple of characters of the name since the name will always end in '::SENFLogArea'). +// +// This however does not allow the use of the containing class as an area. There are several places +// which need to be adjusted to allow using the containing class as an area: The logging statements +// (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via +// route statements. +// +// Lets begin with the compile time configuration. The compile time configuration is done using +// specialization of the senf::log::detail::Config template. This doesn't care, what the area +// template argument really is. Therefore, compile-time configuration just uses the containing class +// as is. So we need to make sure, that the logging statements use the containing class when +// checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the +// targets. +// +// So let's look at the logging statements. The central logic for parsing the logging parameters is +// in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes +// with a SENFLogArea member and then set's things up correctly: It uses the containing class for +// compile time checking (this is, what 'area_base' typedef is for) while using the nested +// SENFLogArea for routing (this is, what the 'area' typedef is for). +// +// So the last thing which needs to be adjusted is the routing which is part of the Target +// class. Here for each template taking an area as an argument we really provide TWO templates, one +// taking the area directly, the other checking for a nested SENFLogArea member. We can +// differentiate these overloads using boost::enable_if and friends. +// +// This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the +// implementation is somewhat different. + +#define SENF_LOG_DEFINE_AREA_I(area, decls) \ + struct area \ + : public senf::log::detail::AreaBase, public senf::singleton \ + { \ + static std::string name() { return instance().v_name(); } \ + using senf::singleton::instance; \ + decls \ + private: \ + area() { init(); } \ + friend class senf::singleton; \ + } + +namespace senf { +namespace log { +namespace detail { + + /// Internal: Alias base class + struct AliasBase {}; + +}}} + +///////////////////////////////ih.e//////////////////////////////////////// +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: