Skip to content

Commit

Permalink
deprecate package key for service parameters, use full type instead (#…
Browse files Browse the repository at this point in the history
…263)

* deprecate package key for service parameters, use full type instead

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* added const to local variables

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
  • Loading branch information
dirk-thomas committed May 26, 2020
1 parent 62fd0d8 commit 06839a0
Showing 1 changed file with 62 additions and 25 deletions.
87 changes: 62 additions & 25 deletions src/parameter_bridge.cpp
Expand Up @@ -46,12 +46,16 @@ int main(int argc, char * argv[])
std::list<ros1_bridge::ServiceBridge2to1> service_bridges_2_to_1;

// bridge all topics listed in a ROS 1 parameter
// the parameter needs to be an array
// the topics parameter needs to be an array
// and each item needs to be a dictionary with the following keys;
// topic: the name of the topic to bridge
// type: the type of the topic to bridge
// topic: the name of the topic to bridge (e.g. '/topic_name')
// type: the type of the topic to bridge (e.g. 'pkgname/msg/MsgName')
// queue_size: the queue size to use (default: 100)
const char * topics_parameter_name = "topics";
// the services parameters need to be arrays
// and each item needs to be a dictionary with the following keys;
// topic: the name of the topic to bridge (e.g. '/service_name')
// type: the type of the topic to bridge (e.g. 'pkgname/srv/SrvName')
const char * services_1_to_2_parameter_name = "services_1_to_2";
const char * services_2_to_1_parameter_name = "services_2_to_1";
if (argc > 1) {
Expand Down Expand Up @@ -108,15 +112,33 @@ int main(int argc, char * argv[])
{
for (size_t i = 0; i < static_cast<size_t>(services_1_to_2.size()); ++i) {
std::string service_name = static_cast<std::string>(services_1_to_2[i]["service"]);
std::string package_name = static_cast<std::string>(services_1_to_2[i]["package"]);
std::string type_name = static_cast<std::string>(services_1_to_2[i]["type"]);
{
// for backward compatibility
std::string package_name = static_cast<std::string>(services_1_to_2[i]["package"]);
if (!package_name.empty()) {
fprintf(
stderr,
"The service '%s' uses the key 'package' which is deprecated for "
"services. Instead prepend the 'type' value with '<package>/'.\n",
service_name.c_str());
type_name = package_name + "/" + type_name;
}
}
printf(
"Trying to create bridge for ROS 2 service '%s' "
"with package '%s' and type '%s'\n",
service_name.c_str(), package_name.c_str(), type_name.c_str());
"Trying to create bridge for ROS 2 service '%s' with type '%s'\n",
service_name.c_str(), type_name.c_str());

const size_t index = type_name.find("/");
if (index == std::string::npos) {
fprintf(
stderr,
"the service '%s' has a type '%s' without a slash.\n",
service_name.c_str(), type_name.c_str());
continue;
}
auto factory = ros1_bridge::get_service_factory(
"ros2", package_name, type_name);
"ros2", type_name.substr(0, index), type_name.substr(index + 1));
if (factory) {
try {
service_bridges_1_to_2.push_back(
Expand All @@ -126,16 +148,14 @@ int main(int argc, char * argv[])
} catch (std::runtime_error & e) {
fprintf(
stderr,
"failed to create bridge ROS 1 service '%s' "
"with package '%s' and type '%s': %s\n",
service_name.c_str(), type_name.c_str(), type_name.c_str(), e.what());
"failed to create bridge ROS 1 service '%s' with type '%s': %s\n",
service_name.c_str(), type_name.c_str(), e.what());
}
} else {
fprintf(
stderr,
"failed to create bridge ROS 1 service '%s' "
"no conversion for package '%s' and type '%s'\n",
service_name.c_str(), package_name.c_str(), type_name.c_str());
"failed to create bridge ROS 1 service '%s' no conversion for type '%s'\n",
service_name.c_str(), type_name.c_str());
}
}

Expand All @@ -154,15 +174,34 @@ int main(int argc, char * argv[])
{
for (size_t i = 0; i < static_cast<size_t>(services_2_to_1.size()); ++i) {
std::string service_name = static_cast<std::string>(services_2_to_1[i]["service"]);
std::string package_name = static_cast<std::string>(services_2_to_1[i]["package"]);
std::string type_name = static_cast<std::string>(services_2_to_1[i]["type"]);
{
// for backward compatibility
std::string package_name = static_cast<std::string>(services_2_to_1[i]["package"]);
if (!package_name.empty()) {
fprintf(
stderr,
"The service '%s' uses the key 'package' which is deprecated for "
"services. Instead prepend the 'type' value with '<package>/'.\n",
service_name.c_str());
type_name = package_name + "/" + type_name;
}
}
printf(
"Trying to create bridge for ROS 1 service '%s' "
"with package '%s' and type '%s'\n",
service_name.c_str(), package_name.c_str(), type_name.c_str());
"Trying to create bridge for ROS 1 service '%s' with type '%s'\n",
service_name.c_str(), type_name.c_str());

const size_t index = type_name.find("/");
if (index == std::string::npos) {
fprintf(
stderr,
"the service '%s' has a type '%s' without a slash.\n",
service_name.c_str(), type_name.c_str());
continue;
}

auto factory = ros1_bridge::get_service_factory(
"ros1", package_name, type_name);
"ros1", type_name.substr(0, index), type_name.substr(index + 1));
if (factory) {
try {
service_bridges_2_to_1.push_back(
Expand All @@ -171,16 +210,14 @@ int main(int argc, char * argv[])
} catch (std::runtime_error & e) {
fprintf(
stderr,
"failed to create bridge ROS 2 service '%s' "
"with package '%s' and type '%s': %s\n",
service_name.c_str(), type_name.c_str(), type_name.c_str(), e.what());
"failed to create bridge ROS 2 service '%s' with type '%s': %s\n",
service_name.c_str(), type_name.c_str(), e.what());
}
} else {
fprintf(
stderr,
"failed to create bridge ROS 2 service '%s' "
"no conversion for package '%s' and type '%s'\n",
service_name.c_str(), package_name.c_str(), type_name.c_str());
"failed to create bridge ROS 2 service '%s' no conversion for type '%s'\n",
service_name.c_str(), type_name.c_str());
}
}

Expand Down

0 comments on commit 06839a0

Please sign in to comment.