28 throw std::runtime_error(
"Failed to lookup service " + serviceName);
33 auto connection = boost::make_shared<ros::Connection>();
37 if (!transport->connect(srvHost, srvPort)) {
38 throw std::runtime_error(
"Failed to connect to service server of service " + serviceName);
41 std::promise<std::string> promise;
42 auto future = promise.get_future();
44 connection->setHeaderReceivedCallback(
46 std::string serviceType;
47 if (
header.getValue(
"type", serviceType)) {
48 promise.set_value(serviceType);
50 promise.set_exception(std::make_exception_ptr(
51 std::runtime_error(
"Key 'type' not found in service connection header")));
54 conn->drop(ros::Connection::DropReason::Destructing);
59 header[
"service"] = serviceName;
62 header[
"persistent"] =
"0";
66 if (future.wait_for(timeout) != std::future_status::ready) {
69 connection->drop(ros::Connection::DropReason::Destructing);
70 throw std::runtime_error(
"Timed out when retrieving service type");