#include <Client.h>
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< ZMQImpl > | zmq_ |
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< InfoPerNode > | requestListOfNodes () |
std::vector< InfoPerTopic > | requestListOfTopics () |
void | subscribe_topic_raw (const std::string &topicName, const topic_callback_t &callback) |
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.
|
private |
using mvsim::Client::topic_callback_t = std::function<void(const zmq::message_t& )> |
Client::Client | ( | ) |
Definition at line 119 of file src/Comms/Client.cpp.
Client::Client | ( | const std::string & | nodeName | ) |
Definition at line 124 of file src/Comms/Client.cpp.
Client::~Client | ( | ) |
Definition at line 126 of file src/Comms/Client.cpp.
void mvsim::Client::advertiseService | ( | const std::string & | serviceName, |
const std::function< OUTPUT_MSG_T(const INPUT_MSG_T &)> & | callback | ||
) |
void mvsim::Client::advertiseTopic | ( | const std::string & | topicName | ) |
void mvsim::Client::callService | ( | const std::string & | serviceName, |
const INPUT_MSG_T & | input, | ||
OUTPUT_MSG_T & | output | ||
) |
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.
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.
bool Client::connected | ( | ) | const |
Whether the client is correctly connected to the server.
Definition at line 130 of file src/Comms/Client.cpp.
|
private |
Definition at line 448 of file src/Comms/Client.cpp.
|
private |
Definition at line 375 of file src/Comms/Client.cpp.
|
private |
Definition at line 755 of file src/Comms/Client.cpp.
|
private |
Definition at line 243 of file src/Comms/Client.cpp.
|
private |
Definition at line 833 of file src/Comms/Client.cpp.
|
private |
Definition at line 272 of file src/Comms/Client.cpp.
|
private |
Definition at line 556 of file src/Comms/Client.cpp.
|
private |
Definition at line 889 of file src/Comms/Client.cpp.
|
private |
Definition at line 631 of file src/Comms/Client.cpp.
|
inline |
void Client::publishTopic | ( | const std::string & | topicName, |
const google::protobuf::Message & | msg | ||
) |
Definition at line 506 of file src/Comms/Client.cpp.
std::vector< Client::InfoPerNode > Client::requestListOfNodes | ( | ) |
Definition at line 302 of file src/Comms/Client.cpp.
std::vector< Client::InfoPerTopic > Client::requestListOfTopics | ( | ) |
Definition at line 332 of file src/Comms/Client.cpp.
|
inline |
|
inline |
void Client::setName | ( | const std::string & | nodeName | ) |
Definition at line 128 of file src/Comms/Client.cpp.
|
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.
void Client::subscribe_topic_raw | ( | const std::string & | topicName, |
const topic_callback_t & | callback | ||
) |
Definition at line 827 of file src/Comms/Client.cpp.
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.
|
private |
|
private |
|
private |
|
private |