-
Notifications
You must be signed in to change notification settings - Fork 43
/
DDSCodeTester.cpp
7852 lines (6774 loc) · 299 KB
/
DDSCodeTester.cpp
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
#include <iostream>
#include <memory>
#include <sstream>
#include <thread>
#include <fastcdr/Cdr.h>
#include <fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp>
#include <fastdds/dds/core/condition/GuardCondition.hpp>
#include <fastdds/dds/core/condition/WaitSet.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/dds/log/FileConsumer.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/log/OStreamConsumer.hpp>
#include <fastdds/dds/log/StdoutConsumer.hpp>
#include <fastdds/dds/log/StdoutErrConsumer.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/PublisherListener.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/subscriber/SubscriberListener.hpp>
#include <fastdds/dds/topic/qos/TopicQos.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/topic/TopicListener.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicData.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilder.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/utils.hpp>
#include <fastdds/rtps/attributes/ThreadSettings.hpp>
#include <fastdds/rtps/common/WriteParams.hpp>
#include <fastdds/rtps/history/IPayloadPool.hpp>
#include <fastdds/rtps/reader/ReaderDiscoveryStatus.hpp>
#include <fastdds/rtps/transport/ChainingTransport.hpp>
#include <fastdds/rtps/transport/ChainingTransportDescriptor.hpp>
#include <fastdds/rtps/transport/network/AllowedNetworkInterface.hpp>
#include <fastdds/rtps/transport/network/BlockedNetworkInterface.hpp>
#include <fastdds/rtps/transport/network/NetmaskFilterKind.hpp>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.hpp>
#include <fastdds/rtps/transport/TCPTransportDescriptor.hpp>
#include <fastdds/rtps/transport/TCPv4TransportDescriptor.hpp>
#include <fastdds/rtps/transport/TCPv6TransportDescriptor.hpp>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.hpp>
#include <fastdds/rtps/transport/UDPv6TransportDescriptor.hpp>
#include <fastdds/rtps/transport/NetworkBuffer.hpp>
#include <fastdds/statistics/dds/domain/DomainParticipant.hpp>
#include <fastdds/statistics/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/statistics/topic_names.hpp>
#include <fastdds/utils/IPLocator.hpp>
using namespace eprosima::fastdds::dds;
class CustomChainingTransportDescriptor : public eprosima::fastdds::rtps::ChainingTransportDescriptor
{
public:
CustomChainingTransportDescriptor(
std::shared_ptr<eprosima::fastdds::rtps::TransportDescriptorInterface> low_level)
: ChainingTransportDescriptor(low_level)
{
}
eprosima::fastdds::rtps::TransportInterface* create_transport() const override;
};
class HelloWorld
{
public:
void msg(
const std::string&)
{
}
std::string msg()
{
return "";
}
};
//CHAINING_TRANSPORT_OVERRIDE
class CustomChainingTransport : public eprosima::fastdds::rtps::ChainingTransport
{
public:
CustomChainingTransport(
const CustomChainingTransportDescriptor& descriptor)
: ChainingTransport(descriptor)
, descriptor_(descriptor)
{
}
eprosima::fastdds::rtps::TransportDescriptorInterface* get_configuration()
{
return &descriptor_;
}
bool send(
eprosima::fastdds::rtps::SenderResource* low_sender_resource,
const std::vector<eprosima::fastdds::rtps::NetworkBuffer>& buffers,
uint32_t total_bytes,
eprosima::fastdds::rtps::LocatorsIterator* destination_locators_begin,
eprosima::fastdds::rtps::LocatorsIterator* destination_locators_end,
const std::chrono::steady_clock::time_point& timeout) override
{
//
// Preprocess outcoming buffer.
//
// Call low level transport
return low_sender_resource->send(buffers, total_bytes, destination_locators_begin,
destination_locators_end, timeout);
}
void receive(
eprosima::fastdds::rtps::TransportReceiverInterface* next_receiver,
const eprosima::fastdds::rtps::octet* receive_buffer,
uint32_t receive_buffer_size,
const eprosima::fastdds::rtps::Locator_t& local_locator,
const eprosima::fastdds::rtps::Locator_t& remote_locator) override
{
//
// Preprocess incoming buffer.
//
// Call upper level
next_receiver->OnDataReceived(receive_buffer, receive_buffer_size, local_locator, remote_locator);
}
private:
CustomChainingTransportDescriptor descriptor_;
};
//!--
eprosima::fastdds::rtps::TransportInterface* CustomChainingTransportDescriptor::create_transport() const
{
return new CustomChainingTransport(*this);
}
//DDS_DOMAINPARTICIPANT_LISTENER_SPECIALIZATION
class CustomDomainParticipantListener : public DomainParticipantListener
{
public:
CustomDomainParticipantListener()
: DomainParticipantListener()
{
}
virtual ~CustomDomainParticipantListener()
{
}
void on_participant_discovery(
DomainParticipant* participant,
eprosima::fastdds::rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override
{
should_be_ignored = false;
if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT)
{
std::cout << "New participant discovered" << std::endl;
// The following line can be modified to evaluate whether the discovered participant should be ignored
// (usually based on fields present in the discovery information)
bool ignoring_condition = false;
if (ignoring_condition)
{
should_be_ignored = true; // Request the ignoring of the discovered participant
}
}
else if (status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT ||
status == eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT)
{
std::cout << "Participant lost" << std::endl;
}
}
#if HAVE_SECURITY
void onParticipantAuthentication(
DomainParticipant* participant,
eprosima::fastdds::rtps::ParticipantAuthenticationInfo&& info) override
{
if (info.status == eprosima::fastdds::rtps::ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT)
{
std::cout << "A participant was authorized" << std::endl;
}
else if (info.status == eprosima::fastdds::rtps::ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT)
{
std::cout << "A participant failed authorization" << std::endl;
}
}
#endif // if HAVE_SECURITY
void on_data_reader_discovery(
DomainParticipant* participant,
eprosima::fastdds::rtps::ReaderDiscoveryStatus reason,
const eprosima::fastdds::rtps::SubscriptionBuiltinTopicData& info,
bool& should_be_ignored) override
{
should_be_ignored = false;
if (reason == eprosima::fastdds::rtps::ReaderDiscoveryStatus::DISCOVERED_READER)
{
std::cout << "New datareader discovered" << std::endl;
// The following line can be modified to evaluate whether the discovered datareader should be ignored
// (usually based on fields present in the discovery information)
bool ignoring_condition = false;
if (ignoring_condition)
{
should_be_ignored = true; // Request the ignoring of the discovered datareader
}
}
else if (reason == eprosima::fastdds::rtps::ReaderDiscoveryStatus::REMOVED_READER)
{
std::cout << "Datareader lost" << std::endl;
}
}
void on_data_writer_discovery(
DomainParticipant* participant,
eprosima::fastdds::rtps::WriterDiscoveryStatus reason,
const eprosima::fastdds::dds::PublicationBuiltinTopicData& info,
bool& should_be_ignored) override
{
static_cast<void>(participant);
static_cast<void>(info);
should_be_ignored = false;
if (reason == eprosima::fastdds::rtps::WriterDiscoveryStatus::DISCOVERED_WRITER)
{
std::cout << "New datawriter discovered" << std::endl;
// The following line can be modified to evaluate whether the discovered datawriter should be ignored
// (usually based on fields present in the discovery information)
bool ignoring_condition = false;
if (ignoring_condition)
{
should_be_ignored = true; // Request the ignoring of the discovered datawriter
}
}
else if (reason == eprosima::fastdds::rtps::WriterDiscoveryStatus::REMOVED_WRITER)
{
std::cout << "Datawriter lost" << std::endl;
}
}
};
//!--
// Custom Payload pool example for documentation
class CustomPayloadPool : public eprosima::fastdds::rtps::IPayloadPool
{
public:
CustomPayloadPool() = default;
~CustomPayloadPool() = default;
bool get_payload(
unsigned int size,
eprosima::fastdds::rtps::SerializedPayload_t& payload)
{
return true;
}
bool get_payload(
const eprosima::fastdds::rtps::SerializedPayload_t& data,
eprosima::fastdds::rtps::SerializedPayload_t& payload)
{
return true;
}
bool release_payload(
eprosima::fastdds::rtps::SerializedPayload_t& payload)
{
return true;
}
};
//!--
void dds_domain_examples()
{
{
//DDS_LOAD_XML_PROFILE
// Load the XML with the profiles
DomainParticipantFactory::get_instance()->load_XML_profiles_file("profiles.xml");
// Profiles can now be used to create Entities
DomainParticipant* participant_with_profile =
DomainParticipantFactory::get_instance()->create_participant_with_profile(0, "participant_profile");
if (nullptr == participant_with_profile)
{
// Error
return;
}
//!--
}
{
//DDS_CREATE_DOMAINPARTICIPANT
// Create a DomainParticipant with default DomainParticipantQos and no Listener
// The value PARTICIPANT_QOS_DEFAULT is used to denote the default QoS.
DomainParticipant* participant_with_default_attributes =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant_with_default_attributes)
{
// Error
return;
}
// A custom DomainParticipantQos can be provided to the creation method
DomainParticipantQos custom_qos;
// Modify QoS attributes
// (...)
DomainParticipant* participant_with_custom_qos =
DomainParticipantFactory::get_instance()->create_participant(0, custom_qos);
if (nullptr == participant_with_custom_qos)
{
// Error
return;
}
// Create a DomainParticipant with default QoS and a custom Listener.
// CustomDomainParticipantListener inherits from DomainParticipantListener.
// The value PARTICIPANT_QOS_DEFAULT is used to denote the default QoS.
CustomDomainParticipantListener custom_listener;
DomainParticipant* participant_with_default_qos_and_custom_listener =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT,
&custom_listener);
if (nullptr == participant_with_default_qos_and_custom_listener)
{
// Error
return;
}
//!--
}
{
//DDS_CREATE_PROFILE_DOMAINPARTICIPANT
// First load the XML with the profiles
DomainParticipantFactory::get_instance()->load_XML_profiles_file("profiles.xml");
// Create a DomainParticipant using a profile and no Listener
DomainParticipant* participant_with_profile =
DomainParticipantFactory::get_instance()->create_participant_with_profile(0, "participant_profile");
if (nullptr == participant_with_profile)
{
// Error
return;
}
// Create a DomainParticipant using a profile and a custom Listener.
// CustomDomainParticipantListener inherits from DomainParticipantListener.
CustomDomainParticipantListener custom_listener;
DomainParticipant* participant_with_profile_and_custom_listener =
DomainParticipantFactory::get_instance()->create_participant_with_profile(0, "participant_profile",
&custom_listener);
if (nullptr == participant_with_profile_and_custom_listener)
{
// Error
return;
}
//!--
}
{
//DDS_CREATE_DOMAINPARTICIPANT_DEFAULT_PROFILE
// Create a DomainParticipant using the environment profile and no Listener
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile();
if (nullptr == participant)
{
// Error
return;
}
// Create a DomainParticipant using the environment profile and a custom Listener.
// CustomDomainParticipantListener inherits from DomainParticipantListener.
CustomDomainParticipantListener custom_listener;
DomainParticipant* participant_with_custom_listener =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile(
&custom_listener, StatusMask::none());
if (nullptr == participant_with_custom_listener)
{
// Error
return;
}
//!--
}
{
//DDS_CHANGE_DOMAINPARTICIPANTQOS
// Create a DomainParticipant with default DomainParticipantQos
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
// Error
return;
}
// Get the current QoS or create a new one from scratch
DomainParticipantQos qos = participant->get_qos();
// Modify QoS attributes
qos.entity_factory().autoenable_created_entities = false;
// Assign the new Qos to the object
participant->set_qos(qos);
//!--
}
{
//DDS_CHANGE_DOMAINPARTICIPANTEXTENDEDQOS
// Create a DomainParticipant with DomainParticipantExtendedQos from profile
DomainParticipantExtendedQos profile_extended_qos;
DomainParticipantFactory::get_instance()->get_participant_extended_qos_from_profile("participant_profile",
profile_extended_qos);
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(profile_extended_qos);
if (nullptr == participant)
{
// Error
return;
}
//!--
}
{
//DDS_CHANGE_DOMAINPARTICIPANTQOS_TO_DEFAULT
// Create a custom DomainParticipantQos
DomainParticipantQos custom_qos;
// Modify QoS attributes
// (...)
// Create a DomainParticipant with a custom DomainParticipantQos
DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, custom_qos);
if (nullptr == participant)
{
// Error
return;
}
// Set the QoS on the participant to the default
if (participant->set_qos(PARTICIPANT_QOS_DEFAULT) != RETCODE_OK)
{
// Error
return;
}
// The previous instruction is equivalent to the following:
if (participant->set_qos(DomainParticipantFactory::get_instance()->get_default_participant_qos())
!= RETCODE_OK)
{
// Error
return;
}
//!--
}
{
//DDS_DELETE_DOMAINPARTICIPANT
// Create a DomainParticipant
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
// Error
return;
}
// Use the DomainParticipant to communicate
// (...)
// Delete entities created by the DomainParticipant
if (participant->delete_contained_entities() != RETCODE_OK)
{
// DomainParticipant failed to delete the entities it created.
return;
}
// Delete the DomainParticipant
if (DomainParticipantFactory::get_instance()->delete_participant(participant) != RETCODE_OK)
{
// Error
return;
}
//!--
}
{
//DDS_CHANGE_DEFAULT_DOMAINPARTICIPANTQOS
// Get the current QoS or create a new one from scratch
DomainParticipantQos qos_type1 = DomainParticipantFactory::get_instance()->get_default_participant_qos();
// Modify QoS attributes
// (...)
// Set as the new default TopicQos
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(qos_type1) !=
RETCODE_OK)
{
// Error
return;
}
// Create a DomainParticipant with the new default DomainParticipantQos.
DomainParticipant* participant_with_qos_type1 =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant_with_qos_type1)
{
// Error
return;
}
// Get the current QoS or create a new one from scratch
DomainParticipantQos qos_type2;
// Modify QoS attributes
// (...)
// Set as the new default TopicQos
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(qos_type2) !=
RETCODE_OK)
{
// Error
return;
}
// Create a Topic with the new default TopicQos.
DomainParticipant* participant_with_qos_type2 =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant_with_qos_type2)
{
// Error
return;
}
// Resetting the default DomainParticipantQos to the original default constructed values
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(PARTICIPANT_QOS_DEFAULT)
!= RETCODE_OK)
{
// Error
return;
}
// The previous instruction is equivalent to the following
if (DomainParticipantFactory::get_instance()->set_default_participant_qos(DomainParticipantQos())
!= RETCODE_OK)
{
// Error
return;
}
//!--
}
{
//DDS_CHANGE_DOMAINPARTICIPANTFACTORYQOS
DomainParticipantFactoryQos qos;
// Setting autoenable_created_entities to true makes the created DomainParticipants
// to be enabled upon creation
qos.entity_factory().autoenable_created_entities = true;
if (DomainParticipantFactory::get_instance()->set_qos(qos) != RETCODE_OK)
{
// Error
return;
}
// Create a DomainParticipant with the new DomainParticipantFactoryQos.
// The returned DomainParticipant is already enabled
DomainParticipant* enabled_participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == enabled_participant)
{
// Error
return;
}
// Setting autoenable_created_entities to false makes the created DomainParticipants
// to be disabled upon creation
qos.entity_factory().autoenable_created_entities = false;
if (DomainParticipantFactory::get_instance()->set_qos(qos) != RETCODE_OK)
{
// Error
return;
}
// Create a DomainParticipant with the new DomainParticipantFactoryQos.
// The returned DomainParticipant is disabled and will need to be enabled explicitly
DomainParticipant* disabled_participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == disabled_participant)
{
// Error
return;
}
//!--
}
{
// DDS_SECURITY_AUTH_PLUGIN
DomainParticipantQos pqos;
// Activate DDS:Auth:PKI-DH plugin
pqos.properties().properties().emplace_back("dds.sec.auth.plugin",
"builtin.PKI-DH");
// Configure DDS:Auth:PKI-DH plugin
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://maincacert.pem");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://partcert.pem");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.identity_crl",
"file://crl.pem");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.private_key",
"file://partkey.pem");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.password",
"domainParticipantPassword");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.preferred_key_agreement",
"ECDH");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.transmit_algorithms_as_legacy",
"true");
//!--
}
{
// DDS_SECURITY_AUTH_HANDSHAKE_PROPS
DomainParticipantQos pqos;
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.max_handshake_requests",
"5");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.initial_handshake_resend_period",
"250");
pqos.properties().properties().emplace_back(
"dds.sec.auth.builtin.PKI-DH.handshake_resend_period_gain",
"1.5");
//!--
}
{
// DDS_SECURITY_ACCESS_CONTROL_PLUGIN
DomainParticipantQos pqos;
// Activate DDS:Access:Permissions plugin
pqos.properties().properties().emplace_back("dds.sec.access.plugin",
"builtin.Access-Permissions");
// Configure DDS:Access:Permissions plugin
pqos.properties().properties().emplace_back(
"dds.sec.access.builtin.Access-Permissions.permissions_ca",
"file://certs/maincacert.pem");
pqos.properties().properties().emplace_back(
"dds.sec.access.builtin.Access-Permissions.governance",
"file://certs/governance.smime");
pqos.properties().properties().emplace_back(
"dds.sec.access.builtin.Access-Permissions.permissions",
"file://certs/permissions.smime");
pqos.properties().properties().emplace_back(
"dds.sec.access.builtin.Access-Permissions.transmit_algorithms_as_legacy",
"true");
//!--
}
{
// DDS_SECURITY_CRYPTO_PLUGIN_DOMAINPARTICIPANT
DomainParticipantQos pqos;
// Activate DDS:Crypto:AES-GCM-GMAC plugin
pqos.properties().properties().emplace_back("dds.sec.crypto.plugin",
"builtin.AES-GCM-GMAC");
//!--
}
{
// DDS_SECURITY_LOGGING_PLUGIN
DomainParticipantQos pqos;
// Activate DDS:Logging:DDS_LogTopic plugin
pqos.properties().properties().emplace_back("dds.sec.log.plugin",
"builtin.DDS_LogTopic");
// Configure DDS:Logging:DDS_LogTopic plugin
pqos.properties().properties().emplace_back(
"dds.sec.log.builtin.DDS_LogTopic.logging_level",
"EMERGENCY_LEVEL");
pqos.properties().properties().emplace_back(
"dds.sec.log.builtin.DDS_LogTopic.log_file",
"myLogFile.log");
//!--
}
{
// FASTDDS_STATISTICS_MODULE
DomainParticipantQos pqos;
// Activate Fast DDS Statistics module
pqos.properties().properties().emplace_back("fastdds.statistics",
"HISTORY_LATENCY_TOPIC;ACKNACK_COUNT_TOPIC;DISCOVERY_TOPIC;PHYSICAL_DATA_TOPIC");
//!--
}
{
// FASTDDS_MONITOR_SERVICE_PROPERTY
DomainParticipantQos pqos;
// Enable Fast DDS Monitor Service through properties
pqos.properties().properties().emplace_back("fastdds.enable_monitor_service",
"true");
// Enable Fast DDS Monitor Service through statistics properties (other way)
pqos.properties().properties().emplace_back("fastdds.statistics",
"MONITOR_SERVICE_TOPIC");
DomainParticipant* participant_with_mon_srv = DomainParticipantFactory::get_instance()->create_participant(0,
pqos);
//!--
}
{
// FASTDDS_MONITOR_SERVICE_API
DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0,
PARTICIPANT_QOS_DEFAULT);
// Obtain pointer to child class
eprosima::fastdds::statistics::dds::DomainParticipant* statistics_participant =
eprosima::fastdds::statistics::dds::DomainParticipant::narrow(participant);
// Enable Fast DDS Monitor Service through API
statistics_participant->enable_monitor_service();
// Disable Fast DDS Monitor Service through API
statistics_participant->disable_monitor_service();
//!--
}
{
// FASTDDS_PHYSICAL_PROPERTIES
/* Create participant which announces default physical properties */
DomainParticipantQos pqos_default_physical;
// NOTE: If FASTDDS_STATISTICS is defined, then setting the properties to "" is not necessary
pqos_default_physical.properties().properties().emplace_back("fastdds.physical_data.host", "");
pqos_default_physical.properties().properties().emplace_back("fastdds.physical_data.user", "");
pqos_default_physical.properties().properties().emplace_back("fastdds.physical_data.process", "");
DomainParticipant* participant_with_physical = DomainParticipantFactory::get_instance()->create_participant(0,
pqos_default_physical);
/* Create participant which announces custom physical properties */
DomainParticipantQos pqos_custom_physical;
// NOTE: If FASTDDS_STATISTICS is defined, then clear the properties before setting them
// pqos_custom_physical.properties().properties().clear()
pqos_custom_physical.properties().properties().emplace_back("fastdds.physical_data.host", "custom_hostname");
pqos_custom_physical.properties().properties().emplace_back("fastdds.physical_data.user", "custom_username");
pqos_custom_physical.properties().properties().emplace_back("fastdds.physical_data.process", "custom_process");
DomainParticipant* participant_custom_physical = DomainParticipantFactory::get_instance()->create_participant(0,
pqos_custom_physical);
/* Create participant which does not announce physical properties */
DomainParticipantQos pqos_no_physical;
pqos_no_physical.properties().properties().clear();
DomainParticipant* participant_without_physical = DomainParticipantFactory::get_instance()->create_participant(
0, pqos_no_physical);
/* Load physical properties from default XML file */
DomainParticipantFactory::get_instance()->load_profiles();
DomainParticipantQos pqos_default_xml_physical =
DomainParticipantFactory::get_instance()->get_default_participant_qos();
DomainParticipant* participant_default_xml_physical =
DomainParticipantFactory::get_instance()->create_participant(0, pqos_default_xml_physical);
/* Load physical properties from specific XML file */
DomainParticipantFactory::get_instance()->load_XML_profiles_file("somefile.xml");
DomainParticipantFactory::get_instance()->load_profiles();
DomainParticipantQos pqos_custom_xml_physical =
DomainParticipantFactory::get_instance()->get_default_participant_qos();
DomainParticipant* participant_custom_xml_physical =
DomainParticipantFactory::get_instance()->create_participant(0, pqos_custom_xml_physical);
//!--
DomainParticipantFactory::get_instance()->delete_participant(participant_with_physical);
DomainParticipantFactory::get_instance()->delete_participant(participant_custom_physical);
DomainParticipantFactory::get_instance()->delete_participant(participant_without_physical);
DomainParticipantFactory::get_instance()->delete_participant(participant_default_xml_physical);
DomainParticipantFactory::get_instance()->delete_participant(participant_custom_xml_physical);
}
{
// ENABLE_DISABLE_STATISTICS_DATAWRITER
// Create a DomainParticipant
DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == participant)
{
// Error
return;
}
// Obtain pointer to child class
eprosima::fastdds::statistics::dds::DomainParticipant* statistics_participant =
eprosima::fastdds::statistics::dds::DomainParticipant::narrow(participant);
// Enable statistics DataWriter
if (statistics_participant->enable_statistics_datawriter(eprosima::fastdds::statistics::GAP_COUNT_TOPIC,
eprosima::fastdds::statistics::dds::STATISTICS_DATAWRITER_QOS) != RETCODE_OK)
{
// Error
return;
}
// Use the DomainParticipant to communicate
// (...)
// Disable statistics DataWriter
if (statistics_participant->disable_statistics_datawriter(eprosima::fastdds::statistics::GAP_COUNT_TOPIC) !=
RETCODE_OK)
{
// Error
return;
}
// Delete DomainParticipant
if (DomainParticipantFactory::get_instance()->delete_participant(participant) != RETCODE_OK)
{
// Error
return;
}
//!--
}
{
// PULL_MODE_DATAWRITER
DataWriterQos wqos;
// Enable pull mode
wqos.properties().properties().emplace_back(
"fastdds.push_mode",
"false");
//!--
}
{
//CONF-QOS-PARTITIONS
PublisherQos pub_11_qos;
pub_11_qos.partition().push_back("Partition_1");
pub_11_qos.partition().push_back("Partition_2");
PublisherQos pub_12_qos;
pub_12_qos.partition().push_back("*");
PublisherQos pub_21_qos;
//No partitions defined for pub_21
PublisherQos pub_22_qos;
pub_22_qos.partition().push_back("Partition*");
SubscriberQos subs_31_qos;
subs_31_qos.partition().push_back("Partition_1");
SubscriberQos subs_32_qos;
subs_32_qos.partition().push_back("Partition_2");
SubscriberQos subs_33_qos;
subs_33_qos.partition().push_back("Partition_3");
SubscriberQos subs_34_qos;
//No partitions defined for subs_34
//!--
}
{
// PARTITION-ON-ENDPOINT
DataWriterQos wqos;
// Add partitions
wqos.properties().properties().emplace_back(
"partitions",
"part1;part2");
DataReaderQos rqos;
// Add partitions
rqos.properties().properties().emplace_back(
"partitions",
"part1;part2");
//!--
}
{
//DDS-STATIC-DISCOVERY-FORMAT
DomainParticipantQos participant_qos;
participant_qos.properties().properties().emplace_back(
"dds.discovery.static_edp.exchange_format",
"v1_Reduced"
);
//!--
}
{
// IGNORE_LOCAL_ENDPOINTS_DOMAINPARTICIPANT
DomainParticipantQos participant_qos;
// Avoid local matching of this participant's endpoints
participant_qos.properties().properties().emplace_back(
"fastdds.ignore_local_endpoints",
"true");
//!--
}
{
//DDS-SHM-ENFORCE-META-TRAFFIC
DomainParticipantQos participant_qos;
// SHM transport will listen for unicast meta-traffic
participant_qos.properties().properties().emplace_back(
"fastdds.shm.enforce_metatraffic",
"unicast");
//!--
}
{
// MAX_MESSAGE_SIZE_PROPERTY_PARTICIPANT
DomainParticipantQos pqos;
// Set maximum number of bytes of the datagram to be sent
pqos.properties().properties().emplace_back(
"fastdds.max_message_size",
"1200");
//!--
}
{
// MAX_MESSAGE_SIZE_PROPERTY_WRITER
DataWriterQos wqos;
// Set maximum number of bytes of the datagram to be sent
wqos.properties().properties().emplace_back(
"fastdds.max_message_size",
"1200");
//!--
}
{
// TYPE_PROPAGATION_PROPERTY
DomainParticipantQos pqos;
pqos.properties().properties().emplace_back(
"fastdds.type_propagation",
"enabled");
//!--
}
}
//DOMAINPARTICIPANTLISTENER-DISCOVERY-CALLBACKS
class DiscoveryDomainParticipantListener : public DomainParticipantListener
{
/* Custom Callback on_participant_discovery */
void on_participant_discovery(
DomainParticipant* participant,
eprosima::fastdds::rtps::ParticipantDiscoveryStatus status,
const ParticipantBuiltinTopicData& info,
bool& should_be_ignored) override
{
should_be_ignored = false;
static_cast<void>(participant);
switch (status){
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT:
{
/* Process the case when a new DomainParticipant was found in the domain */
std::cout << "New DomainParticipant '" << info.participant_name <<
"' with ID '" << info.guid.entityId << "' and GuidPrefix '" <<
info.guid.guidPrefix << "' discovered." << std::endl;
/* The following line can be substituted to evaluate whether the discovered participant should be ignored */
bool ignoring_condition = false;
if (ignoring_condition)
{