OnixS C++ ICE Binary Order Entry Handler 1.0.0
API Documentation
Loading...
Searching...
No Matches
Gateway Class Reference

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
Gatewayoperator= (const Gateway &)=delete
 Gateway (Gateway &&) noexcept
Gatewayoperator= (Gateway &&) noexcept
void swap (Gateway &) noexcept
GatewayacceptConnection (const Timeout &acceptTimeout=defaultTimeout())
bool tryAcceptConnection (const Timeout &acceptTimeout=defaultTimeout())
GatewayacceptSession (SeqNumber outgoingSequenceNumber=1)
LogoutRequestPtr waitUntilTerminate (ClientMessageListener *listener=nullptr, ClientSessionMessageListener *sessionMessageListener=nullptr, std::atomic< bool > *stopRequested=nullptr)
GatewaysendSequence ()
Gatewaydisconnect ()
std::string host () const
int port () const noexcept
GatewayenableLogger (const std::string &logFileName, unsigned int logLevel=3)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, SeqNumber num)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg, SeqNumber num)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, std::initializer_list< SeqNumber > numbers)
template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gatewaysend (MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &&msg, std::initializer_list< SeqNumber > numbers)
template<typename TMsg>
MessagePtr< TMsg > receiveTypedMessage ()
Gatewayrun (ClientMessageListener &listener, std::atomic< bool > *stopRequested=nullptr)
Gatewayrun (ClientMessageListener &appMsgListener, ClientSessionMessageListener &sessionMsgListener, std::atomic< bool > *stopRequested=nullptr)
SeqNumber outSeqNum () const noexcept
GatewayoutSeqNum (SeqNumber nextOutSeqNum) noexcept
GatewaytcpNoDelayOption (bool noDelay)
bool tcpNoDelayOption () const noexcept
int socketReceiveBufferSize () const
GatewaysocketReceiveBufferSize (int bufferSize)
int socketSendBufferSize () const noexcept
GatewaysocketSendBufferSize (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
LogonRequestPtr receiveNegotiate ()
LogonRequestPtr acceptLogonRequest (UInt32 sequenceId)
LogoutRequestPtr receiveLogoutRequest ()
LogoutRequestPtr acceptTerminate ()
GatewaysendTerminate (StrRef userId, Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
LogoutRequestPtr terminate (StrRef userId)
LogonReportContainer createNegotiationResponse (Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
Gatewaysend (Messaging::SbeMessage, Messaging::SimpleOpenFramingHeader &)
GatewaysendData (const void *data, size_t size)
Gatewayclose ()

Static Protected Member Functions

static IPReportContainer createIpReport (StrRef userId, StrRef host, Int16NULL port, StrRef ipSessionToken, Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
static TraderLogonReportContainer createTraderLogonReport (StrRef traderId, int clientId, Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
static TraderLogoutReportContainer createTraderLogoutReport (StrRef traderId, Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
static LogoutReportContainer createLogoutReport (StrRef userId, Int32NULL exchangeCode=NullInt32NULL(), const std::string &text={})
static HeartBeatContainer createSequence ()
static Timeout defaultTimeout ()

Detailed Description

Definition at line 52 of file Gateway.h.

Member Typedef Documentation

◆ Timeout

using Timeout = std::chrono::milliseconds

Timeout alias.

Definition at line 56 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.

◆ acceptLogonRequest()

LogonRequestPtr acceptLogonRequest ( UInt32 sequenceId)
protected

Receives the LogonRequest and responds with the LogonReport message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ acceptSession()

Gateway & acceptSession ( SeqNumber outgoingSequenceNumber = 1)

Accepts an incoming session.

◆ acceptTerminate()

LogoutRequestPtr acceptTerminate ( )
protected

Receive the LogoutRequest message and responds with the LogoutReport message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ close()

Gateway & close ( )
protected

Close the listening socket.

◆ createIpReport()

IPReportContainer createIpReport ( StrRef userId,
StrRef host,
Int16NULL port,
StrRef ipSessionToken,
Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
staticprotected

Creates a IPReport message.

◆ createLogoutReport()

LogoutReportContainer createLogoutReport ( StrRef userId,
Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
staticprotected

Creates a LogoutReport message.

◆ createNegotiationResponse()

LogonReportContainer createNegotiationResponse ( Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
protected

Creates a NegotiationResponse501 message.

◆ createSequence()

HeartBeatContainer createSequence ( )
staticprotected

Creates a Heartbeat message.

◆ createTraderLogonReport()

TraderLogonReportContainer createTraderLogonReport ( StrRef traderId,
int clientId,
Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
staticprotected

Creates a TraderLogonReport message.

◆ createTraderLogoutReport()

TraderLogoutReportContainer createTraderLogoutReport ( StrRef traderId,
Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
staticprotected

Creates a TraderLogoutReport message.

◆ defaultTimeout()

Timeout defaultTimeout ( )
inlinestaticprotected

Default timeout.

Definition at line 273 of file Gateway.h.

◆ disconnect()

Gateway & disconnect ( )

Closes the accepted connection.

◆ enableLogger()

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

Enables logging.

◆ host()

std::string host ( ) const
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.

◆ receiveLogoutRequest()

LogoutRequestPtr receiveLogoutRequest ( )
protected

Receive the LogoutRequest message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ receiveNegotiate()

LogonRequestPtr receiveNegotiate ( )
protected

Receives the LogonRequest 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 285 of file Gateway.h.

◆ run() [1/2]

Gateway & run ( ClientMessageListener & appMsgListener,
ClientSessionMessageListener & sessionMsgListener,
std::atomic< bool > * stopRequested = nullptr )

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,
std::atomic< bool > * stopRequested = nullptr )

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 ( MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > && msg)

Sends the given message.

Note
does not update outSeqNum.

Definition at line 301 of file Gateway.h.

◆ send() [2/7]

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

Sets the given sequence number and sends the message.

Note
does not update outSeqNum.

Definition at line 329 of file Gateway.h.

◆ send() [3/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( 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 348 of file Gateway.h.

◆ send() [4/7]

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

Sends the given message.

Note
does not update outSeqNum.

Definition at line 291 of file Gateway.h.

◆ send() [5/7]

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

Sets the given sequence number and sends the message.

Note
does not update outSeqNum.

Definition at line 322 of file Gateway.h.

◆ send() [6/7]

template<typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
Gateway & send ( 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 336 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 ( )

Sends the Sequence506 message.

◆ sendTerminate()

Gateway & sendTerminate ( StrRef userId,
Int32NULL exchangeCode = NullInt32NULL(),
const std::string & text = {} )
protected

Sends the Terminate507 message.

◆ socketReceiveBufferSize() [1/2]

int socketReceiveBufferSize ( ) const
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::SocketSedndBufferSize.

◆ 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()

LogoutRequestPtr terminate ( StrRef userId)
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.

◆ waitUntilTerminate()

LogoutRequestPtr 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