libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
processing_rules.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_COMMON_FIX_PROCESSING_RULES_HPP
2 #define ISIMUD_EXCHANGES_COMMON_FIX_PROCESSING_RULES_HPP
3 
4 /******************************************************************************
5 ** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2.1 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include "../../common/processing_rules.hpp"
23 
24 #include "core/msm.hpp"
25 
26 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace common {
27 
28 /// An FIX-protocol message handler.
29 template<class SrcMsgDetails, class DestMsgDetails>
30 class client_to_exchange_transformations final : public exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails>, typename SrcMsgDetails::client_to_exchange_messages_t> {
31 public:
32  using base_t=exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails>, typename SrcMsgDetails::client_to_exchange_messages_t>;
33  using src_msg_details_t=typename base_t::src_msg_details_t;
34  using dest_msg_details_t=typename base_t::dest_msg_details_t;
35 
36  /**
37  \return False to continue processing messages, true otherwise.
38  */
39  template<class SktT>
40  bool process_msg(typename src_msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, SktT &dest_skt);
41 
42  std::string to_string() const noexcept(false);
43 
44 private:
45  struct state_machine_t;
46  using machine=libjmmcg::msm::unroll::machine<state_machine_t>;
47 
48  static inline const machine msm{};
49 };
50 
51 template<class SrcMsgDetails, class DestMsgDetails> inline std::ostream &
52 operator<<(std::ostream &os, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails> const &ec) noexcept(false);
53 
54 /// A FIX-protocol-to-client message handler.
55 /**
56  The behaviour of this handler is derived from the specification in [1].
57 */
58 template<class SrcMsgDetails, class DestMsgDetails>
59 class exchange_to_client_transformations final : public exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>, typename SrcMsgDetails::exchange_to_client_messages_t> {
60 public:
61  using base_t=exchanges::common::message_responses<SrcMsgDetails, DestMsgDetails, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>, typename SrcMsgDetails::exchange_to_client_messages_t>;
62  using src_msg_details_t=typename base_t::src_msg_details_t;
63  using dest_msg_details_t=typename base_t::dest_msg_details_t;
64 
65  /**
66  \return False to continue processing messages, true otherwise.
67  */
68  template<class SktT, class ClientCxn>
69  bool process_msg(typename src_msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, ClientCxn &client_skt);
70 
71  std::string to_string() const noexcept(false);
72 
73 private:
74  struct business_state_machine_t;
75  struct admin_state_machine_t;
76  using business_machine=libjmmcg::msm::unroll::machine<business_state_machine_t>;
77  using admin_machine=libjmmcg::msm::unroll::machine<admin_state_machine_t>;
78 
79  static inline const business_machine business_msm{};
80  static inline const admin_machine admin_msm{business_msm, business_msm, business_msm, business_msm};
81 };
82 
83 template<class SrcMsgDetails, class DestMsgDetails> inline std::ostream &
84 operator<<(std::ostream &os, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails> const &ec) noexcept(false);
85 
86 /// A simple, FIX-protocol exchange simulator.
87 /**
88  The behaviour of this simulator is a simplification derived from the specification in [1].
89 */
90 template<class SrcMsgDetails>
91 class simulator_responses final : public exchanges::common::simulator_responses<SrcMsgDetails, simulator_responses<SrcMsgDetails>> {
92 public:
93  using base_t=exchanges::common::simulator_responses<SrcMsgDetails, simulator_responses<SrcMsgDetails>>;
94  using msg_details_t=typename base_t::msg_details_t;
95 
96  static inline constexpr Reason_t logout_reason{'U', 's', 'e', 'r', ' ', 'l', 'o', 'g', 'o', 'u', 't', ' ', 'r', 'e', 'c', 'e', 'i', 'v', 'e', 'd'};
97  /// The only valid instrument, all others will be rejected.
98  static inline constexpr typename msg_details_t::SecurityID_t instrumentID{'1'};
99  /// An invalid instrument, that will be rejected.
100  static inline constexpr typename msg_details_t::SecurityID_t invalidInstrumentID{'2'};
101 
102  simulator_responses() noexcept(true)
103  : base_t(), msm{std::ref(*this), std::ref(*this)} {
104  }
105  simulator_responses(simulator_responses const &sr) noexcept(true)
106  : base_t(sr), msm{std::ref(*this), std::ref(*this)} {
107  }
108 
109  /**
110  \return False to continue processing messages, true otherwise.
111  */
112  template<class SktT>
113  bool process_msg(typename msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, SktT &client_skt);
114 
115  std::string to_string() const noexcept(false);
116 
117 private:
118  struct state_machine_t;
119  using machine=libjmmcg::msm::unroll::machine<state_machine_t>;
120 
121  const machine msm;
122 };
123 
124 template<class SrcMsgDetails> inline std::ostream &
125 operator<<(std::ostream &os, simulator_responses<SrcMsgDetails> const &ec) noexcept(false);
126 
127 } } } } }
128 
130 
131 #endif