OnixS C++ SGX Titan OUCH Trading Handler  1.2.0
API documentation
HandlerImpl.h
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 #pragma once
20 
21 #include <queue>
22 
23 #include <logging/LogFacility.h>
24 #include <licensing/LicenseChecker.h>
25 
26 #include <OnixS/HandlerCore/HandlerLogger.h>
27 
28 #include <OnixS/ItchCore/SoupBinTCP/ReconnectableSession.h>
29 
33 
34 #include "Utils.h"
35 
36 
37 namespace OnixS {
38 namespace SgxTitan {
39 namespace Trading {
40 namespace Ouch {
41 
42 class OutgoingMessage;
43 
44 namespace Implementation {
45 
46 class ListenerHolder;
47 
48 class AuditTrailDumper;
49 
50 
51 class HandlerImpl :
52  public Licensing::LicenseChecker,
53  public OnixS::Logging::LogFacility,
54  private OnixS::ItchCore::SoupBinTCP::ReconnectableSessionListener
55 {
56  typedef Logging::LogFacility base;
57 
58 public:
59  explicit HandlerImpl (const HandlerSettings & settings);
60  virtual ~HandlerImpl ();
61 
63 
64  template <typename TMsg>
65  void log (const TMsg & msg) { logger_->log (msg); }
66 
67  template <typename TMsg>
68  void forceLog (const TMsg & msg) { logger_->getLogger().forceLog (msg); }
69 
70  void commonLog (int logLevel, const char * msg, size_t length);
71 
72  ListenerHolder* listenerHolder () { return listenerHolder_.get(); }
73 
74  void connect (const LogonSettings& logonSettings,
75  const std::string& hostName,
76  UInt16 port,
77  const std::string& localNetworkInterface);
78 
79  void disconnect ();
80  void disconnectAsync ();
81 
82  void send (const OutgoingMessage& message, bool warmupMode = false);
83 
84 
85  UInt64 nextExpectedSequenceNumber() const;
86  std::string sessionId() const;
87 
88 private:
89  void runAuditTrail();
90  void checkState(HandlerState::Enum expectedState) const;
91 
92  void onError(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const std::string&) final;
93  void onWarning(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const std::string&) final;
94  void onStateChange(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
95  OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum oldState,
96  OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum newState) final;
97  void onData(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const void* data, UInt16 size) final;
98 
99  void processData(const void* dataPtr, UInt16 messageLength);
100 
101  std::string os();
102 
103 private:
104  HandlerSettings const settings_;
105 
106  boost::scoped_ptr<OnixS::HandlerCore::Common::HandlerLogger> const logger_;
107  boost::scoped_ptr<ListenerHolder> const listenerHolder_;
108  boost::scoped_ptr<AuditTrailDumper> auditTrailDumper_;
109 
110  mutable HandlerCore::MarketData::FE::AtomicState<HandlerState::Enum> externalState_;
111  boost::scoped_ptr<OnixS::ItchCore::SoupBinTCP::ReconnectableSession> session_;
112 
113 
114  typedef OnixS::Concurrency::RecursiveMutex Mutex;
115  typedef OnixS::Concurrency::Guard<OnixS::Concurrency::Mutex> Guard;
116 
117  mutable Mutex sessionLock_;
118 
119 };
120 
121 } // namespace Implementation
122 
123 
125 {
127 
128 public:
129  explicit Impl(const HandlerSettings & settings)
130  : base(settings)
131  {}
132 };
133 
135 
void connect(const LogonSettings &logonSettings, const std::string &hostName, UInt16 port, const std::string &localNetworkInterface)
void send(const OutgoingMessage &message, bool warmupMode=false)
Enum
Defines the state that the handler is in.
Impl(const HandlerSettings &settings)
Definition: HandlerImpl.h:129
void commonLog(int logLevel, const char *msg, size_t length)
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_END
Definition: Bootstrap.h:31