diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 07eb00f15be..0e302bf89dd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,3 +23,7 @@ add_subdirectory(cpp/discovery_server) add_subdirectory(cpp/hello_world) add_subdirectory(cpp/rtps) add_subdirectory(cpp/xtypes) + +if (SECURITY) + add_subdirectory(cpp/security) +endif() diff --git a/examples/cpp/configuration/Application.hpp b/examples/cpp/configuration/Application.hpp index 67e2359d1c0..298867229b2 100644 --- a/examples/cpp/configuration/Application.hpp +++ b/examples/cpp/configuration/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONFIGURATION_APPLICATION_HPP_ -#define _FASTDDS_CONFIGURATION_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONFIGURATION__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_CONFIGURATION__APPLICATION_HPP #include @@ -52,4 +52,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CONFIGURATION_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CONFIGURATION__APPLICATION_HPP diff --git a/examples/cpp/configuration/CLIParser.hpp b/examples/cpp/configuration/CLIParser.hpp index a88d9999a89..676e20ae090 100644 --- a/examples/cpp/configuration/CLIParser.hpp +++ b/examples/cpp/configuration/CLIParser.hpp @@ -21,8 +21,8 @@ #include #include -#ifndef _FASTDDS_CONFIGURATION_CLI_PARSER_HPP_ -#define _FASTDDS_CONFIGURATION_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONFIGURATION__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_CONFIGURATION__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -1137,4 +1137,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_CONFIGURATION_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONFIGURATION__CLIPARSER_HPP diff --git a/examples/cpp/configuration/PublisherApp.cpp b/examples/cpp/configuration/PublisherApp.cpp index b5b3c7504a1..96ce454b0e4 100644 --- a/examples/cpp/configuration/PublisherApp.cpp +++ b/examples/cpp/configuration/PublisherApp.cpp @@ -35,6 +35,8 @@ #include #include +#include "ConfigurationPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/configuration/PublisherApp.hpp b/examples/cpp/configuration/PublisherApp.hpp index f7ab086e59f..ca5e28eecf9 100644 --- a/examples/cpp/configuration/PublisherApp.hpp +++ b/examples/cpp/configuration/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONFIGURATION_PUBLISHER_APP_HPP_ -#define _FASTDDS_CONFIGURATION_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONFIGURATION__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CONFIGURATION__PUBLISHERAPP_HPP #include @@ -29,7 +29,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "ConfigurationPubSubTypes.hpp" +#include "Configuration.hpp" using namespace eprosima::fastdds::dds; @@ -118,4 +118,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CONFIGURATION_PUBLISHER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CONFIGURATION__PUBLISHERAPP_HPP diff --git a/examples/cpp/configuration/SubscriberApp.hpp b/examples/cpp/configuration/SubscriberApp.hpp index e2bbfd049ca..b6d71ed198d 100644 --- a/examples/cpp/configuration/SubscriberApp.hpp +++ b/examples/cpp/configuration/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONFIGURATION_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_CONFIGURATION_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONFIGURATION__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CONFIGURATION__SUBSCRIBERAPP_HPP #include #include @@ -32,7 +32,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "ConfigurationPubSubTypes.hpp" +#include "Configuration.hpp" using namespace eprosima::fastdds::dds; @@ -123,4 +123,4 @@ class SubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CONFIGURATION_SUBSCRIBER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CONFIGURATION__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/content_filter/Application.hpp b/examples/cpp/content_filter/Application.hpp index ea70fb8766a..02c4ab9db5e 100644 --- a/examples/cpp/content_filter/Application.hpp +++ b/examples/cpp/content_filter/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONTENT_FILTER_APPLICATION_HPP_ -#define _FASTDDS_CONTENT_FILTER_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__APPLICATION_HPP #include @@ -53,4 +53,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CONTEN_FILTER_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__APPLICATION_HPP diff --git a/examples/cpp/content_filter/CLIParser.hpp b/examples/cpp/content_filter/CLIParser.hpp index 9e483a3ba20..291ce9a2d22 100644 --- a/examples/cpp/content_filter/CLIParser.hpp +++ b/examples/cpp/content_filter/CLIParser.hpp @@ -19,8 +19,8 @@ #include -#ifndef _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ -#define _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -465,4 +465,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CLIPARSER_HPP diff --git a/examples/cpp/content_filter/CustomContentFilter.hpp b/examples/cpp/content_filter/CustomContentFilter.hpp index 69ac5f49af6..ae63b9759f3 100644 --- a/examples/cpp/content_filter/CustomContentFilter.hpp +++ b/examples/cpp/content_filter/CustomContentFilter.hpp @@ -1,5 +1,5 @@ -#ifndef _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ -#define _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTER_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTER_HPP #include @@ -78,4 +78,4 @@ class CustomContentFilter : public eprosima::fastdds::dds::IContentFilter }; -#endif // _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTER_HPP diff --git a/examples/cpp/content_filter/CustomContentFilterFactory.hpp b/examples/cpp/content_filter/CustomContentFilterFactory.hpp index ea65f1394e5..aed72191c01 100644 --- a/examples/cpp/content_filter/CustomContentFilterFactory.hpp +++ b/examples/cpp/content_filter/CustomContentFilterFactory.hpp @@ -1,5 +1,5 @@ -#ifndef _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ -#define _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTERFACTORY_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTERFACTORY_HPP #include #include @@ -88,4 +88,4 @@ class CustomContentFilterFactory : public eprosima::fastdds::dds::IContentFilter } }; -#endif // _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__CUSTOMCONTENTFILTERFACTORY_HPP diff --git a/examples/cpp/content_filter/PublisherApp.cpp b/examples/cpp/content_filter/PublisherApp.cpp index c80d9d98f1e..22d23ff2370 100644 --- a/examples/cpp/content_filter/PublisherApp.cpp +++ b/examples/cpp/content_filter/PublisherApp.cpp @@ -31,6 +31,7 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" #include "HelloWorldTypeObjectSupport.hpp" namespace eprosima { diff --git a/examples/cpp/content_filter/PublisherApp.hpp b/examples/cpp/content_filter/PublisherApp.hpp index 614c978f26e..acc48d63885 100644 --- a/examples/cpp/content_filter/PublisherApp.hpp +++ b/examples/cpp/content_filter/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ -#define _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__PUBLISHERAPP_HPP #include @@ -28,7 +28,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; @@ -95,4 +95,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__PUBLISHERAPP_HPP diff --git a/examples/cpp/content_filter/SubscriberApp.cpp b/examples/cpp/content_filter/SubscriberApp.cpp index d61b43c3e63..9c3dc62cdf9 100644 --- a/examples/cpp/content_filter/SubscriberApp.cpp +++ b/examples/cpp/content_filter/SubscriberApp.cpp @@ -31,6 +31,7 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" #include "HelloWorldTypeObjectSupport.hpp" namespace eprosima { diff --git a/examples/cpp/content_filter/SubscriberApp.hpp b/examples/cpp/content_filter/SubscriberApp.hpp index b2a240700f6..256864bead4 100644 --- a/examples/cpp/content_filter/SubscriberApp.hpp +++ b/examples/cpp/content_filter/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__SUBSCRIBERAPP_HPP #include #include @@ -35,8 +35,8 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" #include "CustomContentFilterFactory.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; namespace eprosima { @@ -107,4 +107,4 @@ class SubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CONTENT_FILTER__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/custom_payload_pool/Application.hpp b/examples/cpp/custom_payload_pool/Application.hpp index 3a78297c964..fb47bf6810b 100644 --- a/examples/cpp/custom_payload_pool/Application.hpp +++ b/examples/cpp/custom_payload_pool/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_APPLICATION_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__APPLICATION_HPP #include @@ -53,4 +53,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__APPLICATION_HPP diff --git a/examples/cpp/custom_payload_pool/CLIParser.hpp b/examples/cpp/custom_payload_pool/CLIParser.hpp index 42c81d781e5..1ad01dc6288 100644 --- a/examples/cpp/custom_payload_pool/CLIParser.hpp +++ b/examples/cpp/custom_payload_pool/CLIParser.hpp @@ -18,8 +18,8 @@ #include -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_CLI_PARSER_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -329,4 +329,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_CUSTOM_PAYLOAD_POOL_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CLIPARSER_HPP diff --git a/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp b/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp index 221c0eb4b00..22dd6a92cdb 100644 --- a/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp +++ b/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp @@ -16,8 +16,8 @@ * @file CustomPayloadPool.hpp */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CUSTOMPAYLOADPOOL_HPP +#define FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CUSTOMPAYLOADPOOL_HPP #include #include @@ -97,4 +97,4 @@ class CustomPayloadPool : public eprosima::fastdds::rtps::IPayloadPool }; -#endif // _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__CUSTOMPAYLOADPOOL_HPP diff --git a/examples/cpp/custom_payload_pool/PublisherApp.cpp b/examples/cpp/custom_payload_pool/PublisherApp.cpp index 69c0b21aa65..8353c5b3f8d 100644 --- a/examples/cpp/custom_payload_pool/PublisherApp.cpp +++ b/examples/cpp/custom_payload_pool/PublisherApp.cpp @@ -28,6 +28,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/custom_payload_pool/PublisherApp.hpp b/examples/cpp/custom_payload_pool/PublisherApp.hpp index 8c57893c643..3dd31206bc9 100644 --- a/examples/cpp/custom_payload_pool/PublisherApp.hpp +++ b/examples/cpp/custom_payload_pool/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__PUBLISHERAPP_HPP #include #include @@ -30,7 +30,7 @@ #include "Application.hpp" #include "CLIParser.hpp" #include "CustomPayloadPool.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; @@ -103,4 +103,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__PUBLISHERAPP_HPP diff --git a/examples/cpp/custom_payload_pool/SubscriberApp.cpp b/examples/cpp/custom_payload_pool/SubscriberApp.cpp index 9bd398cffc8..0372b6fa641 100644 --- a/examples/cpp/custom_payload_pool/SubscriberApp.cpp +++ b/examples/cpp/custom_payload_pool/SubscriberApp.cpp @@ -30,6 +30,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { diff --git a/examples/cpp/custom_payload_pool/SubscriberApp.hpp b/examples/cpp/custom_payload_pool/SubscriberApp.hpp index f83483b9089..9dc13fa16f3 100644 --- a/examples/cpp/custom_payload_pool/SubscriberApp.hpp +++ b/examples/cpp/custom_payload_pool/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__SUBSCRIBERAPP_HPP #include #include @@ -31,7 +31,7 @@ #include "Application.hpp" #include "CLIParser.hpp" #include "CustomPayloadPool.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; namespace eprosima { @@ -101,4 +101,4 @@ class SubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_CUSTOM_PAYLOAD_POOL__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/dds/CMakeLists.txt b/examples/cpp/dds/CMakeLists.txt index 32ea44c1f70..19f83e1edea 100644 --- a/examples/cpp/dds/CMakeLists.txt +++ b/examples/cpp/dds/CMakeLists.txt @@ -22,7 +22,3 @@ add_subdirectory(RequestReplyExample) add_subdirectory(StaticHelloWorldExample) add_subdirectory(WriterLoansExample) add_subdirectory(ZeroCopyExample) - -if(SECURITY) - add_subdirectory(SecureHelloWorldExample) -endif() diff --git a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldPublisher.h b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldPublisher.h index 03f734e35aa..190b3e28b95 100644 --- a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldPublisher.h +++ b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldPublisher.h @@ -17,11 +17,10 @@ * */ -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H #include - #include #include @@ -90,4 +89,4 @@ class HelloWorldPublisher -#endif /* HELLOWORLDPUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H diff --git a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.h b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.h index 447d8685e9f..21ad956f5ae 100644 --- a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.h +++ b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.h @@ -17,8 +17,8 @@ * */ -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H #include #include @@ -112,4 +112,4 @@ class HelloWorldSubscriber }; -#endif /* HELLOWORLDSUBSCRIBER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_DYNAMIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H diff --git a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorld_main.cpp b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorld_main.cpp index 582908edb44..6f28f7e5d64 100644 --- a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorld_main.cpp +++ b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorld_main.cpp @@ -17,11 +17,11 @@ * */ +#include + #include "HelloWorldPublisher.h" #include "HelloWorldSubscriber.h" -#include - using eprosima::fastdds::dds::Log; int main( diff --git a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.cpp b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.cpp index 24b6a033e9e..354ca892290 100644 --- a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.cpp +++ b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.cpp @@ -27,6 +27,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; HelloWorldPublisher::HelloWorldPublisher() diff --git a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.h b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.h index 0d2fb051fa0..9b5e4f3135d 100644 --- a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.h +++ b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldPublisher.h @@ -17,15 +17,14 @@ * */ -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDPUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDPUBLISHER_H #include #include #include +#include "HelloWorld.hpp" class HelloWorldPublisher { public: @@ -93,4 +92,4 @@ class HelloWorldPublisher -#endif /* HELLOWORLDPUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDPUBLISHER_H diff --git a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp index 690cdfdab64..aa47451609b 100644 --- a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp @@ -28,6 +28,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; HelloWorldSubscriber::HelloWorldSubscriber() diff --git a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.h b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.h index 719c08a6be6..2aab6e8191a 100644 --- a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.h +++ b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.h @@ -17,15 +17,15 @@ * */ -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDSUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDSUBSCRIBER_H #include #include #include #include -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" class HelloWorldSubscriber { @@ -87,4 +87,4 @@ class HelloWorldSubscriber listener_; }; -#endif /* HELLOWORLDSUBSCRIBER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_DATA_SHARING__HELLOWORLDSUBSCRIBER_H diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.cpp b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.cpp index 3715765847f..3a538254980 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.cpp +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.cpp @@ -19,11 +19,13 @@ #include "HelloWorldPublisher.h" +#include + #include #include #include -#include +#include "HelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.h b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.h index 71a55ef8837..0737504e980 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.h +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldPublisher.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDPUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDPUBLISHER_H #include #include @@ -97,4 +95,4 @@ class HelloWorldPublisher eprosima::fastdds::dds::TypeSupport type_; }; -#endif /* HELLOWORLDPUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDPUBLISHER_H diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp index ba580eb12da..d10208fcb27 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp @@ -27,6 +27,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.h b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.h index 4dfeadd6a5e..70e5fee145b 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.h +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDSUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDSUBSCRIBER_H #include #include @@ -93,4 +91,4 @@ class HelloWorldSubscriber listener_; }; -#endif /* HELLOWORLDSUBSCRIBER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_SHARED_MEM__HELLOWORLDSUBSCRIBER_H diff --git a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.cpp b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.cpp index 315af25244a..a0b8425fbe6 100644 --- a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.cpp +++ b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.cpp @@ -18,11 +18,14 @@ */ #include "HelloWorldPublisher.h" + +#include + #include #include #include -#include +#include "HelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.h b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.h index d719ad13b97..915ead5e66d 100644 --- a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.h +++ b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldPublisher.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDPUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDPUBLISHER_H #include #include @@ -102,4 +100,4 @@ class HelloWorldPublisher -#endif /* HELLOWORLDPUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDPUBLISHER_H diff --git a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp index 90fbac5eab6..e7bfbb6f5b2 100644 --- a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp @@ -27,6 +27,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; diff --git a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.h b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.h index 1d488371131..30435da8ced 100644 --- a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.h +++ b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDSUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDSUBSCRIBER_H #include #include @@ -95,4 +93,4 @@ class HelloWorldSubscriber uint32_t number); }; -#endif /* HELLOWORLDSUBSCRIBER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_HELLO_WORLD_EXAMPLE_TCP__HELLOWORLDSUBSCRIBER_H diff --git a/examples/cpp/dds/RequestReplyExample/CalculatorClient.cpp b/examples/cpp/dds/RequestReplyExample/CalculatorClient.cpp index aaa3ca1df24..84d4334d519 100644 --- a/examples/cpp/dds/RequestReplyExample/CalculatorClient.cpp +++ b/examples/cpp/dds/RequestReplyExample/CalculatorClient.cpp @@ -16,8 +16,6 @@ #include #include -#include "CalculatorPubSubTypes.hpp" - #include #include #include @@ -27,6 +25,8 @@ #include #include +#include "CalculatorPubSubTypes.hpp" + class CalculatorClient { class Listener : public eprosima::fastdds::dds::DataReaderListener diff --git a/examples/cpp/dds/RequestReplyExample/CalculatorServer.cpp b/examples/cpp/dds/RequestReplyExample/CalculatorServer.cpp index c8ba52d1359..a7ee65d9e5e 100644 --- a/examples/cpp/dds/RequestReplyExample/CalculatorServer.cpp +++ b/examples/cpp/dds/RequestReplyExample/CalculatorServer.cpp @@ -16,8 +16,6 @@ #include #include -#include "CalculatorPubSubTypes.hpp" - #include #include #include @@ -27,6 +25,8 @@ #include #include +#include "CalculatorPubSubTypes.hpp" + class CalculatorServer { class Listener : public eprosima::fastdds::dds::DataReaderListener diff --git a/examples/cpp/dds/SecureHelloWorldExample/.gitignore b/examples/cpp/dds/SecureHelloWorldExample/.gitignore deleted file mode 100644 index ffc5570a9c3..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin -output diff --git a/examples/cpp/dds/SecureHelloWorldExample/CMakeLists.txt b/examples/cpp/dds/SecureHelloWorldExample/CMakeLists.txt deleted file mode 100644 index 237263af779..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# 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. - -cmake_minimum_required(VERSION 3.20) - -project(SecureHelloWorldExample VERSION 1 LANGUAGES CXX) - -# Find requirements -if(NOT fastcdr_FOUND) - find_package(fastcdr 2 REQUIRED) -endif() - -if(NOT foonathan_memory_FOUND) - find_package(foonathan_memory REQUIRED) -endif() - -if(NOT fastdds_FOUND) - find_package(fastdds 3 REQUIRED) -endif() - -#Check C++11 -include(CheckCXXCompilerFlag) -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) - if(NOT SUPPORTS_CXX11) - message(FATAL_ERROR "Compiler doesn't support C++11") - endif() -endif() - -message(STATUS "Configuring DDSSecureHelloWorld example...") -file(GLOB DDS_SECURE_HELLOWORLD_EXAMPLE_SOURCES_CXX "*.cxx") -file(GLOB DDS_SECURE_HELLOWORLD_EXAMPLE_SOURCES_CPP "*.cpp") - -add_executable(DDSSecureHelloWorldExample ${DDS_SECURE_HELLOWORLD_EXAMPLE_SOURCES_CXX} ${DDS_SECURE_HELLOWORLD_EXAMPLE_SOURCES_CPP}) -target_compile_definitions(DDSSecureHelloWorldExample PRIVATE - $<$>,$>:__DEBUG> - $<$:__INTERNALDEBUG> # Internal debug activated. - ) -target_include_directories(DDSSecureHelloWorldExample PRIVATE) -target_link_libraries(DDSSecureHelloWorldExample fastdds fastcdr foonathan_memory) -install(TARGETS DDSSecureHelloWorldExample - RUNTIME DESTINATION examples/cpp/dds/SecureHelloWorldExample/${BIN_INSTALL_DIR}) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/certs - DESTINATION examples/cpp/dds/SecureHelloWorldExample/${BIN_INSTALL_DIR}) - -add_custom_command(TARGET DDSSecureHelloWorldExample POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${PROJECT_SOURCE_DIR}/certs - ${PROJECT_BINARY_DIR}/certs) diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.cpp b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.cpp deleted file mode 100644 index cdeb0036204..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// 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. - -/** - * @file HelloWorldPublisher.cpp - * - */ - -#include "HelloWorldPublisher.h" -#include -#include - -using namespace eprosima::fastdds::dds; - -HelloWorldPublisher::HelloWorldPublisher() - : participant_(nullptr) - , publisher_(nullptr) - , topic_(nullptr) - , writer_(nullptr) - , type_(new HelloWorldPubSubType()) -{ -} - -bool HelloWorldPublisher::init() -{ - hello_.index(0); - hello_.message("HelloWorld"); - - //CREATE THE PARTICIPANT - DomainParticipantQos pqos; - pqos.properties().properties().emplace_back("dds.sec.auth.plugin", - "builtin.PKI-DH"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca", - "file://certs/maincacert.pem"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate", - "file://certs/mainpubcert.pem"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key", - "file://certs/mainpubkey.pem"); - pqos.properties().properties().emplace_back("dds.sec.access.plugin", - "builtin.Access-Permissions"); - 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.crypto.plugin", - "builtin.AES-GCM-GMAC"); - - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos); - - if (participant_ == nullptr) - { - return false; - } - - //REGISTER THE TYPE - type_.register_type(participant_); - - //CREATE THE PUBLISHER - publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT); - - if (publisher_ == nullptr) - { - return false; - } - - //CREATE THE TOPIC - topic_ = participant_->create_topic("HelloWorldTopic", "HelloWorld", TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - //CREATE THE DATAWRITER - DataWriterQos wqos; - wqos.reliability().kind = RELIABLE_RELIABILITY_QOS; - wqos.history().kind = KEEP_LAST_HISTORY_QOS; - wqos.history().depth = 20; - wqos.resource_limits().max_samples = 50; - wqos.resource_limits().max_samples_per_instance = 20; - wqos.reliable_writer_qos().times.heartbeat_period.seconds = 2; - wqos.reliable_writer_qos().times.heartbeat_period.nanosec = 200 * 1000 * 1000; - writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); - - if (writer_ == nullptr) - { - return false; - } - - return true; - -} - -HelloWorldPublisher::~HelloWorldPublisher() -{ - if (writer_ != nullptr) - { - publisher_->delete_datawriter(writer_); - } - if (publisher_ != nullptr) - { - participant_->delete_publisher(publisher_); - } - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - DomainParticipantFactory::get_instance()->delete_participant(participant_); -} - -void HelloWorldPublisher::PubListener::on_publication_matched( - eprosima::fastdds::dds::DataWriter*, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) -{ - if (info.current_count_change == 1) - { - matched_ = info.total_count; - first_connected_ = true; - std::cout << "Publisher matched." << std::endl; - } - else if (info.current_count_change == -1) - { - matched_ = info.total_count; - std::cout << "Publisher unmatched." << std::endl; - } - else - { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; - } -} - -void HelloWorldPublisher::run( - uint32_t samples) -{ - for (uint32_t i = 0; i < samples; ++i) - { - if (!publish()) - { - --i; - } - else - { - std::cout << "Message: " << hello_.message() << " with index: " << hello_.index() << " SENT" << std::endl; - } - } -} - -bool HelloWorldPublisher::publish() -{ - if (listener_.matched_ > 0 || listener_.first_connected_) - { - hello_.index(hello_.index() + 1); - writer_->write(&hello_); - return true; - } - return false; -} diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.h b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.h deleted file mode 100644 index e6a6319826a..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPublisher.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// 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. - -/** - * @file HelloWorldPublisher.h - * - */ - -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ - -#include "HelloWorldPubSubTypes.hpp" - -#include -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - -class HelloWorldPublisher -{ -public: - - HelloWorldPublisher(); - - virtual ~HelloWorldPublisher(); - - //!Initialize - bool init(); - - //!Publish a sample - bool publish(); - - //!Run for number samples - void run( - uint32_t number); - -private: - - HelloWorld hello_; - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Publisher* publisher_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataWriter* writer_; - - class PubListener : public eprosima::fastdds::dds::DataWriterListener - { - public: - - PubListener() - : matched_(0) - , first_connected_(false) - { - } - - ~PubListener() override - { - } - - void on_publication_matched( - eprosima::fastdds::dds::DataWriter* writer, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; - - int matched_; - - bool first_connected_; - } - listener_; - - eprosima::fastdds::dds::TypeSupport type_; -}; - - - -#endif /* HELLOWORLDPUBLISHER_H_ */ diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp deleted file mode 100644 index 5d505897f4d..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// 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. - -/** - * @file HelloWorldSubscriber.cpp - * - */ - -#include "HelloWorldSubscriber.h" - -#include -#include - -#include -#include - -using namespace eprosima::fastdds::dds; - -HelloWorldSubscriber::HelloWorldSubscriber() - : participant_(nullptr) - , subscriber_(nullptr) - , topic_(nullptr) - , reader_(nullptr) - , type_(new HelloWorldPubSubType()) -{ -} - -bool HelloWorldSubscriber::init() -{ - //CREATE THE PARTICIPANT - DomainParticipantQos pqos; - - pqos.properties().properties().emplace_back("dds.sec.auth.plugin", - "builtin.PKI-DH"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca", - "file://certs/maincacert.pem"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate", - "file://certs/mainsubcert.pem"); - pqos.properties().properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key", - "file://certs/mainsubkey.pem"); - pqos.properties().properties().emplace_back("dds.sec.access.plugin", - "builtin.Access-Permissions"); - 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.crypto.plugin", - "builtin.AES-GCM-GMAC"); - - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos); - - if (participant_ == nullptr) - { - return false; - } - - //REGISTER THE TYPE - type_.register_type(participant_); - - //CREATE THE SUBSCRIBER - subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT); - - if (subscriber_ == nullptr) - { - return false; - } - - //CREATE THE TOPIC - topic_ = participant_->create_topic("HelloWorldTopic", "HelloWorld", TOPIC_QOS_DEFAULT); - //CREATE THE DATAREADER - DataReaderQos rqos; - rqos.history().kind = KEEP_LAST_HISTORY_QOS; - rqos.history().depth = 30; - rqos.resource_limits().max_samples = 50; - rqos.resource_limits().allocated_samples = 20; - rqos.reliability().kind = RELIABLE_RELIABILITY_QOS; - - reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); - - if (reader_ == nullptr) - { - return false; - } - - return true; -} - -HelloWorldSubscriber::~HelloWorldSubscriber() -{ - if (reader_ != nullptr) - { - subscriber_->delete_datareader(reader_); - } - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - if (subscriber_ != nullptr) - { - participant_->delete_subscriber(subscriber_); - } - DomainParticipantFactory::get_instance()->delete_participant(participant_); -} - -void HelloWorldSubscriber::SubListener::on_subscription_matched( - DataReader*, - const SubscriptionMatchedStatus& info) -{ - if (info.current_count_change == 1) - { - matched_ = info.total_count; - std::cout << "Subscriber matched." << std::endl; - } - else if (info.current_count_change == -1) - { - matched_ = info.total_count; - std::cout << "Subscriber unmatched." << std::endl; - } - else - { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; - } -} - -void HelloWorldSubscriber::SubListener::on_data_available( - DataReader* reader) -{ - SampleInfo info; - if (reader->take_next_sample(&hello_, &info) == RETCODE_OK) - { - if (info.instance_state == ALIVE_INSTANCE_STATE) - { - samples_++; - // Print your structure data here. - std::cout << "Message " << hello_.message() << " " << hello_.index() << " RECEIVED" << std::endl; - } - } -} - -void HelloWorldSubscriber::run() -{ - std::cout << "Subscriber running. Please press enter to stop the Subscriber" << std::endl; - std::cin.ignore(); -} - -void HelloWorldSubscriber::run( - uint32_t number) -{ - std::cout << "Subscriber running until " << number << "samples have been received" << std::endl; - while (number < this->listener_.samples_) - { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } -} diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.h b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.h deleted file mode 100644 index e189e33fe0d..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// 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. - -/** - * @file HelloWorldSubscriber.h - * - */ - -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ - -#include "HelloWorldPubSubTypes.hpp" - -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - -class HelloWorldSubscriber -{ -public: - - HelloWorldSubscriber(); - - virtual ~HelloWorldSubscriber(); - - //!Initialize the subscriber - bool init(); - - //!RUN the subscriber - void run(); - - //!Run the subscriber until number samples have been received. - void run( - uint32_t number); - -private: - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Subscriber* subscriber_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataReader* reader_; - - eprosima::fastdds::dds::TypeSupport type_; - -public: - - class SubListener : public eprosima::fastdds::dds::DataReaderListener - { - public: - - SubListener() - : matched_(0) - , samples_(0) - { - } - - ~SubListener() override - { - } - - void on_data_available( - eprosima::fastdds::dds::DataReader* reader) override; - - void on_subscription_matched( - eprosima::fastdds::dds::DataReader* reader, - const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override; - - HelloWorld hello_; - - int matched_; - - uint32_t samples_; - - } - listener_; - -}; - -#endif /* HELLOWORLDSUBSCRIBER_H_ */ diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorld_main.cpp b/examples/cpp/dds/SecureHelloWorldExample/HelloWorld_main.cpp deleted file mode 100644 index 91394aad3ee..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorld_main.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// 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. - -/** - * @file HelloWorld_main.cpp - * - */ - -#include - -#include "HelloWorldPublisher.h" -#include "HelloWorldSubscriber.h" - -using namespace eprosima; -using namespace fastdds; -using namespace rtps; -using namespace eprosima::fastdds::dds; - -int main( - int argc, - char** argv) -{ - std::cout << "Starting " << std::endl; - int type = 1; - if (argc > 1) - { - if (strcmp(argv[1], "publisher") == 0) - { - type = 1; - } - else if (strcmp(argv[1], "subscriber") == 0) - { - type = 2; - } - } - else - { - std::cout << "publisher OR subscriber argument needed" << std::endl; - Log::Reset(); - return 0; - } - - switch (type) - { - case 1: - { - HelloWorldPublisher mypub; - if (mypub.init()) - { - mypub.run(10); - } - break; - } - case 2: - { - HelloWorldSubscriber mysub; - if (mysub.init()) - { - mysub.run(); - } - break; - } - } - Log::Reset(); - return 0; -} diff --git a/examples/cpp/dds/SecureHelloWorldExample/README.txt b/examples/cpp/dds/SecureHelloWorldExample/README.txt deleted file mode 100644 index 79060cb3e1d..00000000000 --- a/examples/cpp/dds/SecureHelloWorldExample/README.txt +++ /dev/null @@ -1,10 +0,0 @@ -This example needs the certificates stored in "certs" directory. You need to -copy this folder where you will execute the example executable. The -CMakeList.txt file also copies this directory to the folder used to build the -example. - -To launch this test open two different consoles: - -In the first one launch: ./DDSSecureHelloWorldExample publisher (or DDSSecureHelloWorldExample.exe publisher on windows). -In the second one: ./DDSSecureHelloWorldExample subscriber (or DDSSecureHelloWorldExample.exe subscriber on windows). - diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp index dd47e64be7c..6a5b40c9ccc 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp @@ -26,6 +26,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; HelloWorldPublisher::HelloWorldPublisher() diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.h b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.h index 90f3a114fd6..baa2cc8d917 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.h +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDPUBLISHER_H_ -#define HELLOWORLDPUBLISHER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H #include #include @@ -87,4 +85,4 @@ class HelloWorldPublisher -#endif /* HELLOWORLDPUBLISHER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDPUBLISHER_H diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp index 7b38e634fd5..a133fc30c28 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp @@ -26,6 +26,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; HelloWorldSubscriber::HelloWorldSubscriber() diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.h b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.h index b3f2be7d2fd..a45e079a2b0 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.h +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.h @@ -17,10 +17,8 @@ * */ -#ifndef HELLOWORLDSUBSCRIBER_H_ -#define HELLOWORLDSUBSCRIBER_H_ - -#include "HelloWorldPubSubTypes.hpp" +#ifndef FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H #include #include @@ -92,4 +90,4 @@ class HelloWorldSubscriber }; -#endif /* HELLOWORLDSUBSCRIBER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_DDS_STATIC_HELLO_WORLD_EXAMPLE__HELLOWORLDSUBSCRIBER_H diff --git a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.cxx b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.cxx index 4db4a8e26ef..de9f654cd7f 100644 --- a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.cxx +++ b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.cxx @@ -19,9 +19,8 @@ * This file was generated by the tool fastcdrgen. */ - -#include "LoanableHelloWorldPublisher.h" -#include "LoanableHelloWorldPubSubTypes.hpp" +#include +#include #include #include @@ -29,8 +28,8 @@ #include #include -#include -#include +#include "LoanableHelloWorldPublisher.h" +#include "LoanableHelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.h b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.h index 9f8071f7e70..ff3aed9410d 100644 --- a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.h +++ b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldPublisher.h @@ -20,8 +20,8 @@ */ -#ifndef _LOANABLEHELLOWORLD_PUBLISHER_H_ -#define _LOANABLEHELLOWORLD_PUBLISHER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H #include #include @@ -66,4 +66,4 @@ class LoanableHelloWorldPublisher listener_; }; -#endif // _LOANABLEHELLOWORLD_PUBLISHER_H_ \ No newline at end of file +#endif // FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H diff --git a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldSubscriber.h b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldSubscriber.h index cd6488e8527..bf805fe6469 100644 --- a/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldSubscriber.h +++ b/examples/cpp/dds/WriterLoansExample/LoanableHelloWorldSubscriber.h @@ -20,8 +20,8 @@ */ -#ifndef _LOANABLEHELLOWORLD_SUBSCRIBER_H_ -#define _LOANABLEHELLOWORLD_SUBSCRIBER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H #include #include @@ -69,4 +69,4 @@ class LoanableHelloWorldSubscriber listener_; }; -#endif // _LOANABLEHELLOWORLD_SUBSCRIBER_H_ \ No newline at end of file +#endif // FASTDDS_EXAMPLES_CPP_DDS_WRITER_LOANS_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H diff --git a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.cxx b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.cxx index a98cff060a3..3a4ae49cb9c 100644 --- a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.cxx +++ b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.cxx @@ -19,9 +19,8 @@ * This file was generated by the tool fastcdrgen. */ - -#include "LoanableHelloWorldPublisher.h" -#include "LoanableHelloWorldPubSubTypes.hpp" +#include +#include #include #include @@ -29,8 +28,8 @@ #include #include -#include -#include +#include "LoanableHelloWorldPublisher.h" +#include "LoanableHelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.h b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.h index b7045f55b38..94b7386ba7e 100644 --- a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.h +++ b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldPublisher.h @@ -20,8 +20,8 @@ */ -#ifndef _LOANABLEHELLOWORLD_PUBLISHER_H_ -#define _LOANABLEHELLOWORLD_PUBLISHER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H +#define FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H #include #include @@ -66,4 +66,4 @@ class LoanableHelloWorldPublisher listener_; }; -#endif // _LOANABLEHELLOWORLD_PUBLISHER_H_ \ No newline at end of file +#endif // FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_PUBLISHER_H diff --git a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldSubscriber.h b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldSubscriber.h index 40acb6278cd..4b1afdde962 100644 --- a/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldSubscriber.h +++ b/examples/cpp/dds/ZeroCopyExample/LoanableHelloWorldSubscriber.h @@ -20,8 +20,8 @@ */ -#ifndef _LOANABLEHELLOWORLD_SUBSCRIBER_H_ -#define _LOANABLEHELLOWORLD_SUBSCRIBER_H_ +#ifndef FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H +#define FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H #include #include @@ -69,4 +69,4 @@ class LoanableHelloWorldSubscriber listener_; }; -#endif // _LOANABLEHELLOWORLD_SUBSCRIBER_H_ \ No newline at end of file +#endif // FASTDDS_EXAMPLES_CPP_DDS_ZERO_COPY_EXAMPLE__LOANABLE_HELLO_WORLD_SUBSCRIBER_H diff --git a/examples/cpp/delivery_mechanisms/Application.cpp b/examples/cpp/delivery_mechanisms/Application.cpp index ab87cf2ed3b..6c6965dc206 100644 --- a/examples/cpp/delivery_mechanisms/Application.cpp +++ b/examples/cpp/delivery_mechanisms/Application.cpp @@ -24,8 +24,6 @@ #include "SubscriberApp.hpp" #include "PubSubApp.hpp" -using namespace eprosima::fastdds::dds; - namespace eprosima { namespace fastdds { namespace examples { diff --git a/examples/cpp/delivery_mechanisms/Application.hpp b/examples/cpp/delivery_mechanisms/Application.hpp index 5977ab444e9..26066749693 100644 --- a/examples/cpp/delivery_mechanisms/Application.hpp +++ b/examples/cpp/delivery_mechanisms/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DELIVERY_MECHANISMS_APPLICATION_HPP_ -#define _FASTDDS_DELIVERY_MECHANISMS_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__APPLICATION_HPP #include @@ -53,4 +53,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DELIVERY_MECHANISMS_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__APPLICATION_HPP diff --git a/examples/cpp/delivery_mechanisms/CLIParser.hpp b/examples/cpp/delivery_mechanisms/CLIParser.hpp index 5796491847a..11649e3bb71 100644 --- a/examples/cpp/delivery_mechanisms/CLIParser.hpp +++ b/examples/cpp/delivery_mechanisms/CLIParser.hpp @@ -20,15 +20,14 @@ #include #include -#ifndef _FASTDDS_DELIVERY_MECHANISMS_CLI_PARSER_HPP_ -#define _FASTDDS_DELIVERY_MECHANISMS_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__CLIPARSER_HPP namespace eprosima { namespace fastdds { namespace examples { namespace delivery_mechanisms { -using namespace eprosima::fastdds::dds; using dds::Log; class CLIParser @@ -415,4 +414,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_DELIVERY_MECHANISMS_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__CLIPARSER_HPP diff --git a/examples/cpp/delivery_mechanisms/PubSubApp.cpp b/examples/cpp/delivery_mechanisms/PubSubApp.cpp index d2769564239..eab6be79312 100644 --- a/examples/cpp/delivery_mechanisms/PubSubApp.cpp +++ b/examples/cpp/delivery_mechanisms/PubSubApp.cpp @@ -119,7 +119,7 @@ PubSubApp::PubSubApp( { // Large Data is a builtin transport pqos.transport().use_builtin_transports = true; - pqos.setup_transports(eprosima::fastdds::rtps::BuiltinTransports::LARGE_DATA); + pqos.setup_transports(BuiltinTransports::LARGE_DATA); break; } case CLIParser::DeliveryMechanismKind::TCPv4: @@ -135,10 +135,10 @@ PubSubApp::PubSubApp( tcp_ip_address = config.tcp_ip_address; } // Set unicast locators - eprosima::fastdds::rtps::Locator_t tcp_v4_locator_; + Locator_t tcp_v4_locator_; tcp_v4_locator_.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(tcp_v4_locator_, tcp_ip_address); - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(tcp_v4_locator_, 5100); + IPLocator::setIPv4(tcp_v4_locator_, tcp_ip_address); + IPLocator::setPhysicalPort(tcp_v4_locator_, 5100); pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(tcp_v4_locator_); pqos.wire_protocol().default_unicast_locator_list.push_back(tcp_v4_locator_); tcp_v4_transport_->set_WAN_address(tcp_ip_address); @@ -147,7 +147,7 @@ PubSubApp::PubSubApp( Locator tcp_v4_initial_peers_locator_; tcp_v4_initial_peers_locator_.kind = LOCATOR_KIND_TCPv4; tcp_v4_initial_peers_locator_.port = 5100; - eprosima::fastdds::rtps::IPLocator::setIPv4(tcp_v4_initial_peers_locator_, tcp_ip_address); + IPLocator::setIPv4(tcp_v4_initial_peers_locator_, tcp_ip_address); pqos.wire_protocol().builtin.initialPeersList.push_back(tcp_v4_initial_peers_locator_); break; } @@ -164,10 +164,10 @@ PubSubApp::PubSubApp( tcp_ip_address = config.tcp_ip_address; } // Set unicast locators - eprosima::fastdds::rtps::Locator_t tcp_v6_locator_; + Locator_t tcp_v6_locator_; tcp_v6_locator_.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(tcp_v6_locator_, tcp_ip_address); - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(tcp_v6_locator_, 5100); + IPLocator::setIPv6(tcp_v6_locator_, tcp_ip_address); + IPLocator::setPhysicalPort(tcp_v6_locator_, 5100); pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(tcp_v6_locator_); pqos.wire_protocol().default_unicast_locator_list.push_back(tcp_v6_locator_); tcp_v6_transport_->add_listener_port(5100); @@ -175,7 +175,7 @@ PubSubApp::PubSubApp( Locator tcp_v6_initial_peers_locator_; tcp_v6_initial_peers_locator_.kind = LOCATOR_KIND_TCPv6; tcp_v6_initial_peers_locator_.port = 5100; - eprosima::fastdds::rtps::IPLocator::setIPv6(tcp_v6_initial_peers_locator_, tcp_ip_address); + IPLocator::setIPv6(tcp_v6_initial_peers_locator_, tcp_ip_address); pqos.wire_protocol().builtin.initialPeersList.push_back(tcp_v6_initial_peers_locator_); break; } @@ -286,7 +286,7 @@ PubSubApp::~PubSubApp() } void PubSubApp::on_publication_matched( - eprosima::fastdds::dds::DataWriter* /*writer*/, + DataWriter* /*writer*/, const PublicationMatchedStatus& info) { if (info.current_count_change == 1) diff --git a/examples/cpp/delivery_mechanisms/PubSubApp.hpp b/examples/cpp/delivery_mechanisms/PubSubApp.hpp index fab60d8be29..95a51f11ed9 100644 --- a/examples/cpp/delivery_mechanisms/PubSubApp.hpp +++ b/examples/cpp/delivery_mechanisms/PubSubApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_MECHANISMS_PUBSUB_APP_HPP_ -#define _FASTDDS_DISCOVERY_MECHANISMS_PUBSUB_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBSUBAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBSUBAPP_HPP #include #include @@ -35,16 +35,13 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "DeliveryMechanismsPubSubTypes.hpp" - -using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { namespace examples { namespace delivery_mechanisms { -class PubSubApp : public Application, public DataReaderListener, public DataWriterListener +class PubSubApp : public Application, public dds::DataReaderListener, public dds::DataWriterListener { public: @@ -56,17 +53,17 @@ class PubSubApp : public Application, public DataReaderListener, public DataWrit //! Subscription callback void on_data_available( - DataReader* reader) override; + dds::DataReader* reader) override; //! Publisher matched method void on_publication_matched( - DataWriter* writer, - const PublicationMatchedStatus& info) override; + dds::DataWriter* writer, + const dds::PublicationMatchedStatus& info) override; //! Subscriber matched method void on_subscription_matched( - DataReader* reader, - const SubscriptionMatchedStatus& info) override; + dds::DataReader* reader, + const dds::SubscriptionMatchedStatus& info) override; //! Run the subscriber void run() override; @@ -82,19 +79,19 @@ class PubSubApp : public Application, public DataReaderListener, public DataWrit //! Publish a sample bool publish(); - DomainParticipant* participant_; + dds::DomainParticipant* participant_; - Publisher* publisher_; + dds::Publisher* publisher_; - Subscriber* subscriber_; + dds::Subscriber* subscriber_; - Topic* topic_; + dds::Topic* topic_; - DataReader* reader_; + dds::DataReader* reader_; - DataWriter* writer_; + dds::DataWriter* writer_; - TypeSupport type_; + dds::TypeSupport type_; std::condition_variable cv_; @@ -118,4 +115,4 @@ class PubSubApp : public Application, public DataReaderListener, public DataWrit } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_MECHANISMS_PUBSUB_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBSUBAPP_HPP diff --git a/examples/cpp/delivery_mechanisms/PublisherApp.cpp b/examples/cpp/delivery_mechanisms/PublisherApp.cpp index ee8a9e8b224..ea100372f94 100644 --- a/examples/cpp/delivery_mechanisms/PublisherApp.cpp +++ b/examples/cpp/delivery_mechanisms/PublisherApp.cpp @@ -37,9 +37,10 @@ #include #include -using namespace eprosima::fastdds::dds; -using namespace eprosima::fastdds::rtps; +#include "DeliveryMechanismsPubSubTypes.hpp" +using namespace eprosima::fastdds::rtps; +using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { namespace examples { @@ -102,7 +103,7 @@ PublisherApp::PublisherApp( { // Large Data is a builtin transport pqos.transport().use_builtin_transports = true; - pqos.setup_transports(eprosima::fastdds::rtps::BuiltinTransports::LARGE_DATA); + pqos.setup_transports(BuiltinTransports::LARGE_DATA); break; } case CLIParser::DeliveryMechanismKind::TCPv4: @@ -118,10 +119,10 @@ PublisherApp::PublisherApp( tcp_ip_address = config.tcp_ip_address; } // Set unicast locators - eprosima::fastdds::rtps::Locator_t tcp_v4_locator_; + Locator_t tcp_v4_locator_; tcp_v4_locator_.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(tcp_v4_locator_, tcp_ip_address); - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(tcp_v4_locator_, 5100); + IPLocator::setIPv4(tcp_v4_locator_, tcp_ip_address); + IPLocator::setPhysicalPort(tcp_v4_locator_, 5100); pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(tcp_v4_locator_); pqos.wire_protocol().default_unicast_locator_list.push_back(tcp_v4_locator_); tcp_v4_transport_->set_WAN_address(tcp_ip_address); @@ -142,10 +143,10 @@ PublisherApp::PublisherApp( tcp_ip_address = config.tcp_ip_address; } // Set unicast locators - eprosima::fastdds::rtps::Locator_t tcp_v6_locator_; + Locator_t tcp_v6_locator_; tcp_v6_locator_.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(tcp_v6_locator_, tcp_ip_address); - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(tcp_v6_locator_, 5100); + IPLocator::setIPv6(tcp_v6_locator_, tcp_ip_address); + IPLocator::setPhysicalPort(tcp_v6_locator_, 5100); pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(tcp_v6_locator_); pqos.wire_protocol().default_unicast_locator_list.push_back(tcp_v6_locator_); tcp_v6_transport_->add_listener_port(5100); @@ -235,7 +236,7 @@ PublisherApp::~PublisherApp() } void PublisherApp::on_publication_matched( - eprosima::fastdds::dds::DataWriter* /*writer*/, + DataWriter* /*writer*/, const PublicationMatchedStatus& info) { if (info.current_count_change == 1) diff --git a/examples/cpp/delivery_mechanisms/PublisherApp.hpp b/examples/cpp/delivery_mechanisms/PublisherApp.hpp index 729a7012cce..279e03357f5 100644 --- a/examples/cpp/delivery_mechanisms/PublisherApp.hpp +++ b/examples/cpp/delivery_mechanisms/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_MECHANISMS_PUBLISHER_APP_HPP_ -#define _FASTDDS_DISCOVERY_MECHANISMS_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBLISHERAPP_HPP #include @@ -29,16 +29,13 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "DeliveryMechanismsPubSubTypes.hpp" - -using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { namespace examples { namespace delivery_mechanisms { -class PublisherApp : public Application, public DataWriterListener +class PublisherApp : public Application, public dds::DataWriterListener { public: @@ -50,8 +47,8 @@ class PublisherApp : public Application, public DataWriterListener //! Publisher matched method void on_publication_matched( - DataWriter* writer, - const PublicationMatchedStatus& info) override; + dds::DataWriter* writer, + const dds::PublicationMatchedStatus& info) override; //! Run publisher void run() override; @@ -67,15 +64,15 @@ class PublisherApp : public Application, public DataWriterListener //! Publish a sample bool publish(); - DomainParticipant* participant_; + dds::DomainParticipant* participant_; - Publisher* publisher_; + dds::Publisher* publisher_; - Topic* topic_; + dds::Topic* topic_; - DataWriter* writer_; + dds::DataWriter* writer_; - TypeSupport type_; + dds::TypeSupport type_; std::condition_variable cv_; @@ -97,4 +94,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_MECHANISMS_PUBLISHER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__PUBLISHERAPP_HPP diff --git a/examples/cpp/delivery_mechanisms/SubscriberApp.cpp b/examples/cpp/delivery_mechanisms/SubscriberApp.cpp index aae3b111a51..1c2a7d4d520 100644 --- a/examples/cpp/delivery_mechanisms/SubscriberApp.cpp +++ b/examples/cpp/delivery_mechanisms/SubscriberApp.cpp @@ -39,9 +39,8 @@ #include "CLIParser.hpp" #include "DeliveryMechanismsPubSubTypes.hpp" -using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; - +using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { namespace examples { @@ -104,7 +103,7 @@ SubscriberApp::SubscriberApp( { // Large Data is a builtin transport pqos.transport().use_builtin_transports = true; - pqos.setup_transports(eprosima::fastdds::rtps::BuiltinTransports::LARGE_DATA); + pqos.setup_transports(BuiltinTransports::LARGE_DATA); break; } case CLIParser::DeliveryMechanismKind::TCPv4: @@ -117,7 +116,7 @@ SubscriberApp::SubscriberApp( { tcp_ip_address = config.tcp_ip_address; } - eprosima::fastdds::rtps::IPLocator::setIPv4(tcp_v4_initial_peers_locator_, tcp_ip_address); + IPLocator::setIPv4(tcp_v4_initial_peers_locator_, tcp_ip_address); pqos.wire_protocol().builtin.initialPeersList.push_back(tcp_v4_initial_peers_locator_); pqos.wire_protocol().builtin.discovery_config.leaseDuration = eprosima::fastdds::c_TimeInfinite; pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(5, 0); @@ -134,7 +133,7 @@ SubscriberApp::SubscriberApp( { tcp_ip_address = config.tcp_ip_address; } - eprosima::fastdds::rtps::IPLocator::setIPv6(tcp_v6_initial_peers_locator_, tcp_ip_address); + IPLocator::setIPv6(tcp_v6_initial_peers_locator_, tcp_ip_address); pqos.wire_protocol().builtin.initialPeersList.push_back(tcp_v6_initial_peers_locator_); pqos.wire_protocol().builtin.discovery_config.leaseDuration = eprosima::fastdds::c_TimeInfinite; pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(5, 0); diff --git a/examples/cpp/delivery_mechanisms/SubscriberApp.hpp b/examples/cpp/delivery_mechanisms/SubscriberApp.hpp index fdb3a5c81f1..96cc44817d8 100644 --- a/examples/cpp/delivery_mechanisms/SubscriberApp.hpp +++ b/examples/cpp/delivery_mechanisms/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_MECHANISMS_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_DISCOVERY_MECHANISMS_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__SUBSCRIBERAPP_HPP #include #include @@ -32,16 +32,13 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "DeliveryMechanismsPubSubTypes.hpp" - -using namespace eprosima::fastdds::dds; namespace eprosima { namespace fastdds { namespace examples { namespace delivery_mechanisms { -class SubscriberApp : public Application, public DataReaderListener +class SubscriberApp : public Application, public dds::DataReaderListener { public: @@ -53,12 +50,12 @@ class SubscriberApp : public Application, public DataReaderListener //! Subscription callback void on_data_available( - DataReader* reader) override; + dds::DataReader* reader) override; //! Subscriber matched method void on_subscription_matched( - DataReader* reader, - const SubscriptionMatchedStatus& info) override; + dds::DataReader* reader, + const dds::SubscriptionMatchedStatus& info) override; //! Run the subscriber void run() override; @@ -71,15 +68,15 @@ class SubscriberApp : public Application, public DataReaderListener //! Return the current state of execution bool is_stopped(); - DomainParticipant* participant_; + dds::DomainParticipant* participant_; - Subscriber* subscriber_; + dds::Subscriber* subscriber_; - Topic* topic_; + dds::Topic* topic_; - DataReader* reader_; + dds::DataReader* reader_; - TypeSupport type_; + dds::TypeSupport type_; std::condition_variable cv_; @@ -97,4 +94,4 @@ class SubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_MECHANISMS_SUBSCRIBER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_DELIVERY_MECHANISMS__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/discovery_server/Application.hpp b/examples/cpp/discovery_server/Application.hpp index 14df294260e..fa966818b8f 100644 --- a/examples/cpp/discovery_server/Application.hpp +++ b/examples/cpp/discovery_server/Application.hpp @@ -52,4 +52,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__APPLICATION_HPP */ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__APPLICATION_HPP diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 8fe63d5cef8..953259d07c1 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -33,6 +33,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; namespace eprosima { diff --git a/examples/cpp/discovery_server/ClientPublisherApp.hpp b/examples/cpp/discovery_server/ClientPublisherApp.hpp index bfdd291e2b4..9857c4c90e3 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.hpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.hpp @@ -28,7 +28,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; @@ -95,4 +95,4 @@ class ClientPublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTPUBLISHERAPP_HPP */ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTPUBLISHERAPP_HPP diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp index 8918f708df7..a026455eb66 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.cpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -38,6 +38,8 @@ #include "CLIParser.hpp" #include "Application.hpp" +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; namespace eprosima { diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.hpp b/examples/cpp/discovery_server/ClientSubscriberApp.hpp index 2d1ddae1fca..6b237e8d776 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.hpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.hpp @@ -27,7 +27,7 @@ #include #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" #include "Application.hpp" using namespace eprosima::fastdds::dds; @@ -94,4 +94,4 @@ class ClientSubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTSUBSCRIBERAPP_HPP */ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTSUBSCRIBERAPP_HPP diff --git a/examples/cpp/discovery_server/Helpers.hpp b/examples/cpp/discovery_server/Helpers.hpp index c4603c69a9a..d70b4a13779 100644 --- a/examples/cpp/discovery_server/Helpers.hpp +++ b/examples/cpp/discovery_server/Helpers.hpp @@ -78,4 +78,4 @@ inline std::string get_ip_from_dns( return domain_name; } -#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__HELPERS_HPP */ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__HELPERS_HPP diff --git a/examples/cpp/discovery_server/ServerApp.hpp b/examples/cpp/discovery_server/ServerApp.hpp index f9eca825559..7e738cd06e7 100644 --- a/examples/cpp/discovery_server/ServerApp.hpp +++ b/examples/cpp/discovery_server/ServerApp.hpp @@ -83,4 +83,4 @@ class ServerApp : public Application, public DomainParticipantListener } // namespace fastdds } // namespace eprosima -#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__SERVERAPP_HPP */ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__SERVERAPP_HPP diff --git a/examples/cpp/hello_world/Application.hpp b/examples/cpp/hello_world/Application.hpp index 9d1f01b214b..0978ffd938d 100644 --- a/examples/cpp/hello_world/Application.hpp +++ b/examples/cpp/hello_world/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_HELLO_WORLD_APPLICATION_HPP_ -#define _FASTDDS_HELLO_WORLD_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_HELLO_WORLD__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_HELLO_WORLD__APPLICATION_HPP #include @@ -53,4 +53,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_HELLO_WORLD_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_HELLO_WORLD__APPLICATION_HPP diff --git a/examples/cpp/hello_world/CLIParser.hpp b/examples/cpp/hello_world/CLIParser.hpp index 8aebfacde8d..edd0863e321 100644 --- a/examples/cpp/hello_world/CLIParser.hpp +++ b/examples/cpp/hello_world/CLIParser.hpp @@ -18,8 +18,8 @@ #include -#ifndef _FASTDDS_HELLO_WORLD_CLI_PARSER_HPP_ -#define _FASTDDS_HELLO_WORLD_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_HELLO_WORLD__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_HELLO_WORLD__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -258,4 +258,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_HELLO_WORLD_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_HELLO_WORLD__CLIPARSER_HPP diff --git a/examples/cpp/hello_world/ListenerSubscriberApp.hpp b/examples/cpp/hello_world/ListenerSubscriberApp.hpp index 7813cf4487b..6d8978494dd 100644 --- a/examples/cpp/hello_world/ListenerSubscriberApp.hpp +++ b/examples/cpp/hello_world/ListenerSubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_HELLO_WORLD_LISTENER_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_HELLO_WORLD_LISTENER_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_HELLO_WORLD__LISTENERSUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_HELLO_WORLD__LISTENERSUBSCRIBERAPP_HPP #include @@ -27,7 +27,7 @@ #include #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" #include "Application.hpp" using namespace eprosima::fastdds::dds; @@ -95,4 +95,4 @@ class ListenerSubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_HELLO_WORLD_LISTENER_SUBSCRIBER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_HELLO_WORLD__LISTENERSUBSCRIBERAPP_HPP diff --git a/examples/cpp/hello_world/PublisherApp.cpp b/examples/cpp/hello_world/PublisherApp.cpp index d2ec4140767..63b4331137e 100644 --- a/examples/cpp/hello_world/PublisherApp.cpp +++ b/examples/cpp/hello_world/PublisherApp.cpp @@ -28,6 +28,8 @@ #include #include +#include "HelloWorldPubSubTypes.hpp" + using namespace eprosima::fastdds::dds; namespace eprosima { diff --git a/examples/cpp/hello_world/PublisherApp.hpp b/examples/cpp/hello_world/PublisherApp.hpp index c2520a97a1c..ed62f856780 100644 --- a/examples/cpp/hello_world/PublisherApp.hpp +++ b/examples/cpp/hello_world/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_HELLO_WORLD_PUBLISHER_APP_HPP_ -#define _FASTDDS_HELLO_WORLD_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_HELLO_WORLD__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_HELLO_WORLD__PUBLISHERAPP_HPP #include @@ -28,7 +28,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; @@ -96,4 +96,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_HELLO_WORLD_PUBLISHER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_HELLO_WORLD__PUBLISHERAPP_HPP diff --git a/examples/cpp/hello_world/WaitsetSubscriberApp.cpp b/examples/cpp/hello_world/WaitsetSubscriberApp.cpp index 9bf670e5c9c..bedda669990 100644 --- a/examples/cpp/hello_world/WaitsetSubscriberApp.cpp +++ b/examples/cpp/hello_world/WaitsetSubscriberApp.cpp @@ -32,9 +32,9 @@ #include #include -#include "HelloWorldPubSubTypes.hpp" -#include "CLIParser.hpp" #include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/hello_world/WaitsetSubscriberApp.hpp b/examples/cpp/hello_world/WaitsetSubscriberApp.hpp index 507d00ad6ba..88894a324ae 100644 --- a/examples/cpp/hello_world/WaitsetSubscriberApp.hpp +++ b/examples/cpp/hello_world/WaitsetSubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_HELLO_WORLD_WAITSET_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_HELLO_WORLD_WAITSET_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_HELLO_WORLD__WAITSETSUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_HELLO_WORLD__WAITSETSUBSCRIBERAPP_HPP #include #include @@ -28,9 +28,9 @@ #include #include -#include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.hpp" #include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorld.hpp" using namespace eprosima::fastdds::dds; @@ -88,4 +88,4 @@ class WaitsetSubscriberApp : public Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_HELLO_WORLD_WAITSET_SUBSCRIBER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_HELLO_WORLD__WAITSETSUBSCRIBERAPP_HPP diff --git a/examples/cpp/rtps/AsSocket/TestReaderSocket.h b/examples/cpp/rtps/AsSocket/TestReaderSocket.h index 3151590c154..665074146f1 100644 --- a/examples/cpp/rtps/AsSocket/TestReaderSocket.h +++ b/examples/cpp/rtps/AsSocket/TestReaderSocket.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTREADERSOCKET_H_ -#define TESTREADERSOCKET_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTREADERSOCKET_H +#define FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTREADERSOCKET_H #include @@ -75,4 +75,4 @@ class TestReaderSocket }; -#endif /* TESTREADER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTREADERSOCKET_H diff --git a/examples/cpp/rtps/AsSocket/TestWriterSocket.h b/examples/cpp/rtps/AsSocket/TestWriterSocket.h index b427f872ebc..59c4ea042c7 100644 --- a/examples/cpp/rtps/AsSocket/TestWriterSocket.h +++ b/examples/cpp/rtps/AsSocket/TestWriterSocket.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTWRITERSOCKET_H_ -#define TESTWRITERSOCKET_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTWRITERSOCKET_H +#define FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTWRITERSOCKET_H #include #include @@ -57,4 +57,4 @@ class TestWriterSocket uint16_t nmsgs); }; -#endif /* TESTWRITER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_AS_SOCKET__TESTWRITERSOCKET_H diff --git a/examples/cpp/rtps/Persistent/TestReaderPersistent.h b/examples/cpp/rtps/Persistent/TestReaderPersistent.h index 53a6ee5d729..3a7b05047d5 100644 --- a/examples/cpp/rtps/Persistent/TestReaderPersistent.h +++ b/examples/cpp/rtps/Persistent/TestReaderPersistent.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTREADERPERSISTENT_H_ -#define TESTREADERPERSISTENT_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTREADERPERSISTENT_H +#define FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTREADERPERSISTENT_H #include @@ -78,4 +78,4 @@ class TestReaderPersistent m_listener; }; -#endif /* TESTREADERPERSISTENT_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTREADERPERSISTENT_H diff --git a/examples/cpp/rtps/Persistent/TestWriterPersistent.h b/examples/cpp/rtps/Persistent/TestWriterPersistent.h index 39022ddb614..5d1e97a2f6d 100644 --- a/examples/cpp/rtps/Persistent/TestWriterPersistent.h +++ b/examples/cpp/rtps/Persistent/TestWriterPersistent.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTWRITERPERSISTENT_H_ -#define TESTWRITERPERSISTENT_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTWRITERPERSISTENT_H +#define FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTWRITERPERSISTENT_H #include @@ -74,4 +74,4 @@ class TestWriterPersistent m_listener; }; -#endif /* TESTWRITERPERSISTENT_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_PERSISTENT__TESTWRITERPERSISTENT_H diff --git a/examples/cpp/rtps/Registered/TestReaderRegistered.h b/examples/cpp/rtps/Registered/TestReaderRegistered.h index 219823955ed..c177224ba3f 100644 --- a/examples/cpp/rtps/Registered/TestReaderRegistered.h +++ b/examples/cpp/rtps/Registered/TestReaderRegistered.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTREADERREGISTERED_H_ -#define TESTREADERREGISTERED_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTREADERREGISTERED_H +#define FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTREADERREGISTERED_H #include @@ -79,4 +79,4 @@ class TestReaderRegistered m_listener; }; -#endif /* TESTREADER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTREADERREGISTERED_H diff --git a/examples/cpp/rtps/Registered/TestWriterRegistered.h b/examples/cpp/rtps/Registered/TestWriterRegistered.h index e9c62c13406..c9e10e3e6af 100644 --- a/examples/cpp/rtps/Registered/TestWriterRegistered.h +++ b/examples/cpp/rtps/Registered/TestWriterRegistered.h @@ -17,8 +17,8 @@ * */ -#ifndef TESTWRITERREGISTERED_H_ -#define TESTWRITERREGISTERED_H_ +#ifndef FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTWRITERREGISTERED_H +#define FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTWRITERREGISTERED_H #include @@ -73,4 +73,4 @@ class TestWriterRegistered m_listener; }; -#endif /* TESTWRITER_H_ */ +#endif // FASTDDS_EXAMPLES_CPP_RTPS_REGISTERED__TESTWRITERREGISTERED_H diff --git a/examples/cpp/security/Application.cpp b/examples/cpp/security/Application.cpp new file mode 100644 index 00000000000..698d771e034 --- /dev/null +++ b/examples/cpp/security/Application.cpp @@ -0,0 +1,58 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file Application.cpp + * + */ + +#include "Application.hpp" + +#include "CLIParser.hpp" +#include "PublisherApp.hpp" +#include "SubscriberApp.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +//! Factory method to create a publisher or subscriber +std::shared_ptr Application::make_app( + const CLIParser::security_config& config, + const std::string& topic_name) +{ + std::shared_ptr entity; + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + entity = std::make_shared(config.pub_config, topic_name); + break; + case CLIParser::EntityKind::SUBSCRIBER: + entity = std::make_shared(config.sub_config, topic_name); + break; + case CLIParser::EntityKind::UNDEFINED: + default: + throw std::runtime_error("Entity initialization failed"); + break; + } + return entity; +} + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/security/Application.hpp b/examples/cpp/security/Application.hpp new file mode 100644 index 00000000000..1fcf49403a8 --- /dev/null +++ b/examples/cpp/security/Application.hpp @@ -0,0 +1,56 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file Application.hpp + * + */ + +#ifndef FASTDDS_EXAMPLES_CPP_SECURITY__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_SECURITY__APPLICATION_HPP + +#include + +#include "CLIParser.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +class Application +{ +public: + + //! Virtual destructor + virtual ~Application() = default; + + //! Run application + virtual void run() = 0; + + //! Trigger the end of execution + virtual void stop() = 0; + + //! Factory method to create applications based on configuration + static std::shared_ptr make_app( + const CLIParser::security_config& config, + const std::string& topic_name); +}; + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_SECURITY__APPLICATION_HPP diff --git a/examples/cpp/security/CLIParser.hpp b/examples/cpp/security/CLIParser.hpp new file mode 100644 index 00000000000..4e2484698d0 --- /dev/null +++ b/examples/cpp/security/CLIParser.hpp @@ -0,0 +1,295 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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 +#include +#include +#include + +#include + +#ifndef FASTDDS_EXAMPLES_CPP_SECURITY__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_SECURITY__CLIPARSER_HPP + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +using dds::Log; + +class CLIParser +{ +public: + + CLIParser() = delete; + + //! Entity kind enumeration + enum class EntityKind : uint8_t + { + PUBLISHER, + SUBSCRIBER, + UNDEFINED + }; + + //! Configuration structure (shared for both publisher and subscriber applications) + struct entity_config + { + uint16_t samples = 0; + }; + struct publisher_config : entity_config + { + uint32_t interval = 1000; + }; + + //! Configuration structure for the application + struct security_config + { + CLIParser::EntityKind entity = CLIParser::EntityKind::UNDEFINED; + publisher_config pub_config; + entity_config sub_config; + }; + + /** + * @brief Print usage help message and exit with the given return code + * + * @param return_code return code to exit with + * + * @warning This method finishes the execution of the program with the input return code + */ + static void print_help( + uint8_t return_code) + { + std::cout << "Usage: security [options]" << std::endl; + std::cout << "" << std::endl; + std::cout << "Entities:" << std::endl; + std::cout << " publisher Run a publisher entity" << std::endl; + std::cout << " subscriber Run a subscriber entity" << std::endl; + std::cout << "" << std::endl; + std::cout << "Common options:" << std::endl; + std::cout << " -h, --help Print this help message" << std::endl; + std::cout << " -s , --samples Number of samples to send or receive" << std::endl; + std::cout << " [0 <= <= 65535]" << std::endl; + std::cout << " (Default: 0 [unlimited])" << std::endl; + std::cout << "Publisher options:" << std::endl; + std::cout << " -i , --interval Time between samples in milliseconds" << std::endl; + std::cout << " [1 <= <= 4294967]" << std::endl; + std::exit(return_code); + } + + /** + * @brief Parse the command line options and return the configuration_config object + * + * @param argc number of arguments + * @param argv array of arguments + * @return configuration_config object with the parsed options + * + * @warning This method finishes the execution of the program if the input arguments are invalid + */ + static security_config parse_cli_options( + int argc, + char* argv[]) + { + security_config config; + + if (argc < 2) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing entity argument"); + print_help(EXIT_FAILURE); + } + + std::string first_argument = argv[1]; + + if (first_argument == "publisher" ) + { + config.entity = CLIParser::EntityKind::PUBLISHER; + } + else if (first_argument == "subscriber") + { + config.entity = CLIParser::EntityKind::SUBSCRIBER; + } + else if (first_argument == "-h" || first_argument == "--help") + { + print_help(EXIT_SUCCESS); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing entity argument " + first_argument); + print_help(EXIT_FAILURE); + } + // max value allowed taking into account that the input is receiving millisecond values + uint32_t max_duration = static_cast(floor(std::numeric_limits::max() * 1e-3)); // = 4294967 + + for (int i = 2; i < argc; ++i) + { + std::string arg = argv[i]; + if (arg == "-h" || arg == "--help") + { + print_help(EXIT_SUCCESS); + } + else if (arg == "-s" || arg == "--samples") + { + if (i + 1 < argc) + { + try + { + int input = std::stoi(argv[++i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("sample argument out of range"); + } + else + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.samples = static_cast(input); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + config.sub_config.samples = static_cast(input); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --sample argument"); + print_help(EXIT_FAILURE); + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid sample argument for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "sample argument out of range for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-i" || arg == "--interval") + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 1 || static_cast(input) > static_cast(max_duration)) + { + throw std::out_of_range("interval argument " + std::string( + argv[i]) + " out of range [1, " + std::to_string( + max_duration) + "]."); + } + else + { + config.pub_config.interval = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid interval argument " + std::string( + argv[i]) + ": " + std::string(e.what())); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing interval argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "interval argument is only valid for publisher entity"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "unknown option " + arg); + print_help(EXIT_FAILURE); + } + } + + return config; + } + + /** + * @brief Parse the signal number into the signal name + * + * @param signum signal number + * @return std::string signal name + */ + static std::string parse_signal( + const int& signum) + { + switch (signum) + { + case SIGINT: + return "SIGINT"; + case SIGTERM: + return "SIGTERM"; +#ifndef _WIN32 + case SIGQUIT: + return "SIGQUIT"; + case SIGHUP: + return "SIGHUP"; +#endif // _WIN32 + default: + return "UNKNOWN SIGNAL"; + } + } + + /** + * @brief Parse the entity kind into std::string + * + * @param entity entity kind + * @return std::string entity kind + */ + static std::string parse_entity_kind( + const EntityKind& entity) + { + switch (entity) + { + case EntityKind::PUBLISHER: + return "Publisher"; + case EntityKind::SUBSCRIBER: + return "Subscriber"; + case EntityKind::UNDEFINED: + default: + return "Undefined entity"; + } + } + +}; + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_SECURITY__CLIPARSER_HPP diff --git a/examples/cpp/security/CMakeLists.txt b/examples/cpp/security/CMakeLists.txt new file mode 100644 index 00000000000..ec130eb3f5e --- /dev/null +++ b/examples/cpp/security/CMakeLists.txt @@ -0,0 +1,70 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# 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. + +cmake_minimum_required(VERSION 3.20) + +project(fastdds_security_example VERSION 1 LANGUAGES CXX) + +# Find requirements +if(NOT fastcdr_FOUND) + find_package(fastcdr 2 REQUIRED) +endif() + +if(NOT fastdds_FOUND) + find_package(fastdds 3 REQUIRED) +endif() + +#Check C++11 +include(CheckCXXCompilerFlag) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) + if(NOT SUPPORTS_CXX11) + message(FATAL_ERROR "Compiler doesn't support C++11") + endif() +endif() + +message(STATUS "Configuring secure hello world example...") +file(GLOB SECURE_HELLO_WORLD_SOURCES_CXX "*.cxx") +file(GLOB SECURE_HELLO_WORLD_SOURCES_CPP "*.cpp") + +add_executable(security ${SECURE_HELLO_WORLD_SOURCES_CXX} ${SECURE_HELLO_WORLD_SOURCES_CPP}) +target_compile_definitions(security PRIVATE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + $<$:SHM_TRANSPORT_BUILTIN> # Enable SHM as built-in transport +) +target_link_libraries(security fastdds fastcdr) +install(TARGETS security + RUNTIME DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/security/${BIN_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/certs + DESTINATION examples/cpp/security/${BIN_INSTALL_DIR}) +# Copy the XML files over to the build directory +file(GLOB_RECURSE XML_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.xml) +# for each xml file detected +foreach(XML_FILE_COMPLETE_PATH ${XML_FILES}) + # obtain the file name + get_filename_component(XML_FILE ${XML_FILE_COMPLETE_PATH} NAME_WE) + # copy the file from src to build folders + configure_file( + ${XML_FILE_COMPLETE_PATH} # from full src path + ${CMAKE_CURRENT_BINARY_DIR}/${XML_FILE}.xml # to relative build path + COPYONLY) + install(FILES ${XML_FILE_COMPLETE_PATH} + DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/security/${BIN_INSTALL_DIR}) +endforeach() + +add_custom_command(TARGET security POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/certs + ${PROJECT_BINARY_DIR}/certs) diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorld.hpp b/examples/cpp/security/HelloWorld.hpp similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorld.hpp rename to examples/cpp/security/HelloWorld.hpp diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorld.idl b/examples/cpp/security/HelloWorld.idl similarity index 69% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorld.idl rename to examples/cpp/security/HelloWorld.idl index 0fd2c355aee..192f8f9d487 100644 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorld.idl +++ b/examples/cpp/security/HelloWorld.idl @@ -1,3 +1,4 @@ +@extensibility(APPENDABLE) struct HelloWorld { unsigned long index; diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldCdrAux.hpp b/examples/cpp/security/HelloWorldCdrAux.hpp similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldCdrAux.hpp rename to examples/cpp/security/HelloWorldCdrAux.hpp diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldCdrAux.ipp b/examples/cpp/security/HelloWorldCdrAux.ipp similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldCdrAux.ipp rename to examples/cpp/security/HelloWorldCdrAux.ipp diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPubSubTypes.cxx b/examples/cpp/security/HelloWorldPubSubTypes.cxx similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldPubSubTypes.cxx rename to examples/cpp/security/HelloWorldPubSubTypes.cxx diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldPubSubTypes.hpp b/examples/cpp/security/HelloWorldPubSubTypes.hpp similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldPubSubTypes.hpp rename to examples/cpp/security/HelloWorldPubSubTypes.hpp diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldTypeObjectSupport.cxx b/examples/cpp/security/HelloWorldTypeObjectSupport.cxx similarity index 96% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldTypeObjectSupport.cxx rename to examples/cpp/security/HelloWorldTypeObjectSupport.cxx index 58928b6f057..aaf391eeed3 100644 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldTypeObjectSupport.cxx +++ b/examples/cpp/security/HelloWorldTypeObjectSupport.cxx @@ -54,6 +54,13 @@ void register_HelloWorld_type_identifier( QualifiedTypeName type_name_HelloWorld = "HelloWorld"; eprosima::fastcdr::optional type_ann_builtin_HelloWorld; eprosima::fastcdr::optional ann_custom_HelloWorld; + AppliedAnnotationSeq tmp_ann_custom_HelloWorld; + eprosima::fastcdr::optional verbatim_HelloWorld; + if (!tmp_ann_custom_HelloWorld.empty()) + { + ann_custom_HelloWorld = tmp_ann_custom_HelloWorld; + } + CompleteTypeDetail detail_HelloWorld = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloWorld, ann_custom_HelloWorld, type_name_HelloWorld.to_string()); CompleteStructHeader header_HelloWorld; header_HelloWorld = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloWorld); diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldTypeObjectSupport.hpp b/examples/cpp/security/HelloWorldTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/HelloWorldTypeObjectSupport.hpp rename to examples/cpp/security/HelloWorldTypeObjectSupport.hpp diff --git a/examples/cpp/security/PublisherApp.cpp b/examples/cpp/security/PublisherApp.cpp new file mode 100644 index 00000000000..2c8baf8e44e --- /dev/null +++ b/examples/cpp/security/PublisherApp.cpp @@ -0,0 +1,181 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file PublisherApp.cpp + * + */ + +#include "PublisherApp.hpp" + +#include +#include + +#include +#include +#include +#include +#include + +#include "HelloWorldPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +PublisherApp::PublisherApp( + const CLIParser::publisher_config& config, + const std::string& topic_name) + : participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , type_(new HelloWorldPubSubType()) + , period_ms_(config.interval) + , matched_(0) + , samples_(config.samples) + , stop_(false) +{ + // Set up the data type with initial values + hello_.index(0); + hello_.message("Hello world"); + + // Create the participant + auto factory = DomainParticipantFactory::get_instance(); + participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none()); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // Register the type + type_.register_type(participant_); + + // Create the publisher + PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT; + participant_->get_default_publisher_qos(pub_qos); + publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none()); + if (publisher_ == nullptr) + { + throw std::runtime_error("Publisher initialization failed"); + } + + // Create the topic + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_ = participant_->create_topic(topic_name, type_.get_type_name(), topic_qos); + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the data writer + DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT; + publisher_->get_default_datawriter_qos(writer_qos); + writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all()); + if (writer_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } +} + +PublisherApp::~PublisherApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void PublisherApp::on_publication_matched( + DataWriter* /*writer*/, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher matched." << std::endl; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } +} + +void PublisherApp::run() +{ + while (!is_stopped() && ((samples_ == 0) || (hello_.index() < samples_))) + { + if (publish()) + { + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' SENT" << std::endl; + } + // Wait for period or stop event + std::unique_lock period_lock(mutex_); + cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [&]() + { + return is_stopped(); + }); + } +} + +bool PublisherApp::publish() +{ + bool ret = false; + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ > 0) || is_stopped()); + }); + + if (!is_stopped()) + { + hello_.index(hello_.index() + 1); + ret = (writer_->write(&hello_) == RETCODE_OK) ? true : false; + } + return ret; +} + +bool PublisherApp::is_stopped() +{ + return stop_.load(); +} + +void PublisherApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/security/PublisherApp.hpp b/examples/cpp/security/PublisherApp.hpp new file mode 100644 index 00000000000..2b35ddedaf9 --- /dev/null +++ b/examples/cpp/security/PublisherApp.hpp @@ -0,0 +1,100 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file PublisherApp.hpp + * + */ + +#ifndef FASTDDS_EXAMPLES_CPP_SECURITY__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_SECURITY__PUBLISHERAPP_HPP + +#include + +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorld.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +class PublisherApp : public Application, public DataWriterListener +{ +public: + + PublisherApp( + const CLIParser::publisher_config& config, + const std::string& topic_name); + + ~PublisherApp(); + + //! Publisher matched method + void on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) override; + + //! Run publisher + void run() override; + + //! Stop publisher + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + //! Publish a sample + bool publish(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Publisher* publisher_; + + Topic* topic_; + + DataWriter* writer_; + + TypeSupport type_; + + const uint32_t period_ms_; // sleep time (ms) between consecutive samples + + int16_t matched_; + + uint16_t samples_; + + std::mutex mutex_; + + std::condition_variable cv_; + + std::atomic stop_; + +}; + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_SECURITY__PUBLISHERAPP_HPP diff --git a/examples/cpp/security/README.md b/examples/cpp/security/README.md new file mode 100644 index 00000000000..c5a436e6ab9 --- /dev/null +++ b/examples/cpp/security/README.md @@ -0,0 +1,152 @@ +# Security example + +The *eProsima Fast DDS security* example is a simple application intended to demonstrate a basic DDS deployment with security builtin plugins. + +This example is part of the suite of examples designed by eProsima that aims to illustrate the features and possible configurations of DDS deployments through *eProsima Fast DDS*. + +In this case, the *security* example describes the simplest deployment of a Fast DDS publisher and subscriber using the DDS Security specification. + +* [Description of the example](#description-of-the-example) +* [Run the example](#run-the-example) +* [XML profile playground](#xml-profile-playground) + +## Description of the example + +Each example application (publisher and subscriber) creates different nested DDS entities: domain participant, publisher, and data writer; and domain participant, subscriber, and data reader, respectively. +In both cases, the three DDS entities (domain participant, publisher/subscriber and data writer/data reader) load their default configuration from the environment. +If the environment does not specify the expected configuration, they take the default configuration per entity. +For further information regarding the configuration environment, please refer to the *[XML profile playground](#xml-profile-playground)* section. + +This particular example includes only the listening callback mechanism, which consists on declaring a listener class and attaching it to the data reader. When the data reader is triggered by an event, it runs the listener's method associated to that event, as a callback. +For simplicity, in this example, the subscriber class inherits from the listener class, overriding the corresponding callback. + +## Run the example + +To launch this example, two different terminals are required. +One of them will run the publisher example application, and the other will run the subscriber application. Before running the applications, it is necessary to export both the path of the folder where the certificates are located in the environment variable ``CERTS_PATH`` and the path to the corresponding xml profile with ``FASTDDS_DEFAULT_PROFILES_FILE`` (see [XML playground](#xml-profile-playground)): + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ export CERTS_PATH= + ``` + +* Windows + + ```powershell + example_path> set CERTS_PATH= + ``` + + +### Secure Hello world publisher + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./security publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +* Windows + + ```powershell + example_path> security.exe publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +### Secure Hello world subscriber + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./security subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +* Windows + + ```powershell + example_path> security.exe subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +All the example available flags can be queried running the executable with the ``-h`` or ``--help`` flag. + +### Expected output + +Regardless of which application is run first, since the publisher will not start sending data until a subscriber is discovered, the expected output both for publishers and subscribers is a first displayed message acknowledging the match, followed by the amount of samples sent or received until Ctrl+C is pressed. + +### Secure Hello world publisher + +```shell +Publisher running. Please press Ctrl+C to stop the Publisher at any time. +Publisher matched. +Message: 'Hello world' with index: '1' SENT +Message: 'Hello world' with index: '2' SENT +Message: 'Hello world' with index: '3' SENT +... +``` + +### Secure Hello world subscriber + +```shell +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Subscriber matched. +Message: 'Hello world' with index: '1' RECEIVED +Message: 'Hello world' with index: '2' RECEIVED +Message: 'Hello world' with index: '3' RECEIVED +... +``` + +When Ctrl+C is pressed to stop one of the applications, the other one will show the unmatched status, displaying an informative message, and it will stop sending / receiving messages. +The following is a possible output of the publisher application when stopping the subscriber app. + +```shell +... +Message: 'Hello world' with index: '8' SENT +Message: 'Hello world' with index: '9' SENT +Message: 'Hello world' with index: '10' SENT +Message: 'Hello world' with index: '11' SENT +Publisher unmatched. +``` + +## XML profile playground + +The *eProsima Fast DDS* entities can be configured through an XML profile from the environment. +This is accomplished by setting the environment variable ``FASTDDS_DEFAULT_PROFILES_FILE`` to path to the XML profiles file: + +* Ubuntu ( / MacOS ) + +- Publisher profile: + + ```shell + user@machine:example_path$ export FASTDDS_DEFAULT_PROFILES_FILE=secure_publisher_profile.xml + ``` +- Subscriber profile: + + ```shell + user@machine:example_path$ export FASTDDS_DEFAULT_PROFILES_FILE=secure_subscriber_profile.xml + ``` + +* Windows + +- Publisher profile: + + ```powershell + example_path> set FASTDDS_DEFAULT_PROFILES_FILE=secure_publisher_profile.xml + ``` +- Subscriber profile: + + ```powershell + example_path> set FASTDDS_DEFAULT_PROFILES_FILE=secure_subscriber_profile.xml + ``` + +The example provides with an XML profiles files with certain QoS: + +- Reliable reliability: avoid sample loss. +- Transient local durability: enable late-join subscriber applications to receive previous samples. +- Keep-last history with high depth: ensure certain amount of previous samples for late-joiners. + +It also includes by default the builtin plugins required to provide secure communications. +Applying different configurations to the entities will change to a greater or lesser extent how the application behaves in relation to sample management. +Even when these settings affect the behavior of the sample management, the applications' output will be the similar. diff --git a/examples/cpp/security/SubscriberApp.cpp b/examples/cpp/security/SubscriberApp.cpp new file mode 100644 index 00000000000..03b498ec7c6 --- /dev/null +++ b/examples/cpp/security/SubscriberApp.cpp @@ -0,0 +1,170 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file SubscriberApp.cpp + * + */ + +#include "SubscriberApp.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +SubscriberApp::SubscriberApp( + const CLIParser::entity_config& config, + const std::string& topic_name) + : participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , type_(new HelloWorldPubSubType()) + , samples_(config.samples) + , received_samples_(0) + , stop_(false) +{ + // Create the participant + + auto factory = DomainParticipantFactory::get_instance(); + participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none()); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // Register the type + type_.register_type(participant_); + + // Create the subscriber + SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT; + participant_->get_default_subscriber_qos(sub_qos); + subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none()); + if (subscriber_ == nullptr) + { + throw std::runtime_error("Subscriber initialization failed"); + } + + // Create the topic + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_ = participant_->create_topic(topic_name, type_.get_type_name(), topic_qos); + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the reader + DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT; + subscriber_->get_default_datareader_qos(reader_qos); + reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all()); + if (reader_ == nullptr) + { + throw std::runtime_error("DataReader initialization failed"); + } +} + +SubscriberApp::~SubscriberApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void SubscriberApp::on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + std::cout << "Subscriber matched." << std::endl; + } + else if (info.current_count_change == -1) + { + std::cout << "Subscriber unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + } +} + +void SubscriberApp::on_data_available( + DataReader* reader) +{ + SampleInfo info; + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&hello_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + received_samples_++; + // Print Hello world message data + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' RECEIVED" << std::endl; + if (samples_ > 0 && (received_samples_ >= samples_)) + { + stop(); + } + } + } +} + +void SubscriberApp::run() +{ + std::unique_lock lck(terminate_cv_mtx_); + terminate_cv_.wait(lck, [&] + { + return is_stopped(); + }); +} + +bool SubscriberApp::is_stopped() +{ + return stop_.load(); +} + +void SubscriberApp::stop() +{ + stop_.store(true); + terminate_cv_.notify_all(); +} + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/security/SubscriberApp.hpp b/examples/cpp/security/SubscriberApp.hpp new file mode 100644 index 00000000000..f4a11661a0c --- /dev/null +++ b/examples/cpp/security/SubscriberApp.hpp @@ -0,0 +1,98 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file SubscriberApp.hpp + * + */ + +#ifndef FASTDDS_EXAMPLES_CPP_SECURITY__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_SECURITY__SUBSCRIBERAPP_HPP + +#include + +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorld.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace security { + +class SubscriberApp : public Application, public DataReaderListener +{ +public: + + SubscriberApp( + const CLIParser::entity_config& config, + const std::string& topic_name); + + ~SubscriberApp(); + + //! Subscription callback + void on_data_available( + DataReader* reader) override; + + //! Subscriber matched method + void on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) override; + + //! Run subscriber + void run() override; + + //! Trigger the end of execution + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Subscriber* subscriber_; + + Topic* topic_; + + DataReader* reader_; + + TypeSupport type_; + + uint16_t samples_; + + uint16_t received_samples_; + + std::atomic stop_; + + mutable std::mutex terminate_cv_mtx_; + + std::condition_variable terminate_cv_; +}; + +} // namespace security +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_SECURITY__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/governance.smime b/examples/cpp/security/certs/governance.smime similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/governance.smime rename to examples/cpp/security/certs/governance.smime diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/governance_dds_sec.xml b/examples/cpp/security/certs/governance_dds_sec.xml similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/governance_dds_sec.xml rename to examples/cpp/security/certs/governance_dds_sec.xml diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/maincacert.pem b/examples/cpp/security/certs/maincacert.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/maincacert.pem rename to examples/cpp/security/certs/maincacert.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/maincakey.pem b/examples/cpp/security/certs/maincakey.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/maincakey.pem rename to examples/cpp/security/certs/maincakey.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/mainpubcert.pem b/examples/cpp/security/certs/mainpubcert.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/mainpubcert.pem rename to examples/cpp/security/certs/mainpubcert.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/mainpubkey.pem b/examples/cpp/security/certs/mainpubkey.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/mainpubkey.pem rename to examples/cpp/security/certs/mainpubkey.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/mainsubcert.pem b/examples/cpp/security/certs/mainsubcert.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/mainsubcert.pem rename to examples/cpp/security/certs/mainsubcert.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/mainsubkey.pem b/examples/cpp/security/certs/mainsubkey.pem similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/mainsubkey.pem rename to examples/cpp/security/certs/mainsubkey.pem diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/permissions.smime b/examples/cpp/security/certs/permissions.smime similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/permissions.smime rename to examples/cpp/security/certs/permissions.smime diff --git a/examples/cpp/dds/SecureHelloWorldExample/certs/permissions_dds_sec.xml b/examples/cpp/security/certs/permissions_dds_sec.xml similarity index 100% rename from examples/cpp/dds/SecureHelloWorldExample/certs/permissions_dds_sec.xml rename to examples/cpp/security/certs/permissions_dds_sec.xml diff --git a/examples/cpp/security/main.cpp b/examples/cpp/security/main.cpp new file mode 100644 index 00000000000..12f013074ec --- /dev/null +++ b/examples/cpp/security/main.cpp @@ -0,0 +1,108 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file main.cpp + * + */ + +#include +#include +#include + +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" + +using eprosima::fastdds::dds::Log; + +using namespace eprosima::fastdds::examples::security; + +std::function stop_app_handler; +void signal_handler( + int signum) +{ + stop_app_handler(signum); +} + +int main( + int argc, + char** argv) +{ + auto ret = EXIT_SUCCESS; + const std::string topic_name = "HelloWorldTopic"; + CLIParser::security_config config = CLIParser::parse_cli_options(argc, argv); + uint16_t samples = 0; + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + samples = config.pub_config.samples; + break; + case CLIParser::EntityKind::SUBSCRIBER: + samples = config.sub_config.samples; + break; + default: + break; + } + + std::string app_name = CLIParser::parse_entity_kind(config.entity); + std::shared_ptr app; + + try + { + app = Application::make_app(config, topic_name); + } + catch (const std::runtime_error& e) + { + EPROSIMA_LOG_ERROR(app_name, e.what()); + ret = EXIT_FAILURE; + } + + if (EXIT_FAILURE != ret) + { + std::thread thread(&Application::run, app); + + if (samples == 0) + { + std::cout << app_name << " running. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + else + { + std::cout << app_name << " running for " << samples << " samples. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + + stop_app_handler = [&](int signum) + { + std::cout << "\n" << CLIParser::parse_signal(signum) << " received, stopping " << app_name + << " execution." << std::endl; + app->stop(); + }; + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + #ifndef _WIN32 + signal(SIGQUIT, signal_handler); + signal(SIGHUP, signal_handler); + #endif // _WIN32 + + thread.join(); + } + + Log::Reset(); + return ret; +} diff --git a/examples/cpp/security/secure_publisher_profile.xml b/examples/cpp/security/secure_publisher_profile.xml new file mode 100644 index 00000000000..ef41b920b60 --- /dev/null +++ b/examples/cpp/security/secure_publisher_profile.xml @@ -0,0 +1,76 @@ + + + + 0 + + hello_world_participant + + + + + + dds.sec.auth.plugin + builtin.PKI-DH + + + + dds.sec.auth.builtin.PKI-DH.identity_ca + file://${CERTS_PATH}/maincacert.pem + + + dds.sec.auth.builtin.PKI-DH.identity_certificate + file://${CERTS_PATH}/mainpubcert.pem + + + dds.sec.auth.builtin.PKI-DH.private_key + file://${CERTS_PATH}/mainpubkey.pem + + + + dds.sec.access.plugin + builtin.Access-Permissions + + + + dds.sec.access.builtin.Access-Permissions.permissions_ca + file://${CERTS_PATH}/maincacert.pem + + + dds.sec.access.builtin.Access-Permissions.governance + file://${CERTS_PATH}/governance.smime + + + dds.sec.access.builtin.Access-Permissions.permissions + file://${CERTS_PATH}/permissions.smime + + + + dds.sec.crypto.plugin + builtin.AES-GCM-GMAC + + + + + + + + + TRANSIENT_LOCAL + + + RELIABLE + + + + + KEEP_LAST + 100 + + + 100 + 1 + 100 + + + + diff --git a/examples/cpp/security/secure_subscriber_profile.xml b/examples/cpp/security/secure_subscriber_profile.xml new file mode 100644 index 00000000000..e1483c328ad --- /dev/null +++ b/examples/cpp/security/secure_subscriber_profile.xml @@ -0,0 +1,77 @@ + + + + 0 + + hello_world_participant + + + + + + dds.sec.auth.plugin + builtin.PKI-DH + + + + dds.sec.auth.builtin.PKI-DH.identity_ca + file://${CERTS_PATH}/maincacert.pem + + + dds.sec.auth.builtin.PKI-DH.identity_certificate + file://${CERTS_PATH}/mainsubcert.pem + + + dds.sec.auth.builtin.PKI-DH.private_key + file://${CERTS_PATH}/mainsubkey.pem + + + + dds.sec.access.plugin + builtin.Access-Permissions + + + + dds.sec.access.builtin.Access-Permissions.permissions_ca + file://${CERTS_PATH}/maincacert.pem + + + dds.sec.access.builtin.Access-Permissions.governance + file://${CERTS_PATH}/governance.smime + + + dds.sec.access.builtin.Access-Permissions.permissions + file://${CERTS_PATH}/permissions.smime + + + + dds.sec.crypto.plugin + builtin.AES-GCM-GMAC + + + + + + + + + + TRANSIENT_LOCAL + + + RELIABLE + + + + + KEEP_LAST + 100 + + + 100 + 1 + 100 + + + + diff --git a/examples/cpp/xtypes/Application.hpp b/examples/cpp/xtypes/Application.hpp index 94ad75ac43c..546e6ffff54 100644 --- a/examples/cpp/xtypes/Application.hpp +++ b/examples/cpp/xtypes/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_EXAMPLES_XTYPES_APPLICATION_HPP_ -#define _FASTDDS_EXAMPLES_XTYPES_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_XTYPES__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_XTYPES__APPLICATION_HPP #include @@ -53,4 +53,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_EXAMPLES_XTYPES_APPLICATION_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_XTYPES__APPLICATION_HPP diff --git a/examples/cpp/xtypes/CLIParser.hpp b/examples/cpp/xtypes/CLIParser.hpp index 0dd75aa08ec..6b006a0beb3 100644 --- a/examples/cpp/xtypes/CLIParser.hpp +++ b/examples/cpp/xtypes/CLIParser.hpp @@ -18,8 +18,8 @@ #include -#ifndef _FASTDDS_EXAMPLES_XTYPES_CLI_PARSER_HPP_ -#define _FASTDDS_EXAMPLES_XTYPES_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_XTYPES__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_XTYPES__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -246,4 +246,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_EXAMPLES_XTYPES_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_XTYPES__CLIPARSER_HPP diff --git a/examples/cpp/xtypes/PublisherApp.hpp b/examples/cpp/xtypes/PublisherApp.hpp index 37bf8ca4563..664dd0e45fa 100644 --- a/examples/cpp/xtypes/PublisherApp.hpp +++ b/examples/cpp/xtypes/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_EXAMPLES_XTYPES_PUBLISHER_APP_HPP_ -#define _FASTDDS_EXAMPLES_XTYPES_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_XTYPES__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_XTYPES__PUBLISHERAPP_HPP #include @@ -115,4 +115,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_EXAMPLES_XTYPES_PUBLISHER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_XTYPES__PUBLISHERAPP_HPP diff --git a/examples/cpp/xtypes/SubscriberApp.hpp b/examples/cpp/xtypes/SubscriberApp.hpp index 3b6be9b0480..c4e18ccda76 100644 --- a/examples/cpp/xtypes/SubscriberApp.hpp +++ b/examples/cpp/xtypes/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_EXAMPLES_XTYPES_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_EXAMPLES_XTYPES_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_XTYPES__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_XTYPES__SUBSCRIBERAPP_HPP #include @@ -112,4 +112,4 @@ class SubscriberApp : public Application, public DomainParticipantListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_EXAMPLES_XTYPES_SUBSCRIBER_APP_HPP_ */ +#endif // FASTDDS_EXAMPLES_CPP_XTYPES__SUBSCRIBERAPP_HPP diff --git a/test/examples/CMakeLists.txt b/test/examples/CMakeLists.txt index 36a497dc0ee..7dd4dfeedee 100644 --- a/test/examples/CMakeLists.txt +++ b/test/examples/CMakeLists.txt @@ -68,6 +68,11 @@ endif() # Find all pytest files for testing file(GLOB examples_python_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.py) +# Add security test only if security is enabled +if (NOT SECURITY) + list(FILTER examples_python_tests EXCLUDE REGEX "security") +endif() + # Configure the pytest files, and add a test for each one foreach(example_test ${examples_python_tests}) get_filename_component(example_name ${example_test} NAME_WE) diff --git a/test/examples/security.compose.yml b/test/examples/security.compose.yml new file mode 100644 index 00000000000..1abf5eddb90 --- /dev/null +++ b/test/examples/security.compose.yml @@ -0,0 +1,44 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# 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. +version: "3" + +services: + subscriber: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/security + CERTS_PATH: @PROJECT_BINARY_DIR@/examples/cpp/security/certs + FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/security/secure_subscriber_profile.xml + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/security@FILE_EXTENSION@ subscriber --samples 10" + + publisher: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/security + CERTS_PATH: @PROJECT_BINARY_DIR@/examples/cpp/security/certs + FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/security/secure_publisher_profile.xml + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/security@FILE_EXTENSION@ publisher --samples 10" + diff --git a/test/examples/test_security.py b/test/examples/test_security.py new file mode 100644 index 00000000000..b2bcc2c02a4 --- /dev/null +++ b/test/examples/test_security.py @@ -0,0 +1,54 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# 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. + +import subprocess + +def test_security(): + """.""" + ret = False + out = '' + try: + out = subprocess.check_output( + '@DOCKER_EXECUTABLE@ compose -f security.compose.yml up', + stderr=subprocess.STDOUT, + shell=True, + timeout=30 + ).decode().split('\n') + + sent = 0 + received = 0 + for line in out: + if 'SENT' in line: + sent += 1 + continue + + if 'RECEIVED' in line: + received += 1 + continue + + if sent != 0 and received != 0 and sent == received: + ret = True + else: + print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received) + + ' (expected: ' + str(sent) + ')') + raise subprocess.CalledProcessError(1, '') + + except subprocess.CalledProcessError: + for l in out: + print(l) + except subprocess.TimeoutExpired: + print('TIMEOUT') + print(out) + + assert(ret) diff --git a/versions.md b/versions.md index 0e089ecde11..2482d2e68ea 100644 --- a/versions.md +++ b/versions.md @@ -48,6 +48,7 @@ Forthcoming * Calling `DataReader::return_loan` returns `ReturnCode_t::RETCODE_OK` both for empty sequences and for sequences that were not loaned. * Refactor examples: * Hello world example with wait-sets and environment XML profiles. + * Security example with environment XML profiles. * Configuration example that condenses multiple QoS examples. Multiple configurations allowed through argument parsing. * Custom payload pool example that uses a user-defined payload pool instead of the default * X-Types example with dynamic type discovery and Hello world example compatibility.