MessageCracker.h 12 KB

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