Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RWebWindow.hxx
Go to the documentation of this file.
1// Author: Sergey Linev <s.linev@gsi.de>
2// Date: 2017-10-16
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT7_RWebWindow
14#define ROOT7_RWebWindow
15
17
18#include "ROOT/RConfig.hxx"
19
20#include <memory>
21#include <vector>
22#include <string>
23#include <queue>
24#include <map>
25#include <functional>
26#include <mutex>
27#include <thread>
28#include <chrono>
29
30class THttpCallArg;
31class THttpServer;
32
33namespace ROOT {
34
35/// function signature for connect/disconnect call-backs
36/// argument is connection id
37using WebWindowConnectCallback_t = std::function<void(unsigned)>;
38
39/// function signature for call-backs from the window clients
40/// first argument is connection id, second is received data
41using WebWindowDataCallback_t = std::function<void(unsigned, const std::string &)>;
42
43/// function signature for waiting call-backs
44/// Such callback used when calling thread need to waits for some special data,
45/// but wants to run application event loop
46/// As argument, spent time in second will be provided
47/// Waiting will be performed until function returns non-zero value
48using WebWindowWaitFunc_t = std::function<int(double)>;
49
50class RFileDialog;
53
55
56 friend class RWebWindowsManager;
57 friend class RWebWindowWSHandler;
58 friend class RWebDisplayHandle;
59 friend class RFileDialog;
60
61private:
62 using timestamp_t = std::chrono::time_point<std::chrono::system_clock>;
63
64 struct QueueItem {
65 int fChID{1}; ///<! channel
66 bool fText{true}; ///<! is text data
67 std::string fData; ///<! text or binary data
68 QueueItem(int chid, bool txt, std::string &&data) : fChID(chid), fText(txt), fData(data) {}
69 };
70
71 struct WebConn {
72 unsigned fConnId{0}; ///<! connection id (unique inside the window)
73 bool fHeadlessMode{false}; ///<! indicate if connection represent batch job
74 bool fWasFirst{false}; ///<! indicate if this was first connection, will be reinjected also on first place
75 std::string fKey; ///<! key value supplied to the window (when exists)
76 int fKeyUsed{0}; ///<! key value used to verify connection
77 std::string fNewKey; ///<! new key if connection request reload
78 std::unique_ptr<RWebDisplayHandle> fDisplayHandle; ///<! handle assigned with started web display (when exists)
79 std::shared_ptr<THttpCallArg> fHold; ///<! request used to hold headless browser
80 timestamp_t fSendStamp; ///<! last server operation, always used from window thread
81 bool fActive{false}; ///<! flag indicates if connection is active
82 unsigned fWSId{0}; ///<! websocket id
83 int fReady{0}; ///<! 0 - not ready, 1..9 - interim, 10 - done
84 mutable std::mutex fMutex; ///<! mutex must be used to protect all following data
85 timestamp_t fRecvStamp; ///<! last receive operation, protected with connection mutex
86 int fRecvCount{0}; ///<! number of received packets, should return back with next sending
87 int fSendCredits{0}; ///<! how many send operation can be performed without confirmation from other side
88 int fClientCredits{0}; ///<! number of credits received from client
89 bool fDoingSend{false}; ///<! true when performing send operation
90 unsigned long fRecvSeq{0}; ///<! sequence id of last received packet
91 unsigned long fSendSeq{1}; ///<! sequence id of last send packet
92 std::queue<QueueItem> fQueue; ///<! output queue
93 std::map<int,std::shared_ptr<RWebWindow>> fEmbed; ///<! map of embed window for that connection, key value is channel id
94 WebConn() = default;
95 WebConn(unsigned connid) : fConnId(connid) {}
96 WebConn(unsigned connid, unsigned wsid) : fConnId(connid), fActive(true), fWSId(wsid) {}
97 WebConn(unsigned connid, bool headless_mode, const std::string &key)
98 : fConnId(connid), fHeadlessMode(headless_mode), fKey(key)
99 {
100 ResetStamps();
101 }
102 ~WebConn();
103
104 void ResetStamps() { fSendStamp = fRecvStamp = std::chrono::system_clock::now(); }
105
107 {
108 fActive = false;
109 fWSId = 0;
110 fReady = 0;
111 fDoingSend = false;
112 fSendCredits = 0;
113 fClientCredits = 0;
114 fRecvSeq = 0;
115 fSendSeq = 1;
116 while (!fQueue.empty())
117 fQueue.pop();
118 }
119 };
120
121 struct MasterConn {
122 unsigned connid{0};
123 int channel{-1};
125 };
126
128
129 struct QueueEntry {
130 unsigned fConnId{0}; ///<! connection id
131 EQueueEntryKind fKind{kind_None}; ///<! kind of data
132 std::string fData; ///<! data for given connection
133 QueueEntry() = default;
134 QueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&data) : fConnId(connid), fKind(kind), fData(data) {}
135 };
136
137 using ConnectionsList_t = std::vector<std::shared_ptr<WebConn>>;
138
139 std::shared_ptr<RWebWindowsManager> fMgr; ///<! display manager
140 std::shared_ptr<RWebWindow> fMaster; ///<! master window where this window is embedded
141 std::vector<MasterConn> fMasterConns; ///<! master connections
142 std::string fDefaultPage; ///<! HTML page (or file name) returned when window URL is opened
143 std::string fPanelName; ///<! panel name which should be shown in the window
144 unsigned fId{0}; ///<! unique identifier
145 bool fUseServerThreads{false}; ///<! indicates that server thread is using, no special window thread
146 bool fUseProcessEvents{false}; ///<! all window functionality will run through process events
147 bool fProcessMT{false}; ///<! if window event processing performed in dedicated thread
148 bool fSendMT{false}; ///<! true is special threads should be used for sending data
149 bool fRequireAuthKey{true}; ///<! defines if authentication key always required when connect to the widget
150 std::shared_ptr<RWebWindowWSHandler> fWSHandler; ///<! specialize websocket handler for all incoming connections
151 unsigned fConnCnt{0}; ///<! counter of new connections to assign ids
152 ConnectionsList_t fPendingConn; ///<! list of pending connection with pre-assigned keys
153 ConnectionsList_t fConn; ///<! list of all accepted connections
154 mutable std::mutex fConnMutex; ///<! mutex used to protect connection list
155 unsigned fConnLimit{1}; ///<! number of allowed active connections
156 std::string fConnToken; ///<! value of "token" URL parameter which should be provided for connecting window
157 bool fNativeOnlyConn{false}; ///<! only native connection are allowed, created by Show() method
158 bool fUseCurrentDir{false}; ///<! if window can access local files via currentdir/ path of http server
159 unsigned fMaxQueueLength{10}; ///<! maximal number of queue entries
160 WebWindowConnectCallback_t fConnCallback; ///<! callback for connect event
161 WebWindowDataCallback_t fDataCallback; ///<! main callback when data over channel 1 is arrived
162 WebWindowConnectCallback_t fDisconnCallback; ///<! callback for disconnect event
163 std::thread::id fCallbacksThrdId; ///<! thread id where callbacks should be invoked
164 bool fCallbacksThrdIdSet{false}; ///<! flag indicating that thread id is assigned
165 bool fHasWindowThrd{false}; ///<! indicate if special window thread was started
166 std::thread fWindowThrd; ///<! special thread for that window
167 std::queue<QueueEntry> fInputQueue; ///<! input queue for all callbacks
168 std::mutex fInputQueueMutex; ///<! mutex to protect input queue
169 unsigned fWidth{0}, fHeight{0}; ///<! initial window width and height when displayed, zeros are ignored
170 int fX{-1}, fY{-1}; ///<! initial window position, -1 ignored
171 float fOperationTmout{50.}; ///<! timeout in seconds to perform synchronous operation, default 50s
172 std::string fClientVersion; ///<! configured client version, used as prefix in scripts URL
173 std::string fProtocolFileName; ///<! local file where communication protocol will be written
174 int fProtocolCnt{-1}; ///<! counter for protocol recording
175 unsigned fProtocolConnId{0}; ///<! connection id, which is used for writing protocol
176 std::string fProtocolPrefix; ///<! prefix for created files names
177 std::string fProtocol; ///<! protocol
178 std::string fUserArgs; ///<! arbitrary JSON code, which is accessible via conn.getUserArgs() method
179 std::shared_ptr<void> fClearOnClose; ///<! entry which is cleared when last connection is closed
180 static std::string gJSROOTsettings; ///<! custom settings for JSROOT
181
182 std::shared_ptr<RWebWindowWSHandler> CreateWSHandler(std::shared_ptr<RWebWindowsManager> mgr, unsigned id, double tmout);
183
184 bool ProcessWS(THttpCallArg &arg);
185
186 void CompleteWSSend(unsigned wsid);
187
188 ConnectionsList_t GetWindowConnections(unsigned connid = 0, bool only_active = false) const;
189
190 /// Find connection with specified websocket id
191 std::shared_ptr<WebConn> FindConnection(unsigned wsid);
192
193 void ClearConnection(std::shared_ptr<WebConn> &conn, bool provide_signal = false);
194
195 std::shared_ptr<WebConn> RemoveConnection(unsigned wsid, bool provide_signal = false);
196
197 bool _CanTrustIn(std::shared_ptr<WebConn> &conn, const std::string &key, const std::string &ntry, bool remote, bool test_first_time);
198
199 std::string _MakeSendHeader(std::shared_ptr<WebConn> &conn, bool txt, const std::string &data, int chid);
200
201 void ProvideQueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&arg);
202
203 void InvokeCallbacks(bool force = false);
204
205 void SubmitData(unsigned connid, bool txt, std::string &&data, int chid = 1);
206
207 bool CheckDataToSend(std::shared_ptr<WebConn> &conn);
208
209 void CheckDataToSend(bool only_once = false);
210
211 bool HasKey(const std::string &key, bool also_newkey = false) const;
212
213 void RemoveKey(const std::string &key);
214
215 std::string GenerateKey() const;
216
218
220
221 unsigned AddDisplayHandle(bool headless_mode, const std::string &key, std::unique_ptr<RWebDisplayHandle> &handle);
222
223 unsigned AddEmbedWindow(std::shared_ptr<RWebWindow> window, unsigned connid, int channel);
224
225 void RemoveEmbedWindow(unsigned connid, int channel);
226
227 void AddMasterConnection(std::shared_ptr<RWebWindow> window, unsigned connid, int channel);
228
229 std::vector<MasterConn> GetMasterConnections(unsigned connid = 0) const;
230
231 void RemoveMasterConnection(unsigned connid = 0);
232
233 bool ProcessBatchHolder(std::shared_ptr<THttpCallArg> &arg);
234
235 std::string GetConnToken() const;
236
237 unsigned MakeHeadless(bool create_new = false);
238
239 unsigned FindHeadlessConnection();
240
241 static std::function<bool(const std::shared_ptr<RWebWindow> &, unsigned, const std::string &)> gStartDialogFunc;
242
243 static void SetStartDialogFunc(std::function<bool(const std::shared_ptr<RWebWindow> &, unsigned, const std::string &)>);
244
245 static std::string HMAC(const std::string &key, const std::string &sessionKey, const char *msg, int msglen);
246
247public:
248
249 RWebWindow();
250
251 ~RWebWindow();
252
253 /// Returns ID for the window - unique inside window manager
254 unsigned GetId() const { return fId; }
255
256 /// Returns window manager
257 std::shared_ptr<RWebWindowsManager> GetManager() const { return fMgr; }
258
259 /// Set content of default window HTML page
260 /// This page returns when URL address of the window will be requested
261 /// Either HTML code or file name in the form "file:/home/user/data/file.htm"
262 /// One also can using default locations like "file:rootui5sys/canv/canvas.html"
263 void SetDefaultPage(const std::string &page) { fDefaultPage = page; }
264
265 void SetPanelName(const std::string &name);
266
267 /// Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)
268 void SetGeometry(unsigned width, unsigned height)
269 {
270 fWidth = width;
271 fHeight = height;
272 }
273
274 /// Set window position. Will be applied if supported by used web display (like CEF or Chromium)
275 void SetPosition(unsigned x, unsigned y)
276 {
277 fX = x;
278 fY = y;
279 }
280
281 /////////////////////////////////////////////////////////////////////////
282 /// returns configured window width (0 - default)
283 /// actual window width can be different
284 unsigned GetWidth() const { return fWidth; }
285
286 /////////////////////////////////////////////////////////////////////////
287 /// returns configured window height (0 - default)
288 unsigned GetHeight() const { return fHeight; }
289
290 /////////////////////////////////////////////////////////////////////////
291 /// returns configured window X position (-1 - default)
292 int GetX() const { return fX; }
293
294 /////////////////////////////////////////////////////////////////////////
295 /// returns configured window Y position (-1 - default)
296 int GetY() const { return fY; }
297
298 void SetConnLimit(unsigned lmt = 0);
299
300 unsigned GetConnLimit() const;
301
302 void SetConnToken(const std::string &token = "");
303
304 /////////////////////////////////////////////////////////////////////////
305 /// configures maximal queue length of data which can be held by window
306 void SetMaxQueueLength(unsigned len = 10) { fMaxQueueLength = len; }
307
308 /////////////////////////////////////////////////////////////////////////
309 /// Return maximal queue length of data which can be held by window
310 unsigned GetMaxQueueLength() const { return fMaxQueueLength; }
311
312 /////////////////////////////////////////////////////////////////////////
313 /// configures that only native (own-created) connections are allowed
314 void SetNativeOnlyConn(bool on = true) { fNativeOnlyConn = on; }
315
316 /////////////////////////////////////////////////////////////////////////
317 /// returns true if only native (own-created) connections are allowed
318 bool IsNativeOnlyConn() const { return fNativeOnlyConn; }
319
320 /////////////////////////////////////////////////////////////////////////
321 /// Configure if authentication key in connection string is required
323
324 /////////////////////////////////////////////////////////////////////////
325 /// returns true if authentication string is required
326 bool IsRequireAuthKey() const { return fRequireAuthKey; }
327
328 /////////////////////////////////////////////////////////////////////////
329 /// Configure if window can access local files via currentdir/ path of http server
330 void SetUseCurrentDir(bool on = true) { fUseCurrentDir = on; }
331
332 /////////////////////////////////////////////////////////////////////////
333 /// returns true if window can access local files via currentdir/ path of http server
334 bool IsUseCurrentDir() const { return fUseCurrentDir; }
335
336 void SetClientVersion(const std::string &vers);
337
338 std::string GetClientVersion() const;
339
340 void SetUserArgs(const std::string &args);
341
342 std::string GetUserArgs() const;
343
344 int NumConnections(bool with_pending = false) const;
345
346 unsigned GetConnectionId(int num = 0) const;
347
348 std::vector<unsigned> GetConnections(unsigned excludeid = 0) const;
349
350 bool HasConnection(unsigned connid = 0, bool only_active = true) const;
351
352 void CloseConnections();
353
354 void CloseConnection(unsigned connid);
355
356 /// Returns timeout for synchronous WebWindow operations
357 float GetOperationTmout() const { return fOperationTmout; }
358
359 /// Set timeout for synchronous WebWindow operations
360 void SetOperationTmout(float tm = 50.) { fOperationTmout = tm; }
361
362 std::string GetUrl(bool remote = true);
363
365
366 void Sync();
367
368 void Run(double tm = 0.);
369
370 unsigned Show(const RWebDisplayArgs &args = "");
371
372 unsigned GetDisplayConnection() const;
373
374 /// Returns true when window was shown at least once
375 bool IsShown() const { return GetDisplayConnection() != 0; }
376
377 bool CanSend(unsigned connid, bool direct = true) const;
378
379 int GetSendQueueLength(unsigned connid) const;
380
381 void Send(unsigned connid, const std::string &data);
382
383 void SendBinary(unsigned connid, const void *data, std::size_t len);
384
385 void SendBinary(unsigned connid, std::string &&data);
386
387 void RecordData(const std::string &fname = "protocol.json", const std::string &fprefix = "");
388
389 std::string GetAddr() const;
390
391 _R__DEPRECATED_LATER("Use GetUrl() to get valid connection URL") std::string GetRelativeAddr(const std::shared_ptr<RWebWindow> &win) const;
392
394
396
397 void Reset();
398
400
402
404
405 void SetClearOnClose(const std::shared_ptr<void> &handle = nullptr);
406
407 void AssignThreadId();
408
409 void UseServerThreads();
410
412
414
416
417 void StartThread();
418
419 void StopThread();
420
421 void TerminateROOT();
422
423 static std::shared_ptr<RWebWindow> Create();
424
425 static unsigned ShowWindow(std::shared_ptr<RWebWindow> window, const RWebDisplayArgs &args = "");
426
427 static bool IsFileDialogMessage(const std::string &msg);
428
429 static bool EmbedFileDialog(const std::shared_ptr<RWebWindow> &window, unsigned connid, const std::string &args);
430
431 static void SetJSROOTSettings(const std::string &json);
432};
433
434} // namespace ROOT
435
436#endif
nlohmann::json json
#define _R__DEPRECATED_LATER(REASON)
Definition RConfig.hxx:477
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h direct
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t win
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
Web-based FileDialog.
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
Handle of created web-based display Depending from type of web display, holds handle of started brows...
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::string fDefaultPage
! HTML page (or file name) returned when window URL is opened
int WaitFor(WebWindowWaitFunc_t check)
Waits until provided check function or lambdas returns non-zero value Check function has following si...
unsigned GetId() const
Returns ID for the window - unique inside window manager.
std::vector< MasterConn > GetMasterConnections(unsigned connid=0) const
Get list of master connections.
void AddMasterConnection(std::shared_ptr< RWebWindow > window, unsigned connid, int channel)
Add new master connection If there are many connections - only same master is allowed.
std::mutex fConnMutex
! mutex used to protect connection list
WebWindowDataCallback_t fDataCallback
! main callback when data over channel 1 is arrived
void CheckInactiveConnections()
Check if there are connection which are inactive for longer time For instance, batch browser will be ...
unsigned fId
! unique identifier
static void SetJSROOTSettings(const std::string &json)
Set JSROOT settings as json string Will be applied for any web window at the connection time Can be u...
bool fHasWindowThrd
! indicate if special window thread was started
std::vector< MasterConn > fMasterConns
! master connections
void SetClearOnClose(const std::shared_ptr< void > &handle=nullptr)
Set handle which is cleared when last active connection is closed Typically can be used to destroy we...
void StartThread()
Start special thread which will be used by the window to handle all callbacks One has to be sure,...
unsigned fConnCnt
! counter of new connections to assign ids
unsigned fProtocolConnId
! connection id, which is used for writing protocol
ConnectionsList_t GetWindowConnections(unsigned connid=0, bool only_active=false) const
returns connection list (or all active connections)
bool fSendMT
! true is special threads should be used for sending data
std::thread::id fCallbacksThrdId
! thread id where callbacks should be invoked
void RemoveKey(const std::string &key)
Removes all connections with the key.
std::queue< QueueEntry > fInputQueue
! input queue for all callbacks
bool _CanTrustIn(std::shared_ptr< WebConn > &conn, const std::string &key, const std::string &ntry, bool remote, bool test_first_time)
Check if provided hash, ntry parameters from the connection request could be accepted.
void SetConnToken(const std::string &token="")
Configures connection token (default none) When specified, in URL of webpage such token should be pro...
unsigned MakeHeadless(bool create_new=false)
Start headless browser for specified window Normally only single instance is used,...
std::string GetUrl(bool remote=true)
Return URL string to connect web window URL typically includes extra parameters required for connecti...
void CloseConnections()
Closes all connection to clients Normally leads to closing of all correspondent browser windows Some ...
std::shared_ptr< RWebWindow > fMaster
! master window where this window is embedded
int NumConnections(bool with_pending=false) const
Returns current number of active clients connections.
bool fCallbacksThrdIdSet
! flag indicating that thread id is assigned
std::string fUserArgs
! arbitrary JSON code, which is accessible via conn.getUserArgs() method
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...
unsigned fConnLimit
! number of allowed active connections
void InvokeCallbacks(bool force=false)
Invoke callbacks with existing data Must be called from appropriate thread.
std::shared_ptr< WebConn > FindConnection(unsigned wsid)
Find connection with specified websocket id.
std::string GetClientVersion() const
Returns current client version.
void SetConnectCallBack(WebWindowConnectCallback_t func)
Set call-back function for new connection.
bool IsShown() const
Returns true when window was shown at least once.
std::vector< std::shared_ptr< WebConn > > ConnectionsList_t
void Sync()
Special method to process all internal activity when window runs in separate thread.
void UseServerThreads()
Let use THttpServer threads to process requests WARNING!!! only for expert use Should be only used wh...
void SetGeometry(unsigned width, unsigned height)
Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)
void TerminateROOT()
Terminate ROOT session Tries to correctly close THttpServer, associated with RWebWindowsManager After...
bool fUseCurrentDir
! if window can access local files via currentdir/ path of http server
void Send(unsigned connid, const std::string &data)
Sends data to specified connection.
unsigned Show(const RWebDisplayArgs &args="")
Show window in specified location.
THttpServer * GetServer()
Return THttpServer instance serving requests to the window.
unsigned AddDisplayHandle(bool headless_mode, const std::string &key, std::unique_ptr< RWebDisplayHandle > &handle)
Add display handle and associated key Key is large random string generated when starting new window W...
void AssignThreadId()
Assign thread id which has to be used for callbacks WARNING!!! only for expert use Automatically done...
bool IsNativeOnlyConn() const
returns true if only native (own-created) connections are allowed
void SendBinary(unsigned connid, const void *data, std::size_t len)
Send binary data to specified connection.
int fY
! initial window position, -1 ignored
int GetX() const
returns configured window X position (-1 - default)
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
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...
void SetOperationTmout(float tm=50.)
Set timeout for synchronous WebWindow operations.
unsigned AddEmbedWindow(std::shared_ptr< RWebWindow > window, unsigned connid, int channel)
Add embed window.
void SetDisconnectCallBack(WebWindowConnectCallback_t func)
Set call-back function for disconnecting.
std::vector< unsigned > GetConnections(unsigned excludeid=0) const
returns vector with all existing connections ids One also can exclude specified connection from retur...
void SetDataCallBack(WebWindowDataCallback_t func)
Set call-back function for data, received from the clients via websocket.
float fOperationTmout
! timeout in seconds to perform synchronous operation, default 50s
bool fRequireAuthKey
! defines if authentication key always required when connect to the widget
void SetUserArgs(const std::string &args)
Set arbitrary JSON data, which is accessible via conn.getUserArgs() method in JavaScript This JSON co...
std::string fConnToken
! value of "token" URL parameter which should be provided for connecting window
unsigned GetHeight() const
returns configured window height (0 - default)
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...
std::shared_ptr< RWebWindowWSHandler > fWSHandler
! specialize websocket handler for all incoming connections
void StopThread()
Stop special thread.
void SubmitData(unsigned connid, bool txt, std::string &&data, int chid=1)
Internal method to send data.
static std::string HMAC(const std::string &key, const std::string &sessionKey, const char *msg, int msglen)
Calculate HMAC checksum for provided key and message Key combined from connection key and session key...
~RWebWindow()
RWebWindow destructor Closes all connections and remove window from manager.
static bool EmbedFileDialog(const std::shared_ptr< RWebWindow > &window, unsigned connid, const std::string &args)
Create dialog instance to use as embedded dialog inside provided widget Loads libROOTBrowserv7 and tr...
void CloseConnection(unsigned connid)
Close specified connection.
ConnectionsList_t fPendingConn
! list of pending connection with pre-assigned keys
unsigned GetConnectionId(int num=0) const
Returns connection id for specified connection sequence number Only active connections are returned -...
void Reset()
Reset window call-backs and close connections Should be invoked in widget destructor to simplify clea...
std::string GetConnToken() const
Returns configured connection token.
float GetOperationTmout() const
Returns timeout for synchronous WebWindow operations.
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....
void SetPosition(unsigned x, unsigned y)
Set window position. Will be applied if supported by used web display (like CEF or Chromium)
std::shared_ptr< WebConn > RemoveConnection(unsigned wsid, bool provide_signal=false)
Remove connection with given websocket id.
bool IsRequireAuthKey() const
returns true if authentication string is required
RWebWindow()
RWebWindow constructor Should be defined here because of std::unique_ptr<RWebWindowWSHandler>
void SetNativeOnlyConn(bool on=true)
configures that only native (own-created) connections are allowed
std::string fProtocolPrefix
! prefix for created files names
int GetSendQueueLength(unsigned connid) const
Returns send queue length for specified connection.
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...
std::string fProtocol
! protocol
bool CanSend(unsigned connid, bool direct=true) const
Returns true if sending via specified connection can be performed.
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...
bool fUseProcessEvents
! all window functionality will run through process events
unsigned GetDisplayConnection() const
Returns first connection id where window is displayed It could be that connection(s) not yet fully es...
unsigned fMaxQueueLength
! maximal number of queue entries
unsigned GetConnLimit() const
returns configured connections limit (0 - default)
static void SetStartDialogFunc(std::function< bool(const std::shared_ptr< RWebWindow > &, unsigned, const std::string &)>)
Configure func which has to be used for starting dialog.
std::string fPanelName
! panel name which should be shown in the window
void Run(double tm=0.)
Run window functionality for specified time If no action can be performed - just sleep specified time...
unsigned fHeight
! initial window width and height when displayed, zeros are ignored
std::string GetAddr() const
Returns window address which is used in URL.
std::shared_ptr< RWebWindowsManager > fMgr
! display manager
std::string fProtocolFileName
! local file where communication protocol will be written
int GetY() const
returns configured window Y position (-1 - default)
bool fNativeOnlyConn
! only native connection are allowed, created by Show() method
std::shared_ptr< RWebWindowsManager > GetManager() const
Returns window manager.
ConnectionsList_t fConn
! list of all accepted connections
WebWindowConnectCallback_t fConnCallback
! callback for connect event
void CheckPendingConnections()
Check if started process(es) establish connection.
std::shared_ptr< void > fClearOnClose
! entry which is cleared when last connection is closed
std::mutex fInputQueueMutex
! mutex to protect input queue
static std::function< bool(const std::shared_ptr< RWebWindow > &, unsigned, const std::string &) gStartDialogFunc)
std::string _MakeSendHeader(std::shared_ptr< WebConn > &conn, bool txt, const std::string &data, int chid)
Internal method to prepare text part of send data Should be called under locked connection mutex.
std::chrono::time_point< std::chrono::system_clock > timestamp_t
void SetMaxQueueLength(unsigned len=10)
configures maximal queue length of data which can be held by window
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
unsigned GetWidth() const
returns configured window width (0 - default) actual window width can be different
std::thread fWindowThrd
! special thread for that window
void ProvideQueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&arg)
Provide data to user callback User callback must be executed in the window thread.
bool HasKey(const std::string &key, bool also_newkey=false) const
Returns true if provided key value already exists (in processes map or in existing connections) In sp...
void CompleteWSSend(unsigned wsid)
Complete websocket send operation Clear "doing send" flag and check if next operation has to be start...
bool IsUseCurrentDir() const
returns true if window can access local files via currentdir/ path of http server
bool fUseServerThreads
! indicates that server thread is using, no special window thread
unsigned FindHeadlessConnection()
Returns connection id of window running in headless mode This can be special connection which may run...
int WaitForTimed(WebWindowWaitFunc_t check)
Waits until provided check function or lambdas returns non-zero value Check function has following si...
bool fProcessMT
! if window event processing performed in dedicated thread
void ClearConnection(std::shared_ptr< WebConn > &conn, bool provide_signal=false)
Signal that connection is closing.
int fProtocolCnt
! counter for protocol recording
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 RemoveMasterConnection(unsigned connid=0)
Remove master connection - if any.
void RemoveEmbedWindow(unsigned connid, int channel)
Remove RWebWindow associated with the channel.
_R__DEPRECATED_LATER("Use GetUrl() to get valid connection URL") std _R__DEPRECATED_LATER("Use GetAddr() to get valid connection URL") std void SetCallBacks(WebWindowConnectCallback_t conn, WebWindowDataCallback_t data, WebWindowConnectCallback_t disconn=nullptr)
Set call-backs function for connect, data and disconnect events.
void SetRequireAuthKey(bool on)
Configure if authentication key in connection string is required.
static std::string gJSROOTsettings
! custom settings for JSROOT
std::string GenerateKey() const
Generate new unique key for the window.
void SetUseCurrentDir(bool on=true)
Configure if window can access local files via currentdir/ path of http server.
WebWindowConnectCallback_t fDisconnCallback
! callback for disconnect event
unsigned GetMaxQueueLength() const
Return maximal queue length of data which can be held by window.
static bool IsFileDialogMessage(const std::string &msg)
Check if this could be the message send by client to start new file dialog If returns true,...
Central instance to create and show web-based windows like Canvas or FitPanel.
Contains arguments for single HTTP call.
Online http server for arbitrary ROOT application.
Definition THttpServer.h:31
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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< void(unsigned)> WebWindowConnectCallback_t
function signature for connect/disconnect call-backs 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...
MasterConn(unsigned _connid, int _channel)
std::string fData
! data for given connection
EQueueEntryKind fKind
! kind of data
unsigned fConnId
! connection id
QueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&data)
QueueItem(int chid, bool txt, std::string &&data)
std::string fData
! text or binary data
bool fText
! is text data
int fReady
! 0 - not ready, 1..9 - interim, 10 - done
std::shared_ptr< THttpCallArg > fHold
! request used to hold headless browser
WebConn(unsigned connid)
int fClientCredits
! number of credits received from client
unsigned long fRecvSeq
! sequence id of last received packet
bool fActive
! flag indicates if connection is active
bool fHeadlessMode
! indicate if connection represent batch job
unsigned fConnId
! connection id (unique inside the window)
std::map< int, std::shared_ptr< RWebWindow > > fEmbed
! map of embed window for that connection, key value is channel id
std::string fKey
! key value supplied to the window (when exists)
WebConn(unsigned connid, bool headless_mode, const std::string &key)
unsigned long fSendSeq
! sequence id of last send packet
int fKeyUsed
! key value used to verify connection
~WebConn()
Destructor for WebConn Notify special HTTP request which blocks headless browser from exit.
std::mutex fMutex
! mutex must be used to protect all following data
bool fDoingSend
! true when performing send operation
bool fWasFirst
! indicate if this was first connection, will be reinjected also on first place
int fSendCredits
! how many send operation can be performed without confirmation from other side
WebConn(unsigned connid, unsigned wsid)
std::string fNewKey
! new key if connection request reload
unsigned fWSId
! websocket id
timestamp_t fSendStamp
! last server operation, always used from window thread
timestamp_t fRecvStamp
! last receive operation, protected with connection mutex
int fRecvCount
! number of received packets, should return back with next sending
std::queue< QueueItem > fQueue
! output queue
std::unique_ptr< RWebDisplayHandle > fDisplayHandle
! handle assigned with started web display (when exists)