Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding required structs and methods to get a list of publishers or subscribers with their respective qos #186

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cce521a
Added two structs:
jaisontj Sep 27, 2019
8fe5fd2
Added two functions to retrieve the list of all subscribers and publi…
jaisontj Sep 27, 2019
69744dd
Allocator and free functions for rmw_participant_qos_profile
jaisontj Sep 27, 2019
20bedc2
Fixed code indentation issues
jaisontj Sep 28, 2019
94b27b3
Tests to rmw_participant_qos_profile_t_allocator
jaisontj Oct 4, 2019
ed9651e
Modified tests to avoid memory leak
jaisontj Oct 4, 2019
5c5ccbf
- Updated rmw_participants_t to use rmw_participant_qos_profile_t *
jaisontj Oct 8, 2019
06c5d4c
Changed rmw_participants_t to use a pointer to an array.
jaisontj Oct 8, 2019
a5e113b
PR rework after design changes
jaisontj Oct 15, 2019
1714008
- Changed member variables from const type const to const type in
jaisontj Oct 25, 2019
583687e
- Added zero_init, check_zero, init_with_size and fini functions for
jaisontj Oct 29, 2019
91a5668
- More informative comments
jaisontj Nov 13, 2019
091988c
- Fixed warnings on deallocate by casting const char * to char *
jaisontj Nov 14, 2019
ad84fb3
Fixed code formatting issues
jaisontj Nov 15, 2019
9b22c98
- Using strncpy instead of strcpy
jaisontj Nov 16, 2019
383e4a6
Using memcpy instead of strncpy to prevent warnings on Windows
jaisontj Nov 20, 2019
5e0e27f
- Comment modification to be more explicit.
jaisontj Nov 22, 2019
1d9e1fe
- Fixed function comments
jaisontj Nov 26, 2019
cbd91b3
Using memcpy in topic_info_set_gid
jaisontj Nov 27, 2019
e24e1f4
Added init and fini functions for rmw_topic_info_t and tests for the
jaisontj Nov 27, 2019
272a2dc
change c-strings under topic_info to be non-const
mm318 Dec 11, 2019
c00ad69
revert the change that removed const qualifiers
mm318 Dec 12, 2019
3e8f892
address PR comments
mm318 Dec 12, 2019
a1c35de
address PR comments
mm318 Dec 18, 2019
747c4c9
add rmw_qos_profile_unknown
mm318 Jan 2, 2020
06bb093
use constant instead of literal for history depth
mm318 Jan 2, 2020
c82859b
address more PR comments
mm318 Jan 10, 2020
702aef2
rename *topic_info* to *topic_endpoint_info*
mm318 Jan 10, 2020
8ddb815
fix formatting
mm318 Jan 10, 2020
6d9675a
remove unused enum value from rmw_endpoint_type_t
mm318 Jan 10, 2020
2915b73
fix clang compiler warnings
mm318 Jan 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions rmw/include/rmw/topic_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ typedef struct RMW_PUBLIC_TYPE rmw_topic_info_t
rmw_qos_profile_t qos_profile;
} rmw_topic_info_t;

/// Return a rmw_topic_info_t struct with members initialized to `NULL`.
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_topic_info_t
rmw_get_zero_initialized_topic_info(void);

/// Finalize a rmw_topic_info_t object.
/**
* The rmw_topic_info_t struct has members which require memory to be allocated to them before
* setting values. This function reclaims any allocated resources within the object and zeroes out
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
* all other members.
*
* \param[inout] topic_info object to be finalized
* \param[in] allocator the allocator used to allocate memory to the object
* \returns `RMW_RET_OK` on successfully reclaiming memory, or
* \returns `RMW_RET_INVALID_ARGUMENT` if any parameters are NULL, or
* \returns `RMW_RET_ERROR` when an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_topic_info_fini(
rmw_topic_info_t * topic_info,
rcutils_allocator_t * allocator);

/// Set the topic_type in rmw_topic_info_t.
/**
* rmw_topic_info_t has a member topic_type of type const char *;
Expand Down
27 changes: 27 additions & 0 deletions rmw/src/topic_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@
#include "rmw/error_handling.h"
#include "rmw/types.h"

rmw_topic_info_t
rmw_get_zero_initialized_topic_info(void)
{
rmw_topic_info_t zero = {0};
hidmic marked this conversation as resolved.
Show resolved Hide resolved
return zero;
}

rmw_ret_t
rmw_topic_info_fini(
rmw_topic_info_t * topic_info,
rcutils_allocator_t * allocator)
{
if (!topic_info) {
RMW_SET_ERROR_MSG("topic_info is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null");
return RMW_RET_INVALID_ARGUMENT;
}
allocator->deallocate((char *) topic_info->node_name, allocator->state);
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
allocator->deallocate((char *) topic_info->node_namespace, allocator->state);
allocator->deallocate((char *) topic_info->topic_type, allocator->state);
*topic_info = rmw_get_zero_initialized_topic_info();
return RMW_RET_OK;
}

rmw_ret_t
_rmw_topic_info_copy_str(
const char ** topic_info_str,
Expand Down
85 changes: 84 additions & 1 deletion rmw/test/test_topic_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TEST(test_topic_info, set_gid) {
ret = rmw_topic_info_set_gid(&topic_info, gid, RMW_GID_STORAGE_SIZE);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid arguments";
for (uint8_t i = 0; i < RMW_GID_STORAGE_SIZE; i++) {
printf("gid[%d]: %d and topic_gid[%d]: %d", i, gid[i], i, topic_info.gid[i]);
EXPECT_EQ(topic_info.gid[i], gid[i]) << "Gid value is not as expected";
}
}
Expand Down Expand Up @@ -146,3 +145,87 @@ TEST(test_topic_info, set_qos_profile) {
EXPECT_EQ(topic_info.qos_profile.avoid_ros_namespace_conventions,
false) << "Unequal avoid namespace conventions";
}

TEST(test_topic_info, zero_init) {
rmw_topic_info_t topic_info = rmw_get_zero_initialized_topic_info();
EXPECT_FALSE(topic_info.node_name);
EXPECT_FALSE(topic_info.node_namespace);
EXPECT_FALSE(topic_info.topic_type);
for (uint8_t i = 0; i < RMW_GID_STORAGE_SIZE; i++) {
EXPECT_EQ(topic_info.gid[i], 0) << "Gid value should be 0";
}
EXPECT_EQ(topic_info.qos_profile.history, 0) << "Non-zero history";
EXPECT_EQ(topic_info.qos_profile.depth, 0u) << "Non-zero depth";
EXPECT_EQ(topic_info.qos_profile.reliability, 0) << "Non-zero reliability";
EXPECT_EQ(topic_info.qos_profile.durability, 0) << "Non-zero durability";
EXPECT_EQ(topic_info.qos_profile.deadline.sec, 0u) << "Non-zero deadline sec";
EXPECT_EQ(topic_info.qos_profile.deadline.nsec, 0u) << "Non-zero deadline nsec";
EXPECT_EQ(topic_info.qos_profile.lifespan.sec, 0u) << "Non-zero lifespan sec";
EXPECT_EQ(topic_info.qos_profile.lifespan.nsec, 0u) << "Non-zero lifespan nsec";
EXPECT_EQ(topic_info.qos_profile.liveliness, 0) << "Non-zero liveliness";
EXPECT_EQ(topic_info.qos_profile.liveliness_lease_duration.sec,
0u) << "Non-zero liveliness lease duration sec";
EXPECT_EQ(topic_info.qos_profile.liveliness_lease_duration.nsec,
0u) << "Non-zero liveliness lease duration nsec";
EXPECT_EQ(topic_info.qos_profile.avoid_ros_namespace_conventions,
false) << "Non-zero avoid namespace conventions";
}

TEST(test_topic_info, fini) {
rmw_ret_t ret;
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
rcutils_allocator_t allocator = rcutils_get_default_allocator();
rmw_topic_info_t topic_info = rmw_get_zero_initialized_topic_info();
rmw_qos_profile_t qos_profile;
qos_profile.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST;
qos_profile.depth = 0;
qos_profile.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
qos_profile.durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
qos_profile.deadline = {1, 0};
qos_profile.lifespan = {2, 0};
qos_profile.liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE;
qos_profile.liveliness_lease_duration = {3, 0};
qos_profile.avoid_ros_namespace_conventions = false;
ret = rmw_topic_info_set_qos_profile(&topic_info, &qos_profile);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid arguments";
uint8_t gid[RMW_GID_STORAGE_SIZE];
for (uint8_t i = 0; i < RMW_GID_STORAGE_SIZE; i++) {
gid[i] = i * 12;
}
ret = rmw_topic_info_set_gid(&topic_info, gid, RMW_GID_STORAGE_SIZE);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid gid arguments";
ret = rmw_topic_info_set_node_namespace(&topic_info, "namespace", &allocator);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid node_namespace arguments";
ret = rmw_topic_info_set_node_name(&topic_info, "name", &allocator);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid node_name arguments";
ret = rmw_topic_info_set_topic_type(&topic_info, "type", &allocator);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid topic_type arguments";
ret = rmw_topic_info_fini(&topic_info, nullptr);
EXPECT_EQ(ret, RMW_RET_INVALID_ARGUMENT) << "Expected invalid argument for null allocator";
ret = rmw_topic_info_fini(nullptr, &allocator);
EXPECT_EQ(ret, RMW_RET_INVALID_ARGUMENT) << "Expected invalid argument for null topic_info";

ret = rmw_topic_info_fini(&topic_info, &allocator);
// Verify that the values inside the struct are zero-ed out and finished.
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid fini arguments";
EXPECT_FALSE(topic_info.node_name);
EXPECT_FALSE(topic_info.node_namespace);
EXPECT_FALSE(topic_info.topic_type);
for (uint8_t i = 0; i < RMW_GID_STORAGE_SIZE; i++) {
EXPECT_EQ(topic_info.gid[i], 0) << "Gid value should be 0";
}
EXPECT_EQ(topic_info.qos_profile.history, 0) << "Non-zero history";
EXPECT_EQ(topic_info.qos_profile.depth, 0u) << "Non-zero depth";
EXPECT_EQ(topic_info.qos_profile.reliability, 0) << "Non-zero reliability";
EXPECT_EQ(topic_info.qos_profile.durability, 0) << "Non-zero durability";
EXPECT_EQ(topic_info.qos_profile.deadline.sec, 0u) << "Non-zero deadline sec";
EXPECT_EQ(topic_info.qos_profile.deadline.nsec, 0u) << "Non-zero deadline nsec";
EXPECT_EQ(topic_info.qos_profile.lifespan.sec, 0u) << "Non-zero lifespan sec";
EXPECT_EQ(topic_info.qos_profile.lifespan.nsec, 0u) << "Non-zero lifespan nsec";
EXPECT_EQ(topic_info.qos_profile.liveliness, 0) << "Non-zero liveliness";
EXPECT_EQ(topic_info.qos_profile.liveliness_lease_duration.sec,
0u) << "Non-zero liveliness lease duration sec";
EXPECT_EQ(topic_info.qos_profile.liveliness_lease_duration.nsec,
0u) << "Non-zero liveliness lease duration nsec";
EXPECT_EQ(topic_info.qos_profile.avoid_ros_namespace_conventions,
false) << "Non-zero avoid namespace conventions";
}