MessageCracker.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 FIX40_MESSAGECRACKER_H
  21. #define FIX40_MESSAGECRACKER_H
  22. #include "../SessionID.h"
  23. #include "../Exceptions.h"
  24. #include "../fix40/Message.h"
  25. namespace FIX40
  26. {
  27. class Heartbeat;
  28. class TestRequest;
  29. class ResendRequest;
  30. class Reject;
  31. class SequenceReset;
  32. class Logout;
  33. class IOI;
  34. class Advertisement;
  35. class ExecutionReport;
  36. class OrderCancelReject;
  37. class Logon;
  38. class News;
  39. class Email;
  40. class NewOrderSingle;
  41. class NewOrderList;
  42. class OrderCancelRequest;
  43. class OrderCancelReplaceRequest;
  44. class OrderStatusRequest;
  45. class Allocation;
  46. class ListCancelRequest;
  47. class ListExecute;
  48. class ListStatusRequest;
  49. class ListStatus;
  50. class AllocationInstructionAck;
  51. class DontKnowTrade;
  52. class QuoteRequest;
  53. class Quote;
  54. class MessageCracker
  55. {
  56. public:
  57. virtual ~MessageCracker() {}
  58. virtual void onMessage( const Message&, const FIX::SessionID& )
  59. { throw FIX::UnsupportedMessageType(); }
  60. virtual void onMessage( Message&, const FIX::SessionID& )
  61. { throw FIX::UnsupportedMessageType(); }
  62. virtual void onMessage( const Heartbeat&, const FIX::SessionID& )
  63. {}
  64. virtual void onMessage( const TestRequest&, const FIX::SessionID& )
  65. {}
  66. virtual void onMessage( const ResendRequest&, const FIX::SessionID& )
  67. {}
  68. virtual void onMessage( const Reject&, const FIX::SessionID& )
  69. {}
  70. virtual void onMessage( const SequenceReset&, const FIX::SessionID& )
  71. {}
  72. virtual void onMessage( const Logout&, const FIX::SessionID& )
  73. {}
  74. virtual void onMessage( const IOI&, const FIX::SessionID& )
  75. { throw FIX::UnsupportedMessageType(); }
  76. virtual void onMessage( const Advertisement&, const FIX::SessionID& )
  77. { throw FIX::UnsupportedMessageType(); }
  78. virtual void onMessage( const ExecutionReport&, const FIX::SessionID& )
  79. { throw FIX::UnsupportedMessageType(); }
  80. virtual void onMessage( const OrderCancelReject&, const FIX::SessionID& )
  81. { throw FIX::UnsupportedMessageType(); }
  82. virtual void onMessage( const Logon&, const FIX::SessionID& )
  83. {}
  84. virtual void onMessage( const News&, const FIX::SessionID& )
  85. { throw FIX::UnsupportedMessageType(); }
  86. virtual void onMessage( const Email&, const FIX::SessionID& )
  87. { throw FIX::UnsupportedMessageType(); }
  88. virtual void onMessage( const NewOrderSingle&, const FIX::SessionID& )
  89. { throw FIX::UnsupportedMessageType(); }
  90. virtual void onMessage( const NewOrderList&, const FIX::SessionID& )
  91. { throw FIX::UnsupportedMessageType(); }
  92. virtual void onMessage( const OrderCancelRequest&, const FIX::SessionID& )
  93. { throw FIX::UnsupportedMessageType(); }
  94. virtual void onMessage( const OrderCancelReplaceRequest&, const FIX::SessionID& )
  95. { throw FIX::UnsupportedMessageType(); }
  96. virtual void onMessage( const OrderStatusRequest&, const FIX::SessionID& )
  97. { throw FIX::UnsupportedMessageType(); }
  98. virtual void onMessage( const Allocation&, const FIX::SessionID& )
  99. { throw FIX::UnsupportedMessageType(); }
  100. virtual void onMessage( const ListCancelRequest&, const FIX::SessionID& )
  101. { throw FIX::UnsupportedMessageType(); }
  102. virtual void onMessage( const ListExecute&, const FIX::SessionID& )
  103. { throw FIX::UnsupportedMessageType(); }
  104. virtual void onMessage( const ListStatusRequest&, const FIX::SessionID& )
  105. { throw FIX::UnsupportedMessageType(); }
  106. virtual void onMessage( const ListStatus&, const FIX::SessionID& )
  107. { throw FIX::UnsupportedMessageType(); }
  108. virtual void onMessage( const AllocationInstructionAck&, const FIX::SessionID& )
  109. { throw FIX::UnsupportedMessageType(); }
  110. virtual void onMessage( const DontKnowTrade&, const FIX::SessionID& )
  111. { throw FIX::UnsupportedMessageType(); }
  112. virtual void onMessage( const QuoteRequest&, const FIX::SessionID& )
  113. { throw FIX::UnsupportedMessageType(); }
  114. virtual void onMessage( const Quote&, const FIX::SessionID& )
  115. { throw FIX::UnsupportedMessageType(); }
  116. virtual void onMessage( Heartbeat&, const FIX::SessionID& ) {}
  117. virtual void onMessage( TestRequest&, const FIX::SessionID& ) {}
  118. virtual void onMessage( ResendRequest&, const FIX::SessionID& ) {}
  119. virtual void onMessage( Reject&, const FIX::SessionID& ) {}
  120. virtual void onMessage( SequenceReset&, const FIX::SessionID& ) {}
  121. virtual void onMessage( Logout&, const FIX::SessionID& ) {}
  122. virtual void onMessage( IOI&, const FIX::SessionID& ) {}
  123. virtual void onMessage( Advertisement&, const FIX::SessionID& ) {}
  124. virtual void onMessage( ExecutionReport&, const FIX::SessionID& ) {}
  125. virtual void onMessage( OrderCancelReject&, const FIX::SessionID& ) {}
  126. virtual void onMessage( Logon&, const FIX::SessionID& ) {}
  127. virtual void onMessage( News&, const FIX::SessionID& ) {}
  128. virtual void onMessage( Email&, const FIX::SessionID& ) {}
  129. virtual void onMessage( NewOrderSingle&, const FIX::SessionID& ) {}
  130. virtual void onMessage( NewOrderList&, const FIX::SessionID& ) {}
  131. virtual void onMessage( OrderCancelRequest&, const FIX::SessionID& ) {}
  132. virtual void onMessage( OrderCancelReplaceRequest&, const FIX::SessionID& ) {}
  133. virtual void onMessage( OrderStatusRequest&, const FIX::SessionID& ) {}
  134. virtual void onMessage( Allocation&, const FIX::SessionID& ) {}
  135. virtual void onMessage( ListCancelRequest&, const FIX::SessionID& ) {}
  136. virtual void onMessage( ListExecute&, const FIX::SessionID& ) {}
  137. virtual void onMessage( ListStatusRequest&, const FIX::SessionID& ) {}
  138. virtual void onMessage( ListStatus&, const FIX::SessionID& ) {}
  139. virtual void onMessage( AllocationInstructionAck&, const FIX::SessionID& ) {}
  140. virtual void onMessage( DontKnowTrade&, const FIX::SessionID& ) {}
  141. virtual void onMessage( QuoteRequest&, const FIX::SessionID& ) {}
  142. virtual void onMessage( Quote&, const FIX::SessionID& ) {}
  143. public:
  144. void crack( const Message& message,
  145. const FIX::SessionID& sessionID )
  146. {
  147. const std::string& msgTypeValue
  148. = message.getHeader().getField( FIX::FIELD::MsgType );
  149. if( msgTypeValue == "0" )
  150. onMessage( (const Heartbeat&)message, sessionID );
  151. else
  152. if( msgTypeValue == "1" )
  153. onMessage( (const TestRequest&)message, sessionID );
  154. else
  155. if( msgTypeValue == "2" )
  156. onMessage( (const ResendRequest&)message, sessionID );
  157. else
  158. if( msgTypeValue == "3" )
  159. onMessage( (const Reject&)message, sessionID );
  160. else
  161. if( msgTypeValue == "4" )
  162. onMessage( (const SequenceReset&)message, sessionID );
  163. else
  164. if( msgTypeValue == "5" )
  165. onMessage( (const Logout&)message, sessionID );
  166. else
  167. if( msgTypeValue == "6" )
  168. onMessage( (const IOI&)message, sessionID );
  169. else
  170. if( msgTypeValue == "7" )
  171. onMessage( (const Advertisement&)message, sessionID );
  172. else
  173. if( msgTypeValue == "8" )
  174. onMessage( (const ExecutionReport&)message, sessionID );
  175. else
  176. if( msgTypeValue == "9" )
  177. onMessage( (const OrderCancelReject&)message, sessionID );
  178. else
  179. if( msgTypeValue == "A" )
  180. onMessage( (const Logon&)message, sessionID );
  181. else
  182. if( msgTypeValue == "B" )
  183. onMessage( (const News&)message, sessionID );
  184. else
  185. if( msgTypeValue == "C" )
  186. onMessage( (const Email&)message, sessionID );
  187. else
  188. if( msgTypeValue == "D" )
  189. onMessage( (const NewOrderSingle&)message, sessionID );
  190. else
  191. if( msgTypeValue == "E" )
  192. onMessage( (const NewOrderList&)message, sessionID );
  193. else
  194. if( msgTypeValue == "F" )
  195. onMessage( (const OrderCancelRequest&)message, sessionID );
  196. else
  197. if( msgTypeValue == "G" )
  198. onMessage( (const OrderCancelReplaceRequest&)message, sessionID );
  199. else
  200. if( msgTypeValue == "H" )
  201. onMessage( (const OrderStatusRequest&)message, sessionID );
  202. else
  203. if( msgTypeValue == "J" )
  204. onMessage( (const Allocation&)message, sessionID );
  205. else
  206. if( msgTypeValue == "K" )
  207. onMessage( (const ListCancelRequest&)message, sessionID );
  208. else
  209. if( msgTypeValue == "L" )
  210. onMessage( (const ListExecute&)message, sessionID );
  211. else
  212. if( msgTypeValue == "M" )
  213. onMessage( (const ListStatusRequest&)message, sessionID );
  214. else
  215. if( msgTypeValue == "N" )
  216. onMessage( (const ListStatus&)message, sessionID );
  217. else
  218. if( msgTypeValue == "P" )
  219. onMessage( (const AllocationInstructionAck&)message, sessionID );
  220. else
  221. if( msgTypeValue == "Q" )
  222. onMessage( (const DontKnowTrade&)message, sessionID );
  223. else
  224. if( msgTypeValue == "R" )
  225. onMessage( (const QuoteRequest&)message, sessionID );
  226. else
  227. if( msgTypeValue == "S" )
  228. onMessage( (const Quote&)message, sessionID );
  229. else onMessage( message, sessionID );
  230. }
  231. void crack( Message& message,
  232. const FIX::SessionID& sessionID )
  233. {
  234. FIX::MsgType msgType;
  235. message.getHeader().getField(msgType);
  236. std::string msgTypeValue = msgType.getValue();
  237. if( msgTypeValue == "0" )
  238. onMessage( (Heartbeat&)message, sessionID );
  239. else
  240. if( msgTypeValue == "1" )
  241. onMessage( (TestRequest&)message, sessionID );
  242. else
  243. if( msgTypeValue == "2" )
  244. onMessage( (ResendRequest&)message, sessionID );
  245. else
  246. if( msgTypeValue == "3" )
  247. onMessage( (Reject&)message, sessionID );
  248. else
  249. if( msgTypeValue == "4" )
  250. onMessage( (SequenceReset&)message, sessionID );
  251. else
  252. if( msgTypeValue == "5" )
  253. onMessage( (Logout&)message, sessionID );
  254. else
  255. if( msgTypeValue == "6" )
  256. onMessage( (IOI&)message, sessionID );
  257. else
  258. if( msgTypeValue == "7" )
  259. onMessage( (Advertisement&)message, sessionID );
  260. else
  261. if( msgTypeValue == "8" )
  262. onMessage( (ExecutionReport&)message, sessionID );
  263. else
  264. if( msgTypeValue == "9" )
  265. onMessage( (OrderCancelReject&)message, sessionID );
  266. else
  267. if( msgTypeValue == "A" )
  268. onMessage( (Logon&)message, sessionID );
  269. else
  270. if( msgTypeValue == "B" )
  271. onMessage( (News&)message, sessionID );
  272. else
  273. if( msgTypeValue == "C" )
  274. onMessage( (Email&)message, sessionID );
  275. else
  276. if( msgTypeValue == "D" )
  277. onMessage( (NewOrderSingle&)message, sessionID );
  278. else
  279. if( msgTypeValue == "E" )
  280. onMessage( (NewOrderList&)message, sessionID );
  281. else
  282. if( msgTypeValue == "F" )
  283. onMessage( (OrderCancelRequest&)message, sessionID );
  284. else
  285. if( msgTypeValue == "G" )
  286. onMessage( (OrderCancelReplaceRequest&)message, sessionID );
  287. else
  288. if( msgTypeValue == "H" )
  289. onMessage( (OrderStatusRequest&)message, sessionID );
  290. else
  291. if( msgTypeValue == "J" )
  292. onMessage( (Allocation&)message, sessionID );
  293. else
  294. if( msgTypeValue == "K" )
  295. onMessage( (ListCancelRequest&)message, sessionID );
  296. else
  297. if( msgTypeValue == "L" )
  298. onMessage( (ListExecute&)message, sessionID );
  299. else
  300. if( msgTypeValue == "M" )
  301. onMessage( (ListStatusRequest&)message, sessionID );
  302. else
  303. if( msgTypeValue == "N" )
  304. onMessage( (ListStatus&)message, sessionID );
  305. else
  306. if( msgTypeValue == "P" )
  307. onMessage( (AllocationInstructionAck&)message, sessionID );
  308. else
  309. if( msgTypeValue == "Q" )
  310. onMessage( (DontKnowTrade&)message, sessionID );
  311. else
  312. if( msgTypeValue == "R" )
  313. onMessage( (QuoteRequest&)message, sessionID );
  314. else
  315. if( msgTypeValue == "S" )
  316. onMessage( (Quote&)message, sessionID );
  317. else onMessage( message, sessionID );
  318. }
  319. };
  320. }
  321. #endif