Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/ROOT/RWebWindowsManager.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Author: Sergey Linev <s.linev@gsi.de>
0002 // Date: 2017-10-16
0003 // Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT7_RWebWindowsManager
0014 #define ROOT7_RWebWindowsManager
0015 
0016 #include <memory>
0017 #include <string>
0018 #include <thread>
0019 #include <mutex>
0020 #include <functional>
0021 
0022 #include "THttpEngine.h"
0023 
0024 #include <ROOT/RWebWindow.hxx>
0025 
0026 class THttpServer;
0027 class THttpWSHandler;
0028 class TExec;
0029 
0030 namespace ROOT {
0031 
0032 /// function signature for catching show calls of arbitrary RWebWindow
0033 /// if returns true, normal show procedure will not be invoked
0034 using WebWindowShowCallback_t = std::function<bool(RWebWindow &, const RWebDisplayArgs &)>;
0035 
0036 /// function signature for callback when RWebWindow destroyed
0037 using WebWindowDeleteCallback_t = std::function<void(RWebWindow &)>;
0038 
0039 
0040 class RWebWindowsManager {
0041 
0042    friend class RWebWindow;
0043 
0044 private:
0045    std::unique_ptr<THttpServer> fServer;  ///<! central communication with the all used displays
0046    std::string fAddr;                     ///<! HTTP address of the server
0047    std::string fSessionKey;               ///<! secret session key used on client to code connections keys
0048    bool fUseSessionKey{false};            ///<! is session key has to be used for data signing
0049    std::recursive_mutex fMutex;           ///<! main mutex, used for window creations
0050    unsigned fIdCnt{0};                    ///<! counter for identifiers
0051    bool fUseHttpThrd{false};              ///<! use special thread for THttpServer
0052    bool fUseSenderThreads{false};         ///<! use extra threads for sending data from RWebWindow to clients
0053    float fLaunchTmout{30.};               ///<! timeout in seconds to start browser process, default 30s
0054    float fReconnectTmout{15.};            ///<! timeout in seconds to reconnect connection, default 15s
0055    bool fExternalProcessEvents{false};    ///<! indicate that there are external process events engine
0056    std::unique_ptr<TExec> fAssgnExec;     ///<! special exec to assign thread id via ProcessEvents
0057    WebWindowShowCallback_t fShowCallback; ///<! function called for each RWebWindow::Show call
0058    WebWindowDeleteCallback_t fDeleteCallback; ///<! function called when RWebWindow is destroyed
0059 
0060    /// Returns true if http server use special thread for requests processing (default off)
0061    bool IsUseHttpThread() const { return fUseHttpThrd; }
0062 
0063    /// Returns true if extra threads to send data via websockets will be used (default off)
0064    bool IsUseSenderThreads() const { return fUseSenderThreads; }
0065 
0066    /// Returns timeout for launching new browser process
0067    float GetLaunchTmout() const { return fLaunchTmout; }
0068 
0069    /// Returns timeout for launching new browser process
0070    float GetReconnectTmout() const { return fReconnectTmout; }
0071 
0072    void Unregister(RWebWindow &win);
0073 
0074    /// Show window in specified location, see Show() method for more details
0075    unsigned ShowWindow(RWebWindow &win, const RWebDisplayArgs &args);
0076 
0077    int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed = false, double tm = -1);
0078 
0079    std::string GetUrl(RWebWindow &win, bool remote = false, std::string *produced_key = nullptr);
0080 
0081    bool CreateServer(bool with_http = false);
0082 
0083    bool InformListener(const std::string &msg);
0084 
0085    static std::string GenerateKey(int keylen = 32);
0086 
0087 public:
0088    RWebWindowsManager();
0089 
0090    ~RWebWindowsManager();
0091 
0092    /// Returns THttpServer instance
0093    THttpServer *GetServer() const { return fServer.get(); }
0094 
0095    /// Returns http address of the server, empty string when not available
0096    std::string GetServerAddr() const { return fAddr; }
0097 
0098    /// Assign show callback which can catch window showing, used by RBrowser
0099    void SetShowCallback(WebWindowShowCallback_t func) { fShowCallback = func; }
0100 
0101    /// Assign show callback which can catch window showing, used by RBrowser
0102    void SetDeleteCallback(WebWindowDeleteCallback_t func) { fDeleteCallback = func; }
0103 
0104    static std::shared_ptr<RWebWindowsManager> &Instance();
0105 
0106    std::shared_ptr<RWebWindow> CreateWindow();
0107 
0108    void Terminate();
0109 
0110    static bool IsMainThrd();
0111    static void AssignMainThrd();
0112 
0113    static void SetLoopbackMode(bool on = true);
0114    static bool IsLoopbackMode();
0115 
0116    static void SetUseSessionKey(bool on = true);
0117    static void SetUseConnectionKey(bool on = true);
0118    static void SetSingleConnMode(bool on = true);
0119 
0120    static void AddServerLocation(const std::string &server_prefix, const std::string &files_path);
0121    static std::map<std::string, std::string> GetServerLocations();
0122    static void ClearServerLocations();
0123 };
0124 
0125 } // namespace ROOT
0126 
0127 #endif