Skip to content

Commit

Permalink
Removes nitpicks from review, non-functional
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-desmond committed Dec 6, 2018
1 parent 6bd4fe8 commit 4e63fc8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
6 changes: 5 additions & 1 deletion rmw_fastrtps_dynamic_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ rmw_get_service_names_and_types_by_node(
rmw_names_and_types_t * service_names_and_types)
{
return rmw_fastrtps_shared_cpp::__rmw_get_service_names_and_types_by_node(
eprosima_fastrtps_identifier, node, allocator, node_name, node_namespace,
eprosima_fastrtps_identifier,
node,
allocator,
node_name,
node_namespace,
service_names_and_types);
}
} // extern "C"
98 changes: 49 additions & 49 deletions rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,59 +429,59 @@ __rmw_get_service_names_and_types_by_node(
}
}
}

if (services.size()) {
// Setup string array to store names
rmw_ret_t rmw_ret =
rmw_names_and_types_init(service_names_and_types, services.size(), allocator);
if (rmw_ret != RMW_RET_OK) {
return rmw_ret;
if (services.empty()) {
return RMW_RET_OK;
}
// Setup string array to store names
rmw_ret_t rmw_ret =
rmw_names_and_types_init(service_names_and_types, services.size(), allocator);
if (rmw_ret != RMW_RET_OK) {
return rmw_ret;
}
// Setup cleanup function, in case of failure below
auto fail_cleanup = [&service_names_and_types]() {
rmw_ret_t rmw_ret = rmw_names_and_types_fini(service_names_and_types);
if (rmw_ret != RMW_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
kLoggerTag,
"error during report of error: %s", rmw_get_error_string());
}
};
// For each service, store the name, initialize the string array for types, and store all types
size_t index = 0;
for (const auto & service_n_types : services) {
// Duplicate and store the service_name
char * service_name = rcutils_strdup(service_n_types.first.c_str(), *allocator);
if (!service_name) {
RMW_SET_ERROR_MSG("failed to allocate memory for service name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
// Setup cleanup function, in case of failure below
auto fail_cleanup = [&service_names_and_types]() {
rmw_ret_t rmw_ret = rmw_names_and_types_fini(service_names_and_types);
if (rmw_ret != RMW_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
kLoggerTag,
"error during report of error: %s", rmw_get_error_string());
}
};
// For each service, store the name, initialize the string array for types, and store all types
size_t index = 0;
for (const auto & service_n_types : services) {
// Duplicate and store the service_name
char * service_name = rcutils_strdup(service_n_types.first.c_str(), *allocator);
if (!service_name) {
RMW_SET_ERROR_MSG("failed to allocate memory for service name");
service_names_and_types->names.data[index] = service_name;
// Setup storage for types
rcutils_ret_t rcutils_ret = rcutils_string_array_init(
&service_names_and_types->types[index],
service_n_types.second.size(),
allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
fail_cleanup();
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
// Duplicate and store each type for the service
size_t type_index = 0;
for (const auto & type : service_n_types.second) {
char * type_name = rcutils_strdup(type.c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG("failed to allocate memory for type name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
service_names_and_types->names.data[index] = service_name;
// Setup storage for types
rcutils_ret_t rcutils_ret = rcutils_string_array_init(
&service_names_and_types->types[index],
service_n_types.second.size(),
allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
fail_cleanup();
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
// Duplicate and store each type for the service
size_t type_index = 0;
for (const auto & type : service_n_types.second) {
char * type_name = rcutils_strdup(type.c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG("failed to allocate memory for type name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
service_names_and_types->types[index].data[type_index] = type_name;
++type_index;
} // for each type
++index;
} // for each service
}
service_names_and_types->types[index].data[type_index] = type_name;
++type_index;
} // for each type
++index;
} // for each service
return RMW_RET_OK;
}
} // namespace rmw_fastrtps_shared_cpp

0 comments on commit 4e63fc8

Please sign in to comment.