Skip to content
Snippets Groups Projects
Commit c7f3c313 authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

call: hangup subcalls on io thread

Change-Id: Id382d9c31b62c233af3561f0f33132d1a346e0d8
parent bb3ca5bb
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "errno.h" #include "errno.h"
#include <opendht/thread_pool.h>
#include <stdexcept> #include <stdexcept>
#include <system_error> #include <system_error>
#include <algorithm> #include <algorithm>
...@@ -50,33 +52,28 @@ namespace jami { ...@@ -50,33 +52,28 @@ namespace jami {
/// calls the unary predicate \a pred with this call pointer and hangup the call with given error /// calls the unary predicate \a pred with this call pointer and hangup the call with given error
/// code \a errcode when the predicate return true. /// code \a errcode when the predicate return true.
/// The predicate should have <code>bool(Call*) signature</code>. /// The predicate should have <code>bool(Call*) signature</code>.
template<typename T>
inline void inline void
hangupCallsIf(const Call::SubcallSet& callptr_list, hangupCallsIf(Call::SubcallSet&& calls,
int errcode, int errcode,
const std::function<bool(Call*)>& pred) T pred)
{ {
std::for_each(std::begin(callptr_list), for (auto& call : calls) {
std::end(callptr_list), if (not pred(call.get()))
[&](const std::shared_ptr<Call>& call_ptr) { continue;
if (pred(call_ptr.get())) { dht::ThreadPool::io().run([call = std::move(call), errcode] {
try { call->hangup(errcode);
call_ptr->hangup(errcode);
} catch (const std::exception& e) {
JAMI_ERR("[call:%s] hangup failed: %s",
call_ptr->getCallId().c_str(),
e.what());
}
}
}); });
} }
}
/// Hangup many calls with same error code. /// Hangup many calls with same error code.
/// ///
/// Works as hangupCallsIf() with a predicate that always return true. /// Works as hangupCallsIf() with a predicate that always return true.
inline void inline void
hangupCalls(const Call::SubcallSet& callptr_list, int errcode) hangupCalls(Call::SubcallSet&& callptr_list, int errcode)
{ {
hangupCallsIf(callptr_list, errcode, [](Call*) { return true; }); hangupCallsIf(std::move(callptr_list), errcode, [](Call*) { return true; });
} }
//============================================================================== //==============================================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment