rmw  master
C API providing a middleware abstraction layer which is used to implement the rest of ROS.
Macros | Functions
validate_full_topic_name.h File Reference
#include "rmw/macros.h"
#include "rmw/types.h"

Go to the source code of this file.

Macros

#define RMW_TOPIC_VALID   0
 
#define RMW_TOPIC_INVALID_IS_EMPTY_STRING   1
 
#define RMW_TOPIC_INVALID_NOT_ABSOLUTE   2
 
#define RMW_TOPIC_INVALID_ENDS_WITH_FORWARD_SLASH   3
 
#define RMW_TOPIC_INVALID_CONTAINS_UNALLOWED_CHARACTERS   4
 
#define RMW_TOPIC_INVALID_CONTAINS_REPEATED_FORWARD_SLASH   5
 
#define RMW_TOPIC_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER   6
 
#define RMW_TOPIC_INVALID_TOO_LONG   7
 
#define RMW_TOPIC_MAX_NAME_LENGTH   255 /* impl constraint */ - 8 /* reserved for prefixes */
 

Functions

rmw_ret_t rmw_validate_full_topic_name (const char *topic_name, int *validation_result, size_t *invalid_index)
 Determine if a given fully qualified topic name is valid. More...
 
const char * rmw_full_topic_name_validation_result_string (int validation_result)
 Return a validation result description, or NULL if unknown or RMW_TOPIC_VALID. More...
 

Macro Definition Documentation

◆ RMW_TOPIC_VALID

#define RMW_TOPIC_VALID   0

◆ RMW_TOPIC_INVALID_IS_EMPTY_STRING

#define RMW_TOPIC_INVALID_IS_EMPTY_STRING   1

◆ RMW_TOPIC_INVALID_NOT_ABSOLUTE

#define RMW_TOPIC_INVALID_NOT_ABSOLUTE   2

◆ RMW_TOPIC_INVALID_ENDS_WITH_FORWARD_SLASH

#define RMW_TOPIC_INVALID_ENDS_WITH_FORWARD_SLASH   3

◆ RMW_TOPIC_INVALID_CONTAINS_UNALLOWED_CHARACTERS

#define RMW_TOPIC_INVALID_CONTAINS_UNALLOWED_CHARACTERS   4

◆ RMW_TOPIC_INVALID_CONTAINS_REPEATED_FORWARD_SLASH

#define RMW_TOPIC_INVALID_CONTAINS_REPEATED_FORWARD_SLASH   5

◆ RMW_TOPIC_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER

#define RMW_TOPIC_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER   6

◆ RMW_TOPIC_INVALID_TOO_LONG

#define RMW_TOPIC_INVALID_TOO_LONG   7

◆ RMW_TOPIC_MAX_NAME_LENGTH

#define RMW_TOPIC_MAX_NAME_LENGTH   255 /* impl constraint */ - 8 /* reserved for prefixes */

Function Documentation

◆ rmw_validate_full_topic_name()

rmw_ret_t rmw_validate_full_topic_name ( const char *  topic_name,
int *  validation_result,
size_t *  invalid_index 
)

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.

Parameters
[in]topic_nametopic name to be validated
[out]validation_resultint in which the result of the check is stored
[out]invalid_indexsize_t index of the input string where an error occurred
Returns
RMW_RET_OK on successfully running the check, or
RMW_RET_INVALID_ARGUMENT on invalid parameters, or
RMW_RET_ERROR when an unspecified error occurs.

◆ rmw_full_topic_name_validation_result_string()

const char* rmw_full_topic_name_validation_result_string ( int  validation_result)

Return a validation result description, or NULL if unknown or RMW_TOPIC_VALID.