MessageStore.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef FIX_MESSAGESTORE_H
  21. #define FIX_MESSAGESTORE_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include "Message.h"
  26. #include <map>
  27. #include <vector>
  28. #include <string>
  29. namespace FIX
  30. {
  31. class MessageStore;
  32. /**
  33. * This interface must be implemented to create a MessageStore.
  34. */
  35. class MessageStoreFactory
  36. {
  37. public:
  38. virtual ~MessageStoreFactory() {}
  39. virtual MessageStore* create( const SessionID& ) = 0;
  40. virtual void destroy( MessageStore* ) = 0;
  41. };
  42. /**
  43. * Creates a memory based implementation of MessageStore.
  44. *
  45. * This will lose all data on process termination. This class should only
  46. * be used for test applications, never in production.
  47. */
  48. class MemoryStoreFactory : public MessageStoreFactory
  49. {
  50. public:
  51. MessageStore* create( const SessionID& );
  52. void destroy( MessageStore* );
  53. };
  54. /**
  55. * This interface must be implemented to store and retrieve messages and
  56. * sequence numbers.
  57. */
  58. class MessageStore
  59. {
  60. public:
  61. virtual ~MessageStore() {}
  62. virtual bool set( int, const std::string& )
  63. throw ( IOException ) = 0;
  64. virtual void get( int, int, std::vector < std::string > & ) const
  65. throw ( IOException ) = 0;
  66. virtual int getNextSenderMsgSeqNum() const throw ( IOException ) = 0;
  67. virtual int getNextTargetMsgSeqNum() const throw ( IOException ) = 0;
  68. virtual void setNextSenderMsgSeqNum( int ) throw ( IOException ) = 0;
  69. virtual void setNextTargetMsgSeqNum( int ) throw ( IOException ) = 0;
  70. virtual void incrNextSenderMsgSeqNum() throw ( IOException ) = 0;
  71. virtual void incrNextTargetMsgSeqNum() throw ( IOException ) = 0;
  72. virtual UtcTimeStamp getCreationTime() const throw ( IOException ) = 0;
  73. virtual void reset() throw ( IOException ) = 0;
  74. virtual void refresh() throw ( IOException ) = 0;
  75. };
  76. /*! @} */
  77. /**
  78. * Memory based implementation of MessageStore.
  79. *
  80. * This will lose all data on process terminition. This class should only
  81. * be used for test applications, never in production.
  82. */
  83. class MemoryStore : public MessageStore
  84. {
  85. public:
  86. MemoryStore() : m_nextSenderMsgSeqNum( 1 ), m_nextTargetMsgSeqNum( 1 ) {}
  87. bool set( int, const std::string& ) throw ( IOException );
  88. void get( int, int, std::vector < std::string > & ) const throw ( IOException );
  89. int getNextSenderMsgSeqNum() const throw ( IOException )
  90. { return m_nextSenderMsgSeqNum; }
  91. int getNextTargetMsgSeqNum() const throw ( IOException )
  92. { return m_nextTargetMsgSeqNum; }
  93. void setNextSenderMsgSeqNum( int value ) throw ( IOException )
  94. { m_nextSenderMsgSeqNum = value; }
  95. void setNextTargetMsgSeqNum( int value ) throw ( IOException )
  96. { m_nextTargetMsgSeqNum = value; }
  97. void incrNextSenderMsgSeqNum() throw ( IOException )
  98. { ++m_nextSenderMsgSeqNum; }
  99. void incrNextTargetMsgSeqNum() throw ( IOException )
  100. { ++m_nextTargetMsgSeqNum; }
  101. void setCreationTime( const UtcTimeStamp& creationTime ) throw ( IOException )
  102. { m_creationTime = creationTime; }
  103. UtcTimeStamp getCreationTime() const throw ( IOException )
  104. { return m_creationTime; }
  105. void reset() throw ( IOException )
  106. {
  107. m_nextSenderMsgSeqNum = 1; m_nextTargetMsgSeqNum = 1;
  108. m_messages.clear(); m_creationTime.setCurrent();
  109. }
  110. void refresh() throw ( IOException ) {}
  111. private:
  112. typedef std::map < int, std::string > Messages;
  113. Messages m_messages;
  114. int m_nextSenderMsgSeqNum;
  115. int m_nextTargetMsgSeqNum;
  116. UtcTimeStamp m_creationTime;
  117. };
  118. class MessageStoreFactoryExceptionWrapper
  119. {
  120. private:
  121. MessageStoreFactory* m_pFactory;
  122. public:
  123. MessageStoreFactoryExceptionWrapper( MessageStoreFactory* pFactory )
  124. : m_pFactory( pFactory ) {}
  125. MessageStore* create( const SessionID&, bool&, ConfigError& );
  126. void destroy( MessageStore* );
  127. };
  128. class MessageStoreExceptionWrapper
  129. {
  130. private:
  131. MessageStore* m_pStore;
  132. public:
  133. MessageStoreExceptionWrapper( MessageStore* pStore ) : m_pStore( pStore ) {}
  134. ~MessageStoreExceptionWrapper() { delete m_pStore; }
  135. bool set( int, const std::string&, bool&, IOException& );
  136. void get( int, int, std::vector < std::string > &, bool&, IOException& ) const;
  137. int getNextSenderMsgSeqNum( bool&, IOException& ) const;
  138. int getNextTargetMsgSeqNum( bool&, IOException& ) const;
  139. void setNextSenderMsgSeqNum( int, bool&, IOException& );
  140. void setNextTargetMsgSeqNum( int, bool&, IOException& );
  141. void incrNextSenderMsgSeqNum( bool&, IOException& );
  142. void incrNextTargetMsgSeqNum( bool&, IOException& );
  143. UtcTimeStamp getCreationTime( bool&, IOException& );
  144. void reset( bool&, IOException& );
  145. void refresh( bool&, IOException& );
  146. };
  147. }
  148. #endif //FIX_MESSAGESTORE_H