libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_batsboe_main_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 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges {
20 
21 template<class Link> inline int
22 fix_to_batsboe_link<Link>::main(int argc, char const * const *argv) noexcept(true) {
23  return base_t::main<link_t>(
24  argc,
25  argv,
26  BATSBOE::create_program_options<link_t>(create_program_options()),
27  [](boost::program_options::variables_map const &vm) {
28  using conn_pol_t=typename link_t::exchg_link_t::conn_pol_t;
29  using exchange_msg_details_t=typename link_t::exchg_link_t::exchange_msg_details_t;
30 
31  std::string const MIC_code=[]() {
32  std::ostringstream ss;
33  common::mic_codes::to_stream<exchange_msg_details_t::MIC_code>(ss);
34  return ss.str();
35  }();
36  const std::string sess_sub_id(vm[(MIC_code+"_session_sub_id").c_str()].as<std::string>());
37  BATSBOE::common::SessionSubID_t sess_sub_id_conv;
38  std::memcpy(sess_sub_id_conv.data(), sess_sub_id.data(), std::min(sess_sub_id_conv.size(), sess_sub_id.size()));
39  const std::string user(vm[(MIC_code+"_username").c_str()].as<std::string>());
40  typename exchange_msg_details_t::UserName_t user_conv{};
41  std::memcpy(user_conv.data(), user.data(), std::min(user_conv.size(), user.size()));
42  const std::string pass(vm[(MIC_code+"_password").c_str()].as<std::string>());
43  typename exchange_msg_details_t::Password_t pass_conv{};
44  std::memcpy(pass_conv.data(), pass.data(), std::min(pass_conv.size(), pass.size()));
45  // TODO Must be shared, as the link, also the processing rules require a reference to this object.
46  std::shared_ptr<typename exchange_msg_details_t::SeqNum_t> seq_num(
47  std::make_shared<typename exchange_msg_details_t::SeqNum_t>(
48  vm[(MIC_code+"_sequence_number").c_str()].as<unsigned>()
49  )
50  );
51 
52  return std::make_tuple(
53  typename link_t::client_link_t::ctor_args{
54  boost::asio::ip::address_v4::from_string(vm["client_address"].as<std::string>()),
55  vm["client_port"].as<unsigned short>(),
56  typename link_t::client_link_t::proc_rules_t(*seq_num)
57  },
58  conn_pol_t(
59  typename conn_pol_t::gateways_t(
60  std::make_pair(boost::asio::ip::address_v4::from_string(vm[(MIC_code+"_primary_gateway_address").c_str()].as<std::string>()), vm[(MIC_code+"_gateway_port").c_str()].as<unsigned short>())
61  ),
62  typename conn_pol_t::logon_args_t{
63  vm[(MIC_code+"_sequence_number").c_str()].as<unsigned>(),
64  sess_sub_id_conv,
65  user_conv,
66  pass_conv,
67  vm[(MIC_code+"_no_unspec_replay").c_str()].as<bool>()
68  },
69  exchanges::BATSBOE::common::logoff_args_t{
70  *seq_num
71  }
72  ),
73  typename link_t::exchg_to_client_proc_rules_t(*seq_num),
74  seq_num
75  );
76  }
77  );
78 }
79 
80 } } }