libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
processing_rules_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include <functional>
20 
21 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace common {
22 
23 template<class SrcMsgDetails, class DestMsgDetails>
24 struct client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails>::state_machine_t : libjmmcg::msm::unroll::state_transition_table<state_machine_t> {
25  using msm_base_t=libjmmcg::msm::unroll::state_transition_table<state_machine_t>;
26  using row_t=libjmmcg::msm::unroll::row_types<typename src_msg_details_t::MsgType_t, typename dest_msg_details_t::MsgTypes_t>;
27  using transition_table=typename msm_base_t::template rows<
28 // TODO finish implementing this...
29  /// Reject any message that has not been recognised.
30  typename row_t::template row<
31  src_msg_details_t::MatchAll,
32  typename base_t::template send_reject<typename src_msg_details_t::Reject, false>,
33  dest_msg_details_t::Reject::static_type
34  >
35  >;
36 };
37 
38 template<class SrcMsgDetails, class DestMsgDetails>
39 template<class SktT>
40 inline bool
41 client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails>
42 ::process_msg(typename src_msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, SktT &dest_skt) {
43  typename src_msg_details_t::Header_t const &hdr=reinterpret_cast<typename src_msg_details_t::Header_t const &>(buff);
44  const auto last_state=msm.process(hdr.type(), buff, exchg_skt, dest_skt);
45  return last_state==dest_msg_details_t::Exit;
46 }
47 
48 template<class SrcMsgDetails, class DestMsgDetails> inline std::string
49 client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails>::to_string() const noexcept(false) {
50  return base_t::to_string();
51 }
52 
53 template<class SrcMsgDetails, class DestMsgDetails> inline std::ostream &
54 operator<<(std::ostream &os, client_to_exchange_transformations<SrcMsgDetails, DestMsgDetails> const &ec) noexcept(false) {
55  os<<ec.to_string();
56  return os;
57 }
58 
59 template<class SrcMsgDetails, class DestMsgDetails>
60 struct exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>::business_state_machine_t : libjmmcg::msm::unroll::state_transition_table<business_state_machine_t> {
61  using msm_base_t=libjmmcg::msm::unroll::state_transition_table<business_state_machine_t>;
62  using row_t=libjmmcg::msm::unroll::row_types<typename src_msg_details_t::MsgTypes_t, typename dest_msg_details_t::MsgType_t>;
63  using transition_table=typename msm_base_t::template rows<
64 // TODO finish implementing this...
65  /// Reject any message that has not been recognised.
66  typename row_t::template row<
67  src_msg_details_t::MatchAll,
68  typename base_t::template send_reject<typename dest_msg_details_t::Reject, true>,
69  dest_msg_details_t::Reject::static_type
70  >
71  >;
72 };
73 
74 template<class SrcMsgDetails, class DestMsgDetails>
75 struct exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>::admin_state_machine_t : libjmmcg::msm::unroll::state_transition_table<admin_state_machine_t> {
76  using msm_base_t=libjmmcg::msm::unroll::state_transition_table<admin_state_machine_t>;
77  using row_t=libjmmcg::msm::unroll::row_types<typename src_msg_details_t::MsgTypes_t, typename dest_msg_details_t::MsgType_t>;
78  using transition_table=typename msm_base_t::template rows<
79  /**
80  The response to a server Heartbeat is a Heartbeat.
81  */
82  typename row_t::template row<
83  src_msg_details_t::ServerHeartbeat::static_type,
84  typename base_t::template just_send_to_exchg<typename src_msg_details_t::ClientHeartbeat>,
85  src_msg_details_t::ClientHeartbeat::static_type
86  >,
87  typename row_t::template row<
88  src_msg_details_t::Logout::static_type,
89  typename msm_base_t::no_op, // TODO
90  dest_msg_details_t::Exit
91  >,
92 // TODO finish implementing this...
93  /// Reject any message that has not been recognised.
94  typename row_t::template row<
95  src_msg_details_t::MatchAll,
96  typename base_t::template match_all_response<business_machine>,
97  dest_msg_details_t::Reject::static_type
98  >
99  >;
100 };
101 
102 template<class SrcMsgDetails, class DestMsgDetails>
103 template<class SktT, class ClientCxn>
104 inline bool
105 exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>
106 ::process_msg(typename src_msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, ClientCxn &client_skt) {
107  typename src_msg_details_t::Header_t const &hdr=reinterpret_cast<typename src_msg_details_t::Header_t const &>(buff);
108  const auto last_state=admin_msm.process(hdr.type(), buff, exchg_skt, client_skt);
109  return last_state==dest_msg_details_t::Exit;
110 }
111 
112 template<class SrcMsgDetails, class DestMsgDetails> inline std::string
113 exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails>::to_string() const noexcept(false) {
114  return base_t::to_string();
115 }
116 
117 template<class SrcMsgDetails, class DestMsgDetails> inline std::ostream &
118 operator<<(std::ostream &os, exchange_to_client_transformations<SrcMsgDetails, DestMsgDetails> const &ec) noexcept(false) {
119  os<<ec.to_string();
120  return os;
121 }
122 
123 template<class SrcMsgDetails>
124 struct simulator_responses<SrcMsgDetails>::state_machine_t : libjmmcg::msm::unroll::state_transition_table<state_machine_t> {
125  using msm_base_t=libjmmcg::msm::unroll::state_transition_table<state_machine_t>;
126  using row_t=libjmmcg::msm::unroll::row_types<typename msg_details_t::MsgType_t, typename msg_details_t::MsgType_t>;
127  using transition_table=typename msm_base_t::template rows<
128  /**
129  The response to a Heartbeat is nothing.
130  */
131  typename row_t::template row<
132  msg_details_t::ClientHeartbeat::static_type,
133  typename msm_base_t::no_op,
134  msg_details_t::ServerHeartbeat::static_type
135  >,
136 // TODO finish implementing this...
137  /// Reject any message that has not been recognised.
138  typename row_t::template row<
139  msg_details_t::MatchAll,
140  typename base_t::template send_reject<typename msg_details_t::Reject, true>,
141  msg_details_t::Reject::static_type
142  >
143  >;
144 };
145 
146 template<class SrcMsgDetails>
147 template<class SktT>
148 inline bool
149 simulator_responses<SrcMsgDetails>::process_msg(typename msg_details_t::msg_buffer_t const &buff, SktT &exchg_skt, SktT &client_skt) {
150  ++(this->sequenceNumber);
151  typename msg_details_t::Header_t const &hdr=reinterpret_cast<typename msg_details_t::Header_t const &>(buff);
152  const auto last_state=msm.process(hdr.type(), buff, exchg_skt, client_skt);
153  return last_state==msg_details_t::Exit;
154 }
155 
156 template<class SrcMsgDetails> inline std::string
157 simulator_responses<SrcMsgDetails>::to_string() const noexcept(false) {
158  return base_t::to_string();
159 }
160 
161 template<class SrcMsgDetails> inline std::ostream &
162 operator<<(std::ostream &os, simulator_responses<SrcMsgDetails> const &ec) noexcept(false) {
163  os<<ec.to_string();
164  return os;
165 }
166 
167 } } } } }