hdds-c 1.1.1

High-performance DDS (Data Distribution Service) implementation in pure Rust
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
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
/*
 * HDDS C FFI Bindings
 * Auto-generated by cbindgen - DO NOT EDIT
 *
 * This header provides C-compatible bindings for the HDDS DDS implementation.
 */


#ifndef HDDS_H
#define HDDS_H

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
/* ROS2 RMW support - only include if building with ROS2 */
#ifdef HDDS_WITH_ROS2
#include <rosidl_runtime_c/message_type_support_struct.h>
#include <rosidl_runtime_c/string.h>
#include <rosidl_runtime_c/u16string.h>
#else
/* Standalone fallback definitions when not building with ROS 2 */
typedef struct rosidl_runtime_c__String {
  char *data;
  size_t size;
  size_t capacity;
} rosidl_runtime_c__String;
typedef struct rosidl_runtime_c__U16String {
  uint16_t *data;
  size_t size;
  size_t capacity;
} rosidl_runtime_c__U16String;
typedef struct rosidl_message_type_support_t rosidl_message_type_support_t;
#endif


/**
 * Error codes (C-compatible enum)
 *
 * # Error Code Categories
 *
 * - **0-9**: Success and generic errors
 * - **10-19**: Configuration errors
 * - **20-29**: I/O and transport errors
 * - **30-39**: Type and serialization errors
 * - **40-49**: QoS and resource errors
 * - **50-59**: Security errors
 */
typedef enum HddsError {
  /**
   * Operation completed successfully
   */
  HDDS_OK = 0,
  /**
   * Invalid argument provided (null pointer, invalid value)
   */
  HDDS_INVALID_ARGUMENT = 1,
  /**
   * Requested resource not found
   */
  HDDS_NOT_FOUND = 2,
  /**
   * Generic operation failure
   */
  HDDS_OPERATION_FAILED = 3,
  /**
   * Memory allocation failed
   */
  HDDS_OUT_OF_MEMORY = 4,
  /**
   * Invalid configuration settings
   */
  HDDS_CONFIG_ERROR = 10,
  /**
   * Invalid domain ID (must be 0-232)
   */
  HDDS_INVALID_DOMAIN_ID = 11,
  /**
   * Invalid participant ID (must be 0-119)
   */
  HDDS_INVALID_PARTICIPANT_ID = 12,
  /**
   * No available participant ID (all 120 ports occupied)
   */
  HDDS_NO_AVAILABLE_PARTICIPANT_ID = 13,
  /**
   * Invalid entity state for requested operation
   */
  HDDS_INVALID_STATE = 14,
  /**
   * Generic I/O error
   */
  HDDS_IO_ERROR = 20,
  /**
   * UDP transport send/receive failed
   */
  HDDS_TRANSPORT_ERROR = 21,
  /**
   * Topic registration failed
   */
  HDDS_REGISTRATION_FAILED = 22,
  /**
   * Operation would block but non-blocking mode requested
   */
  HDDS_WOULD_BLOCK = 23,
  /**
   * Type mismatch between writer and reader
   */
  HDDS_TYPE_MISMATCH = 30,
  /**
   * CDR serialization failed
   */
  HDDS_SERIALIZATION_ERROR = 31,
  /**
   * Buffer too small for encoding
   */
  HDDS_BUFFER_TOO_SMALL = 32,
  /**
   * CDR endianness mismatch
   */
  HDDS_ENDIAN_MISMATCH = 33,
  /**
   * QoS policies are incompatible between endpoints
   */
  HDDS_QOS_INCOMPATIBLE = 40,
  /**
   * Requested feature or operation is not supported
   */
  HDDS_UNSUPPORTED = 41,
  /**
   * Permission denied by access control (DDS Security)
   */
  HDDS_PERMISSION_DENIED = 50,
  /**
   * Authentication failed
   */
  HDDS_AUTHENTICATION_FAILED = 51,
} HddsError;

/**
 * Liveliness kind enumeration for C FFI.
 */
typedef enum HddsLivelinessKind {
  /**
   * DDS infrastructure automatically asserts liveliness.
   */
  HDDS_LIVELINESS_AUTOMATIC = 0,
  /**
   * Application must assert per participant.
   */
  HDDS_LIVELINESS_MANUAL_BY_PARTICIPANT = 1,
  /**
   * Application must assert per writer/topic.
   */
  HDDS_LIVELINESS_MANUAL_BY_TOPIC = 2,
} HddsLivelinessKind;

/**
 * Log level for HDDS logging
 */
typedef enum HddsLogLevel {
  HDDS_LOG_OFF = 0,
  HDDS_LOG_ERROR = 1,
  HDDS_LOG_WARN = 2,
  HDDS_LOG_INFO = 3,
  HDDS_LOG_DEBUG = 4,
  HDDS_LOG_TRACE = 5,
} HddsLogLevel;

/**
 * Shared memory policy for C FFI.
 */
typedef enum HddsShmPolicy {
  /**
   * Prefer SHM when available, fallback to UDP (default).
   */
  HDDS_SHM_PREFER = 0,
  /**
   * Require SHM, fail if conditions not met.
   */
  HDDS_SHM_REQUIRE = 1,
  /**
   * Disable SHM, always use network transport.
   */
  HDDS_SHM_DISABLE = 2,
} HddsShmPolicy;

/**
 * TCP role for C FFI.
 */
typedef enum HddsTcpRole {
  /**
   * Auto-negotiation via GUID tie-breaker (default).
   */
  HDDS_TCP_ROLE_AUTO = 0,
  /**
   * Server only: listen but never initiate.
   */
  HDDS_TCP_ROLE_SERVER_ONLY = 1,
  /**
   * Client only: initiate but never listen.
   */
  HDDS_TCP_ROLE_CLIENT_ONLY = 2,
} HddsTcpRole;

/**
 * Transport mode for participant creation
 */
typedef enum HddsTransportMode {
  /**
   * Intra-process only (no network, fastest for same-process communication)
   */
  HDDS_TRANSPORT_INTRA_PROCESS = 0,
  /**
   * UDP multicast for network discovery and communication (default for DDS interop)
   */
  HDDS_TRANSPORT_UDP_MULTICAST = 1,
} HddsTransportMode;

/**
 * Transport preference for C FFI.
 */
typedef enum HddsTransportPreference {
  /**
   * UDP only (default).
   */
  HDDS_TRANSPORT_PREF_UDP_ONLY = 0,
  /**
   * TCP only (requires initial peers).
   */
  HDDS_TRANSPORT_PREF_TCP_ONLY = 1,
  /**
   * UDP for discovery, TCP for data.
   */
  HDDS_TRANSPORT_PREF_UDP_DISCOVERY_TCP_DATA = 2,
  /**
   * Prefer SHM for local, UDP for remote.
   */
  HDDS_TRANSPORT_PREF_SHM_PREFERRED = 3,
  /**
   * SHM for local, TCP for remote.
   */
  HDDS_TRANSPORT_PREF_SHM_LOCAL_TCP_REMOTE = 4,
} HddsTransportPreference;

typedef struct Option_HddsLocatorVisitor Option_HddsLocatorVisitor;

typedef struct Option_HddsTopicVisitor Option_HddsTopicVisitor;

/**
 * Opaque handle to a Participant
 */
typedef struct HddsParticipant {
  uint8_t PRIVATE[0];
} HddsParticipant;

/**
 * Opaque handle to a GuardCondition
 */
typedef struct HddsGuardCondition {
  uint8_t PRIVATE[0];
} HddsGuardCondition;

typedef struct HddsTypeObject {
  uint8_t PRIVATE[0];
} HddsTypeObject;

/**
 * Opaque handle to a `DataWriter`
 */
typedef struct HddsDataWriter {
  uint8_t PRIVATE[0];
} HddsDataWriter;

/**
 * Opaque handle to a QoS profile.
 */
typedef struct HddsQoS {
  uint8_t PRIVATE[0];
} HddsQoS;

/**
 * Opaque handle to a `DataReader`
 */
typedef struct HddsDataReader {
  uint8_t PRIVATE[0];
} HddsDataReader;

/**
 * Opaque handle to a StatusCondition
 */
typedef struct HddsStatusCondition {
  uint8_t PRIVATE[0];
} HddsStatusCondition;

/**
 * Opaque handle to a WaitSet
 */
typedef struct HddsWaitSet {
  uint8_t PRIVATE[0];
} HddsWaitSet;

#if defined(HDDS_WITH_ROS2)
/**
 * Opaque handle to an rmw context
 */
typedef struct HddsRmwContext {
  uint8_t PRIVATE[0];
} HddsRmwContext;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct HddsRmwQosProfile {
  uint8_t HISTORY;
  uint32_t DEPTH;
  uint8_t RELIABILITY;
  uint8_t DURABILITY;
  uint64_t DEADLINE_NS;
  uint64_t LIFESPAN_NS;
  uint8_t LIVELINESS;
  uint64_t LIVELINESS_LEASE_NS;
  bool AVOID_ROS_NAMESPACE_CONVENTIONS;
} HddsRmwQosProfile;
#endif

#if defined(HDDS_WITH_ROS2)
typedef void (*HddsNodeVisitor)(const char*, const char*, void*);
#endif

#if defined(HDDS_WITH_ROS2)
typedef void (*HddsNodeEnclaveVisitor)(const char*, const char*, const char*, void*);
#endif

#if defined(HDDS_WITH_ROS2)
typedef void (*HddsEndpointVisitor)(const char*,
                                    const char*,
                                    const uint8_t*,
                                    const struct HddsRmwQosProfile*,
                                    void*);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Opaque handle to an rmw waitset
 */
typedef struct HddsRmwWaitSet {
  uint8_t PRIVATE[0];
} HddsRmwWaitSet;
#endif

/**
 * Callback for data available events.
 *
 * # Parameters
 * - `data`: Pointer to serialized sample bytes
 * - `len`: Length of the serialized data in bytes
 * - `user_data`: User-provided context pointer
 */
typedef void (*HddsOnDataAvailable)(const uint8_t *data, uintptr_t len, void *user_data);

/**
 * Subscription matched status (C-compatible mirror of Rust SubscriptionMatchedStatus).
 *
 * Reports the number of publications matched with this reader.
 */
typedef struct HddsSubscriptionMatchedStatus {
  /**
   * Total cumulative count of matched publications.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
  /**
   * Current number of matched publications.
   */
  uint32_t CURRENT_COUNT;
  /**
   * Change in current_count since last callback.
   */
  int32_t CURRENT_COUNT_CHANGE;
} HddsSubscriptionMatchedStatus;

/**
 * Callback for subscription matched events.
 */
typedef void (*HddsOnSubscriptionMatched)(const struct HddsSubscriptionMatchedStatus *status,
                                          void *user_data);

/**
 * Liveliness changed status (C-compatible mirror of Rust LivelinessChangedStatus).
 *
 * Reports changes in liveliness of matched writers.
 */
typedef struct HddsLivelinessChangedStatus {
  /**
   * Number of publications currently asserting liveliness.
   */
  uint32_t ALIVE_COUNT;
  /**
   * Change in alive_count since last callback.
   */
  int32_t ALIVE_COUNT_CHANGE;
  /**
   * Number of publications that have lost liveliness.
   */
  uint32_t NOT_ALIVE_COUNT;
  /**
   * Change in not_alive_count since last callback.
   */
  int32_t NOT_ALIVE_COUNT_CHANGE;
} HddsLivelinessChangedStatus;

/**
 * Callback for liveliness changed events.
 */
typedef void (*HddsOnLivelinessChanged)(const struct HddsLivelinessChangedStatus *status,
                                        void *user_data);

/**
 * Sample lost status (C-compatible mirror of Rust SampleLostStatus).
 *
 * Reports samples lost due to gaps in sequence numbers.
 */
typedef struct HddsSampleLostStatus {
  /**
   * Total cumulative count of lost samples.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
} HddsSampleLostStatus;

/**
 * Callback for sample lost events.
 */
typedef void (*HddsOnSampleLost)(const struct HddsSampleLostStatus *status, void *user_data);

/**
 * Sample rejected status (C-compatible mirror of Rust SampleRejectedStatus).
 *
 * Reports samples rejected due to resource limits.
 * `last_reason` values: 0=NotRejected, 1=ResourceLimit, 2=InstanceLimit,
 * 3=SamplesPerInstanceLimit.
 */
typedef struct HddsSampleRejectedStatus {
  /**
   * Total cumulative count of rejected samples.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
  /**
   * Reason for rejection (0=NotRejected, 1=ResourceLimit, 2=InstanceLimit, 3=SamplesPerInstanceLimit).
   */
  uint32_t LAST_REASON;
} HddsSampleRejectedStatus;

/**
 * Callback for sample rejected events.
 */
typedef void (*HddsOnSampleRejected)(const struct HddsSampleRejectedStatus *status, void *user_data);

/**
 * Deadline missed status (C-compatible mirror of Rust RequestedDeadlineMissedStatus).
 *
 * Reports missed deadlines on a reader or writer.
 */
typedef struct HddsDeadlineMissedStatus {
  /**
   * Total cumulative count of missed deadlines.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
} HddsDeadlineMissedStatus;

/**
 * Callback for deadline missed events (reader side).
 */
typedef void (*HddsOnDeadlineMissed)(const struct HddsDeadlineMissedStatus *status, void *user_data);

/**
 * Incompatible QoS status (C-compatible mirror of Rust RequestedIncompatibleQosStatus).
 *
 * Reports QoS incompatibility between matched endpoints.
 */
typedef struct HddsIncompatibleQosStatus {
  /**
   * Total cumulative count of incompatible QoS offers.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
  /**
   * ID of the last incompatible QoS policy.
   */
  uint32_t LAST_POLICY_ID;
} HddsIncompatibleQosStatus;

/**
 * Callback for incompatible QoS events (reader side).
 */
typedef void (*HddsOnIncompatibleQos)(const struct HddsIncompatibleQosStatus *status,
                                      void *user_data);

/**
 * C-compatible DataReader listener.
 *
 * Set callback fields to receive events. Any callback set to `None` (NULL)
 * will be silently ignored. The `user_data` pointer is passed through to
 * every callback invocation.
 *
 * # Example (C)
 *
 * ```c
 * HddsReaderListener listener = {0};
 * listener.on_data_available = my_data_callback;
 * listener.on_subscription_matched = my_match_callback;
 * listener.user_data = my_context;
 * hdds_reader_set_listener(reader, &listener);
 * ```
 */
typedef struct HddsReaderListener {
  /**
   * Called when new data is available to read.
   */
  HddsOnDataAvailable ON_DATA_AVAILABLE;
  /**
   * Called when the reader matches/unmatches with a writer.
   */
  HddsOnSubscriptionMatched ON_SUBSCRIPTION_MATCHED;
  /**
   * Called when liveliness of a matched writer changes.
   */
  HddsOnLivelinessChanged ON_LIVELINESS_CHANGED;
  /**
   * Called when samples are lost (gap in sequence numbers).
   */
  HddsOnSampleLost ON_SAMPLE_LOST;
  /**
   * Called when samples are rejected due to resource limits.
   */
  HddsOnSampleRejected ON_SAMPLE_REJECTED;
  /**
   * Called when the requested deadline is missed.
   */
  HddsOnDeadlineMissed ON_DEADLINE_MISSED;
  /**
   * Called when QoS is incompatible with a matched writer.
   */
  HddsOnIncompatibleQos ON_INCOMPATIBLE_QOS;
  /**
   * User-provided context pointer, passed to all callbacks.
   */
  void *USER_DATA;
} HddsReaderListener;

/**
 * Callback for sample written events (writer confirmation).
 *
 * # Parameters
 * - `data`: Pointer to serialized sample bytes
 * - `len`: Length of the serialized data in bytes
 * - `sequence_number`: Assigned RTPS sequence number
 * - `user_data`: User-provided context pointer
 */
typedef void (*HddsOnSampleWritten)(const uint8_t *data,
                                    uintptr_t len,
                                    uint64_t sequence_number,
                                    void *user_data);

/**
 * Publication matched status (C-compatible mirror of Rust PublicationMatchedStatus).
 *
 * Reports the number of subscriptions matched with this writer.
 */
typedef struct HddsPublicationMatchedStatus {
  /**
   * Total cumulative count of matched subscriptions.
   */
  uint32_t TOTAL_COUNT;
  /**
   * Change in total_count since last callback.
   */
  int32_t TOTAL_COUNT_CHANGE;
  /**
   * Current number of matched subscriptions.
   */
  uint32_t CURRENT_COUNT;
  /**
   * Change in current_count since last callback.
   */
  int32_t CURRENT_COUNT_CHANGE;
} HddsPublicationMatchedStatus;

/**
 * Callback for publication matched events.
 */
typedef void (*HddsOnPublicationMatched)(const struct HddsPublicationMatchedStatus *status,
                                         void *user_data);

/**
 * Callback for offered deadline missed events (writer side).
 *
 * # Parameters
 * - `instance_handle`: Handle of the instance that missed the deadline (0 if none)
 * - `user_data`: User-provided context pointer
 */
typedef void (*HddsOnOfferedDeadlineMissed)(uint64_t instance_handle, void *user_data);

/**
 * Callback for offered incompatible QoS events (writer side).
 *
 * # Parameters
 * - `policy_id`: ID of the incompatible QoS policy
 * - `policy_name`: Null-terminated policy name string (e.g., "RELIABILITY")
 * - `user_data`: User-provided context pointer
 */
typedef void (*HddsOnOfferedIncompatibleQos)(uint32_t policy_id,
                                             const char *policy_name,
                                             void *user_data);

/**
 * Callback for liveliness lost events (writer side).
 */
typedef void (*HddsOnLivelinessLost)(void *user_data);

/**
 * C-compatible DataWriter listener.
 *
 * Set callback fields to receive events. Any callback set to `None` (NULL)
 * will be silently ignored. The `user_data` pointer is passed through to
 * every callback invocation.
 *
 * # Example (C)
 *
 * ```c
 * HddsWriterListener listener = {0};
 * listener.on_publication_matched = my_match_callback;
 * listener.user_data = my_context;
 * hdds_writer_set_listener(writer, &listener);
 * ```
 */
typedef struct HddsWriterListener {
  /**
   * Called after a sample is successfully written.
   */
  HddsOnSampleWritten ON_SAMPLE_WRITTEN;
  /**
   * Called when the writer matches/unmatches with a reader.
   */
  HddsOnPublicationMatched ON_PUBLICATION_MATCHED;
  /**
   * Called when an offered deadline is missed.
   */
  HddsOnOfferedDeadlineMissed ON_OFFERED_DEADLINE_MISSED;
  /**
   * Called when QoS is incompatible with a matched reader.
   */
  HddsOnOfferedIncompatibleQos ON_OFFERED_INCOMPATIBLE_QOS;
  /**
   * Called when liveliness is lost (MANUAL_BY_* only).
   */
  HddsOnLivelinessLost ON_LIVELINESS_LOST;
  /**
   * User-provided context pointer, passed to all callbacks.
   */
  void *USER_DATA;
} HddsWriterListener;

/**
 * Opaque handle to a Publisher
 */
typedef struct HddsPublisher {
  uint8_t PRIVATE[0];
} HddsPublisher;

/**
 * Opaque handle to a Subscriber
 */
typedef struct HddsSubscriber {
  uint8_t PRIVATE[0];
} HddsSubscriber;

#if defined(HDDS_WITH_ROS2)
typedef struct RosString {
  char *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosString;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct RosStringSequence {
  struct RosString *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosStringSequence;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct RosOctetSequence {
  uint8_t *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosOctetSequence;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct RosBoolSequence {
  bool *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosBoolSequence;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct RosInt64Sequence {
  int64_t *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosInt64Sequence;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct RosDoubleSequence {
  double *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} RosDoubleSequence;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct ParameterValue {
  uint8_t TYPE;
  bool BOOL_VALUE;
  int64_t INTEGER_VALUE;
  double DOUBLE_VALUE;
  struct RosString STRING_VALUE;
  struct RosOctetSequence BYTE_ARRAY_VALUE;
  struct RosBoolSequence BOOL_ARRAY_VALUE;
  struct RosInt64Sequence INTEGER_ARRAY_VALUE;
  struct RosDoubleSequence DOUBLE_ARRAY_VALUE;
  struct RosStringSequence STRING_ARRAY_VALUE;
} ParameterValue;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct Parameter {
  struct RosString NAME;
  struct ParameterValue VALUE;
} Parameter;
#endif

#if defined(HDDS_WITH_ROS2)
typedef struct ParameterSequence {
  struct Parameter *DATA;
  uintptr_t SIZE;
  uintptr_t CAPACITY;
} ParameterSequence;
#endif

/**
 * Opaque handle to a security configuration.
 */
typedef struct HddsSecurityConfig {
  uint8_t PRIVATE[0];
} HddsSecurityConfig;

/**
 * Opaque handle to a MetricsCollector
 */
typedef struct HddsMetrics {
  uint8_t PRIVATE[0];
} HddsMetrics;

/**
 * Telemetry metrics snapshot (C-compatible)
 */
typedef struct HddsMetricsSnapshot {
  /**
   * Timestamp in nanoseconds since epoch
   */
  uint64_t TIMESTAMP_NS;
  /**
   * Total messages sent
   */
  uint64_t MESSAGES_SENT;
  /**
   * Total messages received
   */
  uint64_t MESSAGES_RECEIVED;
  /**
   * Total messages dropped
   */
  uint64_t MESSAGES_DROPPED;
  /**
   * Total bytes sent
   */
  uint64_t BYTES_SENT;
  /**
   * Latency p50 in nanoseconds
   */
  uint64_t LATENCY_P50_NS;
  /**
   * Latency p99 in nanoseconds
   */
  uint64_t LATENCY_P99_NS;
  /**
   * Latency p999 in nanoseconds
   */
  uint64_t LATENCY_P999_NS;
  /**
   * Merge full count (backpressure events)
   */
  uint64_t MERGE_FULL_COUNT;
  /**
   * Would-block count (send buffer full)
   */
  uint64_t WOULD_BLOCK_COUNT;
} HddsMetricsSnapshot;

/**
 * Opaque handle to a telemetry Exporter
 */
typedef struct HddsTelemetryExporter {
  uint8_t PRIVATE[0];
} HddsTelemetryExporter;

/**
 * Opaque handle to a participant configuration (builder).
 */
typedef struct HddsParticipantConfig {
  uint8_t PRIVATE[0];
} HddsParticipantConfig;

/**
 * Create a new DDS Participant with default settings (UdpMulticast transport)
 *
 * For network DDS communication, this is the recommended function.
 * Use `hdds_participant_create_with_transport` if you need intra-process mode.
 *
 * # Safety
 * - `name` must be a valid null-terminated C string.
 * - The returned handle must be released with `hdds_participant_destroy`.
 */
 struct HddsParticipant *hdds_participant_create(const char *aName);

/**
 * Create a new DDS Participant with specified transport mode
 *
 * # Safety
 * - `name` must be a valid null-terminated C string.
 * - The returned handle must be released with `hdds_participant_destroy`.
 *
 * # Arguments
 * * `name` - Participant name (null-terminated C string)
 * * `transport` - Transport mode:
 *   - `HddsTransportMode::HddsTransportIntraProcess` (0): No network, intra-process only
 *   - `HddsTransportMode::HddsTransportUdpMulticast` (1): UDP multicast for network discovery
 *
 * # Returns
 * Opaque participant handle, or NULL on failure
 */

struct HddsParticipant *hdds_participant_create_with_transport(const char *aName,
                                                               enum HddsTransportMode aTransport);

/**
 * Destroy a Participant
 *
 * # Safety
 * - `participant` must be a valid handle from `hdds_participant_create`, or NULL (no-op).
 * - Must not be called more than once with the same pointer.
 */
 void hdds_participant_destroy(struct HddsParticipant *aParticipant);

/**
 * Get the participant-level graph guard condition.
 *
 * # Safety
 * - `participant` must be a valid handle from `hdds_participant_create`.
 */

const struct HddsGuardCondition *hdds_participant_graph_guard_condition(struct HddsParticipant *aParticipant);

/**
 * Register a ROS 2 type support with the participant.
 *
 * # Safety
 * - `participant` must be a valid handle from `hdds_participant_create`.
 * - `type_support` must be a valid `rosidl_message_type_support_t` pointer.
 * - `out_handle` must be a valid pointer to write the result.
 */

enum HddsError hdds_participant_register_type_support(struct HddsParticipant *aParticipant,
                                                      uint32_t aDistro,
                                                      const rosidl_message_type_support_t *aTypeSupport,
                                                      const struct HddsTypeObject **aOutHandle);

/**
 * Release a type object handle.
 *
 * # Safety
 * - `handle` must be a valid handle from `hdds_participant_register_type_support`, or NULL.
 */
 void hdds_type_object_release(const struct HddsTypeObject *aHandle);

/**
 * Get the type hash from a type object handle.
 *
 * # Safety
 * - `handle` must be a valid handle from `hdds_participant_register_type_support`.
 * - `out_value` must point to a buffer of at least `value_len` bytes.
 */

enum HddsError hdds_type_object_hash(const struct HddsTypeObject *aHandle,
                                     uint8_t *aOutVersion,
                                     uint8_t *aOutValue,
                                     uintptr_t aValueLen);

/**
 * Get HDDS library version string
 *
 * # Safety
 * The returned pointer is valid for the lifetime of the process (static storage).
 */
 const char *hdds_version(void);

/**
 * Create a `DataWriter` for a topic
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 */

struct HddsDataWriter *hdds_writer_create(struct HddsParticipant *aParticipant,
                                          const char *aTopicName);

/**
 * Write data to a topic
 *
 * # Safety
 * - `writer` must be a valid pointer returned from `hdds_writer_create`
 * - `data` must point to valid memory of at least `len` bytes
 */

enum HddsError hdds_writer_write(struct HddsDataWriter *aWriter,
                                 const void *aData,
                                 uintptr_t aLen);

/**
 * Destroy a `DataWriter`
 *
 * # Safety
 * - `writer` must be a valid pointer returned from `hdds_writer_create`
 * - Must not be called more than once with the same pointer
 */
 void hdds_writer_destroy(struct HddsDataWriter *aWriter);

/**
 * Create a `DataWriter` for a topic with custom QoS
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `qos` must be a valid pointer returned from `hdds_qos_*` functions (or NULL for default)
 */

struct HddsDataWriter *hdds_writer_create_with_qos(struct HddsParticipant *aParticipant,
                                                   const char *aTopicName,
                                                   const struct HddsQoS *aQos);

/**
 * Create a `DataWriter` for a topic with custom QoS and explicit type name.
 *
 * The `type_name` is announced via SEDP and must match the remote endpoint's
 * type name for topic matching (e.g. `"P_Mount_PSM::C_Rotational_Mount_setPosition"`).
 * If `type_name` is NULL, falls back to the default `"RawBytes"` type name.
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `type_name` must be a valid null-terminated C string (or NULL for default)
 * - `qos` must be a valid pointer returned from `hdds_qos_*` functions (or NULL for default)
 */

struct HddsDataWriter *hdds_writer_create_with_type(struct HddsParticipant *aParticipant,
                                                    const char *aTopicName,
                                                    const char *aTypeName,
                                                    const struct HddsQoS *aQos);

/**
 * Create a `DataReader` for a topic
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 */

struct HddsDataReader *hdds_reader_create(struct HddsParticipant *aParticipant,
                                          const char *aTopicName);

/**
 * Create a `DataReader` for a topic with custom QoS
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `qos` must be a valid pointer returned from `hdds_qos_*` functions (or NULL for default)
 */

struct HddsDataReader *hdds_reader_create_with_qos(struct HddsParticipant *aParticipant,
                                                   const char *aTopicName,
                                                   const struct HddsQoS *aQos);

/**
 * Create a `DataReader` for a topic with custom QoS and explicit type name.
 *
 * The `type_name` is announced via SEDP and must match the remote endpoint's
 * type name for topic matching (e.g. `"P_Mount_PSM::C_Rotational_Mount_setPosition"`).
 * If `type_name` is NULL, falls back to the default `"RawBytes"` type name.
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `type_name` must be a valid null-terminated C string (or NULL for default)
 * - `qos` must be a valid pointer returned from `hdds_qos_*` functions (or NULL for default)
 */

struct HddsDataReader *hdds_reader_create_with_type(struct HddsParticipant *aParticipant,
                                                    const char *aTopicName,
                                                    const char *aTypeName,
                                                    const struct HddsQoS *aQos);

/**
 * Take data from a topic (non-blocking)
 *
 * # Safety
 * - `reader` must be a valid pointer returned from `hdds_reader_create`
 * - `data_out` must point to a valid buffer of at least `max_len` bytes
 * - `len_out` must be a valid pointer to write the actual data length
 */

enum HddsError hdds_reader_take(struct HddsDataReader *aReader,
                                void *aDataOut,
                                uintptr_t aMaxLen,
                                uintptr_t *aLenOut);

/**
 * Destroy a `DataReader`
 *
 * # Safety
 * - `reader` must be a valid pointer returned from `hdds_reader_create`
 * - Must not be called more than once with the same pointer
 */
 void hdds_reader_destroy(struct HddsDataReader *aReader);

/**
 * Get the status condition associated with a reader.
 *
 * # Safety
 * - `reader` must be a valid handle from `hdds_reader_create`.
 */
 const struct HddsStatusCondition *hdds_reader_get_status_condition(struct HddsDataReader *aReader);

/**
 * Release a previously acquired status condition.
 *
 * # Safety
 * - `condition` must be a valid handle from `hdds_reader_get_status_condition`.
 */
 void hdds_status_condition_release(const struct HddsStatusCondition *aCondition);

/**
 * Create a new guard condition.
 *
 * # Safety
 * The returned handle must be released with `hdds_guard_condition_release`.
 */
 const struct HddsGuardCondition *hdds_guard_condition_create(void);

/**
 * Release a guard condition.
 *
 * # Safety
 * - `condition` must be a valid handle from `hdds_guard_condition_create`.
 */
 void hdds_guard_condition_release(const struct HddsGuardCondition *aCondition);

/**
 * Set a guard condition's trigger value.
 *
 * # Safety
 * - `condition` must be a valid handle from `hdds_guard_condition_create`.
 */
 void hdds_guard_condition_set_trigger(const struct HddsGuardCondition *aCondition, bool aActive);

/**
 * Read a guard condition's current trigger value without modifying it.
 *
 * # Safety
 * - `condition` must be a valid handle from `hdds_guard_condition_create`.
 */
 bool hdds_guard_condition_get_trigger(const struct HddsGuardCondition *aCondition);

/**
 * Create a waitset.
 *
 * # Safety
 * The returned handle must be released with `hdds_waitset_destroy`.
 */
 struct HddsWaitSet *hdds_waitset_create(void);

/**
 * Destroy a waitset.
 *
 * # Safety
 * - `waitset` must be a valid handle from `hdds_waitset_create`, or NULL (no-op).
 */
 void hdds_waitset_destroy(struct HddsWaitSet *aWaitset);

/**
 * Attach a status condition to a waitset.
 *
 * # Safety
 * - `waitset` must be a valid handle from `hdds_waitset_create`.
 * - `condition` must be a valid handle from `hdds_reader_get_status_condition`.
 */

enum HddsError hdds_waitset_attach_status_condition(struct HddsWaitSet *aWaitset,
                                                    const struct HddsStatusCondition *aCondition);

/**
 * Attach a guard condition to a waitset.
 *
 * # Safety
 * - `waitset` must be a valid handle from `hdds_waitset_create`.
 * - `condition` must be a valid handle from `hdds_guard_condition_create`.
 */

enum HddsError hdds_waitset_attach_guard_condition(struct HddsWaitSet *aWaitset,
                                                   const struct HddsGuardCondition *aCondition);

/**
 * Detach a condition (status or guard) from a waitset.
 *
 * # Safety
 * - `waitset` must be a valid handle from `hdds_waitset_create`.
 * - `condition` must be a handle previously attached to this waitset.
 */
 enum HddsError hdds_waitset_detach_condition(struct HddsWaitSet *aWaitset, const void *aCondition);

/**
 * Wait for any attached condition to trigger.
 *
 * # Safety
 * - `waitset` must be a valid handle from `hdds_waitset_create`.
 * - `out_conditions` must point to an array of at least `max_conditions` pointers.
 * - `out_len` must be a valid pointer.
 */

enum HddsError hdds_waitset_wait(struct HddsWaitSet *aWaitset,
                                 int64_t aTimeoutNs,
                                 const void **aOutConditions,
                                 uintptr_t aMaxConditions,
                                 uintptr_t *aOutLen);

#if defined(HDDS_WITH_ROS2)
/**
 * Create a new rmw context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 struct HddsRmwContext *hdds_rmw_context_create(const char *aName);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Destroy an rmw context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 void hdds_rmw_context_destroy(struct HddsRmwContext *aCtx);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Get the graph guard key associated with the context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 uint64_t hdds_rmw_context_graph_guard_key(struct HddsRmwContext *aCtx);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Copy the participant GUID prefix (12 bytes) into `out_prefix`.
 *
 * Returns the participant's stable GUID prefix, suitable for building
 * cross-process unique GIDs (rmw_gid_t).
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 enum HddsError hdds_rmw_context_guid_prefix(struct HddsRmwContext *aCtx, uint8_t *aOutPrefix);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Get the graph guard condition associated with the context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

const struct HddsGuardCondition *hdds_rmw_context_graph_guard_condition(struct HddsRmwContext *aCtx);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Attach a guard condition to the rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_attach_guard_condition(struct HddsRmwContext *aCtx,
                                                       const struct HddsGuardCondition *aGuard,
                                                       uint64_t *aOutKey);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Attach a status condition to the rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_attach_status_condition(struct HddsRmwContext *aCtx,
                                                        const struct HddsStatusCondition *aStatus,
                                                        uint64_t *aOutKey);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Attach a reader to the rmw waitset (convenience helper).
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_attach_reader(struct HddsRmwContext *aCtx,
                                              struct HddsDataReader *aReader,
                                              uint64_t *aOutKey);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Create a DataReader bound to the rmw context participant.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_create_reader(struct HddsRmwContext *aCtx,
                                              const char *aTopicName,
                                              struct HddsDataReader **aOutReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Create a DataReader bound to the rmw context participant with custom QoS.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_create_reader_with_qos(struct HddsRmwContext *aCtx,
                                                       const char *aTopicName,
                                                       const struct HddsQoS *aQos,
                                                       struct HddsDataReader **aOutReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Destroy a DataReader created via the rmw context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_destroy_reader(struct HddsRmwContext *aCtx,
                                               struct HddsDataReader *aReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_create_writer(struct HddsRmwContext *aCtx,
                                              const char *aTopicName,
                                              struct HddsDataWriter **aOutWriter);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_create_writer_with_qos(struct HddsRmwContext *aCtx,
                                                       const char *aTopicName,
                                                       const struct HddsQoS *aQos,
                                                       struct HddsDataWriter **aOutWriter);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_bind_topic_type(struct HddsRmwContext *aCtx,
                                                const char *aTopicName,
                                                const rosidl_message_type_support_t *aTypeSupport);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_destroy_writer(struct HddsRmwContext *aCtx,
                                               struct HddsDataWriter *aWriter);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_register_node(struct HddsRmwContext *aCtx,
                                              const char *aNodeName,
                                              const char *aNodeNamespace,
                                              const char *aNodeEnclave);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_unregister_node(struct HddsRmwContext *aCtx,
                                                const char *aNodeName,
                                                const char *aNodeNamespace);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_register_publisher_endpoint(struct HddsRmwContext *aCtx,
                                                            const char *aNodeName,
                                                            const char *aNodeNamespace,
                                                            const char *aTopicName,
                                                            const rosidl_message_type_support_t *aTypeSupport,
                                                            const uint8_t *aEndpointGid,
                                                            const struct HddsRmwQosProfile *aQosProfile);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_unregister_publisher_endpoint(struct HddsRmwContext *aCtx,
                                                              const char *aNodeName,
                                                              const char *aNodeNamespace,
                                                              const char *aTopicName,
                                                              const uint8_t *aEndpointGid);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_register_subscription_endpoint(struct HddsRmwContext *aCtx,
                                                               const char *aNodeName,
                                                               const char *aNodeNamespace,
                                                               const char *aTopicName,
                                                               const rosidl_message_type_support_t *aTypeSupport,
                                                               const uint8_t *aEndpointGid,
                                                               const struct HddsRmwQosProfile *aQosProfile);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_unregister_subscription_endpoint(struct HddsRmwContext *aCtx,
                                                                 const char *aNodeName,
                                                                 const char *aNodeNamespace,
                                                                 const char *aTopicName,
                                                                 const uint8_t *aEndpointGid);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_node(struct HddsRmwContext *aCtx,
                                              HddsNodeVisitor aVisitor,
                                              void *aUserData,
                                              uint64_t *aOutVersion,
                                              uintptr_t *aOutCount);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_node_with_enclave(struct HddsRmwContext *aCtx,
                                                           HddsNodeEnclaveVisitor aVisitor,
                                                           void *aUserData,
                                                           uint64_t *aOutVersion,
                                                           uintptr_t *aOutCount);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_publisher_endpoint(struct HddsRmwContext *aCtx,
                                                            const char *aNodeName,
                                                            const char *aNodeNamespace,
                                                            HddsEndpointVisitor aVisitor,
                                                            void *aUserData,
                                                            uint64_t *aOutVersion,
                                                            uintptr_t *aOutCount);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_subscription_endpoint(struct HddsRmwContext *aCtx,
                                                               const char *aNodeName,
                                                               const char *aNodeNamespace,
                                                               HddsEndpointVisitor aVisitor,
                                                               void *aUserData,
                                                               uint64_t *aOutVersion,
                                                               uintptr_t *aOutCount);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_topic(struct HddsRmwContext *aCtx,
                                               struct Option_HddsTopicVisitor aVisitor,
                                               void *aUserData,
                                               uint64_t *aOutVersion);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_for_each_user_locator(struct HddsRmwContext *aCtx,
                                                      struct Option_HddsLocatorVisitor aVisitor,
                                                      void *aUserData,
                                                      uintptr_t *aOutCount);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_publish(struct HddsRmwContext *aCtx,
                                        struct HddsDataWriter *aWriter,
                                        const rosidl_message_type_support_t *aTypeSupport,
                                        const void *aRosMessage);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_publish_with_codec(struct HddsRmwContext *aCtx,
                                                   struct HddsDataWriter *aWriter,
                                                   uint8_t aCodecKind,
                                                   const void *aRosMessage);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Try to read from SHM ring buffer for a topic (inter-process fast path).
 *
 * Returns OK with `*len_out > 0` if data was read from SHM.
 * Returns NOT_FOUND if no SHM data available (caller should fall back to RTPS).
 *
 * # Safety
 * - `ctx` must be a valid `HddsRmwContext`
 * - `topic` must be a valid C string
 * - `data_out` must point to a buffer of at least `max_len` bytes
 * - `len_out` must be a valid pointer
 */

enum HddsError hdds_rmw_context_shm_try_take(struct HddsRmwContext *aCtx,
                                             const char *aTopic,
                                             void *aDataOut,
                                             uintptr_t aMaxLen,
                                             uintptr_t *aLenOut);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Check if SHM data is available for a topic (non-blocking).
 *
 * Returns `true` (1) if data is available, `false` (0) otherwise.
 *
 * # Safety
 * - `ctx` must be a valid `HddsRmwContext`
 * - `topic` must be a valid C string
 */
 bool hdds_rmw_context_shm_has_data(struct HddsRmwContext *aCtx, const char *aTopic);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_deserialize_with_codec(uint8_t aCodecKind,
                                               const uint8_t *aData,
                                               uintptr_t aDataLen,
                                               void *aRosMessage);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Check if a ROS2 type has a dynamic TypeDescriptor available.
 * Returns true if the type is supported for dynamic deserialization.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 bool hdds_rmw_has_type_descriptor(const char *aTypeName);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Deserialize CDR data to a ROS2 message using dynamic types.
 * Returns Ok if successful, InvalidArgument if type not supported.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_deserialize_dynamic(const char *aTypeName,
                                            const uint8_t *aData,
                                            uintptr_t aDataLen,
                                            void *aRosMessage);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Detach a condition previously attached to the rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 enum HddsError hdds_rmw_context_detach_condition(struct HddsRmwContext *aCtx, uint64_t aKey);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Detach a reader previously attached to the rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_detach_reader(struct HddsRmwContext *aCtx,
                                              struct HddsDataReader *aReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Wait for the rmw context waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_wait(struct HddsRmwContext *aCtx,
                                     int64_t aTimeoutNs,
                                     uint64_t *aOutKeys,
                                     const void **aOutConditions,
                                     uintptr_t aMaxConditions,
                                     uintptr_t *aOutLen);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Wait for reader notifications and report guard hits.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_context_wait_readers(struct HddsRmwContext *aCtx,
                                             int64_t aTimeoutNs,
                                             struct HddsDataReader **aOutReaders,
                                             uintptr_t aMaxReaders,
                                             uintptr_t *aOutLen,
                                             bool *aOutGuardTriggered);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Create an rmw waitset bound to a context.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 struct HddsRmwWaitSet *hdds_rmw_waitset_create(struct HddsRmwContext *aCtx);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Destroy an rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */
 void hdds_rmw_waitset_destroy(struct HddsRmwWaitSet *aWaitset);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Attach a reader to an rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_waitset_attach_reader(struct HddsRmwWaitSet *aWaitset,
                                              struct HddsDataReader *aReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Detach a reader from an rmw waitset.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_waitset_detach_reader(struct HddsRmwWaitSet *aWaitset,
                                              struct HddsDataReader *aReader);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 * Wait on an rmw waitset and report triggered readers and guard state.
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_waitset_wait(struct HddsRmwWaitSet *aWaitset,
                                     int64_t aTimeoutNs,
                                     struct HddsDataReader **aOutReaders,
                                     uintptr_t aMaxReaders,
                                     uintptr_t *aOutLen,
                                     bool *aOutGuardTriggered);
#endif

/**
 * Get the participant name
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 * - Returns a pointer to an internal string, valid until participant is destroyed
 *
 * # Returns
 * Pointer to null-terminated participant name, or NULL on error
 */
 const char *hdds_participant_name(struct HddsParticipant *aParticipant);

/**
 * Get the participant domain ID
 *
 * # Safety
 * - `participant` must be a valid pointer returned from `hdds_participant_create`
 *
 * # Returns
 * Domain ID (default 0), or 0xFFFFFFFF on error
 */
 uint32_t hdds_participant_domain_id(struct HddsParticipant *aParticipant);

/**
 * Get the participant ID (unique within domain)
 *
 * # Safety
 * - `participant` must be a valid pointer
 *
 * # Returns
 * Participant ID, or 0xFF on error
 */
 uint8_t hdds_participant_id(struct HddsParticipant *aParticipant);

/**
 * Get the topic name for a writer
 *
 * # Safety
 * - `writer` must be a valid pointer
 * - `buf` must point to a buffer of at least `buf_len` bytes
 * - `out_len` must be a valid pointer
 *
 * # Returns
 * `HddsError::HddsOk` on success, writes topic name to buffer
 */

enum HddsError hdds_writer_topic_name(struct HddsDataWriter *aWriter,
                                      char *aBuf,
                                      uintptr_t aBufLen,
                                      uintptr_t *aOutLen);

/**
 * Get the topic name for a reader
 *
 * # Safety
 * - `reader` must be a valid pointer
 * - `buf` must point to a buffer of at least `buf_len` bytes
 * - `out_len` must be a valid pointer
 *
 * # Returns
 * `HddsError::HddsOk` on success, writes topic name to buffer
 */

enum HddsError hdds_reader_topic_name(struct HddsDataReader *aReader,
                                      char *aBuf,
                                      uintptr_t aBufLen,
                                      uintptr_t *aOutLen);

/**
 * Install a listener on a DataReader.
 *
 * The listener struct is copied internally. The caller must ensure that
 * any `user_data` pointer and callback functions remain valid until the
 * listener is cleared or the reader is destroyed.
 *
 * # Safety
 *
 * - `reader` must be a valid pointer returned from `hdds_reader_create` or similar.
 * - `listener` must be a valid pointer to a properly initialized `HddsReaderListener`.
 *
 * # Returns
 *
 * `HddsOk` on success, `HddsInvalidArgument` if either pointer is null.
 */

enum HddsError hdds_reader_set_listener(struct HddsDataReader *aReader,
                                        const struct HddsReaderListener *aListener);

/**
 * Remove the listener from a DataReader.
 *
 * After this call, no more callbacks will be invoked for this reader.
 *
 * # Safety
 *
 * - `reader` must be a valid pointer returned from `hdds_reader_create` or similar.
 *
 * # Returns
 *
 * `HddsOk` on success, `HddsInvalidArgument` if the pointer is null.
 */
 enum HddsError hdds_reader_clear_listener(struct HddsDataReader *aReader);

/**
 * Install a listener on a DataWriter.
 *
 * The listener struct is copied internally. The caller must ensure that
 * any `user_data` pointer and callback functions remain valid until the
 * listener is cleared or the writer is destroyed.
 *
 * # Safety
 *
 * - `writer` must be a valid pointer returned from `hdds_writer_create` or similar.
 * - `listener` must be a valid pointer to a properly initialized `HddsWriterListener`.
 *
 * # Returns
 *
 * `HddsOk` on success, `HddsInvalidArgument` if either pointer is null.
 */

enum HddsError hdds_writer_set_listener(struct HddsDataWriter *aWriter,
                                        const struct HddsWriterListener *aListener);

/**
 * Remove the listener from a DataWriter.
 *
 * After this call, no more callbacks will be invoked for this writer.
 *
 * # Safety
 *
 * - `writer` must be a valid pointer returned from `hdds_writer_create` or similar.
 *
 * # Returns
 *
 * `HddsOk` on success, `HddsInvalidArgument` if the pointer is null.
 */
 enum HddsError hdds_writer_clear_listener(struct HddsDataWriter *aWriter);

/**
 * Initialize HDDS logging with console output
 *
 * # Safety
 * Must be called from a single thread during initialization.
 *
 * # Arguments
 * * `level` - Minimum log level to display
 *
 * # Returns
 * `HddsError::HddsOk` on success, `HddsError::HddsOperationFailed` if already initialized
 *
 * # Example (C)
 * ```c
 * hdds_logging_init(HDDS_LOG_INFO);
 * ```
 */
 enum HddsError hdds_logging_init(enum HddsLogLevel aLevel);

/**
 * Initialize HDDS logging with environment variable override
 *
 * Reads `RUST_LOG` environment variable if set, otherwise uses provided level.
 *
 * # Safety
 * Must be called from a single thread during initialization.
 *
 * # Arguments
 * * `default_level` - Default log level if `RUST_LOG` is not set
 *
 * # Returns
 * `HddsError::HddsOk` on success
 */
 enum HddsError hdds_logging_init_env(enum HddsLogLevel aDefaultLevel);

/**
 * Initialize HDDS logging with custom filter string
 *
 * # Safety
 * - `filter` must be a valid null-terminated C string or NULL.
 *
 * # Arguments
 * * `filter` - Log filter string (e.g., "hdds=debug,info")
 *
 * # Returns
 * `HddsError::HddsOk` on success
 *
 * # Example (C)
 * ```c
 * hdds_logging_init_with_filter("hdds=debug");
 * ```
 */
 enum HddsError hdds_logging_init_with_filter(const char *aFilter);

/**
 * Create a Publisher with default QoS
 *
 * # Safety
 * - `participant` must be a valid pointer
 *
 * # Returns
 * Publisher handle, or NULL on error
 */
 struct HddsPublisher *hdds_publisher_create(struct HddsParticipant *aParticipant);

/**
 * Create a Publisher with custom QoS
 *
 * # Safety
 * - `participant` must be a valid pointer
 * - `qos` can be NULL for default QoS
 *
 * # Returns
 * Publisher handle, or NULL on error
 */

struct HddsPublisher *hdds_publisher_create_with_qos(struct HddsParticipant *aParticipant,
                                                     const struct HddsQoS *aQos);

/**
 * Destroy a Publisher
 *
 * # Safety
 * - `publisher` must be a valid pointer or NULL
 */
 void hdds_publisher_destroy(struct HddsPublisher *aPublisher);

/**
 * Create a Subscriber with default QoS
 *
 * # Safety
 * - `participant` must be a valid pointer
 *
 * # Returns
 * Subscriber handle, or NULL on error
 */
 struct HddsSubscriber *hdds_subscriber_create(struct HddsParticipant *aParticipant);

/**
 * Create a Subscriber with custom QoS
 *
 * # Safety
 * - `participant` must be a valid pointer
 * - `qos` can be NULL for default QoS
 *
 * # Returns
 * Subscriber handle, or NULL on error
 */

struct HddsSubscriber *hdds_subscriber_create_with_qos(struct HddsParticipant *aParticipant,
                                                       const struct HddsQoS *aQos);

/**
 * Destroy a Subscriber
 *
 * # Safety
 * - `subscriber` must be a valid pointer or NULL
 */
 void hdds_subscriber_destroy(struct HddsSubscriber *aSubscriber);

/**
 * Create a DataWriter from a Publisher with default QoS
 *
 * # Safety
 * - `publisher` must be a valid pointer returned from `hdds_publisher_create`
 * - `topic_name` must be a valid null-terminated C string
 *
 * # Returns
 * DataWriter handle, or NULL on error
 */

struct HddsDataWriter *hdds_publisher_create_writer(struct HddsPublisher *aPublisher,
                                                    const char *aTopicName);

/**
 * Create a DataWriter from a Publisher with custom QoS
 *
 * # Safety
 * - `publisher` must be a valid pointer returned from `hdds_publisher_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `qos` can be NULL for default QoS
 *
 * # Returns
 * DataWriter handle, or NULL on error
 */

struct HddsDataWriter *hdds_publisher_create_writer_with_qos(struct HddsPublisher *aPublisher,
                                                             const char *aTopicName,
                                                             const struct HddsQoS *aQos);

/**
 * Create a DataReader from a Subscriber with default QoS
 *
 * # Safety
 * - `subscriber` must be a valid pointer returned from `hdds_subscriber_create`
 * - `topic_name` must be a valid null-terminated C string
 *
 * # Returns
 * DataReader handle, or NULL on error
 */

struct HddsDataReader *hdds_subscriber_create_reader(struct HddsSubscriber *aSubscriber,
                                                     const char *aTopicName);

/**
 * Create a DataReader from a Subscriber with custom QoS
 *
 * # Safety
 * - `subscriber` must be a valid pointer returned from `hdds_subscriber_create`
 * - `topic_name` must be a valid null-terminated C string
 * - `qos` can be NULL for default QoS
 *
 * # Returns
 * DataReader handle, or NULL on error
 */

struct HddsDataReader *hdds_subscriber_create_reader_with_qos(struct HddsSubscriber *aSubscriber,
                                                              const char *aTopicName,
                                                              const struct HddsQoS *aQos);

/**
 * Create a default QoS profile (best-effort, volatile).
 *
 * # Safety
 * The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_default(void);

/**
 * Create a best-effort QoS profile.
 *
 * Best-effort QoS does not guarantee delivery but has lower overhead.
 *
 * # Safety
 * The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_best_effort(void);

/**
 * Create a reliable QoS profile.
 *
 * Reliable QoS guarantees delivery with NACK-driven retransmission.
 *
 * # Safety
 * The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_reliable(void);

/**
 * Create an RTI Connext-compatible QoS profile.
 *
 * Uses RTI Connext DDS 6.x defaults for interoperability.
 *
 * # Safety
 * The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_rti_defaults(void);

/**
 * Destroy a QoS profile.
 *
 * # Safety
 * - `qos` must be a valid pointer returned from a `hdds_qos_*` creation function.
 * - Must not be called more than once with the same pointer.
 */
 void hdds_qos_destroy(struct HddsQoS *aQos);

/**
 * Load QoS from a FastDDS XML profile file.
 *
 * Parses the XML file and extracts the default profile's QoS settings.
 * Supports all 22 DDS QoS policies.
 *
 * # Arguments
 * - `path`: Path to the FastDDS XML profile file (null-terminated C string).
 *
 * # Returns
 * - Valid pointer on success.
 * - NULL if the file cannot be read or parsed.
 *
 * # Safety
 * - `path` must be a valid null-terminated C string.
 * - The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_load_fastdds_xml(const char *aPath);

/**
 * Load QoS from a vendor XML file (auto-detect vendor).
 *
 * Automatically detects the vendor format and parses accordingly.
 * Currently supports: FastDDS (eProsima).
 *
 * # Arguments
 * - `path`: Path to the XML profile file (null-terminated C string).
 *
 * # Returns
 * - Valid pointer on success.
 * - NULL if the file cannot be read or parsed.
 *
 * # Safety
 * - `path` must be a valid null-terminated C string.
 * - The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_from_xml(const char *aPath);

/**
 * Set history depth (KEEP_LAST) on a QoS profile.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_history_depth(struct HddsQoS *aQos, uint32_t aDepth);

/**
 * Set history policy to KEEP_ALL.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_history_keep_all(struct HddsQoS *aQos);

/**
 * Set durability to VOLATILE.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_volatile(struct HddsQoS *aQos);

/**
 * Set durability to TRANSIENT_LOCAL.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_transient_local(struct HddsQoS *aQos);

/**
 * Set durability to PERSISTENT.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_persistent(struct HddsQoS *aQos);

/**
 * Set reliability to RELIABLE.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_reliable(struct HddsQoS *aQos);

/**
 * Set reliability to BEST_EFFORT.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_best_effort(struct HddsQoS *aQos);

/**
 * Set deadline period in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_deadline_ns(struct HddsQoS *aQos, uint64_t aPeriodNs);

/**
 * Set lifespan duration in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_lifespan_ns(struct HddsQoS *aQos, uint64_t aDurationNs);

/**
 * Set ownership to SHARED.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_ownership_shared(struct HddsQoS *aQos);

/**
 * Set ownership to EXCLUSIVE with given strength.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_ownership_exclusive(struct HddsQoS *aQos, int32_t aStrength);

/**
 * Add a partition name to the QoS.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 * - `partition` must be a valid null-terminated C string.
 */
 enum HddsError hdds_qos_add_partition(struct HddsQoS *aQos, const char *aPartition);

/**
 * Check if QoS is reliable.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 bool hdds_qos_is_reliable(const struct HddsQoS *aQos);

/**
 * Check if QoS is transient-local.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 bool hdds_qos_is_transient_local(const struct HddsQoS *aQos);

/**
 * Get history depth.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint32_t hdds_qos_get_history_depth(const struct HddsQoS *aQos);

/**
 * Get deadline period in nanoseconds.
 *
 * Returns `u64::MAX` if infinite.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint64_t hdds_qos_get_deadline_ns(const struct HddsQoS *aQos);

/**
 * Get lifespan duration in nanoseconds.
 *
 * Returns `u64::MAX` if infinite.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint64_t hdds_qos_get_lifespan_ns(const struct HddsQoS *aQos);

/**
 * Check if ownership is exclusive.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 bool hdds_qos_is_ownership_exclusive(const struct HddsQoS *aQos);

/**
 * Get ownership strength value.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 int32_t hdds_qos_get_ownership_strength(const struct HddsQoS *aQos);

/**
 * Get liveliness kind.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsLivelinessKind hdds_qos_get_liveliness_kind(const struct HddsQoS *aQos);

/**
 * Get liveliness lease duration in nanoseconds.
 *
 * Returns `u64::MAX` if infinite.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint64_t hdds_qos_get_liveliness_lease_ns(const struct HddsQoS *aQos);

/**
 * Get time-based filter minimum separation in nanoseconds.
 *
 * Returns 0 if no filtering (all samples delivered).
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint64_t hdds_qos_get_time_based_filter_ns(const struct HddsQoS *aQos);

/**
 * Get latency budget in nanoseconds.
 *
 * Returns 0 if no latency budget (best effort delivery).
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uint64_t hdds_qos_get_latency_budget_ns(const struct HddsQoS *aQos);

/**
 * Get transport priority.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 int32_t hdds_qos_get_transport_priority(const struct HddsQoS *aQos);

/**
 * Get max samples resource limit.
 *
 * Returns `usize::MAX` for unlimited.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uintptr_t hdds_qos_get_max_samples(const struct HddsQoS *aQos);

/**
 * Get max instances resource limit.
 *
 * Returns `usize::MAX` for unlimited.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uintptr_t hdds_qos_get_max_instances(const struct HddsQoS *aQos);

/**
 * Get max samples per instance resource limit.
 *
 * Returns `usize::MAX` for unlimited.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 uintptr_t hdds_qos_get_max_samples_per_instance(const struct HddsQoS *aQos);

/**
 * Set liveliness to automatic with given lease duration in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_liveliness_automatic_ns(struct HddsQoS *aQos, uint64_t aLeaseNs);

/**
 * Set liveliness to manual-by-participant with given lease duration in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */

enum HddsError hdds_qos_set_liveliness_manual_participant_ns(struct HddsQoS *aQos,
                                                             uint64_t aLeaseNs);

/**
 * Set liveliness to manual-by-topic with given lease duration in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_liveliness_manual_topic_ns(struct HddsQoS *aQos, uint64_t aLeaseNs);

/**
 * Set time-based filter minimum separation in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_time_based_filter_ns(struct HddsQoS *aQos, uint64_t aMinSeparationNs);

/**
 * Set latency budget in nanoseconds.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_latency_budget_ns(struct HddsQoS *aQos, uint64_t aBudgetNs);

/**
 * Set transport priority.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */
 enum HddsError hdds_qos_set_transport_priority(struct HddsQoS *aQos, int32_t aPriority);

/**
 * Set resource limits.
 *
 * Use `usize::MAX` for any value to indicate unlimited.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 */

enum HddsError hdds_qos_set_resource_limits(struct HddsQoS *aQos,
                                            uintptr_t aMaxSamples,
                                            uintptr_t aMaxInstances,
                                            uintptr_t aMaxSamplesPerInstance);

/**
 * Clone a QoS profile.
 *
 * # Safety
 * - `qos` must be a valid pointer from `hdds_qos_*` functions.
 * - The returned pointer must be freed with `hdds_qos_destroy`.
 */
 struct HddsQoS *hdds_qos_clone(const struct HddsQoS *aQos);

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__String__init(rosidl_runtime_c__String *aStr);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__String__fini(rosidl_runtime_c__String *aStr);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__String__assign(rosidl_runtime_c__String *aStr, const char *aValue);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__U16String__init(rosidl_runtime_c__U16String *aStr);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__U16String__fini(rosidl_runtime_c__U16String *aStr);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__U16String__assignn(rosidl_runtime_c__U16String *aStr,
                                                 const uint16_t *aValue,
                                                 uintptr_t aLen);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_deserialize_ros_message(const rosidl_message_type_support_t *aTypeSupport,
                                                const uint8_t *aData,
                                                uintptr_t aLen,
                                                void *aRosMessage);
#endif

#if defined(HDDS_WITH_ROS2)
/**
 *
 * # Safety
 * Caller must ensure all pointer arguments are valid or NULL.
 */

enum HddsError hdds_rmw_serialize_ros_message(const rosidl_message_type_support_t *aTypeSupport,
                                              const void *aRosMessage,
                                              uint8_t *aBuffer,
                                              uintptr_t aCapacity,
                                              uintptr_t *aOutLen);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__String__assignn(struct RosString *aStr,
                                              const char *aValue,
                                              uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__String__Sequence__init(struct RosStringSequence *aSeq,
                                                     uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__String__Sequence__fini(struct RosStringSequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__octet__Sequence__init(struct RosOctetSequence *aSeq, uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__octet__Sequence__fini(struct RosOctetSequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__boolean__Sequence__init(struct RosBoolSequence *aSeq,
                                                      uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__boolean__Sequence__fini(struct RosBoolSequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__int64__Sequence__init(struct RosInt64Sequence *aSeq, uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__int64__Sequence__fini(struct RosInt64Sequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__double__Sequence__init(struct RosDoubleSequence *aSeq,
                                                     uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rosidl_runtime_c__double__Sequence__fini(struct RosDoubleSequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rcl_interfaces__msg__Parameter__Sequence__init(struct ParameterSequence *aSeq,
                                                           uintptr_t aSize);
#endif

#if defined(HDDS_WITH_ROS2)
extern void rcl_interfaces__msg__Parameter__Sequence__fini(struct ParameterSequence *aSeq);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__String__assign(rosidl_runtime_c__String *aStr, const char *aValue);
#endif

#if defined(HDDS_WITH_ROS2)
extern bool rosidl_runtime_c__U16String__assignn(rosidl_runtime_c__U16String *aStr,
                                                 const uint16_t *aValue,
                                                 uintptr_t aLen);
#endif

/**
 * Create a new security configuration.
 *
 * Must be attached to a participant config via `hdds_config_set_security`
 * or freed with `hdds_security_config_destroy`.
 */
 struct HddsSecurityConfig *hdds_security_config_create(void);

/**
 * Destroy a security configuration.
 *
 * Only call this if NOT passed to `hdds_config_set_security` (which consumes it).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_security_config_create`, or NULL.
 */
 void hdds_security_config_destroy(struct HddsSecurityConfig *aConfig);

/**
 * Set the identity certificate path (X.509 PEM format, required).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_identity_cert(struct HddsSecurityConfig *aConfig,
                                                      const char *aPath);

/**
 * Set the private key path (PEM format, required).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_private_key(struct HddsSecurityConfig *aConfig,
                                                    const char *aPath);

/**
 * Set the CA certificates path (PEM format, required).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_ca_cert(struct HddsSecurityConfig *aConfig,
                                                const char *aPath);

/**
 * Set the governance XML path (optional, for domain-level security rules).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_governance_xml(struct HddsSecurityConfig *aConfig,
                                                       const char *aPath);

/**
 * Set the permissions XML path (optional, for topic/partition authorization).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_permissions_xml(struct HddsSecurityConfig *aConfig,
                                                        const char *aPath);

/**
 * Enable or disable AES-256-GCM encryption (default: false).
 *
 * # Safety
 * - `config` must be valid.
 */

enum HddsError hdds_security_config_enable_encryption(struct HddsSecurityConfig *aConfig,
                                                      bool aEnabled);

/**
 * Enable or disable audit logging (default: false).
 *
 * # Safety
 * - `config` must be valid.
 */

enum HddsError hdds_security_config_enable_audit_log(struct HddsSecurityConfig *aConfig,
                                                     bool aEnabled);

/**
 * Set audit log file path (optional, in-memory only if not set).
 *
 * # Safety
 * - `config` must be valid. `path` must be null-terminated.
 */

enum HddsError hdds_security_config_set_audit_log_path(struct HddsSecurityConfig *aConfig,
                                                       const char *aPath);

/**
 * Require authentication for all participants (default: true).
 *
 * # Safety
 * - `config` must be valid.
 */

enum HddsError hdds_security_config_require_authentication(struct HddsSecurityConfig *aConfig,
                                                           bool aRequired);

/**
 * Enable CRL/OCSP certificate revocation checking (default: false).
 *
 * Adds ~50-200ms network round-trip per participant.
 *
 * # Safety
 * - `config` must be valid.
 */

enum HddsError hdds_security_config_check_revocation(struct HddsSecurityConfig *aConfig,
                                                     bool aEnabled);

/**
 * Initialize the global metrics collector
 *
 * Creates a thread-safe metrics collector for the entire HDDS instance.
 * Safe to call multiple times - subsequent calls return the same instance.
 *
 * # Safety
 * The returned handle must be released with `hdds_telemetry_release`.
 *
 * # Returns
 * Handle to the metrics collector, or NULL on error
 */
 struct HddsMetrics *hdds_telemetry_init(void);

/**
 * Get the global metrics collector (if initialized)
 *
 * # Safety
 * The returned handle must be released with `hdds_telemetry_release`.
 *
 * # Returns
 * Handle to metrics collector, or NULL if not initialized
 */
 struct HddsMetrics *hdds_telemetry_get(void);

/**
 * Release a metrics handle
 *
 * # Safety
 * - `metrics` must be a valid pointer from `hdds_telemetry_init` or `hdds_telemetry_get`
 */
 void hdds_telemetry_release(struct HddsMetrics *aMetrics);

/**
 * Take a snapshot of current metrics
 *
 * # Safety
 * - `metrics` must be a valid handle
 * - `out` must be a valid pointer to `HddsMetricsSnapshot`
 *
 * # Returns
 * `HddsError::HddsOk` on success
 */

enum HddsError hdds_telemetry_snapshot(struct HddsMetrics *aMetrics,
                                       struct HddsMetricsSnapshot *aOut);

/**
 * Record a latency sample
 *
 * # Safety
 * - `metrics` must be a valid handle
 *
 * # Arguments
 * * `start_ns` - Start timestamp in nanoseconds
 * * `end_ns` - End timestamp in nanoseconds
 */

void hdds_telemetry_record_latency(struct HddsMetrics *aMetrics,
                                   uint64_t aStartNs,
                                   uint64_t aEndNs);

/**
 * Start the telemetry export server
 *
 * Creates a TCP server that streams metrics to connected clients (e.g., HDDS Viewer).
 *
 * # Safety
 * - `bind_addr` must be a valid null-terminated C string.
 * - The returned handle must be released with `hdds_telemetry_stop_exporter`.
 *
 * # Arguments
 * * `bind_addr` - IP address to bind (e.g., "127.0.0.1" or "0.0.0.0")
 * * `port` - Port number (default: 4242)
 *
 * # Returns
 * Handle to exporter, or NULL on error
 */
 struct HddsTelemetryExporter *hdds_telemetry_start_exporter(const char *aBindAddr, uint16_t aPort);

/**
 * Stop and release the telemetry exporter
 *
 * # Safety
 * - `exporter` must be a valid pointer from `hdds_telemetry_start_exporter`
 */
 void hdds_telemetry_stop_exporter(struct HddsTelemetryExporter *aExporter);

/**
 * Create a new participant configuration (builder).
 *
 * The returned handle must be passed to `hdds_config_build` (which consumes it)
 * or freed with `hdds_config_destroy` if not used.
 *
 * # Safety
 * - `name` must be a valid null-terminated C string.
 */
 struct HddsParticipantConfig *hdds_config_create(const char *aName);

/**
 * Destroy a participant configuration without building.
 *
 * Only call this if you do NOT call `hdds_config_build`.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`, or NULL.
 */
 void hdds_config_destroy(struct HddsParticipantConfig *aConfig);

/**
 * Set the DDS domain ID.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_domain_id(struct HddsParticipantConfig *aConfig,
                                         uint32_t aDomainId);

/**
 * Set the participant ID (for port assignment).
 *
 * Each participant on the same host should have a unique ID (0-119).
 * If not set, ports are auto-probed.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_participant_id(struct HddsParticipantConfig *aConfig,
                                              uint8_t aParticipantId);

/**
 * Set the transport mode (IntraProcess or UdpMulticast).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_transport_mode(struct HddsParticipantConfig *aConfig,
                                              enum HddsTransportMode aMode);

/**
 * Set custom discovery ports (override RTPS default port formula).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_discovery_ports(struct HddsParticipantConfig *aConfig,
                                               uint16_t aSpdpMulticast,
                                               uint16_t aSedpUnicast,
                                               uint16_t aUserUnicast);

/**
 * Add a static UDP peer for unicast discovery (e.g. embedded devices).
 *
 * Can be called multiple times.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 * - `addr` must be a valid null-terminated C string in "host:port" format.
 */

enum HddsError hdds_config_add_static_peer(struct HddsParticipantConfig *aConfig,
                                           const char *aAddr);

/**
 * Set shared memory policy.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_shm_policy(struct HddsParticipantConfig *aConfig,
                                          enum HddsShmPolicy aPolicy);

/**
 * Enable TCP transport with a listen port.
 *
 * This enables hybrid mode (UDP discovery + TCP data) by default.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */
 enum HddsError hdds_config_enable_tcp(struct HddsParticipantConfig *aConfig, uint16_t aListenPort);

/**
 * Set TCP role (Auto, ServerOnly, ClientOnly).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_tcp_role(struct HddsParticipantConfig *aConfig,
                                        enum HddsTcpRole aRole);

/**
 * Add a TCP initial peer address (for TCP-only or client mode).
 *
 * Can be called multiple times to add multiple peers.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 * - `addr` must be a valid null-terminated C string in "host:port" format.
 */
 enum HddsError hdds_config_add_tcp_peer(struct HddsParticipantConfig *aConfig, const char *aAddr);

/**
 * Set TCP nodelay option (disable Nagle's algorithm).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */
 enum HddsError hdds_config_set_tcp_nodelay(struct HddsParticipantConfig *aConfig, bool aNodelay);

/**
 * Enable TLS on TCP transport.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */
 enum HddsError hdds_config_enable_tls(struct HddsParticipantConfig *aConfig);

/**
 * Set transport preference (UDP-only, TCP-only, hybrid, SHM+TCP, etc.).
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 */

enum HddsError hdds_config_set_transport_preference(struct HddsParticipantConfig *aConfig,
                                                    enum HddsTransportPreference aPref);

/**
 * Attach a security configuration to this participant config.
 *
 * **This consumes the security config handle.** Do NOT call
 * `hdds_security_config_destroy` after this.
 *
 * Requires the `security` feature to be enabled at compile time.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 * - `security` must be a valid pointer from `hdds_security_config_create`.
 */

enum HddsError hdds_config_set_security(struct HddsParticipantConfig *aConfig,
                                        struct HddsSecurityConfig *aSecurity);

/**
 * Build a Participant from the configuration.
 *
 * **This consumes the config handle.** Do NOT call `hdds_config_destroy`
 * after this. If build fails, the config is still consumed and NULL is returned.
 *
 * # Safety
 * - `config` must be a valid pointer from `hdds_config_create`.
 * - After this call, `config` is invalid (consumed).
 */
 struct HddsParticipant *hdds_config_build(struct HddsParticipantConfig *aConfig);

#endif  /* HDDS_H */