OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
SessionException.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 <OnixS/B3/BOE/Defines.h>
25 
26 #include <string>
27 
28 #if WIN32
29 #pragma warning(push)
30 #pragma warning(disable : 4275)
31 #pragma warning(disable : 4251)
32 #endif
33 
34 namespace OnixS {
35 namespace B3 {
36 namespace BOE {
37 namespace Exceptions{
38 
39 /**
40  * A Session-related exception.
41  */
42 class ONIXS_B3_BOE_EXPORTED SessionException : public std::exception
43 {
44 public:
45  SessionException(SessionErrorReason::Enum reason, const std::string& message);
46 
47  SessionException(SessionErrorReason::Enum reason, const std::string& message, const std::exception& cause);
48 
50 
51  const char* what() const ONIXS_B3_BOE_NOTHROW ONIXS_B3_BOE_OVERRIDE;
52 
54  {
55  return reason_;
56  }
57 
58  const std::string& toString() const ONIXS_B3_BOE_NOTHROW
59  {
60  return message_;
61  }
62 
63 private:
64  std::string message_;
66 };
67 
68 
70  : public SessionException
71 {
72 public:
73  SbeMessageAttachedExceptionBase(SessionErrorReason::Enum reason, const std::string& message, Messaging::SbeMessage sbeMessage);
74 
75  Messaging::SbeMessage receivedMessage() const;
76 
78 
79 private:
80  std::vector<unsigned char> buffer_;
81 };
82 
83 template <typename MessageType>
85 {
86 public:
88  : SbeMessageAttachedExceptionBase(reason, message, sbeMessage)
89  {}
90 
92  {
93  return Messaging::typify<MessageType>(SbeMessageAttachedExceptionBase::receivedMessage());
94  }
95 };
96 
97 /**
98  * An unexpected message type is received.
99  */
102 {
103 public:
105 
106  Messaging::MessageTemplateId templateId() const;
107 
109 };
110 
111 /**
112  * A telecommunication link error is detected.
113  */
115  : public SessionException
116 {
117 public:
118  explicit LinkErrorException(const std::string& rejectReason);
119 
121 };
122 
123 /**
124  * An unexpected message sequence number is detected.
125  */
128 {
129 public:
130  UnexpectedSequenceNumberException(Messaging::SbeMessage receivedMessage, const std::string& rejectReason,
131  SeqNumber actualSeqNum, SeqNumber expectedSeqNum, Messaging::UInt64 sessionVerId);
132 
134 
136  {
137  return actualSeqNum_;
138  }
139 
141  {
142  return expectedSeqNum_;
143  }
144 
145  Messaging::UInt64 sessionVerId() const ONIXS_B3_BOE_NOTHROW
146  {
147  return sessionVerId_;
148  }
149 
150 private:
151  SeqNumber actualSeqNum_;
152  SeqNumber expectedSeqNum_;
153  Messaging::UInt64 sessionVerId_;
154 };
155 
156 /**
157  * A response has not been received during the specified timeout.
158  */
160  : public SessionException
161 {
162 public:
163  explicit ResponseTimeoutException(const std::string& rejectReason, int timeoutMilliseconds)
164  : SessionException(SessionErrorReason::LinkErrorIsDetected, rejectReason)
165  , timeout_(timeoutMilliseconds)
166  {}
167 
169 
170  /// @return timeout in milliseconds
172  {
173  return timeout_;
174  }
175 
176 private:
177  int timeout_; ///< timeout in milliseconds.
178 };
179 
180 
181 /**
182  * The program is finishing its execution.
183  */
185  : public SessionException
186 {
187 public:
189 
191 };
192 
193 /// The telecommunication link cannot be established.
195  : public SessionException
196 {
197 public:
198  /// Constructor.
199  ///
200  /// \param errCode system error code (if present).
201  /// \param rejectReason the telecommunication link error description.
202  CannotEstablishLinkException(int errCode, const std::string& rejectReason);
203 
205 
206  int errCode() const ONIXS_B3_BOE_NOTHROW;
207 
208 private:
209  int errCode_;
210 };
211 
212 
213 /**
214  * The Negotiate message is rejected by the exchange.
215  */
217  : public TypedSbeMessageAttachedExceptionBase<Messaging::NegotiateReject3>
218 {
219 public:
221 
223 
224  Messaging::NegotiationRejectCode::Enum errorCodes() const;
225 };
226 
227 /**
228  * The Establish message is rejected by the exchange.
229  */
231  : public TypedSbeMessageAttachedExceptionBase<Messaging::EstablishReject6>
232 {
233 public:
235 
237 
238  Messaging::EstablishRejectCode::Enum errorCodes() const;
239 };
240 
241 /// Received the Terminate message
242 /// in reply to the Establish or Negotiate messages.
244  : public TypedSbeMessageAttachedExceptionBase<Messaging::Terminate7>
245 {
246 public:
248 
250 
251  Messaging::TerminationCode::Enum errorCodes() const;
252 };
253 
254 /// Received the BusinessReject message
255 /// in reply to the Establish or Negotiate messages.
257  : public TypedSbeMessageAttachedExceptionBase<Messaging::BusinessMessageReject206>
258 {
259 public:
261 
263 
264  Messaging::RejReason errorCodes() const;
265 
266  std::string text() const;
267 };
268 
269 }
270 }
271 }
272 }
273 
274 #if WIN32
275 #pragma warning(pop)
276 #endif
NegotiateReject message is sent when B3 rejects a Negotiate message sent by the client.
Definition: Messages.h:932
The Establish message is rejected by the exchange.
Enum
Identifies the code of reject establishment.
Definition: Fields.h:1236
Terminate message is sent to indicate that the sender is going to disconnect the TCP socket connectio...
Definition: Messages.h:2509
#define ONIXS_B3_BOE_NOTHROW
Definition: Compiler.h:182
#define ONIXS_B3_BOE_EXPORTED
Definition: Compiler.h:181
A response has not been received during the specified timeout.
Enum
Identifies the code of termination.
Definition: Fields.h:1300
UInt32 RejReason
Code to identify reason for order rejection.
Definition: Fields.h:225
The Negotiate message is rejected by the exchange.
Enum
Identifies the code of reject negotiation.
Definition: Fields.h:1178
BusinessMessageReject message can reject an application-level message which fulfills session level ru...
Definition: Messages.h:16229
Received the BusinessReject message in reply to the Establish or Negotiate messages.
Definition: Defines.h:40
const std::string & toString() const noexcept
EstablishmentReject message is sent when an Establish message is rejected by B3 informing the reason ...
Definition: Messages.h:2148
Received the Terminate message in reply to the Establish or Negotiate messages.
Messaging::UInt32 SeqNumber
Definition: Messaging.h:52
A telecommunication link error is detected.
#define ONIXS_B3_BOE_OVERRIDE
Definition: Compiler.h:186
TypedSbeMessageAttachedExceptionBase(SessionErrorReason::Enum reason, const std::string &message, Messaging::SbeMessage sbeMessage)
An unexpected message sequence number is detected.
#define ONIXS_B3_BOE_DEFAULT
Definition: Compiler.h:208
The telecommunication link cannot be established.
SessionErrorReason::Enum reason() const noexcept
ResponseTimeoutException(const std::string &rejectReason, int timeoutMilliseconds)
The program is finishing its execution.
MessageHeader::TemplateId MessageTemplateId
Message type (template) identification.
Defines message type.
Definition: Fields.h:1006