-
Notifications
You must be signed in to change notification settings - Fork 69
/
rmw.h
950 lines (891 loc) · 32 KB
/
rmw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
// Copyright 2014-2017 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/** \mainpage rmw: ROS Middleware Abstraction Interface
*
* `rmw` defines an interface of middleware primitives that are used by the higher level ROS API's.
* It consists of these main components:
*
* - Initialization and Shutdown:
* - rmw/init.h
* - Nodes
* - rmw/rmw.h
* - Publisher
* - rmw/rmw.h
* - Subscription
* - rmw/rmw.h
* - Service Client
* - rmw/rmw.h
* - Service Server
* - rmw/rmw.h
*
* There are some common utility functions in combination with "Topics" or "Services":
* - A function to validate a fully qualified topic or service name
* - rmw_validate_full_topic_name()
* - rmw/validate_full_topic_name.h
* - A function to validate a node's namespace
* - rmw_validate_namespace()
* - rmw/validate_namespace.h
* - A function to validate a node's name
* - rmw_validate_node_name()
* - rmw/validate_node_name.h
*
* It also has some machinery that is necessary to wait on and act on these concepts:
*
* - Initialization and shutdown management (global for now)
* - rmw/rmw.h
* - Wait sets for waiting on messages and service requests / responses to be ready
* - rmw/rmw.h
* - Guard conditions for waking up wait sets asynchronously
* - rmw/rmw.h
* - Introspection of the ROS graph
* - rmw_names_and_types_t
* - rmw_get_topic_names_and_types()
* - 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
*
* Further still there are some useful abstractions and utilities:
*
* - Allocator functions for various types
* - rmw/allocators.h
* - Error handling functionality (C style)
* - rmw/error_handling.h
* - Macros
* - rmw/macros.h
* - Return code types and other utility types
* - rmw/types.h
* - Sanity checks for some of the types
* - rmw/sanity_checks.h
* - Macros for controlling symbol visibility on the library
* - rmw/visibility_control.h
* - Utility function to demangle a type to a human readable string (C++ specific):
* - rmw/impl/cpp/demangle.hpp
*/
#ifndef RMW__RMW_H_
#define RMW__RMW_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "rcutils/types.h"
#include "rosidl_generator_c/message_bounds_struct.h"
#include "rosidl_generator_c/message_type_support_struct.h"
#include "rosidl_generator_c/service_type_support_struct.h"
#include "rmw/init.h"
#include "rmw/macros.h"
#include "rmw/qos_profiles.h"
#include "rmw/types.h"
#include "rmw/visibility_control.h"
RMW_PUBLIC
RMW_WARN_UNUSED
const char *
rmw_get_implementation_identifier(void);
/// Get the unique serialization format for this middleware.
/**
* Return the format in which binary data is serialized.
* One middleware can only have one encoding.
* In contrast to the implementation identifier, the serialization format can be equal between
* multiple RMW implementations.
* This means, that the same binary messages can be deserialized by RMW implementations with the
* same format.
* \sa rmw_serialize
* \sa rmw_deserialize
* \return serialization format
*/
RMW_PUBLIC
RMW_WARN_UNUSED
const char *
rmw_get_serialization_format(void);
// TODO(wjwwood): refactor this API to return a return code when updated to use an allocator
/// Create a node and return a handle to that node.
/**
* This function can fail, and therefore return `NULL`, if:
* - context, name, namespace_, or security_options is `NULL`
* - context, security_options is invalid
* - memory allocation fails during node creation
* - an unspecified error occurs
*
* The context must be non-null and valid, i.e. it has been initialized
* by `rmw_init()` and has not been finalized by `rmw_shutdown()`.
*
* The name and namespace_ should be valid node name and namespace,
* and this should be asserted by the caller (e.g. `rcl`).
*
* The domain ID should be used to physically separate nodes at the
* communication graph level by the middleware.
* For RTPS/DDS this maps naturally to their concept of domain id.
*
* The security options should always be non-null and encapsulate the
* essential security configurations for the node and its entities.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No [1]
* Lock-Free | No [1]
* <i>[1] rmw implementation defined, check the implementation documentation</i>
*
* This should be defined by the rmw implementation.
*
* \param[in] context init context that this node should be associated with
* \param[in] name the node name
* \param[in] namespace_ the node namespace
* \param[in] domain_id the id of the domain that the node should join
* \param[in] security_options the security configurations for the node
* \return rmw node handle or `NULL` if there was an error
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_node_t *
rmw_create_node(
rmw_context_t * context,
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options);
/// Finalize a given node handle, reclaim the resources, and deallocate the node handle.
/**
* \param node the node handle to be destroyed
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if node is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_node(rmw_node_t * node);
/// Manually assert that this node is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE)
/**
* If the rmw Liveliness policy is set to RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE, the creator of
* this node may manually call `assert_liveliness` at some point in time to signal to the rest
* of the system that this Node is still alive.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] node handle to the node that needs liveliness to be asserted
* \return `RMW_RET_OK` if the liveliness assertion was completed successfully, or
* \return `RMW_RET_ERROR` if an unspecified error occurs, or
* \return `RMW_RET_UNSUPPORTED` if the rmw implementation does not support asserting liveliness.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_node_assert_liveliness(const rmw_node_t * node);
/// Return a guard condition which is triggered when the ROS graph changes.
/**
* The handle returned is a pointer to an internally held rmw guard condition.
* This function can fail, and therefore return `NULL`, if:
* - node is `NULL`
* - node is invalid
*
* The returned handle is made invalid if the node is destroyed or if
* rmw_shutdown() is called.
*
* The guard condition will be triggered anytime a change to the ROS graph
* occurs.
* A ROS graph change includes things like (but not limited to) a new publisher
* advertises, a new subscription is created, a new service becomes available,
* a subscription is canceled, etc.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] node pointer to the rmw node
* \return rmw guard condition handle if successful, otherwise `NULL`
*/
RMW_PUBLIC
RMW_WARN_UNUSED
const rmw_guard_condition_t *
rmw_node_get_graph_guard_condition(const rmw_node_t * node);
/// Initialize a publisher allocation to be used with later publications.
/**
* This creates an allocation object that can be used in conjunction with
* the rmw_publish method to perform more carefully control memory allocations.
*
* This will allow the middleware to preallocate the correct amount of memory
* for a given message type and message bounds.
* As allocation is performed in this method, it will not be necessary to allocate
* in the `rmw_publish` method.
*
* \param[in] type_support Type support of the message to be preallocated.
* \param[in] message_bounds Bounds structure of the message to be preallocated.
* \param[out] allocation Allocation structure to be passed to `rmw_publish`.
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if an argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_init_publisher_allocation(
const rosidl_message_type_support_t * type_support,
const rosidl_message_bounds_t * message_bounds,
rmw_publisher_allocation_t * allocation);
/// Destroy a publisher allocation object.
/**
* This deallocates any memory allocated by `rmw_init_publisher_allocation`.
*
* \param[in] allocation Allocation object to be destroyed.
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_fini_publisher_allocation(
rmw_publisher_allocation_t * allocation);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_publisher_t *
rmw_create_publisher(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_support,
const char * topic_name,
const rmw_qos_profile_t * qos_policies);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_publisher(rmw_node_t * node, rmw_publisher_t * publisher);
/// Publish a given ros_message
/**
* Publish a given ROS message via a publisher.
*
* \param[in] publisher Publisher to be used to send message.
* \param[in] ros_message Message to be sent.
* \param[in] allocation Specify preallocated memory to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if publisher or ros_message is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_publish(
const rmw_publisher_t * publisher,
const void * ros_message,
rmw_publisher_allocation_t * allocation);
/// Retrieve the number of matched subscriptions to a publisher.
/**
* Query the underlying middleware to determine how many subscriptions are
* matched to a given publisher.
*
* \param[in] publisher the publisher object to inspect
* \param[out] subscription_count the number of subscriptions matched
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if either argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_publisher_count_matched_subscriptions(
const rmw_publisher_t * publisher,
size_t * subscription_count);
/// Retrieve the actual qos settings of the publisher.
/**
* Query the underlying middleware to determine the qos settings
* of the publisher.
* The actual configuration applied when using RMW_*_SYSTEM_DEFAULT
* can only be resolved after the creation of the publisher, and it
* depends on the underlying rmw implementation.
* If the underlying setting in use can't be represented in ROS terms,
* it will be set to RMW_*_UNKNOWN.
* The value of avoid_ros_namespace_conventions field is not resolved
* with this function. The rcl function rcl_publisher_get_actual_qos
* resolves it.
*
* \param[in] publisher the publisher object to inspect
* \param[out] qos the actual qos settings
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if either argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_publisher_get_actual_qos(
const rmw_publisher_t * publisher,
rmw_qos_profile_t * qos);
/// Publish an already serialized message.
/**
* The publisher must already be registered with the correct message type
* support so that it can send serialized data corresponding to that type.
* This function sends the serialized byte stream directly over the wire without
* having to serialize the message first.
* A ROS message can be serialized manually using the rmw_serialize() function.
*
* \param[in] publisher The publisher object registered to send the message.
* \param[in] serialized_message The serialized message holding the byte stream.
* \param[in] allocation Specify preallocated memory to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_publish_serialized_message(
const rmw_publisher_t * publisher,
const rmw_serialized_message_t * serialized_message,
rmw_publisher_allocation_t * allocation);
/// Compute the size of a serialized message.
/**
* Given a message definition and bounds, compute the serialized size.
*
* \param[in] type_support The type support of the message to compute.
* \param[in] bounds Artifical bounds to use on unbounded fields.
* \param[out] size The computed size of the serialized message.
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if either argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_get_serialized_message_size(
const rosidl_message_type_support_t * type_support,
const rosidl_message_bounds_t * message_bounds,
size_t * size);
/// Manually assert that this Publisher is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC)
/**
* If the rmw Liveliness policy is set to RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC, the creator of
* this publisher may manually call `assert_liveliness` at some point in time to signal to the rest
* of the system that this Node is still alive.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] publisher handle to the publisher that needs liveliness to be asserted
* \return `RMW_RET_OK` if the liveliness assertion was completed successfully, or
* \return `RMW_RET_ERROR` if an unspecified error occurs, or
* \return `RMW_RET_UNSUPPORTED` if the rmw implementation does not support asserting liveliness.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_publisher_assert_liveliness(const rmw_publisher_t * publisher);
/// Serialize a ROS message into a rmw_serialized_message_t.
/**
* The ROS message is serialized into a byte stream contained within the
* rmw_serialized_message_t structure.
* The serialization format depends on the underlying middleware.
*
* \param ros_message the typed ROS message
* \param type_support the typesupport for the ROS message
* \param serialized_message the destination for the serialize ROS message
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_serialize(
const void * ros_message,
const rosidl_message_type_support_t * type_support,
rmw_serialized_message_t * serialized_message);
/// Deserialize a ROS message.
/**
* The given rmw_serialized_message_t's internal byte stream buffer is deserialized
* into the given ROS message.
* The ROS message must already be allocated and initialized, and must match
* the given typesupport structure.
* The serialization format expected in the rmw_serialized_message_t depends on the
* underlying middleware.
*
* \param serialized_message the serialized message holding the byte stream
* \param type_support the typesupport for the typed ros message
* \param ros_message destination for the deserialized ROS message
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_deserialize(
const rmw_serialized_message_t * serialized_message,
const rosidl_message_type_support_t * type_support,
void * ros_message);
/// Initialize a subscription allocation to be used with later `take`s.
/**
* This creates an allocation object that can be used in conjunction with
* the rmw_take method to perform more carefully control memory allocations.
*
* This will allow the middleware to preallocate the correct amount of memory
* for a given message type and message bounds.
* As allocation is performed in this method, it will not be necessary to allocate
* in the `rmw_take` method.
*
* \param[in] type_support Type support of the message to be preallocated.
* \param[in] message_bounds Bounds structure of the message to be preallocated.
* \param[out] allocation Allocation structure to be passed to `rmw_take`.
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if an argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_init_subscription_allocation(
const rosidl_message_type_support_t * type_support,
const rosidl_message_bounds_t * message_bounds,
rmw_subscription_allocation_t * allocation);
/// Destroy a publisher allocation object.
/**
* This deallocates memory allocated by `rmw_init_subscription_allocation`.
*
* \param[in] allocation Allocation object to be destroyed.
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_fini_subscription_allocation(
rmw_subscription_allocation_t * allocation);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_subscription_t *
rmw_create_subscription(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_support,
const char * topic_name,
const rmw_qos_profile_t * qos_policies,
bool ignore_local_publications);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_subscription(rmw_node_t * node, rmw_subscription_t * subscription);
/// Retrieve the number of matched publishers to a subscription.
/**
* Query the underlying middleware to determine how many publishers are
* matched to a given subscription.
*
* \param[in] subscription the subscription object to inspect
* \param[out] publisher_count the number of publishers matched
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if either argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_subscription_count_matched_publishers(
const rmw_subscription_t * subscription,
size_t * publisher_count);
/// Retrieve the actual qos settings of the subscription.
/**
* Query the underlying middleware to determine the qos settings
* of the subscription.
* The actual configuration applied when using RMW_*_SYSTEM_DEFAULT
* can only be resolved after the creation of the subscription, and it
* depends on the underlying rmw implementation.
* If the underlying setting in use can't be represented in ROS terms,
* it will be set to RMW_*_UNKNOWN.
* The value of avoid_ros_namespace_conventions field is not resolved
* with this function. The rcl function rcl_subscription_get_actual_qos
* resolves it.
*
* \param[in] subscription the subscription object to inspect
* \param[out] qos the actual qos settings
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if either argument is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_subscription_get_actual_qos(
const rmw_subscription_t * subscription,
rmw_qos_profile_t * qos);
/// Take an incoming message from a subscription.
/**
* Take an incoming ROS message from a given subscription.
*
* \param[in] subscription The subscription object to take from.
* \param[out] ros_message The ROS message data on success.
* \param[out] taken Boolean flag indicating if a message was taken or not.
* \param[in] allocation Preallocated buffer to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take(
const rmw_subscription_t * subscription,
void * ros_message,
bool * taken,
rmw_subscription_allocation_t * allocation);
/// Take an incoming message from a subscription with additional metadata.
/**
* Take an incoming ROS message from a given subscription.
*
* \param[in] subscription The subscription object to take from.
* \param[out] ros_message The ROS message data on success.
* \param[out] taken Boolean flag indicating if a message was taken or not.
* \param[out] message_info Additional message metadata.
* \param[in] allocation Preallocated buffer to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take_with_info(
const rmw_subscription_t * subscription,
void * ros_message,
bool * taken,
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation);
/// Take a message without deserializing it.
/**
* The message is taken in its serialized form. In contrast to rmw_take, the message
* is not deserialized in its ROS type but rather returned as a byte stream.
* The subscriber has to be registered for a specific type. But instead of receiving
* the message as its corresponding message type, it is taken as a byte stream.
* If needed, this byte stream can then be deserialized in a ROS message with a call to
* rmw_deserialize.
*
* \param[in] subscription Subscription object to take from.
* \param[out] serialized_message The destination in which to store the serialized message.
* \param[out] taken Boolean flag indicating if a message was taken or not.
* \param[in] allocation Preallocated buffer to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take_serialized_message(
const rmw_subscription_t * subscription,
rmw_serialized_message_t * serialized_message,
bool * taken,
rmw_subscription_allocation_t * allocation);
/// Take a message without deserializing it and with its additional message information.
/**
* The same as rmw_take_serialized_message(), except it also includes the
* rmw_message_info_t.
*
* \param[in] subscription Subscription object to take from.
* \param[out] serialized_message The destination in which to store the serialized message.
* \param[out] taken Boolean flag indicating if a message was taken or not.
* \param[out] message_info A structure containing meta information about the taken message.
* \param[in] allocation Preallocated buffer to use (may be NULL).
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take_serialized_message_with_info(
const rmw_subscription_t * subscription,
rmw_serialized_message_t * serialized_message,
bool * taken,
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_client_t *
rmw_create_client(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name,
const rmw_qos_profile_t * qos_policies);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_client(rmw_node_t * node, rmw_client_t * client);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_send_request(
const rmw_client_t * client,
const void * ros_request,
int64_t * sequence_id);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take_response(
const rmw_client_t * client,
rmw_request_id_t * request_header,
void * ros_response,
bool * taken);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_service_t *
rmw_create_service(
const rmw_node_t * node,
const rosidl_service_type_support_t * type_support,
const char * service_name,
const rmw_qos_profile_t * qos_policies);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_service(rmw_node_t * node, rmw_service_t * service);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_take_request(
const rmw_service_t * service,
rmw_request_id_t * request_header,
void * ros_request,
bool * taken);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_send_response(
const rmw_service_t * service,
rmw_request_id_t * request_header,
void * ros_response);
// TODO(wjwwood): refactor this API to return a return code when updated to use an allocator
/// Create a guard condition and return a handle to that guard condition.
/**
* This function can fail, and therefore return `NULL`, if:
* - context is `NULL`
* - context is invalid
* - memory allocation fails during guard condition creation
* - an unspecified error occurs
*
* The context must be non-null and valid, i.e. it has been initialized
* by `rmw_init()` and has not been finalized by `rmw_shutdown()`.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No [1]
* Lock-Free | No [1]
* <i>[1] rmw implementation defined, check the implementation documentation</i>
*
* This should be defined by the rmw implementation.
*
* \param[in] context init context that this node should be associated with
* \return rmw guard condition handle or `NULL` if there was an error
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_guard_condition_t *
rmw_create_guard_condition(rmw_context_t * context);
/// Finalize a given guard condition handle, reclaim the resources, and deallocate the handle.
/**
* \param guard_condition the guard condition handle to be destroyed
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if guard_condition is null, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_guard_condition(rmw_guard_condition_t * guard_condition);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition);
/// Create a wait set to store conditions that the middleware will block on.
/**
* This function can fail, and therefore return `NULL`, if:
* - context is `NULL`
* - context is invalid
* - memory allocation fails during wait set creation
* - an unspecified error occurs
*
* If `max_conditions` is `0`, the wait set can store an unbounded number of
* conditions to wait on.
* If `max_conditions` is greater than `0`, the number of conditions that can
* be attached to the wait set is bounded at `max_conditions`.
*
* \param[in] context init context that this node should be associated with
* \param[in] max_conditions
* The maximum number of conditions that can be attached to the wait set.
* \return A pointer to the created wait set, `NULL` if an error occurred.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_wait_set_t *
rmw_create_wait_set(rmw_context_t * context, size_t max_conditions);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_destroy_wait_set(rmw_wait_set_t * wait_set);
/// Waits on sets of different waitable entities and returns when one is ready.
/**
* Add conditions to the wait set and wait until a response comes in, or until
* the timeout is reached.
* The arrays contain type-erased representations of waitable entities.
* This function casts the pointers to middleware-specific conditions and adds
* them to the wait set.
*
* The count variables in the arrays represents the number of valid pointers
* in the array.
* `NULL` pointers are in the array considered invalid.
* If they are encountered, an error is returned.
*
* The array structs are allocated and deallocated outside of this function.
* They do not have any information about how much memory is allocated for the
* arrays.
*
* After the wait wakes up, the entries in each array that correspond to
* conditions that were not triggered are set to `NULL`.
*
* \param subscriptions Array of subscriptions to wait on
* \param guard_conditions Array of guard conditions to wait on
* \param services Array of services to wait on
* \param clients Array of clients to wait on
* \param wait_set Storage for the wait set
* \param wait_timeout
* If NULL, block until a condition is ready.
* If zero, check only for immediately available conditions and don't block.
* Else, this represents the maximum time to wait for a response from the
* wait set.
* \return `RMW_RET_OK` if success, or
* \return `RMW_RET_ERROR` if error, or
* \return `RMW_RET_TIMEOUT` if wait timed out.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_wait(
rmw_subscriptions_t * subscriptions,
rmw_guard_conditions_t * guard_conditions,
rmw_services_t * services,
rmw_clients_t * clients,
rmw_events_t * events,
rmw_wait_set_t * wait_set,
const rmw_time_t * wait_timeout);
/// Return a list of node name and namespaces discovered via a node.
/**
* This function will return a list of node names and a list of node namespaces
* that are discovered via the middleware.
* The two lists represent pairs of namespace and name for each discovered
* node.
* The lists will be the same length and the same position will refer to the
* same node across lists.
*
* The node parameter must not be `NULL`, and must point to a valid node.
*
* The node_names parameter must not be `NULL`, and must point to a valid
* string array.
*
* The node_namespaces parameter must not be `NULL`, and must point to a
* valid string array.
*
* This function does manipulate heap memory.
* This function is not thread-safe.
* This function is lock-free.
*
* \param[in] node the handle to the node being used to query the ROS graph
* \param[out] node_names a list of discovered node names
* \param[out] node_namespaces a list of discovered node namespaces
* \return `RMW_RET_OK` if node the query was made successfully, or
* \return `RMW_RET_ERROR` if an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_get_node_names(
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_count_publishers(
const rmw_node_t * node,
const char * topic_name,
size_t * count);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_count_subscribers(
const rmw_node_t * node,
const char * topic_name,
size_t * count);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_compare_gids_equal(const rmw_gid_t * gid1, const rmw_gid_t * gid2, bool * result);
/// Check if a service server is available for the given service client.
/**
* This function will return true for `is_available` if there is a service
* server available for the given client.
*
* The node parameter must not be `NULL`, and must point to a valid node.
*
* The client parameter must not be `NULL`, and must point to a valid client.
*
* The given client and node must match, i.e. the client must have been created
* using the given node.
*
* The is_available parameter must not be `NULL`, and must point to a bool
* variable.
* The result of the check will be stored in the is_available parameter.
*
* This function does manipulate heap memory.
* This function is not thread-safe.
* This function is lock-free.
*
* \param[in] node the handle to the node being used to query the ROS graph
* \param[in] client the handle to the service client being queried
* \param[out] is_available
* set to true if there is a service server available, else false
* \return `RMW_RET_OK` if node the check was made successfully, or
* \return `RMW_RET_ERROR` if an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_service_server_is_available(
const rmw_node_t * node,
const rmw_client_t * client,
bool * is_available);
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_set_log_severity(rmw_log_severity_t severity);
#ifdef __cplusplus
}
#endif
#endif // RMW__RMW_H_