Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
mvsim::Client Class Reference

#include <Client.h>

Inheritance diagram for mvsim::Client:
Inheritance graph
[legend]

Classes

struct  InfoPerNode
 
struct  InfoPerTopic
 
struct  ZMQImpl
 

Public Member Functions

 Client ()
 
 Client (const std::string &nodeName)
 
void enable_profiler (bool enable)
 
const mrpt::system::CTimeLogger & profiler () const
 
 ~Client ()
 

Private Types

using service_callback_t = std::function< std::shared_ptr< google::protobuf::Message >(const std::string &)>
 

Private Member Functions

void doAdvertiseService (const std::string &serviceName, const google::protobuf::Descriptor *descIn, const google::protobuf::Descriptor *descOut, service_callback_t callback)
 
void doAdvertiseTopic (const std::string &topicName, const google::protobuf::Descriptor *descriptor)
 
void doCallService (const std::string &serviceName, const std::string &inputSerializedMsg, mrpt::optional_ref< google::protobuf::Message > outputMsg, mrpt::optional_ref< std::string > outputSerializedMsg=std::nullopt, mrpt::optional_ref< std::string > outputMsgTypeName=std::nullopt)
 
void doRegisterClient ()
 
void doSubscribeTopic (const std::string &topicName, const google::protobuf::Descriptor *descriptor, const topic_callback_t &callback)
 
void doUnregisterClient ()
 
void internalServiceServingThread ()
 
void internalTopicSubscribeThread (internal::InfoPerSubscribedTopic &ipt)
 
void internalTopicUpdatesThread ()
 

Private Attributes

std::string nodeName_ = "anonymous"
 
mrpt::system::CTimeLogger profiler_ {false, "mvsim::Client"}
 
std::string serverHostAddress_ = "localhost"
 
std::thread serviceInvokerThread_
 
std::map< std::string, std::string > serviceToEndPointCache_
 
std::mutex serviceToEndPointCacheMtx_
 
std::thread topicUpdatesThread_
 
std::unique_ptr< ZMQImplzmq_
 

Friends

struct internal::InfoPerService
 
struct internal::InfoPerSubscribedTopic
 

Main mvsim client communication API

using topic_callback_t = std::function< void(const zmq::message_t &)>
 
void setName (const std::string &nodeName)
 
const std::string & serverHostAddress () const
 
void serverHostAddress (const std::string &serverIpOrAddressName)
 
void connect ()
 
bool connected () const
 
void shutdown () noexcept
 
template<typename T >
void advertiseTopic (const std::string &topicName)
 
void publishTopic (const std::string &topicName, const google::protobuf::Message &msg)
 
template<typename MSG_T >
void subscribeTopic (const std::string &topicName, const std::function< void(const MSG_T &)> &callback)
 
template<typename INPUT_MSG_T , typename OUTPUT_MSG_T >
void advertiseService (const std::string &serviceName, const std::function< OUTPUT_MSG_T(const INPUT_MSG_T &)> &callback)
 
template<typename INPUT_MSG_T , typename OUTPUT_MSG_T >
void callService (const std::string &serviceName, const INPUT_MSG_T &input, OUTPUT_MSG_T &output)
 
std::string callService (const std::string &serviceName, const std::string &inputSerializedMsg)
 Overload for python wrapper. More...
 
void subscribeTopic (const std::string &topicName, const std::function< void(const std::string &, const std::vector< uint8_t > &)> &callback)
 Overload for python wrapper (callback accepts bytes-string) More...
 
std::vector< InfoPerNoderequestListOfNodes ()
 
std::vector< InfoPerTopicrequestListOfTopics ()
 
void subscribe_topic_raw (const std::string &topicName, const topic_callback_t &callback)
 

Detailed Description

This is the connection of any user program with the MVSIM server, so it can advertise and subscribe to topics and use remote services.

Users should instance a class mvsim::Client (C++) or mvsim.Client (Python) to communicate with the simulation runnin in mvsim::World or any other module.

Usage:

Messages and topics are described as Protobuf messages, and communications are done via ZMQ sockets.

See: https://mvsimulator.readthedocs.io/

Definition at line 48 of file Client.h.

Member Typedef Documentation

◆ service_callback_t

using mvsim::Client::service_callback_t = std::function<std::shared_ptr<google::protobuf::Message>( const std::string& )>
private

Definition at line 161 of file Client.h.

◆ topic_callback_t

using mvsim::Client::topic_callback_t = std::function<void(const zmq::message_t& )>

Definition at line 127 of file Client.h.

Constructor & Destructor Documentation

◆ Client() [1/2]

Client::Client ( )

Definition at line 119 of file src/Comms/Client.cpp.

◆ Client() [2/2]

Client::Client ( const std::string &  nodeName)

Definition at line 124 of file src/Comms/Client.cpp.

◆ ~Client()

Client::~Client ( )

Definition at line 126 of file src/Comms/Client.cpp.

Member Function Documentation

◆ advertiseService()

template<typename INPUT_MSG_T , typename OUTPUT_MSG_T >
void mvsim::Client::advertiseService ( const std::string &  serviceName,
const std::function< OUTPUT_MSG_T(const INPUT_MSG_T &)> &  callback 
)

Definition at line 193 of file Client.h.

◆ advertiseTopic()

template<typename T >
void mvsim::Client::advertiseTopic ( const std::string &  topicName)

Definition at line 187 of file Client.h.

◆ callService() [1/2]

template<typename INPUT_MSG_T , typename OUTPUT_MSG_T >
void mvsim::Client::callService ( const std::string &  serviceName,
const INPUT_MSG_T &  input,
OUTPUT_MSG_T &  output 
)

Definition at line 221 of file Client.h.

◆ callService() [2/2]

std::string Client::callService ( const std::string &  serviceName,
const std::string &  inputSerializedMsg 
)

Overload for python wrapper.

Definition at line 721 of file src/Comms/Client.cpp.

◆ connect()

void Client::connect ( )

Connects to the server in a parallel thread. Default server address is localhost, can be changed with serverHostAddress().

Definition at line 139 of file src/Comms/Client.cpp.

◆ connected()

bool Client::connected ( ) const

Whether the client is correctly connected to the server.

Definition at line 130 of file src/Comms/Client.cpp.

◆ doAdvertiseService()

void Client::doAdvertiseService ( const std::string &  serviceName,
const google::protobuf::Descriptor *  descIn,
const google::protobuf::Descriptor *  descOut,
service_callback_t  callback 
)
private

Definition at line 448 of file src/Comms/Client.cpp.

◆ doAdvertiseTopic()

void Client::doAdvertiseTopic ( const std::string &  topicName,
const google::protobuf::Descriptor *  descriptor 
)
private

Definition at line 375 of file src/Comms/Client.cpp.

◆ doCallService()

void Client::doCallService ( const std::string &  serviceName,
const std::string &  inputSerializedMsg,
mrpt::optional_ref< google::protobuf::Message >  outputMsg,
mrpt::optional_ref< std::string >  outputSerializedMsg = std::nullopt,
mrpt::optional_ref< std::string >  outputMsgTypeName = std::nullopt 
)
private

Definition at line 755 of file src/Comms/Client.cpp.

◆ doRegisterClient()

void Client::doRegisterClient ( )
private

Definition at line 243 of file src/Comms/Client.cpp.

◆ doSubscribeTopic()

void Client::doSubscribeTopic ( const std::string &  topicName,
const google::protobuf::Descriptor *  descriptor,
const topic_callback_t callback 
)
private

Definition at line 833 of file src/Comms/Client.cpp.

◆ doUnregisterClient()

void Client::doUnregisterClient ( )
private

Definition at line 272 of file src/Comms/Client.cpp.

◆ enable_profiler()

void mvsim::Client::enable_profiler ( bool  enable)
inline

Definition at line 135 of file Client.h.

◆ internalServiceServingThread()

void Client::internalServiceServingThread ( )
private

Definition at line 556 of file src/Comms/Client.cpp.

◆ internalTopicSubscribeThread()

void Client::internalTopicSubscribeThread ( internal::InfoPerSubscribedTopic &  ipt)
private

Definition at line 889 of file src/Comms/Client.cpp.

◆ internalTopicUpdatesThread()

void Client::internalTopicUpdatesThread ( )
private

Definition at line 631 of file src/Comms/Client.cpp.

◆ profiler()

const mrpt::system::CTimeLogger& mvsim::Client::profiler ( ) const
inline

Definition at line 134 of file Client.h.

◆ publishTopic()

void Client::publishTopic ( const std::string &  topicName,
const google::protobuf::Message &  msg 
)

Definition at line 506 of file src/Comms/Client.cpp.

◆ requestListOfNodes()

std::vector< Client::InfoPerNode > Client::requestListOfNodes ( )

Definition at line 302 of file src/Comms/Client.cpp.

◆ requestListOfTopics()

std::vector< Client::InfoPerTopic > Client::requestListOfTopics ( )

Definition at line 332 of file src/Comms/Client.cpp.

◆ serverHostAddress() [1/2]

const std::string& mvsim::Client::serverHostAddress ( ) const
inline

Definition at line 60 of file Client.h.

◆ serverHostAddress() [2/2]

void mvsim::Client::serverHostAddress ( const std::string &  serverIpOrAddressName)
inline

Definition at line 61 of file Client.h.

◆ setName()

void Client::setName ( const std::string &  nodeName)

Definition at line 128 of file src/Comms/Client.cpp.

◆ shutdown()

void Client::shutdown ( )
noexcept

Shutdowns the communication thread. Blocks until the thread is stopped. There is no need to manually call this method, it is called upon destruction.

Definition at line 209 of file src/Comms/Client.cpp.

◆ subscribe_topic_raw()

void Client::subscribe_topic_raw ( const std::string &  topicName,
const topic_callback_t callback 
)

Definition at line 827 of file src/Comms/Client.cpp.

◆ subscribeTopic() [1/2]

template<typename MSG_T >
void mvsim::Client::subscribeTopic ( const std::string &  topicName,
const std::function< void(const MSG_T &)> &  callback 
)

Definition at line 207 of file Client.h.

◆ subscribeTopic() [2/2]

void Client::subscribeTopic ( const std::string &  topicName,
const std::function< void(const std::string &, const std::vector< uint8_t > &)> &  callback 
)

Overload for python wrapper (callback accepts bytes-string)

Overload for python wrapper.

Definition at line 736 of file src/Comms/Client.cpp.

Friends And Related Function Documentation

◆ internal::InfoPerService

friend struct internal::InfoPerService
friend

Definition at line 182 of file Client.h.

◆ internal::InfoPerSubscribedTopic

friend struct internal::InfoPerSubscribedTopic
friend

Definition at line 183 of file Client.h.

Member Data Documentation

◆ nodeName_

std::string mvsim::Client::nodeName_ = "anonymous"
private

Definition at line 142 of file Client.h.

◆ profiler_

mrpt::system::CTimeLogger mvsim::Client::profiler_ {false, "mvsim::Client"}
private

Definition at line 150 of file Client.h.

◆ serverHostAddress_

std::string mvsim::Client::serverHostAddress_ = "localhost"
private

Definition at line 141 of file Client.h.

◆ serviceInvokerThread_

std::thread mvsim::Client::serviceInvokerThread_
private

Definition at line 144 of file Client.h.

◆ serviceToEndPointCache_

std::map<std::string, std::string> mvsim::Client::serviceToEndPointCache_
private

Definition at line 147 of file Client.h.

◆ serviceToEndPointCacheMtx_

std::mutex mvsim::Client::serviceToEndPointCacheMtx_
private

Definition at line 148 of file Client.h.

◆ topicUpdatesThread_

std::thread mvsim::Client::topicUpdatesThread_
private

Definition at line 145 of file Client.h.

◆ zmq_

std::unique_ptr<ZMQImpl> mvsim::Client::zmq_
private

Definition at line 138 of file Client.h.


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


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:23