00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 {
00032 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 }
00179 }
00180
00181 #endif