Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <yadunund@openrobotics.org>
  • Loading branch information
Yadunund committed Dec 28, 2023
1 parent bac9f11 commit 33c1bdd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
41 changes: 20 additions & 21 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void GraphCache::parse_put(const std::string & keyexpr)
if (entity.type() != EntityType::Publisher &&
entity.type() != EntityType::Subscription &&
entity.type() != EntityType::Service &&
entity.type() != EntityType::Client) {
entity.type() != EntityType::Client)
{
RCUTILS_LOG_WARN_NAMED(
"rmw_zenoh_cpp",
"add_topic_data() for invalid EntityType. Report this.");
Expand All @@ -92,29 +93,27 @@ void GraphCache::parse_put(const std::string & keyexpr)
const liveliness::TopicInfo topic_info = entity.topic_info().value();
std::string entity_desc = "";
GraphNode::TopicMap & topic_map =
[&]() -> GraphNode::TopicMap&
[&]() -> GraphNode::TopicMap &
{
if (entity.type() == EntityType::Publisher) {
entity_desc = "publisher";
return graph_node.pubs_;
}
else if (entity.type() == EntityType::Subscription) {
} else if (entity.type() == EntityType::Subscription) {
entity_desc = "subscription";
return graph_node.subs_;
}
else if (entity.type() == EntityType::Service) {
} else if (entity.type() == EntityType::Service) {
entity_desc = "service";
return graph_node.services_;

}
else {
} else {
entity_desc = "client";
return graph_node.clients_;
}
}();
// For the sake of reusing data structures and lookup functions, we treat publishers and clients are equivalent.
// Similarly, subscriptions and services are equivalent.
const std::size_t pub_count = entity.type() == EntityType::Publisher || entity.type() == EntityType::Client ? 1 : 0;
const std::size_t pub_count = entity.type() == EntityType::Publisher ||
entity.type() == EntityType::Client ? 1 : 0;
const std::size_t sub_count = !pub_count;

TopicDataPtr graph_topic_data = std::make_shared<TopicData>(
Expand Down Expand Up @@ -332,7 +331,8 @@ void GraphCache::parse_del(const std::string & keyexpr)
if (entity.type() != EntityType::Publisher &&
entity.type() != EntityType::Subscription &&
entity.type() != EntityType::Service &&
entity.type() != EntityType::Client) {
entity.type() != EntityType::Client)
{
RCUTILS_LOG_WARN_NAMED(
"rmw_zenoh_cpp",
"remove_topic_data() for invalid EntityType. Report this.");
Expand All @@ -350,29 +350,27 @@ void GraphCache::parse_del(const std::string & keyexpr)
const liveliness::TopicInfo topic_info = entity.topic_info().value();
std::string entity_desc = "";
GraphNode::TopicMap & topic_map =
[&]() -> GraphNode::TopicMap&
[&]() -> GraphNode::TopicMap &
{
if (entity.type() == EntityType::Publisher) {
entity_desc = "publisher";
return graph_node.pubs_;
}
else if (entity.type() == EntityType::Subscription) {
} else if (entity.type() == EntityType::Subscription) {
entity_desc = "subscription";
return graph_node.subs_;
}
else if (entity.type() == EntityType::Service) {
} else if (entity.type() == EntityType::Service) {
entity_desc = "service";
return graph_node.services_;

}
else {
} else {
entity_desc = "client";
return graph_node.clients_;
}
}();
// For the sake of reusing data structures and lookup functions, we treat publishers and clients are equivalent.
// Similarly, subscriptions and services are equivalent.
const std::size_t pub_count = entity.type() == EntityType::Publisher || entity.type() == EntityType::Client ? 1 : 0;
const std::size_t pub_count = entity.type() == EntityType::Publisher ||
entity.type() == EntityType::Client ? 1 : 0;
const std::size_t sub_count = !pub_count;

GraphNode::TopicMap::iterator topic_it = topic_map.find(topic_info.name_);
Expand Down Expand Up @@ -464,7 +462,8 @@ void GraphCache::parse_del(const std::string & keyexpr)
);
auto remove_topics =
[&](const GraphNode::TopicMap & topic_map, const EntityType & entity_type) -> void {
std::size_t pub_count = entity_type == EntityType::Publisher || entity_type == EntityType::Client ? 1 : 0;
std::size_t pub_count = entity_type == EntityType::Publisher ||
entity_type == EntityType::Client ? 1 : 0;
std::size_t sub_count = !pub_count;
for (auto topic_it = topic_map.begin(); topic_it != topic_map.end(); ++topic_it) {
for (auto type_it = topic_it->second.begin(); type_it != topic_it->second.end();
Expand Down Expand Up @@ -975,9 +974,9 @@ rmw_ret_t GraphCache::service_server_is_available(
*is_available = false;
std::lock_guard<std::mutex> lock(graph_mutex_);
GraphNode::TopicMap::iterator service_it = graph_services_.find(service_name);
if (service_it != graph_services_.end()){
if (service_it != graph_services_.end()) {
GraphNode::TopicDataMap::iterator type_it = service_it->second.find(service_type);
if (type_it != service_it->second.end()){
if (type_it != service_it->second.end()) {
*is_available = true;
}
}
Expand Down
15 changes: 8 additions & 7 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ Entity::Entity(
if (topic_info_.has_value()) {
const auto & topic_info = this->topic_info_.value();
// Note: We don't append a leading "/" as we expect the ROS topic name to start with a "/".
token_ss << "/" + mangle_name(topic_info.name_) + "/" + topic_info.type_ + "/" + topic_info.qos_;
token_ss <<
"/" + mangle_name(topic_info.name_) + "/" + topic_info.type_ + "/" + topic_info.qos_;
}

this->keyexpr_ = token_ss.str();
Expand Down Expand Up @@ -389,27 +390,27 @@ bool PublishToken::del(
}

///=============================================================================
std::string mangle_name(const std::string& input) {
std::string mangle_name(const std::string & input)
{
std::string output = "";
for (std::size_t i = 0; i < input.length(); ++i) {
if (input[i] == '/') {
output += SLASH_REPLACEMENT;
}
else {
} else {
output += input[i];
}
}
return output;
}

///=============================================================================
std::string demangle_name(const std::string& input) {
std::string demangle_name(const std::string & input)
{
std::string output = "";
for (std::size_t i = 0; i < input.length(); ++i) {
if (input[i] == SLASH_REPLACEMENT) {
output += '/';
}
else {
} else {
output += input[i];
}
}
Expand Down
4 changes: 2 additions & 2 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ class PublishToken
};

/// Replace "/" instances with "§".
std::string mangle_name(const std::string& input);
std::string mangle_name(const std::string & input);

/// Replace "§" instances with "/".
std::string demangle_name(const std::string& input);
std::string demangle_name(const std::string & input);

} // namespace liveliness

Expand Down
18 changes: 8 additions & 10 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,13 +1848,12 @@ rmw_create_client(
size_t suffix_substring_position = service_type.find("Request_");
if (std::string::npos != suffix_substring_position) {
service_type = service_type.substr(0, suffix_substring_position);
}
else {
} else {
RCUTILS_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
"Unexpected type %s for client %s. Report this bug",
service_type.c_str(), rmw_client->service_name);
return nullptr;
return nullptr;
}
const auto liveliness_entity = liveliness::Entity::make(
z_info_zid(z_loan(node->context->impl->session)),
Expand Down Expand Up @@ -2338,13 +2337,12 @@ rmw_create_service(
size_t suffix_substring_position = service_type.find("Response_");
if (std::string::npos != suffix_substring_position) {
service_type = service_type.substr(0, suffix_substring_position);
}
else {
} else {
RCUTILS_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
"Unexpected type %s for service %s. Report this bug",
service_type.c_str(), rmw_service->service_name);
return nullptr;
return nullptr;
}
const auto liveliness_entity = liveliness::Entity::make(
z_info_zid(z_loan(node->context->impl->session)),
Expand Down Expand Up @@ -3178,21 +3176,21 @@ rmw_service_server_is_available(

rmw_client_data_t * client_data = static_cast<rmw_client_data_t *>(client->data);
if (client_data == nullptr) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("Unable to retreive client_data from client for service %s", client->service_name);
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Unable to retreive client_data from client for service %s", client->service_name);
return RMW_RET_INVALID_ARGUMENT;
}

std::string service_type = client_data->request_type_support->get_name();
size_t suffix_substring_position = service_type.find("Request_");
if (std::string::npos != suffix_substring_position) {
service_type = service_type.substr(0, suffix_substring_position);
}
else {
} else {
RCUTILS_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
"Unexpected type %s for client %s. Report this bug",
service_type.c_str(), client->service_name);
return RMW_RET_INVALID_ARGUMENT;
return RMW_RET_INVALID_ARGUMENT;
}

return node->context->impl->graph_cache.service_server_is_available(
Expand Down

0 comments on commit 33c1bdd

Please sign in to comment.