forked from ADLINK-IST/opensplice-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tglib.c
1984 lines (1843 loc) · 71.8 KB
/
tglib.c
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
/* Copyright 2017 PrismTech Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <inttypes.h>
#include <dds_dcps.h>
#include "common.h"
#include "tglib.h"
#include "porting.h"
static const char *mdParticipantBuiltinTopicData = "<MetaData version=\"1.0.0\"><Module name=\"DDS\"><TypeDef name=\"BuiltinTopicKey_t\"><Array size=\"3\"><Long/></Array></TypeDef><TypeDef name=\"octSeq\"><Sequence><Octet/></Sequence></TypeDef><Struct name=\"UserDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"ParticipantBuiltinTopicData\"><Member name=\"key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"user_data\"><Type name=\"UserDataQosPolicy\"/></Member></Struct></Module></MetaData>";
static const char *mdTopicBuiltinTopicData = "<MetaData version=\"1.0.0\"><Module name=\"DDS\"><TypeDef name=\"BuiltinTopicKey_t\"><Array size=\"3\"><Long/></Array></TypeDef><Enum name=\"DurabilityQosPolicyKind\"><Element name=\"VOLATILE_DURABILITY_QOS\" value=\"0\"/><Element name=\"TRANSIENT_LOCAL_DURABILITY_QOS\" value=\"1\"/><Element name=\"TRANSIENT_DURABILITY_QOS\" value=\"2\"/><Element name=\"PERSISTENT_DURABILITY_QOS\" value=\"3\"/></Enum><Struct name=\"Duration_t\"><Member name=\"sec\"><Long/></Member><Member name=\"nanosec\"><ULong/></Member></Struct><Enum name=\"HistoryQosPolicyKind\"><Element name=\"KEEP_LAST_HISTORY_QOS\" value=\"0\"/><Element name=\"KEEP_ALL_HISTORY_QOS\" value=\"1\"/></Enum><Enum name=\"LivelinessQosPolicyKind\"><Element name=\"AUTOMATIC_LIVELINESS_QOS\" value=\"0\"/><Element name=\"MANUAL_BY_PARTICIPANT_LIVELINESS_QOS\" value=\"1\"/><Element name=\"MANUAL_BY_TOPIC_LIVELINESS_QOS\" value=\"2\"/></Enum><Enum name=\"ReliabilityQosPolicyKind\"><Element name=\"BEST_EFFORT_RELIABILITY_QOS\" value=\"0\"/><Element name=\"RELIABLE_RELIABILITY_QOS\" value=\"1\"/></Enum><Struct name=\"TransportPriorityQosPolicy\"><Member name=\"value\"><Long/></Member></Struct><Enum name=\"DestinationOrderQosPolicyKind\"><Element name=\"BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"0\"/><Element name=\"BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"1\"/></Enum><Struct name=\"ResourceLimitsQosPolicy\"><Member name=\"max_samples\"><Long/></Member><Member name=\"max_instances\"><Long/></Member><Member name=\"max_samples_per_instance\"><Long/></Member></Struct><Enum name=\"OwnershipQosPolicyKind\"><Element name=\"SHARED_OWNERSHIP_QOS\" value=\"0\"/><Element name=\"EXCLUSIVE_OWNERSHIP_QOS\" value=\"1\"/></Enum><TypeDef name=\"octSeq\"><Sequence><Octet/></Sequence></TypeDef><Struct name=\"DurabilityQosPolicy\"><Member name=\"kind\"><Type name=\"DurabilityQosPolicyKind\"/></Member></Struct><Struct name=\"LifespanQosPolicy\"><Member name=\"duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"LatencyBudgetQosPolicy\"><Member name=\"duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"DeadlineQosPolicy\"><Member name=\"period\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"HistoryQosPolicy\"><Member name=\"kind\"><Type name=\"HistoryQosPolicyKind\"/></Member><Member name=\"depth\"><Long/></Member></Struct><Struct name=\"DurabilityServiceQosPolicy\"><Member name=\"service_cleanup_delay\"><Type name=\"Duration_t\"/></Member><Member name=\"history_kind\"><Type name=\"HistoryQosPolicyKind\"/></Member><Member name=\"history_depth\"><Long/></Member><Member name=\"max_samples\"><Long/></Member><Member name=\"max_instances\"><Long/></Member><Member name=\"max_samples_per_instance\"><Long/></Member></Struct><Struct name=\"LivelinessQosPolicy\"><Member name=\"kind\"><Type name=\"LivelinessQosPolicyKind\"/></Member><Member name=\"lease_duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"ReliabilityQosPolicy\"><Member name=\"kind\"><Type name=\"ReliabilityQosPolicyKind\"/></Member><Member name=\"max_blocking_time\"><Type name=\"Duration_t\"/></Member><Member name=\"synchronous\"><Boolean/></Member></Struct><Struct name=\"DestinationOrderQosPolicy\"><Member name=\"kind\"><Type name=\"DestinationOrderQosPolicyKind\"/></Member></Struct><Struct name=\"OwnershipQosPolicy\"><Member name=\"kind\"><Type name=\"OwnershipQosPolicyKind\"/></Member></Struct><Struct name=\"TopicDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"TopicBuiltinTopicData\"><Member name=\"key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"name\"><String/></Member><Member name=\"type_name\"><String/></Member><Member name=\"durability\"><Type name=\"DurabilityQosPolicy\"/></Member><Member name=\"durability_service\"><Type name=\"DurabilityServiceQosPolicy\"/></Member><Member name=\"deadline\"><Type name=\"DeadlineQosPolicy\"/></Member><Member name=\"latency_budget\"><Type name=\"LatencyBudgetQosPolicy\"/></Member><Member name=\"liveliness\"><Type name=\"LivelinessQosPolicy\"/></Member><Member name=\"reliability\"><Type name=\"ReliabilityQosPolicy\"/></Member><Member name=\"transport_priority\"><Type name=\"TransportPriorityQosPolicy\"/></Member><Member name=\"lifespan\"><Type name=\"LifespanQosPolicy\"/></Member><Member name=\"destination_order\"><Type name=\"DestinationOrderQosPolicy\"/></Member><Member name=\"history\"><Type name=\"HistoryQosPolicy\"/></Member><Member name=\"resource_limits\"><Type name=\"ResourceLimitsQosPolicy\"/></Member><Member name=\"ownership\"><Type name=\"OwnershipQosPolicy\"/></Member><Member name=\"topic_data\"><Type name=\"TopicDataQosPolicy\"/></Member></Struct></Module></MetaData>";
static const char *mdPublicationBuiltinTopicData = "<MetaData version=\"1.0.0\"><Module name=\"DDS\"><TypeDef name=\"BuiltinTopicKey_t\"><Array size=\"3\"><Long/></Array></TypeDef><Enum name=\"DurabilityQosPolicyKind\"><Element name=\"VOLATILE_DURABILITY_QOS\" value=\"0\"/><Element name=\"TRANSIENT_LOCAL_DURABILITY_QOS\" value=\"1\"/><Element name=\"TRANSIENT_DURABILITY_QOS\" value=\"2\"/><Element name=\"PERSISTENT_DURABILITY_QOS\" value=\"3\"/></Enum><Struct name=\"Duration_t\"><Member name=\"sec\"><Long/></Member><Member name=\"nanosec\"><ULong/></Member></Struct><Enum name=\"LivelinessQosPolicyKind\"><Element name=\"AUTOMATIC_LIVELINESS_QOS\" value=\"0\"/><Element name=\"MANUAL_BY_PARTICIPANT_LIVELINESS_QOS\" value=\"1\"/><Element name=\"MANUAL_BY_TOPIC_LIVELINESS_QOS\" value=\"2\"/></Enum><Enum name=\"ReliabilityQosPolicyKind\"><Element name=\"BEST_EFFORT_RELIABILITY_QOS\" value=\"0\"/><Element name=\"RELIABLE_RELIABILITY_QOS\" value=\"1\"/></Enum><Enum name=\"DestinationOrderQosPolicyKind\"><Element name=\"BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"0\"/><Element name=\"BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"1\"/></Enum><TypeDef name=\"octSeq\"><Sequence><Octet/></Sequence></TypeDef><Enum name=\"OwnershipQosPolicyKind\"><Element name=\"SHARED_OWNERSHIP_QOS\" value=\"0\"/><Element name=\"EXCLUSIVE_OWNERSHIP_QOS\" value=\"1\"/></Enum><Struct name=\"OwnershipStrengthQosPolicy\"><Member name=\"value\"><Long/></Member></Struct><Enum name=\"PresentationQosPolicyAccessScopeKind\"><Element name=\"INSTANCE_PRESENTATION_QOS\" value=\"0\"/><Element name=\"TOPIC_PRESENTATION_QOS\" value=\"1\"/><Element name=\"GROUP_PRESENTATION_QOS\" value=\"2\"/></Enum><TypeDef name=\"StringSeq\"><Sequence><String/></Sequence></TypeDef><Struct name=\"DurabilityQosPolicy\"><Member name=\"kind\"><Type name=\"DurabilityQosPolicyKind\"/></Member></Struct><Struct name=\"LifespanQosPolicy\"><Member name=\"duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"LatencyBudgetQosPolicy\"><Member name=\"duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"DeadlineQosPolicy\"><Member name=\"period\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"LivelinessQosPolicy\"><Member name=\"kind\"><Type name=\"LivelinessQosPolicyKind\"/></Member><Member name=\"lease_duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"ReliabilityQosPolicy\"><Member name=\"kind\"><Type name=\"ReliabilityQosPolicyKind\"/></Member><Member name=\"max_blocking_time\"><Type name=\"Duration_t\"/></Member><Member name=\"synchronous\"><Boolean/></Member></Struct><Struct name=\"DestinationOrderQosPolicy\"><Member name=\"kind\"><Type name=\"DestinationOrderQosPolicyKind\"/></Member></Struct><Struct name=\"GroupDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"TopicDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"UserDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"OwnershipQosPolicy\"><Member name=\"kind\"><Type name=\"OwnershipQosPolicyKind\"/></Member></Struct><Struct name=\"PresentationQosPolicy\"><Member name=\"access_scope\"><Type name=\"PresentationQosPolicyAccessScopeKind\"/></Member><Member name=\"coherent_access\"><Boolean/></Member><Member name=\"ordered_access\"><Boolean/></Member></Struct><Struct name=\"PartitionQosPolicy\"><Member name=\"name\"><Type name=\"StringSeq\"/></Member></Struct><Struct name=\"PublicationBuiltinTopicData\"><Member name=\"key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"participant_key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"topic_name\"><String/></Member><Member name=\"type_name\"><String/></Member><Member name=\"durability\"><Type name=\"DurabilityQosPolicy\"/></Member><Member name=\"deadline\"><Type name=\"DeadlineQosPolicy\"/></Member><Member name=\"latency_budget\"><Type name=\"LatencyBudgetQosPolicy\"/></Member><Member name=\"liveliness\"><Type name=\"LivelinessQosPolicy\"/></Member><Member name=\"reliability\"><Type name=\"ReliabilityQosPolicy\"/></Member><Member name=\"lifespan\"><Type name=\"LifespanQosPolicy\"/></Member><Member name=\"destination_order\"><Type name=\"DestinationOrderQosPolicy\"/></Member><Member name=\"user_data\"><Type name=\"UserDataQosPolicy\"/></Member><Member name=\"ownership\"><Type name=\"OwnershipQosPolicy\"/></Member><Member name=\"ownership_strength\"><Type name=\"OwnershipStrengthQosPolicy\"/></Member><Member name=\"presentation\"><Type name=\"PresentationQosPolicy\"/></Member><Member name=\"partition\"><Type name=\"PartitionQosPolicy\"/></Member><Member name=\"topic_data\"><Type name=\"TopicDataQosPolicy\"/></Member><Member name=\"group_data\"><Type name=\"GroupDataQosPolicy\"/></Member></Struct></Module></MetaData>";
static const char *mdSubscriptionBuiltinTopicData = "<MetaData version=\"1.0.0\"><Module name=\"DDS\"><TypeDef name=\"BuiltinTopicKey_t\"><Array size=\"3\"><Long/></Array></TypeDef><Enum name=\"DurabilityQosPolicyKind\"><Element name=\"VOLATILE_DURABILITY_QOS\" value=\"0\"/><Element name=\"TRANSIENT_LOCAL_DURABILITY_QOS\" value=\"1\"/><Element name=\"TRANSIENT_DURABILITY_QOS\" value=\"2\"/><Element name=\"PERSISTENT_DURABILITY_QOS\" value=\"3\"/></Enum><Struct name=\"Duration_t\"><Member name=\"sec\"><Long/></Member><Member name=\"nanosec\"><ULong/></Member></Struct><Enum name=\"LivelinessQosPolicyKind\"><Element name=\"AUTOMATIC_LIVELINESS_QOS\" value=\"0\"/><Element name=\"MANUAL_BY_PARTICIPANT_LIVELINESS_QOS\" value=\"1\"/><Element name=\"MANUAL_BY_TOPIC_LIVELINESS_QOS\" value=\"2\"/></Enum><Enum name=\"ReliabilityQosPolicyKind\"><Element name=\"BEST_EFFORT_RELIABILITY_QOS\" value=\"0\"/><Element name=\"RELIABLE_RELIABILITY_QOS\" value=\"1\"/></Enum><Enum name=\"OwnershipQosPolicyKind\"><Element name=\"SHARED_OWNERSHIP_QOS\" value=\"0\"/><Element name=\"EXCLUSIVE_OWNERSHIP_QOS\" value=\"1\"/></Enum><Enum name=\"DestinationOrderQosPolicyKind\"><Element name=\"BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"0\"/><Element name=\"BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS\" value=\"1\"/></Enum><TypeDef name=\"octSeq\"><Sequence><Octet/></Sequence></TypeDef><Enum name=\"PresentationQosPolicyAccessScopeKind\"><Element name=\"INSTANCE_PRESENTATION_QOS\" value=\"0\"/><Element name=\"TOPIC_PRESENTATION_QOS\" value=\"1\"/><Element name=\"GROUP_PRESENTATION_QOS\" value=\"2\"/></Enum><TypeDef name=\"StringSeq\"><Sequence><String/></Sequence></TypeDef><Struct name=\"DurabilityQosPolicy\"><Member name=\"kind\"><Type name=\"DurabilityQosPolicyKind\"/></Member></Struct><Struct name=\"TimeBasedFilterQosPolicy\"><Member name=\"minimum_separation\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"LatencyBudgetQosPolicy\"><Member name=\"duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"DeadlineQosPolicy\"><Member name=\"period\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"LivelinessQosPolicy\"><Member name=\"kind\"><Type name=\"LivelinessQosPolicyKind\"/></Member><Member name=\"lease_duration\"><Type name=\"Duration_t\"/></Member></Struct><Struct name=\"ReliabilityQosPolicy\"><Member name=\"kind\"><Type name=\"ReliabilityQosPolicyKind\"/></Member><Member name=\"max_blocking_time\"><Type name=\"Duration_t\"/></Member><Member name=\"synchronous\"><Boolean/></Member></Struct><Struct name=\"OwnershipQosPolicy\"><Member name=\"kind\"><Type name=\"OwnershipQosPolicyKind\"/></Member></Struct><Struct name=\"DestinationOrderQosPolicy\"><Member name=\"kind\"><Type name=\"DestinationOrderQosPolicyKind\"/></Member></Struct><Struct name=\"GroupDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"TopicDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"UserDataQosPolicy\"><Member name=\"value\"><Type name=\"octSeq\"/></Member></Struct><Struct name=\"PresentationQosPolicy\"><Member name=\"access_scope\"><Type name=\"PresentationQosPolicyAccessScopeKind\"/></Member><Member name=\"coherent_access\"><Boolean/></Member><Member name=\"ordered_access\"><Boolean/></Member></Struct><Struct name=\"PartitionQosPolicy\"><Member name=\"name\"><Type name=\"StringSeq\"/></Member></Struct><Struct name=\"SubscriptionBuiltinTopicData\"><Member name=\"key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"participant_key\"><Type name=\"BuiltinTopicKey_t\"/></Member><Member name=\"topic_name\"><String/></Member><Member name=\"type_name\"><String/></Member><Member name=\"durability\"><Type name=\"DurabilityQosPolicy\"/></Member><Member name=\"deadline\"><Type name=\"DeadlineQosPolicy\"/></Member><Member name=\"latency_budget\"><Type name=\"LatencyBudgetQosPolicy\"/></Member><Member name=\"liveliness\"><Type name=\"LivelinessQosPolicy\"/></Member><Member name=\"reliability\"><Type name=\"ReliabilityQosPolicy\"/></Member><Member name=\"ownership\"><Type name=\"OwnershipQosPolicy\"/></Member><Member name=\"destination_order\"><Type name=\"DestinationOrderQosPolicy\"/></Member><Member name=\"user_data\"><Type name=\"UserDataQosPolicy\"/></Member><Member name=\"time_based_filter\"><Type name=\"TimeBasedFilterQosPolicy\"/></Member><Member name=\"presentation\"><Type name=\"PresentationQosPolicy\"/></Member><Member name=\"partition\"><Type name=\"PartitionQosPolicy\"/></Member><Member name=\"topic_data\"><Type name=\"TopicDataQosPolicy\"/></Member><Member name=\"group_data\"><Type name=\"GroupDataQosPolicy\"/></Member></Struct></Module></MetaData>";
union tokenval {
int64_t i;
uint64_t ui;
char ch;
double d;
char *str;
};
enum tokenkind {
TOK_ERROR,
TOK_EOF,
TOK_INT,
TOK_FLOAT,
TOK_CHAR,
TOK_STRING,
TOK_SYMBOL,
TOK_COMMA,
TOK_DOT,
TOK_EQUALS,
TOK_LBRACE,
TOK_RBRACE,
TOK_COLON,
TOK_LBRACKET,
TOK_RBRACKET,
TOK_LITERAL
};
struct token {
const char *src;
enum tokenkind kind;
union tokenval val;
};
#define TOKEN_INIT(src) { (src), TOK_ERROR, { .i = 0 } }
struct lexer {
int error;
int have_token;
struct token token;
const char *srcstart;
const char *src;
};
enum tgkind {
TG_BOOLEAN,
TG_CHAR,
TG_INT,
TG_UINT,
TG_FLOAT,
TG_ENUM,
TG_TIME,
TG_STRING,
TG_SEQUENCE,
TG_ARRAY,
TG_STRUCT,
TG_UNION,
TG_TYPEDEF,
TG_PREDECL
};
struct tgtype {
char *name; /* or null if anonymous */
size_t size; /* size in memory, also discriminates between widths of prim types */
size_t align;
enum tgkind kind;
union tgtype_u {
struct tgtype_td {
struct tgtype *type;
} td;
struct tgtype_S {
unsigned n;
struct tgtype_Sms {
size_t off;
char *name;
struct tgtype *type;
} *ms;
} S;
struct tgtype_str {
unsigned maxn;
} str;
struct tgtype_seq {
unsigned maxn;
struct tgtype *type;
} seq;
struct tgtype_ary {
unsigned n;
struct tgtype *type;
} ary;
struct tgtype_e {
unsigned n;
struct tgtype_ems {
int v;
char *name;
} *ms;
} e;
struct tgtype_U {
struct tgtype *dtype;
size_t off;
unsigned n;
int msidxdef;
struct tgtype_Ums {
char *name;
struct tgtype *type;
} *ms;
unsigned nlab;
struct tgtype_lab {
uint64_t val;
int msidx;
} *labs;
} U;
} u;
};
struct dictnode {
struct dictnode *next;
const char *name; /* aliases type->name */
struct tgtype *type;
};
struct parse_context {
struct dictnode *dict;
char *nameprefix;
int depth;
};
struct parse_arg {
struct parse_context *context;
struct tgtype *type;
};
#if PRE_V6_5
typedef DDS_sequence_octet dds_seq_t;
#else
typedef struct DDS_sequence_s dds_seq_t;
#endif
static void init_lexer(struct token *tok, struct lexer *l, const char *src);
static enum tokenkind scantoken(struct token *tok, struct lexer *l);
static void freetoken(struct token *tok);
static int scanerror(struct token *tok, struct lexer *l, const char *fmt, ...);
static int casttoint(struct token *tok, struct lexer *l);
struct alignof_int16_t { char c; int16_t x; };
struct alignof_int32_t { char c; int32_t x; };
struct alignof_int64_t { char c; int64_t x; };
struct alignof_float { char c; float x; };
struct alignof_double { char c; double x; };
struct alignof_ptr { char c; void *x; };
struct alignof_dds_seq { char c; dds_seq_t x; };
#define alignof(t) offsetof (struct alignof_##t, x)
static const char *typekindstr(DDS_TypeElementKind kind)
{
switch (kind)
{
case DDS_TYPE_ELEMENT_KIND_MODULE: return "module";
case DDS_TYPE_ELEMENT_KIND_STRUCT: return "struct";
case DDS_TYPE_ELEMENT_KIND_MEMBER: return "member";
case DDS_TYPE_ELEMENT_KIND_UNION: return "union";
case DDS_TYPE_ELEMENT_KIND_UNIONCASE: return "unioncase";
case DDS_TYPE_ELEMENT_KIND_UNIONSWITCH: return "unionswitch";
case DDS_TYPE_ELEMENT_KIND_UNIONLABEL: return "unionlabel";
case DDS_TYPE_ELEMENT_KIND_TYPEDEF: return "typedef";
case DDS_TYPE_ELEMENT_KIND_ENUM: return "enum";
case DDS_TYPE_ELEMENT_KIND_ENUMLABEL: return "enumlabel";
case DDS_TYPE_ELEMENT_KIND_TYPE: return "type";
case DDS_TYPE_ELEMENT_KIND_ARRAY: return "array";
case DDS_TYPE_ELEMENT_KIND_SEQUENCE: return "sequence";
case DDS_TYPE_ELEMENT_KIND_STRING: return "string";
case DDS_TYPE_ELEMENT_KIND_CHAR: return "char";
case DDS_TYPE_ELEMENT_KIND_BOOLEAN: return "boolean";
case DDS_TYPE_ELEMENT_KIND_OCTET: return "octet";
case DDS_TYPE_ELEMENT_KIND_SHORT: return "short";
case DDS_TYPE_ELEMENT_KIND_USHORT: return "unsigned short";
case DDS_TYPE_ELEMENT_KIND_LONG: return "long";
case DDS_TYPE_ELEMENT_KIND_ULONG: return "unsigned long";
case DDS_TYPE_ELEMENT_KIND_LONGLONG: return "long long";
case DDS_TYPE_ELEMENT_KIND_ULONGLONG: return "unsigned long long";
case DDS_TYPE_ELEMENT_KIND_FLOAT: return "float";
case DDS_TYPE_ELEMENT_KIND_DOUBLE: return "double";
case DDS_TYPE_ELEMENT_KIND_TIME: return "time";
case DDS_TYPE_ELEMENT_KIND_UNIONLABELDEFAULT: return "unionlabeldefault";
#if HAVE_FORWARDDECLARATION
case DDS_TYPE_ELEMENT_KIND_FORWARDDECLARATION: return "forwarddeclaration";
#endif
}
return NULL;
}
const char *tgkindstr(enum tgkind kind)
{
switch (kind)
{
case TG_BOOLEAN: return "boolean";
case TG_CHAR: return "char";
case TG_INT: return "int";
case TG_UINT: return "uint";
case TG_FLOAT: return "float";
case TG_ENUM: return "enum";
case TG_TIME: return "time";
case TG_STRING: return "string";
case TG_SEQUENCE: return "sequence";
case TG_ARRAY: return "array";
case TG_STRUCT: return "struct";
case TG_UNION: return "union";
case TG_TYPEDEF: return "typedef";
case TG_PREDECL: return "predecl";
}
return "?";
}
static char *fullname(struct parse_arg *arg, const char *name)
{
if (name == NULL)
return NULL;
else
{
size_t sz = strlen(arg->context->nameprefix) + 2 + strlen(name) + 1;
char *x = malloc(sz);
(void) snprintf(x, sz, "%s::%s", arg->context->nameprefix, name);
return x;
}
}
static struct dictnode *lookupdictnode1(struct dictnode *dict, const char *name)
{
struct dictnode *n = dict;
while (n && strcmp(n->name, name) != 0)
n = n->next;
return n;
}
static struct dictnode *lookupdictnode(struct parse_arg *arg, const char *name)
{
if (strncmp(name, "::", 2) == 0)
return lookupdictnode1(arg->context->dict, name);
else
{
char *prefix = strdup(arg->context->nameprefix);
size_t sz = strlen(prefix) + 2 + strlen(name) + 1;
char *tmp = malloc(sz);
struct dictnode *n;
(void) snprintf(tmp, sz, "%s::%s", prefix, name);
while((n = lookupdictnode1(arg->context->dict, tmp)) == NULL && *prefix)
{
char *x = strrchr(prefix, ':');
assert(x > prefix && x[-1] == ':');
x[-1] = 0;
(void) snprintf(tmp, sz, "%s::%s", prefix, name);
}
free(prefix);
free(tmp);
return n;
}
}
static struct tgtype *lookupname(struct parse_arg *arg, const char *name)
{
struct dictnode *n;
if ((n = lookupdictnode (arg, name)) == NULL)
return NULL;
return n->type;
}
static void addtodict(struct parse_arg *arg, const char *name, struct tgtype *t)
{
if (name)
{
assert(t->name == NULL);
struct dictnode *n = lookupdictnode (arg, name);
if (n == NULL)
{
t->name = strdup(name);
n = malloc(sizeof(*n));
n->name = fullname(arg, name);
n->type = t;
n->next = arg->context->dict;
arg->context->dict = n;
}
else
{
assert (n->type->kind == TG_PREDECL);
*n->type = *t;
// leak
}
}
}
static void pushmodule(struct parse_arg *arg, const char *name)
{
size_t sz = strlen(arg->context->nameprefix) + 2 + strlen(name) + 1;
char *np = malloc(sz);
(void) snprintf(np, sz, "%s::%s", arg->context->nameprefix, name);
free(arg->context->nameprefix);
arg->context->nameprefix = np;
}
static void popmodule(struct parse_arg *arg)
{
char *x = strrchr(arg->context->nameprefix, ':');
assert(x > arg->context->nameprefix && x[-1] == ':');
x[-1] = 0;
}
static DDS_boolean parse_type_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs, DDS_TypeParserHandle handle __attribute__ ((unused)), void *varg);
static struct tgtype *newtgtype(enum tgkind kind, size_t sz /* 0 if still to be computed */, size_t align)
{
struct tgtype *t = malloc(sizeof (*t));
memset(t, 0, sizeof (*t));
t->kind = kind;
t->size = sz;
t->align = align;
return t;
}
static size_t alignup (size_t pos, size_t align)
{
assert((align & -align) == align);
return (pos + align - 1) & -align;
}
static struct tgtype *detypedef (const struct tgtype *t)
{
while (t->kind == TG_TYPEDEF)
t = t->u.td.type;
return (struct tgtype *) t;
}
static DDS_boolean parse_struct_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs __attribute__ ((unused)), DDS_TypeParserHandle handle, void *varg)
{
struct parse_arg *arg = varg;
struct parse_arg subarg = { .context = arg->context, .type = NULL };
struct tgtype *t = arg->type;
struct tgtype_S *ts = &t->u.S;
assert(kind == DDS_TYPE_ELEMENT_KIND_MEMBER);
ts->ms = realloc(ts->ms, ++ts->n * sizeof(*ts->ms));
arg->context->depth++;
(void) DDS_TypeSupport_walk_type_description(handle, parse_type_cb, &subarg);
arg->context->depth--;
assert(subarg.type != NULL);
ts->ms[ts->n-1].off = alignup (t->size, subarg.type->align);
ts->ms[ts->n-1].name = strdup(name);
ts->ms[ts->n-1].type = subarg.type;
t->size = ts->ms[ts->n-1].off + subarg.type->size;
if (t->align < subarg.type->align)
t->align = subarg.type->align;
return 1;
}
static DDS_boolean parse_enum_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs, DDS_TypeParserHandle handle __attribute__ ((unused)), void *varg)
{
struct parse_arg *arg = varg;
assert(kind == DDS_TYPE_ELEMENT_KIND_ENUMLABEL);
assert(attrs->_length == 1);
assert(attrs->_buffer[0].value._d == DDS_TYPE_ATTRIBUTE_KIND_NUMBER);
arg->type->u.e.ms = realloc(arg->type->u.e.ms, ++arg->type->u.e.n * sizeof(*arg->type->u.e.ms));
arg->type->u.e.ms[arg->type->u.e.n-1].v = attrs->_buffer[0].value._u.nvalue;
arg->type->u.e.ms[arg->type->u.e.n-1].name = strdup(name);
return 1;
}
static DDS_boolean parse_unioncase_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs, DDS_TypeParserHandle handle, void *varg)
{
struct parse_arg *arg = varg;
struct tgtype *t = arg->type;
struct tgtype_U *tu = &t->u.U;
switch (kind)
{
case DDS_TYPE_ELEMENT_KIND_UNIONLABELDEFAULT:
tu->msidxdef = (int) tu->n;
break;
case DDS_TYPE_ELEMENT_KIND_UNIONLABEL: {
unsigned i, j;
assert(tu->dtype != NULL); /* I think the discriminator type always is first, but I may be wrong ... */
tu->labs = realloc(tu->labs, ((unsigned) tu->nlab + attrs->_length) * sizeof(*tu->labs));
for (i = 0; i < attrs->_length; i++)
{
const DDS_TypeAttribute *a = &attrs->_buffer[i];
switch (a->value._d)
{
case DDS_TYPE_ATTRIBUTE_KIND_NUMBER:
tu->labs[tu->nlab].val = (uint64_t) a->value._u.nvalue;
break;
case DDS_TYPE_ATTRIBUTE_KIND_STRING:
if(tu->dtype->kind == TG_ENUM) {
for (j = 0; j < tu->dtype->u.e.n; j++)
if (strcmp(a->value._u.svalue, tu->dtype->u.e.ms[j].name) == 0)
break;
assert(j < tu->dtype->u.e.n);
tu->labs[tu->nlab].val = (uint64_t) tu->dtype->u.e.ms[j].v;
} else if(tu->dtype->kind == TG_BOOLEAN) {
if(strcmp(a->value._u.svalue, "False") == 0)
tu->labs[tu->nlab].val = 0;
else if(strcmp(a->value._u.svalue, "True") == 0)
tu->labs[tu->nlab].val = 1;
else
assert(0);
} else if(tu->dtype->kind == TG_CHAR) {
tu->labs[tu->nlab].val = (unsigned char) a->value._u.svalue[0];
} else {
assert(tu->dtype->kind == TG_INT || tu->dtype->kind == TG_UINT);
tu->labs[tu->nlab].val = strtoull(a->value._u.svalue, NULL, 10);
}
break;
}
tu->labs[tu->nlab].msidx = (int) tu->n;
tu->nlab++;
}
break;
}
default: {
struct parse_arg subarg = { .context = arg->context, .type = NULL };
(void) parse_type_cb(kind, name, attrs, handle, &subarg);
assert(subarg.type != NULL);
assert(tu->ms[tu->n].name != NULL);
tu->ms[tu->n].type = subarg.type;
t->align = alignup(t->align, subarg.type->align);
tu->off = alignup(tu->off, subarg.type->align);
if (t->size < alignup(tu->off + subarg.type->size, t->align))
t->size = alignup(tu->off + subarg.type->size, t->align);
break;
}
}
return 1;
}
static DDS_boolean parse_union_cb(DDS_TypeElementKind kind, const DDS_string name __attribute__ ((unused)), const DDS_TypeAttributeSeq *attrs __attribute__ ((unused)), DDS_TypeParserHandle handle, void *varg)
{
struct parse_arg *arg = varg;
struct tgtype *t = arg->type;
struct tgtype_U *tu = &t->u.U;
switch (kind)
{
case DDS_TYPE_ELEMENT_KIND_UNIONSWITCH: {
struct parse_arg subarg = { .context = arg->context, .type = NULL };
assert(tu->dtype == NULL);
arg->context->depth++;
(void) DDS_TypeSupport_walk_type_description(handle, parse_type_cb, &subarg);
arg->context->depth--;
assert(subarg.type != NULL);
tu->dtype = detypedef (subarg.type);
t->size = tu->off = tu->dtype->size;
t->align = tu->dtype->align;
break;
}
case DDS_TYPE_ELEMENT_KIND_UNIONCASE: {
tu->ms = realloc(tu->ms, (tu->n+1) * sizeof(*tu->ms));
memset(&tu->ms[tu->n], 0, sizeof(*tu->ms));
tu->ms[tu->n].name = strdup(name);
arg->context->depth++;
(void) DDS_TypeSupport_walk_type_description(handle, parse_unioncase_cb, arg);
arg->context->depth--;
assert(tu->ms[tu->n].type != NULL);
tu->n++;
break;
}
default:
assert(0);
}
return 1;
}
static DDS_boolean print_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs, DDS_TypeParserHandle handle, void *varg)
{
struct parse_arg *arg = varg;
unsigned i;
printf("%*.*s%s %s\n", 4*arg->context->depth, 4*arg->context->depth, " ", typekindstr(kind), name ? name : "(null)");
for (i = 0; i < attrs->_length; i++)
{
const DDS_TypeAttribute *a = &attrs->_buffer[i];
printf("%*.*s %s=", 4*arg->context->depth, 4*arg->context->depth, " ", a->name);
switch (a->value._d)
{
case DDS_TYPE_ATTRIBUTE_KIND_NUMBER:
printf("%d\n", a->value._u.nvalue);
break;
case DDS_TYPE_ATTRIBUTE_KIND_STRING:
printf("%s\n", a->value._u.svalue);
break;
}
}
arg->context->depth++;
(void) DDS_TypeSupport_walk_type_description(handle, print_cb, arg);
arg->context->depth--;
return 1;
}
static unsigned intattr_w_0_default(const DDS_TypeAttributeSeq *attrs, const char *name)
{
unsigned i;
for (i = 0; i < attrs->_length; i++)
{
const DDS_TypeAttribute *a = &attrs->_buffer[i];
if (strcmp(a->name, name) == 0)
{
assert(a->value._d == DDS_TYPE_ATTRIBUTE_KIND_NUMBER);
assert(a->value._u.nvalue >= 0);
return (unsigned) a->value._u.nvalue;
}
}
return 0;
}
static DDS_boolean parse_type_cb(DDS_TypeElementKind kind, const DDS_string name, const DDS_TypeAttributeSeq *attrs, DDS_TypeParserHandle handle, void *varg)
{
struct parse_arg *arg = varg;
arg->context->depth++;
switch (kind)
{
case DDS_TYPE_ELEMENT_KIND_MODULE:
{
struct parse_arg subarg = { .context = arg->context, .type = NULL };
pushmodule(arg, name);
(void) DDS_TypeSupport_walk_type_description(handle, parse_type_cb, &subarg);
popmodule(arg);
break;
}
case DDS_TYPE_ELEMENT_KIND_TYPEDEF:
{
struct parse_arg subarg = { .context = arg->context, .type = NULL };
struct tgtype *t;
(void) DDS_TypeSupport_walk_type_description(handle, parse_type_cb, &subarg);
t = newtgtype(TG_TYPEDEF, subarg.type->size, subarg.type->align);
t->u.td.type = subarg.type;
if (name) addtodict(arg, name, t);
break;
}
case DDS_TYPE_ELEMENT_KIND_TYPE:
arg->type = lookupname(arg, name);
assert(arg->type);
break;
#if HAVE_FORWARDDECLARATION
case DDS_TYPE_ELEMENT_KIND_FORWARDDECLARATION:
if (!lookupname (arg, name))
{
struct tgtype *t;
t = newtgtype (TG_PREDECL, 1, 1);
addtodict(arg, name, t);
}
break;
#endif
case DDS_TYPE_ELEMENT_KIND_STRUCT:
{
struct tgtype *t = newtgtype(TG_STRUCT, 0, 0);
struct parse_arg subarg = { .context = arg->context, .type = t };
(void) DDS_TypeSupport_walk_type_description(handle, parse_struct_cb, &subarg);
t->size = alignup(t->size, t->align);
if (name) addtodict(arg, name, t);
arg->type = t;
break;
}
case DDS_TYPE_ELEMENT_KIND_UNION:
{
struct tgtype *t = newtgtype(TG_UNION, 0, 0);
struct parse_arg subarg = { .context = arg->context, .type = t };
t->u.U.msidxdef = -1;
(void) DDS_TypeSupport_walk_type_description(handle, parse_union_cb, &subarg);
t->size = alignup(t->size, t->align);
if (name) addtodict(arg, name, t);
arg->type = t;
break;
}
case DDS_TYPE_ELEMENT_KIND_ARRAY:
case DDS_TYPE_ELEMENT_KIND_SEQUENCE:
{
unsigned n = intattr_w_0_default(attrs, "size");
int isseq = (kind == DDS_TYPE_ELEMENT_KIND_SEQUENCE || n == 0);
struct tgtype *t = newtgtype(isseq ? TG_SEQUENCE : TG_ARRAY, 0, 0);
struct parse_arg subarg = { .context = arg->context, .type = NULL };
(void) DDS_TypeSupport_walk_type_description(handle, parse_type_cb, &subarg);
assert(subarg.type);
if (isseq) {
t->u.seq.maxn = n;
t->u.seq.type = subarg.type;
t->size = sizeof (dds_seq_t);
t->align = alignof (dds_seq);
} else {
t->u.ary.type = subarg.type;
t->u.ary.n = n;
t->size = n * subarg.type->size;
t->align = subarg.type->align;
}
if (name) addtodict(arg, name, t);
arg->type = t;
break;
}
case DDS_TYPE_ELEMENT_KIND_ENUM:
{
struct tgtype *t = newtgtype(TG_ENUM, 4, alignof (int32_t));
struct parse_arg subarg = { .context = arg->context, .type = t };
(void) DDS_TypeSupport_walk_type_description(handle, parse_enum_cb, &subarg);
if (name) addtodict(arg, name, t);
arg->type = t;
break;
}
case DDS_TYPE_ELEMENT_KIND_BOOLEAN: arg->type = newtgtype(TG_BOOLEAN, 1, 1); break;
case DDS_TYPE_ELEMENT_KIND_CHAR: arg->type = newtgtype(TG_CHAR, 1, 1); break;
case DDS_TYPE_ELEMENT_KIND_OCTET: arg->type = newtgtype(TG_UINT, 1, 1); break;
case DDS_TYPE_ELEMENT_KIND_SHORT: arg->type = newtgtype(TG_INT, 2, alignof(int16_t)); break;
case DDS_TYPE_ELEMENT_KIND_USHORT: arg->type = newtgtype(TG_UINT, 2, alignof(int16_t)); break;
case DDS_TYPE_ELEMENT_KIND_LONG: arg->type = newtgtype(TG_INT, 4, alignof(int32_t)); break;
case DDS_TYPE_ELEMENT_KIND_ULONG: arg->type = newtgtype(TG_UINT, 4, alignof(int32_t)); break;
case DDS_TYPE_ELEMENT_KIND_LONGLONG: arg->type = newtgtype(TG_INT, 8, alignof(int64_t)); break;
case DDS_TYPE_ELEMENT_KIND_ULONGLONG: arg->type = newtgtype(TG_UINT, 8, alignof(int64_t)); break;
case DDS_TYPE_ELEMENT_KIND_FLOAT: arg->type = newtgtype(TG_FLOAT, 4, alignof(float)); break;
case DDS_TYPE_ELEMENT_KIND_DOUBLE: arg->type = newtgtype(TG_FLOAT, 8, alignof(double)); break;
case DDS_TYPE_ELEMENT_KIND_TIME: arg->type = newtgtype(TG_TIME, 8, alignof(int32_t)); break;
case DDS_TYPE_ELEMENT_KIND_STRING: arg->type = newtgtype(TG_STRING, sizeof(char *), alignof(ptr)); break;
default:
print_cb(kind, name, attrs, handle, arg);
break;
}
arg->context->depth--;
return 1;
}
static int lookupfield(const struct tgtype **ptype, size_t *poff, const struct tgtype *type, const char *name)
{
struct lexer l;
struct token tok;
enum tokenkind tk;
enum { SYMBOL = 1, DOTSYMBOL = 2, INDEX = 4 };
unsigned allowed = SYMBOL;
init_lexer(&tok, &l, name);
*poff = 0;
*ptype = detypedef(type);
while ((tk = scantoken(&tok, &l)) != TOK_ERROR && tk != TOK_EOF && *ptype != NULL) {
switch (tk) {
case TOK_DOT:
if (!(allowed & DOTSYMBOL))
return scanerror(&tok, &l, "'.' unexpected");
allowed = SYMBOL;
break;
case TOK_SYMBOL:
if (!(allowed & SYMBOL))
return scanerror(&tok, &l, "symbol unexpected");
else if ((*ptype)->kind != TG_STRUCT)
return scanerror(&tok, &l, "expected type to be a struct");
else {
const struct tgtype_S *ts = &(*ptype)->u.S;
const unsigned n = ts->n;
unsigned i;
for (i = 0; i < n; i++) {
if (strcmp(tok.val.str, ts->ms[i].name) == 0) {
*poff += ts->ms[i].off;
(*ptype) = detypedef(ts->ms[i].type);
break;
}
}
if (i == n) {
return scanerror(&tok, &l, "field not found in struct");
}
allowed = DOTSYMBOL | INDEX;
}
break;
case TOK_LBRACKET:
if (!(allowed & INDEX))
return scanerror(&tok, &l, "index unexpected");
else if ((*ptype)->kind != TG_ARRAY)
return scanerror(&tok, &l, "expected type to be an array");
else {
const struct tgtype_ary *ta = &(*ptype)->u.ary;
(void) scantoken(&tok, &l);
if (!casttoint(&tok, &l))
return scanerror(&tok, &l, "integer expected");
if (tok.val.ui > (unsigned) ta->n)
return scanerror(&tok, &l, "index out of bounds");
*poff += (size_t) tok.val.ui * ta->type->size;
(*ptype) = detypedef(ta->type);
if (scantoken(&tok, &l) != TOK_RBRACKET)
return scanerror(&tok, &l, "']' expected");
allowed = DOTSYMBOL | INDEX;
}
break;
default:
return scanerror(&tok, &l, "unexpected token");
}
}
if (*ptype == NULL) {
return scanerror(&tok, &l, "non-existent key");
} else if (tk != TOK_EOF || allowed == SYMBOL) {
return scanerror(&tok, &l, "junk at end of input");
} else switch ((*ptype)->kind) {
case TG_CHAR:
case TG_BOOLEAN:
case TG_INT:
case TG_UINT:
case TG_ENUM:
case TG_STRING:
break;
default:
return scanerror(&tok, &l, "not a valid key type");
}
freetoken(&tok);
return 1;
}
static char *get_metadescription(DDS_Topic dds_tp, char **typename, char **keylist)
{
char *md;
*typename = DDS_Topic_get_type_name(dds_tp);
if (strcmp(*typename, "kernelModule::v_participantInfo") == 0) {
DDS_free(*typename);
md = DDS_string_dup(mdParticipantBuiltinTopicData);
*keylist = DDS_string_dup("key[1],key[0]");
*typename = DDS_string_dup("DDS::ParticipantBuiltinTopicData");
} else if(strcmp(*typename, "kernelModule::v_publicationInfo") == 0) {
DDS_free(*typename);
md = DDS_string_dup(mdPublicationBuiltinTopicData);
*keylist = DDS_string_dup("key[1],key[0]");
*typename = DDS_string_dup("DDS::PublicationBuiltinTopicData");
} else if(strcmp(*typename, "kernelModule::v_subscriptionInfo") == 0) {
DDS_free(*typename);
md = DDS_string_dup(mdSubscriptionBuiltinTopicData);
*keylist = DDS_string_dup("key[1],key[0]");
*typename = DDS_string_dup("DDS::SubscriptionBuiltinTopicData");
} else if(strcmp(*typename, "kernelModule::v_topicInfo") == 0) {
DDS_free(*typename);
md = DDS_string_dup(mdTopicBuiltinTopicData);
*keylist = DDS_string_dup("key[1],key[0]");
*typename = DDS_string_dup("DDS::TopicBuiltinTopicData");
} else if(strcmp(*typename, "kernelModule::v_deliveryInfo") == 0) {
/* workaround for a bug */
md = DDS_Topic_get_metadescription(dds_tp);
*keylist = DDS_string_dup("");
} else {
*keylist = DDS_Topic_get_keylist(dds_tp);
md = DDS_Topic_get_metadescription(dds_tp);
}
return md;
}
struct tgtopic *tgnew(DDS_Topic dds_tp, int printtype)
{
DDS_ReturnCode_t result;
struct parse_context context = { .dict = NULL, .nameprefix = strdup(""), .depth = 0 };
struct parse_arg arg = { .context = &context, .type = NULL };
struct tgtopic *tp;
char *topicname;
char *typename;
char *keylist;
char *xs;
topicname = DDS_Topic_get_name(dds_tp);
xs = get_metadescription(dds_tp, &typename, &keylist);
if (printtype && (result = DDS_TypeSupport_parse_type_description(xs, print_cb, &arg)) != DDS_RETCODE_OK)
error("DDS_TypeSupport_parse_type_description: error %d (%s)\n", (int) result, dds_strerror(result));
if ((result = DDS_TypeSupport_parse_type_description(xs, parse_type_cb, &arg)) != DDS_RETCODE_OK)
error("DDS_TypeSupport_parse_type_description: error %d (%s)\n", (int) result, dds_strerror(result));
DDS_free(xs);
tp = malloc(sizeof(*tp));
tp->name = strdup(topicname);
if (arg.type)
tp->type = arg.type;
else
{
tp->type = lookupname(&arg, typename);
if (tp->type == NULL)
error("topic %s: can't find type %s\n", tp->name, typename);
}
tp->size = tp->type->size;
if (*keylist == 0)
{
tp->nkeys = 0;
tp->keys = NULL;
}
else
{
char *cursor, *key;
unsigned i = 0, n = 0;
cursor = keylist;
while (cursor)
{
n++;
cursor = strchr(cursor, ',');
if (cursor) cursor++;
}
tp->nkeys = n;
tp->keys = malloc(n * sizeof (*tp->keys));
cursor = keylist;
while ((key = strsep(&cursor, ",")) != NULL)
{
tp->keys[i].name = strdup(key);
if (!lookupfield(&tp->keys[i].type, &tp->keys[i].off, tp->type, key))
error("topic %s key %s not found\n", tp->name, key);
i++;
}
}
DDS_free(typename);
DDS_free(topicname);
DDS_free(keylist);
while (context.dict)
{
struct dictnode *n = context.dict;
context.dict = n->next;
free(n);
}
free(context.nameprefix);
return tp;
}
void tgfree(struct tgtopic *tp)
{
unsigned i;
for (i = 0; i < tp->nkeys; i++)
free(tp->keys[i].name);
/* FIXME: free tp->type */
free(tp->name);
free(tp->keys);
free(tp);
}
static uint64_t loaddisc(const struct tgtype *t, const char *data)
{
switch (t->kind) {
case TG_BOOLEAN:
return (uint64_t) *data;
case TG_INT:
switch (t->size) {
case 1: return (uint8_t) (*(int8_t *)data);
case 2: return (uint16_t) (*(int16_t *)data);
case 4: return (uint32_t) (*(int32_t *)data);
case 8: return (uint64_t) (*(int64_t *)data);
}
break;
case TG_UINT:
switch (t->size) {
case 1: return *(uint8_t *)data;
case 2: return *(uint16_t *)data;
case 4: return *(uint32_t *)data;
case 8: return *(uint64_t *)data;
}
break;
case TG_ENUM:
return *(uint32_t *)data;
default:
break;
}
assert(0);
return 0;
}
static void storedisc(char *dst, const struct tgtype *t, uint64_t v)
{
switch (t->kind) {
case TG_BOOLEAN:
*(char *)dst = (char) !!v;
break;
case TG_INT:
switch (t->size) {
case 1: *(int8_t *)dst = (int8_t) v; break;
case 2: *(int16_t *)dst = (int16_t) v; break;
case 4: *(int32_t *)dst = (int32_t) v; break;
case 8: *(int64_t *)dst = (int64_t) v; break;
default: assert(0);
}
break;
case TG_UINT:
switch (t->size) {
case 1: *(uint8_t *)dst = (uint8_t) v; break;
case 2: *(uint16_t *)dst = (uint16_t) v; break;
case 4: *(uint32_t *)dst = (uint32_t) v; break;
case 8: *(uint64_t *)dst = (uint64_t) v; break;
default: assert(0);
}
break;
case TG_ENUM:
*(uint32_t *)dst = (uint32_t) v;
break;
default:
assert(0);
}
}
void tgstring_init(struct tgstring *s, size_t chop)
{
s->size = 4096;
s->buf = malloc(s->size);
s->buf[0] = 0;
s->pos = 0;
s->chop = chop;
s->chopped = 0;
}
void tgstring_fini(struct tgstring *s)
{
free(s->buf);
tgstring_init(s, s->chop);
}
static int tgprintf(struct tgstring *s, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
static int tgprintf(struct tgstring *s, const char *fmt, ...)
{
int n;
va_list ap;
if (s->chopped)
return 0;
assert (s->pos < s->size);
va_start(ap, fmt);
n = vsnprintf(s->buf + s->pos, s->size - s->pos, fmt, ap);
va_end(ap);
while (n >= 0 && (size_t)n >= s->size - s->pos)
{
static size_t chunk = 4096-1;
s->size += ((size_t)n+1 + (chunk-1)) & ~(chunk-1);
s->buf = realloc(s->buf, s->size);
va_start(ap, fmt);
n = vsnprintf(s->buf + s->pos, s->size - s->pos, fmt, ap);
va_end(ap);
}
if (n > 0)
s->pos += (size_t)n;
assert(s->pos < s->size);
if (s->pos > s->chop)
{
s->pos = s->chop;
s->buf[s->chop] = 0;
s->chopped = 1;
}
return !s->chopped;
}
static int printchar(struct tgstring *s, int ch, int quote)
{
assert(ch >= 0);
if (ch == quote || ch == '\\')
return tgprintf(s, "\\%c", ch);
else if (isprint(ch))
return tgprintf(s, "%c", ch);
else
return tgprintf(s, "\\x%02x", ch);
}
static unsigned isprint_runlen (const unsigned char *s, unsigned n)
{
unsigned m;
for (m = 0; m < n && s[m] != '"' && s[m] != '\\' && isprint (s[m]); m++)
;
return m;
}
static int tgprint1(struct tgstring *s, const struct tgtype *t, const char *data, int indent, enum tgprint_mode mode)
{
const char *space = (mode == TGPM_DENSE) ? "" : " ";
const char *commaspace = (mode == TGPM_DENSE) ? "," : ", ";
switch (t->kind) {
case TG_PREDECL:
abort ();