Logo ROOT  
Reference Guide
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 <memory>
19#include <vector>
20#include <string>
21#include <queue>
22#include <map>
23#include <functional>
24#include <mutex>
25#include <thread>
26#include <chrono>
27
28class THttpCallArg;
29class THttpServer;
30
31namespace ROOT {
32namespace Experimental {
33
34
35/// function signature for connect/disconnect call-backs
36/// argument is connection id
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
49
52
54
55 friend class RWebWindowsManager;
56 friend class RWebWindowWSHandler;
57 friend class RWebDisplayHandle;
58
59private:
60 using timestamp_t = std::chrono::time_point<std::chrono::system_clock>;
61
62 struct QueueItem {
63 int fChID{1}; ///<! channel
64 bool fText{true}; ///<! is text data
65 std::string fData; ///<! text or binary data
66 QueueItem(int chid, bool txt, std::string &&data) : fChID(chid), fText(txt), fData(data) {}
67 };
68
69 struct WebConn {
70 unsigned fConnId{0}; ///<! connection id (unique inside the window)
71 bool fHeadlessMode{false}; ///<! indicate if connection represent batch job
72 std::string fKey; ///<! key value supplied to the window (when exists)
73 int fKeyUsed{0}; ///<! key value used to verify connection
74 std::unique_ptr<RWebDisplayHandle> fDisplayHandle; ///<! handle assigned with started web display (when exists)
75 std::shared_ptr<THttpCallArg> fHold; ///<! request used to hold headless browser
76 timestamp_t fSendStamp; ///<! last server operation, always used from window thread
77 bool fActive{false}; ///<! flag indicates if connection is active
78 unsigned fWSId{0}; ///<! websocket id
79 int fReady{0}; ///<! 0 - not ready, 1..9 - interim, 10 - done
80 mutable std::mutex fMutex; ///<! mutex must be used to protect all following data
81 timestamp_t fRecvStamp; ///<! last receive operation, protected with connection mutex
82 int fRecvCount{0}; ///<! number of received packets, should return back with next sending
83 int fSendCredits{0}; ///<! how many send operation can be performed without confirmation from other side
84 int fClientCredits{0}; ///<! number of credits received from client
85 bool fDoingSend{false}; ///<! true when performing send operation
86 std::queue<QueueItem> fQueue; ///<! output queue
87 std::map<int,std::shared_ptr<RWebWindow>> fEmbed; ///<! map of embed window for that connection, key value is channel id
88 WebConn() = default;
89 WebConn(unsigned connid) : fConnId(connid) {}
90 WebConn(unsigned connid, unsigned wsid) : fConnId(connid), fActive(true), fWSId(wsid) {}
91 WebConn(unsigned connid, bool headless_mode, const std::string &key)
92 : fConnId(connid), fHeadlessMode(headless_mode), fKey(key)
93 {
95 }
96 ~WebConn();
97
98 void ResetStamps() { fSendStamp = fRecvStamp = std::chrono::system_clock::now(); }
99
101 {
102 fActive = false;
103 fWSId = 0;
104 fReady = 0;
105 fDoingSend = false;
106 fSendCredits = 0;
107 fClientCredits = 0;
108 while (!fQueue.empty())
109 fQueue.pop();
110 }
111 };
112
114
115 struct QueueEntry {
116 unsigned fConnId{0}; ///<! connection id
117 EQueueEntryKind fKind{kind_None}; ///<! kind of data
118 std::string fData; ///<! data for given connection
119 QueueEntry() = default;
120 QueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&data) : fConnId(connid), fKind(kind), fData(data) {}
121 };
122
123 using ConnectionsList_t = std::vector<std::shared_ptr<WebConn>>;
124
125 std::shared_ptr<RWebWindowsManager> fMgr; ///<! display manager
126 std::shared_ptr<RWebWindow> fMaster; ///<! master window where this window is embedded
127 unsigned fMasterConnId{0}; ///<! master connection id
128 int fMasterChannel{-1}; ///<! channel id in the master window
129 std::string fDefaultPage; ///<! HTML page (or file name) returned when window URL is opened
130 std::string fPanelName; ///<! panel name which should be shown in the window
131 unsigned fId{0}; ///<! unique identifier
132 bool fUseServerThreads{false}; ///<! indicates that server thread is using, no special window thread
133 bool fProcessMT{false}; ///<! if window event processing performed in dedicated thread
134 bool fSendMT{false}; ///<! true is special threads should be used for sending data
135 std::shared_ptr<RWebWindowWSHandler> fWSHandler; ///<! specialize websocket handler for all incoming connections
136 unsigned fConnCnt{0}; ///<! counter of new connections to assign ids
137 ConnectionsList_t fPendingConn; ///<! list of pending connection with pre-assigned keys
138 ConnectionsList_t fConn; ///<! list of all accepted connections
139 mutable std::mutex fConnMutex; ///<! mutex used to protect connection list
140 unsigned fConnLimit{1}; ///<! number of allowed active connections
141 std::string fConnToken; ///<! value of "token" URL parameter which should be provided for connecting window
142 bool fNativeOnlyConn{false}; ///<! only native connection are allowed, created by Show() method
143 unsigned fMaxQueueLength{10}; ///<! maximal number of queue entries
144 WebWindowConnectCallback_t fConnCallback; ///<! callback for connect event
145 WebWindowDataCallback_t fDataCallback; ///<! main callback when data over channel 1 is arrived
146 WebWindowConnectCallback_t fDisconnCallback; ///<! callback for disconnect event
147 std::thread::id fCallbacksThrdId; ///<! thread id where callbacks should be invoked
148 bool fCallbacksThrdIdSet{false}; ///<! flag indicating that thread id is assigned
149 bool fHasWindowThrd{false}; ///<! indicate if special window thread was started
150 std::thread fWindowThrd; ///<! special thread for that window
151 std::queue<QueueEntry> fInputQueue; ///<! input queue for all callbacks
152 std::mutex fInputQueueMutex; ///<! mutex to protect input queue
153 unsigned fWidth{0}; ///<! initial window width when displayed
154 unsigned fHeight{0}; ///<! initial window height when displayed
155 float fOperationTmout{50.}; ///<! timeout in seconds to perform synchronous operation, default 50s
156 std::string fClientVersion; ///<! configured client version, used as prefix in scripts URL
157 std::string fProtocolFileName; ///<! local file where communication protocol will be written
158 int fProtocolCnt{-1}; ///<! counter for protocol recording
159 unsigned fProtocolConnId{0}; ///<! connection id, which is used for writing protocol
160 std::string fProtocolPrefix; ///<! prefix for created files names
161 std::string fProtocol; ///<! protocol
162 std::string fUserArgs; ///<! arbitrary JSON code, which is accessible via conn.getUserArgs() method
163
164 std::shared_ptr<RWebWindowWSHandler> CreateWSHandler(std::shared_ptr<RWebWindowsManager> mgr, unsigned id, double tmout);
165
166 bool ProcessWS(THttpCallArg &arg);
167
168 void CompleteWSSend(unsigned wsid);
169
170 ConnectionsList_t GetConnections(unsigned connid = 0, bool only_active = false) const;
171
172 std::shared_ptr<WebConn> FindOrCreateConnection(unsigned wsid, bool make_new, const char *query);
173
174 /// Find connection with specified websocket id
175 std::shared_ptr<WebConn> FindConnection(unsigned wsid) { return FindOrCreateConnection(wsid, false, nullptr); }
176
177 std::shared_ptr<WebConn> RemoveConnection(unsigned wsid);
178
179 std::shared_ptr<WebConn> _FindConnWithKey(const std::string &key) const;
180
181 std::string _MakeSendHeader(std::shared_ptr<WebConn> &conn, bool txt, const std::string &data, int chid);
182
183 void ProvideQueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&arg);
184
185 void InvokeCallbacks(bool force = false);
186
187 void SubmitData(unsigned connid, bool txt, std::string &&data, int chid = 1);
188
189 bool CheckDataToSend(std::shared_ptr<WebConn> &conn);
190
191 void CheckDataToSend(bool only_once = false);
192
193 bool HasKey(const std::string &key) const;
194
195 std::string GenerateKey() const;
196
198
200
201 unsigned AddDisplayHandle(bool headless_mode, const std::string &key, std::unique_ptr<RWebDisplayHandle> &handle);
202
203 unsigned AddEmbedWindow(std::shared_ptr<RWebWindow> window, int channel);
204
205 void RemoveEmbedWindow(unsigned connid, int channel);
206
207 bool ProcessBatchHolder(std::shared_ptr<THttpCallArg> &arg);
208
209 std::string GetConnToken() const;
210
211 unsigned MakeHeadless(bool create_new = false);
212
213 unsigned FindHeadlessConnection();
214
215 void CheckThreadAssign();
216
217public:
218
220
221 ~RWebWindow();
222
223 /// Returns ID for the window - unique inside window manager
224 unsigned GetId() const { return fId; }
225
226 /// Returns window manager
227 std::shared_ptr<RWebWindowsManager> GetManager() const { return fMgr; }
228
229 /// Set content of default window HTML page
230 /// This page returns when URL address of the window will be requested
231 /// Either HTML code or file name in the form "file:/home/user/data/file.htm"
232 /// One also can using default locations like "file:rootui5sys/canv/canvas.html"
233 void SetDefaultPage(const std::string &page) { fDefaultPage = page; }
234
235 void SetPanelName(const std::string &name);
236
237 /// Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)
238 void SetGeometry(unsigned width, unsigned height)
239 {
240 fWidth = width;
241 fHeight = height;
242 }
243
244 /////////////////////////////////////////////////////////////////////////
245 /// returns configured window width (0 - default)
246 /// actual window width can be different
247 unsigned GetWidth() const { return fWidth; }
248
249 /////////////////////////////////////////////////////////////////////////
250 /// returns configured window height (0 - default)
251 unsigned GetHeight() const { return fHeight; }
252
253 void SetConnLimit(unsigned lmt = 0);
254
255 unsigned GetConnLimit() const;
256
257 void SetConnToken(const std::string &token = "");
258
259 /////////////////////////////////////////////////////////////////////////
260 /// configures maximal queue length of data which can be held by window
261 void SetMaxQueueLength(unsigned len = 10) { fMaxQueueLength = len; }
262
263 /////////////////////////////////////////////////////////////////////////
264 /// Return maximal queue length of data which can be held by window
265 unsigned GetMaxQueueLength() const { return fMaxQueueLength; }
266
267 /////////////////////////////////////////////////////////////////////////
268 /// configures that only native (own-created) connections are allowed
269 void SetNativeOnlyConn(bool on = true) { fNativeOnlyConn = on; }
270
271 /////////////////////////////////////////////////////////////////////////
272 /// returns true if only native (own-created) connections are allowed
273 bool IsNativeOnlyConn() const { return fNativeOnlyConn; }
274
275 void SetClientVersion(const std::string &vers);
276
277 std::string GetClientVersion() const;
278
279 void SetUserArgs(const std::string &args);
280
281 std::string GetUserArgs() const;
282
283 int NumConnections(bool with_pending = false) const;
284
285 unsigned GetConnectionId(int num = 0) const;
286
287 bool HasConnection(unsigned connid = 0, bool only_active = true) const;
288
289 void CloseConnections();
290
291 void CloseConnection(unsigned connid);
292
293 /// Returns timeout for synchronous WebWindow operations
294 float GetOperationTmout() const { return fOperationTmout; }
295
296 /// Set timeout for synchronous WebWindow operations
297 void SetOperationTmout(float tm = 50.) { fOperationTmout = tm; }
298
299 std::string GetUrl(bool remote = true);
300
302
303 void Sync();
304
305 void Run(double tm = 0.);
306
307 unsigned Show(const RWebDisplayArgs &args = "");
308
309 unsigned GetDisplayConnection() const;
310
311 /// Returns true when window was shown at least once
312 bool IsShown() const { return GetDisplayConnection() != 0; }
313
314 bool CanSend(unsigned connid, bool direct = true) const;
315
316 int GetSendQueueLength(unsigned connid) const;
317
318 void Send(unsigned connid, const std::string &data);
319
320 void SendBinary(unsigned connid, const void *data, std::size_t len);
321
322 void SendBinary(unsigned connid, std::string &&data);
323
324 void RecordData(const std::string &fname = "protocol.json", const std::string &fprefix = "");
325
326 std::string GetAddr() const;
327
328 std::string GetRelativeAddr(const std::shared_ptr<RWebWindow> &win) const;
329
330 std::string GetRelativeAddr(const RWebWindow &win) const;
331
333
335
337
339
340 void AssignThreadId();
341
342 void UseServerThreads();
343
344 int WaitFor(WebWindowWaitFunc_t check);
345
347
348 int WaitForTimed(WebWindowWaitFunc_t check, double duration);
349
350 void StartThread();
351
352 void StopThread();
353
354 void TerminateROOT();
355
356 static std::shared_ptr<RWebWindow> Create();
357
358 static unsigned ShowWindow(std::shared_ptr<RWebWindow> window, const RWebDisplayArgs &args = "");
359
360};
361
362} // namespace Experimental
363} // namespace ROOT
364
365#endif
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 id
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
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.
Definition: RWebWindow.hxx:53
bool CheckDataToSend(std::shared_ptr< WebConn > &conn)
Checks if one should send data for specified connection Returns true when send operation was performe...
Definition: RWebWindow.cxx:910
std::vector< std::shared_ptr< WebConn > > ConnectionsList_t
Definition: RWebWindow.hxx:123
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
Definition: RWebWindow.hxx:129
unsigned AddEmbedWindow(std::shared_ptr< RWebWindow > window, int channel)
Add embed window.
std::shared_ptr< RWebWindow > fMaster
! master window where this window is embedded
Definition: RWebWindow.hxx:126
void CheckInactiveConnections()
Check if there are connection which are inactive for longer time For instance, batch browser will be ...
Definition: RWebWindow.cxx:527
ConnectionsList_t GetConnections(unsigned connid=0, bool only_active=false) const
returns connection list (or all active connections)
std::string fUserArgs
! arbitrary JSON code, which is accessible via conn.getUserArgs() method
Definition: RWebWindow.hxx:162
int fMasterChannel
! channel id in the master window
Definition: RWebWindow.hxx:128
void StartThread()
Start special thread which will be used by the window to handle all callbacks One has to be sure,...
float GetOperationTmout() const
Returns timeout for synchronous WebWindow operations.
Definition: RWebWindow.hxx:294
std::shared_ptr< WebConn > FindConnection(unsigned wsid)
Find connection with specified websocket id.
Definition: RWebWindow.hxx:175
void SetConnToken(const std::string &token="")
Configures connection token (default none) When specified, in URL of webpage such token should be pro...
Definition: RWebWindow.cxx:584
unsigned MakeHeadless(bool create_new=false)
Start headless browser for specified window Normally only single instance is used,...
Definition: RWebWindow.cxx:177
std::string GetUrl(bool remote=true)
Return URL string to access web window.
Definition: RWebWindow.cxx:148
void CloseConnections()
Closes all connection to clients Normally leads to closing of all correspondent browser windows Some ...
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...
Definition: RWebWindow.hxx:233
std::thread fWindowThrd
! special thread for that window
Definition: RWebWindow.hxx:150
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.
Definition: RWebWindow.hxx:224
ConnectionsList_t fConn
! list of all accepted connections
Definition: RWebWindow.hxx:138
void InvokeCallbacks(bool force=false)
Invoke callbacks with existing data Must be called from appropriate thread.
Definition: RWebWindow.cxx:376
std::string fProtocolPrefix
! prefix for created files names
Definition: RWebWindow.hxx:160
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
Definition: RWebWindow.hxx:144
unsigned GetMaxQueueLength() const
Return maximal queue length of data which can be held by window.
Definition: RWebWindow.hxx:265
void Sync()
Special method to process all internal activity when window runs in separate thread.
Definition: RWebWindow.cxx:978
void UseServerThreads()
Let use THttpServer threads to process requests WARNING!!! only for expert use Should be only used wh...
void TerminateROOT()
Terminate ROOT session Tries to correctly close THttpServer, associated with RWebWindowsManager After...
unsigned fConnLimit
! number of allowed active connections
Definition: RWebWindow.hxx:140
void Send(unsigned connid, const std::string &data)
Sends data to specified connection.
bool fCallbacksThrdIdSet
! flag indicating that thread id is assigned
Definition: RWebWindow.hxx:148
unsigned Show(const RWebDisplayArgs &args="")
Show window in specified location.
Definition: RWebWindow.cxx:166
THttpServer * GetServer()
Return THttpServer instance serving requests to the window.
Definition: RWebWindow.cxx:156
unsigned AddDisplayHandle(bool headless_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...
Definition: RWebWindow.cxx:420
unsigned fMasterConnId
! master connection id
Definition: RWebWindow.hxx:127
void AssignThreadId()
Assign thread id which has to be used for callbacks WARNING!!! only for expert use Automatically done...
bool fSendMT
! true is special threads should be used for sending data
Definition: RWebWindow.hxx:134
void SendBinary(unsigned connid, const void *data, std::size_t len)
Send binary data to specified connection.
unsigned fWidth
! initial window width when displayed
Definition: RWebWindow.hxx:153
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
std::thread::id fCallbacksThrdId
! thread id where callbacks should be invoked
Definition: RWebWindow.hxx:147
std::chrono::time_point< std::chrono::system_clock > timestamp_t
Definition: RWebWindow.hxx:60
std::string fClientVersion
! configured client version, used as prefix in scripts URL
Definition: RWebWindow.hxx:156
bool ProcessBatchHolder(std::shared_ptr< THttpCallArg > &arg)
Process special http request, used to hold headless browser running Such requests should not be repli...
Definition: RWebWindow.cxx:315
unsigned fConnCnt
! counter of new connections to assign ids
Definition: RWebWindow.hxx:136
unsigned fMaxQueueLength
! maximal number of queue entries
Definition: RWebWindow.hxx:143
void SetDisconnectCallBack(WebWindowConnectCallback_t func)
Set call-back function for disconnecting.
std::string fPanelName
! panel name which should be shown in the window
Definition: RWebWindow.hxx:130
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
Definition: RWebWindow.hxx:159
void SetUserArgs(const std::string &args)
Set arbitrary JSON data, which is accessible via conn.getUserArgs() method in JavaScript This JSON co...
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...
void StopThread()
Stop special thread.
WebWindowDataCallback_t fDataCallback
! main callback when data over channel 1 is arrived
Definition: RWebWindow.hxx:145
void SubmitData(unsigned connid, bool txt, std::string &&data, int chid=1)
Internal method to send data.
~RWebWindow()
RWebWindow destructor Closes all connections and remove window from manager.
Definition: RWebWindow.cxx:77
std::shared_ptr< RWebWindowsManager > GetManager() const
Returns window manager.
Definition: RWebWindow.hxx:227
void CloseConnection(unsigned connid)
Close specified connection.
unsigned GetConnectionId(int num=0) const
Returns connection id for specified connection sequence number Only active connections are returned -...
bool IsShown() const
Returns true when window was shown at least once.
Definition: RWebWindow.hxx:312
std::string GetConnToken() const
Returns configured connection token.
Definition: RWebWindow.cxx:594
void SetMaxQueueLength(unsigned len=10)
configures maximal queue length of data which can be held by window
Definition: RWebWindow.hxx:261
ConnectionsList_t fPendingConn
! list of pending connection with pre-assigned keys
Definition: RWebWindow.hxx:137
void SetConnLimit(unsigned lmt=0)
Configure maximal number of allowed connections - 0 is unlimited Will not affect already existing con...
Definition: RWebWindow.cxx:562
void SetPanelName(const std::string &name)
Configure window to show some of existing JSROOT panels It uses "file:rootui5sys/panel/panel....
Definition: RWebWindow.cxx:114
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.
Definition: RWebWindow.cxx:239
bool fHasWindowThrd
! indicate if special window thread was started
Definition: RWebWindow.hxx:149
int GetSendQueueLength(unsigned connid) const
Returns send queue length for specified connection.
std::shared_ptr< WebConn > RemoveConnection(unsigned wsid)
Remove connection with given websocket id.
Definition: RWebWindow.cxx:286
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...
Definition: RWebWindow.cxx:132
std::shared_ptr< WebConn > _FindConnWithKey(const std::string &key) const
Find connection with specified key.
Definition: RWebWindow.cxx:437
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...
unsigned GetHeight() const
returns configured window height (0 - default)
Definition: RWebWindow.hxx:251
void CheckThreadAssign()
Internal method to verify and thread id has to be assigned from manager again Special case when Proce...
Definition: RWebWindow.cxx:605
bool HasKey(const std::string &key) const
Returns true if provided key value already exists (in processes map or in existing connections)
Definition: RWebWindow.cxx:458
unsigned GetDisplayConnection() const
Returns first connection id where window is displayed It could be that connection(s) not yet fully es...
Definition: RWebWindow.cxx:219
void SetOperationTmout(float tm=50.)
Set timeout for synchronous WebWindow operations.
Definition: RWebWindow.hxx:297
unsigned GetConnLimit() const
returns configured connections limit (0 - default)
Definition: RWebWindow.cxx:572
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...
std::string GetAddr() const
Returns window address which is used in URL.
Definition: RWebWindow.cxx:992
bool fNativeOnlyConn
! only native connection are allowed, created by Show() method
Definition: RWebWindow.hxx:142
void SetGeometry(unsigned width, unsigned height)
Set window geometry. Will be applied if supported by used web display (like CEF or Chromium)
Definition: RWebWindow.hxx:238
unsigned GetWidth() const
returns configured window width (0 - default) actual window width can be different
Definition: RWebWindow.hxx:247
std::shared_ptr< RWebWindowWSHandler > fWSHandler
! specialize websocket handler for all incoming connections
Definition: RWebWindow.hxx:135
bool fUseServerThreads
! indicates that server thread is using, no special window thread
Definition: RWebWindow.hxx:132
std::string fProtocolFileName
! local file where communication protocol will be written
Definition: RWebWindow.hxx:157
unsigned fHeight
! initial window height when displayed
Definition: RWebWindow.hxx:154
std::shared_ptr< RWebWindowsManager > fMgr
! display manager
Definition: RWebWindow.hxx:125
void CheckPendingConnections()
Check if started process(es) establish connection.
Definition: RWebWindow.cxx:492
std::string fConnToken
! value of "token" URL parameter which should be provided for connecting window
Definition: RWebWindow.hxx:141
std::mutex fInputQueueMutex
! mutex to protect input queue
Definition: RWebWindow.hxx:152
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.
Definition: RWebWindow.cxx:863
bool IsNativeOnlyConn() const
returns true if only native (own-created) connections are allowed
Definition: RWebWindow.hxx:273
bool ProcessWS(THttpCallArg &arg)
Processing of websockets call-backs, invoked from RWebWindowWSHandler Method invoked from http server...
Definition: RWebWindow.cxx:615
bool HasConnection(unsigned connid=0, bool only_active=true) const
returns true if specified connection id exists
int fProtocolCnt
! counter for protocol recording
Definition: RWebWindow.hxx:158
std::queue< QueueEntry > fInputQueue
! input queue for all callbacks
Definition: RWebWindow.hxx:151
bool fProcessMT
! if window event processing performed in dedicated thread
Definition: RWebWindow.hxx:133
std::string fProtocol
! protocol
Definition: RWebWindow.hxx:161
void ProvideQueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&arg)
Provide data to user callback User callback must be executed in the window thread.
Definition: RWebWindow.cxx:362
void CompleteWSSend(unsigned wsid)
Complete websocket send operation Clear "doing send" flag and check if next operation has to be start...
Definition: RWebWindow.cxx:844
unsigned fId
! unique identifier
Definition: RWebWindow.hxx:131
float fOperationTmout
! timeout in seconds to perform synchronous operation, default 50s
Definition: RWebWindow.hxx:155
unsigned FindHeadlessConnection()
Returns connection id of window running in headless mode This can be special connection which may run...
Definition: RWebWindow.cxx:196
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
Definition: RWebWindow.hxx:146
void SetNativeOnlyConn(bool on=true)
configures that only native (own-created) connections are allowed
Definition: RWebWindow.hxx:269
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::string GenerateKey() const
Generate new unique key for the window.
Definition: RWebWindow.cxx:472
std::mutex fConnMutex
! mutex used to protect connection list
Definition: RWebWindow.hxx:139
Central instance to create and show web-based windows like Canvas or FitPanel.
Contains arguments for single HTTP call.
Definition: THttpCallArg.h:27
Online http server for arbitrary ROOT application.
Definition: THttpServer.h:31
std::function< void(unsigned)> WebWindowConnectCallback_t
function signature for connect/disconnect call-backs argument is connection id
Definition: RWebWindow.hxx:37
std::function< void(unsigned, const std::string &)> WebWindowDataCallback_t
function signature for call-backs from the window clients first argument is connection id,...
Definition: RWebWindow.hxx:41
std::function< int(double)> WebWindowWaitFunc_t
function signature for waiting call-backs Such callback used when calling thread need to waits for so...
Definition: RWebWindow.hxx:48
void(off) SmallVectorTemplateBase< T
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
QueueEntry(unsigned connid, EQueueEntryKind kind, std::string &&data)
Definition: RWebWindow.hxx:120
EQueueEntryKind fKind
! kind of data
Definition: RWebWindow.hxx:117
std::string fData
! data for given connection
Definition: RWebWindow.hxx:118
std::string fData
! text or binary data
Definition: RWebWindow.hxx:65
QueueItem(int chid, bool txt, std::string &&data)
Definition: RWebWindow.hxx:66
std::queue< QueueItem > fQueue
! output queue
Definition: RWebWindow.hxx:86
WebConn(unsigned connid, unsigned wsid)
Definition: RWebWindow.hxx:90
int fReady
! 0 - not ready, 1..9 - interim, 10 - done
Definition: RWebWindow.hxx:79
int fClientCredits
! number of credits received from client
Definition: RWebWindow.hxx:84
std::mutex fMutex
! mutex must be used to protect all following data
Definition: RWebWindow.hxx:80
timestamp_t fRecvStamp
! last receive operation, protected with connection mutex
Definition: RWebWindow.hxx:81
int fSendCredits
! how many send operation can be performed without confirmation from other side
Definition: RWebWindow.hxx:83
unsigned fConnId
! connection id (unique inside the window)
Definition: RWebWindow.hxx:70
bool fDoingSend
! true when performing send operation
Definition: RWebWindow.hxx:85
~WebConn()
Destructor for WebConn Notify special HTTP request which blocks headless browser from exit.
Definition: RWebWindow.cxx:38
WebConn(unsigned connid, bool headless_mode, const std::string &key)
Definition: RWebWindow.hxx:91
std::string fKey
! key value supplied to the window (when exists)
Definition: RWebWindow.hxx:72
std::shared_ptr< THttpCallArg > fHold
! request used to hold headless browser
Definition: RWebWindow.hxx:75
int fRecvCount
! number of received packets, should return back with next sending
Definition: RWebWindow.hxx:82
timestamp_t fSendStamp
! last server operation, always used from window thread
Definition: RWebWindow.hxx:76
bool fActive
! flag indicates if connection is active
Definition: RWebWindow.hxx:77
std::unique_ptr< RWebDisplayHandle > fDisplayHandle
! handle assigned with started web display (when exists)
Definition: RWebWindow.hxx:74
bool fHeadlessMode
! indicate if connection represent batch job
Definition: RWebWindow.hxx:71
std::map< int, std::shared_ptr< RWebWindow > > fEmbed
! map of embed window for that connection, key value is channel id
Definition: RWebWindow.hxx:87
int fKeyUsed
! key value used to verify connection
Definition: RWebWindow.hxx:73