platform/reactors/TransformReactor.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_TRANSFORMREACTOR_HEADER__
00021 #define __PION_TRANSFORMREACTOR_HEADER__
00022 
00023 #include <vector>
00024 #include <pion/PionConfig.hpp>
00025 #include <pion/PionException.hpp>
00026 #include <pion/platform/Reactor.hpp>
00027 #include <pion/platform/Comparison.hpp>
00028 #include <pion/platform/Transform.hpp>
00029 
00030 
00031 namespace pion {        // begin namespace pion
00032 namespace plugins {     // begin namespace plugins
00033 
00034 
00039 class TransformReactor :
00040     public pion::platform::Reactor
00041 {
00042 public:
00043 
00045     class InvalidTransformation : public PionException {
00046     public:
00047         InvalidTransformation(const std::string& type_str)
00048             : PionException("Invalid type of transformation: ", type_str) {}
00049     };
00050 
00052     class EmptyTermException : public PionException {
00053     public:
00054         EmptyTermException(const std::string& reactor_id)
00055             : PionException("TransformReactor configuration is missing a term identifier: ", reactor_id) {}
00056     };
00057 
00059     class UnknownTermException : public PionException {
00060     public:
00061         UnknownTermException(const std::string& reactor_id)
00062             : PionException("TransformReactor configuration maps field to an unknown term: ", reactor_id) {}
00063     };
00064 
00066     class EmptyTypeException : public PionException {
00067     public:
00068         EmptyTypeException(const std::string& reactor_id)
00069             : PionException("TransformReactor configuration does not include a comparison type: ", reactor_id) {}
00070     };
00071 
00073     class EmptyValueException : public PionException {
00074     public:
00075         EmptyValueException(const std::string& reactor_id)
00076             : PionException("TransformReactor configuration is missing a required comparison value: ", reactor_id) {}
00077     };
00078 
00080     class EmptyTransformationException : public PionException {
00081     public:
00082         EmptyTransformationException(const std::string& reactor_id)
00083             : PionException("TransformReactor configuration is missing the set value: ", reactor_id) {}
00084     };
00085 
00087     class EmptySetTermException : public PionException {
00088     public:
00089         EmptySetTermException(const std::string& reactor_id)
00090             : PionException("TransformReactor configuration is missing the set term identifier: ", reactor_id) {}
00091     };
00092 
00094     class TransformFailureException : public PionException {
00095     public:
00096         TransformFailureException(const std::string& reactor_id)
00097             : PionException("Transformation failed: ", reactor_id) {}
00098     };
00099 
00101     TransformReactor(void) :
00102         Reactor(TYPE_PROCESSING),
00103         m_event_type(pion::platform::Vocabulary::UNDEFINED_TERM_REF)
00104     {}
00105 
00107     virtual ~TransformReactor() {
00108             stop();
00109             for (TransformChain::iterator i = m_transforms.begin(); i != m_transforms.end(); ++i)
00110                 delete (*i);
00111     }
00112 
00120     virtual void setConfig(const pion::platform::Vocabulary& v, const xmlNodePtr config_ptr);
00121 
00128     virtual void updateVocabulary(const pion::platform::Vocabulary& v);
00129 
00136     virtual void process(const pion::platform::EventPtr& e);
00137 
00138 
00139 private:
00140 
00142     typedef std::vector<pion::platform::Transform *>        TransformChain;
00143 
00145     static const std::string        TERM_ELEMENT_NAME;
00146 
00148     static const std::string        TYPE_ELEMENT_NAME;
00149 
00151     static const std::string        OUTGOING_EVENT_ELEMENT_NAME;
00152     static const std::string        COPY_ORIGINAL_ELEMENT_NAME;
00153 
00155     static const std::string        TRANSFORMATION_ELEMENT_NAME;
00156 
00158     static const std::string        DELIVER_ORIGINAL_NAME;
00159 
00161     TransformChain                  m_transforms;
00162 
00164     pion::platform::Vocabulary::TermRef m_event_type;
00165 
00167     enum { DO_NEVER, DO_SOMETIMES, DO_ALWAYS }
00168                                     m_deliver_original;
00169 
00171     enum { COPY_ALL, COPY_UNCHANGED, COPY_NONE }
00172                                     m_copy_original;
00173 
00175     pion::platform::EventFactory    m_event_factory;
00176 };
00177 
00178 }   // end namespace plugins
00179 }   // end namespace pion
00180 
00181 #endif

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