Skip to content
Snippets Groups Projects
Commit 6e6b2d39 authored by Sergey Linev's avatar Sergey Linev Committed by Philippe Canal
Browse files

webgui: adjust TWebWindowsManager configuration interface

Instead of using static variables just configure gEnv->SetValue()
parameters directly. Adjust tutorial
parent a4032903
No related branches found
No related tags found
No related merge requests found
......@@ -44,10 +44,17 @@ private:
std::mutex fMutex; ///<! main mutex to protect
int fMutexBooked{0}; ///<! flag indicating that mutex is booked for some long operation
std::thread::id fBookedThrd; ///<! thread where mutex is booked, can be reused
unsigned fIdCnt{0}; ///<! counter for identifiers
unsigned fIdCnt{0}; ///<! counter for identifiers
bool fUseHttpThrd{false}; ///<! use special thread for THttpServer
bool fUseSenderThreads{false}; ///<! use extra threads for sending data from RWebWindow to clients
// std::list<std::shared_ptr<TWebWindow>> fDisplays; ///<! list of existing displays (not used at the moment)
static bool IsUseHttpThread();
/// Returns true if extra threads to send data via websockets will be used (default off)
bool IsUseHttpThread() const { return fUseHttpThrd; }
/// Returns true if extra threads to send data via websockets will be used (default off)
bool IsUseSenderThreads() const { return fUseSenderThreads; }
bool CreateHttpServer(bool with_http = false);
void Unregister(TWebWindow &win);
......@@ -70,11 +77,6 @@ public:
/// Returns THttpServer instance
THttpServer *GetServer() const { return fServer.get(); }
static void SetUseHttpThread(bool on = true);
static void SetUseSenderThreads(bool on = true);
static bool IsUseSenderThreads();
static std::shared_ptr<TWebWindowsManager> &Instance();
static bool IsMainThrd();
......
......@@ -109,7 +109,7 @@ void ROOT::Experimental::TWebWindow::SetPanelName(const std::string &name)
void ROOT::Experimental::TWebWindow::CreateWSHandler()
{
if (!fWSHandler) {
fSendMT = TWebWindowsManager::IsUseSenderThreads();
fSendMT = fMgr->IsUseSenderThreads();
fWSHandler = std::make_shared<TWebWindowWSHandler>(*this, Form("win%u", GetId()));
}
}
......@@ -723,7 +723,7 @@ void ROOT::Experimental::TWebWindow::SetDataCallBack(WebWindowDataCallback_t fun
fDataThrdId = std::this_thread::get_id();
if (!TWebWindowsManager::IsMainThrd()) {
fProcessMT = true;
} else if (TWebWindowsManager::IsUseHttpThread()) {
} else if (fMgr->IsUseHttpThread()) {
// special thread is used by the manager, but main thread used for the canvas - not supported
R__ERROR_HERE("webgui") << "create web window from main thread when THttpServer created with special thread - not supported";
}
......
......@@ -45,9 +45,6 @@
namespace ROOT {
namespace Experimental {
static int sUseHttpThread = -1; // undefined
static int sUseSenderThreads = -1; // undefined
class TWebWindowManagerGuard {
TWebWindowsManager &fMgr;
......@@ -150,54 +147,6 @@ ROOT::Experimental::TWebWindowsManager::~TWebWindowsManager()
gApplication->Disconnect("Terminate(Int_t)", "THttpServer", fServer.get(), "SetTerminate()");
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Configure usage of extra thread for the processing of THttpServer requests (default off)
/// Required when application does not run main ROOT event loop or
/// when many different instances of THttpServer should be used in the system
/// When enabled, TWebWindow MUST run in there own threads, using TWebWindow::Run() functionality
/// Equivalent to configuring option in rootrc file:
/// WebGui.HttpThrd: yes | no
void ROOT::Experimental::TWebWindowsManager::SetUseHttpThread(bool on)
{
sUseHttpThread = on ? 1 : 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Returns true if extra thread will be used for THttpServer processing (default false)
/// If not configured before, WebGui.HttpThrd value from rootrc file is used
bool ROOT::Experimental::TWebWindowsManager::IsUseHttpThread()
{
if (sUseHttpThread > 0) return true;
if (sUseHttpThread == 0) return false;
const char *serv_thrd = gEnv->GetValue("WebGui.HttpThrd", "no");
return (serv_thrd && strstr(serv_thrd, "yes"));
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Configure usage of extra threads to send data via websockets to connection (default off)
/// Can be very useful when many (slow) clients connected to the same window and consume much resources
/// Equivalent to configuring option in rootrc file:
/// WebGui.SenderThrds: yes | no
void ROOT::Experimental::TWebWindowsManager::SetUseSenderThreads(bool on)
{
sUseSenderThreads = on ? 1 : 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Returns true if extra threads to send data via websockets will be used (default off)
bool ROOT::Experimental::TWebWindowsManager::IsUseSenderThreads()
{
return (sUseSenderThreads > 0);
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Creates http server, if required - with real http engine (civetweb)
/// One could configure concrete HTTP port, which should be used for the server,
......@@ -246,6 +195,12 @@ bool ROOT::Experimental::TWebWindowsManager::CreateHttpServer(bool with_http)
fServer = std::make_unique<THttpServer>("basic_sniffer");
const char *serv_thrd = gEnv->GetValue("WebGui.HttpThrd", "");
if (serv_thrd && strstr(serv_thrd, "yes"))
fUseHttpThrd = true;
else if (serv_thrd && strstr(serv_thrd, "no"))
fUseHttpThrd = false;
if (IsUseHttpThread())
fServer->CreateServerThread();
......@@ -269,10 +224,11 @@ bool ROOT::Experimental::TWebWindowsManager::CreateHttpServer(bool with_http)
const char *http_ssl = gEnv->GetValue("WebGui.UseHttps", "no");
const char *ssl_cert = gEnv->GetValue("WebGui.ServerCert", "rootserver.pem");
if (sUseSenderThreads < 0) {
const char *send_thrds = gEnv->GetValue("WebGui.SenderThrds", "");
if (send_thrds && strstr(send_thrds,"yes")) sUseSenderThreads = 1;
}
const char *send_thrds = gEnv->GetValue("WebGui.SenderThrds", "");
if (send_thrds && strstr(send_thrds, "yes"))
fUseSenderThreads = true;
else if (send_thrds && strstr(send_thrds, "no"))
fUseSenderThreads = false;
bool assign_loopback = http_loopback && strstr(http_loopback, "yes");
bool use_secure = http_ssl && strstr(http_ssl, "yes");
......
......@@ -29,6 +29,7 @@ R__LOAD_LIBRARY(libROOTGpadv7);
#include "ROOT/TWebWindowsManager.hxx"
#include "TRandom3.h"
#include "TEnv.h"
#include <thread>
// #include <chrono>
......@@ -83,8 +84,8 @@ void draw_canvas(const std::string &title, RColor col)
void draw_mt()
{
TWebWindowsManager::SetUseHttpThread(true);
TWebWindowsManager::SetUseSenderThreads(true);
gEnv->SetValue("WebGui.HttpThrd","yes");
gEnv->SetValue("WebGui.SenderThrds","yes");
std::thread thrd1(draw_canvas, "First canvas", RColor::kRed);
std::thread thrd2(draw_canvas, "Second canvas", RColor::kBlue);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment