53 static std::shared_ptr<RWebWindowsManager> sInstance = std::make_shared<RWebWindowsManager>();
175 std::lock_guard<std::recursive_mutex> grd(
fMutex);
179 fServer = std::make_unique<THttpServer>(
"basic_sniffer");
181 const char *serv_thrd =
gEnv->
GetValue(
"WebGui.HttpThrd",
"");
182 if (serv_thrd && strstr(serv_thrd,
"yes"))
184 else if (serv_thrd && strstr(serv_thrd,
"no"))
187 const char *send_thrds =
gEnv->
GetValue(
"WebGui.SenderThrds",
"");
188 if (send_thrds && *send_thrds) {
189 if (strstr(send_thrds,
"yes"))
191 else if (strstr(send_thrds,
"no"))
204 fServer->SetWSOnly(wsonly != 0);
216 R__LOG_ERROR(
WebGUILog()) <<
"Path to ROOT ui5 sources " << ui5dir <<
" not found, set ROOTUI5SYS correctly";
220 fServer->AddLocation(
"rootui5sys/", ui5dir.
Data());
223 if (!with_http ||
fServer->IsAnyEngine())
227 int http_min =
gEnv->
GetValue(
"WebGui.HttpPortMin", 8800);
228 int http_max =
gEnv->
GetValue(
"WebGui.HttpPortMax", 9800);
229 int http_wstmout =
gEnv->
GetValue(
"WebGui.HttpWSTmout", 10000);
230 int http_maxage =
gEnv->
GetValue(
"WebGui.HttpMaxAge", -1);
231 int fcgi_port =
gEnv->
GetValue(
"WebGui.FastCgiPort", 0);
232 int fcgi_thrds =
gEnv->
GetValue(
"WebGui.FastCgiThreads", 10);
233 const char *fcgi_serv =
gEnv->
GetValue(
"WebGui.FastCgiServer",
"");
235 const char *http_loopback =
gEnv->
GetValue(
"WebGui.HttpLoopback",
"no");
236 const char *http_bind =
gEnv->
GetValue(
"WebGui.HttpBind",
"");
237 const char *http_ssl =
gEnv->
GetValue(
"WebGui.UseHttps",
"no");
238 const char *ssl_cert =
gEnv->
GetValue(
"WebGui.ServerCert",
"rootserver.pem");
240 bool assign_loopback = http_loopback && strstr(http_loopback,
"yes");
241 bool use_secure = http_ssl && strstr(http_ssl,
"yes");
244 if ((http_port < 0) && (fcgi_port <= 0)) {
256 if (http_max - http_min < ntry)
257 ntry = http_max - http_min;
263 while (ntry-- >= 0) {
264 if ((http_port == 0) && (fcgi_port <= 0)) {
265 if ((http_min <= 0) || (http_max <= http_min)) {
266 R__LOG_ERROR(
WebGUILog()) <<
"Wrong HTTP range configuration, check WebGui.HttpPortMin/Max variables";
270 http_port = (
int)(http_min + (http_max - http_min) *
gRandom->
Rndm(1));
276 engine.
Form(
"fastcgi:%d?thrds=%d", fcgi_port, fcgi_thrds);
277 if (!
fServer->CreateEngine(engine))
return false;
278 if (fcgi_serv && (strlen(fcgi_serv) > 0))
fAddr = fcgi_serv;
279 if (http_port < 0)
return true;
281 }
else if (http_port > 0) {
282 url = use_secure ?
"https://" :
"http://";
283 engine.
Form(
"%s:%d?websocket_timeout=%d", (use_secure ?
"https" :
"http"), http_port, http_wstmout);
284 if (assign_loopback) {
285 engine.
Append(
"&loopback");
287 }
else if (http_bind && (strlen(http_bind) > 0)) {
295 if (http_maxage >= 0)
299 engine.
Append(
"&ssl_cert=");
303 if (
fServer->CreateEngine(engine)) {
306 fAddr.append(std::to_string(http_port));
324 std::lock_guard<std::recursive_mutex> grd(
fMutex);
331 std::shared_ptr<RWebWindow> win = std::make_shared<RWebWindow>();
338 double dflt_tmout =
gEnv->
GetValue(
"WebGui.OperationTmout", 50.);
340 auto wshandler = win->CreateWSHandler(
Instance(), ++
fIdCnt, dflt_tmout);
343 std::string fname, prefix;
345 prefix = std::string(
"f") + std::to_string(
fIdCnt) +
"_";
346 fname = std::string(
"protcol") + std::to_string(
fIdCnt) +
".json";
348 fname =
"protocol.json";
350 win->RecordData(fname, prefix);
353 const char *token =
gEnv->
GetValue(
"WebGui.ConnToken",
"");
355 win->SetConnToken(token);
357 fServer->RegisterWS(wshandler);
382 std::string addr =
"/";
439 if (!batch_mode &&
gROOT->IsWebDisplayBatch())
450 std::lock_guard<std::recursive_mutex> grd(
fMutex);
462 }
while ((--ntry > 0) && win.
HasKey(key));
480 if (!normal_http && (
gEnv->
GetValue(
"WebGui.ForceHttp",0) == 1))
483 std::string url =
GetUrl(win, normal_http);
488 if (normal_http &&
fAddr.empty()) {
529 auto start = std::chrono::high_resolution_clock::now();
533 while ((res = check(spent)) == 0) {
540 std::this_thread::sleep_for(std::chrono::milliseconds(1));
542 std::chrono::duration<double, std::milli> elapsed = std::chrono::high_resolution_clock::now() - start;
544 spent = elapsed.count() * 1
e-3;
546 if (timed && (spent > timelimit))
#define R__LOG_WARNING(...)
#define R__LOG_ERROR(...)
static std::thread::id gWebWinMainThrd
This thread id used to identify main application thread, where ROOT event processing runs To inject c...
R__EXTERN TApplication * gApplication
R__EXTERN TRandom * gRandom
R__EXTERN TSystem * gSystem
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::string GetBrowserName() const
Returns configured browser name.
bool IsSupportHeadless() const
returns true if browser supports headless (batch) mode, used for image production
RWebDisplayArgs & SetUrl(const std::string &url)
set window url
int GetHeight() const
returns preferable web window height
void SetHeadless(bool on=true)
set headless mode
void SetHttpServer(THttpServer *serv)
set http server instance, used for window display
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
void AppendUrlOpt(const std::string &opt)
append extra url options, add "&" as separator if required
bool IsLocalDisplay() const
returns true if local display like CEF or Qt5 QWebEngine should be used
@ kEmbedded
window will be embedded into other, no extra browser need to be started
RWebDisplayArgs & SetHeight(int h=0)
set preferable web window height
int GetWidth() const
returns preferable web window width
RWebDisplayArgs & SetWidth(int w=0)
set preferable web window width
static std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args)
Create web display.
Represents web window, which can be shown in web browser or any other supported environment.
unsigned AddDisplayHandle(bool batch_mode, const std::string &key, std::unique_ptr< RWebDisplayHandle > &handle)
Add display handle and associated key Key is random number generated when starting new window When cl...
void Sync()
Special method to process all internal activity when window runs in separate thread.
std::string GetConnToken() const
Returns configured connection token.
unsigned GetHeight() const
returns configured window height (0 - default)
bool HasKey(const std::string &key) const
Returns true if provided key value already exists (in processes map or in existing connections)
unsigned GetWidth() const
returns configured window width (0 - default) actual window width can be different
std::shared_ptr< RWebWindowWSHandler > fWSHandler
! specialize websocket handler for all incoming connections
std::unique_ptr< THttpServer > fServer
! central communication with the all used displays
std::string GetUrl(const RWebWindow &win, bool remote=false)
Provide URL address to access specified window from inside or from remote.
bool CreateServer(bool with_http=false)
Creates http server, if required - with real http engine (civetweb) One could configure concrete HTTP...
RWebWindowsManager()
window manager constructor Required here for correct usage of unique_ptr<THttpServer>
int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed=false, double tm=-1)
Waits until provided check function or lambdas returns non-zero value Regularly calls WebWindow::Sync...
std::recursive_mutex fMutex
! main mutex, used for window creations
unsigned fIdCnt
! counter for identifiers
std::string fAddr
! HTTP address of the server
bool fUseSenderThreads
! use extra threads for sending data from RWebWindow to clients
void Terminate()
Terminate http server and ROOT application.
~RWebWindowsManager()
window manager destructor Required here for correct usage of unique_ptr<THttpServer>
THttpServer * GetServer() const
Returns THttpServer instance.
static void AssignMainThrd()
Re-assigns main thread id Normally main thread id recognized at the moment when library is loaded It ...
bool IsUseHttpThread() const
Returns true if http server use special thread for requests processing (default off)
static bool IsMainThrd()
Returns true when called from main process Main process recognized at the moment when library is load...
static std::shared_ptr< RWebWindowsManager > & Instance()
Returns default window manager Used to display all standard ROOT elements like TCanvas or TFitPanel.
bool fUseHttpThrd
! use special thread for THttpServer
unsigned ShowWindow(RWebWindow &win, bool batch_mode, const RWebDisplayArgs &args)
Show window in specified location, see Show() method for more details.
void Unregister(RWebWindow &win)
Release all references to specified window Called from RWebWindow destructor.
float fLaunchTmout
! timeout in seconds to start browser process, default 30s
std::shared_ptr< RWebWindow > CreateWindow()
Creates new window To show window, RWebWindow::Show() have to be called.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
virtual Double_t Rndm()
Machine independent random number generator.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
const char * Data() const
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual const char * Getenv(const char *env)
Get environment variable.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.
std::function< int(double)> WebWindowWaitFunc_t
function signature for waiting call-backs Such callback used when calling thread need to waits for so...