OnixS C++ FIX Engine  4.13.0
API Documentation
ISessionListener.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 
20 #pragma once
21 
22 #include <string>
23 
28 
29 namespace OnixS {
30 namespace FIX {
31 ONIXS_FIXENGINE_API_DECL(class, Message);
32 ONIXS_FIXENGINE_API_DECL(class, FlatMessage);
33 ONIXS_FIXENGINE_API_DECL(class, Session);
34 
35 /// The error reason.
36 struct ErrorReason {
37  enum Enum {
38  /// The general system-related error.
40 
41  /// The first message received is not a Logon message.
43 
44  /// The incoming message has a sequence number less than expected and the PossDupFlag is not set, it indicates a serious error.
45  /// It is strongly recommended that the session be terminated and a manual intervention be initiated.
47 
48  /// The FIX Connection cannot be restored.
50 
51  /// An exception was thrown during processing of the incoming message.
53 
54  /// The FIX message received is not valid.
56 
57  /// An exception was thrown in the client event handler implementation.
59 
60  /// Socket options cannot be set.
62  };
63 };
64 
65 /// The warning reason.
66 struct WarningReason {
67  enum Enum {
68  /// The general system-related warning
70 
71  /// A garbled message is received.
73 
74  /// The telecommunication link error is detected.
76 
77  /// The sequence gap in the incoming messages is detected.
79 
80  /// The ResendTimeout is elapsed.
82 
83  /// Cannot re-establish the FIX Connection after the reconnect attempt.
84  CannotConnect
85  };
86 };
87 
88 /// Represents a timestamp of the received data.
89 /// If the source is `None`, no timestamp is available.
91 {
92 public:
93 
94  enum Source
95  {
96  /// No timestamp available.
98 
99  /// Timestamp provided by the OS kernel / user-level network stack.
101 
102  /// Timestamp provided by the network card.
103  Hardware
104  };
105 
106  ReceivedDataTimestamp():timestamp_(), source_(Source::None) { }
107 
108  ReceivedDataTimestamp(const Timestamp & timestamp, Source source):timestamp_(timestamp), source_(source) { }
109 
110  /// Returns the received data timestamp.
111  const Timestamp & timestamp() const
112  {
113  return timestamp_;
114  }
115 
116  /// Returns the source of the received data timestamp.
117  Source source() const
118  {
119  return source_;
120  }
121 
122  /// Returns a human-readable presentation.
123  std::string toString() const
124  {
125  const std::string TimeStr = timestamp_.toString();
126  std::string str = "ReceivedDataTimestamp [source = ";
127 
128  if(source_ == ReceivedDataTimestamp::None)
129  str += "None";
130  else if(source_ == ReceivedDataTimestamp::Software)
131  str += "Software, time = " + TimeStr;
132  else if (source_ == ReceivedDataTimestamp::Hardware)
133  str += "Hardware, time = " + TimeStr;
134  else
135  str += "Unknown";
136 
137  str += "]";
138  return str;
139  }
140 
141 private:
142 
143  /// The timestamp.
144  Timestamp timestamp_;
145  Source source_;
146 };
147 
148 /// The session's Listener.
150 {
151 public:
152  /// @note the FIX Engine/Session does NOT manage the lifetime of this listener.
154 
155  /// Is called when the message mode is `Message` and the application-level message is received from the counterparty.
156  ///
157  /// @note: do no call the base method if you have overridden it in the derived class.
158  virtual void onInboundApplicationMsg(Message & message, Session * session) = 0;
159 
160  /// Is called when the message mode is `FlatMessage` and the application-level message is received from the counterparty.
161  ///
162  /// @note: do no call the base method if you have overridden it in the derived class.
164 
165  /// Is called when the message mode is `Message` and the session-level message is received from the counterparty.
166  /// @note: do no call the base method if you have overridden it in the derived class.
167  virtual void onInboundSessionMsg(Message & /*message*/, Session * /*session*/) {}
168 
169  /// Is called when the message mode is `FlatMessage` and the session-level message is received from the counterparty.
170  /// @note: do no call the base method if you have overridden it in the derived class.
171  virtual void onInboundSessionMsg(FlatMessage & /*message*/, Session * /*session*/) {}
172 
173  /// Is called when the application-level message is sent to the counterparty.
174  ///
175  /// @note: do no call the base method if you have overridden it in the derived class.
176  /// @note: The message's sequence number is the preliminary one.
177  ///
178  /// @warning: It is called under the session's lock.
179  virtual void onOutboundApplicationMsg(Message & /*message*/, Session * /*session*/) {}
180 
181  /// Is called when the session-level message is sent to the counterparty.
182  ///
183  /// @note: do no call the base method if you have overridden it in the derived class.
184  /// @note: The message's sequence number is the preliminary one.
185  ///
186  /// @warning: It is called under the session's lock.
187  virtual void onOutboundSessionMsg(Message & /*message*/, Session * /*session*/) {}
188 
189  /// Is called as soon as bytes are received from the wire.
190  virtual void onReceivedBytes(const char * /*bytes*/, size_t /*size*/, const ReceivedDataTimestamp & /*timestamp*/, Session* /*session*/) {}
191 
192  /// Is called just before the FIX message is sent to the wire.
193  ///
194  /// @warning: It is called under the session's lock.
195  virtual void onMessageSending(SequenceNumber /*msgSeqNum*/, char * /*bytes*/, size_t /*size*/, Session * /*session*/) {}
196 
197  /// Is called when the session changes its state.
198  virtual void onStateChange(SessionState::Enum /*newState*/, SessionState::Enum /*prevState*/, Session * /*session*/) {}
199 
200  /// Is called when the message mode is `Message` and the sent application-level message is about to be
201  /// re-sent to the counterparty in reply to the ResendRequest<2> message.
202  ///
203  /// @return `true` if the message should be re-sent, otherwise - `false`.
204  virtual bool onResendRequest(Message & /*message*/, Session * /*session*/) { return false; }
205 
206  /// Is called when the message mode is `FlatMessage` and the sent application-level message is about to be
207  /// re-sent to the counterparty in reply to the ResendRequest<2> message.
208  ///
209  /// @return `true` if the message should be re-sent, otherwise - `false`.
210  virtual bool onResendRequest(FlatMessage & /*message*/, Session * /*session*/) { return false; }
211 
212  /// Is called when the ResendRequest<2> message is received and the session is about to start to resend messages.
213  virtual void onResendingStarted(SequenceNumber /*beginSeqNo*/, SequenceNumber /*endSeqNo*/, Session* /*session*/) {}
214 
215  /// Is called when the resending process is completed.
216  virtual void onResendingFinished(SequenceNumber /*beginSeqNo*/, SequenceNumber /*endSeqNo*/, Session* /*session*/) {}
217 
218  /// Is called when an error condition is detected.
219  virtual void onError(ErrorReason::Enum /*reason*/, const std::string & /*description*/, Session * /*session*/) {}
220 
221  /// Is called when a warning condition is detected.
222  virtual void onWarning(WarningReason::Enum /*reason*/, const std::string & /*description*/, Session * /*session*/) {}
223 };
224 }
225 }
The FIX Session - a bi-directional stream of ordered messages between two parties within a continuous...
Definition: Session.h:97
virtual void onStateChange(SessionState::Enum, SessionState::Enum, Session *)
Is called when the session changes its state.
The warning reason.
virtual void onWarning(WarningReason::Enum, const std::string &, Session *)
Is called when a warning condition is detected.
virtual void onResendingStarted(SequenceNumber, SequenceNumber, Session *)
Is called when the ResendRequest<2> message is received and the session is about to start to resend m...
virtual void onInboundApplicationMsg(FlatMessage &, Session *)
Is called when the message mode is FlatMessage and the application-level message is received from the...
virtual void onReceivedBytes(const char *, size_t, const ReceivedDataTimestamp &, Session *)
Is called as soon as bytes are received from the wire.
The sequence gap in the incoming messages is detected.
The session&#39;s Listener.
#define ONIXS_FIXENGINE_DEFAULT
Definition: Compiler.h:194
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
The incoming message has a sequence number less than expected and the PossDupFlag is not set...
Provides an access to FIX fields from a flat (tag=value) message.
Definition: FlatMessage.h:109
An exception was thrown during processing of the incoming message.
The first message received is not a Logon message.
virtual void onInboundSessionMsg(Message &, Session *)
Is called when the message mode is Message and the session-level message is received from the counter...
virtual void onError(ErrorReason::Enum, const std::string &, Session *)
Is called when an error condition is detected.
virtual bool onResendRequest(FlatMessage &, Session *)
Is called when the message mode is FlatMessage and the sent application-level message is about to be ...
virtual bool onResendRequest(Message &, Session *)
Is called when the message mode is Message and the sent application-level message is about to be re-s...
std::string toString() const
Returns a human-readable presentation.
ReceivedDataTimestamp(const Timestamp &timestamp, Source source)
Timestamp provided by the network card.
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
Timestamp provided by the OS kernel / user-level network stack.
Represents a timestamp of the received data.
The error reason.
The general system-related error.
virtual void onOutboundApplicationMsg(Message &, Session *)
Is called when the application-level message is sent to the counterparty.
An exception was thrown in the client event handler implementation.
The general system-related warning.
virtual void onOutboundSessionMsg(Message &, Session *)
Is called when the session-level message is sent to the counterparty.
The FIX Connection cannot be restored.
unsigned int SequenceNumber
Alias for the sequence number.
virtual void onInboundSessionMsg(FlatMessage &, Session *)
Is called when the message mode is FlatMessage and the session-level message is received from the cou...
const Timestamp & timestamp() const
Returns the received data timestamp.
The ResendTimeout is elapsed.
Encapsulates operations over a FIX Message.
Definition: Message.h:49
The FIX message received is not valid.
The timestamps related functionality.
Definition: Timestamp.h:91
The telecommunication link error is detected.
Source source() const
Returns the source of the received data timestamp.
virtual void onResendingFinished(SequenceNumber, SequenceNumber, Session *)
Is called when the resending process is completed.
virtual void onMessageSending(SequenceNumber, char *, size_t, Session *)
Is called just before the FIX message is sent to the wire.