Gaudi Framework, version v20r2

Generated: 18 Jul 2008

MessageSvc.h

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

Generated at Fri Jul 18 11:59:25 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004