Compare commits

...

6 Commits
main ... main

Author SHA1 Message Date
91ef7ad770
FIX: fixed empty bug
All checks were successful
continuous-integration/drone Build is passing
2024-01-16 12:41:45 +01:00
0198266526
FIX: removed unnecessary atomic 2024-01-16 12:27:12 +01:00
22ff983817
FIX: test if thread is joinable before join 2024-01-16 12:25:53 +01:00
caa13b0159
ADD: add CI/CD flow
Some checks reported errors
continuous-integration/drone Build encountered an error
2023-09-04 21:50:56 +02:00
7a1f5b4ae1
FIX: unsubscribe participant from all events on disconnect 2023-07-03 12:35:53 +02:00
38c69d8da1
FIX: subscribing when manager is unset
One feature added to EventManager has been disconnecting
a participant at runtime. Unfortunatly, then the
manager of this participant is set to nullptr using
the setManager method. But this method also subscribes to the
shutdown event afterwords. This commit checks if the manager
is nullptr and ignore subscribing in that case.
2023-07-03 12:23:04 +02:00
5 changed files with 78 additions and 10 deletions

48
.drone.yml Normal file
View File

@ -0,0 +1,48 @@
kind: pipeline
type: kubernetes
name: build-amd64
platform:
arch: amd64
node_selector:
kubernetes.io/arch: amd64
steps:
- name: submodules
image: alpine/git
commands:
- git submodule update --init --recursive
- name: build-amd64
image: debian:bookworm-slim
commands:
- apt-get update
- apt-get -qy install gcc-12 cmake make build-essential
- mkdir build
- cd build; cmake ..
- make -j 4
- make test
---
kind: pipeline
type: kubernetes
name: build-arm64
platform:
arch: arm64
node_selector:
kubernetes.io/arch: arm64
steps:
- name: submodules
image: alpine/git
commands:
- git submodule update --init --recursive
- name: build-arm64
image: debian:bookworm-slim
commands:
- apt-get update
- apt-get -qy install gcc-12 cmake make build-essential
- mkdir build
- cd build; cmake ..
- make -j 4
- make test

View File

@ -42,7 +42,7 @@
std::uint64_t responseId_; std::uint64_t responseId_;
/// identifies if this event is a response to another event /// identifies if this event is a response to another event
std::atomic<bool> isResponse_; bool isResponse_;
/// emitter of the event /// emitter of the event
std::shared_ptr<EventManager::Participant> emitter_; std::shared_ptr<EventManager::Participant> emitter_;

View File

@ -181,7 +181,13 @@
* *
* @param manager - the manager to set * @param manager - the manager to set
*/ */
void setManager(std::shared_ptr<EventManager::Manager> manager) { manager_=manager;_subscribe(EVENT_TYPE_SHUTDOWN);} void setManager(std::shared_ptr<EventManager::Manager> manager)
{ manager_=manager;
if (manager_!=nullptr)
{
_subscribe(EVENT_TYPE_SHUTDOWN);
}
}
/** /**
* @brief Method to set the unique id of the participant * @brief Method to set the unique id of the participant

View File

@ -88,7 +88,10 @@
throw std::runtime_error("can not stop main thread"); throw std::runtime_error("can not stop main thread");
} }
mainThread_->join(); if (mainThread_->joinable())
{
mainThread_->join();
}
} }
void EventManager::Manager::stopScheduling_() void EventManager::Manager::stopScheduling_()
@ -107,8 +110,11 @@
throw std::runtime_error("can not stop scheduling thread"); throw std::runtime_error("can not stop scheduling thread");
} }
schedulingThread_->join(); if (schedulingThread_->joinable())
} {
schedulingThread_->join();
}
}
void EventManager::Manager::start() void EventManager::Manager::start()
{ {
@ -288,6 +294,11 @@
bool EventManager::Manager::empty() const bool EventManager::Manager::empty() const
{ {
bool isEmpty=true; bool isEmpty=true;
while(!commandQueue_.empty())
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
for (auto it = eventMap_.begin(); it != eventMap_.end(); ++it) for (auto it = eventMap_.begin(); it != eventMap_.end(); ++it)
{ {
@ -383,6 +394,9 @@ void EventManager::Manager::processDisconnect_( std::shared_ptr<EventManager::Pa
// before the participant gets disconnected it has to be unscheduled // before the participant gets disconnected it has to be unscheduled
processDisableScheduling_( participant ); processDisableScheduling_( participant );
// unsubscribe plugin from all events
unsubscribe(participant);
std::lock_guard<std::mutex> guard(mutexParticipants_); std::lock_guard<std::mutex> guard(mutexParticipants_);
auto it = std::find( participants_.begin(), participants_.end(), participant ); auto it = std::find( participants_.begin(), participants_.end(), participant );
if( it != participants_.end() ) if( it != participants_.end() )

View File

@ -87,6 +87,11 @@ SCENARIO("Basic Usage of EventManager", "[Manager]")
manager = std::make_shared<EventManager::Manager>(); manager = std::make_shared<EventManager::Manager>();
}()); }());
REQUIRE_NOTHROW([&]()
{
manager->start();
}());
REQUIRE(manager->empty() == true); REQUIRE(manager->empty() == true);
std::shared_ptr<myParticipant> participant0; std::shared_ptr<myParticipant> participant0;
@ -107,11 +112,6 @@ SCENARIO("Basic Usage of EventManager", "[Manager]")
REQUIRE(manager->empty() == false); REQUIRE(manager->empty() == false);
REQUIRE_NOTHROW([&]()
{
manager->start();
}());
REQUIRE(manager->isRunning() == true); REQUIRE(manager->isRunning() == true);
WHEN("emitting shutdown event") WHEN("emitting shutdown event")