Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::cli::CliEndpoint Class Reference

Where the CLI server's commands reach a thread that owns some state (the main thread, or a venue's order gateway), and where that thread's answers come back. More...

#include <cli/cli_endpoint.hpp>

Collaboration diagram for slick::sim::cli::CliEndpoint:

Public Member Functions

 CliEndpoint (std::string name={})
 CliEndpoint (const CliEndpoint &)=delete
CliEndpoint & operator= (const CliEndpoint &)=delete
const std::string & name () const noexcept
 How the CLI addresses it, /-separated from the venue down: cme/<segment>.
void set_name (std::string name)
 Before the endpoint is given to the CLI server.
template<typename Handler>
void serve (Handler &&handler)
 Owner thread.
bool post (const Command &command)
 CLI server thread. False, posting nothing, while busy().
bool busy () const noexcept
 CLI server thread.
template<typename OnReply>
void take_replies (OnReply &&on_reply)
 CLI server thread.

Static Public Attributes

static constexpr uint32_t MAX_IN_FLIGHT = 16
static constexpr uint32_t MAX_REPLY_TEXT = 4096
 A longer reply is cut, ending in "...".

Detailed Description

Where the CLI server's commands reach a thread that owns some state (the main thread, or a venue's order gateway), and where that thread's answers come back.

Two lock-free slick::queues, one each way. The CLI server thread is the only one that posts and takes replies, the owner thread the only one that serves. post() refuses while MAX_IN_FLIGHT commands are unanswered, so neither ring, lossy when lapped, is lapped.

The owner calls serve() from its loop. With nothing waiting it is one acquire load.

Definition at line 87 of file cli_endpoint.hpp.

Constructor & Destructor Documentation

◆ CliEndpoint() [1/2]

slick::sim::cli::CliEndpoint::CliEndpoint ( std::string name = {})
inlineexplicit

Definition at line 93 of file cli_endpoint.hpp.

References name().

Referenced by CliEndpoint(), and operator=().

◆ CliEndpoint() [2/2]

slick::sim::cli::CliEndpoint::CliEndpoint ( const CliEndpoint & )
delete

References CliEndpoint().

Member Function Documentation

◆ busy()

bool slick::sim::cli::CliEndpoint::busy ( ) const
inlinenodiscardnoexcept

CLI server thread.

MAX_IN_FLIGHT commands posted and not yet answered through take_replies(), however long ago: one more would lap the inbox.

Definition at line 134 of file cli_endpoint.hpp.

References MAX_IN_FLIGHT.

Referenced by post().

◆ name()

const std::string & slick::sim::cli::CliEndpoint::name ( ) const
inlinenodiscardnoexcept

How the CLI addresses it, /-separated from the venue down: cme/<segment>.

Definition at line 98 of file cli_endpoint.hpp.

Referenced by CliEndpoint(), and set_name().

◆ operator=()

CliEndpoint & slick::sim::cli::CliEndpoint::operator= ( const CliEndpoint & )
delete

References CliEndpoint().

◆ post()

bool slick::sim::cli::CliEndpoint::post ( const Command & command)
inlinenodiscard

CLI server thread. False, posting nothing, while busy().

Definition at line 121 of file cli_endpoint.hpp.

References busy().

◆ serve()

template<typename Handler>
void slick::sim::cli::CliEndpoint::serve ( Handler && handler)
inline

Owner thread.

Runs bool handler(const Command &, std::string &text) on each command waiting, logs what it said and posts text back, OK when the handler returned true.

Definition at line 106 of file cli_endpoint.hpp.

References slick::sim::FAILED, slick::sim::cli::log_level(), and slick::sim::OK.

Referenced by main().

◆ set_name()

void slick::sim::cli::CliEndpoint::set_name ( std::string name)
inline

Before the endpoint is given to the CLI server.

Definition at line 100 of file cli_endpoint.hpp.

References name().

◆ take_replies()

template<typename OnReply>
void slick::sim::cli::CliEndpoint::take_replies ( OnReply && on_reply)
inline

CLI server thread.

Runs on_reply(uint64_t ticket, CliStatus, std::string_view) on each reply waiting.

Definition at line 139 of file cli_endpoint.hpp.

Member Data Documentation

◆ MAX_IN_FLIGHT

uint32_t slick::sim::cli::CliEndpoint::MAX_IN_FLIGHT = 16
staticconstexpr

Definition at line 89 of file cli_endpoint.hpp.

Referenced by busy().

◆ MAX_REPLY_TEXT

uint32_t slick::sim::cli::CliEndpoint::MAX_REPLY_TEXT = 4096
staticconstexpr

A longer reply is cut, ending in "...".

Definition at line 91 of file cli_endpoint.hpp.


The documentation for this class was generated from the following file: