root/isimud/exchanges/FIX/common/processing_rules.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */