libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_to_link_main_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2017 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, class Operation>
22 inline int
23 fix_to_link::main(int argc, char const * const *argv, boost::program_options::options_description &&all, Operation &&op) noexcept(true) {
24  using namespace libjmmcg;
25  using link_t=Link;
26  using thread_traits=typename link_t::thread_traits;
27 
28  try {
29  boost::program_options::variables_map vm;
30  boost::program_options::store(boost::program_options::parse_command_line(argc, argv, all), vm);
31  if (vm.count("help")) {
32  std::cout<<all<<std::endl;
34  }
35  if (vm.count("version")) {
36  std::cout<<LIBJMMCG_DETAILED_VERSION_INFO " Built with FIX: " ISIMUD_FIX_EXCHANGE_VERSION ", MICs generated on: '" ISIMUD_ISO_10383_MIC_XML_GENERATED_DATE "', currency-codes created on: '" ISIMUD_ISO_4217_CURRENCY_CODES_XML_GENERATED_DATE "' and country-codes generated on: '" ISIMUD_ISO_3166_COUNTRY_CODES_XML_GENERATED_DATE "'" << std::endl;
38  }
39  boost::program_options::notify(vm);
40 
41  thread_traits::set_backtrace_on_signal();
42  auto const ctor_args=op(vm);
43  const std::size_t num_timestamps=vm["num_timings"].as<std::size_t>();
44  latency_timestamps timestamps(num_timestamps);
45  {
46  link_t link(
47  std::get<0>(ctor_args),
48  std::get<1>(ctor_args),
51  std::get<2>(ctor_args),
52  timestamps,
53  "link" LIBJMMCG_ENQUOTE(__LINE__)
54  );
55  std::clog<<link<<std::endl;
56  thread_traits::set_kernel_affinity(
57  thread_traits::get_current_thread(),
58  typename thread_traits::api_params_type::processor_mask_type(common::thread_traits::main_thread.core)
59  );
60  thread_traits::set_kernel_priority(
61  thread_traits::get_current_thread(),
62  common::thread_traits::main_thread.priority
63  );
64  while (!link.signal_status()) {
65  thread_traits::sleep(0);
66  }
67  std::clog<<link<<std::endl;
68  }
69  timestamps.write_to_csv_file(std::clog, argv[0]);
71  } catch (std::exception const &ex) {
72  std::cerr<<"STL-derived exception. Details: "<<boost::diagnostic_information(ex)<<std::endl;
74  } catch (...) {
75  std::cerr<<"Unknown exception."<<std::endl;
77  }
79 }
80 
81 } } }