From 668767066bc31024de55d805f21e77eae7cabc5f Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:18:38 +0200 Subject: [PATCH 1/6] add 2 new event API functions gOpenNamedEvent and gOpenUnnamedEvent gOpenNamedEvent can handle ownership --- ecal/core/include/ecal/ecal_event.h | 23 ++++++ ecal/core/src/ecal_event.cpp | 73 ++++++++++++++++-- ecal/core/src/ecal_thread.cpp | 2 +- ecal/core/src/ecal_util.cpp | 2 +- ecal/core/src/ecalc.cpp | 2 +- ecal/core/src/io/ecal_memfile_pool.cpp | 4 +- ecal/core/src/io/ecal_memfile_sync.cpp | 6 +- ecal/core/src/pubsub/ecal_subgate.cpp | 2 +- samples/cpp/misc/event_rec/src/event_rec.cpp | 2 +- samples/cpp/misc/event_snd/src/event_snd.cpp | 2 +- testing/ecal/event_test/src/event_test.cpp | 9 ++- testing/ecal/pubsub_test/src/pubsub_test.cpp | 79 ++++++++++++++++++-- 12 files changed, 177 insertions(+), 29 deletions(-) diff --git a/ecal/core/include/ecal/ecal_event.h b/ecal/core/include/ecal/ecal_event.h index 5ce11a9018..fb5b1e690a 100644 --- a/ecal/core/include/ecal/ecal_event.h +++ b/ecal/core/include/ecal/ecal_event.h @@ -26,10 +26,32 @@ #include #include +#include + #include namespace eCAL { + /** + * @brief Open a named event with ownership. + * + * @param [out] event_ Returned event struct. + * @param event_name_ Event name. + * @param ownership_ Event is owned by the caller and will be destroyed on CloseEvent + * + * @return True if succeeded. + **/ + ECAL_API bool gOpenNamedEvent(eCAL::EventHandleT* event_, const std::string& event_name_, bool ownership_); + + /** + * @brief Open a named event with ownership. + * + * @param [out] event_ Returned event struct. + * + * @return True if succeeded. + **/ + ECAL_API bool gOpenUnnamedEvent(eCAL::EventHandleT* event_); + /** * @brief Open a named or unnamed event. * @@ -38,6 +60,7 @@ namespace eCAL * * @return True if succeeded. **/ + ECAL_DEPRECATE_SINCE_5_13("Use either gOpenNamedEvent or gOpenUnnamedEvent") ECAL_API bool gOpenEvent(eCAL::EventHandleT* event_, const std::string& event_name_ = ""); /** diff --git a/ecal/core/src/ecal_event.cpp b/ecal/core/src/ecal_event.cpp index e93ecb9344..9b81d2e122 100644 --- a/ecal/core/src/ecal_event.cpp +++ b/ecal/core/src/ecal_event.cpp @@ -18,7 +18,7 @@ */ /** - * @brief eCAL handle helper class - windows platform + * @brief eCAL handle helper class **/ #include @@ -35,12 +35,12 @@ #include "ecal_win_main.h" -namespace eCAL +namespace { - bool gOpenEvent(EventHandleT* event_, const std::string& event_name_) + bool OpenEvent(eCAL::EventHandleT* event_, const std::string& event_name_) { if(event_ == nullptr) return(false); - EventHandleT event; + eCAL::EventHandleT event; event.name = event_name_; event.handle = ::CreateEvent(nullptr, false, false, event_name_.c_str()); if(event.handle != nullptr) @@ -50,6 +50,25 @@ namespace eCAL } return(false); } +} + +namespace eCAL +{ + bool gOpenNamedEvent(eCAL::EventHandleT* event_, const std::string& event_name_, bool /*ownership_*/) + { + return OpenEvent(event_, event_name_); + } + + bool gOpenUnnamedEvent(eCAL::EventHandleT* event_) + { + return OpenEvent(event_, ""); + } + + // deprecated + bool gOpenEvent(EventHandleT* event_, const std::string& event_name_) + { + return OpenEvent(event_, event_name_); + } bool gCloseEvent(const EventHandleT& event_) { @@ -302,9 +321,10 @@ namespace eCAL class CNamedEvent { public: - explicit CNamedEvent(const std::string& name_) : + explicit CNamedEvent(const std::string& name_, bool ownership_) : m_name(name_ + "_evt"), - m_event(nullptr) + m_event(nullptr), + m_owner(ownership_) { m_name = (m_name[0] != '/') ? "/" + m_name : m_name; // make memory file path compatible for all posix systems m_event = named_event_open(m_name.c_str()); @@ -318,7 +338,10 @@ namespace eCAL { if(m_event == nullptr) return; named_event_close(m_event); - named_event_destroy(m_name.c_str()); + if(m_owner) + { + named_event_destroy(m_name.c_str()); + } } void set() @@ -371,8 +394,42 @@ namespace eCAL std::string m_name; named_event_t* m_event; + bool m_owner; }; + bool gOpenNamedEvent(EventHandleT* event_, const std::string& event_name_, bool ownership_) + { + if(event_ == nullptr) return(false); + + EventHandleT event; + event.name = event_name_; + event.handle = new CNamedEvent(event.name, ownership_); + + if(event.handle != nullptr) + { + *event_ = event; + return true; + } + return false; + } + + bool gOpenUnnamedEvent(EventHandleT* event_) + { + if(event_ == nullptr) return(false); + + EventHandleT event; + event.name = ""; + event.handle = new CEvent(); + + if(event.handle != nullptr) + { + *event_ = event; + return true; + } + return false; + } + + // deprecated bool gOpenEvent(EventHandleT* event_, const std::string& event_name_) { if(event_ == nullptr) return(false); @@ -386,7 +443,7 @@ namespace eCAL } else { - event.handle = new CNamedEvent(event.name); + event.handle = new CNamedEvent(event.name, true); } if(event.handle != nullptr) diff --git a/ecal/core/src/ecal_thread.cpp b/ecal/core/src/ecal_thread.cpp index e4bf8aed82..d118a53dbf 100644 --- a/ecal/core/src/ecal_thread.cpp +++ b/ecal/core/src/ecal_thread.cpp @@ -41,7 +41,7 @@ namespace eCAL { if(m_tdata.is_started) return(0); - gOpenEvent(&m_tdata.event); + gOpenUnnamedEvent(&m_tdata.event); m_tdata.do_stop = false; m_tdata.period = period_; m_tdata.ext_caller = ext_caller_; diff --git a/ecal/core/src/ecal_util.cpp b/ecal/core/src/ecal_util.cpp index df8806be9e..4590ecc939 100644 --- a/ecal/core/src/ecal_util.cpp +++ b/ecal/core/src/ecal_util.cpp @@ -91,7 +91,7 @@ namespace eCAL { const std::string event_name = EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(process_id_); EventHandleT event; - if (gOpenEvent(&event, event_name)) + if (gOpenNamedEvent(&event, event_name, true)) { std::cout << "Shutdown local eCAL process " << process_id_ << std::endl; gSetEvent(event); diff --git a/ecal/core/src/ecalc.cpp b/ecal/core/src/ecalc.cpp index 8cd8492b68..c8f68be5e8 100644 --- a/ecal/core/src/ecalc.cpp +++ b/ecal/core/src/ecalc.cpp @@ -469,7 +469,7 @@ extern "C" ECALC_API ECAL_HANDLE eCAL_Event_gOpenEvent(const char* event_name_) { eCAL::EventHandleT* event_handle = new eCAL::EventHandleT; - const bool success = eCAL::gOpenEvent(event_handle, event_name_); + const bool success = eCAL::gOpenNamedEvent(event_handle, event_name_, true); if (success) { return(event_handle); diff --git a/ecal/core/src/io/ecal_memfile_pool.cpp b/ecal/core/src/io/ecal_memfile_pool.cpp index a028b5780b..eb274c859c 100644 --- a/ecal/core/src/io/ecal_memfile_pool.cpp +++ b/ecal/core/src/io/ecal_memfile_pool.cpp @@ -54,8 +54,8 @@ namespace eCAL if (m_created) return false; // open memory file events - gOpenEvent(&m_event_snd, memfile_event_); - gOpenEvent(&m_event_ack, memfile_event_ + "_ack"); + gOpenNamedEvent(&m_event_snd, memfile_event_, false); + gOpenNamedEvent(&m_event_ack, memfile_event_ + "_ack", false); // create memory file access m_memfile.Create(memfile_name_.c_str(), false); diff --git a/ecal/core/src/io/ecal_memfile_sync.cpp b/ecal/core/src/io/ecal_memfile_sync.cpp index ee22d8a363..d32649c4d1 100644 --- a/ecal/core/src/io/ecal_memfile_sync.cpp +++ b/ecal/core/src/io/ecal_memfile_sync.cpp @@ -65,8 +65,8 @@ namespace eCAL if (iter == m_event_handle_map.end()) { SEventHandlePair event_pair; - gOpenEvent(&event_pair.event_snd, event_snd_name); - gOpenEvent(&event_pair.event_ack, event_ack_name); + gOpenNamedEvent(&event_pair.event_snd, event_snd_name, true); + gOpenNamedEvent(&event_pair.event_ack, event_ack_name, true); m_event_handle_map.insert(std::pair(process_id_, event_pair)); return true; } @@ -77,7 +77,7 @@ namespace eCAL // event was deactivated by a sync timeout in SendSyncEvents if (!gEventIsValid(iter->second.event_ack)) { - gOpenEvent(&iter->second.event_ack, event_ack_name); + gOpenNamedEvent(&iter->second.event_ack, event_ack_name, true); } // Set the ack event to valid again, so we will wait for the subscriber diff --git a/ecal/core/src/pubsub/ecal_subgate.cpp b/ecal/core/src/pubsub/ecal_subgate.cpp index de43f46526..1959a7dbf3 100644 --- a/ecal/core/src/pubsub/ecal_subgate.cpp +++ b/ecal/core/src/pubsub/ecal_subgate.cpp @@ -47,7 +47,7 @@ namespace eCAL static const std::string event_name(EVENT_SHUTDOWN_PROC + std::string("_") + std::to_string(Process::GetProcessID())); if (!gEventIsValid(evt)) { - gOpenEvent(&evt, event_name); + gOpenNamedEvent(&evt, event_name, true); } return(evt); } diff --git a/samples/cpp/misc/event_rec/src/event_rec.cpp b/samples/cpp/misc/event_rec/src/event_rec.cpp index 435c0f67a2..ac6b894ec4 100644 --- a/samples/cpp/misc/event_rec/src/event_rec.cpp +++ b/samples/cpp/misc/event_rec/src/event_rec.cpp @@ -30,7 +30,7 @@ int main(int /*argc*/, char** /*argv*/) // create named event eCAL::EventHandleT event_handle; - eCAL::gOpenEvent(&event_handle, event_name); + eCAL::gOpenNamedEvent(&event_handle, event_name, false); // timer auto start_time(std::chrono::steady_clock::now()); diff --git a/samples/cpp/misc/event_snd/src/event_snd.cpp b/samples/cpp/misc/event_snd/src/event_snd.cpp index 6825b9cdd8..6835fd2c0c 100644 --- a/samples/cpp/misc/event_snd/src/event_snd.cpp +++ b/samples/cpp/misc/event_snd/src/event_snd.cpp @@ -30,7 +30,7 @@ int main(int /*argc*/, char** /*argv*/) // create named event eCAL::EventHandleT event_handle; - eCAL::gOpenEvent(&event_handle, event_name); + eCAL::gOpenNamedEvent(&event_handle, event_name, true); // timer auto start_time(std::chrono::steady_clock::now()); diff --git a/testing/ecal/event_test/src/event_test.cpp b/testing/ecal/event_test/src/event_test.cpp index 6e02acc94f..b62cf8d836 100644 --- a/testing/ecal/event_test/src/event_test.cpp +++ b/testing/ecal/event_test/src/event_test.cpp @@ -28,14 +28,17 @@ TEST(Event, EventSetGet) // create named event eCAL::EventHandleT event_handle; - EXPECT_EQ(true, eCAL::gOpenEvent(&event_handle, event_name)); + EXPECT_EQ(true, eCAL::gOpenNamedEvent(&event_handle, event_name, true)); - // get none set event + // wait for event, expect false EXPECT_EQ(false, gWaitForEvent(event_handle, 10)); // set event EXPECT_EQ(true, gSetEvent(event_handle)); - // get set event + // wait for event, expect true now EXPECT_EQ(true, gWaitForEvent(event_handle, 100)); + + // close (and unlink/destroy) event + EXPECT_EQ(true, eCAL::gCloseEvent(event_handle)); } diff --git a/testing/ecal/pubsub_test/src/pubsub_test.cpp b/testing/ecal/pubsub_test/src/pubsub_test.cpp index 214412cc92..5d908e4453 100644 --- a/testing/ecal/pubsub_test/src/pubsub_test.cpp +++ b/testing/ecal/pubsub_test/src/pubsub_test.cpp @@ -869,10 +869,6 @@ TEST(IO, MultipleSendsUDP) eCAL::Finalize(); } - - - - #if 0 TEST(IO, ZeroPayloadMessageTCP) { @@ -923,8 +919,6 @@ TEST(IO, ZeroPayloadMessageTCP) } #endif -#include -#include TEST(IO, DestroyInCallback) { /* Test setup : @@ -988,4 +982,75 @@ TEST(IO, DestroyInCallback) // finalize eCAL API // without destroying any pub / sub eCAL::Finalize(); -} \ No newline at end of file +} + +TEST(IO, SubscriberReconnection) +{ + /* Test setup : + * publisher runs permanently in a thread + * subscriber start reading + * subscriber gets out of scope (destruction) + * subscriber starts again in a new scope + * Test ensures that subscriber is reconnecting and all sync mechanism are working properly again. + */ + + // initialize eCAL API + eCAL::Initialize(0, nullptr, "SubscriberReconnection"); + + // enable loop back communication in the same thread + eCAL::Util::EnableLoopback(true); + + // start publishing thread + std::atomic stop_publishing(false); + eCAL::string::CPublisher pub_foo("foo"); + std::thread pub_foo_t([&pub_foo, &stop_publishing]() { + while (!stop_publishing) + { + pub_foo.Send("Hello World"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + std::cout << "Stopped publishing" << std::endl; + }); + + // scope 1 + { + size_t callback_received_count(0); + + eCAL::string::CSubscriber sub_foo("foo"); + auto receive_lambda = [&sub_foo, &callback_received_count](const char* /*topic_*/, const std::string& /*msg*/, long long /*time_*/, long long /*clock_*/, long long /*id_*/) { + std::cout << "Receiving in scope 1" << std::endl; + callback_received_count++; + }; + sub_foo.AddReceiveCallback(receive_lambda); + + // sleep for 2 seconds, we should receive something + std::this_thread::sleep_for(std::chrono::seconds(2)); + + EXPECT_TRUE(callback_received_count > 0); + } + + // scope 2 + { + size_t callback_received_count(0); + + eCAL::string::CSubscriber sub_foo("foo"); + auto receive_lambda = [&sub_foo, &callback_received_count](const char* /*topic_*/, const std::string& /*msg*/, long long /*time_*/, long long /*clock_*/, long long /*id_*/) { + std::cout << "Receiving in scope 2" << std::endl; + callback_received_count++; + }; + sub_foo.AddReceiveCallback(receive_lambda); + + // sleep for 2 seconds, we should receive something + std::this_thread::sleep_for(std::chrono::seconds(2)); + + EXPECT_TRUE(callback_received_count > 0); + } + + // stop publishing and join thread + stop_publishing = true; + pub_foo_t.join(); + + // finalize eCAL API + // without destroying any pub / sub + eCAL::Finalize(); +} From 850cbf3f971053ff1a2fa998dd7a809201bfda0a Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:00:52 +0200 Subject: [PATCH 2/6] CDataWriterSHM::RemLocConnection removed (this function makes no sense) --- ecal/core/src/readwrite/ecal_writer_shm.cpp | 22 --------------------- 1 file changed, 22 deletions(-) diff --git a/ecal/core/src/readwrite/ecal_writer_shm.cpp b/ecal/core/src/readwrite/ecal_writer_shm.cpp index eefbb74227..6872910273 100644 --- a/ecal/core/src/readwrite/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/ecal_writer_shm.cpp @@ -190,28 +190,6 @@ namespace eCAL return ret_state; } - bool CDataWriterSHM::RemLocConnection(const std::string& process_id_) - { - if (!m_created) return false; - bool ret_state(true); - - for (auto& memory_file : m_memory_file_vec) - { - // This is not working correctly under POSIX for memory files that are read and written within the same process. - // - // The functions 'CSyncMemoryFile::Disconnect' and 'CDataWriterSHM::RemLocConnection' are now called - // by the new Subscriber Unregistration event logic and were never called in any previous eCAL version. - // - // TODO: Fix this in 'CSyncMemoryFile::Disconnect' to handle event resources properly. - if (std::to_string(eCAL::Process::GetProcessID()) != process_id_) - { - ret_state &= memory_file->Disconnect(process_id_); - } - } - - return ret_state; - } - std::string CDataWriterSHM::GetConnectionParameter() { // starting from eCAL version > 5.8.13/5.9.0 the ConnectionParameter is defined as google protobuf From 6e47bb9299869b57e38ac5950fbb58443100a5c3 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:02:42 +0200 Subject: [PATCH 3/6] CDataWriterSHM::RemLocConnection removed from header (this function makes no sense) --- ecal/core/src/readwrite/ecal_writer_shm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ecal/core/src/readwrite/ecal_writer_shm.h b/ecal/core/src/readwrite/ecal_writer_shm.h index b4dbdbfd64..fae8988450 100644 --- a/ecal/core/src/readwrite/ecal_writer_shm.h +++ b/ecal/core/src/readwrite/ecal_writer_shm.h @@ -52,7 +52,6 @@ namespace eCAL bool Write(CPayloadWriter& payload_, const SWriterAttr& attr_) override; bool AddLocConnection(const std::string& process_id_, const std::string& conn_par_) override; - bool RemLocConnection(const std::string& process_id_) override; std::string GetConnectionParameter() override; From e597793bb3b9fee2cffd332a808ac583c0a0bda8 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:44:11 +0200 Subject: [PATCH 4/6] doxygen comment fixed --- ecal/core/include/ecal/ecal_event.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecal/core/include/ecal/ecal_event.h b/ecal/core/include/ecal/ecal_event.h index fb5b1e690a..a581df606d 100644 --- a/ecal/core/include/ecal/ecal_event.h +++ b/ecal/core/include/ecal/ecal_event.h @@ -44,9 +44,9 @@ namespace eCAL ECAL_API bool gOpenNamedEvent(eCAL::EventHandleT* event_, const std::string& event_name_, bool ownership_); /** - * @brief Open a named event with ownership. + * @brief Open an unnamed event. * - * @param [out] event_ Returned event struct. + * @param [out] event_ Returned event struct. * * @return True if succeeded. **/ From e73e4643a1e58f71aed93fcc40f97836d67bef9f Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:52:57 +0200 Subject: [PATCH 5/6] logging added --- ecal/core/src/readwrite/ecal_writer_shm.cpp | 3 +++ ecal/core/src/readwrite/ecal_writer_shm.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ecal/core/src/readwrite/ecal_writer_shm.cpp b/ecal/core/src/readwrite/ecal_writer_shm.cpp index 5dbee9cd44..3e45771701 100644 --- a/ecal/core/src/readwrite/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/ecal_writer_shm.cpp @@ -184,6 +184,9 @@ namespace eCAL for (auto& memory_file : m_memory_file_vec) { memory_file->Connect(process_id_); +#ifndef NDEBUG + Logging::Log(log_level_debug1, std::string("CDataWriterSHM::AddLocConnection - Memory FileName: ") + memory_file->GetName() + " to ProcessId " + process_id_); +#endif } } diff --git a/ecal/core/src/readwrite/ecal_writer_shm.h b/ecal/core/src/readwrite/ecal_writer_shm.h index 6dd7e72e40..daac497abf 100644 --- a/ecal/core/src/readwrite/ecal_writer_shm.h +++ b/ecal/core/src/readwrite/ecal_writer_shm.h @@ -51,7 +51,7 @@ namespace eCAL bool Write(CPayloadWriter& payload_, const SWriterAttr& attr_) override; - void AddLocConnection(const std::string& process_id_, const std::string& /*topic_id_*/, const std::string& conn_par_) override; + void AddLocConnection(const std::string& process_id_, const std::string& topic_id_, const std::string& conn_par_) override; std::string GetConnectionParameter() override; From 85e193e8698dcacda0fd927a250bc9ff5abd0f11 Mon Sep 17 00:00:00 2001 From: tftzee <49162693+rex-schilasky@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:49:50 +0200 Subject: [PATCH 6/6] new event functions gOpenNamedEvent and gOpenUnnamedEvent moved to internal API (ecal_event_internal.h) to be fully API/ABI compatible again --- ecal/core/include/ecal/ecal_event.h | 23 --------- ecal/core/src/ecal_event_internal.h | 54 ++++++++++++++++++++ ecal/core/src/ecal_thread.cpp | 1 + ecal/core/src/ecal_util.cpp | 1 + ecal/core/src/ecalc.cpp | 2 +- ecal/core/src/io/ecal_memfile_pool.cpp | 1 + ecal/core/src/io/ecal_memfile_sync.cpp | 1 + ecal/core/src/pubsub/ecal_subgate.cpp | 1 + samples/cpp/misc/event_rec/src/event_rec.cpp | 2 +- samples/cpp/misc/event_snd/src/event_snd.cpp | 2 +- testing/ecal/event_test/src/event_test.cpp | 9 ++-- 11 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 ecal/core/src/ecal_event_internal.h diff --git a/ecal/core/include/ecal/ecal_event.h b/ecal/core/include/ecal/ecal_event.h index a581df606d..5ce11a9018 100644 --- a/ecal/core/include/ecal/ecal_event.h +++ b/ecal/core/include/ecal/ecal_event.h @@ -26,32 +26,10 @@ #include #include -#include - #include namespace eCAL { - /** - * @brief Open a named event with ownership. - * - * @param [out] event_ Returned event struct. - * @param event_name_ Event name. - * @param ownership_ Event is owned by the caller and will be destroyed on CloseEvent - * - * @return True if succeeded. - **/ - ECAL_API bool gOpenNamedEvent(eCAL::EventHandleT* event_, const std::string& event_name_, bool ownership_); - - /** - * @brief Open an unnamed event. - * - * @param [out] event_ Returned event struct. - * - * @return True if succeeded. - **/ - ECAL_API bool gOpenUnnamedEvent(eCAL::EventHandleT* event_); - /** * @brief Open a named or unnamed event. * @@ -60,7 +38,6 @@ namespace eCAL * * @return True if succeeded. **/ - ECAL_DEPRECATE_SINCE_5_13("Use either gOpenNamedEvent or gOpenUnnamedEvent") ECAL_API bool gOpenEvent(eCAL::EventHandleT* event_, const std::string& event_name_ = ""); /** diff --git a/ecal/core/src/ecal_event_internal.h b/ecal/core/src/ecal_event_internal.h new file mode 100644 index 0000000000..5441d95769 --- /dev/null +++ b/ecal/core/src/ecal_event_internal.h @@ -0,0 +1,54 @@ +/* ========================= 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 ================================= +*/ + +/** + * @file ecal_event_internal.h + * @brief eCAL event interface (internal) + * + * This file will be renamed back to ecal_event.h after removing event API from eCAL's public API. +**/ + +#pragma once + +#include + +#include + +namespace eCAL +{ + /** + * @brief Open a named event with ownership. + * + * @param [out] event_ Returned event struct. + * @param event_name_ Event name. + * @param ownership_ Event is owned by the caller and will be destroyed on CloseEvent + * + * @return True if succeeded. + **/ + bool gOpenNamedEvent(eCAL::EventHandleT* event_, const std::string& event_name_, bool ownership_); + + /** + * @brief Open an unnamed event. + * + * @param [out] event_ Returned event struct. + * + * @return True if succeeded. + **/ + bool gOpenUnnamedEvent(eCAL::EventHandleT* event_); +} diff --git a/ecal/core/src/ecal_thread.cpp b/ecal/core/src/ecal_thread.cpp index d118a53dbf..7bb1ce5cc9 100644 --- a/ecal/core/src/ecal_thread.cpp +++ b/ecal/core/src/ecal_thread.cpp @@ -23,6 +23,7 @@ #include +#include "ecal_event_internal.h" #include "ecal_thread.h" #include diff --git a/ecal/core/src/ecal_util.cpp b/ecal/core/src/ecal_util.cpp index 4590ecc939..e4e3f117d2 100644 --- a/ecal/core/src/ecal_util.cpp +++ b/ecal/core/src/ecal_util.cpp @@ -22,6 +22,7 @@ #include #include "ecal_def.h" +#include "ecal_event_internal.h" #include "ecal_descgate.h" #include "ecal_process.h" #include "ecal_registration_receiver.h" diff --git a/ecal/core/src/ecalc.cpp b/ecal/core/src/ecalc.cpp index c8f68be5e8..8cd8492b68 100644 --- a/ecal/core/src/ecalc.cpp +++ b/ecal/core/src/ecalc.cpp @@ -469,7 +469,7 @@ extern "C" ECALC_API ECAL_HANDLE eCAL_Event_gOpenEvent(const char* event_name_) { eCAL::EventHandleT* event_handle = new eCAL::EventHandleT; - const bool success = eCAL::gOpenNamedEvent(event_handle, event_name_, true); + const bool success = eCAL::gOpenEvent(event_handle, event_name_); if (success) { return(event_handle); diff --git a/ecal/core/src/io/ecal_memfile_pool.cpp b/ecal/core/src/io/ecal_memfile_pool.cpp index eb274c859c..04ac67929a 100644 --- a/ecal/core/src/io/ecal_memfile_pool.cpp +++ b/ecal/core/src/io/ecal_memfile_pool.cpp @@ -23,6 +23,7 @@ **/ #include "ecal_def.h" +#include "ecal_event_internal.h" #include "ecal_memfile_pool.h" #include diff --git a/ecal/core/src/io/ecal_memfile_sync.cpp b/ecal/core/src/io/ecal_memfile_sync.cpp index d32649c4d1..b7533b4ea3 100644 --- a/ecal/core/src/io/ecal_memfile_sync.cpp +++ b/ecal/core/src/io/ecal_memfile_sync.cpp @@ -24,6 +24,7 @@ #include #include +#include "ecal_event_internal.h" #include "ecal_memfile_header.h" #include "ecal_memfile_naming.h" #include "ecal_memfile_sync.h" diff --git a/ecal/core/src/pubsub/ecal_subgate.cpp b/ecal/core/src/pubsub/ecal_subgate.cpp index 1959a7dbf3..757e4ac827 100644 --- a/ecal/core/src/pubsub/ecal_subgate.cpp +++ b/ecal/core/src/pubsub/ecal_subgate.cpp @@ -31,6 +31,7 @@ #endif #include "ecal_def.h" +#include "ecal_event_internal.h" #include "ecal_descgate.h" #include "pubsub/ecal_subgate.h" diff --git a/samples/cpp/misc/event_rec/src/event_rec.cpp b/samples/cpp/misc/event_rec/src/event_rec.cpp index ac6b894ec4..435c0f67a2 100644 --- a/samples/cpp/misc/event_rec/src/event_rec.cpp +++ b/samples/cpp/misc/event_rec/src/event_rec.cpp @@ -30,7 +30,7 @@ int main(int /*argc*/, char** /*argv*/) // create named event eCAL::EventHandleT event_handle; - eCAL::gOpenNamedEvent(&event_handle, event_name, false); + eCAL::gOpenEvent(&event_handle, event_name); // timer auto start_time(std::chrono::steady_clock::now()); diff --git a/samples/cpp/misc/event_snd/src/event_snd.cpp b/samples/cpp/misc/event_snd/src/event_snd.cpp index 6835fd2c0c..6825b9cdd8 100644 --- a/samples/cpp/misc/event_snd/src/event_snd.cpp +++ b/samples/cpp/misc/event_snd/src/event_snd.cpp @@ -30,7 +30,7 @@ int main(int /*argc*/, char** /*argv*/) // create named event eCAL::EventHandleT event_handle; - eCAL::gOpenNamedEvent(&event_handle, event_name, true); + eCAL::gOpenEvent(&event_handle, event_name); // timer auto start_time(std::chrono::steady_clock::now()); diff --git a/testing/ecal/event_test/src/event_test.cpp b/testing/ecal/event_test/src/event_test.cpp index b62cf8d836..6e02acc94f 100644 --- a/testing/ecal/event_test/src/event_test.cpp +++ b/testing/ecal/event_test/src/event_test.cpp @@ -28,17 +28,14 @@ TEST(Event, EventSetGet) // create named event eCAL::EventHandleT event_handle; - EXPECT_EQ(true, eCAL::gOpenNamedEvent(&event_handle, event_name, true)); + EXPECT_EQ(true, eCAL::gOpenEvent(&event_handle, event_name)); - // wait for event, expect false + // get none set event EXPECT_EQ(false, gWaitForEvent(event_handle, 10)); // set event EXPECT_EQ(true, gSetEvent(event_handle)); - // wait for event, expect true now + // get set event EXPECT_EQ(true, gWaitForEvent(event_handle, 100)); - - // close (and unlink/destroy) event - EXPECT_EQ(true, eCAL::gCloseEvent(event_handle)); }