From 00fcce119467d53dc5f57246fe8895385985c4d1 Mon Sep 17 00:00:00 2001 From: Kristof Hannemann <50989282+hannemn@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:04:04 +0100 Subject: [PATCH 1/2] Adapted c-api of monitoring to remain c-return value compliant and removed obsolete ecal_clang functions --- ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp | 8 +-- lang/python/core/src/ecal_clang.cpp | 57 ------------------- lang/python/core/src/ecal_clang.h | 54 ------------------ lang/python/core/src/ecal_wrap.cxx | 2 +- 4 files changed, 5 insertions(+), 116 deletions(-) diff --git a/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp b/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp index 7115187709..bdbca536d0 100644 --- a/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp +++ b/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp @@ -32,23 +32,23 @@ extern "C" { ECALC_API int eCAL_Monitoring_SetExclFilter(const char* filter_) { - return(eCAL::Monitoring::SetExclFilter(std::string(filter_))); + return(!eCAL::Monitoring::SetExclFilter(std::string(filter_))); } ECALC_API int eCAL_Monitoring_SetInclFilter(const char* filter_) { - return(eCAL::Monitoring::SetInclFilter(std::string(filter_))); + return(!eCAL::Monitoring::SetInclFilter(std::string(filter_))); } ECALC_API int eCAL_Monitoring_SetFilterState(int state_) { - return(eCAL::Monitoring::SetFilterState(state_ != 0)); + return(!eCAL::Monitoring::SetFilterState(state_ != 0)); } ECALC_API int eCAL_Monitoring_GetMonitoring(void* buf_, int buf_len_) { std::string buf; - if (eCAL::Monitoring::GetMonitoring(buf) != 0) + if (eCAL::Monitoring::GetMonitoring(buf)) { return(CopyBuffer(buf_, buf_len_, buf)); } diff --git a/lang/python/core/src/ecal_clang.cpp b/lang/python/core/src/ecal_clang.cpp index 10b4d014dc..ea2e4a987d 100644 --- a/lang/python/core/src/ecal_clang.cpp +++ b/lang/python/core/src/ecal_clang.cpp @@ -733,63 +733,6 @@ int mon_finalize() return(ecal_finalize()); } -/****************************************/ -/* mon_set_excl_filter */ -/****************************************/ -int mon_set_excl_filter(const char* filter_) -{ - return(eCAL::Monitoring::SetExclFilter(filter_)); -} - -/****************************************/ -/* mon_set_incl_filter */ -/****************************************/ -int mon_set_incl_filter(const char* filter_) -{ - return(eCAL::Monitoring::SetInclFilter(filter_)); -} - -/****************************************/ -/* mon_set_filter_state */ -/****************************************/ -int mon_set_filter_state(const bool state_) -{ - return(eCAL::Monitoring::SetFilterState(state_)); -} - -/****************************************/ -/* mon_get_monitoring */ -/****************************************/ -int mon_get_monitoring(const char** mon_buf_, int* mon_buf_len_) -{ - std::string mon_s; - const int size = eCAL::Monitoring::GetMonitoring(mon_s); - if(size > 0) - { - // this has to be freed by caller (ecal_free_mem) - char* cbuf = str_malloc(mon_s); - if(cbuf == nullptr) return(0); - - if (mon_buf_ != nullptr) { - *mon_buf_ = cbuf; - 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_ != nullptr) *mon_buf_len_ = 0; - // operation could't be completed successfully - return(0); - } - return(static_cast(mon_s.size())); - } - else - { - return(0); - } -} - /****************************************/ /* mon_get_logging */ /****************************************/ diff --git a/lang/python/core/src/ecal_clang.h b/lang/python/core/src/ecal_clang.h index 951f52031e..c6356ce5b5 100644 --- a/lang/python/core/src/ecal_clang.h +++ b/lang/python/core/src/ecal_clang.h @@ -521,60 +521,6 @@ int mon_initialize(); **/ int mon_finalize(); -/** - * @brief Set topics filter blacklist regular expression. - * - * @param filter_ Topic filter as regular expression. - * - * @return Zero if succeeded. -**/ -int mon_set_excl_filter(const char* filter_); - -/** - * @brief Set topics filter whitelist regular expression. - * - * @param filter_ Topic filter as regular expression. - * - * @return Zero if succeeded. -**/ -int mon_set_incl_filter(const char* filter_); - -/** - * @brief Switch topics filter using regular expression on/off. - * - * @param state_ Filter on / off state. - * - * @return Zero if succeeded. -**/ -int mon_set_filter_state(bool state_); - -/** - * @brief Get monitoring protobuf string. - * - * @param [out] mon_buf_ Pointer to store the monitoring information. - * @param [out] mon_buf_len_ Length of allocated buffer, - * eCAL is allocating the buffer for you, use ecal_free_mem to free the buffer finally. - * - * @return Monitoring buffer length or zero if failed. -**/ -/** - * @code - * // let eCAL allocate memory for the monitoring buffer and return the pointer to 'buf' - * const char* mon_buf_ = NULL; - * int mon_buf_len_ = 0; - * mon_get_monitoring(subscriber_handle, &mon_buf_, &mon_buf_len_); - * if(mon_buf_len_ > 0) - * { - * ... - * // PROCESS THE BUFFER CONTENT HERE - * ... - * // finally free the allocated memory - * ecal_free_mem(((void*)rcv_buf);); - * } - * @endcode -**/ -int mon_get_monitoring(const char** mon_buf_, int* mon_buf_len_); - /** * @brief Get logging string. * diff --git a/lang/python/core/src/ecal_wrap.cxx b/lang/python/core/src/ecal_wrap.cxx index 167c0a13de..216bd633ec 100644 --- a/lang/python/core/src/ecal_wrap.cxx +++ b/lang/python/core/src/ecal_wrap.cxx @@ -1055,7 +1055,7 @@ PyObject* mon_monitoring(PyObject* /*self*/, PyObject* /*args*/) PyObject* retDict = PyDict_New(); eCAL::Monitoring::SMonitoring monitoring; - if (eCAL::Monitoring::GetMonitoring(monitoring) != 0) + if (eCAL::Monitoring::GetMonitoring(monitoring)) { PyObject* val; From 647cd81e259572b3ac8bc1fe258de12d2942ffa6 Mon Sep 17 00:00:00 2001 From: Kristof Hannemann <50989282+hannemn@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:41:14 +0100 Subject: [PATCH 2/2] Added explicit conversions from bool to int --- ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp b/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp index bdbca536d0..cea6351e09 100644 --- a/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp +++ b/ecal/core/src/cimpl/ecal_monitoring_cimpl.cpp @@ -32,17 +32,17 @@ extern "C" { ECALC_API int eCAL_Monitoring_SetExclFilter(const char* filter_) { - return(!eCAL::Monitoring::SetExclFilter(std::string(filter_))); + return(static_cast(!eCAL::Monitoring::SetExclFilter(std::string(filter_)))); } ECALC_API int eCAL_Monitoring_SetInclFilter(const char* filter_) { - return(!eCAL::Monitoring::SetInclFilter(std::string(filter_))); + return(static_cast(!eCAL::Monitoring::SetInclFilter(std::string(filter_)))); } ECALC_API int eCAL_Monitoring_SetFilterState(int state_) { - return(!eCAL::Monitoring::SetFilterState(state_ != 0)); + return(static_cast(!eCAL::Monitoring::SetFilterState(state_ != 0))); } ECALC_API int eCAL_Monitoring_GetMonitoring(void* buf_, int buf_len_)