Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::RWebWindowsManager Class Reference

Central instance to create and show web-based windows like Canvas or FitPanel.

Manager responsible to creating THttpServer instance, which is used for RWebWindow's communication with clients.

Method RWebWindows::Show() used to show window in specified location.

Definition at line 40 of file RWebWindowsManager.hxx.

Public Member Functions

 RWebWindowsManager ()
 window manager constructor Required here for correct usage of unique_ptr<THttpServer>
 
 ~RWebWindowsManager ()
 window manager destructor Required here for correct usage of unique_ptr<THttpServer>
 
std::shared_ptr< RWebWindowCreateWindow ()
 Creates new window To show window, RWebWindow::Show() have to be called.
 
THttpServerGetServer () const
 Returns THttpServer instance.
 
std::string GetServerAddr () const
 Returns http address of the server, empty string when not available.
 
void SetDeleteCallback (WebWindowDeleteCallback_t func)
 Assign show callback which can catch window showing, used by RBrowser.
 
void SetShowCallback (WebWindowShowCallback_t func)
 Assign show callback which can catch window showing, used by RBrowser.
 
void Terminate ()
 Terminate http server and ROOT application.
 

Static Public Member Functions

static void AddServerLocation (const std::string &server_prefix, const std::string &files_path)
 Configure server location which can be used for loading of custom scripts or files When THttpServer instance of RWebWindowsManager will be created, THttpServer::AddLocation() method with correspondent arguments will be invoked.
 
static void AssignMainThrd ()
 Re-assigns main thread id Normally main thread id recognized at the moment when library is loaded It supposed to be a thread where gApplication->Run() will be called If application runs in separate thread, one have to call this method to let RWebWindowsManager correctly recognize such situation.
 
static void ClearServerLocations ()
 Clear all server locations Does not change configuration of already running HTTP server.
 
static std::map< std::string, std::string > GetServerLocations ()
 Returns server locations as <std::string, std::string> Key is location name (with slash at the end) and value is file path.
 
static std::shared_ptr< RWebWindowsManager > & Instance ()
 Returns default window manager Used to display all standard ROOT elements like TCanvas or TFitPanel.
 
static bool IsLoopbackMode ()
 Returns true if loopback mode used by THttpServer for web widgets.
 
static bool IsMainThrd ()
 Returns true when called from main process Main process recognized at the moment when library is loaded It supposed to be a thread where gApplication->Run() will be called If application runs in separate thread, one have to use AssignMainThrd() method to let RWebWindowsManager correctly recognize such situation.
 
static void SetLoopbackMode (bool on=true)
 Set loopback mode for THttpServer used for web widgets By default is on.
 
static void SetSingleConnMode (bool on=true)
 Enable or disable single connection mode (default on) If enabled, one connection only with any web widget is possible Any attempt to establish more connections will fail if this mode is disabled some widgets like geom viewer or web canvas will be able to to serve several clients - only when they are connected with required authentication keys.
 
static void SetUseConnectionKey (bool on=true)
 Enable or disable usage of connection key (default on) If enabled, each connection (and reconnection) to widget requires unique key Connection key used together with session key to calculate hash sum of each packet send to or from server This protects ROOT http server from anauthorized usage.
 
static void SetUseSessionKey (bool on=true)
 Enable or disable usage of session key (default on) If enabled, secrete session key used to calculate hash sum of each packet send to or from server This protects ROOT http server from anauthorized usage.
 

Private Member Functions

bool CreateServer (bool with_http=false)
 Creates http server, if required - with real http engine (civetweb) One could configure concrete HTTP port, which should be used for the server, provide following entry in rootrc file:
 
float GetLaunchTmout () const
 Returns timeout for launching new browser process.
 
std::string GetUrl (RWebWindow &win, bool remote=false, std::string *produced_key=nullptr)
 Provide URL address to access specified window from inside or from remote.
 
bool InformListener (const std::string &msg)
 If ROOT_LISTENER_SOCKET variable is configured, message will be sent to that unix socket.
 
bool IsUseHttpThread () const
 Returns true if http server use special thread for requests processing (default off)
 
bool IsUseSenderThreads () const
 Returns true if extra threads to send data via websockets will be used (default off)
 
unsigned ShowWindow (RWebWindow &win, 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.
 
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() method to let run event loop If call from the main thread, runs system events processing Check function has following signature: int func(double spent_tm) Parameter spent_tm is time in seconds, which already spent inside function Waiting will be continued, if function returns zero.
 

Static Private Member Functions

static std::string GenerateKey (int keylen=32)
 Static method to generate cryptographic key Parameter keylen defines length of cryptographic key in bytes Output string will be hex formatted and includes "-" separator after every 4 bytes Example for 16 bytes: "fca45856-41bee066-ff74cc96-9154d405".
 

Private Attributes

std::string fAddr
 ! HTTP address of the server
 
std::unique_ptr< TExecfAssgnExec
 ! special exec to assign thread id via ProcessEvents
 
WebWindowDeleteCallback_t fDeleteCallback
 ! function called when RWebWindow is destroyed
 
bool fExternalProcessEvents {false}
 ! indicate that there are external process events engine
 
unsigned fIdCnt {0}
 ! counter for identifiers
 
float fLaunchTmout {30.}
 ! timeout in seconds to start browser process, default 30s
 
std::recursive_mutex fMutex
 ! main mutex, used for window creations
 
std::unique_ptr< THttpServerfServer
 ! central communication with the all used displays
 
std::string fSessionKey
 ! secret session key used on client to code connections keys
 
WebWindowShowCallback_t fShowCallback
 ! function called for each RWebWindow::Show call
 
bool fUseHttpThrd {false}
 ! use special thread for THttpServer
 
bool fUseSenderThreads {false}
 ! use extra threads for sending data from RWebWindow to clients
 
bool fUseSessionKey {false}
 ! is session key has to be used for data signing
 

Friends

class RWebWindow
 

#include <ROOT/RWebWindowsManager.hxx>

Constructor & Destructor Documentation

◆ RWebWindowsManager()

RWebWindowsManager::RWebWindowsManager ( )

window manager constructor Required here for correct usage of unique_ptr<THttpServer>

Definition at line 285 of file RWebWindowsManager.cxx.

◆ ~RWebWindowsManager()

RWebWindowsManager::~RWebWindowsManager ( )

window manager destructor Required here for correct usage of unique_ptr<THttpServer>

Definition at line 299 of file RWebWindowsManager.cxx.

Member Function Documentation

◆ AddServerLocation()

void RWebWindowsManager::AddServerLocation ( const std::string &  server_prefix,
const std::string &  files_path 
)
static

Configure server location which can be used for loading of custom scripts or files When THttpServer instance of RWebWindowsManager will be created, THttpServer::AddLocation() method with correspondent arguments will be invoked.

Definition at line 190 of file RWebWindowsManager.cxx.

◆ AssignMainThrd()

void RWebWindowsManager::AssignMainThrd ( )
static

Re-assigns main thread id Normally main thread id recognized at the moment when library is loaded It supposed to be a thread where gApplication->Run() will be called If application runs in separate thread, one have to call this method to let RWebWindowsManager correctly recognize such situation.

Definition at line 117 of file RWebWindowsManager.cxx.

◆ ClearServerLocations()

void RWebWindowsManager::ClearServerLocations ( )
static

Clear all server locations Does not change configuration of already running HTTP server.

Definition at line 251 of file RWebWindowsManager.cxx.

◆ CreateServer()

bool RWebWindowsManager::CreateServer ( bool  with_http = false)
private

Creates http server, if required - with real http engine (civetweb) One could configure concrete HTTP port, which should be used for the server, provide following entry in rootrc file:

 WebGui.HttpPort: 8088

or specify range of http ports, which can be used:

 WebGui.HttpPortMin: 8800
 WebGui.HttpPortMax: 9800

By default range [8800..9800] is used

One also can bind HTTP server socket to loopback address, In that case only connection from localhost will be available:

 WebGui.HttpLoopback: yes

Or one could specify hostname which should be used for binding of server socket

 WebGui.HttpBind: hostname | ipaddress

To use secured protocol, following parameter should be specified

 WebGui.UseHttps: yes
 WebGui.ServerCert: sertificate_filename.pem

Alternatively, one can specify unix socket to handle requests:

 WebGui.UnixSocket: /path/to/unix/socket
 WebGui.UnixSocketMode: 0700

Typically one used unix sockets together with server mode like root --web=server:/tmp/root.socket and then redirect it via ssh tunnel (e.g. using rootssh) to client node

All incoming requests processed in THttpServer in timer handler with 10 ms timeout. One may decrease value to improve latency or increase value to minimize CPU load

 WebGui.HttpTimer: 10

To processing incoming http requests and websockets, THttpServer allocate 10 threads One have to increase this number if more simultaneous connections are expected:

 WebGui.HttpThrds: 10

One also can configure usage of special thread of processing of http server requests

 WebGui.HttpThrd: no

Extra threads can be used to send data to different clients via websocket (default no)

 WebGui.SenderThrds: no

If required, one could change websocket timeouts (default is 10000 ms)

 WebGui.HttpWSTmout: 10000

By default, THttpServer created in restricted mode which only allows websocket handlers and processes only very few other related http requests. For security reasons such mode should be always enabled. Only if it is really necessary to process all other kinds of HTTP requests, one could specify no for following parameter (default yes):

 WebGui.WSOnly: yes

In some applications one may need to force longpoll websocket emulations from the beginning, for instance when clients connected via proxys. Although JSROOT should automatically fallback to longpoll engine, one can configure this directly (default no)

 WebGui.WSLongpoll: no

Following parameter controls browser max-age caching parameter for files (default 3600) When 0 is specified, browser cache will be disabled

 WebGui.HttpMaxAge: 3600

Also one can provide extra URL options for, see TCivetweb::Create for list of supported options

 WebGui.HttpExtraArgs: winsymlinks=no

One also can configure usage of FastCGI server for web windows:

 WebGui.FastCgiPort: 4000
 WebGui.FastCgiThreads: 10

To be able start web browser for such windows, one can provide real URL of the web server which will connect with that FastCGI instance:

 WebGui.FastCgiServer: https://your_apache_server.com/root_cgi_path

For some custom applications one requires to load JavaScript modules or other files. For such applications one may require to load files from other locations which can be configured with AddServerLocation() method or directly via:

 WebGui.ServerLocations: location1:/file/path/to/location1;location2:/file/path/to/location2 

Definition at line 442 of file RWebWindowsManager.cxx.

◆ CreateWindow()

std::shared_ptr< RWebWindow > RWebWindowsManager::CreateWindow ( )

Creates new window To show window, RWebWindow::Show() have to be called.

Definition at line 631 of file RWebWindowsManager.cxx.

◆ GenerateKey()

std::string RWebWindowsManager::GenerateKey ( int  keylen = 32)
staticprivate

Static method to generate cryptographic key Parameter keylen defines length of cryptographic key in bytes Output string will be hex formatted and includes "-" separator after every 4 bytes Example for 16 bytes: "fca45856-41bee066-ff74cc96-9154d405".

Definition at line 262 of file RWebWindowsManager.cxx.

◆ GetLaunchTmout()

float ROOT::RWebWindowsManager::GetLaunchTmout ( ) const
inlineprivate

Returns timeout for launching new browser process.

Definition at line 66 of file RWebWindowsManager.hxx.

◆ GetServer()

THttpServer * ROOT::RWebWindowsManager::GetServer ( ) const
inline

Returns THttpServer instance.

Definition at line 89 of file RWebWindowsManager.hxx.

◆ GetServerAddr()

std::string ROOT::RWebWindowsManager::GetServerAddr ( ) const
inline

Returns http address of the server, empty string when not available.

Definition at line 92 of file RWebWindowsManager.hxx.

◆ GetServerLocations()

std::map< std::string, std::string > RWebWindowsManager::GetServerLocations ( )
static

Returns server locations as <std::string, std::string> Key is location name (with slash at the end) and value is file path.

Definition at line 221 of file RWebWindowsManager.cxx.

◆ GetUrl()

std::string RWebWindowsManager::GetUrl ( RWebWindow win,
bool  remote = false,
std::string *  produced_key = nullptr 
)
private

Provide URL address to access specified window from inside or from remote.

Definition at line 698 of file RWebWindowsManager.cxx.

◆ InformListener()

bool RWebWindowsManager::InformListener ( const std::string &  msg)
private

If ROOT_LISTENER_SOCKET variable is configured, message will be sent to that unix socket.

Definition at line 311 of file RWebWindowsManager.cxx.

◆ Instance()

std::shared_ptr< RWebWindowsManager > & RWebWindowsManager::Instance ( )
static

Returns default window manager Used to display all standard ROOT elements like TCanvas or TFitPanel.

Definition at line 79 of file RWebWindowsManager.cxx.

◆ IsLoopbackMode()

bool RWebWindowsManager::IsLoopbackMode ( )
static

Returns true if loopback mode used by THttpServer for web widgets.

Definition at line 147 of file RWebWindowsManager.cxx.

◆ IsMainThrd()

bool RWebWindowsManager::IsMainThrd ( )
static

Returns true when called from main process Main process recognized at the moment when library is loaded It supposed to be a thread where gApplication->Run() will be called If application runs in separate thread, one have to use AssignMainThrd() method to let RWebWindowsManager correctly recognize such situation.

Definition at line 105 of file RWebWindowsManager.cxx.

◆ IsUseHttpThread()

bool ROOT::RWebWindowsManager::IsUseHttpThread ( ) const
inlineprivate

Returns true if http server use special thread for requests processing (default off)

Definition at line 60 of file RWebWindowsManager.hxx.

◆ IsUseSenderThreads()

bool ROOT::RWebWindowsManager::IsUseSenderThreads ( ) const
inlineprivate

Returns true if extra threads to send data via websockets will be used (default off)

Definition at line 63 of file RWebWindowsManager.hxx.

◆ SetDeleteCallback()

void ROOT::RWebWindowsManager::SetDeleteCallback ( WebWindowDeleteCallback_t  func)
inline

Assign show callback which can catch window showing, used by RBrowser.

Definition at line 98 of file RWebWindowsManager.hxx.

◆ SetLoopbackMode()

void RWebWindowsManager::SetLoopbackMode ( bool  on = true)
static

Set loopback mode for THttpServer used for web widgets By default is on.

Only local communication via localhost address is possible Disable it only if really necessary - it may open unauthorized access to your application from external nodes!!

Definition at line 129 of file RWebWindowsManager.cxx.

◆ SetShowCallback()

void ROOT::RWebWindowsManager::SetShowCallback ( WebWindowShowCallback_t  func)
inline

Assign show callback which can catch window showing, used by RBrowser.

Definition at line 95 of file RWebWindowsManager.hxx.

◆ SetSingleConnMode()

void RWebWindowsManager::SetSingleConnMode ( bool  on = true)
static

Enable or disable single connection mode (default on) If enabled, one connection only with any web widget is possible Any attempt to establish more connections will fail if this mode is disabled some widgets like geom viewer or web canvas will be able to to serve several clients - only when they are connected with required authentication keys.

Definition at line 180 of file RWebWindowsManager.cxx.

◆ SetUseConnectionKey()

void RWebWindowsManager::SetUseConnectionKey ( bool  on = true)
static

Enable or disable usage of connection key (default on) If enabled, each connection (and reconnection) to widget requires unique key Connection key used together with session key to calculate hash sum of each packet send to or from server This protects ROOT http server from anauthorized usage.

Definition at line 168 of file RWebWindowsManager.cxx.

◆ SetUseSessionKey()

void RWebWindowsManager::SetUseSessionKey ( bool  on = true)
static

Enable or disable usage of session key (default on) If enabled, secrete session key used to calculate hash sum of each packet send to or from server This protects ROOT http server from anauthorized usage.

Definition at line 157 of file RWebWindowsManager.cxx.

◆ ShowWindow()

unsigned RWebWindowsManager::ShowWindow ( RWebWindow win,
const RWebDisplayArgs user_args 
)
private

Show window in specified location, see Show() method for more details.

Show web window in specified location.

Parameters
[in,out]winweb window by reference
user_argsspecifies where and how display web window

As display args one can use string like "firefox" or "chrome" - these are two main supported web browsers. See RWebDisplayArgs::SetBrowserKind() for all available options. Default value for the browser can be configured when starting root with –web argument like: "root --web=chrome". When root started in web server mode "root --web=server", no any web browser will be started - just URL will be printout, which can be entered in any running web browser

If allowed, same window can be displayed several times (like for RCanvas or TCanvas)

Following parameters can be configured in rootrc file:

 WebGui.Display: kind of display like chrome or firefox or browser, can be overwritten by --web=value command line argument
 WebGui.OnetimeKey: if configured requires unique key every time window is connected (default yes)
 WebGui.SingleConnMode: if configured the only connection and the only user of any widget is possible (default yes)
 WebGui.Chrome: full path to Google Chrome executable
 WebGui.ChromeBatch: command to start chrome in batch, used for image production, like "$prog --headless --disable-gpu $geometry $url"
 WebGui.ChromeHeadless: command to start chrome in headless mode, like "fork: --headless --disable-gpu $geometry $url"
 WebGui.ChromeInteractive: command to start chrome in interactive mode, like "$prog $geometry --app=\'$url\' &"
 WebGui.Firefox: full path to Mozilla Firefox executable
 WebGui.FirefoxHeadless: command to start Firefox in headless mode, like "fork:--headless --private-window --no-remote $profile $url"
 WebGui.FirefoxInteractive: command to start Firefox in interactive mode, like "$prog --private-window \'$url\' &"
 WebGui.FirefoxProfile: name of Firefox profile to use
 WebGui.FirefoxProfilePath: file path to Firefox profile
 WebGui.FirefoxRandomProfile: usage of random Firefox profile -1 never, 0 - only for headless mode (dflt), 1 - always
 WebGui.LaunchTmout: time required to start process in seconds (default 30 s)
 WebGui.OperationTmout: time required to perform WebWindow operation like execute command or update drawings
 WebGui.RecordData: if specified enables data recording for each web window 0 - off, 1 - on
 WebGui.JsonComp: compression factor for JSON conversion, if not specified - each widget uses own default values
 WebGui.ForceHttp: 0 - off (default), 1 - always create real http server to run web window
 WebGui.Console: -1 - output only console.error(), 0 - add console.warn(), 1  - add console.log() output
 WebGui.ConnCredits: 10 - number of packets which can be send by server or client without acknowledge from receiving side
 WebGui.openui5src: alternative location for openui5 like https://openui5.hana.ondemand.com/1.128.0/
 WebGui.openui5libs: list of pre-loaded ui5 libs like sap.m, sap.ui.layout, sap.ui.unified
 WebGui.openui5theme: openui5 theme like sap_belize (default) or sap_fiori_3

THttpServer-related parameters documented in CreateServer method

Definition at line 791 of file RWebWindowsManager.cxx.

◆ Terminate()

void RWebWindowsManager::Terminate ( )

Terminate http server and ROOT application.

Definition at line 950 of file RWebWindowsManager.cxx.

◆ Unregister()

void RWebWindowsManager::Unregister ( RWebWindow win)
private

Release all references to specified window Called from RWebWindow destructor.

Definition at line 686 of file RWebWindowsManager.cxx.

◆ WaitFor()

int RWebWindowsManager::WaitFor ( RWebWindow win,
WebWindowWaitFunc_t  check,
bool  timed = false,
double  timelimit = -1 
)
private

Waits until provided check function or lambdas returns non-zero value Regularly calls WebWindow::Sync() method to let run event loop If call from the main thread, runs system events processing Check function has following signature: int func(double spent_tm) Parameter spent_tm is time in seconds, which already spent inside function Waiting will be continued, if function returns zero.

First non-zero value breaks waiting loop and result is returned (or 0 if time is expired). If parameter timed is true, timelimit (in seconds) defines how long to wait

Definition at line 914 of file RWebWindowsManager.cxx.

Friends And Related Symbol Documentation

◆ RWebWindow

friend class RWebWindow
friend

Definition at line 42 of file RWebWindowsManager.hxx.

Member Data Documentation

◆ fAddr

std::string ROOT::RWebWindowsManager::fAddr
private

! HTTP address of the server

Definition at line 46 of file RWebWindowsManager.hxx.

◆ fAssgnExec

std::unique_ptr<TExec> ROOT::RWebWindowsManager::fAssgnExec
private

! special exec to assign thread id via ProcessEvents

Definition at line 55 of file RWebWindowsManager.hxx.

◆ fDeleteCallback

WebWindowDeleteCallback_t ROOT::RWebWindowsManager::fDeleteCallback
private

! function called when RWebWindow is destroyed

Definition at line 57 of file RWebWindowsManager.hxx.

◆ fExternalProcessEvents

bool ROOT::RWebWindowsManager::fExternalProcessEvents {false}
private

! indicate that there are external process events engine

Definition at line 54 of file RWebWindowsManager.hxx.

◆ fIdCnt

unsigned ROOT::RWebWindowsManager::fIdCnt {0}
private

! counter for identifiers

Definition at line 50 of file RWebWindowsManager.hxx.

◆ fLaunchTmout

float ROOT::RWebWindowsManager::fLaunchTmout {30.}
private

! timeout in seconds to start browser process, default 30s

Definition at line 53 of file RWebWindowsManager.hxx.

◆ fMutex

std::recursive_mutex ROOT::RWebWindowsManager::fMutex
private

! main mutex, used for window creations

Definition at line 49 of file RWebWindowsManager.hxx.

◆ fServer

std::unique_ptr<THttpServer> ROOT::RWebWindowsManager::fServer
private

! central communication with the all used displays

Definition at line 45 of file RWebWindowsManager.hxx.

◆ fSessionKey

std::string ROOT::RWebWindowsManager::fSessionKey
private

! secret session key used on client to code connections keys

Definition at line 47 of file RWebWindowsManager.hxx.

◆ fShowCallback

WebWindowShowCallback_t ROOT::RWebWindowsManager::fShowCallback
private

! function called for each RWebWindow::Show call

Definition at line 56 of file RWebWindowsManager.hxx.

◆ fUseHttpThrd

bool ROOT::RWebWindowsManager::fUseHttpThrd {false}
private

! use special thread for THttpServer

Definition at line 51 of file RWebWindowsManager.hxx.

◆ fUseSenderThreads

bool ROOT::RWebWindowsManager::fUseSenderThreads {false}
private

! use extra threads for sending data from RWebWindow to clients

Definition at line 52 of file RWebWindowsManager.hxx.

◆ fUseSessionKey

bool ROOT::RWebWindowsManager::fUseSessionKey {false}
private

! is session key has to be used for data signing

Definition at line 48 of file RWebWindowsManager.hxx.

Libraries for ROOT::RWebWindowsManager:

The documentation for this class was generated from the following files: