From 0e8a72c737355a83993075a0374d45fc6421b0fe Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:36:50 +0100 Subject: [PATCH 1/5] fixed a few simple warnings updated README.md --- README.md | 12 +++++------- ecal/core/src/service/ecal_service_client_impl.cpp | 2 +- ecal/service/sample/src/main.cpp | 2 +- lang/csharp/Continental/eCAL/Core/ecal_clr.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 681de6fc6c..888904f0ad 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ [![License](https://img.shields.io/github/license/continental/ecal.svg?style=flat)](LICENSE.txt) The **e**nhanced **C**ommunication **A**bstraction **L**ayer (eCAL) is a middleware that enables scalable, high performance interprocess communication on a single computer node or between different nodes in a computer network. -eCAL uses a **publish - subscribe** pattern to automatically connect different nodes in the network. +eCAL provides **publish - subscribe** and **server - client** pattern to connect different nodes in the network with almost no configuration required. -eCAL automatically chooses the best available data transport mechanism for each link: +eCAL automatically chooses the best available data transport mechanism for each link, it supports: - **Shared memory** for local communication _(incredibly fast!)_ -- **UDP** for network communication +- **UDP** and **TCP** for network communication -Visit the eCAL Documentation at 🌐 http://ecal.io for more information. +Visit the eCAL Documentation at 🌐 https://ecal.io for more information. ## Architecture @@ -63,7 +63,7 @@ sudo apt-get install ecal ``` This PPA will always upgrade you to the latest eCAL Release (-> Rolling Release PPA). If you intend to stay on an specific release, check out other PPAs [here](https://eclipse-ecal.github.io/ecal/getting_started/setup.html#fa-ubuntu-automatically-install-ecal-from-a-ppa). -*Ubuntu 16.04, 18.04, 20.04, 20.10, 21.04 for CPU architectures i386, x64, armhf, arm64 are supported at the time of writing.* +*Ubuntu 18.04, 20.04, 22.04, 23.04, 23.10 for CPU architectures (i386), x64, armhf, arm64 are supported at the time of writing.* ## Example @@ -125,8 +125,6 @@ eCAL comes with a set of read-to-use tools that will help you with developing, t ## eCAL & ROS * [rmw_ecal](https://github.com/eclipse-ecal/rmw_ecal) - eCAL / ROS2 middleware layer * [rosidl_typesupport_protobuf](https://github.com/eclipse-ecal/rosidl_typesupport_protobuf) - Protobuf based rosidl typesupport -* [ecal-ros2-publisher](https://github.com/ecal-io/ecal-ros2-publisher) - Publishing eCAL topics to ROS2 -* [ecal-ros2-subscriber](https://github.com/ecal-io/ecal-ros2-subscriber) - Subscribing ROS2 topics in eCAL ## Other projects related to eCAL * [fineftp-server](https://github.com/eclipse-ecal/fineftp-server) - FTP functionality to collect distributed measurement artifacts over network diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index d1d04d768b..269c59d595 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -752,7 +752,7 @@ namespace eCAL const auto port_to_use = (protocol_version == 0 ? iter.tcp_port_v0 : iter.tcp_port_v1); // Create the client and add it to the map - const auto new_client_session = client_manager->create_client(protocol_version, iter.hname, port_to_use, event_callback); + const auto new_client_session = client_manager->create_client(static_cast(protocol_version), iter.hname, port_to_use, event_callback); if (new_client_session) m_client_map[iter.key] = new_client_session; } diff --git a/ecal/service/sample/src/main.cpp b/ecal/service/sample/src/main.cpp index 40f4761bfb..be38fbca0f 100644 --- a/ecal/service/sample/src/main.cpp +++ b/ecal/service/sample/src/main.cpp @@ -24,7 +24,7 @@ #include #include -int main(int argc, char** argv) +int main(int /*argc*/, char** /*argv*/) { // Create an io_context auto io_context = std::make_shared(); diff --git a/lang/csharp/Continental/eCAL/Core/ecal_clr.cpp b/lang/csharp/Continental/eCAL/Core/ecal_clr.cpp index 6e3c6f1735..083276ddcf 100644 --- a/lang/csharp/Continental/eCAL/Core/ecal_clr.cpp +++ b/lang/csharp/Continental/eCAL/Core/ecal_clr.cpp @@ -454,7 +454,7 @@ bool ServiceServer::RemMethodCallback(String^ methodName, MethodCallback^ callba return(false); } -int ServiceServer::OnMethodCall(const std::string& method_, const std::string& req_type_, const std::string& resp_type_, const std::string& request_, std::string& response_) +int ServiceServer::OnMethodCall(const std::string& method_, const std::string& /*req_type_*/, const std::string& /*resp_type_*/, const std::string& request_, std::string& response_) { array^ result = m_callbacks(StlStringToString(method_), StlStringToString(method_), StlStringToString(method_), StlStringToByteArray(request_)); response_ = ByteArrayToStlString(result); From fc330d56a6081d40882e173173702de001d6d007 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:27:11 +0100 Subject: [PATCH 2/5] clang tidy ecal/core/io --- .../src/custom_tclap/advanced_tclap_output.h | 6 ++-- .../src/io/ecal_memfile_broadcast_reader.h | 2 +- ecal/core/src/io/ecal_memfile_db.cpp | 6 ++-- ecal/core/src/io/ecal_memfile_db.h | 2 +- ecal/core/src/io/ecal_memfile_header.h | 2 +- ecal/core/src/io/ecal_memfile_info.h | 28 ++++++------------- ecal/core/src/io/ecal_memfile_pool.h | 2 +- ecal/core/src/io/ecal_memfile_sync.h | 2 +- ecal/core/src/io/ecal_named_mutex_base.h | 2 +- ecal/core/src/io/rcv_sample.h | 2 +- ecal/core/src/io/snd_raw_buffer.cpp | 4 +-- ecal/core/src/io/snd_raw_buffer.h | 2 +- ecal/core/src/io/udp_init.cpp | 2 +- ecal/core/src/io/udp_receiver_asio.cpp | 2 +- 14 files changed, 27 insertions(+), 37 deletions(-) diff --git a/ecal/core/src/custom_tclap/advanced_tclap_output.h b/ecal/core/src/custom_tclap/advanced_tclap_output.h index 5415eb4fa0..521c13f208 100644 --- a/ecal/core/src/custom_tclap/advanced_tclap_output.h +++ b/ecal/core/src/custom_tclap/advanced_tclap_output.h @@ -69,9 +69,9 @@ namespace CustomTclap */ AdvancedTclapOutput(std::ostream* output_stream, int max_width); - virtual void version(TCLAP::CmdLineInterface &cmd) override; - virtual void usage(TCLAP::CmdLineInterface &cmd) override; - virtual void failure(TCLAP::CmdLineInterface &cmd, TCLAP::ArgException &e) override; + void version(TCLAP::CmdLineInterface &cmd) override; + void usage(TCLAP::CmdLineInterface &cmd) override; + void failure(TCLAP::CmdLineInterface &cmd, TCLAP::ArgException &e) override; /** * @brief Hides / un-hides an argument diff --git a/ecal/core/src/io/ecal_memfile_broadcast_reader.h b/ecal/core/src/io/ecal_memfile_broadcast_reader.h index 8dda745bd2..7b031b39bd 100644 --- a/ecal/core/src/io/ecal_memfile_broadcast_reader.h +++ b/ecal/core/src/io/ecal_memfile_broadcast_reader.h @@ -39,7 +39,7 @@ namespace eCAL std::int64_t timestamp; }; - typedef std::vector MemfileBroadcastMessageListT; + using MemfileBroadcastMessageListT = std::vector; class CMemoryFileBroadcastReader { diff --git a/ecal/core/src/io/ecal_memfile_db.cpp b/ecal/core/src/io/ecal_memfile_db.cpp index f60abfeff2..36e1a94428 100644 --- a/ecal/core/src/io/ecal_memfile_db.cpp +++ b/ecal/core/src/io/ecal_memfile_db.cpp @@ -164,19 +164,19 @@ namespace eCAL { bool AddFile(const std::string& name_, const bool create_, const size_t len_, SMemFileInfo& mem_file_info_) { - if (!g_memfile_map()) return false; + if (g_memfile_map() == nullptr) return false; return g_memfile_map()->AddFile(name_, create_, len_, mem_file_info_); } bool RemoveFile(const std::string& name_, const bool remove_) { - if (!g_memfile_map()) return false; + if (g_memfile_map() == nullptr) return false; return g_memfile_map()->RemoveFile(name_, remove_); } bool CheckFileSize(const std::string& name_, const size_t len_, SMemFileInfo& mem_file_info_) { - if (!g_memfile_map()) return false; + if (g_memfile_map() == nullptr) return false; return g_memfile_map()->CheckFileSize(name_, len_, mem_file_info_); } } diff --git a/ecal/core/src/io/ecal_memfile_db.h b/ecal/core/src/io/ecal_memfile_db.h index a716bd5e16..a60224bf30 100644 --- a/ecal/core/src/io/ecal_memfile_db.h +++ b/ecal/core/src/io/ecal_memfile_db.h @@ -44,7 +44,7 @@ namespace eCAL bool CheckFileSize(const std::string& name_, const size_t len_, SMemFileInfo& mem_file_info_); protected: - typedef std::unordered_map MemFileMapT; + using MemFileMapT = std::unordered_map; std::mutex m_memfile_map_mtx; MemFileMapT m_memfile_map; }; diff --git a/ecal/core/src/io/ecal_memfile_header.h b/ecal/core/src/io/ecal_memfile_header.h index 96e76e483b..a016179f59 100644 --- a/ecal/core/src/io/ecal_memfile_header.h +++ b/ecal/core/src/io/ecal_memfile_header.h @@ -23,7 +23,7 @@ #pragma once -#include +#include namespace eCAL { diff --git a/ecal/core/src/io/ecal_memfile_info.h b/ecal/core/src/io/ecal_memfile_info.h index 14344009a3..dc37723d23 100644 --- a/ecal/core/src/io/ecal_memfile_info.h +++ b/ecal/core/src/io/ecal_memfile_info.h @@ -32,8 +32,8 @@ #include "ecal_win_main.h" -typedef HANDLE MemFileT; -typedef HANDLE MapRegionT; +using MemFileT = HANDLE; +using MapRegionT = HANDLE; #endif /* ECAL_OS_WINDOWS */ @@ -48,23 +48,13 @@ namespace eCAL { struct SMemFileInfo { - SMemFileInfo() - { - refcnt = 0; - remove = false; - memfile = 0; - map_region = 0; - mem_address = 0; - size = 0; - exists = false; - } - int refcnt; - bool remove; - MemFileT memfile; - MapRegionT map_region; - void* mem_address; + int refcnt = 0; + bool remove = false; + MemFileT memfile = 0; + MapRegionT map_region = 0; + void* mem_address = 0; std::string name; - size_t size; - bool exists; + size_t size = 0; + bool exists = false; }; } diff --git a/ecal/core/src/io/ecal_memfile_pool.h b/ecal/core/src/io/ecal_memfile_pool.h index c09c7f6b7e..7357055eaf 100644 --- a/ecal/core/src/io/ecal_memfile_pool.h +++ b/ecal/core/src/io/ecal_memfile_pool.h @@ -39,7 +39,7 @@ namespace eCAL { - typedef std::function MemFileDataCallbackT; + using MemFileDataCallbackT = std::function; //////////////////////////////////////// // CMemFileObserver diff --git a/ecal/core/src/io/ecal_memfile_sync.h b/ecal/core/src/io/ecal_memfile_sync.h index a6756116d0..ca0e972d1f 100644 --- a/ecal/core/src/io/ecal_memfile_sync.h +++ b/ecal/core/src/io/ecal_memfile_sync.h @@ -79,7 +79,7 @@ namespace eCAL EventHandleT event_ack; bool event_ack_is_invalid = false; //!< The ack event has timeouted. Thus, we don't wait for it anymore, until the subscriber notifies us via registration layer that it is still alive. }; - typedef std::unordered_map EventHandleMapT; + using EventHandleMapT = std::unordered_map; std::mutex m_event_handle_map_sync; EventHandleMapT m_event_handle_map; }; diff --git a/ecal/core/src/io/ecal_named_mutex_base.h b/ecal/core/src/io/ecal_named_mutex_base.h index b2bb25a3c0..dfd186f1d0 100644 --- a/ecal/core/src/io/ecal_named_mutex_base.h +++ b/ecal/core/src/io/ecal_named_mutex_base.h @@ -31,7 +31,7 @@ namespace eCAL class CNamedMutexImplBase { public: - virtual ~CNamedMutexImplBase(){} + virtual ~CNamedMutexImplBase()= default; virtual bool IsCreated() const = 0; virtual bool IsRecoverable() const = 0; diff --git a/ecal/core/src/io/rcv_sample.h b/ecal/core/src/io/rcv_sample.h index 447f92acc4..511003b7f3 100644 --- a/ecal/core/src/io/rcv_sample.h +++ b/ecal/core/src/io/rcv_sample.h @@ -107,7 +107,7 @@ class CSampleReceiver int Process(const char* sample_buffer_, size_t sample_buffer_len_); protected: - typedef std::unordered_map> ReceiveSlotMapT; + using ReceiveSlotMapT = std::unordered_map>; ReceiveSlotMapT m_receive_slot_map; std::vector m_msg_buffer; eCAL::pb::Sample m_ecal_sample; diff --git a/ecal/core/src/io/snd_raw_buffer.cpp b/ecal/core/src/io/snd_raw_buffer.cpp index cadbe11f28..4208fc1eb6 100644 --- a/ecal/core/src/io/snd_raw_buffer.cpp +++ b/ecal/core/src/io/snd_raw_buffer.cpp @@ -79,7 +79,7 @@ namespace eCAL size_t SendSampleBuffer(char* buf_, size_t buf_len_, long bandwidth_, TransmitCallbackT transmit_cb_) { - if (!buf_) return(0); + if (buf_ == nullptr) return(0); size_t sent(0); size_t sent_sum(0); @@ -168,7 +168,7 @@ namespace eCAL // send data package sent = transmit_cb_(buf_ + static_cast(current_packet_num)*MSG_PAYLOAD_SIZE, sizeof(struct SUDPMessageHead) + current_snd_len); if (sent == 0) return(sent); - if (send_sleep_us) + if (send_sleep_us != 0) eCAL::Process::SleepFor(std::chrono::microseconds(send_sleep_us)); #ifndef NDEBUG diff --git a/ecal/core/src/io/snd_raw_buffer.h b/ecal/core/src/io/snd_raw_buffer.h index bfcdf1635e..4cc864f1ac 100644 --- a/ecal/core/src/io/snd_raw_buffer.h +++ b/ecal/core/src/io/snd_raw_buffer.h @@ -36,6 +36,6 @@ namespace eCAL { size_t CreateSampleBuffer(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, std::vector& payload_); - typedef std::function TransmitCallbackT; + using TransmitCallbackT = std::function; size_t SendSampleBuffer(char* buf_, size_t buf_len_, long bandwidth_, TransmitCallbackT transmit_cb_); } diff --git a/ecal/core/src/io/udp_init.cpp b/ecal/core/src/io/udp_init.cpp index a39a75f86f..1636cd86b2 100644 --- a/ecal/core/src/io/udp_init.cpp +++ b/ecal/core/src/io/udp_init.cpp @@ -23,7 +23,7 @@ #include -#include +#include #include #ifdef ECAL_OS_WINDOWS diff --git a/ecal/core/src/io/udp_receiver_asio.cpp b/ecal/core/src/io/udp_receiver_asio.cpp index 3f1f572838..86c01f5408 100644 --- a/ecal/core/src/io/udp_receiver_asio.cpp +++ b/ecal/core/src/io/udp_receiver_asio.cpp @@ -189,7 +189,7 @@ namespace eCAL RunIOContext(asio::chrono::milliseconds(timeout_)); // retrieve underlaying raw socket informations - if (address_) + if (address_ != nullptr) { if (m_sender_endpoint.address().is_v4()) { From 5cd4c7c0f5d911a697f0e166a4f963bbd293330f Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:01:47 +0100 Subject: [PATCH 3/5] clang tidy ecal/core/src/pubsub --- ecal/core/src/pubsub/ecal_pubgate.cpp | 6 +++--- ecal/core/src/pubsub/ecal_publisher.cpp | 2 +- ecal/core/src/pubsub/ecal_subgate.cpp | 6 +++--- ecal/core/src/pubsub/ecal_subscriber.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ecal/core/src/pubsub/ecal_pubgate.cpp b/ecal/core/src/pubsub/ecal_pubgate.cpp index e9324adfd9..3fbc58a6ce 100644 --- a/ecal/core/src/pubsub/ecal_pubgate.cpp +++ b/ecal/core/src/pubsub/ecal_pubgate.cpp @@ -117,7 +117,7 @@ namespace eCAL CDataWriter::SLocalSubscriptionInfo subscription_info; subscription_info.topic_id = ecal_sample.tid(); subscription_info.process_id = std::to_string(ecal_sample.pid()); - SDataTypeInformation topic_information{ eCALSampleToTopicInformation(ecal_sample_) }; + const SDataTypeInformation topic_information{ eCALSampleToTopicInformation(ecal_sample_) }; std::string reader_par; for (const auto& layer : ecal_sample.tlayer()) @@ -169,7 +169,7 @@ namespace eCAL subscription_info.host_name = ecal_sample.hname(); subscription_info.topic_id = ecal_sample.tid(); subscription_info.process_id = std::to_string(ecal_sample.pid()); - SDataTypeInformation topic_information{ eCALSampleToTopicInformation(ecal_sample_) }; + const SDataTypeInformation topic_information{ eCALSampleToTopicInformation(ecal_sample_) }; std::string reader_par; for (const auto& layer : ecal_sample.tlayer()) @@ -218,7 +218,7 @@ namespace eCAL // refresh publisher registrations const std::shared_lock lock(m_topic_name_datawriter_sync); - for (auto iter : m_topic_name_datawriter_map) + for (const auto& iter : m_topic_name_datawriter_map) { iter.second->RefreshRegistration(); } diff --git a/ecal/core/src/pubsub/ecal_publisher.cpp b/ecal/core/src/pubsub/ecal_publisher.cpp index cf44221aee..bbb9611a2d 100644 --- a/ecal/core/src/pubsub/ecal_publisher.cpp +++ b/ecal/core/src/pubsub/ecal_publisher.cpp @@ -426,7 +426,7 @@ namespace eCAL std::string CPublisher::GetTypeName() const { - SDataTypeInformation info = GetDataTypeInformation(); + const SDataTypeInformation info = GetDataTypeInformation(); return(Util::CombinedTopicEncodingAndType(info.encoding, info.name)); } diff --git a/ecal/core/src/pubsub/ecal_subgate.cpp b/ecal/core/src/pubsub/ecal_subgate.cpp index 757e4ac827..33b8bdccd7 100644 --- a/ecal/core/src/pubsub/ecal_subgate.cpp +++ b/ecal/core/src/pubsub/ecal_subgate.cpp @@ -234,7 +234,7 @@ namespace eCAL if (topic_name.empty()) return; const std::string& topic_id = ecal_sample.tid(); - SDataTypeInformation topic_info{ eCALSampleToTopicInformation(ecal_sample_) }; + const SDataTypeInformation topic_info{ eCALSampleToTopicInformation(ecal_sample_) }; // store description ApplyTopicToDescGate(topic_name, topic_info); @@ -313,7 +313,7 @@ namespace eCAL const std::string& host_name = ecal_sample.hname(); const std::string& topic_name = ecal_sample.tname(); const std::string& topic_id = ecal_sample.tid(); - SDataTypeInformation topic_info{ eCALSampleToTopicInformation(ecal_sample_) }; + const SDataTypeInformation topic_info{ eCALSampleToTopicInformation(ecal_sample_) }; const std::string process_id = std::to_string(ecal_sample.pid()); // store description @@ -361,7 +361,7 @@ namespace eCAL // refresh reader registrations const std::shared_lock lock(m_topic_name_datareader_sync); - for (auto iter : m_topic_name_datareader_map) + for (const auto& iter : m_topic_name_datareader_map) { iter.second->RefreshRegistration(); } diff --git a/ecal/core/src/pubsub/ecal_subscriber.cpp b/ecal/core/src/pubsub/ecal_subscriber.cpp index f04edf78d4..2056bb1cd8 100644 --- a/ecal/core/src/pubsub/ecal_subscriber.cpp +++ b/ecal/core/src/pubsub/ecal_subscriber.cpp @@ -263,7 +263,7 @@ namespace eCAL std::string CSubscriber::GetTypeName() const { if(m_datareader == nullptr) return(""); - SDataTypeInformation info = m_datareader->GetDataTypeInformation(); + const SDataTypeInformation info = m_datareader->GetDataTypeInformation(); return(Util::CombinedTopicEncodingAndType(info.encoding, info.name)); } From 558bfb13c9800a8266ae14a8abb7bfe6c559ff20 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:13:15 +0100 Subject: [PATCH 4/5] clang tidy ecal/core/src/service --- ecal/core/src/service/ecal_clientgate.h | 4 ++-- ecal/core/src/service/ecal_service_client_impl.cpp | 2 +- ecal/core/src/service/ecal_service_server_impl.cpp | 4 ++-- ecal/core/src/service/ecal_service_singleton_manager.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ecal/core/src/service/ecal_clientgate.h b/ecal/core/src/service/ecal_clientgate.h index bced1a7e8b..f6f7e14b87 100644 --- a/ecal/core/src/service/ecal_clientgate.h +++ b/ecal/core/src/service/ecal_clientgate.h @@ -70,11 +70,11 @@ namespace eCAL protected: static std::atomic m_created; - typedef std::set ServiceNameServiceImplSetT; + using ServiceNameServiceImplSetT = std::set; std::shared_timed_mutex m_client_set_sync; ServiceNameServiceImplSetT m_client_set; - typedef Util::CExpMap ConnectedMapT; + using ConnectedMapT = Util::CExpMap; std::shared_timed_mutex m_service_register_map_sync; ConnectedMapT m_service_register_map; }; diff --git a/ecal/core/src/service/ecal_service_client_impl.cpp b/ecal/core/src/service/ecal_service_client_impl.cpp index 269c59d595..1d5553edde 100644 --- a/ecal/core/src/service/ecal_service_client_impl.cpp +++ b/ecal/core/src/service/ecal_service_client_impl.cpp @@ -320,7 +320,7 @@ namespace eCAL }; // Call service asynchronously - bool call_success = client->second->async_call_service(request_shared_ptr, response_callback); + const bool call_success = client->second->async_call_service(request_shared_ptr, response_callback); if (!call_success) { diff --git a/ecal/core/src/service/ecal_service_server_impl.cpp b/ecal/core/src/service/ecal_service_server_impl.cpp index 76042dc325..ba3141b5b1 100644 --- a/ecal/core/src/service/ecal_service_server_impl.cpp +++ b/ecal/core/src/service/ecal_service_server_impl.cpp @@ -162,7 +162,7 @@ namespace eCAL m_service_id.clear(); { - std::lock_guard connected_lock(m_connected_mutex); + const std::lock_guard connected_lock(m_connected_mutex); m_connected_v0 = false; m_connected_v1 = false; } @@ -464,7 +464,7 @@ namespace eCAL bool mode_changed(false); { - std::lock_guard connected_lock(m_connected_mutex); + const std::lock_guard connected_lock(m_connected_mutex); // protocol version 0 if (m_connected_v0) diff --git a/ecal/core/src/service/ecal_service_singleton_manager.cpp b/ecal/core/src/service/ecal_service_singleton_manager.cpp index 1de4b2fe85..4cce08d1e3 100644 --- a/ecal/core/src/service/ecal_service_singleton_manager.cpp +++ b/ecal/core/src/service/ecal_service_singleton_manager.cpp @@ -89,7 +89,7 @@ namespace eCAL return nullptr; // Lock the mutex to actually make it thread safe - std::lock_guard singleton_lock(singleton_mutex); + const std::lock_guard singleton_lock(singleton_mutex); if (!stopped) { // Create io_context, if it didn't exist, yet @@ -126,7 +126,7 @@ namespace eCAL return nullptr; // Lock the mutex to actually make it thread safe - std::lock_guard singleton_lock(singleton_mutex); + const std::lock_guard singleton_lock(singleton_mutex); if (!stopped) { // Create io_context, if it didn't exist, yet @@ -156,7 +156,7 @@ namespace eCAL void ServiceManager::stop() { - std::lock_guard singleton_lock(singleton_mutex); + const std::lock_guard singleton_lock(singleton_mutex); stopped = true; @@ -177,7 +177,7 @@ namespace eCAL void ServiceManager::reset() { - std::lock_guard singleton_lock(singleton_mutex); + const std::lock_guard singleton_lock(singleton_mutex); stopped = false; } From 7eda3cfc4ea91a60f49de7c11388d082e78b9407 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:46:08 +0100 Subject: [PATCH 5/5] clang tidy ecal/core/src --- ecal/core/src/ecal_clang.cpp | 82 ++++++++++++------------- ecal/core/src/ecal_descgate.cpp | 2 +- ecal/core/src/ecal_event.cpp | 6 +- ecal/core/src/ecal_expmap.h | 30 ++++----- ecal/core/src/ecal_global_accessors.cpp | 26 ++++---- ecal/core/src/ecal_globals.cpp | 36 +++++------ ecal/core/src/ecal_log.cpp | 16 ++--- ecal/core/src/ecal_process.cpp | 22 +++---- ecal/core/src/ecal_thread.cpp | 2 +- ecal/core/src/ecal_time.cpp | 18 +++--- ecal/core/src/ecal_timegate.cpp | 28 ++++----- ecal/core/src/ecal_util.cpp | 20 +++--- 12 files changed, 141 insertions(+), 147 deletions(-) diff --git a/ecal/core/src/ecal_clang.cpp b/ecal/core/src/ecal_clang.cpp index 0581c2ab14..d7ee5ceaac 100644 --- a/ecal/core/src/ecal_clang.cpp +++ b/ecal/core/src/ecal_clang.cpp @@ -159,14 +159,14 @@ ECAL_API bool ecal_get_type_name(const char* topic_name_, const char** topic_typ char* cbuf = str_malloc(topic_type_s); if(cbuf == nullptr) return(false); - if (topic_type_) { + if (topic_type_ != nullptr) { *topic_type_ = cbuf; - if(topic_type_len_) *topic_type_len_ = static_cast(topic_type_s.size()); + if(topic_type_len_ != nullptr) *topic_type_len_ = static_cast(topic_type_s.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (topic_type_len_) *topic_type_len_ = 0; + if (topic_type_len_ != nullptr) *topic_type_len_ = 0; ret = false; } } @@ -186,14 +186,14 @@ ECAL_API bool ecal_get_description(const char* topic_name_, const char** topic_d char* cbuf = str_malloc(topic_desc_s); if(cbuf == nullptr) return(false); - if (topic_desc_) { + if (topic_desc_ != nullptr) { *topic_desc_ = cbuf; - if (topic_desc_len_) *topic_desc_len_ = static_cast(topic_desc_s.size()); + if (topic_desc_len_ != nullptr) *topic_desc_len_ = static_cast(topic_desc_s.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (topic_desc_len_) *topic_desc_len_ = 0; + if (topic_desc_len_ != nullptr) *topic_desc_len_ = 0; ret = false; } } @@ -245,7 +245,7 @@ ECAL_API ECAL_HANDLE pub_create(const char* topic_name_, const char* topic_type_ ECAL_API bool pub_destroy(ECAL_HANDLE handle_) { eCAL::CPublisher* pub = static_cast(handle_); - if(pub) + if(pub != nullptr) { delete pub; pub = nullptr; @@ -263,7 +263,7 @@ ECAL_API bool pub_destroy(ECAL_HANDLE handle_) ECAL_API bool pub_set_type_name(ECAL_HANDLE handle_, const char* topic_type_name_, const int topic_type_name_length_) { eCAL::CPublisher* pub = static_cast(handle_); - if (pub) + if (pub != nullptr) { return(pub->SetTypeName(std::string(topic_type_name_, static_cast(topic_type_name_length_)))); } @@ -276,7 +276,7 @@ ECAL_API bool pub_set_type_name(ECAL_HANDLE handle_, const char* topic_type_name ECAL_API bool pub_set_description(ECAL_HANDLE handle_, const char* topic_desc_, const int topic_desc_length_) { eCAL::CPublisher* pub = static_cast(handle_); - if(pub) + if(pub != nullptr) { return(pub->SetDescription(std::string(topic_desc_, static_cast(topic_desc_length_)))); } @@ -288,7 +288,7 @@ ECAL_API bool pub_set_description(ECAL_HANDLE handle_, const char* topic_desc_, /****************************************/ ECAL_API bool pub_set_qos(ECAL_HANDLE handle_, struct SWriterQOSC qos_) //-V813 { - int ret = eCAL_Pub_SetQOS(handle_, qos_); + const int ret = eCAL_Pub_SetQOS(handle_, qos_); return(ret == 0); } @@ -297,7 +297,7 @@ ECAL_API bool pub_set_qos(ECAL_HANDLE handle_, struct SWriterQOSC qos_) //-V813 /****************************************/ ECAL_API bool pub_get_qos(ECAL_HANDLE handle_, struct SWriterQOSC* qos_) { - int ret = eCAL_Pub_GetQOS(handle_, qos_); + const int ret = eCAL_Pub_GetQOS(handle_, qos_); return(ret == 0); } @@ -307,7 +307,7 @@ ECAL_API bool pub_get_qos(ECAL_HANDLE handle_, struct SWriterQOSC* qos_) ECAL_API bool pub_set_layer_mode(ECAL_HANDLE handle_, const int layer_, const int mode_) { eCAL::CPublisher* pub = static_cast(handle_); - if(pub) + if(pub != nullptr) { return(pub->SetLayerMode(eCAL::TLayer::eTransportLayer(layer_), eCAL::TLayer::eSendMode(mode_))); } @@ -320,7 +320,7 @@ ECAL_API bool pub_set_layer_mode(ECAL_HANDLE handle_, const int layer_, const in ECAL_API bool pub_set_max_bandwidth_udp(ECAL_HANDLE handle_, long bandwidth_) { eCAL::CPublisher* pub = static_cast(handle_); - if (pub) + if (pub != nullptr) { return(pub->SetMaxBandwidthUDP(bandwidth_)); } @@ -333,7 +333,7 @@ ECAL_API bool pub_set_max_bandwidth_udp(ECAL_HANDLE handle_, long bandwidth_) ECAL_API int pub_send(ECAL_HANDLE handle_, const char* payload_, const int length_, const long long time_) { eCAL::CPublisher* pub = static_cast(handle_); - if(pub) + if(pub != nullptr) { const size_t ret = pub->Send(payload_, static_cast(length_), time_); if(static_cast(ret) == length_) @@ -350,7 +350,7 @@ ECAL_API int pub_send(ECAL_HANDLE handle_, const char* payload_, const int lengt ECAL_API int pub_send_sync(ECAL_HANDLE handle_, const char* payload_, const int length_, const long long time_, const long long acknowledge_timeout_ms_) { eCAL::CPublisher* pub = static_cast(handle_); - if (pub) + if (pub != nullptr) { const size_t ret = pub->Send(payload_, static_cast(length_), time_, acknowledge_timeout_ms_); if (static_cast(ret) == length_) @@ -417,7 +417,7 @@ ECAL_API ECAL_HANDLE sub_create(const char* topic_name_, const char* topic_type_ ECAL_API bool sub_destroy(ECAL_HANDLE handle_) { eCAL::CSubscriber* sub = static_cast(handle_); - if(sub) + if(sub != nullptr) { delete sub; sub = nullptr; @@ -450,7 +450,7 @@ ECAL_API bool sub_get_qos(ECAL_HANDLE handle_, struct SReaderQOSC* qos_) ECAL_API int sub_receive(ECAL_HANDLE handle_, const char** rcv_buf_, int* rcv_buf_len_, long long* rcv_time_, const int timeout_) { eCAL::CSubscriber* sub = static_cast(handle_); - if(sub) + if(sub != nullptr) { std::string rcv_buf; long long rcv_time = 0; @@ -462,19 +462,19 @@ ECAL_API int sub_receive(ECAL_HANDLE handle_, const char** rcv_buf_, int* rcv_bu char* cbuf = str_malloc(rcv_buf); if(cbuf == nullptr) return(0); - if (rcv_buf_) { + if (rcv_buf_ != nullptr) { *rcv_buf_ = cbuf; - if (rcv_buf_len_) *rcv_buf_len_ = static_cast(rcv_buf.size()); + if (rcv_buf_len_ != nullptr) *rcv_buf_len_ = static_cast(rcv_buf.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (rcv_buf_len_) *rcv_buf_len_ = 0; + if (rcv_buf_len_ != nullptr) *rcv_buf_len_ = 0; // operation could't be completed successfully return(0); } - if(rcv_time_) *rcv_time_ = rcv_time; + if(rcv_time_ != nullptr) *rcv_time_ = rcv_time; return(static_cast(rcv_buf.size())); } @@ -488,7 +488,7 @@ ECAL_API int sub_receive(ECAL_HANDLE handle_, const char** rcv_buf_, int* rcv_bu ECAL_API bool sub_receive_buffer(ECAL_HANDLE handle_, const char** rcv_buf_, int* rcv_buf_len_, long long* rcv_time_, const int timeout_) { eCAL::CSubscriber* sub = static_cast(handle_); - if (sub) + if (sub != nullptr) { std::string rcv_buf; long long rcv_time = 0; @@ -497,20 +497,20 @@ ECAL_API bool sub_receive_buffer(ECAL_HANDLE handle_, const char** rcv_buf_, int { // this has to be freed by caller (ecal_free_mem) char* cbuf = str_malloc(rcv_buf); - if (cbuf == nullptr) return(0); + if (cbuf == nullptr) return(false); - if (rcv_buf_) { + if (rcv_buf_ != nullptr) { *rcv_buf_ = cbuf; - if (rcv_buf_len_) *rcv_buf_len_ = static_cast(rcv_buf.size()); + if (rcv_buf_len_ != nullptr) *rcv_buf_len_ = static_cast(rcv_buf.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (rcv_buf_len_) *rcv_buf_len_ = 0; + if (rcv_buf_len_ != nullptr) *rcv_buf_len_ = 0; // operation couldn't be completed successfullly. return(false); } - if (rcv_time_) *rcv_time_ = rcv_time; + if (rcv_time_ != nullptr) *rcv_time_ = rcv_time; return(true); } @@ -617,7 +617,7 @@ ECAL_API ECAL_HANDLE dyn_json_sub_create(const char* topic_name_) ECAL_API bool dyn_json_sub_destroy(ECAL_HANDLE handle_) { eCAL::protobuf::CDynamicJSONSubscriber* sub = static_cast(handle_); - if (sub) + if (sub != nullptr) { delete sub; sub = nullptr; @@ -681,7 +681,7 @@ ECAL_API ECAL_HANDLE server_create(const char* service_name_) ECAL_API bool server_destroy(ECAL_HANDLE handle_) { eCAL::CServiceServer* server = static_cast(handle_); - if (server) + if (server != nullptr) { delete server; server = nullptr; @@ -710,7 +710,7 @@ static int g_server_method_callback(const std::string& method_, const std::strin ECAL_API bool server_add_method_callback(ECAL_HANDLE handle_, const char* method_name_, const char* req_type_, const char* resp_type_, const MethodCallbackCT callback_, void* par_) { eCAL::CServiceServer* server = static_cast(handle_); - if (server) + if (server != nullptr) { auto callback = std::bind(g_server_method_callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, callback_, par_); return(server->AddMethodCallback(method_name_, req_type_, resp_type_, callback)); @@ -727,7 +727,7 @@ ECAL_API bool server_add_method_callback(ECAL_HANDLE handle_, const char* metho ECAL_API bool server_rem_method_callback(ECAL_HANDLE handle_, const char* method_name_) { eCAL::CServiceServer* server = static_cast(handle_); - if (server) + if (server != nullptr) { return(server->RemMethodCallback(method_name_)); } @@ -758,7 +758,7 @@ ECAL_API ECAL_HANDLE client_create(const char* service_name_) ECAL_API bool client_destroy(ECAL_HANDLE handle_) { eCAL::CServiceClient* client = static_cast(handle_); - if (client) + if (client != nullptr) { delete client; client = nullptr; @@ -776,7 +776,7 @@ ECAL_API bool client_destroy(ECAL_HANDLE handle_) ECAL_API bool client_set_hostname(ECAL_HANDLE handle_, const char* host_name_) { eCAL::CServiceClient* client = static_cast(handle_); - if (client) + if (client != nullptr) { return(client->SetHostName(host_name_)); } @@ -792,7 +792,7 @@ ECAL_API bool client_set_hostname(ECAL_HANDLE handle_, const char* host_name_) ECAL_API bool client_call_method(ECAL_HANDLE handle_, const char* method_name_, const char* request_, const int request_len_, const int timeout_) { eCAL::CServiceClient* client = static_cast(handle_); - if (client) + if (client != nullptr) { std::string request(request_, request_len_); return(client->Call(method_name_, request, timeout_)); @@ -809,7 +809,7 @@ ECAL_API bool client_call_method(ECAL_HANDLE handle_, const char* method_name_, ECAL_API bool client_call_method_async(ECAL_HANDLE handle_, const char* method_name_, const char* request_, const int request_len_, const int timeout_) { eCAL::CServiceClient* client = static_cast(handle_); - if (client) + if (client != nullptr) { std::string request(request_, request_len_); return(client->CallAsync(method_name_, request, timeout_)); @@ -882,15 +882,15 @@ ECAL_API int mon_get_monitoring(const char** mon_buf_, int* mon_buf_len_) char* cbuf = str_malloc(mon_s); if(cbuf == nullptr) return(0); - if (mon_buf_) { + if (mon_buf_ != nullptr) { *mon_buf_ = cbuf; - if (mon_buf_len_) *mon_buf_len_ = static_cast(mon_s.size()); + if (mon_buf_len_ != nullptr) *mon_buf_len_ = static_cast(mon_s.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (mon_buf_len_) *mon_buf_len_ = 0; + if (mon_buf_len_ != nullptr) *mon_buf_len_ = 0; // operation could't be completed successfully return(0); } @@ -915,14 +915,14 @@ ECAL_API int mon_get_logging(const char** log_buf_, int* log_buf_len_) char* cbuf = str_malloc(log_s); if(cbuf == nullptr) return(0); - if (log_buf_) { + if (log_buf_ != nullptr) { *log_buf_ = cbuf; - if (log_buf_len_) *log_buf_len_ = static_cast(log_s.size()); + if (log_buf_len_ != nullptr) *log_buf_len_ = static_cast(log_s.size()); } else { // free allocated memory: ecal_free_mem(cbuf); - if (log_buf_len_) *log_buf_len_ = 0; + if (log_buf_len_ != nullptr) *log_buf_len_ = 0; // operation couldn't be completed successfullly. return(0); } diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index d80357e023..57f5b9a5ad 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -25,7 +25,7 @@ #include #include "ecal_descgate.h" -#include +#include #include #include diff --git a/ecal/core/src/ecal_event.cpp b/ecal/core/src/ecal_event.cpp index 9b81d2e122..dfb786e70b 100644 --- a/ecal/core/src/ecal_event.cpp +++ b/ecal/core/src/ecal_event.cpp @@ -72,19 +72,19 @@ namespace eCAL bool gCloseEvent(const EventHandleT& event_) { - if(!event_.handle) return(false); + if(event_.handle == nullptr) return(false); return(::CloseHandle(event_.handle) != 0); } bool gSetEvent(const EventHandleT& event_) { - if(!event_.handle) return(false); + if(event_.handle == nullptr) return(false); return(::SetEvent(event_.handle) != 0); } bool gWaitForEvent(const EventHandleT& event_, const long timeout_) { - if(!event_.handle) return(false); + if(event_.handle == nullptr) return(false); if(timeout_ < 0) { return(::WaitForSingleObject(event_.handle, INFINITE) == WAIT_OBJECT_0); diff --git a/ecal/core/src/ecal_expmap.h b/ecal/core/src/ecal_expmap.h index ea26b4dcb0..cc090c31c9 100644 --- a/ecal/core/src/ecal_expmap.h +++ b/ecal/core/src/ecal_expmap.h @@ -45,27 +45,21 @@ namespace eCAL class CExpMap { public: - typedef std::chrono::steady_clock clock_type; + using clock_type = std::chrono::steady_clock; // Key access history, most recent at back - typedef std::list> key_tracker_type; + using key_tracker_type = std::list>; // Key to value and key history iterator - typedef std::map< - Key, - std::pair< - T, - typename key_tracker_type::iterator - > - > key_to_value_type; - - typedef Alloc allocator_type; - typedef std::pair value_type; - typedef typename Alloc::reference reference; - typedef typename Alloc::const_reference const_reference; - typedef typename Alloc::difference_type difference_type; - typedef typename Alloc::size_type size_type; - typedef Key key_type; - typedef T mapped_type; + using key_to_value_type = std::map>; + + using allocator_type = Alloc; + using value_type = std::pair; + 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; class iterator : public std::iterator> //class iterator : public std::iterator diff --git a/ecal/core/src/ecal_global_accessors.cpp b/ecal/core/src/ecal_global_accessors.cpp index e3b89e73e4..c2909c6edf 100644 --- a/ecal/core/src/ecal_global_accessors.cpp +++ b/ecal/core/src/ecal_global_accessors.cpp @@ -62,79 +62,79 @@ namespace eCAL CConfig* g_config() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->config().get()); } CLog* g_log() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->log().get()); } CMonitoring* g_monitoring() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->monitoring().get()); } CTimeGate* g_timegate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->timegate().get()); } CRegistrationProvider* g_registration_provider() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->registration_provider().get()); } CDescGate* g_descgate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->descgate().get()); } CSubGate* g_subgate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->subgate().get()); } CPubGate* g_pubgate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->pubgate().get()); } CServiceGate* g_servicegate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->servicegate().get()); } CClientGate* g_clientgate() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->clientgate().get()); } CRegistrationReceiver* g_registration_receiver() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->registration_receiver().get()); } CMemFileThreadPool* g_memfile_pool() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->memfile_pool().get()); } CMemFileMap* g_memfile_map() { - if (!g_globals()) return(nullptr); + if (g_globals() == nullptr) return(nullptr); return(g_globals()->memfile_map().get()); } } diff --git a/ecal/core/src/ecal_globals.cpp b/ecal/core/src/ecal_globals.cpp index a433d12c3d..cae6b658c3 100644 --- a/ecal/core/src/ecal_globals.cpp +++ b/ecal/core/src/ecal_globals.cpp @@ -125,7 +125,7 @@ namespace eCAL ///////////////////// // SUBSCRIBER GATE ///////////////////// - if (components_ & Init::Subscriber) + if ((components_ & Init::Subscriber) != 0u) { if (subgate_instance == nullptr) { @@ -137,7 +137,7 @@ namespace eCAL ///////////////////// // PUBLISHER GATE ///////////////////// - if (components_ & Init::Publisher) + if ((components_ & Init::Publisher) != 0u) { if (pubgate_instance == nullptr) { @@ -146,7 +146,7 @@ namespace eCAL } } - if (components_ & Init::Service) + if ((components_ & Init::Service) != 0u) { // Reset the service manager, so it will be able to create new services, again eCAL::service::ServiceManager::instance()->reset(); @@ -173,7 +173,7 @@ namespace eCAL ///////////////////// // TIMEGATE ///////////////////// - if (components_ & Init::TimeSync) + if ((components_ & Init::TimeSync) != 0u) { if (timegate_instance == nullptr) { @@ -185,7 +185,7 @@ namespace eCAL ///////////////////// // MONITORING ///////////////////// - if (components_ & Init::Monitoring) + if ((components_ & Init::Monitoring) != 0u) { if (monitoring_instance == nullptr) { @@ -197,7 +197,7 @@ namespace eCAL ///////////////////// // LOGGING ///////////////////// - if (components_ & Init::Logging) + if ((components_ & Init::Logging) != 0u) { if (log_instance == nullptr) { @@ -209,18 +209,18 @@ namespace eCAL ///////////////////// // CREATE ALL ///////////////////// - //if (config_instance) config_instance->Create(); - if (log_instance && (components_ & Init::Logging)) log_instance->Create(); - if (registration_provider_instance) registration_provider_instance->Create(true, true, (components_ & Init::ProcessReg) != 0x0); - if (descgate_instance) descgate_instance->Create(); - if (registration_receiver_instance) registration_receiver_instance->Create(); - if (memfile_pool_instance) memfile_pool_instance->Create(); - if (subgate_instance && (components_ & Init::Subscriber)) subgate_instance->Create(); - if (pubgate_instance && (components_ & Init::Publisher)) pubgate_instance->Create(); - if (servicegate_instance && (components_ & Init::Service)) servicegate_instance->Create(); - if (clientgate_instance && (components_ & Init::Service)) clientgate_instance->Create(); - if (timegate_instance && (components_ & Init::TimeSync)) timegate_instance->Create(CTimeGate::eTimeSyncMode::realtime); - if (monitoring_instance && (components_ & Init::Monitoring)) monitoring_instance->Create(); + //if (config_instance) config_instance->Create(); + if (log_instance && ((components_ & Init::Logging) != 0u)) log_instance->Create(); + if (registration_provider_instance) registration_provider_instance->Create(true, true, (components_ & Init::ProcessReg) != 0x0); + if (descgate_instance) descgate_instance->Create(); + if (registration_receiver_instance) registration_receiver_instance->Create(); + if (memfile_pool_instance) memfile_pool_instance->Create(); + if (subgate_instance && ((components_ & Init::Subscriber) != 0u)) subgate_instance->Create(); + if (pubgate_instance && ((components_ & Init::Publisher) != 0u)) pubgate_instance->Create(); + if (servicegate_instance && ((components_ & Init::Service) != 0u)) servicegate_instance->Create(); + if (clientgate_instance && ((components_ & Init::Service) != 0u)) clientgate_instance->Create(); + if (timegate_instance && ((components_ & Init::TimeSync) != 0u)) timegate_instance->Create(CTimeGate::eTimeSyncMode::realtime); + if (monitoring_instance && ((components_ & Init::Monitoring) != 0u)) monitoring_instance->Create(); initialized = true; components |= components_; diff --git a/ecal/core/src/ecal_log.cpp b/ecal/core/src/ecal_log.cpp index 353208cd18..557dce7e25 100644 --- a/ecal/core/src/ecal_log.cpp +++ b/ecal/core/src/ecal_log.cpp @@ -39,7 +39,7 @@ namespace eCAL **/ void SetLogLevel(const eCAL_Logging_eLogLevel level_) { - if(g_log()) g_log()->SetLogLevel(level_); + if(g_log() != nullptr) g_log()->SetLogLevel(level_); } /** @@ -49,8 +49,8 @@ namespace eCAL **/ eCAL_Logging_eLogLevel GetLogLevel() { - if(g_log()) return(g_log()->GetLogLevel()); - else return(log_level_none); + if(g_log() != nullptr) return(g_log()->GetLogLevel()); + else return(log_level_none); } /** @@ -60,7 +60,7 @@ namespace eCAL **/ void Log(const std::string& msg_) { - if(g_log()) g_log()->Log(msg_); + if(g_log() != nullptr) g_log()->Log(msg_); } /** @@ -68,7 +68,7 @@ namespace eCAL **/ void StartCoreTimer() { - if(g_log()) g_log()->StartCoreTimer(); + if(g_log() != nullptr) g_log()->StartCoreTimer(); } /** @@ -76,7 +76,7 @@ namespace eCAL **/ void StopCoreTimer() { - if(g_log()) g_log()->StopCoreTimer(); + if(g_log() != nullptr) g_log()->StopCoreTimer(); } /** @@ -84,7 +84,7 @@ namespace eCAL **/ void SetCoreTime(const double time_) { - if(g_log()) g_log()->SetCoreTime(std::chrono::duration(time_)); + if(g_log() != nullptr) g_log()->SetCoreTime(std::chrono::duration(time_)); } /** @@ -92,7 +92,7 @@ namespace eCAL **/ double GetCoreTime() { - if(g_log()) + if(g_log() != nullptr) { return(g_log()->GetCoreTime().count()); } diff --git a/ecal/core/src/ecal_process.cpp b/ecal/core/src/ecal_process.cpp index 3307398612..945fec3045 100644 --- a/ecal/core/src/ecal_process.cpp +++ b/ecal/core/src/ecal_process.cpp @@ -151,7 +151,7 @@ namespace // iterate adapters and create hash int hash(0); - while(pAdapter) + while(pAdapter != nullptr) { for (UINT i = 0; i < pAdapter->AddressLength; ++i) { @@ -205,7 +205,7 @@ namespace eCAL #endif sstream << std::endl; - if (!eCAL::IsInitialized()) + if (eCAL::IsInitialized() == 0) { sstream << "Components : NOT INITIALIZED ( call eCAL::Initialize() )"; sstream << std::endl; @@ -452,14 +452,14 @@ namespace eCAL int AddRegistrationCallback(enum eCAL_Registration_Event event_, RegistrationCallbackT callback_) { - if (!g_registration_receiver()) return -1; + if (g_registration_receiver() == nullptr) return -1; if (g_registration_receiver()->AddRegistrationCallback(event_, callback_)) return 0; return -1; } int RemRegistrationCallback(enum eCAL_Registration_Event event_) { - if (!g_registration_receiver()) return -1; + if (g_registration_receiver() == nullptr) return -1; if (g_registration_receiver()->RemRegistrationCallback(event_)) return 0; return -1; } @@ -626,11 +626,11 @@ namespace eCAL if (block_) { // Wait until child process exits. - if (pi.hProcess) WaitForSingleObject(pi.hProcess, INFINITE); + if (pi.hProcess != nullptr) WaitForSingleObject(pi.hProcess, INFINITE); // Close process and thread handles. - if (pi.hProcess) CloseHandle(pi.hProcess); - if (pi.hThread) CloseHandle(pi.hThread); + if (pi.hProcess != nullptr) CloseHandle(pi.hProcess); + if (pi.hThread != nullptr) CloseHandle(pi.hThread); } return(ret_pid); @@ -692,8 +692,8 @@ namespace eCAL GetExitCodeProcess(pi.hProcess, &taskkill_error); // Close process and thread handles. - if (pi.hProcess) CloseHandle(pi.hProcess); - if (pi.hThread) CloseHandle(pi.hThread); + if (pi.hProcess != nullptr) CloseHandle(pi.hProcess); + if (pi.hThread != nullptr) CloseHandle(pi.hThread); return (taskkill_error == 0); } @@ -745,8 +745,8 @@ namespace eCAL GetExitCodeProcess(pi.hProcess, &taskkill_error); // Close process and thread handles. - if (pi.hProcess) CloseHandle(pi.hProcess); - if (pi.hThread) CloseHandle(pi.hThread); + if (pi.hProcess != nullptr) CloseHandle(pi.hProcess); + if (pi.hThread != nullptr) CloseHandle(pi.hThread); return (taskkill_error == 0); } diff --git a/ecal/core/src/ecal_thread.cpp b/ecal/core/src/ecal_thread.cpp index 7bb1ce5cc9..2ece2fc9e0 100644 --- a/ecal/core/src/ecal_thread.cpp +++ b/ecal/core/src/ecal_thread.cpp @@ -85,7 +85,7 @@ namespace eCAL void CThread::HelperThread(void* par_) { - if(!par_) return; + if(par_ == nullptr) return; struct ThreadData* tdata = static_cast(par_); if(!gEventIsValid(tdata->event)) return; diff --git a/ecal/core/src/ecal_time.cpp b/ecal/core/src/ecal_time.cpp index 9c3aed145e..e0c92801ad 100644 --- a/ecal/core/src/ecal_time.cpp +++ b/ecal/core/src/ecal_time.cpp @@ -35,13 +35,13 @@ namespace eCAL { std::string GetName() { - if (!g_timegate() || !g_timegate()->IsValid()) return(""); + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) return(""); return(g_timegate()->GetName()); } long long GetMicroSeconds() { - if (!g_timegate() || !g_timegate()->IsValid()) + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) { const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); return(std::chrono::duration_cast(now.time_since_epoch()).count()); @@ -51,7 +51,7 @@ namespace eCAL long long GetNanoSeconds() { - if (!g_timegate() || !g_timegate()->IsValid()) + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) { const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); return(std::chrono::duration_cast(now.time_since_epoch()).count()); @@ -61,25 +61,25 @@ namespace eCAL bool SetNanoSeconds(long long time_) { - if (!g_timegate() || !g_timegate()->IsValid()) return(false); + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) return(false); return(g_timegate()->SetNanoSeconds(time_)); } bool IsSynchronized() { - if (!g_timegate() || !g_timegate()->IsValid()) return(false); + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) return(false); return(g_timegate()->IsSynchronized()); } bool IsMaster() { - if (!g_timegate() || !g_timegate()->IsValid()) return(false); + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) return(false); return(g_timegate()->IsMaster()); } void SleepForNanoseconds(long long duration_nsecs_) { - if (!g_timegate() || !g_timegate()->IsValid()) + if ((g_timegate() == nullptr) || !g_timegate()->IsValid()) { eCAL::Process::SleepFor(std::chrono::nanoseconds(duration_nsecs_)); } @@ -90,9 +90,9 @@ namespace eCAL } void GetStatus(int& error_, std::string* const status_message_) { - if (!g_timegate()) { + if (g_timegate() == nullptr) { error_ = -1; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("Timegate has not been initialized!"); } } diff --git a/ecal/core/src/ecal_timegate.cpp b/ecal/core/src/ecal_timegate.cpp index 9f206ac9ae..c11ae054b9 100644 --- a/ecal/core/src/ecal_timegate.cpp +++ b/ecal/core/src/ecal_timegate.cpp @@ -97,13 +97,13 @@ namespace eCAL } // initialize real time - if (!m_is_initialized_rt && m_time_sync_rt.etime_initialize_ptr) + if (!m_is_initialized_rt && (m_time_sync_rt.etime_initialize_ptr != nullptr)) { m_is_initialized_rt = m_time_sync_rt.etime_initialize_ptr() == 0; } // initialize replay - if (!m_is_initialized_replay && m_time_sync_replay.etime_initialize_ptr) + if (!m_is_initialized_replay && (m_time_sync_replay.etime_initialize_ptr != nullptr)) { m_is_initialized_replay = m_time_sync_replay.etime_initialize_ptr() == 0; } @@ -273,7 +273,7 @@ namespace eCAL { if (!m_created) { error_ = -1; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("eCAL Timegate has not been created."); } } @@ -284,19 +284,19 @@ namespace eCAL { case eTimeSyncMode::none: error_ = 0; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("Timesync mode is set to NONE."); } break; case eTimeSyncMode::realtime: if (!m_successfully_loaded_rt){ error_ = -1; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("Failed to load realtime timesync module "); status_message_->append(GetName()); } } else { - if (status_message_) { + if (status_message_ != nullptr) { char buffer[buffer_len]; buffer[0] = 0x0; m_time_sync_rt.etime_get_status_ptr(&error_, buffer, buffer_len); @@ -311,12 +311,12 @@ namespace eCAL case eTimeSyncMode::replay: if (!m_successfully_loaded_replay){ error_ = -1; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("Failed to load realtime timesync module "); status_message_->append(GetName()); } } else { - if (status_message_) { + if (status_message_ != nullptr) { char buffer[buffer_len]; buffer[0] = 0x0; m_time_sync_replay.etime_get_status_ptr(&error_, buffer, buffer_len); @@ -330,7 +330,7 @@ namespace eCAL break; default: error_ = -1; - if (status_message_) { + if (status_message_ != nullptr) { status_message_->assign("Unknown Error."); } } @@ -379,7 +379,7 @@ namespace eCAL module_name = "lib" + module_name + ".dylib"; #endif // __APPLE__ - if (!interface_.module_handle) + if (interface_.module_handle == nullptr) { #ifdef _WIN32 // try to load plugin from paths that are specified in the time plugin environment variable @@ -387,18 +387,18 @@ namespace eCAL { const auto module_path = ecal_time_plugin_path + "\\" + module_name; interface_.module_handle = LoadLibrary(module_path.c_str()); - if (interface_.module_handle) break; + if (interface_.module_handle != nullptr) break; } // try to load plugin in standard path - if (!interface_.module_handle) + if (interface_.module_handle == nullptr) { const auto module_path = module_name; interface_.module_handle = LoadLibrary(module_path.c_str()); } // try to load plugin from sub folder "ecal_time_plugin_dir" - if (!interface_.module_handle) + if (interface_.module_handle == nullptr) { const auto module_path = std::string(ecal_time_plugin_dir) + "\\" + module_name; interface_.module_handle = LoadLibrary(module_path.c_str()); @@ -421,7 +421,7 @@ namespace eCAL } #endif // defined(__linux__) || defined(__APPLE__) - if (!interface_.module_handle) + if (interface_.module_handle == nullptr) { eCAL::Logging::Log(log_level_error, "Could not load eCAL time sync module " + module_name); return false; diff --git a/ecal/core/src/ecal_util.cpp b/ecal/core/src/ecal_util.cpp index e4e3f117d2..aa18a13118 100644 --- a/ecal/core/src/ecal_util.cpp +++ b/ecal/core/src/ecal_util.cpp @@ -59,7 +59,7 @@ namespace eCAL } eCAL::pb::Monitoring monitoring; - if (eCAL::g_monitoring()) eCAL::g_monitoring()->GetMonitoring(monitoring); + if (eCAL::g_monitoring() != nullptr) eCAL::g_monitoring()->GetMonitoring(monitoring); return(monitoring); } @@ -168,28 +168,28 @@ namespace eCAL void EnableLoopback(bool state_) { - if (g_registration_receiver()) g_registration_receiver()->EnableLoopback(state_); + if (g_registration_receiver() != nullptr) g_registration_receiver()->EnableLoopback(state_); } void PubShareType(bool state_) { - if (g_pubgate()) g_pubgate()->ShareType(state_); + if (g_pubgate() != nullptr) g_pubgate()->ShareType(state_); } void PubShareDescription(bool state_) { - if (g_pubgate()) g_pubgate()->ShareDescription(state_); + if (g_pubgate() != nullptr) g_pubgate()->ShareDescription(state_); } void GetTopics(std::unordered_map& topic_info_map_) { - if (!g_descgate()) return; + if (g_descgate() == nullptr) return; g_descgate()->GetTopics(topic_info_map_); } void GetTopicNames(std::vector& topic_names_) { - if (!g_descgate()) return; + if (g_descgate() == nullptr) return; g_descgate()->GetTopicNames(topic_names_); } @@ -294,25 +294,25 @@ namespace eCAL void GetServices(std::map, SServiceMethodInformation>& service_info_map_) { - if (!g_descgate()) return; + if (g_descgate() == nullptr) return; g_descgate()->GetServices(service_info_map_); } void GetServiceNames(std::vector>& service_method_names_) { - if (!g_descgate()) return; + if (g_descgate() == nullptr) return; g_descgate()->GetServiceNames(service_method_names_); } bool GetServiceTypeNames(const std::string& service_name_, const std::string& method_name_, std::string& req_type_, std::string& resp_type_) { - if (!g_descgate()) return(false); + if (g_descgate() == nullptr) return(false); return(g_descgate()->GetServiceTypeNames(service_name_, method_name_, req_type_, resp_type_)); } bool GetServiceDescription(const std::string& service_name_, const std::string& method_name_, std::string& req_desc_, std::string& resp_desc_) { - if (!g_descgate()) return(false); + if (g_descgate() == nullptr) return(false); return(g_descgate()->GetServiceDescription(service_name_, method_name_, req_desc_, resp_desc_)); } }