1414
1515#include "./callbacks.h"
1616
17+ #include <rmw/error_handling.h>
18+
1719void on_status (
1820 struct uxrSession * session ,
1921 uxrObjectId object_id ,
@@ -58,30 +60,35 @@ void on_topic(
5860 (void )args ;
5961#endif // RMW_UXRCE_GRAPH
6062
63+ // Iterate along the allocated subscriptions
6164 rmw_uxrce_mempool_item_t * subscription_item = subscription_memory .allocateditems ;
6265 while (subscription_item != NULL )
6366 {
6467 rmw_uxrce_subscription_t * custom_subscription =
6568 (rmw_uxrce_subscription_t * )subscription_item -> data ;
69+
70+ // Check if topic is related to the subscription
6671 if ((custom_subscription -> datareader_id .id == object_id .id ) &&
6772 (custom_subscription -> datareader_id .type == object_id .type ))
6873 {
69- custom_subscription -> micro_buffer_lenght [custom_subscription -> history_write_index ] = length ;
70- ucdr_deserialize_array_uint8_t (
71- ub ,
72- custom_subscription -> micro_buffer [custom_subscription -> history_write_index ], length );
73-
74- // TODO(pablogs9): Circular overlapping buffer implemented: use qos
75- if (custom_subscription -> micro_buffer_in_use &&
76- custom_subscription -> history_write_index == custom_subscription -> history_read_index )
74+ rmw_uxrce_mempool_item_t * memory_node = get_memory (& static_buffer_memory );
75+ if (!memory_node )
7776 {
78- custom_subscription -> history_read_index = ( custom_subscription -> history_read_index + 1 ) %
79- RMW_UXRCE_MAX_HISTORY ;
77+ RMW_SET_ERROR_MSG ( "Not available static buffer memory node" );
78+ return ;
8079 }
8180
82- custom_subscription -> history_write_index = (custom_subscription -> history_write_index + 1 ) %
83- RMW_UXRCE_MAX_HISTORY ;
84- custom_subscription -> micro_buffer_in_use = true;
81+ rmw_uxrce_static_input_buffer_t * static_buffer = (rmw_uxrce_static_input_buffer_t * )memory_node -> data ;
82+ static_buffer -> owner = (void * ) custom_subscription ;
83+ static_buffer -> length = length ;
84+
85+ if (!ucdr_deserialize_array_uint8_t (
86+ ub ,
87+ static_buffer -> buffer ,
88+ length ))
89+ {
90+ put_memory (& static_buffer_memory , memory_node );
91+ }
8592
8693 break ;
8794 }
@@ -102,31 +109,33 @@ void on_request(
102109 (void )object_id ;
103110 (void )args ;
104111
112+ // Iterate along the allocated services
105113 rmw_uxrce_mempool_item_t * service_item = service_memory .allocateditems ;
106114 while (service_item != NULL )
107115 {
116+ // Check if request is related to the service
108117 rmw_uxrce_service_t * custom_service = (rmw_uxrce_service_t * )service_item -> data ;
109118 if (custom_service -> service_data_resquest == request_id )
110119 {
111- custom_service -> micro_buffer_lenght [custom_service -> history_write_index ] = length ;
112- ucdr_deserialize_array_uint8_t (
113- ub ,
114- custom_service -> micro_buffer [custom_service -> history_write_index ], length );
115- memcpy (
116- & custom_service -> sample_id [custom_service -> history_write_index ],
117- sample_id , sizeof (SampleIdentity ));
118-
119- // TODO(pablogs9): Circular overlapping buffer implemented: use qos
120- if (custom_service -> micro_buffer_in_use &&
121- custom_service -> history_write_index == custom_service -> history_read_index )
120+ rmw_uxrce_mempool_item_t * memory_node = get_memory (& static_buffer_memory );
121+ if (!memory_node )
122122 {
123- custom_service -> history_read_index = ( custom_service -> history_read_index + 1 ) %
124- RMW_UXRCE_MAX_HISTORY ;
123+ RMW_SET_ERROR_MSG ( "Not available static buffer memory node" );
124+ return ;
125125 }
126126
127- custom_service -> history_write_index = (custom_service -> history_write_index + 1 ) %
128- RMW_UXRCE_MAX_HISTORY ;
129- custom_service -> micro_buffer_in_use = true;
127+ rmw_uxrce_static_input_buffer_t * static_buffer = (rmw_uxrce_static_input_buffer_t * )memory_node -> data ;
128+ static_buffer -> owner = (void * ) custom_service ;
129+ static_buffer -> length = length ;
130+ static_buffer -> related .sample_id = * sample_id ;
131+
132+ if (!ucdr_deserialize_array_uint8_t (
133+ ub ,
134+ static_buffer -> buffer ,
135+ length ))
136+ {
137+ put_memory (& static_buffer_memory , memory_node );
138+ }
130139
131140 break ;
132141 }
@@ -147,29 +156,33 @@ void on_reply(
147156 (void )object_id ;
148157 (void )args ;
149158
159+ // Iterate along the allocated clients
150160 rmw_uxrce_mempool_item_t * client_item = client_memory .allocateditems ;
151161 while (client_item != NULL )
152162 {
163+ // Check if reply is related to the client
153164 rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t * )client_item -> data ;
154165 if (custom_client -> client_data_request == request_id )
155166 {
156- custom_client -> micro_buffer_lenght [custom_client -> history_write_index ] = length ;
157- ucdr_deserialize_array_uint8_t (
158- ub ,
159- custom_client -> micro_buffer [custom_client -> history_write_index ], length );
160- custom_client -> reply_id [custom_client -> history_write_index ] = reply_id ;
161-
162- // TODO(pablogs9): Circular overlapping buffer implemented: use qos
163- if (custom_client -> micro_buffer_in_use &&
164- custom_client -> history_write_index == custom_client -> history_read_index )
167+ rmw_uxrce_mempool_item_t * memory_node = get_memory (& static_buffer_memory );
168+ if (!memory_node )
165169 {
166- custom_client -> history_read_index = ( custom_client -> history_read_index + 1 ) %
167- RMW_UXRCE_MAX_HISTORY ;
170+ RMW_SET_ERROR_MSG ( "Not available static buffer memory node" );
171+ return ;
168172 }
169173
170- custom_client -> history_write_index = (custom_client -> history_write_index + 1 ) %
171- RMW_UXRCE_MAX_HISTORY ;
172- custom_client -> micro_buffer_in_use = true;
174+ rmw_uxrce_static_input_buffer_t * static_buffer = (rmw_uxrce_static_input_buffer_t * )memory_node -> data ;
175+ static_buffer -> owner = (void * ) custom_client ;
176+ static_buffer -> length = length ;
177+ static_buffer -> related .reply_id = reply_id ;
178+
179+ if (!ucdr_deserialize_array_uint8_t (
180+ ub ,
181+ static_buffer -> buffer ,
182+ length ))
183+ {
184+ put_memory (& static_buffer_memory , memory_node );
185+ }
173186
174187 break ;
175188 }
0 commit comments