service_utils.cpp
Go to the documentation of this file.
1 #include <ros/connection.h>
2 #include <ros/service_manager.h>
4 
6 
7 namespace foxglove_bridge {
8 
9 std::future<std::string> retrieveServiceType(const std::string& serviceName) {
10  auto link = ros::ServiceManager::instance()->createServiceServerLink(serviceName, false, "*", "*",
11  {{"probe", "1"}});
12  auto promise = std::make_shared<std::promise<std::string>>();
13  auto future = promise->get_future();
14 
15  link->getConnection()->setHeaderReceivedCallback(
16  [promise = std::move(promise)](const ros::ConnectionPtr&, const ros::Header& header) mutable {
17  std::string serviceType;
18  if (header.getValue("type", serviceType)) {
19  promise->set_value(serviceType);
20  } else {
21  promise->set_exception(std::make_exception_ptr(
22  std::runtime_error("Key 'type' not found in service connection header")));
23  }
24  return true;
25  });
26 
27  return future;
28 }
29 
30 } // namespace foxglove_bridge
std::future< std::string > retrieveServiceType(const std::string &serviceName)
static const ServiceManagerPtr & instance()
bool getValue(const std::string &key, std::string &value) const
const std::string header


foxglove_bridge
Author(s): Foxglove
autogenerated on Mon Jul 3 2023 02:12:22