diff --git a/CMakeLists.txt b/CMakeLists.txt index 758c19d..8d9ff02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,9 +72,9 @@ endif() # additional builds (adapt to your needs) # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ option(ECAL_CORE_BUILD_SAMPLES "Build the eCAL samples" ON) -option(ECAL_CORE_BUILD_SAMPLES_PROTOBUF "Build the eCAL samples using google protobuf message definition" OFF) +option(ECAL_CORE_BUILD_SAMPLES_PROTOBUF "Build the eCAL samples using google protobuf message definition" ON) option(ECAL_CORE_BUILD_TESTS "Build the eCAL google tests" ON) -option(ECAL_CORE_BUILD_TESTS_PROTOBUF "Build the eCAL google tests using google protobuf message definition" OFF) +option(ECAL_CORE_BUILD_TESTS_PROTOBUF "Build the eCAL google tests using google protobuf message definition" ON) # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ # core internal feature configuration (adapt to your needs) @@ -82,7 +82,7 @@ option(ECAL_CORE_BUILD_TESTS_PROTOBUF "Build the eCAL google option(ECAL_CORE_CONFIG_INIFILE "Enables to configure eCAL via ecal.ini file" ON) option(ECAL_CORE_COMMAND_LINE "Enables eCAL application cmd line interfaces" ON) option(ECAL_CORE_REGISTRATION "Enables the eCAL registration layer" ON) -option(ECAL_CORE_MONITORING "Enables the eCAL monitoring functionality" OFF) +option(ECAL_CORE_MONITORING "Enables the eCAL monitoring functionality" ON) option(ECAL_CORE_PUBLISHER "Enables the eCAL publisher functionality" ON) option(ECAL_CORE_SUBSCRIBER "Enables the eCAL subscriber functionality" ON) option(ECAL_CORE_SERVICE "Enables the eCAL server/client functionality" ON) @@ -98,7 +98,7 @@ option(ECAL_CORE_REGISTRATION_SHM "Enables the eCAL regis # core transport layer options (change with care) # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ option(ECAL_CORE_TRANSPORT_UDP "Enables the eCAL to transport payload via UDP multicast" ON) -option(ECAL_CORE_TRANSPORT_TCP "Enables the eCAL to transport payload via TCP" OFF) +option(ECAL_CORE_TRANSPORT_TCP "Enables the eCAL to transport payload via TCP" ON) option(ECAL_CORE_TRANSPORT_SHM "Enables the eCAL to transport payload via local shared memory" ON) # ------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 8955f95..e77754f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -107,6 +107,7 @@ if(ECAL_CORE_SUBSCRIBER) add_subdirectory(cpp/pubsub/protobuf/proto_dyn_json_rec) if(ECAL_CORE_MONITORING) add_subdirectory(cpp/pubsub/protobuf/proto_dyn_rec) + add_subdirectory(cpp/pubsub/protobuf/proto_dyn_snd) endif() endif() endif() diff --git a/samples/cpp/pubsub/protobuf/proto_dyn_snd/CMakeLists.txt b/samples/cpp/pubsub/protobuf/proto_dyn_snd/CMakeLists.txt new file mode 100644 index 0000000..b40e685 --- /dev/null +++ b/samples/cpp/pubsub/protobuf/proto_dyn_snd/CMakeLists.txt @@ -0,0 +1,49 @@ +# ========================= eCAL LICENSE ================================= +# +# Copyright (C) 2016 - 2019 Continental Corporation +# +# 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. +# +# ========================= eCAL LICENSE ================================= + +cmake_minimum_required(VERSION 3.10) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +project(proto_dyn_snd) + +find_package(eCAL REQUIRED) +find_package(Protobuf REQUIRED) + +set(proto_dyn_snd_src + src/proto_dyn_snd.cpp +) + +set(proto_dyn_snd_proto + ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/animal.proto + ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/house.proto + ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/person.proto +) +ecal_add_sample(${PROJECT_NAME} ${proto_dyn_snd_src}) +PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf ${proto_dyn_snd_proto}) + +target_link_libraries(${PROJECT_NAME} + eCAL::core + protobuf::libprotobuf +) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) + +ecal_install_sample(${PROJECT_NAME}) + +set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/pubsub/protobuf) diff --git a/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/proto_dyn_snd.cpp b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/proto_dyn_snd.cpp new file mode 100644 index 0000000..3604a8d --- /dev/null +++ b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/proto_dyn_snd.cpp @@ -0,0 +1,99 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +#include +#include + +#include + +#include "person.pb.h" + +int main(int argc, char **argv) +{ + // initialize eCAL API + eCAL::Initialize(argc, argv, "person publisher dynamic"); + + // set process state + eCAL::Process::SetState(proc_sev_healthy, proc_sev_level1, "I feel good !"); + + // create a dynamic publisher (topic name "person") + eCAL::protobuf::CDynamicPublisher pub1("person", std::make_shared()); + std::shared_ptr person1 = pub1.GetAs(); + + // create a dynamic publisher (topic name "person") + eCAL::protobuf::CDynamicPublisher pub2("person", "pb.People.Person"); + std::shared_ptr person2 = pub2.GetAs(); + + // set person1 object content + person1->set_name("Max"); + person1->set_stype(pb::People::Person_SType_MALE); + person1->set_email("max@mail.net"); + person1->mutable_dog()->set_name("Brandy"); + person1->mutable_house()->set_rooms(4); + + // set person2 object content + person2->set_name("Romy"); + person2->set_stype(pb::People::Person_SType_FEMALE); + person2->set_email("romy@mail.net"); + person2->mutable_dog()->set_name("Gorky"); + person2->mutable_house()->set_rooms(4); + + // enter main loop + auto cnt = 0; + std::shared_ptr person; + + while(eCAL::Ok()) + { + if (++cnt % 2) + { + // modify and send the person1 object + person1->set_id(cnt); + pub1.Send(); + + // for later printing + person = person1; + } + else + { + // modify and send the person2 object + person2->set_id(cnt); + pub2.Send(); + + // for later printing + person = person2; + } + + // print current person message + std::cout << "person id : " << person->id() << std::endl; + std::cout << "person name : " << person->name() << std::endl; + std::cout << "person stype : " << person->stype() << std::endl; + std::cout << "person email : " << person->email() << std::endl; + std::cout << "dog.name : " << person->dog().name() << std::endl; + std::cout << "house.rooms : " << person->house().rooms() << std::endl; + std::cout << std::endl; + + // sleep 500 ms + eCAL::Process::SleepMS(500); + } + + // finalize eCAL API + eCAL::Finalize(); + + return(0); +} diff --git a/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/animal.proto b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/animal.proto new file mode 100644 index 0000000..625a78d --- /dev/null +++ b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/animal.proto @@ -0,0 +1,28 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +syntax = "proto3"; + +package pb.Animal; + +message Dog +{ + string name = 1; + string colour = 2; +} diff --git a/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/house.proto b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/house.proto new file mode 100644 index 0000000..fbe8cce --- /dev/null +++ b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/house.proto @@ -0,0 +1,27 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +syntax = "proto3"; + +package pb.Environment; + +message House +{ + int32 rooms = 1; +} diff --git a/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/person.proto b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/person.proto new file mode 100644 index 0000000..4200a43 --- /dev/null +++ b/samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/person.proto @@ -0,0 +1,42 @@ +/* ========================= eCAL LICENSE ================================= + * + * Copyright (C) 2016 - 2019 Continental Corporation + * + * 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. + * + * ========================= eCAL LICENSE ================================= +*/ + +syntax = "proto3"; + +import "animal.proto"; +import "house.proto"; + +package pb.People; + +message Person +{ + enum SType + { + MALE = 0; + FEMALE = 1; + } + + int32 id = 1; + string name = 2; + SType stype = 3; + string email = 4; + + Animal.Dog dog = 5; + Environment.House house = 6; +} diff --git a/src/core/include/ecal/ecal_client.h b/src/core/include/ecal/ecal_client.h index 3666f39..e6f8435 100644 --- a/src/core/include/ecal/ecal_client.h +++ b/src/core/include/ecal/ecal_client.h @@ -54,7 +54,7 @@ namespace eCAL * * @param service_name_ Unique service name. **/ - ECAL_API CServiceClient(const std::string& service_name_); + ECAL_API explicit CServiceClient(const std::string& service_name_); /** * @brief Destructor. @@ -64,12 +64,12 @@ namespace eCAL /** * @brief CServiceClients are non-copyable **/ - ECAL_API CServiceClient(const CServiceClient&) = delete; + CServiceClient(const CServiceClient&) = delete; /** * @brief CServiceClients are non-copyable **/ - ECAL_API CServiceClient& operator=(const CServiceClient&) = delete; + CServiceClient& operator=(const CServiceClient&) = delete; /** * @brief Creates this object. diff --git a/src/core/include/ecal/ecal_process.h b/src/core/include/ecal/ecal_process.h index f37d905..1282d45 100644 --- a/src/core/include/ecal/ecal_process.h +++ b/src/core/include/ecal/ecal_process.h @@ -98,7 +98,7 @@ namespace eCAL * * @param time_ns_ Time to sleep in ns. **/ - ECAL_API void SleepNS(const long long time_ns_); + ECAL_API void SleepNS(long long time_ns_); /** * @brief Sleep current thread. diff --git a/src/core/include/ecal/ecal_publisher.h b/src/core/include/ecal/ecal_publisher.h index 7d6c1e3..06aa4c6 100644 --- a/src/core/include/ecal/ecal_publisher.h +++ b/src/core/include/ecal/ecal_publisher.h @@ -90,7 +90,7 @@ namespace eCAL * * @param topic_name_ Unique topic name. **/ - ECAL_API CPublisher(const std::string& topic_name_); + ECAL_API explicit CPublisher(const std::string& topic_name_); /** * @brief Destructor. @@ -100,12 +100,12 @@ namespace eCAL /** * @brief CPublishers are non-copyable **/ - ECAL_API CPublisher(const CPublisher&) = delete; + CPublisher(const CPublisher&) = delete; /** * @brief CPublishers are non-copyable **/ - ECAL_API CPublisher& operator=(const CPublisher&) = delete; + CPublisher& operator=(const CPublisher&) = delete; /** * @brief CPublishers are move-enabled @@ -125,7 +125,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_); + ECAL_API virtual bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_); /** * @brief Creates this object. @@ -134,14 +134,14 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_); + ECAL_API virtual bool Create(const std::string& topic_name_); /** * @brief Destroys this object. * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Destroy(); + ECAL_API virtual bool Destroy(); /** * @brief Setup topic information. diff --git a/src/core/include/ecal/ecal_server.h b/src/core/include/ecal/ecal_server.h index 3491cce..c8ea77c 100644 --- a/src/core/include/ecal/ecal_server.h +++ b/src/core/include/ecal/ecal_server.h @@ -53,7 +53,7 @@ namespace eCAL * * @param service_name_ Unique service name. **/ - ECAL_API CServiceServer(const std::string& service_name_); + ECAL_API explicit CServiceServer(const std::string& service_name_); /** * @brief Destructor. @@ -63,12 +63,12 @@ namespace eCAL /** * @brief CServiceServers are non-copyable **/ - ECAL_API CServiceServer(const CServiceServer&) = delete; + CServiceServer(const CServiceServer&) = delete; /** * @brief CServiceServers are non-copyable **/ - ECAL_API CServiceServer& operator=(const CServiceServer&) = delete; + CServiceServer& operator=(const CServiceServer&) = delete; /** * @brief Creates this object. diff --git a/src/core/include/ecal/ecal_subscriber.h b/src/core/include/ecal/ecal_subscriber.h index 32741ca..c24f59d 100644 --- a/src/core/include/ecal/ecal_subscriber.h +++ b/src/core/include/ecal/ecal_subscriber.h @@ -102,7 +102,7 @@ namespace eCAL * * @param topic_name_ Unique topic name. **/ - ECAL_API CSubscriber(const std::string& topic_name_); + ECAL_API explicit CSubscriber(const std::string& topic_name_); /** * @brief Destructor. @@ -112,12 +112,12 @@ namespace eCAL /** * @brief CSubscribers are non-copyable **/ - ECAL_API CSubscriber(const CSubscriber&) = delete; + CSubscriber(const CSubscriber&) = delete; /** * @brief CSubscribers are non-copyable **/ - ECAL_API CSubscriber& operator=(const CSubscriber&) = delete; + CSubscriber& operator=(const CSubscriber&) = delete; /** * @brief CSubscribers are move-enabled @@ -136,7 +136,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_); + ECAL_API virtual bool Create(const std::string& topic_name_); /** * @brief Creates this object. @@ -146,14 +146,14 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_); + ECAL_API virtual bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_); /** * @brief Destroys this object. * * @return true if it succeeds, false if it fails. **/ - ECAL_API bool Destroy(); + ECAL_API virtual bool Destroy(); /** * @brief Set a set of id's to prefiltering topics (see CPublisher::SetID). diff --git a/src/core/include/ecal/ecal_types.h b/src/core/include/ecal/ecal_types.h index 3c946cc..14187ea 100644 --- a/src/core/include/ecal/ecal_types.h +++ b/src/core/include/ecal/ecal_types.h @@ -50,27 +50,6 @@ namespace eCAL //!< @endcond }; - /** - * @brief Optional compile time information associated with a given topic - * (necessary for reflection / runtime type checking) - **/ - struct STopicInformation - { - SDataTypeInformation topic_type; //!< Data type description of the topic - - //!< @cond - bool operator==(const STopicInformation& other) const - { - return topic_type == other.topic_type; - } - - bool operator!=(const STopicInformation& other) const - { - return !(*this == other); - } - //!< @endcond - }; - /** * @brief Optional compile time information associated with a given service method * (necessary for reflection / runtime type checking) diff --git a/src/core/include/ecal/msg/dynamic.h b/src/core/include/ecal/msg/dynamic.h index 6f85fa8..7f7b2fe 100644 --- a/src/core/include/ecal/msg/dynamic.h +++ b/src/core/include/ecal/msg/dynamic.h @@ -34,8 +34,8 @@ namespace eCAL class DynamicReflectionException : public std::exception { public: - DynamicReflectionException(const std::string& message) : message_(message) {} - virtual const char* what() const throw() { return message_.c_str(); } + explicit DynamicReflectionException(const std::string& message) : message_(message) {} + const char* what() const noexcept override { return message_.c_str(); } private: std::string message_; }; diff --git a/src/core/include/ecal/msg/protobuf/client.h b/src/core/include/ecal/msg/protobuf/client.h index c96f1d5..eac51be 100644 --- a/src/core/include/ecal/msg/protobuf/client.h +++ b/src/core/include/ecal/msg/protobuf/client.h @@ -65,7 +65,7 @@ namespace eCAL * * @param service_name_ Unique service name. **/ - CServiceClient(const std::string& service_name_) + explicit CServiceClient(const std::string& service_name_) { Create(service_name_); } @@ -177,7 +177,7 @@ namespace eCAL SetHostName(host_name_); if (Call(method_name_, request_.SerializeAsString(), timeout_, &service_response_vec)) { - if (service_response_vec.size() > 0) + if (!service_response_vec.empty()) { service_response_ = service_response_vec[0]; response_.ParseFromString(service_response_vec[0].response); diff --git a/src/core/include/ecal/msg/protobuf/ecal_proto_dyn.h b/src/core/include/ecal/msg/protobuf/ecal_proto_dyn.h index 1b4f15a..2041770 100644 --- a/src/core/include/ecal/msg/protobuf/ecal_proto_dyn.h +++ b/src/core/include/ecal/msg/protobuf/ecal_proto_dyn.h @@ -170,7 +170,7 @@ namespace eCAL * * @return true if succeeded otherwise false (details see error_s_) **/ - bool GetFileDescriptorFromString(const std::string& proto_string_, google::protobuf::FileDescriptorProto* file_desc_proto_, std::string& error_s_); + static bool GetFileDescriptorFromString(const std::string& proto_string_, google::protobuf::FileDescriptorProto* file_desc_proto_, std::string& error_s_); protected: google::protobuf::DescriptorPool m_descriptor_pool; @@ -180,15 +180,15 @@ namespace eCAL class ParserErrorCollector : public google::protobuf::io::ErrorCollector { public: - ParserErrorCollector() {} - ~ParserErrorCollector() {} + ParserErrorCollector() = default; + ~ParserErrorCollector() override = default; std::string Get() { return (m_ss.str()); } // Indicates that there was an error in the input at the given line and // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. - void AddError(int line_, int column_, const std::string& msg_) + void AddError(int line_, int column_, const std::string& msg_) override { Add(line_, column_, "ERROR: " + msg_); } @@ -196,7 +196,7 @@ namespace eCAL // Indicates that there was a warning in the input at the given line and // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. - void AddWarning(int line_, int column_, const std::string& msg_) + void AddWarning(int line_, int column_, const std::string& msg_) override { Add(line_, column_, "WARNING: " + msg_); } @@ -213,8 +213,8 @@ namespace eCAL class DescriptorErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector { public: - DescriptorErrorCollector() {} - ~DescriptorErrorCollector() {} + DescriptorErrorCollector() = default; + ~DescriptorErrorCollector() override = default; std::string Get() { return (m_ss.str()); } @@ -224,7 +224,7 @@ namespace eCAL const google::protobuf::Message* descriptor, // Descriptor of the erroneous element. ErrorLocation location, // One of the location constants, above. const std::string& message // Human-readable error message. - ) + ) override { Add(filename, element_name, descriptor, location, "ERROR: " + message); } @@ -235,7 +235,7 @@ namespace eCAL const google::protobuf::Message* descriptor, // Descriptor of the erroneous element. ErrorLocation location, // One of the location constants, above. const std::string& message // Human-readable error message. - ) + ) override { Add(filename, element_name, descriptor, location, "WARNING: " + message); } diff --git a/src/core/include/ecal/msg/protobuf/publisher.h b/src/core/include/ecal/msg/protobuf/publisher.h index 894fc19..bc65dd9 100644 --- a/src/core/include/ecal/msg/protobuf/publisher.h +++ b/src/core/include/ecal/msg/protobuf/publisher.h @@ -76,11 +76,10 @@ namespace eCAL } size_t GetSize() override { - size_t size(0); #if GOOGLE_PROTOBUF_VERSION >= 3001000 - size = static_cast(message.ByteSizeLong()); + auto size = static_cast(message.ByteSizeLong()); #else - size = static_cast(message.ByteSize()); + auto size = static_cast(message.ByteSize()); #endif return(size); }; @@ -143,7 +142,7 @@ namespace eCAL * * @return True if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_) + bool Create(const std::string& topic_name_) override { return(eCAL::CPublisher::Create(topic_name_, GetDataTypeInformation())); } diff --git a/src/core/include/ecal/msg/protobuf/server.h b/src/core/include/ecal/msg/protobuf/server.h index 2f6cb8c..67c897c 100644 --- a/src/core/include/ecal/msg/protobuf/server.h +++ b/src/core/include/ecal/msg/protobuf/server.h @@ -67,7 +67,7 @@ namespace eCAL * * @param service_ Google protobuf service instance. **/ - CServiceServer(std::shared_ptr service_) : m_service(nullptr) + explicit CServiceServer(std::shared_ptr service_) : m_service(nullptr) { Create(service_); } @@ -86,7 +86,7 @@ namespace eCAL /** * @brief Destructor. **/ - ~CServiceServer() + ~CServiceServer() override { Destroy(); } diff --git a/src/core/include/ecal/msg/subscriber.h b/src/core/include/ecal/msg/subscriber.h index f7c7c9c..13d82c4 100644 --- a/src/core/include/ecal/msg/subscriber.h +++ b/src/core/include/ecal/msg/subscriber.h @@ -64,7 +64,7 @@ namespace eCAL { } - virtual ~CMsgSubscriber() = default; + ~CMsgSubscriber() override = default; /** * @brief Copy Constructor is not available. @@ -123,7 +123,7 @@ namespace eCAL * * @return true if it succeeds, false if it fails. **/ - bool Create(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_) + bool Create(const std::string& topic_name_, const struct SDataTypeInformation& topic_info_) override { return(CSubscriber::Create(topic_name_, topic_info_)); } @@ -133,7 +133,7 @@ namespace eCAL * * @return true if it succeeds, false if it fails. **/ - bool Destroy() + bool Destroy() override { RemReceiveCallback(); return(CSubscriber::Destroy()); diff --git a/src/core/include/ecal/types/monitoring.h b/src/core/include/ecal/types/monitoring.h index 7007560..0e293f1 100644 --- a/src/core/include/ecal/types/monitoring.h +++ b/src/core/include/ecal/types/monitoring.h @@ -179,6 +179,7 @@ namespace eCAL { rclock = 0; pid = 0; + version = 0; tcp_port_v0 = 0; tcp_port_v1 = 0; }; @@ -203,8 +204,9 @@ namespace eCAL { SClientMon() { - rclock = 0; - pid = 0; + rclock = 0; + pid = 0; + version = 0; }; int32_t rclock; //; using reference = typename Alloc::reference; - using const_reference = typename Alloc::const_reference; - using difference_type = typename Alloc::difference_type; using size_type = typename Alloc::size_type; using key_type = Key; using mapped_type = T; @@ -68,13 +66,11 @@ namespace eCAL friend class const_iterator; public: - using iterator_category = std::bidirectional_iterator_tag; - using value_type = std::pair; - using difference_type = std::ptrdiff_t; - using pointer = std::pair*; - using reference = std::pair&; + using value_type = std::pair; + using pointer = std::pair*; + using reference = std::pair&; - iterator(const typename key_to_value_type::iterator _it) + explicit iterator(const typename key_to_value_type::iterator _it) : it(_it) {} @@ -106,17 +102,15 @@ namespace eCAL class const_iterator { public: - using iterator_category = std::bidirectional_iterator_tag; - using value_type = std::pair; - using difference_type = std::ptrdiff_t; - using pointer = std::pair*; - using reference = std::pair&; + using value_type = std::pair; + using pointer = std::pair*; + using reference = std::pair&; - const_iterator(const iterator& other) + explicit const_iterator(const iterator& other) : it(other.it) {} - const_iterator(const typename key_to_value_type::const_iterator _it) + explicit const_iterator(const typename key_to_value_type::const_iterator _it) : it(_it) {} @@ -149,7 +143,7 @@ namespace eCAL // Constructor specifies the timeout of the map CExpMap() : _timeout(std::chrono::milliseconds(5000)) {}; - CExpMap(clock_type::duration t) : _timeout(t) {}; + explicit CExpMap(clock_type::duration t) : _timeout(t) {}; /** * @brief set expiration time diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d20aeb8..b614a93 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,7 +28,7 @@ if(ECAL_CORE_REGISTRATION_SHM OR ECAL_CORE_TRANSPORT_SHM) add_subdirectory(io_memfile_test) endif() -if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER) +if(ECAL_CORE_REGISTRATION AND ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER) add_subdirectory(core_test) if(ECAL_CORE_TRANSPORT_SHM OR ECAL_CORE_TRANSPORT_UDP) # this test is running for shm and udp layer only, needs to be fixed for tcp add_subdirectory(pubsub_test) diff --git a/tests/clientserver_proto_test/src/clientserver_test_proto.cpp b/tests/clientserver_proto_test/src/clientserver_test_proto.cpp index 4ccf4e6..d717a8d 100644 --- a/tests/clientserver_proto_test/src/clientserver_test_proto.cpp +++ b/tests/clientserver_proto_test/src/clientserver_test_proto.cpp @@ -40,7 +40,7 @@ class MathServiceImpl : public MathService { public: - virtual void Add(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) + void Add(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) override { // print request and std::cout << "Received request MathService / Add : " << request_->inp1() << " and " << request_->inp2() << std::endl << std::endl; @@ -48,7 +48,7 @@ class MathServiceImpl : public MathService response_->set_out(request_->inp1() + request_->inp2()); } - virtual void Multiply(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) + void Multiply(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) override { // print request and std::cout << "Received request MathService / Multiply : " << request_->inp1() << " and " << request_->inp2() << std::endl << std::endl; @@ -56,7 +56,7 @@ class MathServiceImpl : public MathService response_->set_out(request_->inp1() * request_->inp2()); } - virtual void Divide(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) + void Divide(::google::protobuf::RpcController* /* controller_ */, const ::SFloatTuple* request_, ::SFloat* response_, ::google::protobuf::Closure* /* done_ */) override { // print request and std::cout << "Received request MathService / Divide : " << request_->inp1() << " and " << request_->inp2() << std::endl << std::endl; @@ -146,7 +146,7 @@ TEST(ClientServerProto, ClientServerProtoCallback) class PingServiceImpl : public PingService { public: - void Ping(::google::protobuf::RpcController* /* controller_ */, const ::PingRequest* request_, ::PingResponse* response_, ::google::protobuf::Closure* /* done_ */) + void Ping(::google::protobuf::RpcController* /* controller_ */, const ::PingRequest* request_, ::PingResponse* response_, ::google::protobuf::Closure* /* done_ */) override { // print request and std::cout << "Received request PingService / Ping : " << request_->message() << std::endl << std::endl; @@ -176,7 +176,7 @@ TEST(ClientServerProto, ClientServerProtoBlocking) ping_request.set_message("PING"); ping_client.Call("Ping", ping_request, -1, &service_response_vec); std::cout << std::endl << "Ping method called with message : " << ping_request.message() << std::endl; - for (auto service_response : service_response_vec) + for (const auto& service_response : service_response_vec) { EXPECT_EQ(call_state_executed, service_response.call_state); switch (service_response.call_state) diff --git a/tests/clientserver_test/src/clientserver_test.cpp b/tests/clientserver_test/src/clientserver_test.cpp index 9fc35fc..c0d2930 100644 --- a/tests/clientserver_test/src/clientserver_test.cpp +++ b/tests/clientserver_test/src/clientserver_test.cpp @@ -168,11 +168,11 @@ TEST(ClientServer, ServerConnectEvent) { switch (data_->type) { - case client_event_connected: + case server_event_connected: std::cout << "event connected fired" << std::endl; event_connected_fired++; break; - case client_event_disconnected: + case server_event_disconnected: std::cout << "event disconnected fired" << std::endl; event_disconnected_fired++; break; @@ -251,7 +251,7 @@ TEST(ClientServer, ClientServerBaseCallback) }; // add method callbacks - for (auto service : service_vec) + for (const auto& service : service_vec) { service->AddMethodCallback("foo::method1", "foo::req_type1", "foo::resp_type1", method_callback); service->AddMethodCallback("foo::method2", "foo::req_type2", "foo::resp_type2", method_callback); @@ -273,7 +273,7 @@ TEST(ClientServer, ClientServerBaseCallback) }; // add callback for server response - for (auto client : client_vec) + for (const auto& client : client_vec) { client->AddResponseCallback(response_callback); } @@ -289,7 +289,7 @@ TEST(ClientServer, ClientServerBaseCallback) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 success &= client->Call("foo::method1", "my request for method 1"); @@ -308,7 +308,7 @@ TEST(ClientServer, ClientServerBaseCallback) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 success &= client->Call("foo::method1", "my request for method 1"); @@ -365,7 +365,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) }; // add method callbacks - for (auto service : service_vec) + for (const auto& service : service_vec) { service->AddMethodCallback("foo::method1", "foo::req_type1", "foo::resp_type1", method_callback); service->AddMethodCallback("foo::method2", "foo::req_type2", "foo::resp_type2", method_callback); @@ -387,7 +387,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) }; // add callback for server response - for (auto client : client_vec) + for (const auto& client : client_vec) { client->AddResponseCallback(response_callback); } @@ -398,7 +398,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) { timeout_fired++; }; - for (auto client : client_vec) + for (const auto& client : client_vec) { // catch events client->AddEventCallback(client_event_timeout, std::bind(event_callback, std::placeholders::_2)); @@ -416,7 +416,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 success &= client->Call("foo::method1", "my request for method 1"); @@ -447,7 +447,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 success &= client->Call("foo::method1", "my request for method 1", method_process_time * 4); @@ -478,7 +478,7 @@ TEST(ClientServer, ClientServerBaseCallbackTimeout) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 success &= client->Call("foo::method1", "my request for method 1", method_process_time / 10); @@ -714,7 +714,7 @@ TEST(ClientServer, ClientServerBaseBlocking) }; // add method callback - for (auto service : service_vec) + for (const auto& service : service_vec) { service->AddMethodCallback("foo::method1", "foo::req_type1", "foo::resp_type1", method_callback); service->AddMethodCallback("foo::method2", "foo::req_type2", "foo::resp_type2", method_callback); @@ -737,7 +737,7 @@ TEST(ClientServer, ClientServerBaseBlocking) for (auto i = 0; i < calls; ++i) { // call methods - for (auto client : client_vec) + for (const auto& client : client_vec) { // call method 1 if (client->Call("foo::method1", "my request for method 1", -1, &service_response_vec)) @@ -775,7 +775,7 @@ TEST(ClientServer, ClientServerBaseBlocking) EXPECT_EQ(methods_called * num_services, responses_executed); // remove method callback - for (auto service : service_vec) + for (const auto& service : service_vec) { service->RemMethodCallback("foo::method1"); service->RemMethodCallback("foo::method2"); diff --git a/tests/core_test/src/core_test.cpp b/tests/core_test/src/core_test.cpp index 47fcc63..35c3fda 100644 --- a/tests/core_test/src/core_test.cpp +++ b/tests/core_test/src/core_test.cpp @@ -20,10 +20,8 @@ #include #include #include -#include #include #include -#include #include #define CMN_REGISTRATION_REFRESH 1000 diff --git a/tests/io_memfile_test/src/memfile_naming_test.cpp b/tests/io_memfile_test/src/memfile_naming_test.cpp index 929d701..0f6673f 100644 --- a/tests/io_memfile_test/src/memfile_naming_test.cpp +++ b/tests/io_memfile_test/src/memfile_naming_test.cpp @@ -21,9 +21,6 @@ #include #include -#include -#include -#include #include diff --git a/tests/pubsub_proto_test/src/proto_dyn_subscriber_test.cpp b/tests/pubsub_proto_test/src/proto_dyn_subscriber_test.cpp index a79630c..7d13527 100644 --- a/tests/pubsub_proto_test/src/proto_dyn_subscriber_test.cpp +++ b/tests/pubsub_proto_test/src/proto_dyn_subscriber_test.cpp @@ -32,8 +32,6 @@ // subscriber callback function -#define REGISTRATION_REFRESH_CYCLE 1000 - class ProtoDynSubscriberTest : public ::testing::Test { public: ProtoDynSubscriberTest() @@ -45,7 +43,7 @@ class ProtoDynSubscriberTest : public ::testing::Test { eCAL::Util::EnableLoopback(true); } - virtual ~ProtoDynSubscriberTest() { + ~ProtoDynSubscriberTest() override { // Finalize eCAL eCAL::Finalize(); } diff --git a/tests/pubsub_proto_test/src/proto_publisher_test.cpp b/tests/pubsub_proto_test/src/proto_publisher_test.cpp index a0f10c5..c1751e2 100644 --- a/tests/pubsub_proto_test/src/proto_publisher_test.cpp +++ b/tests/pubsub_proto_test/src/proto_publisher_test.cpp @@ -34,7 +34,7 @@ class ProtoPublisherTest : public ::testing::Test { eCAL::Initialize(); } - virtual ~ProtoPublisherTest() { + ~ProtoPublisherTest() override { eCAL::Finalize(); } diff --git a/tests/pubsub_proto_test/src/proto_subscriber_test.cpp b/tests/pubsub_proto_test/src/proto_subscriber_test.cpp index 001b8ff..a56306b 100644 --- a/tests/pubsub_proto_test/src/proto_subscriber_test.cpp +++ b/tests/pubsub_proto_test/src/proto_subscriber_test.cpp @@ -41,7 +41,7 @@ class ProtoSubscriberTest : public ::testing::Test { eCAL::Util::EnableLoopback(true); } - virtual ~ProtoSubscriberTest() { + ~ProtoSubscriberTest() override { // Finalize eCAL eCAL::Finalize(); } diff --git a/tests/pubsub_test/src/pubsub_acknowledge.cpp b/tests/pubsub_test/src/pubsub_acknowledge.cpp index b39734f..fe94f64 100644 --- a/tests/pubsub_test/src/pubsub_acknowledge.cpp +++ b/tests/pubsub_test/src/pubsub_acknowledge.cpp @@ -17,19 +17,13 @@ * ========================= eCAL LICENSE ================================= */ -#include #include -#include -#include -#include #include -#include #include -#include namespace { - std::chrono::nanoseconds TimeOperation(std::function func) + std::chrono::nanoseconds TimeOperation(const std::function& func) { auto start = std::chrono::steady_clock::now(); func(); @@ -38,7 +32,7 @@ namespace } template - void AssertOperationExecutionTimeInRange(std::function func, std::chrono::duration min, std::chrono::duration max) + void AssertOperationExecutionTimeInRange(const std::function& func, std::chrono::duration min, std::chrono::duration max) { auto operation_time = TimeOperation(func); EXPECT_GE(operation_time.count(), std::chrono::duration_cast(min).count()) << "Timed operation less than minimum threshold"; diff --git a/tests/pubsub_test/src/pubsub_gettopics.cpp b/tests/pubsub_test/src/pubsub_gettopics.cpp index 9901f23..fd59090 100644 --- a/tests/pubsub_test/src/pubsub_gettopics.cpp +++ b/tests/pubsub_test/src/pubsub_gettopics.cpp @@ -26,8 +26,6 @@ #define CMN_REGISTRATION_REFRESH 1000 #define CMN_MONITORING_TIMEOUT 5000 -#if ECAL_CORE_REGISTRATION // the registration provider is currently updating the descgate, maybe we need to separate this update logic - TEST(PubSub, GetTopics) { // initialize eCAL API @@ -140,5 +138,3 @@ TEST(PubSub, GetTopics) // finalize eCAL API eCAL::Finalize(); } - -#endif // ECAL_CORE_REGISTRATION