Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

MessageSvc.h

Go to the documentation of this file.
00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiSvc/src/MessageSvc/MessageSvc.h,v 1.15 2008/10/21 16:25:55 marcocle Exp $
00002 #ifndef GAUDI_MESSAGESVC_H
00003 #define GAUDI_MESSAGESVC_H
00004 
00005 // Include files
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009 #include <set>
00010 #include <iosfwd>
00011 
00012 #include "GaudiKernel/StatusCode.h"
00013 #include "GaudiKernel/Service.h"
00014 #include "GaudiKernel/IMessageSvc.h"
00015 #include "GaudiKernel/Message.h"
00016 #include "GaudiKernel/Property.h"
00017 
00018 #include <boost/thread/recursive_mutex.hpp>
00019 
00020 // Forward declarations
00021 class ISvcLocator;
00022 
00023 //
00024 // ClassName:   MessageSvc
00025 //
00026 // Description: The MessageSvc service implements the IMessageSvc interface and provides the
00027 //              basic messaging needed by batch oriented applications.
00028 //
00029 // Author:      Iain Last
00030 //
00031 class MessageSvc : public extends1<Service, IMessageSvc> {
00032 public:
00033   typedef std::pair< std::string, std::ostream* > NamedStream;
00034   typedef std::multimap< int, NamedStream > StreamMap;
00035   typedef std::multimap< StatusCode, Message > MessageMap;
00036   typedef std::map< std::string, int > ThresholdMap;
00037 
00038   // Default constructor.
00039   MessageSvc( const std::string& name, ISvcLocator* svcloc );
00040   // Destructor.
00041   virtual ~MessageSvc();
00042 
00043   // Implementation of IService::reinitialize()
00044   virtual StatusCode reinitialize();
00045   // Implementation of IService::initialize()
00046   virtual StatusCode initialize();
00047   // Implementation of IService::finalize()
00048   virtual StatusCode finalize();
00049 
00050   // Implementation of IMessageSvc::reportMessage()
00051   virtual void reportMessage( const Message& message );
00052 
00053   // Implementation of IMessageSvc::reportMessage()
00054   virtual void reportMessage( const Message& msg, int outputLevel );
00055 
00056   // Implementation of IMessageSvc::reportMessage()
00057   virtual void reportMessage( const StatusCode& code, const std::string& source = "");
00058 
00059   // Implementation of IMessageSvc::reportMessage()
00060   virtual void reportMessage( const char* source, int type, const char* message);
00061 
00062   // Implementation of IMessageSvc::reportMessage()
00063   virtual void reportMessage( const std::string& source, int type, const std::string& message);
00064 
00065   // Implementation of IMessageSvc::insertMessage()
00066   virtual void insertMessage( const StatusCode& code, const Message& message );
00067 
00068   // Implementation of IMessageSvc::eraseMessage()
00069   virtual void eraseMessage();
00070 
00071   // Implementation of IMessageSvc::eraseMessage()
00072   virtual void eraseMessage( const StatusCode& code ) ;
00073 
00074   // Implementation of IMessageSvc::eraseMessage()
00075   virtual void eraseMessage( const StatusCode& code, const Message& message );
00076 
00077   // Implementation of IMessageSvc::insertStream()
00078   virtual void insertStream( int message_type, const std::string& name, std::ostream* stream );
00079 
00080   // Implementation of IMessageSvc::eraseStream()
00081   virtual void eraseStream();
00082 
00083   // Implementation of IMessageSvc::eraseStream()
00084   virtual void eraseStream( int message_type );
00085 
00086   // Implementation of IMessageSvc::eraseStream()
00087   virtual void eraseStream( int message_type, std::ostream* stream );
00088 
00089   // Implementation of IMessageSvc::eraseStream()
00090   virtual void eraseStream( std::ostream* stream );
00091 
00092   // Implementation of IMessageSvc::desaultStream()
00093   virtual std::ostream* defaultStream() const {
00094     return m_defaultStream;
00095   }
00096 
00097   // Implementation of IMessageSvc::setDefaultStream()
00098   virtual void setDefaultStream( std::ostream* stream ) {
00099     boost::recursive_mutex::scoped_lock lock(m_reportMutex);
00100     m_defaultStream = stream;
00101   }
00102 
00103   // Implementation of IMessageSvc::ouputLevel()
00104   virtual int outputLevel()   const;
00105 
00106   // Implementation of IMessageSvc::ouputLevel()
00107   virtual int outputLevel(const std::string& source)   const;
00108 
00109   // Implementation of IMessageSvc::setOuputLevel()
00110   virtual void setOutputLevel(int new_level);
00111 
00112   // Implementation of IMessageSvc::setOuputLevel()
00113   virtual void setOutputLevel(const std::string& source, int new_level);
00114 
00115   // Implementation of IMessageSvc::useColor()
00116   virtual bool useColor() const { return m_color; }
00117 
00118   // Implementation of IMessageSvc::getLogColor()
00119   virtual std::string getLogColor(int logLevel) const;
00120 
00121   // Implementation of IMessageSvc::messageCount()
00122   virtual int messageCount( MSG::Level logLevel ) const;
00123 
00124 private:
00125   std::ostream* m_defaultStream;      
00126   Message m_defaultMessage;           
00127   StreamMap m_streamMap;              
00128   MessageMap m_messageMap;            
00129   ThresholdMap m_thresholdMap;        
00130   std::string m_defaultFormat;        
00131   std::string m_defaultTimeFormat;    
00132   StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS]; 
00133   BooleanProperty m_color;
00134   BooleanProperty m_stats;
00135   UnsignedIntegerProperty m_statLevel;
00136   StringArrayProperty m_logColors[MSG::NUM_LEVELS];
00137   IntegerProperty m_msgLimit[MSG::NUM_LEVELS];
00138 
00139   std::string m_logColorCodes[MSG::NUM_LEVELS];
00140 
00141   struct msgAry {
00142     int msg[MSG::NUM_LEVELS];
00143   };
00144   std::map<std::string,msgAry> m_sourceMap;
00145   BooleanProperty m_suppress;
00146 
00147   std::string colTrans(std::string, int);
00148   typedef std::map<std::string, MSG::Color> ColorMap;
00149   ColorMap m_colMap;
00150 
00151   int m_msgCount[MSG::NUM_LEVELS];
00152 
00153   std::map<std::string, std::string> m_loggedStreamsName;
00154   typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
00155   LoggedStreamsMap_t m_loggedStreams;
00156 
00157   void initColors(Property& prop);
00158   void setupColors(Property& prop);
00159   void setupLimits(Property& prop);
00160   void setupThreshold(Property& prop);
00161 
00162   void setupLogStreams();
00163 
00164   void tee( const std::string& sourceName, const std::string& logFileName,
00165             const std::set<std::string>& declaredOutFileNames );
00166 
00168   mutable boost::recursive_mutex m_reportMutex;
00169 
00171   mutable boost::recursive_mutex m_messageMapMutex;
00172 
00175   mutable boost::recursive_mutex m_thresholdMapMutex;
00176 };
00177 
00178 #endif

Generated at Mon Sep 7 18:05:50 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004