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
38 changes: 18 additions & 20 deletions rmw/include/rmw/get_topic_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C"
#include "rmw/topic_info_array.h"
#include "rmw/visibility_control.h"

/// Retrieves the information for all publishers to a given topic.
/// Retrieve the information for all publishers to a given topic.
/**
* The retrieved information will contain the publisher's node name, node namespace,
* associated topic type, publisher gid and qos profile.
Expand All @@ -32,25 +32,24 @@ extern "C"
*
* The topic_name parameter must not be `NULL` and must follow the topic naming rules
* mentioned at http://design.ros2.org/articles/topic_and_service_names.html
* Non existent topic names are allowed.
* Names of non-existent topics are allowed.
* In that case, this function will return an empty array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like they are allowed? Why not an error case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what error code to use in this case (a generic RMW_RET_ERROR? RCL_RET_TOPIC_NAME_INVALID migrated over to rmw?).

Also, this function shouldn't be used for detecting the existence of a topic; that feels like it is encroaching on the purpose of rmw_get_topic_names_and_types().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this comment doesn't make since if "non-existent topic" just means a topic that isn't on the graph. I was still thinking an empty string, in which case it should create an error, just like if it violated any of the other rules in the topic name rules set.

I think this can be resolved without changes. Though a follow up question is what happens if the value for topic_name violates one of the topic name rules, e.g. empty string, starts with a number, etc.

There is already this function:

/// Determine if a given fully qualified topic name is valid.
/** Validity of a FQN for topic is determined based on rules defined here:
*
* http://design.ros2.org/articles/topic_and_service_names.html
*
* Note that this function expects any URL suffixes as described in the above
* document to have already been removed.
*
* If either the C string or validation_result pointer are null, then
* `RMW_RET_INVALID_ARGUMENT` will be returned.
* The topic_name should be a valid, null-terminated C string.
* The validation_result int pointer should point to valid memory so a result
* can be stored in it as an output variable.
* The invalid_index size_t pointer should either point NULL or to valid memory
* so in the event of a validation error, the location in the input string can
* be stored therein.
* If NULL is passed in for invalid_index, it will be not be set.
*
* The invalid_index will not be assigned a value if the topic is valid.
*
* The int which validation_result points to will have a one of a few possible
* results values (defined with macros) stored into it:
*
* - RMW_TOPIC_VALID
* - RMW_TOPIC_INVALID_IS_EMPTY_STRING
* - RMW_TOPIC_INVALID_NOT_ABSOLUTE
* - RMW_TOPIC_INVALID_ENDS_WITH_FORWARD_SLASH
* - RMW_TOPIC_INVALID_CONTAINS_UNALLOWED_CHARACTERS
* - RMW_TOPIC_INVALID_CONTAINS_REPEATED_FORWARD_SLASH
* - RMW_TOPIC_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER
* - RMW_TOPIC_INVALID_TOO_LONG
*
* The result value can be converted to a description with the
* rmw_full_topic_name_validation_result_string() function.
*
* The `RMW_TOPIC_INVALID_TOO_LONG` is guaranteed to be checked last, such
* that if you get that result, then you can assume all other checks succeeded.
* This is done so that the length limit can be treated as a warning rather
* than an error if desired.
*
* \param[in] topic_name topic name to be validated
* \param[out] validation_result int in which the result of the check is stored
* \param[out] invalid_index size_t index of the input string where an error occurred
* \returns `RMW_RET_OK` on successfully running the check, or
* \returns `RMW_RET_INVALID_ARGUMENT` on invalid parameters, or
* \returns `RMW_RET_ERROR` when an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_validate_full_topic_name(
const char * topic_name,
int * validation_result,
size_t * invalid_index);

*
* It is the responsibility of the caller to ensure that `publishers_info` parameter points
* to a valid struct of type rmw_topic_info_array_t.
* The `count` field inside the struct must be set to 0 and the `info_array` field inside
* the struct must be set to null.
* @see rmw_get_zero_initialized_topic_info_array
* The rmw_topic_info_array_t struct must be zero initialized.
* \see rmw_get_zero_initialized_topic_info_array
*
* The `allocator` will be used to allocate memory to the `info_array` member
* inside of `publishers_info`.
* Moreover, every const char * member inside of
* Moreover, every `const char *` member inside of
* rmw_topic_info_t will be assigned a copied value on allocated memory.
* @see rmw_topic_info_set_topic_type
* @see rmw_topic_info_set_node_name
* @see rmw_topic_info_set_node_namespace
* \see rmw_topic_info_set_topic_type
* \see rmw_topic_info_set_node_name
* \see rmw_topic_info_set_node_namespace
* However, it is the responsibility of the caller to
* reclaim any allocated resources to `publishers_info` to avoid leaking memory.
* @see rmw_topic_info_array_fini
* \see rmw_topic_info_array_fini
*
* \param[in] node the handle to the node being used to query the ROS graph.
* \param[in] allocator the allocator to be used when allocating space for the array.
Expand All @@ -73,7 +72,7 @@ rmw_get_publishers_info_by_topic(
bool no_mangle,
rmw_topic_info_array_t * publishers_info);

/// Retrieves the information for all subscriptions to a given topic.
/// Retrieve the information for all subscriptions to a given topic.
/**
* The retrieved information will contain the subscriptions's node name, node namespace,
* associated topic type, subscription gid and qos profile.
Expand All @@ -82,25 +81,24 @@ rmw_get_publishers_info_by_topic(
*
* The topic_name parameter must not be `NULL` and must follow the topic naming rules
* mentioned at http://design.ros2.org/articles/topic_and_service_names.html
* Non existent topic names are allowed.
* Names of non-existent topics are allowed.
* They will return an empty array.
*
* It is the responsibility of the caller to ensure that `subscriptions_info` parameter points
* to a valid struct of type rmw_topic_info_array_t.
* The `count` field inside the struct must be set to 0 and the `info_array` field inside
* the struct must be set to null.
* @see rmw_get_zero_initialized_topic_info_array
* The rmw_topic_info_array_t struct must be zero initialized.
* \see rmw_get_zero_initialized_topic_info_array
*
* The `allocator` will be used to allocate memory to the `info_array` member
* inside of `publishers_info`.
* Moreover, every const char * member inside of
* Moreover, every `const char *` member inside of
* rmw_topic_info_t will be assigned a copied value on allocated memory.
* @see rmw_topic_info_set_topic_type
* @see rmw_topic_info_set_node_name
* @see rmw_topic_info_set_node_namespace
* \see rmw_topic_info_set_topic_type
* \see rmw_topic_info_set_node_name
* \see rmw_topic_info_set_node_namespace
* However, it is the responsibility of the caller to
* reclaim any allocated resources to `publishers_info` to avoid leaking memory.
* @see rmw_topic_info_array_fini
* \see rmw_topic_info_array_fini
*
* \param[in] node the handle to the node being used to query the ROS graph.
* \param[in] allocator the allocator to be used when allocating space for the array.
Expand Down
2 changes: 1 addition & 1 deletion rmw/include/rmw/rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
* - rmw_get_service_names_and_types()
* - rmw/names_and_types.h
* - rmw/get_topic_names_and_types.h
* - rmw/get_service_names_and_types.h
* - rmw/get_topic_info.h
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
* - rmw/get_service_names_and_types.h
*
* Further still there are some useful abstractions and utilities:
*
Expand Down
69 changes: 21 additions & 48 deletions rmw/include/rmw/topic_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C"
#include "rmw/visibility_control.h"

/// A structure that encapsulates the name, namespace, topic_type, gid and qos_profile
/// of publishers and subscriptions for a topic
/// of publishers and subscriptions for a topic.
typedef struct RMW_PUBLIC_TYPE rmw_topic_info_t
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
{
/// Name of the node
Expand All @@ -34,9 +34,11 @@ typedef struct RMW_PUBLIC_TYPE rmw_topic_info_t
const char * node_namespace;
/// The associated topic type
const char * topic_type;
/// The GID of the node
uint8_t gid[RMW_GID_STORAGE_SIZE];
/// Qos profile of the node
/// The endpoint type
rmw_endpoint_type_t endpoint_type;
/// The GID of the endpoint
uint8_t endpoint_gid[RMW_GID_STORAGE_SIZE];
/// QoS profile of the endpoint
rmw_qos_profile_t qos_profile;
} rmw_topic_info_t;

Expand Down Expand Up @@ -126,23 +128,24 @@ rmw_topic_info_set_node_namespace(
const char * node_namespace,
rcutils_allocator_t * allocator);

/// Set the qos_profile in rmw_topic_info_t.
/// Set the gid in rmw_topic_info_t.
/**
* rmw_topic_info_t has a member qos_profile of type const rmw_qos_profile_t *.
* This function assigns the passed qos_profile pointer to the member.
* Copies the values from gid into the gid member inside topic_info.
*
* \param[inout] topic_info pointer to an initialized instance of rmw_topic_info_t
* \param[in] qos_profile the qos_profile to set in rmw_topic_info_t
* \returns `RMW_RET_OK` on successfully setting the qos_profile, or
* \param[in] gid the gid value to set in rmw_topic_info_t
* \param[in] size the size of the gid param
* \returns `RMW_RET_OK` on successfully setting the gid, or
* \returns `RMW_RET_INVALID_ARGUMENT` if any parameters are NULL, or
* \returns `RMW_RET_INVALID_ARGUMENT` size is greater than RMW_GID_STORAGE_SIZE, or
* \returns `RMW_RET_ERROR` when an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_topic_info_set_qos_profile(
rmw_topic_info_set_endpoint_type(
rmw_topic_info_t * topic_info,
const rmw_qos_profile_t * qos_profile);
rmw_endpoint_type_t type);

/// Set the gid in rmw_topic_info_t.
/**
Expand All @@ -164,53 +167,23 @@ rmw_topic_info_set_gid(
const uint8_t gid[],
size_t size);

/// Free the memory which was allocated for topic_info.node_name
/**
*
* \param[inout] topic_info pointer to an initialized instance of rmw_topic_info_t
* \param[in] allocator the allocator that was used to allocate memory
* \returns `RMW_RET_OK` on successfully freeing the 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_node_name(
rmw_topic_info_t * topic_info,
rcutils_allocator_t * allocator);

/// Free the memory which was allocated for topic_info.node_namespace
/**
*
* \param[inout] topic_info pointer to an initialized instance of rmw_topic_info_t
* \param[in] allocator the allocator that was used to allocate memory
* \returns `RMW_RET_OK` on successfully freeing the 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_node_namespace(
rmw_topic_info_t * topic_info,
rcutils_allocator_t * allocator);

/// Free the memory which was allocated for topic_info.topic_type
/// Set the qos_profile in rmw_topic_info_t.
/**
* rmw_topic_info_t has a member qos_profile of type const rmw_qos_profile_t *.
* This function assigns the passed qos_profile pointer to the member.
*
* \param[inout] topic_info pointer to an initialized instance of rmw_topic_info_t
* \param[in] allocator the allocator that was used to allocate memory
* \returns `RMW_RET_OK` on successfully freeing the memory, or
* \param[in] qos_profile the qos_profile to set in rmw_topic_info_t
* \returns `RMW_RET_OK` on successfully setting the qos_profile, 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_topic_type(
rmw_topic_info_set_qos_profile(
rmw_topic_info_t * topic_info,
rcutils_allocator_t * allocator);
const rmw_qos_profile_t * qos_profile);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions rmw/include/rmw/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ typedef struct RMW_PUBLIC_TYPE rmw_node_t
rmw_context_t * context;
} rmw_node_t;

typedef enum RMW_PUBLIC_TYPE
{
RMW_ENDPOINT_INVALID = 0,
RMW_ENDPOINT_PUBLISHER,
RMW_ENDPOINT_SUBSCRIPTION,
RMW_ENDPOINT_UNKNOWN
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
} rmw_endpoint_type_t;

/// Options that can be used to configure the creation of a publisher in rmw.
typedef struct RMW_PUBLIC_TYPE rmw_publisher_options_t
{
Expand Down
Loading