OnixS C++ CME iLink 3 Binary Order Entry Handler 1.19.7
Users' manual and API documentation
Loading...
Searching...
No Matches
Gateway Class Reference

#include <OnixS/CME/iLink3/testing/Gateway.h>

Public Types

using Timeout = std::chrono::milliseconds

Public Member Functions

 Gateway (const SessionSettings::LicenseStores &licenseStores, int port, const char *host="127.0.0.1", const Timeout &acceptTimeout=defaultTimeout(), const Timeout &sendReceiveTimeout=defaultTimeout())
virtual ~Gateway ()
 Gateway (const Gateway &)=delete
Gateway & operator= (const Gateway &)=delete
 Gateway (Gateway &&) noexcept
Gateway & operator= (Gateway &&) noexcept
void swap (Gateway &) noexcept
Gateway & acceptConnection (const Timeout &acceptTimeout=defaultTimeout())
bool tryAcceptConnection (const Timeout &acceptTimeout=defaultTimeout())
Gateway & acceptSession (SeqNumber outgoingSequenceNumber=1, UInt64 previousUuid=0, UInt32 previousSeqNo=0)
Terminate507Ptr waitUntilTerminate (ClientMessageListener *listener=nullptr, ClientSessionMessageListener *sessionMessageListener=nullptr, std::atomic< bool > *stopRequested=nullptr)
bool dispatch (MessageBasePtr msg, ClientMessageListener *listener=nullptr, ClientSessionMessageListener *sessionMessageListener=nullptr)
Gateway & sendSequence (UInt32 nextSeqNo, KeepAliveLapsed::Enum keepAliveLapsed=KeepAliveLapsed::NotLapsed, UInt64 uuid=0)
Gateway & disconnect ()
const char * host () const noexcept
int port () const noexcept
Gateway & enableLogger (const std::string &logFileName, unsigned int logLevel=3)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, SeqNumber num)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg, SeqNumber num)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, std::initializer_list< SeqNumber > numbers)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send (iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg, std::initializer_list< SeqNumber > numbers)
template<typename TMsg>
MessagePtr< TMsg > receiveTypedMessage ()
Gateway & run (ClientMessageListener &listener)
Gateway & run (ClientMessageListener &appMsgListener, ClientSessionMessageListener &sessionMsgListener)
SeqNumber outSeqNum () const noexcept
Gateway & outSeqNum (SeqNumber nextOutSeqNum) noexcept
UInt64 uuid () const noexcept
FTI::Enum faultToleranceIndicator () const noexcept
Gateway & faultToleranceIndicator (FTI::Enum value)
Gateway & tcpNoDelayOption (bool noDelay)
bool tcpNoDelayOption () const noexcept
int socketReceiveBufferSize () const noexcept
Gateway & socketReceiveBufferSize (int bufferSize)
int socketSendBufferSize () const noexcept
Gateway & socketSendBufferSize (int bufferSize)

Protected Member Functions

bool isConnectionClosed (const Timeout &timeout) const
bool isConnectionClosed () const
MessageBasePtr receive () const
MessageBasePtr tryReceive (const std::chrono::microseconds &timeout=defaultTimeout()) const
Negotiate500Ptr receiveNegotiate ()
Negotiate500Ptr acceptNegotiate (UInt32 previousSeqNo=0)
Negotiate500Ptr rejectNegotiate (NegotiationRejectErrorCode::Enum errorCodes=NegotiationRejectErrorCode::Enum(), const std::string &reason=std::string())
Establish503Ptr receiveEstablish ()
Establish503Ptr acceptEstablish (UInt32 outgoingSequenceNumber=1, UInt64 previousUuid=0, UInt32 previousSeqNo=0)
Establish503Ptr rejectEstablish (UInt32 outgoingSequenceNumber=1, EstablishmentRejectErrorCode::Enum errorCodes=EstablishmentRejectErrorCode::Enum(), const std::string &reason=std::string())
Terminate507Ptr receiveTerminate ()
Terminate507Ptr acceptTerminate ()
Gateway & sendTerminate (const std::string &reason={}, UInt16 errCode=TerminateErrorCode::Other)
Terminate507Ptr terminate (const std::string &reason={}, UInt16 errCode=TerminateErrorCode::Other)
NegotiationResponse501Container createNegotiationResponse (const Negotiate500Ptr &request, UInt32 previousSeqNo)
NegotiationReject502Container createNegotiationReject (const Negotiate500Ptr &request, NegotiationRejectErrorCode::Enum errorCodes, const std::string &reason)
EstablishmentAck504Container createEstablishmentAck (const Establish503Ptr &request, UInt32 outgoingSequenceNumber)
EstablishmentReject505Container createEstablishmentReject (const Establish503Ptr &request, UInt32 outgoingSequenceNumber, EstablishmentRejectErrorCode::Enum errorCodes, const std::string &reason)
Terminate507Container createTerminate (const Terminate507Ptr &request)
Terminate507Container createTerminate (const std::string &reason, UInt16 errCode)
Sequence506Container createSequence (UInt32 nextSeqNo, KeepAliveLapsed::Enum keepAliveLapsed=KeepAliveLapsed::NotLapsed, UInt64 uuid=0)
Gateway & send (Messaging::SbeMessage, Messaging::SimpleOpenFramingHeader &)
Gateway & sendData (const void *data, size_t size)
Gateway & close ()

Static Protected Member Functions

static Timeout defaultTimeout ()

Protected Attributes

UInt64 uId_ {0}

Detailed Description

Definition at line 64 of file Gateway.h.

Member Typedef Documentation

◆ Timeout

using Timeout = std::chrono::milliseconds

Timeout alias.

Definition at line 68 of file Gateway.h.

Constructor & Destructor Documentation

◆ Gateway() [1/3]

Gateway ( const SessionSettings::LicenseStores & licenseStores,
int port,
const char * host = "127.0.0.1",
const Timeout & acceptTimeout = defaultTimeout(),
const Timeout & sendReceiveTimeout = defaultTimeout() )

◆ ~Gateway()

virtual ~Gateway ( )
virtual

◆ Gateway() [2/3]

Gateway ( const Gateway & )
delete

Deleted.

◆ Gateway() [3/3]

Gateway ( Gateway && )
noexcept

Move semantic.

Member Function Documentation

◆ acceptConnection()

Gateway & acceptConnection ( const Timeout & acceptTimeout = defaultTimeout())

Accepts an incoming connection. If the acceptTimeout is zero, the acceptTimeout provided in the constructor is used.

◆ acceptEstablish()

Establish503Ptr acceptEstablish ( UInt32 outgoingSequenceNumber = 1,
UInt64 previousUuid = 0,
UInt32 previousSeqNo = 0 )
protected

Receive the Establish503 message and respond with the EstablishmentAck504 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ acceptNegotiate()

Negotiate500Ptr acceptNegotiate ( UInt32 previousSeqNo = 0)
protected

Receives the Negotiate500 and responds with the NegotiationResponse501 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ acceptSession()

Gateway & acceptSession ( SeqNumber outgoingSequenceNumber = 1,
UInt64 previousUuid = 0,
UInt32 previousSeqNo = 0 )

Accepts an incoming iLink 3 session.

◆ acceptTerminate()

Terminate507Ptr acceptTerminate ( )
protected

Receive the Terminate507 message and responds with the Terminate507 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ close()

Gateway & close ( )
protected

Close the listening socket.

◆ createEstablishmentAck()

EstablishmentAck504Container createEstablishmentAck ( const Establish503Ptr & request,
UInt32 outgoingSequenceNumber )
protected

Creates a EstablishmentAck504 message.

◆ createEstablishmentReject()

EstablishmentReject505Container createEstablishmentReject ( const Establish503Ptr & request,
UInt32 outgoingSequenceNumber,
EstablishmentRejectErrorCode::Enum errorCodes,
const std::string & reason )
protected

Creates a EstablishmentReject505 message.

◆ createNegotiationReject()

NegotiationReject502Container createNegotiationReject ( const Negotiate500Ptr & request,
NegotiationRejectErrorCode::Enum errorCodes,
const std::string & reason )
protected

Creates a NegotiationReject502 message.

◆ createNegotiationResponse()

NegotiationResponse501Container createNegotiationResponse ( const Negotiate500Ptr & request,
UInt32 previousSeqNo )
protected

Creates a NegotiationResponse501 message.

◆ createSequence()

Sequence506Container createSequence ( UInt32 nextSeqNo,
KeepAliveLapsed::Enum keepAliveLapsed = KeepAliveLapsed::NotLapsed,
UInt64 uuid = 0 )
protected

Creates a Sequence506 message.

◆ createTerminate() [1/2]

Terminate507Container createTerminate ( const std::string & reason,
UInt16 errCode )
protected

Creates a Terminate507 message.

◆ createTerminate() [2/2]

Terminate507Container createTerminate ( const Terminate507Ptr & request)
protected

Creates a Terminate507 message.

◆ defaultTimeout()

Timeout defaultTimeout ( )
inlinestaticprotected

Default timeout.

Definition at line 341 of file Gateway.h.

◆ disconnect()

Gateway & disconnect ( )

Closes the accepted connection.

◆ dispatch()

bool dispatch ( MessageBasePtr msg,
ClientMessageListener * listener = nullptr,
ClientSessionMessageListener * sessionMessageListener = nullptr )

Dispatches the provided message for the established session. If the listener is provided, then receives and reports application-level messages via the corresponding callback. Responds to the Sequence506 message if received.

Returns
true if the terminate message was sent.
Note
actual outSeqNum must be provided before invocation

◆ enableLogger()

Gateway & enableLogger ( const std::string & logFileName,
unsigned int logLevel = 3 )

Enables logging.

◆ faultToleranceIndicator() [1/2]

FTI::Enum faultToleranceIndicator ( ) const
inlinenoexcept
Returns
the Fault Tolerance Indicator.

Definition at line 198 of file Gateway.h.

◆ faultToleranceIndicator() [2/2]

Gateway & faultToleranceIndicator ( FTI::Enum value)
inline

Sets the Fault Tolerance Indicator.

Definition at line 204 of file Gateway.h.

◆ host()

const char * host ( ) const
noexcept
Returns
listen host.

◆ isConnectionClosed() [1/2]

bool isConnectionClosed ( ) const
protected

Checks whether the connection is closed by the counterparty using the default timeout (provided in the constructor).

◆ isConnectionClosed() [2/2]

bool isConnectionClosed ( const Timeout & timeout) const
protected

Checks whether the connection is closed by the counterparty.

◆ operator=() [1/2]

Gateway & operator= ( const Gateway & )
delete

◆ operator=() [2/2]

Gateway & operator= ( Gateway && )
noexcept

◆ outSeqNum() [1/2]

SeqNumber outSeqNum ( ) const
noexcept
Returns
the sequence number of the next outgoing message.

◆ outSeqNum() [2/2]

Gateway & outSeqNum ( SeqNumber nextOutSeqNum)
noexcept

Sets the sequence number of the next outgoing message.

◆ port()

int port ( ) const
noexcept
Returns
the listen port.

◆ receive()

MessageBasePtr receive ( ) const
protected

Receives a message.

◆ receiveEstablish()

Establish503Ptr receiveEstablish ( )
protected

Receives the Establish503 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ receiveNegotiate()

Negotiate500Ptr receiveNegotiate ( )
protected

Receives the Negotiate500 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ receiveTerminate()

Terminate507Ptr receiveTerminate ( )
protected

Receive the Terminate507 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ receiveTypedMessage()

template<typename TMsg>
MessagePtr< TMsg > receiveTypedMessage ( )

Receives the message of the particular type.

Exceptions
std::logic_errorif an unexpected type is received.

Definition at line 358 of file Gateway.h.

◆ rejectEstablish()

Establish503Ptr rejectEstablish ( UInt32 outgoingSequenceNumber = 1,
EstablishmentRejectErrorCode::Enum errorCodes = EstablishmentRejectErrorCode::Enum(),
const std::string & reason = std::string() )
protected

Receives the Establish503 message and responds with the EstablishmentReject505 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ rejectNegotiate()

Negotiate500Ptr rejectNegotiate ( NegotiationRejectErrorCode::Enum errorCodes = NegotiationRejectErrorCode::Enum(),
const std::string & reason = std::string() )
protected

Receives the Negotiate500 message and responds with the NegotiationReject502 message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ run() [1/2]

Gateway & run ( ClientMessageListener & appMsgListener,
ClientSessionMessageListener & sessionMsgListener )

Accepts an incoming connection and establishes the session.

  • Receives and reports application-level messages via the corresponding callback.
  • Receives and reports session-level messages via the corresponding callback.
  • Sends Sequence messages.

◆ run() [2/2]

Gateway & run ( ClientMessageListener & listener)

Accepts an incoming connection and establishes the session.

  • Receives and reports application-level messages via the corresponding callback.
  • Sends Sequence messages in response to the received ones.

◆ send() [1/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > && msg)

Sends the given message.

Note
does not update outSeqNum.

Definition at line 374 of file Gateway.h.

◆ send() [2/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > && msg,
SeqNumber num )

Sets the given sequence number and sends the message.

Note
does not update outSeqNum.

Definition at line 401 of file Gateway.h.

◆ send() [3/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > && msg,
std::initializer_list< SeqNumber > numbers )

Sets the given sequence numbers and sends the messages.

Note
does not update outSeqNum.

Definition at line 420 of file Gateway.h.

◆ send() [4/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > & msg)

Sends the given message.

Note
does not update outSeqNum.

Definition at line 364 of file Gateway.h.

◆ send() [5/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > & msg,
SeqNumber num )

Sets the given sequence number and sends the message.

Note
does not update outSeqNum.

Definition at line 394 of file Gateway.h.

◆ send() [6/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( iLink3::Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > & msg,
std::initializer_list< SeqNumber > numbers )

Sets the given sequence numbers and sends the messages.

Note
does not update outSeqNum.

Definition at line 408 of file Gateway.h.

◆ send() [7/7]

Sends the given message.

◆ sendData()

Gateway & sendData ( const void * data,
size_t size )
protected

Sends the given data.

◆ sendSequence()

Gateway & sendSequence ( UInt32 nextSeqNo,
KeepAliveLapsed::Enum keepAliveLapsed = KeepAliveLapsed::NotLapsed,
UInt64 uuid = 0 )

Sends the Sequence506 message.

◆ sendTerminate()

Gateway & sendTerminate ( const std::string & reason = {},
UInt16 errCode = TerminateErrorCode::Other )
protected

Sends the Terminate507 message.

◆ socketReceiveBufferSize() [1/2]

int socketReceiveBufferSize ( ) const
noexcept
Returns
the socket receive buffer size.

The default value is SessionSettings::Default::SocketReceiveBufferSize.

◆ socketReceiveBufferSize() [2/2]

Gateway & socketReceiveBufferSize ( int bufferSize)

Sets the socket receive buffer size.

Parameters
bufferSizethe size of the socket receive buffer size. If SessionSettings::UseOsDefaultSocketBufferSize then the default operating system value is used.

◆ socketSendBufferSize() [1/2]

int socketSendBufferSize ( ) const
noexcept
Returns
the size of the socket send buffer size.

The default value is SessionSettings::Default::SocketSendBufferSize.

◆ socketSendBufferSize() [2/2]

Gateway & socketSendBufferSize ( int bufferSize)

Sets the size of the socket send buffer size.

Parameters
bufferSizethe size of the socket send buffer size. If SessionSettings::UseOsDefaultSocketBufferSize then the default operating system value is used.

◆ swap()

void swap ( Gateway & )
noexcept

Swap with other.

◆ tcpNoDelayOption() [1/2]

bool tcpNoDelayOption ( ) const
noexcept
Returns
the value of the option to improve latency at the expense of message throughput (the TCP_NODELAY socket option).

The default value is SessionSettings::Default::TcpNoDelayOption.

◆ tcpNoDelayOption() [2/2]

Gateway & tcpNoDelayOption ( bool noDelay)

Sets the value of the option to improve latency at the expense of message throughput (the TCP_NODELAY socket option).

◆ terminate()

Terminate507Ptr terminate ( const std::string & reason = {},
UInt16 errCode = TerminateErrorCode::Other )
protected

Sends the Terminate507 message and waits until the response is received.

◆ tryAcceptConnection()

bool tryAcceptConnection ( const Timeout & acceptTimeout = defaultTimeout())

Accepts an incoming connection. If the operation is timed out, false is returned.

◆ tryReceive()

MessageBasePtr tryReceive ( const std::chrono::microseconds & timeout = defaultTimeout()) const
protected

Receives a message using the provided timeout. If the operation is timed out, an empty message is returned.

◆ uuid()

UInt64 uuid ( ) const
inlinenoexcept
Returns
UUID.

Definition at line 191 of file Gateway.h.

◆ waitUntilTerminate()

Terminate507Ptr waitUntilTerminate ( ClientMessageListener * listener = nullptr,
ClientSessionMessageListener * sessionMessageListener = nullptr,
std::atomic< bool > * stopRequested = nullptr )

Waits until the Terminate507 message is received.

If the listener is provided, then receives and reports application-level messages via the corresponding callback. Responds to the Sequence506 message if received.

Note
actual outSeqNum must be provided before invocation

Member Data Documentation

◆ uId_

UInt64 uId_ {0}
protected

UUID.

Definition at line 347 of file Gateway.h.