CIRCT 24.0.0git
Loading...
Searching...
No Matches
RpcClient Class Reference

A client for the cosim RPC server. More...

#include <RpcClient.h>

Collaboration diagram for RpcClient:

Classes

struct  ChannelDesc
 Description of a channel from the server. More...
class  ReadChannelConnection
 Abstract handle for a read channel connection. More...

Public Types

enum class  ChannelDirection { ToServer , ToClient }
 Channel direction as reported by the server. More...
using ReadCallback
 Callback type for receiving messages from a client-bound channel.

Public Member Functions

 RpcClient (Logger &logger, const std::string &hostname, uint16_t port)
 RpcClient (const RpcClient &)=delete
 ~RpcClient ()
RpcClient & operator= (const RpcClient &)=delete
uint32_t getEsiVersion () const
 Get the ESI version from the manifest.
std::vector< uint8_t > getCompressedManifest () const
 Get the compressed manifest from the server.
bool getChannelDesc (const std::string &channelName, ChannelDesc &desc) const
 Get the channel description for a channel name.
std::vector< ChannelDesc > listChannels () const
 List all channels available on the server.
void writeToServer (const std::string &channelName, const MessageData &data)
 Send a message to a server-bound channel.
bool tryWriteToServer (const std::string &channelName, const std::vector< MessageData > &frames, bool force=false)
 Non-blocking send of one message, split into frames, to a server-bound channel.
void setToServerMaxInFlight (const std::string &channelName, unsigned maxInFlight)
 Set the maximum number of unconsumed frames on a server-bound channel.
std::unique_ptr< ReadChannelConnection > connectClientReceiver (const std::string &channelName, ReadCallback callback, unsigned maxInFlight=DefaultToClientMaxInFlight)
 Connect to a client-bound channel and receive messages via callback.

Static Public Attributes

static constexpr unsigned DefaultToServerMaxInFlight = 16
 Default maximum number of frames sent to a server-bound channel which the simulation has not yet consumed.
static constexpr unsigned DefaultToClientMaxInFlight = 32
 Default maximum number of frames in flight (queued in the simulator or sent but not yet consumed by the client) on a client-bound channel.

Private Attributes

std::unique_ptr< Impl > impl

Detailed Description

A client for the cosim RPC server.

Hides the WebSocket + JSON transport behind a small C++ API; see cosim-protocol.md for the wire format.

Definition at line 34 of file RpcClient.h.

Member Typedef Documentation

◆ ReadCallback

Initial value:
std::function<bool(std::unique_ptr<SegmentedMessageData> &)>

Callback type for receiving messages from a client-bound channel.

Return true if the message was consumed, false to retry the same owning message object.

Definition at line 97 of file RpcClient.h.

Member Enumeration Documentation

◆ ChannelDirection

Channel direction as reported by the server.

Enumerator
ToServer 
ToClient 

Definition at line 50 of file RpcClient.h.

Constructor & Destructor Documentation

◆ RpcClient() [1/2]

RpcClient::RpcClient ( Logger & logger,
const std::string & hostname,
uint16_t port )

Definition at line 932 of file RpcClient.cpp.

◆ RpcClient() [2/2]

◆ ~RpcClient()

RpcClient::~RpcClient ( )
default

Member Function Documentation

◆ connectClientReceiver()

std::unique_ptr< RpcClient::ReadChannelConnection > RpcClient::connectClientReceiver ( const std::string & channelName,
ReadCallback callback,
unsigned maxInFlight = DefaultToClientMaxInFlight )

Connect to a client-bound channel and receive messages via callback.

maxInFlight is the maximum number of frames the simulator may have in flight for this channel; zero means unbounded. A frame stops counting once callback returns true for it. Returns a handle that disconnects when destroyed.

Definition at line 969 of file RpcClient.cpp.

◆ getChannelDesc()

bool RpcClient::getChannelDesc ( const std::string & channelName,
ChannelDesc & desc ) const

Get the channel description for a channel name.

Returns true if the channel was found.

Definition at line 943 of file RpcClient.cpp.

◆ getCompressedManifest()

std::vector< uint8_t > RpcClient::getCompressedManifest ( ) const

Get the compressed manifest from the server.

Definition at line 939 of file RpcClient.cpp.

◆ getEsiVersion()

uint32_t RpcClient::getEsiVersion ( ) const

Get the ESI version from the manifest.

Definition at line 937 of file RpcClient.cpp.

◆ listChannels()

std::vector< RpcClient::ChannelDesc > RpcClient::listChannels ( ) const

List all channels available on the server.

Definition at line 948 of file RpcClient.cpp.

◆ operator=()

RpcClient & esi::backends::cosim::RpcClient::operator= ( const RpcClient & )
delete

◆ setToServerMaxInFlight()

void RpcClient::setToServerMaxInFlight ( const std::string & channelName,
unsigned maxInFlight )

Set the maximum number of unconsumed frames on a server-bound channel.

Zero means unbounded.

Definition at line 963 of file RpcClient.cpp.

◆ tryWriteToServer()

bool RpcClient::tryWriteToServer ( const std::string & channelName,
const std::vector< MessageData > & frames,
bool force = false )

Non-blocking send of one message, split into frames, to a server-bound channel.

If the channel is below its in-flight limit, sends all of them (possibly overshooting the limit by frames.size() - 1) and returns true. Otherwise sends nothing and returns false. With force, sends regardless of the limit (but still counts the frames as in flight); for the rest of a message whose first part was admitted.

Definition at line 957 of file RpcClient.cpp.

◆ writeToServer()

void RpcClient::writeToServer ( const std::string & channelName,
const MessageData & data )

Send a message to a server-bound channel.

Blocks while the channel's in-flight limit is reached. Throws if the connection is lost. Frames sent before the simulation has connected its end of the channel are held by the server (and count as in flight), not dropped.

Definition at line 952 of file RpcClient.cpp.

Member Data Documentation

◆ DefaultToClientMaxInFlight

Default maximum number of frames in flight (queued in the simulator or sent but not yet consumed by the client) on a client-bound channel.

Definition at line 71 of file RpcClient.h.

◆ DefaultToServerMaxInFlight

Default maximum number of frames sent to a server-bound channel which the simulation has not yet consumed.

Definition at line 68 of file RpcClient.h.

◆ impl

std::unique_ptr<Impl> esi::backends::cosim::RpcClient::impl
private

Definition at line 121 of file RpcClient.h.


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