MessageCracker.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 FIXT11_MESSAGECRACKER_H
  21. #define FIXT11_MESSAGECRACKER_H
  22. #include "../SessionID.h"
  23. #include "../Exceptions.h"
  24. #include "../fixt11/Message.h"
  25. namespace FIXT11
  26. {
  27. class Heartbeat;
  28. class TestRequest;
  29. class ResendRequest;
  30. class Reject;
  31. class SequenceReset;
  32. class Logout;
  33. class Logon;
  34. class MessageCracker
  35. {
  36. public:
  37. virtual ~MessageCracker() {}
  38. virtual void onMessage( const Message&, const FIX::SessionID& )
  39. { throw FIX::UnsupportedMessageType(); }
  40. virtual void onMessage( Message&, const FIX::SessionID& )
  41. { throw FIX::UnsupportedMessageType(); }
  42. virtual void onMessage( const Heartbeat&, const FIX::SessionID& )
  43. {}
  44. virtual void onMessage( const TestRequest&, const FIX::SessionID& )
  45. {}
  46. virtual void onMessage( const ResendRequest&, const FIX::SessionID& )
  47. {}
  48. virtual void onMessage( const Reject&, const FIX::SessionID& )
  49. {}
  50. virtual void onMessage( const SequenceReset&, const FIX::SessionID& )
  51. {}
  52. virtual void onMessage( const Logout&, const FIX::SessionID& )
  53. {}
  54. virtual void onMessage( const Logon&, const FIX::SessionID& )
  55. {}
  56. virtual void onMessage( Heartbeat&, const FIX::SessionID& ) {}
  57. virtual void onMessage( TestRequest&, const FIX::SessionID& ) {}
  58. virtual void onMessage( ResendRequest&, const FIX::SessionID& ) {}
  59. virtual void onMessage( Reject&, const FIX::SessionID& ) {}
  60. virtual void onMessage( SequenceReset&, const FIX::SessionID& ) {}
  61. virtual void onMessage( Logout&, const FIX::SessionID& ) {}
  62. virtual void onMessage( Logon&, const FIX::SessionID& ) {}
  63. public:
  64. void crack( const Message& message,
  65. const FIX::SessionID& sessionID )
  66. {
  67. const std::string& msgTypeValue
  68. = message.getHeader().getField( FIX::FIELD::MsgType );
  69. if( msgTypeValue == "0" )
  70. onMessage( (const Heartbeat&)message, sessionID );
  71. else
  72. if( msgTypeValue == "1" )
  73. onMessage( (const TestRequest&)message, sessionID );
  74. else
  75. if( msgTypeValue == "2" )
  76. onMessage( (const ResendRequest&)message, sessionID );
  77. else
  78. if( msgTypeValue == "3" )
  79. onMessage( (const Reject&)message, sessionID );
  80. else
  81. if( msgTypeValue == "4" )
  82. onMessage( (const SequenceReset&)message, sessionID );
  83. else
  84. if( msgTypeValue == "5" )
  85. onMessage( (const Logout&)message, sessionID );
  86. else
  87. if( msgTypeValue == "A" )
  88. onMessage( (const Logon&)message, sessionID );
  89. else onMessage( message, sessionID );
  90. }
  91. void crack( Message& message,
  92. const FIX::SessionID& sessionID )
  93. {
  94. FIX::MsgType msgType;
  95. message.getHeader().getField(msgType);
  96. std::string msgTypeValue = msgType.getValue();
  97. if( msgTypeValue == "0" )
  98. onMessage( (Heartbeat&)message, sessionID );
  99. else
  100. if( msgTypeValue == "1" )
  101. onMessage( (TestRequest&)message, sessionID );
  102. else
  103. if( msgTypeValue == "2" )
  104. onMessage( (ResendRequest&)message, sessionID );
  105. else
  106. if( msgTypeValue == "3" )
  107. onMessage( (Reject&)message, sessionID );
  108. else
  109. if( msgTypeValue == "4" )
  110. onMessage( (SequenceReset&)message, sessionID );
  111. else
  112. if( msgTypeValue == "5" )
  113. onMessage( (Logout&)message, sessionID );
  114. else
  115. if( msgTypeValue == "A" )
  116. onMessage( (Logon&)message, sessionID );
  117. else onMessage( message, sessionID );
  118. }
  119. };
  120. }
  121. #endif