Skip to content
Snippets Groups Projects
Commit d87f2d32 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

smarttools: use main scheduler instead of dedicated thread

Change-Id: I9fdfd1a0e1815d37dbacc871c8ef27586a7a605f
parent 5e345065
Branches
No related tags found
No related merge requests found
......@@ -18,12 +18,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "smartools.h"
#include "media/media_decoder.h"
#include "media/video/video_input.h"
#include "media/video/video_device.h"
#include "manager.h"
#include "dring/callmanager_interface.h"
#include "client/ring_signal.h"
#include "string_utils.h"
namespace jami {
......@@ -34,14 +31,8 @@ Smartools& Smartools::getInstance()
return instance_;
}
// Launch process() in new thread
Smartools::Smartools()
: loop_([] { return true; }, [this] { process(); }, [] {})
{}
Smartools::~Smartools()
{
loop_.join();
Smartools::~Smartools() {
stop();
}
void
......@@ -52,21 +43,16 @@ Smartools::sendInfo()
information_.clear();
}
void
Smartools::process()
{
// Send the signal SmartInfo
Smartools::sendInfo();
std::this_thread::sleep_for(refreshTimeMs_);
}
void
Smartools::start(std::chrono::milliseconds refreshTimeMs)
{
JAMI_DBG("Start SmartInfo");
refreshTimeMs_ = refreshTimeMs;
loop_.stop();
loop_.start();
if (auto t = std::move(task_))
t->cancel();
task_ = Manager::instance().scheduler().scheduleAtFixedRate([this]{
sendInfo();
return true;
}, refreshTimeMs);
}
void
......@@ -74,7 +60,8 @@ Smartools::stop()
{
std::lock_guard<std::mutex> lk(mutexInfo_);
JAMI_DBG("Stop SmartInfo");
loop_.stop();
if (auto t = std::move(task_))
t->cancel();
information_.clear();
}
......@@ -131,12 +118,9 @@ Smartools::setRemoteVideoCodec(const std::string& remoteVideoCodec, const std::s
{
std::lock_guard<std::mutex> lk(mutexInfo_);
information_["remote video codec"]= remoteVideoCodec;
auto call = Manager::instance().getCallFromCallID(callID);
if (!call) {
return;
}
if (auto call = Manager::instance().getCallFromCallID(callID)) {
auto confID = call->getConfId();
if (confID != ""){
if (not confID.empty()) {
information_["type"]= "conference";
information_["callID"]= confID;
} else {
......@@ -144,5 +128,6 @@ Smartools::setRemoteVideoCodec(const std::string& remoteVideoCodec, const std::s
information_["callID"]= callID;
}
}
}
} // end namespace jami
......@@ -19,11 +19,15 @@
*/
#pragma once
#include "threadloop.h"
#include "manager.h"
#include <string>
#include <chrono>
#include <mutex>
#include <map>
#include <memory>
namespace jami {
class RepeatedTask;
class Smartools
{
// Use for the unit tests
......@@ -44,12 +48,10 @@ class Smartools
void sendInfo();
private:
Smartools();
Smartools() {};
~Smartools();
void process();
std::map<std::string, std::string> information_;
std::mutex mutexInfo_; // Protect information_ from multithreading
std::chrono::milliseconds refreshTimeMs_ {500};
ThreadLoop loop_; // Has to be last member
std::map<std::string, std::string> information_;
std::shared_ptr<RepeatedTask> task_;
};
} //ring namespace
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment