19 #include <boost/bind.hpp> 20 #include <boost/current_function.hpp> 21 #include <boost/format.hpp> 23 #include <system/Directory.h> 24 #include <util/Base64Encoding.h> 25 #include <util/HexEncoding.h> 26 #include <licensing/LicenseManager.h> 28 #include <OnixS/HandlerCore/HandlerLogger.h> 29 #include <OnixS/HandlerCore/Utils.h> 30 #include <OnixS/HandlerCore/Compiler.h> 49 : Licensing::LicenseChecker(settings.licenseDirectory,
productId)
50 , base(
"Handler", nullptr, static_cast<Logging::
LogLevel>(settings.logLevel))
52 , logger_(new
OnixS::HandlerCore::Common::HandlerLogger(
OnixS::HandlerCore::Common::convertLogSettings(settings)))
57 LogFacility facility(
"Handler",
nullptr, Logging::LOG_LEVEL_DEBUG);
60 <<
"OnixS C++ SGX TITAN OUCH Trading Handler, version " 66 forceLog(ONIXS_LOG_INFO[&facility] << settings_);
71 void HandlerImpl::onError(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
const std::string& what)
73 BOOST_ASSERT(listenerHolder_);
77 void HandlerImpl::onWarning(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
const std::string& what)
79 BOOST_ASSERT(listenerHolder_);
80 listenerHolder_->invokeWarning(what);
83 void HandlerImpl::onStateChange(
84 OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
85 OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum ,
86 OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum newState)
88 externalState_.change(static_cast<HandlerState::Enum>(newState));
90 BOOST_ASSERT(listenerHolder_);
91 listenerHolder_->invokeStateChanged(externalState_.read());
94 void HandlerImpl::onData(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
const void* data, UInt16 size)
96 BOOST_ASSERT(listenerHolder_);
97 listenerHolder_->invokeReceivedBytes(static_cast<const char*>(data), size);
99 processData(data, size);
106 Guard guard (sessionLock_);
108 BOOST_ASSERT(session_);
109 return session_->receivingSeqNo();
116 Guard guard (sessionLock_);
118 BOOST_ASSERT(session_);
119 return session_->sessionId();
122 void HandlerImpl::runAuditTrail()
128 if (auditTrailDir.find_last_of(
"\\/") != auditTrailDir.length() - 1)
129 auditTrailDir.append(
"/");
131 if (!OnixS::System::Directory::exists(auditTrailDir))
132 OnixS::System::Directory::create(auditTrailDir);
136 auditTrailDumper_.reset(
137 new AuditTrailDumper(
144 catch (
const std::exception& ex)
146 throw OperationException(BOOST_CURRENT_FUNCTION, OnixS::Util::format(
"Can't create Audit Trail file: %s", ex.what()).c_str());
166 if (auditTrailDumper_)
167 auditTrailDumper_->stop();
174 return externalState_.read();
179 BOOST_ASSERT(msg !=
nullptr);
180 BOOST_ASSERT(length != 0);
182 if (logLevel < OnixS::Logging::MIN_LOG_LEVEL || logLevel > OnixS::Logging::MAX_LOG_LEVEL)
184 BOOST_CURRENT_FUNCTION,
185 (boost::format(
"An error occurred during log operation. Invalid log level (logLevel=%d).")
186 % logLevel).str().c_str()
189 static const std::string userLogFacilityName =
"USER";
192 OnixS::Logging::LogMsg(
193 OnixS::Logging::LogLevel(logLevel))[userLogFacilityName] << OnixS::Util::ValuePtr(msg, length)
198 const std::string& hostName,
200 const std::string& localNetworkInterface)
202 ItchCore::SoupBinTCP::ReconnectableSessionSettings settings;
208 ItchCore::SoupBinTCP::ConnectivitySettings connectivitySettings;
209 connectivitySettings.connectionA = ItchCore::SoupBinTCP::ValidatedNetFeedConnection(hostName, port, localNetworkInterface);
210 connectivitySettings.authenticationSettings.userName = logonSettings.
userName;
211 connectivitySettings.authenticationSettings.password = logonSettings.
password;
212 connectivitySettings.authenticationSettings.session = logonSettings.
session;
213 connectivitySettings.initialSequenceNumber = logonSettings.
sequenceNumber;
216 Guard guard (sessionLock_);
219 new ItchCore::SoupBinTCP::ReconnectableSession(settings, connectivitySettings,
this,
this)
222 session_->setLogger(logger_.get());
234 Guard guard (sessionLock_);
238 session_->disconnect(
false);
247 Guard guard (sessionLock_);
251 session_->disconnect(
true);
259 if (auditTrailDumper_)
260 auditTrailDumper_->onOutboundMessage(msg, warmupMode);
265 log(ONIXS_LOG_DEBUG[
this] <<
"Sending " << msg);
267 Guard guard (sessionLock_);
269 BOOST_ASSERT(session_);
276 if (state!= expectedState)
277 throw OnixS::DomainException(
278 (boost::format(
"Wrong state = %s, expected = %s.") %
toStr(state) %
toStr(expectedState)).str()
282 std::string HandlerImpl::os()
287 std::string res =
"Linux";
void connect(const LogonSettings &logonSettings, const std::string &hostName, UInt16 port, const std::string &localNetworkInterface)
unsigned int sendTimeoutMs
ConnectionRetries connectionRetries
const OnixS::Licensing::ProductId productId
const void * binary() const
Message content.
void send(const OutgoingMessage &message, bool warmupMode=false)
std::string auditTrailDirectory
Identifies errors of generic nature.
std::string sessionId() const
Enum
Defines the state that the handler is in.
MessageSize binarySize() const
Size of message.
CpuIndexes auditTrailThreadAffinity
UInt64 nextExpectedSequenceNumber() const
std::string session
Requested Session.
void log(const TMsg &msg)
void commonLog(int logLevel, const char *msg, size_t length)
std::string userName
Username.
unsigned int receiveTimeoutMs
ONIXS_SGXTITAN_OUCH_API void toStr(std::string &, OutboundMessageTypes::Enum)
Appends string presentation of object.
Defines the state that the handler is in.
void forceLog(const TMsg &msg)
size_t auditTrailFileMaxSize
std::string password
Password.
HandlerState::Enum getState()
std::string auditTrailFile