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