CIRCT 24.0.0git
Loading...
Searching...
No Matches
RpcServer::Impl Class Reference
Collaboration diagram for RpcServer::Impl:

Classes

struct  ChannelInfo
struct  ClientSession

Public Member Functions

 Impl (Context &ctxt, int port)
 ~Impl ()
Context & getContext ()
void setManifest (int esiVersion, const std::vector< uint8_t > &compressedManifest)
ReadChannelPort & registerReadPort (const std::string &name, const std::string &type)
WriteChannelPort & registerWritePort (const std::string &name, const std::string &type)
void messageConsumed (ReadChannelPort &port)
void stop (uint32_t timeoutMS)
int getPort () const
void logRefusedFrame (uint64_t channelId, size_t size)
 Log that a size-byte frame for channel channelId was dropped since the simulator-side consumer refused it.

Public Attributes

utils::ReadyIdSet< uint64_t > readyIds

Private Types

using ChannelDirection = backends::cosim::RpcClient::ChannelDirection

Private Member Functions

std::shared_ptr< ClientSession > getSession ()
 The active session, if any.
std::shared_ptr< ClientSession > sessionFor (const ix::WebSocket &ws)
 The active session if ws is its socket, else null.
void onClientMessage (const std::weak_ptr< ix::WebSocket > &wsWeak, ix::WebSocket &ws, const ix::WebSocketMessagePtr &msg)
void onOpen (const std::weak_ptr< ix::WebSocket > &wsWeak)
void onClose (ix::WebSocket &ws)
void handleBinaryFrame (uint64_t generation, const std::string &data)
void handleControlFrame (ix::WebSocket &ws, const std::string &text)
void handleEvent (uint64_t generation, const json &frame)
void handleHello (ix::WebSocket &ws, uint64_t requestId, const json &params)
void handleSubscribe (ix::WebSocket &ws, uint64_t requestId, const json &params)
void handleUnsubscribe (ix::WebSocket &ws, uint64_t requestId, const json &params)
std::optional< ChannelInfo > findChannel (ix::WebSocket &ws, uint64_t requestId, uint64_t channelId, ChannelDirection dir)
 Look up a channel.
void sendResult (ix::WebSocket &ws, uint64_t requestId, const json &result)
void sendError (ix::WebSocket &ws, uint64_t requestId, const std::string &code, const std::string &message)
void transportLoop ()
void sendConsumedEvent (const std::unordered_set< uint64_t > &ids)
 Send a batched consumed event for any to-server messages the simulation has consumed since the last call.
void retireSession (uint64_t generation)
 Forget all per-channel state belonging to client session generation, which has disconnected.

Private Attributes

Context & ctxt
std::mutex manifestMutex
std::condition_variable manifestReadyCV
int esiVersion = -1
std::vector< uint8_t > compressedManifest
bool manifestReady = false
std::mutex channelsMutex
std::map< std::string, std::unique_ptr< RpcServerReadPort > > readPorts
std::map< std::string, std::unique_ptr< RpcServerWritePort > > writePorts
std::unordered_map< uint64_t, ChannelInfo > channelById
std::unordered_map< std::string, uint64_t > idByName
uint64_t nextChannelId = 0
std::mutex sessionMutex
std::shared_ptr< ClientSession > session
uint64_t nextSessionGeneration = 1
std::thread transportThread
std::unique_ptr< ix::WebSocketServer > server
int boundPort = -1
::esi::cosim::FaultStash faultStash

Detailed Description

Definition at line 129 of file RpcServer.cpp.

Member Typedef Documentation

◆ ChannelDirection

Constructor & Destructor Documentation

◆ Impl()

Impl::Impl ( Context & ctxt,
int port )

Definition at line 673 of file RpcServer.cpp.

◆ ~Impl()

Definition at line 727 of file RpcServer.cpp.

Member Function Documentation

◆ findChannel()

std::optional< Impl::ChannelInfo > Impl::findChannel ( ix::WebSocket & ws,
uint64_t requestId,
uint64_t channelId,
ChannelDirection dir )
private

Look up a channel.

If it doesn't exist or doesn't have direction dir, reply with an error and return nullopt.

Definition at line 1244 of file RpcServer.cpp.

◆ getContext()

Definition at line 134 of file RpcServer.cpp.

◆ getPort()

Definition at line 146 of file RpcServer.cpp.

◆ getSession()

std::shared_ptr< ClientSession > esi::cosim::RpcServer::Impl::getSession ( )
inlineprivate

The active session, if any.

The returned pointer stays valid after the client disconnects; sends on it then just fail.

Definition at line 229 of file RpcServer.cpp.

◆ handleBinaryFrame()

void Impl::handleBinaryFrame ( uint64_t generation,
const std::string & data )
private

Definition at line 927 of file RpcServer.cpp.

◆ handleControlFrame()

void Impl::handleControlFrame ( ix::WebSocket & ws,
const std::string & text )
private

Definition at line 973 of file RpcServer.cpp.

◆ handleEvent()

void Impl::handleEvent ( uint64_t generation,
const json & frame )
private

Definition at line 1066 of file RpcServer.cpp.

◆ handleHello()

void Impl::handleHello ( ix::WebSocket & ws,
uint64_t requestId,
const json & params )
private

Definition at line 1095 of file RpcServer.cpp.

◆ handleSubscribe()

void Impl::handleSubscribe ( ix::WebSocket & ws,
uint64_t requestId,
const json & params )
private

Definition at line 1152 of file RpcServer.cpp.

◆ handleUnsubscribe()

void Impl::handleUnsubscribe ( ix::WebSocket & ws,
uint64_t requestId,
const json & params )
private

Definition at line 1202 of file RpcServer.cpp.

◆ logRefusedFrame()

void Impl::logRefusedFrame ( uint64_t channelId,
size_t size )

Log that a size-byte frame for channel channelId was dropped since the simulator-side consumer refused it.

Definition at line 966 of file RpcServer.cpp.

◆ messageConsumed()

Definition at line 774 of file RpcServer.cpp.

◆ onClientMessage()

void Impl::onClientMessage ( const std::weak_ptr< ix::WebSocket > & wsWeak,
ix::WebSocket & ws,
const ix::WebSocketMessagePtr & msg )
private

Definition at line 834 of file RpcServer.cpp.

◆ onClose()

void Impl::onClose ( ix::WebSocket & ws)
private

Definition at line 902 of file RpcServer.cpp.

◆ onOpen()

void Impl::onOpen ( const std::weak_ptr< ix::WebSocket > & wsWeak)
private

Definition at line 872 of file RpcServer.cpp.

◆ registerReadPort()

ReadChannelPort & Impl::registerReadPort ( const std::string & name,
const std::string & type )

Definition at line 759 of file RpcServer.cpp.

◆ registerWritePort()

WriteChannelPort & Impl::registerWritePort ( const std::string & name,
const std::string & type )

Definition at line 780 of file RpcServer.cpp.

◆ retireSession()

void Impl::retireSession ( uint64_t generation)
private

Forget all per-channel state belonging to client session generation, which has disconnected.

Definition at line 919 of file RpcServer.cpp.

◆ sendConsumedEvent()

void Impl::sendConsumedEvent ( const std::unordered_set< uint64_t > & ids)
private

Send a batched consumed event for any to-server messages the simulation has consumed since the last call.

Transport thread only.

Definition at line 1348 of file RpcServer.cpp.

◆ sendError()

void Impl::sendError ( ix::WebSocket & ws,
uint64_t requestId,
const std::string & code,
const std::string & message )
private

Definition at line 1281 of file RpcServer.cpp.

◆ sendResult()

void Impl::sendResult ( ix::WebSocket & ws,
uint64_t requestId,
const json & result )
private

Definition at line 1270 of file RpcServer.cpp.

◆ sessionFor()

std::shared_ptr< ClientSession > esi::cosim::RpcServer::Impl::sessionFor ( const ix::WebSocket & ws)
inlineprivate

The active session if ws is its socket, else null.

Requests are handled through this, so one still being handled when its client disconnects can't act on a replacement client's session.

Definition at line 236 of file RpcServer.cpp.

◆ setManifest()

void Impl::setManifest ( int esiVersion,
const std::vector< uint8_t > & compressedManifest )

Definition at line 747 of file RpcServer.cpp.

◆ stop()

void Impl::stop ( uint32_t timeoutMS)

Definition at line 795 of file RpcServer.cpp.

◆ transportLoop()

void Impl::transportLoop ( )
private

Definition at line 1297 of file RpcServer.cpp.

Member Data Documentation

◆ boundPort

Definition at line 248 of file RpcServer.cpp.

◆ channelById

std::unordered_map<uint64_t, ChannelInfo> esi::cosim::RpcServer::Impl::channelById
private

Definition at line 218 of file RpcServer.cpp.

◆ channelsMutex

Definition at line 215 of file RpcServer.cpp.

◆ compressedManifest

Definition at line 210 of file RpcServer.cpp.

◆ ctxt

Definition at line 203 of file RpcServer.cpp.

◆ esiVersion

Definition at line 209 of file RpcServer.cpp.

◆ faultStash

◆ idByName

std::unordered_map<std::string, uint64_t> esi::cosim::RpcServer::Impl::idByName
private

Definition at line 219 of file RpcServer.cpp.

◆ manifestMutex

Definition at line 207 of file RpcServer.cpp.

◆ manifestReady

Definition at line 211 of file RpcServer.cpp.

◆ manifestReadyCV

std::condition_variable esi::cosim::RpcServer::Impl::manifestReadyCV
private

Definition at line 208 of file RpcServer.cpp.

◆ nextChannelId

Definition at line 220 of file RpcServer.cpp.

◆ nextSessionGeneration

Definition at line 225 of file RpcServer.cpp.

◆ readPorts

std::map<std::string, std::unique_ptr<RpcServerReadPort> > esi::cosim::RpcServer::Impl::readPorts
private

Definition at line 216 of file RpcServer.cpp.

◆ readyIds

◆ server

std::unique_ptr<ix::WebSocketServer> esi::cosim::RpcServer::Impl::server
private

Definition at line 247 of file RpcServer.cpp.

◆ session

Definition at line 224 of file RpcServer.cpp.

◆ sessionMutex

Definition at line 223 of file RpcServer.cpp.

◆ transportThread

Definition at line 244 of file RpcServer.cpp.

◆ writePorts

std::map<std::string, std::unique_ptr<RpcServerWritePort> > esi::cosim::RpcServer::Impl::writePorts
private

Definition at line 217 of file RpcServer.cpp.


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