platform/reactors/FissionReactor.hpp

00001 // ------------------------------------------------------------------------
00002 // Pion is a development platform for building Reactors that process Events
00003 // ------------------------------------------------------------------------
00004 // Copyright (C) 2007-2009 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_FISSIONREACTOR_HEADER__
00021 #define __PION_FISSIONREACTOR_HEADER__
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <boost/thread/mutex.hpp>
00026 #include <pion/PionConfig.hpp>
00027 #include <pion/PionException.hpp>
00028 #include <pion/platform/Codec.hpp>
00029 #include <pion/platform/Reactor.hpp>
00030 #include <pion/platform/Vocabulary.hpp>
00031 
00032 
00033 namespace pion {        // begin namespace pion
00034 namespace plugins {     // begin namespace plugins
00035 
00036 
00040 class FissionReactor :
00041     public pion::platform::Reactor
00042 {
00043 public: 
00044     
00046     class UnknownTermException : public PionException {
00047     public:
00048         UnknownTermException(const std::string& term_id)
00049             : PionException("FissionReactor configuration references an unknown term: ", term_id) {}
00050     };
00051 
00053     class NotAnObjectException : public PionException {
00054     public:
00055         NotAnObjectException(const std::string& event_type)
00056             : PionException("FissionReactor configuration defines a non-object input event type: ", event_type) {}
00057     };
00058 
00060     class TermNotStringException : public PionException {
00061     public:
00062         TermNotStringException(const std::string& term_id)
00063             : PionException("FissionReactor non-string input event term specified: ", term_id) {}
00064     };
00065 
00067     class EmptyCodecException : public PionException {
00068     public:
00069         EmptyCodecException(const std::string& reactor_id)
00070             : PionException("FissionReactor configuration is missing a required Codec parameter: ", reactor_id) {}
00071     };
00072 
00074     class EmptyInputEventTypeException : public PionException {
00075     public:
00076         EmptyInputEventTypeException(const std::string& reactor_id)
00077             : PionException("FissionReactor configuration is missing a required InputEventType parameter: ", reactor_id) {}
00078     };
00079 
00081     class EmptyInputEventTermException : public PionException {
00082     public:
00083         EmptyInputEventTermException(const std::string& reactor_id)
00084             : PionException("FissionReactor configuration is missing a required InputEventTerm parameter: ", reactor_id) {}
00085     };
00086 
00087 
00089     FissionReactor(void)
00090         : Reactor(TYPE_PROCESSING), m_copy_all_terms(false),
00091         m_input_event_type(""), m_input_event_term("")
00092     {}
00093     
00095     virtual ~FissionReactor() { stop(); }
00096     
00104     virtual void setConfig(const pion::platform::Vocabulary& v, const xmlNodePtr config_ptr);
00105     
00112     virtual void updateVocabulary(const pion::platform::Vocabulary& v);
00113 
00118     virtual void updateCodecs(void);
00119 
00129     virtual void process(const pion::platform::EventPtr& e);
00130     
00131     
00132 private:
00133 
00135     typedef std::vector<pion::platform::Vocabulary::Term>   TermVector;
00136 
00137 
00139     static const std::string            COPY_TERM_ELEMENT_NAME;
00140 
00142     static const std::string            COPY_ALL_TERMS_ELEMENT_NAME;
00143 
00145     static const std::string            INPUT_EVENT_TYPE_ELEMENT_NAME;
00146 
00148     static const std::string            INPUT_EVENT_TERM_ELEMENT_NAME;
00149 
00151     static const std::string            CODEC_ELEMENT_NAME;
00152 
00153 
00155     bool                                m_copy_all_terms;
00156 
00158     TermVector                          m_copy_terms;
00159 
00161     pion::platform::Vocabulary::Term    m_input_event_type;
00162 
00164     pion::platform::Vocabulary::Term    m_input_event_term;
00165 
00167     pion::platform::CodecPtr            m_codec_ptr;
00168 
00170     std::string                         m_codec_id;
00171 
00173     boost::mutex                        m_codec_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