00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_CODEC_HEADER__
00021 #define __PION_CODEC_HEADER__
00022
00023 #include <istream>
00024 #include <ostream>
00025 #include <libxml/tree.h>
00026 #include <boost/shared_ptr.hpp>
00027 #include <pion/PionConfig.hpp>
00028 #include <pion/PionException.hpp>
00029 #include <pion/platform/Event.hpp>
00030 #include <pion/platform/Vocabulary.hpp>
00031 #include <pion/platform/PlatformPlugin.hpp>
00032
00033
00034 namespace pion {
00035 namespace platform {
00036
00037
00041 class PION_PLATFORM_API Codec
00042 : public PlatformPlugin
00043 {
00044 public:
00045
00047 class EmptyEventException : public PionException {
00048 public:
00049 EmptyEventException(const std::string& codec_id)
00050 : PionException("Codec configuration does not define an event type: ", codec_id) {}
00051 };
00052
00054 class UnknownTermException : public PionException {
00055 public:
00056 UnknownTermException(const std::string& event_type)
00057 : PionException("Codec configuration references an unknown event type: ", event_type) {}
00058 };
00059
00061 class NotAnObjectException : public PionException {
00062 public:
00063 NotAnObjectException(const std::string& event_type)
00064 : PionException("Codec configuration defines a non-object event type: ", event_type) {}
00065 };
00066
00068 class WrongEventTypeException : public PionException {
00069 public:
00070 WrongEventTypeException(void)
00071 : PionException("Event is not of the expected type") {}
00072 };
00073
00075 Codec(void) {}
00076
00078 virtual ~Codec() {}
00079
00081 virtual const std::string& getContentType(void) const = 0;
00082
00088 virtual boost::shared_ptr<Codec> clone(void) const = 0;
00089
00096 virtual void write(std::ostream& out, const Event& e) = 0;
00097
00104 virtual void finish(std::ostream& out) = 0;
00105
00113 virtual bool read(std::istream& in, Event& e) = 0;
00114
00122 virtual void setConfig(const Vocabulary& v, const xmlNodePtr config_ptr);
00123
00130 virtual void updateVocabulary(const Vocabulary& v);
00131
00140 inline EventPtr read(std::istream& in, EventFactory& f) {
00141 EventPtr event_ptr(f.create(getEventType()));
00142 if (! read(in, *event_ptr))
00143 event_ptr.reset();
00144 return event_ptr;
00145 }
00146
00148 inline Event::EventType getEventType(void) const { return m_event_term.term_ref; }
00149
00150
00151 protected:
00152
00154 inline void copyCodec(const Codec& c) {
00155 copyPlugin(c);
00156 m_event_term = c.m_event_term;
00157 }
00158
00159
00160 private:
00161
00163 static const std::string EVENT_ELEMENT_NAME;
00164
00165
00167 Vocabulary::Term m_event_term;
00168 };
00169
00170
00172 typedef boost::shared_ptr<Codec> CodecPtr;
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 }
00201 }
00202
00203 #endif