OnixS C++ CME MDP Conflated TCP Handler 1.3.6
API Documentation
Loading...
Searching...
No Matches
Gateway.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19
20#pragma once
21
23
24#if defined(ONIXS_CONFLATEDTCP_HAS_GATEWAY_EMULATOR)
25
28#include <OnixS/CME/ConflatedTCP/testing/ClientMessageListener.h>
29
30#include <chrono>
31
32namespace OnixS {
33namespace CME {
34namespace ConflatedTCP {
35namespace Testing {
36
37// Assume NegotiationResponse202::credentials is empty
38constexpr
40{
41 using Message = NegotiationResponse202;
42
43 return
44 Message::blockLength(Message::Schema::Version)
46 + Message::getMinimalVariableFieldsSize(Message::Schema::Version);
47}
48
49// Type aliases
55
61
64{
65public:
66 explicit
67 Gateway(int port, const char* host = "127.0.0.1", const std::chrono::seconds& timeout = std::chrono::seconds(10));
68
70 virtual ~Gateway();
71
73 Gateway(const Gateway&) = delete;
74 Gateway& operator=(const Gateway&) = delete;
75
77 Gateway(Gateway&&) noexcept;
78 Gateway& operator=(Gateway&&) noexcept;
79
81 void swap(Gateway&) noexcept;
82
85
87 Gateway& acceptSession(SeqNumber outgoingSequenceNumber = 1, UInt64 previousUuid = 0, UInt32 previousSeqNo = 0);
88
93 Terminate203Ptr waitUntilTerminate(ClientMessageListener* listener = nullptr);
94
97
100 int port() const noexcept;
101
103 Gateway& enableLogger(const std::string& logFileName);
104
106 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
107 Gateway& send(ConflatedTCP::Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer>& msg);
108
110 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
111 Gateway& send(ConflatedTCP::Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer>&& msg);
112
114 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
115 Gateway& send(ConflatedTCP::Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer>& msg, SeqNumber num);
116
118 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
119 Gateway& send(ConflatedTCP::Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer>&& msg, SeqNumber num);
120
124 template <typename TMsg>
126
131 Gateway& run(ClientMessageListener& listener);
132
136
138 Gateway& outSeqNum(SeqNumber nextOutSeqNum);
139
142 UInt64 uuid() const noexcept
143 {
144 return uId_;
145 }
146
148 Gateway& tcpNoDelayOption(bool noDelay);
149
154 bool tcpNoDelayOption() const;
155
161
167
173
179
180protected:
183 bool isConnectionClosed(const std::chrono::seconds& timeout) const;
184
188 bool isConnectionClosed() const;
189
192
197
202
206 Negotiate200Ptr rejectNegotiate(ErrorCodes::Enum errorCodes = ErrorCodes::Enum(), const std::string & reason = std::string());
207
212
217
219 Gateway& sendTerminate(const std::string& reason = {}, ErrorCodes::Enum errCode = ErrorCodes::Other);
220
222 Terminate203Ptr terminate(const std::string& reason = {}, ErrorCodes::Enum errCode = ErrorCodes::Other);
223
226
228 NegotiationReject201Container createNegotiationReject(const Negotiate200Ptr& request, ErrorCodes::Enum errorCodes, const std::string & reason);
229
231 template <typename TRequestMsg>
232 RequestAck206Container createRequestAck(const TRequestMsg& request);
233
235 template <typename TRequestMsg>
236 RequestReject207Container createRequestReject(const TRequestMsg& request);
237
240
242 Terminate203Container createTerminate(const std::string& reason, ErrorCodes::Enum errCode);
243
246
248 Gateway& sendData(const void* data, size_t size);
249
252
253private:
254 template<typename MessageType>
255 void invokeCallback(void(ClientMessageListener::*Callback)(const MessageType &, Gateway *), ClientMessageListener * listener, const MessageBasePtr & msg)
256 {
257 if(listener)
258 (listener->*Callback)(cast<MessageType>(msg), this);
259 }
260
261 class Impl;
262 Impl* impl_;
263};
264
265template <typename TRequestMsg>
267{
269
270 response.message()
271 .setReqId(request->reqId())
272 .setSubscriptionReqType(request->subscriptionReqType())
273 .setReqIdStatus(RequestIDStatus::FullAck);
274
275 return response;
276}
277
278template <typename TRequestMsg>
280{
282
283 response.message()
284 .setReqId(request->reqId())
285 .setReqRejReason(ReqRejReason::Other);
286
287 return response;
288}
289
290template <typename TMsg>
295
296template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
298{
299 const auto messageSize = msg.setHeader();
300 auto* const header = msg.header();
301 assert(header);
302
303 return send(Messaging::SbeMessage(header + 1, messageSize), *header);
304}
305
306template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
311
312template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
318
319template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
325
326}}}}
327
328#endif
#define ONIXS_CONFLATEDTCP_EXPORTED
Definition Compiler.h:175
#define ONIXS_CONFLATEDTCP_NODISCARD
Definition Compiler.h:185
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
const SimpleOpenFramingHeader * header() const noexcept
MessageSize setHeader() noexcept
Calculates the binary size of the message and updates the Simple Open Framing Header accordingly.
CME Conflated TCP Gateway Emulator.
Definition Gateway.h:64
Negotiate200Ptr acceptNegotiate(UInt32 previousSeqNo=0)
Receives the Negotiate200 and responds with the NegotiationResponse202 message.
MessageBasePtr receive() const
Receives a message.
Gateway(const Gateway &)=delete
Deleted.
Terminate203Ptr terminate(const std::string &reason={}, ErrorCodes::Enum errCode=ErrorCodes::Other)
Sends the Terminate203 meassage and waist until the response is received.
Gateway & send(Messaging::SbeMessage, Messaging::SimpleOpenFramingHeader &)
Sends the given message.
NegotiationResponse202Container createNegotiationResponse(const Negotiate200Ptr &request, UInt32 previousSeqNo)
Creates a NegotiationResponse202 message.
Gateway & socketReceiveBufferSize(int bufferSize)
Sets the socket receive buffer size.
Gateway & socketSendBufferSize(int bufferSize)
Sets the size of the socket send buffer size.
Terminate203Ptr acceptTerminate()
Receive the Terminate203 message and responds with the Terminate203 message.
Negotiate200Ptr rejectNegotiate(ErrorCodes::Enum errorCodes=ErrorCodes::Enum(), const std::string &reason=std::string())
Receives the Negotiate200 message and responds with the NegotiationReject201 message.
RequestAck206Container createRequestAck(const TRequestMsg &request)
Creates a RequestAck206 message.
Definition Gateway.h:266
Gateway & acceptSession(SeqNumber outgoingSequenceNumber=1, UInt64 previousUuid=0, UInt32 previousSeqNo=0)
Accepts an incoming Conflated TCP session.
Gateway & sendData(const void *data, size_t size)
Sends the given data.
bool isConnectionClosed() const
Checks whether the connection is closed by the counterparty using the default timeout (provided in th...
Gateway & operator=(const Gateway &)=delete
Gateway & disconnect()
Closes the accepted connection.
Gateway(Gateway &&) noexcept
Move semantic.
Gateway & sendTerminate(const std::string &reason={}, ErrorCodes::Enum errCode=ErrorCodes::Other)
Sends the Terminate203 message.
NegotiationReject201Container createNegotiationReject(const Negotiate200Ptr &request, ErrorCodes::Enum errorCodes, const std::string &reason)
Creates a NegotiationReject201 message.
Gateway & acceptConnection()
Accepts an incoming connection.
Gateway & run(ClientMessageListener &listener)
Accepts an incoming connection and establishes the session.
Terminate203Container createTerminate(const std::string &reason, ErrorCodes::Enum errCode)
Creates a Terminate203 message.
Gateway & send(ConflatedTCP::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg)
Sends the given message.
Definition Gateway.h:297
bool isConnectionClosed(const std::chrono::seconds &timeout) const
Checks whether the connection is closed by the counterparty.
Negotiate200Ptr receiveNegotiate()
Receives the Negotiate200 message.
Gateway & enableLogger(const std::string &logFileName)
Enables logging.
Gateway(int port, const char *host="127.0.0.1", const std::chrono::seconds &timeout=std::chrono::seconds(10))
MessagePtr< TMsg > receiveTypedMessage()
Receives the message of the particular type.
Definition Gateway.h:291
Terminate203Ptr waitUntilTerminate(ClientMessageListener *listener=nullptr)
Waits until the Terminate203 message is received.
void swap(Gateway &) noexcept
Swap with other.
Terminate203Ptr receiveTerminate()
Receive the Terminate203 message.
RequestReject207Container createRequestReject(const TRequestMsg &request)
Creates a RequestReject207 message.
Definition Gateway.h:279
Gateway & tcpNoDelayOption(bool noDelay)
Sets the value of the option to improve latency at the expense of message throughput (the TCP_NODELAY...
Terminate203Container createTerminate(const Terminate203Ptr &request)
Creates a Terminate203 message.
MessageHolder< RequestAck206 > RequestAck206Container
Definition Gateway.h:53
MessageHolder< NegotiationResponse202, calculateNegotiationResponse202MaxSize()> NegotiationResponse202Container
Definition Gateway.h:50
MessagePtr< Negotiate200 > Negotiate200Ptr
Definition Gateway.h:57
MessageHolder< NegotiationReject201 > NegotiationReject201Container
Definition Gateway.h:51
MessagePtr< RequestAck206 > RequestAck206Ptr
Definition Gateway.h:59
MessageHolder< RequestReject207 > RequestReject207Container
Definition Gateway.h:54
MessagePtr< RequestReject207 > RequestReject207Ptr
Definition Gateway.h:60
MessageHolder< Terminate203 > Terminate203Container
Definition Gateway.h:52
MessagePtr< Terminate203 > Terminate203Ptr
Definition Gateway.h:58
MessagePtr< AnotherType > cast(const MessagePtr< BaseType > &ptr)
Tries to cast to another type.
Definition MessagePtr.h:215
MessagePtr< SbeMessage > MessageBasePtr
Definition Gateway.h:56
constexpr UInt16 calculateNegotiationResponse202MaxSize()
Definition Gateway.h:39
Messaging::UInt32 SeqNumber
Definition Messaging.h:58
@ Other
Unexpected request, see Reason field for details.
Definition Fields.h:66
@ FullAck
Requested subscription scope is fully acknowledged .
Definition Fields.h:113