13#ifndef ROOT7_RWebWindow
14#define ROOT7_RWebWindow
32namespace Experimental {
60 using timestamp_t = std::chrono::time_point<std::chrono::system_clock>;
74 std::shared_ptr<THttpCallArg>
fHold;
86 std::map<int,std::shared_ptr<RWebWindow>>
fEmbed;
90 WebConn(
unsigned connid,
bool batch_mode,
const std::string &key)
112 std::shared_ptr<RWebWindowsManager>
fMgr;
148 std::shared_ptr<RWebWindowWSHandler>
CreateWSHandler(std::shared_ptr<RWebWindowsManager> mgr,
unsigned id,
double tmout);
162 std::string
_MakeSendHeader(std::shared_ptr<WebConn> &conn,
bool txt,
const std::string &data,
int chid);
168 void SubmitData(
unsigned connid,
bool txt, std::string &&data,
int chid = 1);
174 bool HasKey(
const std::string &key)
const;
180 unsigned AddDisplayHandle(
bool batch_mode,
const std::string &key, std::unique_ptr<RWebDisplayHandle> &handle);
182 unsigned AddEmbedWindow(std::shared_ptr<RWebWindow> window,
int channel);
259 bool HasConnection(
unsigned connid = 0,
bool only_active =
true)
const;
271 std::string
GetUrl(
bool remote =
true);
277 void Run(
double tm = 0.);
290 bool CanSend(
unsigned connid,
bool direct =
true)
const;
294 void Send(
unsigned connid,
const std::string &data);
296 void SendBinary(
unsigned connid,
const void *data, std::size_t len);
298 void SendBinary(
unsigned connid, std::string &&data);
300 void RecordData(
const std::string &fname =
"protocol.json",
const std::string &fprefix =
"");
304 std::string
GetRelativeAddr(
const std::shared_ptr<RWebWindow> &win)
const;
322 static std::shared_ptr<RWebWindow>
Create();
include TDocParser_001 C image html pict1_TDocParser_001 png width
typedef void((*Func_t)())
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
just wrapper to deliver websockets call-backs to the RWebWindow class
Represents web window, which can be shown in web browser or any other supported environment.
bool CheckDataToSend(std::shared_ptr< WebConn > &conn)
Checks if one should send data for specified connection Returns true when send operation was performe...
std::vector< std::shared_ptr< WebConn > > ConnectionsList_t
int WaitFor(WebWindowWaitFunc_t check)
Waits until provided check function or lambdas returns non-zero value Check function has following si...
std::string fDefaultPage
! HTML page (or file name) returned when window URL is opened
unsigned AddEmbedWindow(std::shared_ptr< RWebWindow > window, int channel)
Add embed window.
std::shared_ptr< RWebWindow > fMaster
! master window where this window is embeded
void CheckInactiveConnections()
Check if there are connection which are inactive for longer time For instance, batch browser will be ...
ConnectionsList_t GetConnections(unsigned connid=0, bool only_active=false) const
returns connection (or all active connections)
std::string fUserArgs
! arbitrary JSON code, which is accessible via conn.getUserArgs() method
int fMasterChannel
! channel id in the master window
float GetOperationTmout() const
Returns timeout for synchronous WebWindow operations.
std::shared_ptr< WebConn > FindConnection(unsigned wsid)
void SetConnToken(const std::string &token="")
Configures connection token (default none) When specified, in URL of webpage such token should be pro...
std::string GetUrl(bool remote=true)
Return URL string to access web window If remote flag is specified, real HTTP server will be started ...
void CloseConnections()
Closes all connection to clients Normally leads to closing of all correspondent browser windows Some ...
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 SetDefaultPage(const std::string &page)
Set content of default window HTML page This page returns when URL address of the window will be requ...
int NumConnections(bool with_pending=false) const
Returns current number of active clients connections.
unsigned GetId() const
Returns ID for the window - unique inside window manager.
ConnectionsList_t fConn
! list of all accepted connections
void InvokeCallbacks(bool force=false)
Invoke callbacks with existing data Must be called from appropriate thread.
std::string fProtocolPrefix
! prefix for created files names
std::string GetClientVersion() const
Returns current client version.
void SetConnectCallBack(WebWindowConnectCallback_t func)
Set call-back function for new connection.
WebWindowConnectCallback_t fConnCallback
! callback for connect event
unsigned GetMaxQueueLength() const
Return maximal queue length of data which can be held by window.
void Sync()
Special method to process all internal activity when window runs in separate thread.
void TerminateROOT()
Terminate ROOT session Tries to correctly close THttpServer, associated with RWebWindowsManager After...
unsigned fConnLimit
! number of allowed active connections
void Send(unsigned connid, const std::string &data)
Sends data to specified connection If connid==0, data will be send to all connections.
bool fCallbacksThrdIdSet
! flag indicating that thread id is assigned
unsigned Show(const RWebDisplayArgs &args="")
Show window in specified location See ROOT::Experimental::RWebWindowsManager::Show() docu for more in...
THttpServer * GetServer()
Return THttpServer instance serving requests to the window.
unsigned fMasterConnId
! master connection id
void AssignCallbackThreadId()
Assign thread id which has to be used for callbacks.
bool fSendMT
! true is special threads should be used for sending data
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.
unsigned fWidth
! initial window width when displayed
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
std::thread::id fCallbacksThrdId
! thread id where callbacks should be invoked
std::chrono::time_point< std::chrono::system_clock > timestamp_t
std::string fClientVersion
! configured client version, used as prefix in scripts URL
bool ProcessBatchHolder(std::shared_ptr< THttpCallArg > &arg)
Process special http request, used to hold headless browser running Such requests should not be repli...
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...
unsigned fConnCnt
! counter of new connections to assign ids
unsigned fMaxQueueLength
! maximal number of queue entries
void SetDisconnectCallBack(WebWindowConnectCallback_t func)
Set call-back function for disconnecting.
std::string fPanelName
! panel name which should be shown in the window
void SetDataCallBack(WebWindowDataCallback_t func)
Set call-back function for data, received from the clients via websocket.
unsigned fProtocolConnId
! connection id, which is used for writing protocol
void SetUserArgs(const std::string &args)
Set arbitrary JSON code, which is accessible via conn.GetUserArgs() method This JSON code injected in...
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...
WebWindowDataCallback_t fDataCallback
! main callback when data over channel 1 is arrived
void SubmitData(unsigned connid, bool txt, std::string &&data, int chid=1)
Internal method to send data Allows to specify channel.
~RWebWindow()
RWebWindow destructor Closes all connections and remove window from manager.
void CloseConnection(unsigned connid)
Close specified connection Connection id usually appears in the correspondent call-backs.
unsigned GetConnectionId(int num=0) const
Returns connection for specified connection number Only active connections are returned - where clien...
bool IsShown() const
Returns true when window was shown at least once.
std::string GetConnToken() const
Returns configured connection token.
void SetMaxQueueLength(unsigned len=10)
configures maximal queue length of data which can be held by window
ConnectionsList_t fPendingConn
! list of pending connection with pre-assigned keys
void SetConnLimit(unsigned lmt=0)
Configure maximal number of allowed connections - 0 is unlimited Will not affect already existing con...
void SetPanelName(const std::string &name)
Configure window to show some of existing JSROOT panels It uses "file:rootui5sys/panel/panel....
RWebWindow()
RWebWindow constructor Should be defined here because of std::unique_ptr<RWebWindowWSHandler>
std::shared_ptr< WebConn > FindOrCreateConnection(unsigned wsid, bool make_new, const char *query)
Find connection with given websocket id Connection mutex should be locked before method calling.
int GetSendQueueLength(unsigned connid) const
returns send queue length for specified connection if connid==0, maximal value for all connections is...
std::shared_ptr< WebConn > RemoveConnection(unsigned wsid)
Remove connection with given websocket id.
std::shared_ptr< RWebWindowWSHandler > CreateWSHandler(std::shared_ptr< RWebWindowsManager > mgr, unsigned id, double tmout)
Assigns manager reference, window id and creates websocket handler, used for communication with the c...
bool CanSend(unsigned connid, bool direct=true) const
returns true if sending via specified connection can be performed if direct==true,...
std::string GetUserArgs() const
Returns configured user arguments for web window See SetUserArgs method for more details.
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 J...
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 GetDisplayConnection() const
Returns first connection id where window is displayed It could be that connection(s) not yet fully es...
void SetOperationTmout(float tm=50.)
Set timeout for synchronous WebWindow operations.
unsigned GetConnLimit() const
returns configured connections limit (0 - default)
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 ...
void Run(double tm=0.)
Run window functionality for specified time If no action can be performed - just sleep specified time...
unsigned FindBatch()
Returns connection id of batch job Connection to that job may not be initialized yet If connection do...
std::string GetAddr() const
Returns window address which is used in URL.
bool fNativeOnlyConn
! only native connection are allowed, created by Show() method
void SetGeometry(unsigned width, unsigned height)
Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)
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::string fProtocolFileName
! local file where communication protocol will be written
unsigned fHeight
! initial window height when displayed
std::shared_ptr< RWebWindowsManager > fMgr
! display manager
void CheckPendingConnections()
Check if started process(es) establish connection.
std::string fConnToken
! value of "token" URL parameter which should be provided for connecting window
std::mutex fInputQueueMutex
! mutex to protect input queue
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.
bool IsNativeOnlyConn() const
returns true if only native (own-created) connections are allowed
bool ProcessWS(THttpCallArg &arg)
Processing of websockets call-backs, invoked from RWebWindowWSHandler Method invoked from http server...
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,...
int fProtocolCnt
! counter for protocol recording
std::queue< QueueEntry > fInputQueue
! input queue for all callbacks
bool fProcessMT
! if window event processing performed in dedicated thread
std::string fProtocol
! protocol
void ProvideQueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&arg)
Provide data to user callback User callback must be executed in the window thread.
void CompleteWSSend(unsigned wsid)
unsigned fId
! unique identifier
float fOperationTmout
! timeout in seconds to perform synchronous operation, default 50s
int WaitForTimed(WebWindowWaitFunc_t check)
Waits until provided check function or lambdas returns non-zero value Check function has following si...
WebWindowConnectCallback_t fDisconnCallback
! callback for disconnect event
void SetNativeOnlyConn(bool on=true)
configures that only native (own-created) connections are allowed
void SetClientVersion(const std::string &vers)
Set client version, used as prefix in scripts URL When changed, web browser will reload all related J...
void RemoveEmbedWindow(unsigned connid, int channel)
Remove RWebWindow associated with the channel.
void SetCallBacks(WebWindowConnectCallback_t conn, WebWindowDataCallback_t data, WebWindowConnectCallback_t disconn=nullptr)
Set call-backs function for connect, data and disconnect events.
std::mutex fConnMutex
! mutex used to protect connection list
Central instance to create and show web-based windows like Canvas or FitPanel.
std::function< void(unsigned)> WebWindowConnectCallback_t
function signature for connect/disconnect call-backs argument is connection id
std::function< void(unsigned, const std::string &)> WebWindowDataCallback_t
function signature for call-backs from the window clients first argument is connection id,...
std::function< int(double)> WebWindowWaitFunc_t
function signature for waiting call-backs Such callback used when calling thread need to waits for so...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
unsigned fConnId
! connection id
QueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&data)
EQueueEntryKind fKind
! kind of data
std::string fData
! data for given connection
std::string fData
! text or binary data
QueueItem(int chid, bool txt, std::string &&data)
unsigned fWSId
! websocket id
bool fBatchMode
! indicate if connection represent batch job
std::queue< QueueItem > fQueue
! output queue
WebConn(unsigned connid, unsigned wsid)
int fReady
! 0 - not ready, 1..9 - interim, 10 - done
int fClientCredits
! number of credits received from client
std::mutex fMutex
! mutex must be used to protect all following data
timestamp_t fRecvStamp
! last receive operation, protected with connection mutex
int fSendCredits
! how many send operation can be performed without confirmation from other side
unsigned fConnId
! connection id (unique inside the window)
bool fDoingSend
! true when performing send operation
~WebConn()
Destructor for WebConn Notify special HTTP request which blocks headless browser from exit.
std::string fKey
! key value supplied to the window (when exists)
std::shared_ptr< THttpCallArg > fHold
! request used to hold headless browser
int fRecvCount
! number of received packets, should return back with next sending
timestamp_t fSendStamp
! last server operation, always used from window thread
bool fActive
! flag indicates if connection is active
std::unique_ptr< RWebDisplayHandle > fDisplayHandle
! handle assigned with started web display (when exists)
std::map< int, std::shared_ptr< RWebWindow > > fEmbed
! map of embed window for that connection, key value is channel id
WebConn(unsigned connid, bool batch_mode, const std::string &key)