Logo ROOT  
Reference Guide
ROOT::Experimental::RWebWindow Class Reference

Represents web window, which can be shown in web browser or any other supported environment.

Window can be configured to run either in the normal or in the batch (headless) mode. In second case no any graphical elements will be created. For the normal window one can configure geometry (width and height), which are applied when window shown.

Each window can be shown several times (if allowed) in different places - either as the CEF (chromium embedded) window or in the standard web browser. When started, window will open and show HTML page, configured with RWebWindow::SetDefaultPage() method.

Typically (but not necessarily) clients open web socket connection to the window and one can exchange data, using RWebWindow::Send() method and call-back function assigned via RWebWindow::SetDataCallBack().

Definition at line 56 of file RWebWindow.hxx.

Classes

struct  QueueEntry
 
struct  QueueItem
 
struct  WebConn
 

Public Member Functions

 RWebWindow ()
 RWebWindow constructor Should be defined here because of std::unique_ptr<RWebWindowWSHandler> More...
 
 ~RWebWindow ()
 RWebWindow destructor Closes all connections and remove window from manager. More...
 
bool CanSend (unsigned connid, bool direct=true) const
 returns true if sending via specified connection can be performed if direct==true, checks if direct sending (without queuing) is possible if connid==0, all existing connections are checked More...
 
void CloseConnection (unsigned connid)
 Close specified connection Connection id usually appears in the correspondent call-backs. More...
 
void CloseConnections ()
 Closes all connection to clients Normally leads to closing of all correspondent browser windows Some browsers (like firefox) do not allow by default to close window. More...
 
unsigned FindBatch ()
 Returns connection id of batch job Connection to that job may not be initialized yet If connection does not exists, returns 0. More...
 
std::string GetAddr () const
 Returns window address which is used in URL. More...
 
std::string GetClientVersion () const
 Returns current client version. More...
 
unsigned GetConnectionId (int num=0) const
 Returns connection for specified connection number Only active connections are returned - where clients confirms connection Total number of connections can be retrieved with NumConnections() method. More...
 
unsigned GetConnLimit () const
 returns configured connections limit (0 - default) More...
 
unsigned GetDisplayConnection () const
 Returns first connection id where window is displayed It could be that connection(s) not yet fully established - but also not timed out Batch jobs will be ignored here Returns 0 if connection not exists. More...
 
unsigned GetHeight () const
 returns configured window height (0 - default) More...
 
unsigned GetId () const
 Returns ID for the window - unique inside window manager. More...
 
unsigned GetMaxQueueLength () const
 Return maximal queue length of data which can be held by window. More...
 
float GetOperationTmout () const
 Returns timeout for synchronous WebWindow operations. More...
 
std::string GetRelativeAddr (const std::shared_ptr< RWebWindow > &win) const
 Returns relative URL address for the specified window Address can be required if one needs to access data from one window into another window Used for instance when inserting panel into canvas. More...
 
int GetSendQueueLength (unsigned connid) const
 returns send queue length for specified connection if connid==0, maximal value for all connections is returned If wrong connection is specified, -1 is return More...
 
THttpServerGetServer ()
 Return THttpServer instance serving requests to the window. More...
 
std::string GetUrl (bool remote=true)
 Return URL string to access web window If remote flag is specified, real HTTP server will be started automatically. More...
 
std::string GetUserArgs () const
 Returns configured user arguments for web window See SetUserArgs method for more details. More...
 
unsigned GetWidth () const
 returns configured window width (0 - default) actual window width can be different More...
 
bool HasConnection (unsigned connid=0, bool only_active=true) const
 returns true if specified connection id exists connid is connection (0 - any) if only_active==false, also inactive connections check or connections which should appear More...
 
bool IsNativeOnlyConn () const
 returns true if only native (own-created) connections are allowed More...
 
bool IsShown () const
 Returns true when window was shown at least once. More...
 
unsigned MakeBatch (bool create_new=false, const RWebDisplayArgs &args="")
 Create batch job for specified window Normally only single batch job is used, but many can be created See ROOT::Experimental::RWebWindowsManager::Show() docu for more info returns (future) connection id (or 0 when fails) More...
 
int NumConnections (bool with_pending=false) const
 Returns current number of active clients connections. More...
 
void RecordData (const std::string &fname="protocol.json", const std::string &fprefix="")
 Configures recording of communication data in protocol file Provided filename will be used to store JSON array with names of written files - text or binary If data was send from client, "send" entry will be placed. More...
 
void Run (double tm=0.)
 Run window functionality for specified time If no action can be performed - just sleep specified time. More...
 
void Send (unsigned connid, const std::string &data)
 Sends data to specified connection If connid==0, data will be send to all connections. More...
 
void SendBinary (unsigned connid, const void *data, std::size_t len)
 Send binary data to specified connection If connid==0, data will be sent to all connections. More...
 
void SendBinary (unsigned connid, std::string &&data)
 Send binary data to specified connection If connid==0, data will be sent to all connections. More...
 
void SetCallBacks (WebWindowConnectCallback_t conn, WebWindowDataCallback_t data, WebWindowConnectCallback_t disconn=nullptr)
 Set call-backs function for connect, data and disconnect events. More...
 
void SetClientVersion (const std::string &vers)
 Set client version, used as prefix in scripts URL When changed, web browser will reload all related JS files while full URL will be different Default is empty value - no extra string in URL Version should be string like "1.2" or "ver1.subv2" and not contain any special symbols. More...
 
void SetConnectCallBack (WebWindowConnectCallback_t func)
 Set call-back function for new connection. More...
 
void SetConnLimit (unsigned lmt=0)
 Configure maximal number of allowed connections - 0 is unlimited Will not affect already existing connections Default is 1 - the only client is allowed. More...
 
void SetDataCallBack (WebWindowDataCallback_t func)
 Set call-back function for data, received from the clients via websocket. More...
 
void SetDefaultPage (const std::string &page)
 Set content of default window HTML page This page returns when URL address of the window will be requested Either HTML code or file name in the form "file:/home/user/data/file.htm" One also can using default locations like "file:rootui5sys/canv/canvas.html". More...
 
void SetDisconnectCallBack (WebWindowConnectCallback_t func)
 Set call-back function for disconnecting. More...
 
void SetGeometry (unsigned width, unsigned height)
 Set window geometry. Will be applied if supported by used web display (like CEF or Chromium) More...
 
void SetMaxQueueLength (unsigned len=10)
 configures maximal queue length of data which can be held by window More...
 
void SetNativeOnlyConn (bool on=true)
 configures that only native (own-created) connections are allowed More...
 
void SetOperationTmout (float tm=50.)
 Set timeout for synchronous WebWindow operations. More...
 
void SetPanelName (const std::string &name)
 Configure window to show some of existing JSROOT panels It uses "file:rootui5sys/panel/panel.html" as default HTML page At the moment only FitPanel is existing. More...
 
void SetUserArgs (const std::string &args)
 Set arbitrary JSON code, which is accessible via conn.GetUserArgs() method This JSON code injected into main HTML document into JSROOT.ConnectWebWindow() Must be called before RWebWindow::Show() method is called. More...
 
unsigned Show (const RWebDisplayArgs &args="")
 Show window in specified location See ROOT::Experimental::RWebWindowsManager::Show() docu for more info returns (future) connection id (or 0 when fails) More...
 
void Sync ()
 Special method to process all internal activity when window runs in separate thread. More...
 
void TerminateROOT ()
 Terminate ROOT session Tries to correctly close THttpServer, associated with RWebWindowsManager After that exit from process. More...
 
int WaitFor (WebWindowWaitFunc_t check)
 Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero. More...
 
int WaitForTimed (WebWindowWaitFunc_t check)
 Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero. More...
 
int WaitForTimed (WebWindowWaitFunc_t check, double duration)
 Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero. More...
 

Static Public Member Functions

static std::shared_ptr< RWebWindowCreate ()
 Create new RWebWindow Using default RWebWindowsManager. More...
 
static unsigned ShowWindow (std::shared_ptr< RWebWindow > window, const RWebDisplayArgs &args="")
 Static method to show web window Has to be used instead of RWebWindow::Show() when window potentially can be embed into other windows Soon RWebWindow::Show() method will be done protected. More...
 

Private Types

using ConnectionsList_t = std::vector< std::shared_ptr< WebConn > >
 
enum  EQueueEntryKind { kind_None , kind_Connect , kind_Data , kind_Disconnect }
 
using timestamp_t = std::chrono::time_point< std::chrono::system_clock >
 

Private Member Functions

std::string _MakeSendHeader (std::shared_ptr< WebConn > &conn, bool txt, const std::string &data, int chid)
 Prepare text part of send data Should be called under locked connection mutex. More...
 
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 client is connected, key should be supplied to correctly identify it. More...
 
unsigned AddEmbedWindow (std::shared_ptr< RWebWindow > window, int channel)
 Add embed window. More...
 
void AssignCallbackThreadId ()
 Assign thread id which has to be used for callbacks. More...
 
void CheckDataToSend (bool only_once=false)
 Checks if new data can be send (internal use only) If necessary, provide credits to the client. More...
 
bool CheckDataToSend (std::shared_ptr< WebConn > &conn)
 Checks if one should send data for specified connection Returns true when send operation was performed. More...
 
void CheckInactiveConnections ()
 Check if there are connection which are inactive for longer time For instance, batch browser will be stopped if no activity for 30 sec is there. More...
 
void CheckPendingConnections ()
 Check if started process(es) establish connection. More...
 
void CompleteWSSend (unsigned wsid)
 
std::shared_ptr< RWebWindowWSHandlerCreateWSHandler (std::shared_ptr< RWebWindowsManager > mgr, unsigned id, double tmout)
 Assigns manager reference, window id and creates websocket handler, used for communication with the clients. More...
 
std::shared_ptr< WebConnFindConnection (unsigned wsid)
 
std::shared_ptr< WebConnFindOrCreateConnection (unsigned wsid, bool make_new, const char *query)
 Find connection with given websocket id Connection mutex should be locked before method calling. More...
 
ConnectionsList_t GetConnections (unsigned connid=0, bool only_active=false) const
 returns connection (or all active connections) More...
 
bool HasKey (const std::string &key) const
 Returns true if provided key value already exists (in processes map or in existing connections) More...
 
void InvokeCallbacks (bool force=false)
 Invoke callbacks with existing data Must be called from appropriate thread. More...
 
bool ProcessBatchHolder (std::shared_ptr< THttpCallArg > &arg)
 Process special http request, used to hold headless browser running Such requests should not be replied for the long time Be aware that function called directly from THttpServer thread, which is not same thread as window. More...
 
bool ProcessWS (THttpCallArg &arg)
 Processing of websockets call-backs, invoked from RWebWindowWSHandler Method invoked from http server thread, therefore appropriate mutex must be used on all relevant data. More...
 
void ProvideQueueEntry (unsigned connid, EQueueEntryKind kind, std::string &&arg)
 Provide data to user callback User callback must be executed in the window thread. More...
 
std::shared_ptr< WebConnRemoveConnection (unsigned wsid)
 Remove connection with given websocket id. More...
 
void RemoveEmbedWindow (unsigned connid, int channel)
 Remove RWebWindow associated with the channel. More...
 
void SubmitData (unsigned connid, bool txt, std::string &&data, int chid=1)
 Internal method to send data Allows to specify channel. More...
 

Private Attributes

std::thread::id fCallbacksThrdId
 ! thread id where callbacks should be invoked More...
 
bool fCallbacksThrdIdSet {false}
 ! flag indicating that thread id is assigned More...
 
std::string fClientVersion
 ! configured client version, used as prefix in scripts URL More...
 
ConnectionsList_t fConn
 ! list of all accepted connections More...
 
WebWindowConnectCallback_t fConnCallback
 ! callback for connect event More...
 
unsigned fConnCnt {0}
 ! counter of new connections to assign ids More...
 
unsigned fConnLimit {1}
 ! number of allowed active connections More...
 
std::mutex fConnMutex
 ! mutex used to protect connection list More...
 
WebWindowDataCallback_t fDataCallback
 ! main callback when data over channel 1 is arrived More...
 
std::string fDefaultPage
 ! HTML page (or file name) returned when window URL is opened More...
 
WebWindowConnectCallback_t fDisconnCallback
 ! callback for disconnect event More...
 
unsigned fHeight {0}
 ! initial window height when displayed More...
 
unsigned fId {0}
 ! unique identifier More...
 
std::queue< QueueEntryfInputQueue
 ! input queue for all callbacks More...
 
std::mutex fInputQueueMutex
 ! mutex to protect input queue More...
 
std::shared_ptr< RWebWindowfMaster
 ! master window where this window is embeded More...
 
int fMasterChannel {-1}
 ! channel id in the master window More...
 
unsigned fMasterConnId {0}
 ! master connection id More...
 
unsigned fMaxQueueLength {10}
 ! maximal number of queue entries More...
 
std::shared_ptr< RWebWindowsManagerfMgr
 ! display manager More...
 
bool fNativeOnlyConn {false}
 ! only native connection are allowed, created by Show() method More...
 
float fOperationTmout {50.}
 ! timeout in seconds to perform synchronous operation, default 50s More...
 
std::string fPanelName
 ! panel name which should be shown in the window More...
 
ConnectionsList_t fPendingConn
 ! list of pending connection with pre-assigned keys More...
 
bool fProcessMT {false}
 ! if window event processing performed in dedicated thread More...
 
std::string fProtocol
 ! protocol More...
 
int fProtocolCnt {-1}
 ! counter for protocol recording More...
 
unsigned fProtocolConnId {0}
 ! connection id, which is used for writing protocol More...
 
std::string fProtocolFileName
 ! local file where communication protocol will be written More...
 
std::string fProtocolPrefix
 ! prefix for created files names More...
 
bool fSendMT {false}
 ! true is special threads should be used for sending data More...
 
std::string fUserArgs
 ! arbitrary JSON code, which is accessible via conn.getUserArgs() method More...
 
unsigned fWidth {0}
 ! initial window width when displayed More...
 
std::shared_ptr< RWebWindowWSHandlerfWSHandler
 ! specialize websocket handler for all incoming connections More...
 

Friends

class RWebDisplayHandle
 
class RWebWindowsManager
 
class RWebWindowWSHandler
 

#include <ROOT/RWebWindow.hxx>

Member Typedef Documentation

◆ ConnectionsList_t

using ROOT::Experimental::RWebWindow::ConnectionsList_t = std::vector<std::shared_ptr<WebConn> >
private

Definition at line 113 of file RWebWindow.hxx.

◆ timestamp_t

using ROOT::Experimental::RWebWindow::timestamp_t = std::chrono::time_point<std::chrono::system_clock>
private

Definition at line 63 of file RWebWindow.hxx.

Member Enumeration Documentation

◆ EQueueEntryKind

Enumerator
kind_None 
kind_Connect 
kind_Data 
kind_Disconnect 

Definition at line 103 of file RWebWindow.hxx.

Constructor & Destructor Documentation

◆ RWebWindow()

ROOT::Experimental::RWebWindow::RWebWindow ( )
default

RWebWindow constructor Should be defined here because of std::unique_ptr<RWebWindowWSHandler>

◆ ~RWebWindow()

ROOT::Experimental::RWebWindow::~RWebWindow ( )

RWebWindow destructor Closes all connections and remove window from manager.

Definition at line 78 of file RWebWindow.cxx.

Member Function Documentation

◆ _MakeSendHeader()

std::string ROOT::Experimental::RWebWindow::_MakeSendHeader ( std::shared_ptr< WebConn > &  conn,
bool  txt,
const std::string &  data,
int  chid 
)
private

Prepare text part of send data Should be called under locked connection mutex.

Definition at line 713 of file RWebWindow.cxx.

◆ AddDisplayHandle()

unsigned ROOT::Experimental::RWebWindow::AddDisplayHandle ( bool  batch_mode,
const std::string &  key,
std::unique_ptr< RWebDisplayHandle > &  handle 
)
private

Add display handle and associated key Key is random number generated when starting new window When client is connected, key should be supplied to correctly identify it.

Definition at line 417 of file RWebWindow.cxx.

◆ AddEmbedWindow()

unsigned ROOT::Experimental::RWebWindow::AddEmbedWindow ( std::shared_ptr< RWebWindow window,
int  channel 
)
private

Add embed window.

Definition at line 1282 of file RWebWindow.cxx.

◆ AssignCallbackThreadId()

void ROOT::Experimental::RWebWindow::AssignCallbackThreadId ( )
private

Assign thread id which has to be used for callbacks.

Definition at line 1149 of file RWebWindow.cxx.

◆ CanSend()

bool ROOT::Experimental::RWebWindow::CanSend ( unsigned  connid,
bool  direct = true 
) const

returns true if sending via specified connection can be performed if direct==true, checks if direct sending (without queuing) is possible if connid==0, all existing connections are checked

Definition at line 1021 of file RWebWindow.cxx.

◆ CheckDataToSend() [1/2]

void ROOT::Experimental::RWebWindow::CheckDataToSend ( bool  only_once = false)
private

Checks if new data can be send (internal use only) If necessary, provide credits to the client.

Definition at line 808 of file RWebWindow.cxx.

◆ CheckDataToSend() [2/2]

bool ROOT::Experimental::RWebWindow::CheckDataToSend ( std::shared_ptr< WebConn > &  conn)
private

Checks if one should send data for specified connection Returns true when send operation was performed.

Definition at line 760 of file RWebWindow.cxx.

◆ CheckInactiveConnections()

void ROOT::Experimental::RWebWindow::CheckInactiveConnections ( )
private

Check if there are connection which are inactive for longer time For instance, batch browser will be stopped if no activity for 30 sec is there.

Definition at line 491 of file RWebWindow.cxx.

◆ CheckPendingConnections()

void ROOT::Experimental::RWebWindow::CheckPendingConnections ( )
private

Check if started process(es) establish connection.

After timeout such processed will be killed Method invoked from http server thread, therefore appropriate mutex must be used on all relevant data

Definition at line 456 of file RWebWindow.cxx.

◆ CloseConnection()

void ROOT::Experimental::RWebWindow::CloseConnection ( unsigned  connid)

Close specified connection Connection id usually appears in the correspondent call-backs.

Definition at line 986 of file RWebWindow.cxx.

◆ CloseConnections()

void ROOT::Experimental::RWebWindow::CloseConnections ( )

Closes all connection to clients Normally leads to closing of all correspondent browser windows Some browsers (like firefox) do not allow by default to close window.

Definition at line 977 of file RWebWindow.cxx.

◆ CompleteWSSend()

void ROOT::Experimental::RWebWindow::CompleteWSSend ( unsigned  wsid)
private

Definition at line 694 of file RWebWindow.cxx.

◆ Create()

std::shared_ptr< ROOT::Experimental::RWebWindow > ROOT::Experimental::RWebWindow::Create ( )
static

Create new RWebWindow Using default RWebWindowsManager.

Definition at line 1319 of file RWebWindow.cxx.

◆ CreateWSHandler()

std::shared_ptr< ROOT::Experimental::RWebWindowWSHandler > ROOT::Experimental::RWebWindow::CreateWSHandler ( std::shared_ptr< RWebWindowsManager mgr,
unsigned  id,
double  tmout 
)
private

Assigns manager reference, window id and creates websocket handler, used for communication with the clients.

Definition at line 131 of file RWebWindow.cxx.

◆ FindBatch()

unsigned ROOT::Experimental::RWebWindow::FindBatch ( )

Returns connection id of batch job Connection to that job may not be initialized yet If connection does not exists, returns 0.

Definition at line 191 of file RWebWindow.cxx.

◆ FindConnection()

std::shared_ptr< WebConn > ROOT::Experimental::RWebWindow::FindConnection ( unsigned  wsid)
inlineprivate

Definition at line 160 of file RWebWindow.hxx.

◆ FindOrCreateConnection()

std::shared_ptr< ROOT::Experimental::RWebWindow::WebConn > ROOT::Experimental::RWebWindow::FindOrCreateConnection ( unsigned  wsid,
bool  make_new,
const char *  query 
)
private

Find connection with given websocket id Connection mutex should be locked before method calling.

Definition at line 235 of file RWebWindow.cxx.

◆ GetAddr()

std::string ROOT::Experimental::RWebWindow::GetAddr ( ) const

Returns window address which is used in URL.

Definition at line 842 of file RWebWindow.cxx.

◆ GetClientVersion()

std::string ROOT::Experimental::RWebWindow::GetClientVersion ( ) const

Returns current client version.

Definition at line 880 of file RWebWindow.cxx.

◆ GetConnectionId()

unsigned ROOT::Experimental::RWebWindow::GetConnectionId ( int  num = 0) const

Returns connection for specified connection number Only active connections are returned - where clients confirms connection Total number of connections can be retrieved with NumConnections() method.

Definition at line 941 of file RWebWindow.cxx.

◆ GetConnections()

ROOT::Experimental::RWebWindow::ConnectionsList_t ROOT::Experimental::RWebWindow::GetConnections ( unsigned  connid = 0,
bool  only_active = false 
) const
private

returns connection (or all active connections)

Definition at line 995 of file RWebWindow.cxx.

◆ GetConnLimit()

unsigned ROOT::Experimental::RWebWindow::GetConnLimit ( ) const
inline

returns configured connections limit (0 - default)

Definition at line 233 of file RWebWindow.hxx.

◆ GetDisplayConnection()

unsigned ROOT::Experimental::RWebWindow::GetDisplayConnection ( ) const

Returns first connection id where window is displayed It could be that connection(s) not yet fully established - but also not timed out Batch jobs will be ignored here Returns 0 if connection not exists.

Definition at line 214 of file RWebWindow.cxx.

◆ GetHeight()

unsigned ROOT::Experimental::RWebWindow::GetHeight ( ) const
inline

returns configured window height (0 - default)

Definition at line 223 of file RWebWindow.hxx.

◆ GetId()

unsigned ROOT::Experimental::RWebWindow::GetId ( ) const
inline

Returns ID for the window - unique inside window manager.

Definition at line 199 of file RWebWindow.hxx.

◆ GetMaxQueueLength()

unsigned ROOT::Experimental::RWebWindow::GetMaxQueueLength ( ) const
inline

Return maximal queue length of data which can be held by window.

Definition at line 241 of file RWebWindow.hxx.

◆ GetOperationTmout()

float ROOT::Experimental::RWebWindow::GetOperationTmout ( ) const
inline

Returns timeout for synchronous WebWindow operations.

Definition at line 270 of file RWebWindow.hxx.

◆ GetRelativeAddr()

std::string ROOT::Experimental::RWebWindow::GetRelativeAddr ( const std::shared_ptr< RWebWindow > &  win) const

Returns relative URL address for the specified window Address can be required if one needs to access data from one window into another window Used for instance when inserting panel into canvas.

Definition at line 852 of file RWebWindow.cxx.

◆ GetSendQueueLength()

int ROOT::Experimental::RWebWindow::GetSendQueueLength ( unsigned  connid) const

returns send queue length for specified connection if connid==0, maximal value for all connections is returned If wrong connection is specified, -1 is return

Definition at line 1046 of file RWebWindow.cxx.

◆ GetServer()

THttpServer * ROOT::Experimental::RWebWindow::GetServer ( )

Return THttpServer instance serving requests to the window.

Definition at line 155 of file RWebWindow.cxx.

◆ GetUrl()

std::string ROOT::Experimental::RWebWindow::GetUrl ( bool  remote = true)

Return URL string to access web window If remote flag is specified, real HTTP server will be started automatically.

Definition at line 147 of file RWebWindow.cxx.

◆ GetUserArgs()

std::string ROOT::Experimental::RWebWindow::GetUserArgs ( ) const

Returns configured user arguments for web window See SetUserArgs method for more details.

Definition at line 901 of file RWebWindow.cxx.

◆ GetWidth()

unsigned ROOT::Experimental::RWebWindow::GetWidth ( ) const
inline

returns configured window width (0 - default) actual window width can be different

Definition at line 219 of file RWebWindow.hxx.

◆ HasConnection()

bool ROOT::Experimental::RWebWindow::HasConnection ( unsigned  connid = 0,
bool  only_active = true 
) const

returns true if specified connection id exists connid is connection (0 - any) if only_active==false, also inactive connections check or connections which should appear

Definition at line 952 of file RWebWindow.cxx.

◆ HasKey()

bool ROOT::Experimental::RWebWindow::HasKey ( const std::string &  key) const
private

Returns true if provided key value already exists (in processes map or in existing connections)

Definition at line 435 of file RWebWindow.cxx.

◆ InvokeCallbacks()

void ROOT::Experimental::RWebWindow::InvokeCallbacks ( bool  force = false)
private

Invoke callbacks with existing data Must be called from appropriate thread.

Definition at line 373 of file RWebWindow.cxx.

◆ IsNativeOnlyConn()

bool ROOT::Experimental::RWebWindow::IsNativeOnlyConn ( ) const
inline

returns true if only native (own-created) connections are allowed

Definition at line 249 of file RWebWindow.hxx.

◆ IsShown()

bool ROOT::Experimental::RWebWindow::IsShown ( ) const
inline

Returns true when window was shown at least once.

Definition at line 288 of file RWebWindow.hxx.

◆ MakeBatch()

unsigned ROOT::Experimental::RWebWindow::MakeBatch ( bool  create_new = false,
const RWebDisplayArgs args = "" 
)

Create batch job for specified window Normally only single batch job is used, but many can be created See ROOT::Experimental::RWebWindowsManager::Show() docu for more info returns (future) connection id (or 0 when fails)

Definition at line 176 of file RWebWindow.cxx.

◆ NumConnections()

int ROOT::Experimental::RWebWindow::NumConnections ( bool  with_pending = false) const

Returns current number of active clients connections.

Definition at line 910 of file RWebWindow.cxx.

◆ ProcessBatchHolder()

bool ROOT::Experimental::RWebWindow::ProcessBatchHolder ( std::shared_ptr< THttpCallArg > &  arg)
private

Process special http request, used to hold headless browser running Such requests should not be replied for the long time Be aware that function called directly from THttpServer thread, which is not same thread as window.

Definition at line 311 of file RWebWindow.cxx.

◆ ProcessWS()

bool ROOT::Experimental::RWebWindow::ProcessWS ( THttpCallArg arg)
private

Processing of websockets call-backs, invoked from RWebWindowWSHandler Method invoked from http server thread, therefore appropriate mutex must be used on all relevant data.

Definition at line 525 of file RWebWindow.cxx.

◆ ProvideQueueEntry()

void ROOT::Experimental::RWebWindow::ProvideQueueEntry ( unsigned  connid,
EQueueEntryKind  kind,
std::string &&  arg 
)
private

Provide data to user callback User callback must be executed in the window thread.

Definition at line 359 of file RWebWindow.cxx.

◆ RecordData()

void ROOT::Experimental::RWebWindow::RecordData ( const std::string &  fname = "protocol.json",
const std::string &  fprefix = "" 
)

Configures recording of communication data in protocol file Provided filename will be used to store JSON array with names of written files - text or binary If data was send from client, "send" entry will be placed.

JSON file will look like: ["send","msg0.txt","send","msg1.txt","msg2.txt"] If empty file name is provided, data recording will be disabled Recorded data can be used in JSROOT directly to test client code without running C++ server

Definition at line 927 of file RWebWindow.cxx.

◆ RemoveConnection()

std::shared_ptr< ROOT::Experimental::RWebWindow::WebConn > ROOT::Experimental::RWebWindow::RemoveConnection ( unsigned  wsid)
private

Remove connection with given websocket id.

Definition at line 282 of file RWebWindow.cxx.

◆ RemoveEmbedWindow()

void ROOT::Experimental::RWebWindow::RemoveEmbedWindow ( unsigned  connid,
int  channel 
)
private

Remove RWebWindow associated with the channel.

Definition at line 1303 of file RWebWindow.cxx.

◆ Run()

void ROOT::Experimental::RWebWindow::Run ( double  tm = 0.)

Run window functionality for specified time If no action can be performed - just sleep specified time.

Definition at line 1263 of file RWebWindow.cxx.

◆ Send()

void ROOT::Experimental::RWebWindow::Send ( unsigned  connid,
const std::string &  data 
)

Sends data to specified connection If connid==0, data will be send to all connections.

Definition at line 1120 of file RWebWindow.cxx.

◆ SendBinary() [1/2]

void ROOT::Experimental::RWebWindow::SendBinary ( unsigned  connid,
const void data,
std::size_t  len 
)

Send binary data to specified connection If connid==0, data will be sent to all connections.

Definition at line 1138 of file RWebWindow.cxx.

◆ SendBinary() [2/2]

void ROOT::Experimental::RWebWindow::SendBinary ( unsigned  connid,
std::string &&  data 
)

Send binary data to specified connection If connid==0, data will be sent to all connections.

Definition at line 1129 of file RWebWindow.cxx.

◆ SetCallBacks()

void ROOT::Experimental::RWebWindow::SetCallBacks ( WebWindowConnectCallback_t  conn,
WebWindowDataCallback_t  data,
WebWindowConnectCallback_t  disconn = nullptr 
)

Set call-backs function for connect, data and disconnect events.

Definition at line 1209 of file RWebWindow.cxx.

◆ SetClientVersion()

void ROOT::Experimental::RWebWindow::SetClientVersion ( const std::string &  vers)

Set client version, used as prefix in scripts URL When changed, web browser will reload all related JS files while full URL will be different Default is empty value - no extra string in URL Version should be string like "1.2" or "ver1.subv2" and not contain any special symbols.

Definition at line 871 of file RWebWindow.cxx.

◆ SetConnectCallBack()

void ROOT::Experimental::RWebWindow::SetConnectCallBack ( WebWindowConnectCallback_t  func)

Set call-back function for new connection.

Definition at line 1191 of file RWebWindow.cxx.

◆ SetConnLimit()

void ROOT::Experimental::RWebWindow::SetConnLimit ( unsigned  lmt = 0)
inline

Configure maximal number of allowed connections - 0 is unlimited Will not affect already existing connections Default is 1 - the only client is allowed.

Definition at line 229 of file RWebWindow.hxx.

◆ SetDataCallBack()

void ROOT::Experimental::RWebWindow::SetDataCallBack ( WebWindowDataCallback_t  func)

Set call-back function for data, received from the clients via websocket.

Function should have signature like void func(unsigned connid, const std::string &data) First argument identifies connection (unique for each window), second argument is received data

At the moment when callback is assigned, RWebWindow working thread is detected. If called not from main application thread, RWebWindow::Run() function must be regularly called from that thread.

Most simple way to assign call-back - use of c++11 lambdas like:

auto win = RWebWindow::Create();
win->SetDefaultPage("file:./page.htm");
win->SetDataCallBack(
[](unsigned connid, const std::string &data) {
printf("Conn:%u data:%s\n", connid, data.c_str());
}
);
win->Show();
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.

Definition at line 1182 of file RWebWindow.cxx.

◆ SetDefaultPage()

void ROOT::Experimental::RWebWindow::SetDefaultPage ( const std::string &  page)
inline

Set content of default window HTML page This page returns when URL address of the window will be requested Either HTML code or file name in the form "file:/home/user/data/file.htm" One also can using default locations like "file:rootui5sys/canv/canvas.html".

Definition at line 205 of file RWebWindow.hxx.

◆ SetDisconnectCallBack()

void ROOT::Experimental::RWebWindow::SetDisconnectCallBack ( WebWindowConnectCallback_t  func)

Set call-back function for disconnecting.

Definition at line 1200 of file RWebWindow.cxx.

◆ SetGeometry()

void ROOT::Experimental::RWebWindow::SetGeometry ( unsigned  width,
unsigned  height 
)
inline

Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)

Definition at line 210 of file RWebWindow.hxx.

◆ SetMaxQueueLength()

void ROOT::Experimental::RWebWindow::SetMaxQueueLength ( unsigned  len = 10)
inline

configures maximal queue length of data which can be held by window

Definition at line 237 of file RWebWindow.hxx.

◆ SetNativeOnlyConn()

void ROOT::Experimental::RWebWindow::SetNativeOnlyConn ( bool  on = true)
inline

configures that only native (own-created) connections are allowed

Definition at line 245 of file RWebWindow.hxx.

◆ SetOperationTmout()

void ROOT::Experimental::RWebWindow::SetOperationTmout ( float  tm = 50.)
inline

Set timeout for synchronous WebWindow operations.

Definition at line 273 of file RWebWindow.hxx.

◆ SetPanelName()

void ROOT::Experimental::RWebWindow::SetPanelName ( const std::string &  name)

Configure window to show some of existing JSROOT panels It uses "file:rootui5sys/panel/panel.html" as default HTML page At the moment only FitPanel is existing.

Definition at line 113 of file RWebWindow.cxx.

◆ SetUserArgs()

void ROOT::Experimental::RWebWindow::SetUserArgs ( const std::string &  args)

Set arbitrary JSON code, which is accessible via conn.GetUserArgs() method This JSON code injected into main HTML document into JSROOT.ConnectWebWindow() Must be called before RWebWindow::Show() method is called.

Definition at line 891 of file RWebWindow.cxx.

◆ Show()

unsigned ROOT::Experimental::RWebWindow::Show ( const RWebDisplayArgs args = "")

Show window in specified location See ROOT::Experimental::RWebWindowsManager::Show() docu for more info returns (future) connection id (or 0 when fails)

Definition at line 165 of file RWebWindow.cxx.

◆ ShowWindow()

unsigned ROOT::Experimental::RWebWindow::ShowWindow ( std::shared_ptr< RWebWindow window,
const RWebDisplayArgs args = "" 
)
static

Static method to show web window Has to be used instead of RWebWindow::Show() when window potentially can be embed into other windows Soon RWebWindow::Show() method will be done protected.

Definition at line 1339 of file RWebWindow.cxx.

◆ SubmitData()

void ROOT::Experimental::RWebWindow::SubmitData ( unsigned  connid,
bool  txt,
std::string &&  data,
int  chid = 1 
)
private

Internal method to send data Allows to specify channel.

chid==1 is normal communication, chid==0 for internal with higher priority If connid==0, data will be send to all connections

Definition at line 1065 of file RWebWindow.cxx.

◆ Sync()

void ROOT::Experimental::RWebWindow::Sync ( )

Special method to process all internal activity when window runs in separate thread.

Definition at line 828 of file RWebWindow.cxx.

◆ TerminateROOT()

void ROOT::Experimental::RWebWindow::TerminateROOT ( )

Terminate ROOT session Tries to correctly close THttpServer, associated with RWebWindowsManager After that exit from process.

Definition at line 1329 of file RWebWindow.cxx.

◆ WaitFor()

int ROOT::Experimental::RWebWindow::WaitFor ( WebWindowWaitFunc_t  check)

Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero.

Parameter spent_tm is time in seconds, which already spent inside the function First non-zero value breaks loop and result is returned. Runs application mainloop and short sleeps in-between

Definition at line 1225 of file RWebWindow.cxx.

◆ WaitForTimed() [1/2]

int ROOT::Experimental::RWebWindow::WaitForTimed ( WebWindowWaitFunc_t  check)

Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero.

Parameter spent_tm in lambda is time in seconds, which already spent inside the function First non-zero value breaks waiting loop and result is returned (or 0 if time is expired). Runs application mainloop and short sleeps in-between WebGui.OperationTmout rootrc parameter defines waiting time in seconds

Definition at line 1239 of file RWebWindow.cxx.

◆ WaitForTimed() [2/2]

int ROOT::Experimental::RWebWindow::WaitForTimed ( WebWindowWaitFunc_t  check,
double  duration 
)

Waits until provided check function or lambdas returns non-zero value Check function has following signature: int func(double spent_tm) Waiting will be continued, if function returns zero.

Parameter spent_tm in lambda is time in seconds, which already spent inside the function First non-zero value breaks waiting loop and result is returned (or 0 if time is expired). Runs application mainloop and short sleeps in-between duration (in seconds) defines waiting time

Definition at line 1253 of file RWebWindow.cxx.

Friends And Related Function Documentation

◆ RWebDisplayHandle

friend class RWebDisplayHandle
friend

Definition at line 60 of file RWebWindow.hxx.

◆ RWebWindowsManager

friend class RWebWindowsManager
friend

Definition at line 58 of file RWebWindow.hxx.

◆ RWebWindowWSHandler

friend class RWebWindowWSHandler
friend

Definition at line 59 of file RWebWindow.hxx.

Member Data Documentation

◆ fCallbacksThrdId

std::thread::id ROOT::Experimental::RWebWindow::fCallbacksThrdId
private

! thread id where callbacks should be invoked

Definition at line 135 of file RWebWindow.hxx.

◆ fCallbacksThrdIdSet

bool ROOT::Experimental::RWebWindow::fCallbacksThrdIdSet {false}
private

! flag indicating that thread id is assigned

Definition at line 136 of file RWebWindow.hxx.

◆ fClientVersion

std::string ROOT::Experimental::RWebWindow::fClientVersion
private

! configured client version, used as prefix in scripts URL

Definition at line 142 of file RWebWindow.hxx.

◆ fConn

ConnectionsList_t ROOT::Experimental::RWebWindow::fConn
private

! list of all accepted connections

Definition at line 127 of file RWebWindow.hxx.

◆ fConnCallback

WebWindowConnectCallback_t ROOT::Experimental::RWebWindow::fConnCallback
private

! callback for connect event

Definition at line 132 of file RWebWindow.hxx.

◆ fConnCnt

unsigned ROOT::Experimental::RWebWindow::fConnCnt {0}
private

! counter of new connections to assign ids

Definition at line 125 of file RWebWindow.hxx.

◆ fConnLimit

unsigned ROOT::Experimental::RWebWindow::fConnLimit {1}
private

! number of allowed active connections

Definition at line 129 of file RWebWindow.hxx.

◆ fConnMutex

std::mutex ROOT::Experimental::RWebWindow::fConnMutex
mutableprivate

! mutex used to protect connection list

Definition at line 128 of file RWebWindow.hxx.

◆ fDataCallback

WebWindowDataCallback_t ROOT::Experimental::RWebWindow::fDataCallback
private

! main callback when data over channel 1 is arrived

Definition at line 133 of file RWebWindow.hxx.

◆ fDefaultPage

std::string ROOT::Experimental::RWebWindow::fDefaultPage
private

! HTML page (or file name) returned when window URL is opened

Definition at line 119 of file RWebWindow.hxx.

◆ fDisconnCallback

WebWindowConnectCallback_t ROOT::Experimental::RWebWindow::fDisconnCallback
private

! callback for disconnect event

Definition at line 134 of file RWebWindow.hxx.

◆ fHeight

unsigned ROOT::Experimental::RWebWindow::fHeight {0}
private

! initial window height when displayed

Definition at line 140 of file RWebWindow.hxx.

◆ fId

unsigned ROOT::Experimental::RWebWindow::fId {0}
private

! unique identifier

Definition at line 121 of file RWebWindow.hxx.

◆ fInputQueue

std::queue<QueueEntry> ROOT::Experimental::RWebWindow::fInputQueue
private

! input queue for all callbacks

Definition at line 137 of file RWebWindow.hxx.

◆ fInputQueueMutex

std::mutex ROOT::Experimental::RWebWindow::fInputQueueMutex
private

! mutex to protect input queue

Definition at line 138 of file RWebWindow.hxx.

◆ fMaster

std::shared_ptr<RWebWindow> ROOT::Experimental::RWebWindow::fMaster
private

! master window where this window is embeded

Definition at line 116 of file RWebWindow.hxx.

◆ fMasterChannel

int ROOT::Experimental::RWebWindow::fMasterChannel {-1}
private

! channel id in the master window

Definition at line 118 of file RWebWindow.hxx.

◆ fMasterConnId

unsigned ROOT::Experimental::RWebWindow::fMasterConnId {0}
private

! master connection id

Definition at line 117 of file RWebWindow.hxx.

◆ fMaxQueueLength

unsigned ROOT::Experimental::RWebWindow::fMaxQueueLength {10}
private

! maximal number of queue entries

Definition at line 131 of file RWebWindow.hxx.

◆ fMgr

std::shared_ptr<RWebWindowsManager> ROOT::Experimental::RWebWindow::fMgr
private

! display manager

Definition at line 115 of file RWebWindow.hxx.

◆ fNativeOnlyConn

bool ROOT::Experimental::RWebWindow::fNativeOnlyConn {false}
private

! only native connection are allowed, created by Show() method

Definition at line 130 of file RWebWindow.hxx.

◆ fOperationTmout

float ROOT::Experimental::RWebWindow::fOperationTmout {50.}
private

! timeout in seconds to perform synchronous operation, default 50s

Definition at line 141 of file RWebWindow.hxx.

◆ fPanelName

std::string ROOT::Experimental::RWebWindow::fPanelName
private

! panel name which should be shown in the window

Definition at line 120 of file RWebWindow.hxx.

◆ fPendingConn

ConnectionsList_t ROOT::Experimental::RWebWindow::fPendingConn
private

! list of pending connection with pre-assigned keys

Definition at line 126 of file RWebWindow.hxx.

◆ fProcessMT

bool ROOT::Experimental::RWebWindow::fProcessMT {false}
private

! if window event processing performed in dedicated thread

Definition at line 122 of file RWebWindow.hxx.

◆ fProtocol

std::string ROOT::Experimental::RWebWindow::fProtocol
private

! protocol

Definition at line 147 of file RWebWindow.hxx.

◆ fProtocolCnt

int ROOT::Experimental::RWebWindow::fProtocolCnt {-1}
private

! counter for protocol recording

Definition at line 144 of file RWebWindow.hxx.

◆ fProtocolConnId

unsigned ROOT::Experimental::RWebWindow::fProtocolConnId {0}
private

! connection id, which is used for writing protocol

Definition at line 145 of file RWebWindow.hxx.

◆ fProtocolFileName

std::string ROOT::Experimental::RWebWindow::fProtocolFileName
private

! local file where communication protocol will be written

Definition at line 143 of file RWebWindow.hxx.

◆ fProtocolPrefix

std::string ROOT::Experimental::RWebWindow::fProtocolPrefix
private

! prefix for created files names

Definition at line 146 of file RWebWindow.hxx.

◆ fSendMT

bool ROOT::Experimental::RWebWindow::fSendMT {false}
private

! true is special threads should be used for sending data

Definition at line 123 of file RWebWindow.hxx.

◆ fUserArgs

std::string ROOT::Experimental::RWebWindow::fUserArgs
private

! arbitrary JSON code, which is accessible via conn.getUserArgs() method

Definition at line 148 of file RWebWindow.hxx.

◆ fWidth

unsigned ROOT::Experimental::RWebWindow::fWidth {0}
private

! initial window width when displayed

Definition at line 139 of file RWebWindow.hxx.

◆ fWSHandler

std::shared_ptr<RWebWindowWSHandler> ROOT::Experimental::RWebWindow::fWSHandler
private

! specialize websocket handler for all incoming connections

Definition at line 124 of file RWebWindow.hxx.

Libraries for ROOT::Experimental::RWebWindow:
[legend]

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