Skip to content

Commit 8229a77

Browse files
authored
Adding doxygen documentation and READMEs to packages (ros2#204)
* Adding doxygen documentation and READMEs to packages Signed-off-by: Stephen Brawner <[email protected]> * PR Fixup Signed-off-by: Stephen Brawner <[email protected]> * Fixing merge with master Signed-off-by: Stephen Brawner <[email protected]>
1 parent f618306 commit 8229a77

19 files changed

+524
-35
lines changed

README.md

Whitespace-only changes.

rmw/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RMW
2+
3+
The ROS 2 Middleware Interface provides an abstraction layer to different DDS implementations for communication with the ROS 2 Client Library. This package contains the `rmw` interface for DDS implementation and some general functionality useful for implementers.
4+
5+
For more information, see https://design.ros2.org/articles/ros_middleware_interface.html
6+
7+
## Interface and Features
8+
For specific information about the rmw interface and features, see its [api docs](http://docs.ros2.org/latest/api/rmw/).

rmw/include/rmw/allocators.h

+65
Original file line numberDiff line numberDiff line change
@@ -23,66 +23,131 @@ extern "C"
2323
#include "rmw/types.h"
2424
#include "rmw/visibility_control.h"
2525

26+
/// Allocate memory of size in bytes using rcutils default allocator's allocate()
27+
/**
28+
* \param[in] size The number of bytes to allocate
29+
* \return pointer to allocated memory
30+
*/
2631
RMW_PUBLIC
2732
void *
2833
rmw_allocate(size_t size);
2934

35+
/// Free memory using rcutils default allocator's deallocate()
36+
/**
37+
* \param[in] size pointer to allocated memory
38+
*/
3039
RMW_PUBLIC
3140
void
3241
rmw_free(void * pointer);
3342

43+
/// Allocate memory for an `rmw_node_t` using rcutils default allocator's allocate()
44+
/**
45+
* \return pointer to allocated memory
46+
*/
3447
RMW_PUBLIC
3548
rmw_node_t *
3649
rmw_node_allocate(void);
3750

51+
/// Free memory allocated to this node pointer using rcutils default allocator's deallocate()
52+
/**
53+
* \param[in] pointer to allocated memory
54+
*/
3855
RMW_PUBLIC
3956
void
4057
rmw_node_free(rmw_node_t * node);
4158

59+
/// Allocate memory for an `rmw_publisher_t` using rcutils default allocator's allocate()
60+
/**
61+
* \return pointer to allocated memory
62+
*/
4263
RMW_PUBLIC
4364
rmw_publisher_t *
4465
rmw_publisher_allocate(void);
4566

67+
/// Free memory using rcutils default allocator's deallocate()
68+
/**
69+
* \param[in] size pointer to allocated memory
70+
*/
4671
RMW_PUBLIC
4772
void
4873
rmw_publisher_free(rmw_publisher_t * publisher);
4974

75+
/// Allocate memory for an `rmw_subscription_t` using rcutils default allocator's allocate()
76+
/**
77+
* \return pointer to allocated memory
78+
*/
5079
RMW_PUBLIC
5180
rmw_subscription_t *
5281
rmw_subscription_allocate(void);
5382

83+
/// Free memory using rcutils default allocator's deallocate()
84+
/**
85+
* \param[in] size pointer to allocated memory
86+
*/
5487
RMW_PUBLIC
5588
void
5689
rmw_subscription_free(rmw_subscription_t * subscription);
5790

91+
/// Allocate memory for an `rmw_guard_condition_t` using rcutils default allocator's allocate()
92+
/**
93+
* \return pointer to allocated memory
94+
*/
5895
RMW_PUBLIC
5996
rmw_guard_condition_t *
6097
rmw_guard_condition_allocate(void);
6198

99+
/// Free memory using rcutils default allocator's deallocate()
100+
/**
101+
* \param[in] size pointer to allocated memory
102+
*/
62103
RMW_PUBLIC
63104
void
64105
rmw_guard_condition_free(rmw_guard_condition_t * guard_condition);
65106

107+
/// Allocate memory for an `rmw_client_t` using rcutils default allocator's allocate()
108+
/**
109+
* \return pointer to allocated memory
110+
*/
66111
RMW_PUBLIC
67112
rmw_client_t *
68113
rmw_client_allocate(void);
69114

115+
/// Free memory using rcutils default allocator's deallocate()
116+
/**
117+
* \param[in] size pointer to allocated memory
118+
*/
70119
RMW_PUBLIC
71120
void
72121
rmw_client_free(rmw_client_t * client);
73122

123+
/// Allocate memory for an `rmw_service_t` using rcutils default allocator's allocate()
124+
/**
125+
* \return pointer to allocated memory
126+
*/
74127
RMW_PUBLIC
75128
rmw_service_t *
76129
rmw_service_allocate(void);
77130

131+
/// Free memory using rcutils default allocator's deallocate()
132+
/**
133+
* \param[in] size pointer to allocated memory
134+
*/
78135
RMW_PUBLIC
79136
void
80137
rmw_service_free(rmw_service_t * service);
81138

139+
/// Allocate memory for an `rmw_wait_set_t` using rcutils default allocator's allocate()
140+
/**
141+
* \return pointer to allocated memory
142+
*/
82143
RMW_PUBLIC
83144
rmw_wait_set_t *
84145
rmw_wait_set_allocate(void);
85146

147+
/// Free memory using rcutils default allocator's deallocate()
148+
/**
149+
* \param[in] size pointer to allocated memory
150+
*/
86151
RMW_PUBLIC
87152
void
88153
rmw_wait_set_free(rmw_wait_set_t * wait_set);

rmw/include/rmw/convert_rcutils_ret_to_rmw_ret.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ extern "C"
2525
#include "rmw/types.h"
2626
#include "rmw/visibility_control.h"
2727

28+
/// Map a `rcutil_ret_t` value to the equivalent `rmw_ret_t` value
29+
/**
30+
* \param[in] rcutils_ret The rcutils type to map
31+
* \return rmw_ret_t result mapped value, or RMW_RET_ERROR if the rcutils_ret value is not supported
32+
*/
2833
RMW_PUBLIC
2934
RMW_WARN_UNUSED
3035
rmw_ret_t

rmw/include/rmw/error_handling.h

+124
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/**
16+
* @file error_handling.h
17+
* @brief Functions and macros to interact with error handling mechanisms
18+
*
19+
* This logic pretty much renames many `rcutils` functions and macros. Also check out that
20+
* package's documentation for more information.
21+
*/
22+
1523
#ifndef RMW__ERROR_HANDLING_H_
1624
#define RMW__ERROR_HANDLING_H_
1725

@@ -22,33 +30,149 @@ extern "C"
2230

2331
#include <rcutils/error_handling.h>
2432

33+
/// Struct wrapping a fixed-size c string used for returning the formatted error string.
2534
typedef rcutils_error_string_t rmw_error_string_t;
35+
36+
/// Struct which encapsulates the error state set by RMW_SET_ERROR_MSG().
2637
typedef rcutils_error_state_t rmw_error_state_t;
2738

39+
/// Limit the buffer size in the `fwrite` call to give an upper bound to buffer overrun in the case
40+
/// of non-null terminated `msg`.
2841
#define RMW_SAFE_FWRITE_TO_STDERR RCUTILS_SAFE_FWRITE_TO_STDERR
2942

43+
/// Forces initialization of thread-local storage if called in a newly created thread.
44+
/**
45+
* If this function is not called beforehand, then the first time the error
46+
* state is set or the first time the error message is retrieved, the default
47+
* allocator will be used to allocate thread-local storage.
48+
*
49+
* This function may or may not allocate memory.
50+
* The system's thread-local storage implementation may need to allocate
51+
* memory, since it usually has no way of knowing how much storage is needed
52+
* without knowing how many threads will be created.
53+
* Most implementations (e.g. C11, C++11, and pthread) do not have ways to
54+
* specify how this memory is allocated, but if the implementation allows, the
55+
* given allocator to this function will be used, but is otherwise unused.
56+
* This only occurs when creating and destroying threads, which can be avoided
57+
* in the "steady" state by reusing pools of threads.
58+
*
59+
* It is worth considering that repeated thread creation and destruction will
60+
* result in repeated memory allocations and could result in memory
61+
* fragmentation.
62+
* This is typically avoided anyways by using pools of threads.
63+
*
64+
* In case an error is indicated by the return code, no error message will have
65+
* been set.
66+
*
67+
* If called more than once in a thread, or after implicitly initialized by
68+
* setting the error state, it will still return `RCUTILS_RET_OK`, even
69+
* if the given allocator is invalid.
70+
* Essentially this function does nothing if thread-local storage has already
71+
* been called.
72+
* If already initialized, the given allocator is ignored, even if it does not
73+
* match the allocator used originally to initialize the thread-local storage.
74+
*
75+
* \return `RCUTILS_RET_OK` if successful, or
76+
* \return `RCUTILS_RET_INVALID_ARGUMENT` if the allocator is invalid, or
77+
* \return `RCUTILS_RET_BAD_ALLOC` if allocating memory fails, or
78+
* \return `RCUTILS_RET_ERROR` if an unspecified error occurs.
79+
*/
3080
#define rmw_initialize_error_handling_thread_local_storage \
3181
rcutils_initialize_error_handling_thread_local_storage
3282

83+
/// Set the error message, as well as the file and line on which it occurred.
84+
/**
85+
* This is not meant to be used directly, but instead via the
86+
* RMW_SET_ERROR_MSG(msg) macro.
87+
*
88+
* The error_msg parameter is copied into the internal error storage and must
89+
* be null terminated.
90+
* The file parameter is copied into the internal error storage and must
91+
* be null terminated.
92+
*
93+
* \param[in] error_string The error message to set.
94+
* \param[in] file The path to the file in which the error occurred.
95+
* \param[in] line_number The line number on which the error occurred.
96+
*/
3397
#define rmw_set_error_state rcutils_set_error_state
3498

99+
/// Check an argument for a null value.
100+
/**
101+
* If the argument's value is `NULL`, set the error message saying so and
102+
* return the `error_return_type`.
103+
*
104+
* \param[in] argument The argument to test.
105+
* \param[in] error_return_type The type to return if the argument is `NULL`.
106+
*/
35107
#define RMW_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type) \
36108
RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type)
37109

110+
/// Check a value for null, with an error message and error statement.
111+
/**
112+
* If `value` is `NULL`, the error statement will be evaluated after
113+
* setting the error message.
114+
*
115+
* \param[in] value The value to test.
116+
* \param[in] msg The error message if `value` is `NULL`.
117+
* \param[in] error_statement The statement to evaluate if `value` is `NULL`.
118+
*/
38119
#define RMW_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement) \
39120
RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement)
40121

122+
/// Set the error message, as well as append the current file and line number.
123+
/**
124+
* If an error message was previously set, and rmw_reset_error() was not called
125+
* afterwards, and this library was built with RCUTILS_REPORT_ERROR_HANDLING_ERRORS
126+
* turned on, then the previously set error message will be printed to stderr.
127+
* Error state storage is thread local and so all error related functions are
128+
* also thread local.
129+
*
130+
* \param[in] msg The error message to be set.
131+
*/
41132
#define RMW_SET_ERROR_MSG(msg) RCUTILS_SET_ERROR_MSG(msg)
42133

134+
/// Set the error message using a format string and format arguments.
135+
/**
136+
* This function sets the error message using the given format string.
137+
* The resulting formatted string is silently truncated at
138+
* RCUTILS_ERROR_MESSAGE_MAX_LENGTH.
139+
*
140+
* \param[in] format_string The string to be used as the format of the error message.
141+
* \param[in] ... Arguments for the format string.
142+
*/
43143
#define RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, ...) \
44144
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(format_string, __VA_ARGS__)
45145

146+
/// Return `true` if the error is set, otherwise `false`.
147+
/**
148+
* This is currently defines as `rcutils_error_is_set`
149+
*/
46150
#define rmw_error_is_set rcutils_error_is_set
47151

152+
/// Return an rcutils_error_state_t which was set with rcutils_set_error_state().
153+
/**
154+
* The returned pointer will be NULL if no error has been set in this thread.
155+
*
156+
* The returned pointer is valid until RCUTILS_SET_ERROR_MSG, rcutils_set_error_state,
157+
* or rcutils_reset_error are called in the same thread.
158+
*
159+
* \return A pointer to the current error state struct.
160+
*/
48161
#define rmw_get_error_state rcutils_get_error_state
49162

163+
/// Return the error message followed by `, at <file>:<line>` if set, else "error not set".
164+
/**
165+
* This function is "safe" because it returns a copy of the current error
166+
* string or one containing the string "error not set" if no error was set.
167+
* This ensures that the copy is owned by the calling thread and is therefore
168+
* never invalidated by other error handling calls, and that the C string
169+
* inside is always valid and null terminated.
170+
*
171+
* \return The current error string, with file and line number, or "error not set" if not set.
172+
*/
50173
#define rmw_get_error_string rcutils_get_error_string
51174

175+
/// Reset the error state by clearing any previously set error state.
52176
#define rmw_reset_error rcutils_reset_error
53177

54178
#ifdef __cplusplus

rmw/include/rmw/event.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ rmw_get_zero_initialized_event(void);
6666
/// Initialize a rmw publisher event.
6767
/**
6868
* \param[in|out] rmw_event to initialize
69-
* \param publisher to initialize with
70-
* \param event_type for the event to handle
69+
* \param[in] publisher to initialize with
70+
* \param[in|out] event_type for the event to initialize
7171
* \return `RMW_RET_OK` if successful, or
7272
* \return `RMW_RET_INVALID_ARGUMENT` if invalid argument, or
7373
* \return `RMW_RET_UNSUPPORTED` if event_type is not supported, or
@@ -84,8 +84,8 @@ rmw_publisher_event_init(
8484
/// Initialize a rmw subscription event.
8585
/**
8686
* \param[in|out] rmw_event to initialize
87-
* \param subscription to initialize with
88-
* \param event_type for the event to handle
87+
* \param[in] subscription to initialize with
88+
* \param[in|out] event_type for the event to handle
8989
* \return `RMW_RET_OK` if successful, or
9090
* \return `RMW_RET_INVALID_ARGUMENT` if invalid argument, or
9191
* \return `RMW_RET_UNSUPPORTED` if event_type is not supported, or
@@ -101,9 +101,9 @@ rmw_subscription_event_init(
101101

102102
/// Take an event from the event handle.
103103
/**
104-
* \param event_handle event object to take from
105-
* \param event_info event info object to write taken data into
106-
* \param taken boolean flag indicating if an event was taken or not
104+
* \param[in] event_handle event object to take from
105+
* \param[in|out] event_info event info object to write taken data into
106+
* \param[out] taken boolean flag indicating if an event was taken or not
107107
* \return `RMW_RET_OK` if successful, or
108108
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
109109
* \return `RMW_RET_ERROR` if an unexpected error occurs.
@@ -118,7 +118,7 @@ rmw_take_event(
118118

119119
/// Finalize an rmw_event_t.
120120
/**
121-
* \param event to finalize
121+
* \param[in] event to finalize
122122
*/
123123
RMW_PUBLIC
124124
RMW_WARN_UNUSED

rmw/include/rmw/macros.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
#include "rcutils/macros.h"
1919

20+
/// Expand the argument to its literal text
2021
#define RMW_STRINGIFY(x) RCUTILS_STRINGIFY(x)
2122

23+
/// Indicate that a variable is not used, and prevent compiler from issuing warnings
2224
#define RMW_WARN_UNUSED RCUTILS_WARN_UNUSED
2325

2426
#endif // RMW__MACROS_H_

0 commit comments

Comments
 (0)