Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RWebWindowsManager.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_RWebWindowsManager
14#define ROOT7_RWebWindowsManager
15
16#include <memory>
17#include <string>
18#include <thread>
19#include <mutex>
20#include <functional>
21
22#include "THttpEngine.h"
23
24#include <ROOT/RWebWindow.hxx>
25
26class THttpServer;
27class THttpWSHandler;
28class TExec;
29
30namespace ROOT {
31
32/// function signature for catching show calls of arbitrary RWebWindow
33/// if returns true, normal show procedure will not be invoked
34using WebWindowShowCallback_t = std::function<bool(RWebWindow &, const RWebDisplayArgs &)>;
35
37
38 friend class RWebWindow;
39
40private:
41 std::unique_ptr<THttpServer> fServer; ///<! central communication with the all used displays
42 std::string fAddr; ///<! HTTP address of the server
43 std::string fSessionKey; ///<! secret session key used on client to code connections keys
44 bool fUseSessionKey{false}; ///<! is session key has to be used for data signing
45 std::recursive_mutex fMutex; ///<! main mutex, used for window creations
46 unsigned fIdCnt{0}; ///<! counter for identifiers
47 bool fUseHttpThrd{false}; ///<! use special thread for THttpServer
48 bool fUseSenderThreads{false}; ///<! use extra threads for sending data from RWebWindow to clients
49 float fLaunchTmout{30.}; ///<! timeout in seconds to start browser process, default 30s
50 bool fExternalProcessEvents{false}; ///<! indicate that there are external process events engine
51 std::unique_ptr<TExec> fAssgnExec; ///<! special exec to assign thread id via ProcessEvents
52 WebWindowShowCallback_t fShowCallback; ///<! function called for each RWebWindow::Show call
53
54 /// Returns true if http server use special thread for requests processing (default off)
55 bool IsUseHttpThread() const { return fUseHttpThrd; }
56
57 /// Returns true if extra threads to send data via websockets will be used (default off)
58 bool IsUseSenderThreads() const { return fUseSenderThreads; }
59
60 /// Returns timeout for launching new browser process
61 float GetLaunchTmout() const { return fLaunchTmout; }
62
64
65 /// Show window in specified location, see Show() method for more details
66 unsigned ShowWindow(RWebWindow &win, const RWebDisplayArgs &args);
67
68 int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed = false, double tm = -1);
69
70 std::string GetUrl(RWebWindow &win, bool remote = false, std::string *produced_key = nullptr);
71
72 bool CreateServer(bool with_http = false);
73
74 bool InformListener(const std::string &msg);
75
76 static std::string GenerateKey(int keylen = 32);
77
78public:
80
82
83 /// Returns THttpServer instance
84 THttpServer *GetServer() const { return fServer.get(); }
85
86 /// Returns http address of the server, empty string when not available
87 std::string GetServerAddr() const { return fAddr; }
88
89 /// Assign show callback which can catch window showing, used by RBrowser
91
92 static std::shared_ptr<RWebWindowsManager> &Instance();
93
94 std::shared_ptr<RWebWindow> CreateWindow();
95
96 void Terminate();
97
98 static bool IsMainThrd();
99 static void AssignMainThrd();
100
101 static void SetLoopbackMode(bool on = true);
102 static bool IsLoopbackMode();
103
104 static void SetUseSessionKey(bool on = true);
105 static void SetUseConnectionKey(bool on = true);
106};
107
108} // namespace ROOT
109
110#endif
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 win
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
Represents web window, which can be shown in web browser or any other supported environment.
Central instance to create and show web-based windows like Canvas or FitPanel.
static std::string GenerateKey(int keylen=32)
Static method to generate cryptographic key Parameter keylen defines length of cryptographic key in b...
bool fUseSessionKey
! is session key has to be used for data signing
std::unique_ptr< TExec > fAssgnExec
! special exec to assign thread id via ProcessEvents
bool CreateServer(bool with_http=false)
Creates http server, if required - with real http engine (civetweb) One could configure concrete HTTP...
float GetLaunchTmout() const
Returns timeout for launching new browser process.
static void SetUseConnectionKey(bool on=true)
Enable or disable usage of connection key (default on) If enabled, each connection (and reconnection)...
bool fExternalProcessEvents
! indicate that there are external process events engine
std::recursive_mutex fMutex
! main mutex, used for window creations
RWebWindowsManager()
window manager constructor Required here for correct usage of unique_ptr<THttpServer>
int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed=false, double tm=-1)
Waits until provided check function or lambdas returns non-zero value Regularly calls WebWindow::Sync...
WebWindowShowCallback_t fShowCallback
! function called for each RWebWindow::Show call
unsigned ShowWindow(RWebWindow &win, const RWebDisplayArgs &args)
Show window in specified location, see Show() method for more details.
std::string fAddr
! HTTP address of the server
void Terminate()
Terminate http server and ROOT application.
unsigned fIdCnt
! counter for identifiers
bool IsUseSenderThreads() const
Returns true if extra threads to send data via websockets will be used (default off)
void SetShowCallback(WebWindowShowCallback_t func)
Assign show callback which can catch window showing, used by RBrowser.
~RWebWindowsManager()
window manager destructor Required here for correct usage of unique_ptr<THttpServer>
THttpServer * GetServer() const
Returns THttpServer instance.
std::string fSessionKey
! secret session key used on client to code connections keys
bool fUseHttpThrd
! use special thread for THttpServer
static void AssignMainThrd()
Re-assigns main thread id Normally main thread id recognized at the moment when library is loaded It ...
static void SetUseSessionKey(bool on=true)
Enable or disable usage of session key (default on) If enabled, secrete session key used to calculate...
bool IsUseHttpThread() const
Returns true if http server use special thread for requests processing (default off)
std::string GetServerAddr() const
Returns http address of the server, empty string when not available.
bool fUseSenderThreads
! use extra threads for sending data from RWebWindow to clients
std::unique_ptr< THttpServer > fServer
! central communication with the all used displays
static void SetLoopbackMode(bool on=true)
Set loopback mode for THttpServer used for web widgets By default is on.
static bool IsMainThrd()
Returns true when called from main process Main process recognized at the moment when library is load...
static std::shared_ptr< RWebWindowsManager > & Instance()
Returns default window manager Used to display all standard ROOT elements like TCanvas or TFitPanel.
bool InformListener(const std::string &msg)
If ROOT_LISTENER_SOCKET variable is configured, message will be sent to that unix socket.
float fLaunchTmout
! timeout in seconds to start browser process, default 30s
std::string GetUrl(RWebWindow &win, bool remote=false, std::string *produced_key=nullptr)
Provide URL address to access specified window from inside or from remote.
void Unregister(RWebWindow &win)
Release all references to specified window Called from RWebWindow destructor.
static bool IsLoopbackMode()
Returns true if loopback mode used by THttpServer for web widgets.
std::shared_ptr< RWebWindow > CreateWindow()
Creates new window To show window, RWebWindow::Show() have to be called.
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
Definition TExec.h:26
Online http server for arbitrary ROOT application.
Definition THttpServer.h:31
Class for user-side handling of websocket with THttpServer.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::function< bool(RWebWindow &, const RWebDisplayArgs &)> WebWindowShowCallback_t
function signature for catching show calls of arbitrary RWebWindow if returns true,...
std::function< int(double)> WebWindowWaitFunc_t
function signature for waiting call-backs Such callback used when calling thread need to waits for so...