platform/include/pion/platform/Protocol.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_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 {        // begin namespace pion
00037 namespace platform {    // begin namespace platform (Pion Platform Library)
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 }   // end namespace platform
00177 }   // end namespace pion
00178 
00179 #endif

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