platform/reactors/LogOutputReactor.hpp

00001 // ------------------------------------------------------------------------
00002 // Pion is a development platform for building Reactors that process Events
00003 // ------------------------------------------------------------------------
00004 // Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
00005 //
00006 // Pion is free software: you can redistribute it and/or modify it under the
00007 // terms of the GNU Affero General Public License as published by the Free
00008 // Software Foundation, either version 3 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Pion is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Affero General Public License
00017 // along with Pion.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef __PION_LOGOUTPUTREACTOR_HEADER__
00021 #define __PION_LOGOUTPUTREACTOR_HEADER__
00022 
00023 #include <string>
00024 #include <fstream>
00025 #include <pion/PionConfig.hpp>
00026 #include <pion/PionLogger.hpp>
00027 #include <pion/PionException.hpp>
00028 #include <pion/platform/Codec.hpp>
00029 #include <pion/platform/Reactor.hpp>
00030 
00031 
00032 namespace pion {        // begin namespace pion
00033 namespace plugins {     // begin namespace plugins
00034 
00035 
00039 class LogOutputReactor :
00040     public pion::platform::Reactor
00041 {
00042 public:
00043 
00045     class EmptyCodecException : public PionException {
00046     public:
00047         EmptyCodecException(const std::string& reactor_id)
00048             : PionException("LogOutputReactor configuration is missing a required Codec parameter: ", reactor_id) {}
00049     };
00050     
00052     class EmptyFilenameException : public PionException {
00053     public:
00054         EmptyFilenameException(const std::string& reactor_id)
00055             : PionException("LogOutputReactor configuration is missing a required Filename parameter: ", reactor_id) {}
00056     };
00057     
00059     class OpenLogException : public PionException {
00060     public:
00061         OpenLogException(const std::string& log_filename)
00062             : PionException("Unable to open log file for writing: ", log_filename) {}
00063     };
00064     
00066     class WriteToLogException : public PionException {
00067     public:
00068         WriteToLogException(const std::string& log_filename)
00069             : PionException("Unable to write Event to log file: ", log_filename) {}
00070     };
00071 
00073     class LogRotationException : public PionException {
00074     public:
00075         LogRotationException(const std::string& log_filename)
00076             : PionException("Unable to rotate log file: ", log_filename) {}
00077     };
00078 
00079 
00081     LogOutputReactor(void)
00082         : Reactor(TYPE_STORAGE),
00083         m_logger(PION_GET_LOGGER("pion.LogOutputReactor"))
00084     {}
00085     
00087     virtual ~LogOutputReactor() { stop(); }
00088     
00096     virtual void setConfig(const pion::platform::Vocabulary& v, const xmlNodePtr config_ptr);
00097     
00104     virtual void updateVocabulary(const pion::platform::Vocabulary& v);
00105     
00110     virtual void updateCodecs(void);
00111     
00117     virtual void process(const pion::platform::EventPtr& e);
00118     
00126     virtual void query(std::ostream& out, const QueryBranches& branches,
00127         const QueryParams& qp);
00128     
00130     virtual void start(void);
00131     
00133     virtual void stop(void);
00134 
00136     inline void setLogger(PionLogger log_ptr) { m_logger = log_ptr; }
00137     
00139     inline PionLogger getLogger(void) { return m_logger; }
00140     
00141     
00142 private:
00143 
00145     void openLogFileNoLock(void);
00146 
00148     void closeLogFileNoLock(void);
00149 
00151     static const std::string            CODEC_ELEMENT_NAME;
00152     
00154     static const std::string            FILENAME_ELEMENT_NAME;
00155     
00156     
00158     PionLogger                          m_logger;
00159     
00161     std::string                         m_codec_id;
00162     
00164     pion::platform::CodecPtr            m_codec_ptr;
00165     
00167     std::string                         m_log_filename;
00168     
00170     std::ofstream                       m_log_stream;
00171 
00173     boost::mutex                        m_log_writer_mutex;
00174 };
00175 
00176 
00177 }   // end namespace plugins
00178 }   // end namespace pion
00179 
00180 #endif

Generated on Wed Apr 13 16:38:34 2011 for pion-platform by  doxygen 1.4.7