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)
 
 ~Client ()
 
Main mvsim client communication API
void setName (const std::string &nodeName)
 
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)
 
std::vector< InfoPerNoderequestListOfNodes ()
 
std::vector< InfoPerTopicrequestListOfTopics ()
 

Private Types

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

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"
 
std::string serverHostAddress_ = "localhost"
 
std::thread serviceInvokerThread_
 
std::thread topicUpdatesThread_
 
std::unique_ptr< ZMQImplzmq_
 

Friends

struct internal::InfoPerService
 
struct internal::InfoPerSubscribedTopic
 

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 47 of file Client.h.

Member Typedef Documentation

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

Definition at line 130 of file Client.h.

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

Definition at line 141 of file Client.h.

Constructor & Destructor Documentation

Client::Client ( )

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

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

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

Client::~Client ( )

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

Member Function Documentation

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 164 of file Client.h.

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

Definition at line 158 of file Client.h.

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 192 of file Client.h.

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

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

void Client::connect ( )

Connects to the server in a parallel thread.

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

bool Client::connected ( ) const

Whether the client is correctly connected to the server.

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

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 419 of file src/Comms/Client.cpp.

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

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

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 705 of file src/Comms/Client.cpp.

void Client::doRegisterClient ( )
private

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

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

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

void Client::doUnregisterClient ( )
private

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

void Client::internalServiceServingThread ( )
private

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

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

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

void Client::internalTopicUpdatesThread ( )
private

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

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

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

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

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

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

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

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

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

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 204 of file src/Comms/Client.cpp.

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

Definition at line 178 of file Client.h.

Friends And Related Function Documentation

friend struct internal::InfoPerService
friend

Definition at line 153 of file Client.h.

friend struct internal::InfoPerSubscribedTopic
friend

Definition at line 154 of file Client.h.

Member Data Documentation

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

Definition at line 116 of file Client.h.

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

Definition at line 115 of file Client.h.

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

Definition at line 118 of file Client.h.

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

Definition at line 119 of file Client.h.

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

Definition at line 112 of file Client.h.


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


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:52