OnixS C++ ICE Binary Order Entry Handler 1.1.1
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 noexcept
GatewaysocketReceiveBufferSize (int bufferSize)
int socketSendBufferSize () const noexcept
GatewaysocketSendBufferSize (int bufferSize)
LogonReportContainer createLogonReport (Int32NULL exchangeCode=NullInt32NULL(), std::string text={})

Static Public Member Functions

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

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 receiveLogonRequest ()
LogonRequestPtr acceptLogonRequest (UInt32 sequenceId)
LogoutRequestPtr receiveLogoutRequest ()
LogoutRequestPtr acceptLogoutRequest ()
GatewaysendLogoutRequest (StrRef userId, Int32NULL exchangeCode=NullInt32NULL(), std::string text={})
LogoutRequestPtr terminate (StrRef userId)
Gatewaysend (Messaging::SbeMessage, Messaging::SimpleOpenFramingHeader &)
GatewaysendData (const void *data, size_t size)
Gatewayclose ()

Static Protected Member Functions

static Timeout defaultTimeout ()

Friends

class ClientMessageListener
class ClientSessionMessageListener

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.

◆ acceptLogoutRequest()

LogoutRequestPtr acceptLogoutRequest ( )
protected

Receive the LogoutRequest message and responds with the LogoutReport message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ acceptSession()

Gateway & acceptSession ( SeqNumber outgoingSequenceNumber = 1)

Accepts an incoming session.

◆ close()

Gateway & close ( )
protected

Close the listening socket.

◆ createHeartBeat()

HeartBeatContainer createHeartBeat ( )
static

Creates a Heartbeat message.

◆ createIpReport()

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

Creates a IPReport message.

◆ createLogonReport()

LogonReportContainer createLogonReport ( Int32NULL exchangeCode = NullInt32NULL(),
std::string text = {} )

Creates a LogonReport message.

◆ createLogoutReport()

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

Creates a LogoutReport message.

◆ createTraderLogonReport()

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

Creates a TraderLogonReport message.

◆ createTraderLogoutReport()

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

Creates a TraderLogoutReport message.

◆ defaultTimeout()

Timeout defaultTimeout ( )
inlinestaticprotected

Default timeout.

Definition at line 286 of file Gateway.h.

287 {
288 return Timeout(30000);
289 }

◆ 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.

◆ receiveLogonRequest()

LogonRequestPtr receiveLogonRequest ( )
protected

Receives the LogonRequest message.

Exceptions
std::logic_errorif an unexpected type is received.

◆ receiveLogoutRequest()

LogoutRequestPtr receiveLogoutRequest ( )
protected

Receive the LogoutRequest 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 301 of file Gateway.h.

302{
303 return cast<TMsg>(receive());
304}

◆ 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 HeartBeat 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 HeartBeat 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 317 of file Gateway.h.

318{
319 return send(msg);
320}

◆ 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 344 of file Gateway.h.

345{
346 setSeqNum(msg, num);
347 return send(msg);
348}
std::enable_if< std::is_base_of< TagBased::Message, typenameHolder::MessageType >::value >::type setSeqNum(Holder &, SeqNumber)
Definition Gateway.h:324

◆ 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 363 of file Gateway.h.

365{
366 for(auto seqNum : numbers)
367 {
368 send(msg, seqNum);
369 }
370
371 return *this;
372}

◆ 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 307 of file Gateway.h.

308{
309 const auto messageSize = msg.setHeader();
310 auto* const header = msg.header();
311 assert(header);
312
313 return send(Messaging::SbeMessage(header + 1, messageSize), *header);
314}

◆ 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 337 of file Gateway.h.

338{
339 setSeqNum(msg, num);
340 return send(msg);
341}

◆ 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 351 of file Gateway.h.

353{
354 for(auto seqNum : numbers)
355 {
356 send(msg, seqNum);
357 }
358
359 return *this;
360}

◆ send() [7/7]

Sends the given message.

◆ sendData()

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

Sends the given data.

◆ sendLogoutRequest()

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

Sends the LogoutReport message.

◆ sendSequence()

Gateway & sendSequence ( )

Sends the HeartBeat 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()

LogoutRequestPtr terminate ( StrRef userId)
protected

Sends the LogoutReport 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 LogoutRequest message is received.

If the listener is provided, then receives and reports application-level messages via the corresponding callback.

◆ ClientMessageListener

friend class ClientMessageListener
friend

Definition at line 295 of file Gateway.h.

◆ ClientSessionMessageListener

friend class ClientSessionMessageListener
friend

Definition at line 296 of file Gateway.h.