OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.4.2
API documentation
BaseHandlerImp.cpp
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 #include <boost/scope_exit.hpp>
20 #include <boost/foreach.hpp>
21 #include <boost/format.hpp>
22 
23 #include <OnixS/HandlerCore/MulticastFeedHandler.h>
24 
26 
28 
29 #include "BaseHandlerImp.h"
30 
31 
32 using namespace OnixS;
33 using namespace OnixS::Util;
34 using namespace OnixS::HandlerCore::Common;
35 
36 
37 namespace OnixS {
38 namespace Eurex {
39 namespace MarketData {
40 namespace Implementation {
41 
42 
43 const Licensing::ProductId productId = 67;
44 
45 BaseHandlerImp::BaseHandlerImp(
46  const std::string& name,
47  Logging::LogFacility* parent, unsigned short maxPacketSize, const std::string& licenseDir)
48  : Licensing::LicenseChecker(licenseDir, productId)
49  , MulticastFeedHandler(name, parent, maxPacketSize)
50 {
51 }
52 
54 {
55  BOOST_ASSERT(getState() == State::Stopped);
56 }
57 
58 void BaseHandlerImp::commonLog(int logLevel, const char * msg, size_t length)
59 {
60  BOOST_ASSERT(msg != nullptr);
61  BOOST_ASSERT(length != 0);
62 
63  if (logLevel < OnixS::Logging::MIN_LOG_LEVEL || logLevel > OnixS::Logging::MAX_LOG_LEVEL)
64  throw OperationException (
65  BOOST_CURRENT_FUNCTION,
66  (boost::format("An error occurred during log operation. Invalid log level (logLevel=%d).")
67  % logLevel).str().c_str()
68  );
69 
70  static const std::string userLogFacilityName = "USER";
71 
72  log (
73  OnixS::Logging::LogMsg(
74  OnixS::Logging::LogLevel(logLevel))[userLogFacilityName] << OnixS::Util::ValuePtr(msg, length)
75  );
76 }
77 
79 {
80  try
81  {
82  BOOST_ASSERT(lock());
83 
84  lock()->acquire();
85 
86  BOOST_SCOPE_EXIT(this_) {
87  this_->lock()->release();
88  } BOOST_SCOPE_EXIT_END
89 
90  MulticastFeedHandler::start();
91  }
92  catch (const std::exception& ex)
93  {
94  reportError(TextBuilder() << "Exception while starting: " << ex.what());
95  throw;
96  }
97  catch (...)
98  {
99  reportError("Unknown exception while starting!");
100  throw;
101  }
102 }
103 
105 {
106  try
107  {
108  BOOST_ASSERT(lock());
109 
110  lock()->acquire();
111 
112  BOOST_SCOPE_EXIT(this_) {
113  this_->lock()->release();
114  } BOOST_SCOPE_EXIT_END
115 
116  MulticastFeedHandler::stop();
117  }
118  catch (const std::exception& ex)
119  {
120  reportError(TextBuilder() << "Exception while stopping: " << ex.what());
121  throw;
122  }
123  catch (...)
124  {
125  reportError("Unknown exception while stopping!");
126  throw;
127  }
128 }
129 
130 void BaseHandlerImp::start(const ReplayOptions& options, const LogPlayerLinks& links, const std::string& feedName)
131 {
132  if (options.logs.size() > 0)
133  {
134  TextBuilder tb;
135  tb << "Log file to replay: ";
136 
137  BOOST_FOREACH(const std::string& item, options.logs)
138  {
139  tb << '\n' << item;
140  }
141 
142  log(ONIXS_LOG_INFO[this] << tb.toString());
143  }
144 
145  // 20141013-05:36:50.893 [EOBI.Incremental] 490913 Packet received (IADLMv////+hfQcAZwAAAAIBAAAAAAAAkP8wdyywnBMQAMky/////3liAAAAAAAA).
146  const std::string parser = "(\\S+).*\\[" + feedName + "\\.(\\w+)\\].*Packet received \\((.*)\\)\\.";
147 
148  const float playSpeedMultiplier = options.replayMode == ReplayMode::ConstantPacketReplayDelay ? 0 : options.playSpeedMultiplier;
149 
150  boost::function<void(const std::string&)> onReplayError =
151  boost::bind(&ReplayListener::onReplayError, options.listener, _1);
152 
153  HandlerCore::MarketData::MulticastFeedHandler::startReplay(
154  options.logs,
155  playSpeedMultiplier,
156  options.packetReplayDelay,
157  links,
158  onReplayError,
159  boost::bind(&ReplayListener::onReplayFinished, options.listener),
160  parser,
161  0,
162  1,
163  2
164  );
165 }
166 
167 std::string os()
168 {
169 #if BOOST_OS_WINDOWS
170  return "Windows";
171 #elif BOOST_OS_UNIX
172  std::string res = "Linux";
173  res += ", ";
174  res += __VERSION__;
175  return res;
176 #else
177 # error "Unknown OS"
178 #endif
179 }
180 
181 }
182 }
183 }
184 }
const Licensing::ProductId productId
Util::TextBuilder TextBuilder
Definition: Formatting.h:43
void commonLog(int logLevel, const char *msg, size_t length)
User&#39;s common log.
Definition: Defines.h:30
ReplayMode::Enum replayMode
Replay mode. The default value is ReplayMode::ConstantPacketReplayDelay.
Definition: Replay.h:96
Defines params which affect logs replay.
Definition: Replay.h:77
virtual void onReplayFinished()=0
Is called once all the logs are replayed.
ReplayListener * listener
Instance to notify about replay events.
Definition: Replay.h:84
virtual void onReplayError(const std::string &errorDescription)=0
Is called once error occurs while replaying logs.