diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 4a8bd5a625..3d8a010faa 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -464,6 +464,7 @@ set(ecal_header_cmn include/ecal/ecal_process.h include/ecal/ecal_process_severity.h include/ecal/ecal_publisher.h + include/ecal/ecal_publisher_config.h include/ecal/ecal_server.h include/ecal/ecal_service_info.h include/ecal/ecal_subscriber.h diff --git a/ecal/core/include/ecal/ecal_publisher_config.h b/ecal/core/include/ecal/ecal_publisher_config.h index 55710c6895..a1ee52208a 100644 --- a/ecal/core/include/ecal/ecal_publisher_config.h +++ b/ecal/core/include/ecal/ecal_publisher_config.h @@ -26,6 +26,8 @@ #include +#include + namespace eCAL { struct ECAL_API SHMPubConfig diff --git a/ecal/core/include/ecal/msg/capnproto/publisher.h b/ecal/core/include/ecal/msg/capnproto/publisher.h index 6108a2fd9a..35ff623c8c 100644 --- a/ecal/core/include/ecal/msg/capnproto/publisher.h +++ b/ecal/core/include/ecal/msg/capnproto/publisher.h @@ -101,7 +101,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) + CPublisher(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) : eCAL::CPublisher(topic_name_, GetDataTypeInformation(), config_) , builder(std::make_unique()) , root_builder(builder->initRoot()) @@ -150,7 +150,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/flatbuffers/publisher.h b/ecal/core/include/ecal/msg/flatbuffers/publisher.h index 1af1df9cc4..caae741322 100644 --- a/ecal/core/include/ecal/msg/flatbuffers/publisher.h +++ b/ecal/core/include/ecal/msg/flatbuffers/publisher.h @@ -53,7 +53,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -85,7 +85,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/core/include/ecal/msg/messagepack/publisher.h b/ecal/core/include/ecal/msg/messagepack/publisher.h index c5c859e66f..983e0042d4 100644 --- a/ecal/core/include/ecal/msg/messagepack/publisher.h +++ b/ecal/core/include/ecal/msg/messagepack/publisher.h @@ -56,7 +56,7 @@ namespace eCAL * @param topic_name_ Unique topic name. * @param config_ Optional configuration parameters. **/ - CPublisher(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) + CPublisher(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) : CMsgPublisher(topic_name_, GetDataTypeInformation(), config_) { } @@ -88,7 +88,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const eCAL::CPublisher::Config& config_ = {}) + bool Create(const std::string& topic_name_, const eCAL::PubConfig& config_ = {}) { return(CMsgPublisher::Create(topic_name_, GetDataTypeInformation(), config_)); } diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_multibuffer.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_multibuffer.cpp index f80b9584f5..95783ede4b 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_multibuffer.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_multibuffer.cpp @@ -26,9 +26,11 @@ #include -#define CMN_REGISTRATION_REFRESH 1000 -#define DATA_FLOW_TIME 50 -#define PAYLOAD_SIZE 1024 +enum { + CMN_REGISTRATION_REFRESH_MS = 1000, + DATA_FLOW_TIME_MS = 50, + PAYLOAD_SIZE_BYTE = 1024 +}; // a binary payload object for testing // full (WriteFull) and partial (WriteModified) writing @@ -68,7 +70,7 @@ class CBinaryPayload : public eCAL::CPayloadWriter std::vector multibuffer_pub_sub_test(int buffer_count, bool zero_copy, int publications, int bytes_to_read) { // create payload - CBinaryPayload binary_payload(PAYLOAD_SIZE); + CBinaryPayload binary_payload(PAYLOAD_SIZE_BYTE); // create subscriber for topic "A" eCAL::CSubscriber sub("A"); @@ -106,13 +108,13 @@ std::vector multibuffer_pub_sub_test(int buffer_count, bool zero_copy, int EXPECT_EQ(true, sub.AddReceiveCallback(lambda)); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // run publications for (int i = 0; i < publications; ++i) { - EXPECT_EQ(PAYLOAD_SIZE, pub.Send(binary_payload)); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + EXPECT_EQ(PAYLOAD_SIZE_BYTE, pub.Send(binary_payload)); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); } return received_content; diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp index cc6bc53170..4e18f043e6 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_receive_test.cpp @@ -28,7 +28,9 @@ #include -#define CMN_REGISTRATION_REFRESH 1000 +enum { + CMN_REGISTRATION_REFRESH_MS = 1000 +}; using namespace std::chrono_literals; @@ -76,7 +78,7 @@ TEST(core_cpp_pubsub, TimingSubscriberReceive) eCAL::string::CSubscriber sub("CLOCK"); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // Send nothing and make sure the functions return as specified std::string received; @@ -173,7 +175,7 @@ TEST(core_cpp_pubsub, SporadicEmptyReceives) eCAL::string::CSubscriber sub("CLOCK"); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // start publishing thread std::atomic pub_stop(false); diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp index 79587b1b39..6090b16ce2 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_test.cpp @@ -26,9 +26,11 @@ #include -#define CMN_REGISTRATION_REFRESH 1000 -#define DATA_FLOW_TIME 50 -#define PAYLOAD_SIZE 1024 +enum { + CMN_REGISTRATION_REFRESH_MS = 1000, + DATA_FLOW_TIME_MS = 50, + PAYLOAD_SIZE_BYTE = 1024 +}; namespace { @@ -69,7 +71,7 @@ TEST(core_cpp_pubsub, LeakedPubSub) eCAL::CPublisher pub("foo"); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // start publishing thread std::atomic pub_stop(false); @@ -201,7 +203,7 @@ TEST(core_cpp_pubsub, CreateDestroy) TEST(core_cpp_pubsub, SimpleMessage1) { // default send / receive strings - std::string send_s = CreatePayLoad(PAYLOAD_SIZE); + std::string send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE); std::string recv_s; // initialize eCAL API @@ -217,20 +219,20 @@ TEST(core_cpp_pubsub, SimpleMessage1) eCAL::CSubscriber sub("foo"); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content EXPECT_EQ(send_s.size(), pub.Send(send_s)); - // receive content with DATA_FLOW_TIME ms timeout + // receive content with DATA_FLOW_TIME_MS timeout recv_s.clear(); - EXPECT_EQ(true, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME)); + EXPECT_EQ(true, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME_MS)); EXPECT_EQ(send_s.size(), recv_s.size()); - // receive content with DATA_FLOW_TIME ms timeout + // receive content with DATA_FLOW_TIME_MS timeout // should return because no new publishing recv_s.clear(); - EXPECT_EQ(false, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME)); + EXPECT_EQ(false, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME_MS)); EXPECT_EQ(0, recv_s.size()); // destroy publisher @@ -246,7 +248,7 @@ TEST(core_cpp_pubsub, SimpleMessage1) TEST(core_cpp_pubsub, SimpleMessage2) { // default send / receive strings - std::string send_s = CreatePayLoad(PAYLOAD_SIZE); + std::string send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE); std::string recv_s; // initialize eCAL API @@ -262,14 +264,14 @@ TEST(core_cpp_pubsub, SimpleMessage2) eCAL::CPublisher pub("foo"); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content EXPECT_EQ(send_s.size(), pub.Send(send_s)); - // receive content with DATA_FLOW_TIME ms timeout + // receive content with DATA_FLOW_TIME_MS timeout recv_s.clear(); - EXPECT_EQ(true, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME)); + EXPECT_EQ(true, sub.ReceiveBuffer(recv_s, nullptr, DATA_FLOW_TIME_MS)); EXPECT_EQ(send_s.size(), recv_s.size()); // destroy publisher @@ -285,7 +287,7 @@ TEST(core_cpp_pubsub, SimpleMessage2) TEST(core_cpp_pubsub, SimpleMessageCB) { // default send string - std::string send_s = CreatePayLoad(PAYLOAD_SIZE); + std::string send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE); // initialize eCAL API eCAL::Initialize(0, nullptr, "pubsub_test"); @@ -303,14 +305,14 @@ TEST(core_cpp_pubsub, SimpleMessageCB) EXPECT_EQ(true, sub.AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -323,7 +325,7 @@ TEST(core_cpp_pubsub, SimpleMessageCB) EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(0, g_callback_received_bytes); @@ -336,7 +338,7 @@ TEST(core_cpp_pubsub, SimpleMessageCB) EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -349,7 +351,7 @@ TEST(core_cpp_pubsub, SimpleMessageCB) EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(0, g_callback_received_bytes); @@ -364,7 +366,7 @@ TEST(core_cpp_pubsub, SimpleMessageCB) TEST(core_cpp_pubsub, DynamicSizeCB) { // default send string - std::string send_s = CreatePayLoad(PAYLOAD_SIZE); + std::string send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE); // initialize eCAL API eCAL::Initialize(0, nullptr, "pubsub_test"); @@ -382,27 +384,27 @@ TEST(core_cpp_pubsub, DynamicSizeCB) EXPECT_EQ(true, sub.AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); // increase payload size - send_s = CreatePayLoad(PAYLOAD_SIZE*10); + send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE*10); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub.Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -420,7 +422,7 @@ TEST(core_cpp_pubsub, DynamicSizeCB) TEST(core_cpp_pubsub, DynamicCreate) { // default send string - std::string send_s = CreatePayLoad(PAYLOAD_SIZE); + std::string send_s = CreatePayLoad(PAYLOAD_SIZE_BYTE); // initialize eCAL API eCAL::Initialize(0, nullptr, "pubsub_test"); @@ -440,14 +442,14 @@ TEST(core_cpp_pubsub, DynamicCreate) EXPECT_EQ(true, sub->AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub->Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -463,14 +465,14 @@ TEST(core_cpp_pubsub, DynamicCreate) EXPECT_EQ(true, sub->AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub->Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -485,14 +487,14 @@ TEST(core_cpp_pubsub, DynamicCreate) EXPECT_EQ(true, sub->AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); // send content g_callback_received_bytes = 0; EXPECT_EQ(send_s.size(), pub->Send(send_s)); // let the data flow - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_test_shm.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_test_shm.cpp index 4c7480483e..11436f7984 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_test_shm.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_test_shm.cpp @@ -26,8 +26,10 @@ #include -#define CMN_REGISTRATION_REFRESH 1000 -#define DATA_FLOW_TIME 50 +enum { + CMN_REGISTRATION_REFRESH_MS = 1000, + DATA_FLOW_TIME_MS = 50, +}; namespace { @@ -69,16 +71,16 @@ TEST(core_cpp_pubsub, ZeroPayloadMessageSHM) EXPECT_EQ(true, sub.AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); g_callback_received_bytes = 0; g_callback_received_count = 0; EXPECT_EQ(send_s.size(), pub.Send(send_s)); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); EXPECT_EQ(send_s.size(), pub.Send(nullptr, 0)); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -97,9 +99,9 @@ TEST(core_cpp_pubsub, ZeroPayloadMessageSHM) TEST(core_cpp_pubsub, MultipleSendsSHM) { // default send string - std::vector send_vector{ "this", "is", "a", "", "testtest" }; + const std::vector send_vector{ "this", "is", "a", "", "testtest" }; std::string last_received_msg; - long long last_received_timestamp; + long long last_received_timestamp(0); // initialize eCAL API eCAL::Initialize(0, nullptr, "pubsub_test"); @@ -129,12 +131,12 @@ TEST(core_cpp_pubsub, MultipleSendsSHM) EXPECT_TRUE(sub.AddReceiveCallback(save_data)); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); long long timestamp = 1; for (const auto& elem : send_vector) { pub.Send(elem, timestamp); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); EXPECT_EQ(last_received_msg, elem); EXPECT_EQ(last_received_timestamp, timestamp); ++timestamp; diff --git a/ecal/tests/cpp/pubsub_test/src/pubsub_test_udp.cpp b/ecal/tests/cpp/pubsub_test/src/pubsub_test_udp.cpp index 5e1a4e7dcb..0093d3cb5c 100644 --- a/ecal/tests/cpp/pubsub_test/src/pubsub_test_udp.cpp +++ b/ecal/tests/cpp/pubsub_test/src/pubsub_test_udp.cpp @@ -26,8 +26,10 @@ #include -#define CMN_REGISTRATION_REFRESH 1000 -#define DATA_FLOW_TIME 50 +enum { + CMN_REGISTRATION_REFRESH_MS = 1000, + DATA_FLOW_TIME_MS = 50, +}; namespace { @@ -44,7 +46,7 @@ namespace TEST(core_cpp_pubsub, ZeroPayloadMessageUDP) { // default send string - std::string send_s; + const std::string send_s; // initialize eCAL API eCAL::Initialize(0, nullptr, "pubsub_test"); @@ -69,16 +71,16 @@ TEST(core_cpp_pubsub, ZeroPayloadMessageUDP) EXPECT_EQ(true, sub.AddReceiveCallback(std::bind(OnReceive, std::placeholders::_1, std::placeholders::_2))); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); g_callback_received_bytes = 0; g_callback_received_count = 0; EXPECT_EQ(send_s.size(), pub.Send(send_s)); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); EXPECT_EQ(send_s.size(), pub.Send(nullptr, 0)); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); // check callback receive EXPECT_EQ(send_s.size(), g_callback_received_bytes); @@ -129,12 +131,12 @@ TEST(core_cpp_pubsub, MultipleSendsUDP) EXPECT_TRUE(sub.AddReceiveCallback(save_data)); // let's match them - eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH); + eCAL::Process::SleepMS(2 * CMN_REGISTRATION_REFRESH_MS); long long timestamp = 1; for (const auto& elem : send_vector) { pub.Send(elem, timestamp); - eCAL::Process::SleepMS(DATA_FLOW_TIME); + eCAL::Process::SleepMS(DATA_FLOW_TIME_MS); EXPECT_EQ(last_received_msg, elem); EXPECT_EQ(last_received_timestamp, timestamp); ++timestamp;