OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
GlimpseService.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 <boost/function.hpp>
22 #include <boost/scoped_ptr.hpp>
23 
24 #include <OnixS/ItchCore/Types.h>
25 #include <OnixS/ItchCore/SoupBinTCP/ReconnectableSession.h>
26 
27 #include "NamespaceHelper.h"
28 
29 namespace OnixS {
30 namespace HandlerCore {
31 namespace Common {
32  class HandlerLogger;
33 }}}
34 
35 ONIXS_HANDLER_NAMESPACE_BEGIN
36 
37 struct HandlerSettings;
38 
39 class GlimpseService : public Logging::LogFacility, private OnixS::ItchCore::SoupBinTCP::ReconnectableSessionListener
40 {
41 public:
42  typedef boost::function<void(const std::string&)> OnFailureCallback;
43  typedef boost::function<void(const std::string&)> OnWarningCallback;
44 
45  typedef boost::function<void(const DataSource&, const IncomingMessage*)> OnMessageCallback;
46  typedef boost::function<void()> OnRestartedCallback;
47 
49  const HandlerSettings& settings,
50  const Logging::LogFacility* parent,
51  HandlerCore::Common::HandlerLogger* logger);
52 
53  virtual ~GlimpseService();
54 
55  void request(const OnixS::ItchCore::SessionType& session, SequenceNumber requestedSequence);
56 
57  void stop(bool wait);
58 
59  bool inProgress() const;
60 
61  void subscribeOnFailure(OnFailureCallback callback);
62  void subscribeOnWarning(OnWarningCallback callback);
63  void subscribeOnMessage(OnMessageCallback callback);
64  void subscribeOnRestarted(OnRestartedCallback callback);
65 
66 
67 
68 private:
69  template<typename TMsg>
70  void log (const TMsg & msg) { if(logger_) logger_->log (msg); }
71 
72  void processData(OnixS::ItchCore::SoupBinTCP::ReconnectableSession& session, const void* data, UInt16 size);
73 
74  void invokeOnFailure(const std::string&);
75  void invokeOnWarning(const std::string&);
76 
77  void invokeOnMessage(const DataSource&, const IncomingMessage&);
78  void invokeOnRestarted();
79 
80 
81  void onError(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const std::string&) override;
82  void onWarning(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const std::string&) override;
83  void onStateChange(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&,
84  OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum oldState,
85  OnixS::ItchCore::SoupBinTCP::ReconnectableSessionState::Enum newState) override;
86  void onData(OnixS::ItchCore::SoupBinTCP::ReconnectableSession&, const void* data, UInt16 size) override;
87 
88 private:
89  const HandlerSettings& settings_;
90  const OnixS::ItchCore::SoupBinTCP::ReconnectableSessionSettings sessionSettings_;
91  OnixS::ItchCore::SoupBinTCP::ConnectivitySettings sessionConnectivitySettings_;
92  HandlerCore::Common::HandlerLogger* logger_;
93 
94  boost::scoped_ptr<OnixS::ItchCore::SoupBinTCP::ReconnectableSession> session_;
95 
96  boost::atomic_bool inProgress_;
97 
98  OnFailureCallback onFailureCallback_;
99  OnWarningCallback onWarningCallback_;
100  OnMessageCallback onMessageCallback_;
101  OnRestartedCallback onRestartedCallback_;
102 
103  typedef OnixS::Concurrency::RecursiveMutex Mutex;
104  typedef OnixS::Concurrency::Guard<OnixS::Concurrency::Mutex> Guard;
105 
106  mutable Mutex sessionLock_;
107  std::string sessionId_;
108 };
109 
110 
111 ONIXS_HANDLER_NAMESPACE_END
112 
boost::function< void(const DataSource &, const IncomingMessage *)> OnMessageCallback
UInt64 SequenceNumber
Alias for Sequence Number type.
Definition: Defines.h:37
boost::function< void(const std::string &)> OnFailureCallback
boost::function< void(const std::string &)> OnWarningCallback