12 #include <mrpt/system/COutputLogger.h> 13 #include <mrpt/system/CTimeLogger.h> 23 struct InfoPerService;
24 struct InfoPerSubscribedTopic;
48 class Client :
public mrpt::system::COutputLogger
52 Client(
const std::string& nodeName);
58 void setName(
const std::string& nodeName);
63 ASSERT_(!connected());
64 serverHostAddress_ = serverIpOrAddressName;
74 bool connected()
const;
82 void advertiseTopic(
const std::string& topicName);
85 const std::string& topicName,
const google::protobuf::Message& msg);
87 template <
typename MSG_T>
89 const std::string& topicName,
90 const std::function<
void(
const MSG_T&)>& callback);
92 template <
typename INPUT_MSG_T,
typename OUTPUT_MSG_T>
94 const std::string& serviceName,
95 const std::function<OUTPUT_MSG_T(
const INPUT_MSG_T&)>& callback);
97 template <
typename INPUT_MSG_T,
typename OUTPUT_MSG_T>
99 const std::string& serviceName,
const INPUT_MSG_T& input,
100 OUTPUT_MSG_T& output);
103 std::string callService(
104 const std::string& serviceName,
const std::string& inputSerializedMsg);
108 const std::string& topicName,
109 const std::function<
void(
111 const std::vector<uint8_t>& )>& callback);
117 std::vector<InfoPerNode> requestListOfNodes();
125 std::vector<InfoPerTopic> requestListOfTopics();
129 void subscribe_topic_raw(
134 const mrpt::system::CTimeLogger&
profiler()
const {
return profiler_; }
139 std::unique_ptr<ZMQImpl>
zmq_;
141 std::string serverHostAddress_ =
"localhost";
142 std::string nodeName_ =
"anonymous";
150 mrpt::system::CTimeLogger profiler_{
false,
"mvsim::Client"};
152 void doRegisterClient();
153 void doUnregisterClient();
155 void internalServiceServingThread();
156 void internalTopicUpdatesThread();
157 void internalTopicSubscribeThread(internal::InfoPerSubscribedTopic& ipt);
160 std::function<std::shared_ptr<google::protobuf::Message>(
161 const std::string& )>;
163 void doAdvertiseTopic(
164 const std::string& topicName,
165 const google::protobuf::Descriptor* descriptor);
166 void doAdvertiseService(
167 const std::string& serviceName,
168 const google::protobuf::Descriptor* descIn,
169 const google::protobuf::Descriptor* descOut,
172 void doSubscribeTopic(
173 const std::string& topicName,
174 const google::protobuf::Descriptor* descriptor,
177 const std::string& serviceName,
const std::string& inputSerializedMsg,
178 mrpt::optional_ref<google::protobuf::Message> outputMsg,
179 mrpt::optional_ref<std::string> outputSerializedMsg = std::nullopt,
180 mrpt::optional_ref<std::string> outputMsgTypeName = std::nullopt);
182 friend struct internal::InfoPerService;
183 friend struct internal::InfoPerSubscribedTopic;
186 template <
typename T>
189 doAdvertiseTopic(topicName, T::descriptor());
192 template <
typename INPUT_MSG_T,
typename OUTPUT_MSG_T>
194 const std::string& serviceName,
195 const std::function<OUTPUT_MSG_T(
const INPUT_MSG_T&)>& callback)
198 serviceName, INPUT_MSG_T::descriptor(), OUTPUT_MSG_T::descriptor(),
201 in.ParseFromString(inData);
202 return std::make_shared<OUTPUT_MSG_T>(callback(in));
206 template <
typename MSG_T>
208 const std::string& topicName,
209 const std::function<
void(
const MSG_T&)>& callback)
212 topicName, MSG_T::descriptor(),
215 mvsim::parseMessage(m, in);
220 template <
typename INPUT_MSG_T,
typename OUTPUT_MSG_T>
222 const std::string& serviceName,
const INPUT_MSG_T& input,
223 OUTPUT_MSG_T& output)
225 doCallService(serviceName, input.SerializeAsString(), output);
void enable_profiler(bool enable)
std::thread topicUpdatesThread_
const mrpt::system::CTimeLogger & profiler() const
std::unique_ptr< ZMQImpl > zmq_
std::map< std::string, std::string > serviceToEndPointCache_
void subscribeTopic(const std::string &topicName, const std::function< void(const MSG_T &)> &callback)
ServiceServer advertiseService(ros::NodeHandle n, std::string name, boost::function< bool(const typename ActionSpec::_action_goal_type::_goal_type &, typename ActionSpec::_action_result_type::_result_type &result)> service_cb)
std::function< void(const zmq::message_t &)> topic_callback_t
void advertiseService(const std::string &serviceName, const std::function< OUTPUT_MSG_T(const INPUT_MSG_T &)> &callback)
void callService(const std::string &serviceName, const INPUT_MSG_T &input, OUTPUT_MSG_T &output)
void serverHostAddress(const std::string &serverIpOrAddressName)
typedef void(GLAD_API_PTR *GLDEBUGPROC)(GLenum source
std::thread serviceInvokerThread_
void advertiseTopic(const std::string &topicName)
ROSCONSOLE_DECL void shutdown()
const std::string & serverHostAddress() const
std::vector< std::string > publishers
std::function< std::shared_ptr< google::protobuf::Message >(const std::string &)> service_callback_t
std::mutex serviceToEndPointCacheMtx_