MessageStore.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_MESSAGESTORE_H
00023 #define FIX_MESSAGESTORE_H
00024
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028
00029 #include "Message.h"
00030 #include <map>
00031 #include <vector>
00032 #include <string>
00033
00034 namespace FIX
00035 {
00036 class MessageStore;
00037
00041 class MessageStoreFactory
00042 {
00043 public:
00044 virtual ~MessageStoreFactory() {}
00045 virtual MessageStore* create( const SessionID& ) = 0;
00046 virtual void destroy( MessageStore* ) = 0;
00047 };
00048
00055 class MemoryStoreFactory : public MessageStoreFactory
00056 {
00057 public:
00058 MessageStore* create( const SessionID& );
00059 void destroy( MessageStore* );
00060 };
00061
00066 class MessageStore
00067 {
00068 public:
00069 virtual ~MessageStore() {}
00070
00071 virtual bool set( int, const std::string& )
00072 throw ( IOException ) = 0;
00073 virtual void get( int, int, std::vector < std::string > & ) const
00074 throw ( IOException ) = 0;
00075
00076 virtual int getNextSenderMsgSeqNum() const throw ( IOException ) = 0;
00077 virtual int getNextTargetMsgSeqNum() const throw ( IOException ) = 0;
00078 virtual void setNextSenderMsgSeqNum( int ) throw ( IOException ) = 0;
00079 virtual void setNextTargetMsgSeqNum( int ) throw ( IOException ) = 0;
00080 virtual void incrNextSenderMsgSeqNum() throw ( IOException ) = 0;
00081 virtual void incrNextTargetMsgSeqNum() throw ( IOException ) = 0;
00082
00083 virtual UtcTimeStamp getCreationTime() const throw ( IOException ) = 0;
00084
00085 virtual void reset() throw ( IOException ) = 0;
00086 virtual void refresh() throw ( IOException ) = 0;
00087 };
00096 class MemoryStore : public MessageStore
00097 {
00098 public:
00099 MemoryStore() : m_nextSenderMsgSeqNum( 1 ), m_nextTargetMsgSeqNum( 1 ) {}
00100
00101 bool set( int, const std::string& ) throw ( IOException );
00102 void get( int, int, std::vector < std::string > & ) const throw ( IOException );
00103
00104 int getNextSenderMsgSeqNum() const throw ( IOException )
00105 { return m_nextSenderMsgSeqNum; }
00106 int getNextTargetMsgSeqNum() const throw ( IOException )
00107 { return m_nextTargetMsgSeqNum; }
00108 void setNextSenderMsgSeqNum( int value ) throw ( IOException )
00109 { m_nextSenderMsgSeqNum = value; }
00110 void setNextTargetMsgSeqNum( int value ) throw ( IOException )
00111 { m_nextTargetMsgSeqNum = value; }
00112 void incrNextSenderMsgSeqNum() throw ( IOException )
00113 { ++m_nextSenderMsgSeqNum; }
00114 void incrNextTargetMsgSeqNum() throw ( IOException )
00115 { ++m_nextTargetMsgSeqNum; }
00116
00117 void setCreationTime( const UtcTimeStamp& creationTime ) throw ( IOException )
00118 { m_creationTime = creationTime; }
00119 UtcTimeStamp getCreationTime() const throw ( IOException )
00120 { return m_creationTime; }
00121
00122 void reset() throw ( IOException )
00123 {
00124 m_nextSenderMsgSeqNum = 1; m_nextTargetMsgSeqNum = 1;
00125 m_messages.clear(); m_creationTime.setCurrent();
00126 }
00127 void refresh() throw ( IOException ) {}
00128
00129 private:
00130 typedef std::map < int, std::string > Messages;
00131
00132 Messages m_messages;
00133 int m_nextSenderMsgSeqNum;
00134 int m_nextTargetMsgSeqNum;
00135 UtcTimeStamp m_creationTime;
00136 };
00137
00138 class MessageStoreFactoryExceptionWrapper
00139 {
00140 private:
00141 MessageStoreFactory* m_pFactory;
00142 public:
00143 MessageStoreFactoryExceptionWrapper( MessageStoreFactory* pFactory )
00144 : m_pFactory( pFactory ) {}
00145
00146 MessageStore* create( const SessionID&, bool&, ConfigError& );
00147 void destroy( MessageStore* );
00148 };
00149
00150 class MessageStoreExceptionWrapper
00151 {
00152 private:
00153 MessageStore* m_pStore;
00154 public:
00155 MessageStoreExceptionWrapper( MessageStore* pStore ) : m_pStore( pStore ) {}
00156 ~MessageStoreExceptionWrapper() { delete m_pStore; }
00157
00158 bool set( int, const std::string&, bool&, IOException& );
00159 void get( int, int, std::vector < std::string > &, bool&, IOException& ) const;
00160 int getNextSenderMsgSeqNum( bool&, IOException& ) const;
00161 int getNextTargetMsgSeqNum( bool&, IOException& ) const;
00162 void setNextSenderMsgSeqNum( int, bool&, IOException& );
00163 void setNextTargetMsgSeqNum( int, bool&, IOException& );
00164 void incrNextSenderMsgSeqNum( bool&, IOException& );
00165 void incrNextTargetMsgSeqNum( bool&, IOException& );
00166
00167 UtcTimeStamp getCreationTime( bool&, IOException& );
00168
00169 void reset( bool&, IOException& );
00170 void refresh( bool&, IOException& );
00171 };
00172 }
00173
00174 #endif //FIX_MESSAGESTORE_H