main #2
@ -70,7 +70,7 @@
|
||||
std::mutex mutexSchedulingParticipants_;
|
||||
|
||||
/// list of all participants connected
|
||||
std::list<std::shared_ptr<EventManager::Participant>> particpants_;
|
||||
std::list<std::shared_ptr<EventManager::Participant>> participants_;
|
||||
|
||||
/// mutex to protect participants_
|
||||
std::mutex mutexParticipants_;
|
||||
@ -84,6 +84,12 @@
|
||||
/// mutex to protect connectionQueue_
|
||||
std::mutex mutexConnectionQueue_;
|
||||
|
||||
/// queue for disable scheduling request so the participants are not scheduled by the manager any longer
|
||||
std::queue<std::shared_ptr<EventManager::Participant>> disableScheduleQueue_;
|
||||
|
||||
/// mutex to protect disableScheduleQueue_
|
||||
std::mutex mutexDisableScheduleQueue_;
|
||||
|
||||
/*
|
||||
* all private methods
|
||||
*/
|
||||
@ -103,9 +109,24 @@
|
||||
*/
|
||||
void processEvent(const std::shared_ptr<EventManager::Event> event);
|
||||
|
||||
|
||||
/**
|
||||
* @brief adds the queued participants to the list of connected participants
|
||||
*
|
||||
* The connectionQueue_ contains the participants that should be connected to
|
||||
* the manager. All connected participants are stored in the list participants_.
|
||||
* This class function adds the queued participants to the list participants_
|
||||
* and removes them from the queue.
|
||||
*/
|
||||
void processConnections_();
|
||||
|
||||
/**
|
||||
* @brief disables the scheduling of the requested participants
|
||||
*
|
||||
* Removes the participants from the schedulingParticipants_ list that
|
||||
* should not be scheduled anymore.
|
||||
*/
|
||||
void processDisableScheduling_();
|
||||
|
||||
/**
|
||||
* @brief start the main thread
|
||||
*/
|
||||
|
@ -200,6 +200,7 @@
|
||||
mutexSchedulingParticipants_.unlock();
|
||||
|
||||
processConnections_();
|
||||
processDisableScheduling_();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
@ -331,18 +332,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EventManager::Manager::unschedule(std::shared_ptr<EventManager::Participant> participant )
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutexSchedulingParticipants_);
|
||||
|
||||
auto it = std::find(schedulingParticipants_.begin(), schedulingParticipants_.end(), participant);
|
||||
|
||||
if (it != schedulingParticipants_.end())
|
||||
{
|
||||
schedulingParticipants_.erase(it);
|
||||
}
|
||||
std::lock_guard<std::mutex> guard( mutexDisableScheduleQueue_ );
|
||||
disableScheduleQueue_.push( participant );
|
||||
}
|
||||
|
||||
|
||||
void EventManager::Manager::processConnections_()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutexParticipants_);
|
||||
@ -352,13 +349,33 @@
|
||||
{
|
||||
std::shared_ptr<EventManager::Participant> participant = connectionQueue_.front();
|
||||
connectionQueue_.pop();
|
||||
particpants_.push_back(participant);
|
||||
participants_.push_back(participant);
|
||||
|
||||
|
||||
participant->init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EventManager::Manager::processDisableScheduling_()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard( mutexDisableScheduleQueue_ );
|
||||
while( disableScheduleQueue_.empty() != true )
|
||||
{
|
||||
std::shared_ptr<EventManager::Participant> participant = disableScheduleQueue_.front();
|
||||
disableScheduleQueue_.pop();
|
||||
|
||||
std::unique_lock<std::mutex> lk(mutexSchedulingParticipants_);
|
||||
auto it = std::find(schedulingParticipants_.begin(), schedulingParticipants_.end(), participant);
|
||||
|
||||
if (it != schedulingParticipants_.end())
|
||||
{
|
||||
schedulingParticipants_.erase(it);
|
||||
}
|
||||
lk.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EventManager::Manager::connect(std::shared_ptr<EventManager::Participant> participant)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutexParticipants_);
|
||||
@ -375,20 +392,17 @@
|
||||
|
||||
void EventManager::Manager::disconnect(std::shared_ptr<EventManager::Participant> participant)
|
||||
{
|
||||
|
||||
disconnect(participant);
|
||||
|
||||
std::lock_guard<std::mutex> guard(mutexParticipants_);
|
||||
std::list<std::shared_ptr<EventManager::Participant>>::iterator it;
|
||||
|
||||
it = std::find(particpants_.begin(), particpants_.end(),participant);
|
||||
it = std::find(participants_.begin(), participants_.end(),participant);
|
||||
|
||||
if (it != particpants_.end())
|
||||
if (it != participants_.end())
|
||||
{
|
||||
particpants_.erase(it);
|
||||
participants_.erase(it);
|
||||
}
|
||||
|
||||
|
||||
|
||||
participant->setManager(nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user