00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_PROTOCOL_HEADER__
00021 #define __PION_PROTOCOL_HEADER__
00022
00023 #include <istream>
00024 #include <ostream>
00025 #include <libxml/tree.h>
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/logic/tribool.hpp>
00028 #include <boost/system/error_code.hpp>
00029 #include <pion/PionConfig.hpp>
00030 #include <pion/PionException.hpp>
00031 #include <pion/platform/Event.hpp>
00032 #include <pion/platform/Vocabulary.hpp>
00033 #include <pion/platform/PlatformPlugin.hpp>
00034
00035
00036 namespace pion {
00037 namespace platform {
00038
00039
00043 class PION_PLATFORM_API Protocol
00044 : public PlatformPlugin
00045 {
00046 public:
00047
00049 class EmptyEventException : public PionException {
00050 public:
00051 EmptyEventException(const std::string& protocol_id)
00052 : PionException("Protocol configuration does not define an event type: ", protocol_id) {}
00053 };
00054
00056 class UnknownTermException : public PionException {
00057 public:
00058 UnknownTermException(const std::string& term)
00059 : PionException("Protocol configuration references an unknown term: ", term) {}
00060 };
00061
00063 class NotAnObjectException : public PionException {
00064 public:
00065 NotAnObjectException(const std::string& event_type)
00066 : PionException("Protocol configuration defines a non-object event type: ", event_type) {}
00067 };
00068
00070 Protocol(void) {}
00071
00073 virtual ~Protocol() {}
00074
00076 virtual void reset(void) = 0;
00077
00083 virtual boost::shared_ptr<Protocol> clone(void) const = 0;
00084
00095 virtual bool close(pion::platform::EventPtr& event_ptr_ref,
00096 bool client_reset, bool server_reset) = 0;
00097
00112 virtual boost::tribool readNext(bool request, const char* ptr, size_t len,
00113 boost::posix_time::ptime data_timestamp, boost::posix_time::ptime ack_timestamp,
00114 pion::platform::EventContainer& events, boost::system::error_code& ec) = 0;
00115
00126 virtual bool checkRecoveryPacket(bool request, const char* ptr, size_t len);
00127
00135 virtual void setConfig(const Vocabulary& v, const xmlNodePtr config_ptr);
00136
00143 virtual void updateVocabulary(const Vocabulary& v);
00144
00146 inline Event::EventType getEventType(void) const { return m_event_term.term_ref; }
00147
00148
00149 protected:
00150
00152 inline void copyProtocol(const Protocol& c) {
00153 copyPlugin(c);
00154 m_event_term = c.m_event_term;
00155 }
00156
00158 EventFactory m_event_factory;
00159
00160
00161 private:
00162
00164 static const std::string EVENT_ELEMENT_NAME;
00165
00166
00168 Vocabulary::Term m_event_term;
00169 };
00170
00171
00173 typedef boost::shared_ptr<Protocol> ProtocolPtr;
00174
00175
00176 }
00177 }
00178
00179 #endif