xrpld
Loading...
Searching...
No Matches
xrpl::test::WSClientImpl Class Reference
Inheritance diagram for xrpl::test::WSClientImpl:
Collaboration diagram for xrpl::test::WSClientImpl:

Classes

struct  Msg

Public Member Functions

 WSClientImpl (Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers={})
 ~WSClientImpl () override
json::Value invoke (std::string const &cmd, json::Value const &params) override
 Submit a command synchronously.
std::optional< json::ValuegetMsg (std::chrono::milliseconds const &timeout) override
 Retrieve a message.
std::optional< json::ValuefindMsg (std::chrono::milliseconds const &timeout, std::function< bool(json::Value const &)> pred) override
 Retrieve a message that meets the predicate criteria.
unsigned version () const override
 Get RPC 1.0 or RPC 2.0.

Private Types

using error_code = boost::system::error_code

Private Member Functions

void cleanup ()
void onReadMsg (error_code const &ec)
void onReadDone ()

Static Private Member Functions

static boost::asio::ip::tcp::endpoint getEndpoint (BasicConfig const &cfg, bool v2)
template<class ConstBuffers>
static std::string bufferString (ConstBuffers const &b)

Private Attributes

boost::asio::io_context ios_
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
std::thread thread_
boost::asio::ip::tcp::socket stream_
boost::beast::websocket::stream< boost::asio::ip::tcp::socket & > ws_
boost::beast::multi_buffer rb_
bool peerClosed_ = false
bool b0_ = false
std::mutex m0_
std::condition_variable cv0_
std::mutex m_
std::condition_variable cv_
std::list< std::shared_ptr< Msg > > msgs_
unsigned rpcVersion_

Detailed Description

Definition at line 48 of file WSClient.cpp.

Member Typedef Documentation

◆ error_code

using xrpl::test::WSClientImpl::error_code = boost::system::error_code
private

Definition at line 50 of file WSClient.cpp.

Constructor & Destructor Documentation

◆ WSClientImpl()

xrpl::test::WSClientImpl::WSClientImpl ( Config const & cfg,
bool v2,
unsigned rpcVersion,
std::unordered_map< std::string, std::string > const & headers = {} )

Definition at line 151 of file WSClient.cpp.

◆ ~WSClientImpl()

xrpl::test::WSClientImpl::~WSClientImpl ( )
override

Definition at line 186 of file WSClient.cpp.

Member Function Documentation

◆ getEndpoint()

boost::asio::ip::tcp::endpoint xrpl::test::WSClientImpl::getEndpoint ( BasicConfig const & cfg,
bool v2 )
staticprivate

Definition at line 62 of file WSClient.cpp.

◆ bufferString()

template<class ConstBuffers>
std::string xrpl::test::WSClientImpl::bufferString ( ConstBuffers const & b)
staticprivate

Definition at line 94 of file WSClient.cpp.

◆ cleanup()

void xrpl::test::WSClientImpl::cleanup ( )
private

Definition at line 127 of file WSClient.cpp.

◆ invoke()

json::Value xrpl::test::WSClientImpl::invoke ( std::string const & cmd,
json::Value const & params )
overridevirtual

Submit a command synchronously.

The arguments to the function and the returned JSON are in a normalized format, the same whether the client is using the JSON-RPC over HTTP/S or WebSocket transport.

Parameters
cmdThe command to execute
paramsjson::Value of null or object type with zero or more key/value pairs.
Returns
The server response in normalized format.

Implements xrpl::test::AbstractClient.

Definition at line 192 of file WSClient.cpp.

◆ getMsg()

std::optional< json::Value > xrpl::test::WSClientImpl::getMsg ( std::chrono::milliseconds const & timeout)
overridevirtual

Retrieve a message.

Implements xrpl::test::WSClient.

Definition at line 246 of file WSClient.cpp.

◆ findMsg()

std::optional< json::Value > xrpl::test::WSClientImpl::findMsg ( std::chrono::milliseconds const & timeout,
std::function< bool(json::Value const &)> pred )
overridevirtual

Retrieve a message that meets the predicate criteria.

Implements xrpl::test::WSClient.

Definition at line 260 of file WSClient.cpp.

◆ version()

unsigned xrpl::test::WSClientImpl::version ( ) const
nodiscardoverridevirtual

Get RPC 1.0 or RPC 2.0.

Implements xrpl::test::AbstractClient.

Definition at line 286 of file WSClient.cpp.

◆ onReadMsg()

void xrpl::test::WSClientImpl::onReadMsg ( error_code const & ec)
private

Definition at line 293 of file WSClient.cpp.

◆ onReadDone()

void xrpl::test::WSClientImpl::onReadDone ( )
private

Definition at line 320 of file WSClient.cpp.

Member Data Documentation

◆ ios_

boost::asio::io_context xrpl::test::WSClientImpl::ios_
private

Definition at line 104 of file WSClient.cpp.

◆ work_

std::optional<boost::asio::executor_work_guard<boost::asio::io_context::executor_type> > xrpl::test::WSClientImpl::work_
private

Definition at line 105 of file WSClient.cpp.

◆ strand_

boost::asio::strand<boost::asio::io_context::executor_type> xrpl::test::WSClientImpl::strand_
private

Definition at line 106 of file WSClient.cpp.

◆ thread_

std::thread xrpl::test::WSClientImpl::thread_
private

Definition at line 107 of file WSClient.cpp.

◆ stream_

boost::asio::ip::tcp::socket xrpl::test::WSClientImpl::stream_
private

Definition at line 108 of file WSClient.cpp.

◆ ws_

boost::beast::websocket::stream<boost::asio::ip::tcp::socket&> xrpl::test::WSClientImpl::ws_
private

Definition at line 109 of file WSClient.cpp.

◆ rb_

boost::beast::multi_buffer xrpl::test::WSClientImpl::rb_
private

Definition at line 110 of file WSClient.cpp.

◆ peerClosed_

bool xrpl::test::WSClientImpl::peerClosed_ = false
private

Definition at line 112 of file WSClient.cpp.

◆ b0_

bool xrpl::test::WSClientImpl::b0_ = false
private

Definition at line 115 of file WSClient.cpp.

◆ m0_

std::mutex xrpl::test::WSClientImpl::m0_
private

Definition at line 116 of file WSClient.cpp.

◆ cv0_

std::condition_variable xrpl::test::WSClientImpl::cv0_
private

Definition at line 117 of file WSClient.cpp.

◆ m_

std::mutex xrpl::test::WSClientImpl::m_
private

Definition at line 120 of file WSClient.cpp.

◆ cv_

std::condition_variable xrpl::test::WSClientImpl::cv_
private

Definition at line 121 of file WSClient.cpp.

◆ msgs_

std::list<std::shared_ptr<Msg> > xrpl::test::WSClientImpl::msgs_
private

Definition at line 122 of file WSClient.cpp.

◆ rpcVersion_

unsigned xrpl::test::WSClientImpl::rpcVersion_
private

Definition at line 124 of file WSClient.cpp.