Skip to content
Snippets Groups Projects
Commit 7396949b authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

manager: add self-managed event task system

This patch adds a new mananger API to inject callbacks called
periodically in the event loop.
This callbacks are not removable as current EventHandler system.
The callback return is checked: if false the callback is definitively
removed.

Refs #67321

Change-Id: I244a947faad2ab3c986dd1d406cb5c8a081a9d17
parent f1a602bf
No related branches found
No related tags found
No related merge requests found
......@@ -1380,8 +1380,17 @@ ManagerImpl::unregisterEventHandler(uintptr_t handlerId)
}
}
// Not thread-safe, SHOULD be called in same thread that run poolEvents()
void
ManagerImpl::addTask(const std::function<bool()>&& task)
{
pendingTaskList_.emplace_back(task);
}
// Must be invoked periodically by a timer from the main event loop
void ManagerImpl::pollEvents()
{
//-- Handlers
{
auto iter = eventHandlerMap_.begin();
while (iter != eventHandlerMap_.end()) {
......@@ -1398,6 +1407,24 @@ void ManagerImpl::pollEvents()
}
}
//-- Tasks
{
auto tmpList = std::move(pendingTaskList_);
pendingTaskList_.clear();
auto iter = std::begin(tmpList);
while (iter != tmpList.cend()) {
if (finished_)
return;
auto next = std::next(iter);
if (not (*iter)())
tmpList.erase(iter);
iter = next;
}
pendingTaskList_.splice(std::end(pendingTaskList_), tmpList);
}
}
//THREAD=Main
void
ManagerImpl::saveConfig()
......
......@@ -48,6 +48,7 @@
#include <mutex>
#include <random>
#include <atomic>
#include <functional>
#include "conference.h"
......@@ -941,12 +942,16 @@ class ManagerImpl {
IceTransportFactory& getIceTransportFactory() { return *ice_tf_; }
void addTask(const std::function<bool()>&& task);
private:
NON_COPYABLE(ManagerImpl);
std::map<uintptr_t, EventHandler> eventHandlerMap_;
decltype(eventHandlerMap_)::iterator nextEventHandler_;
std::list<std::function<bool()>> pendingTaskList_;
/**
* Test if call is a valid call, i.e. have been created and stored in
* call-account map
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment