File indexing completed on 2025-01-18 10:10:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
0033
0034 using WebWindowShowCallback_t = std::function<bool(RWebWindow &, const RWebDisplayArgs &)>;
0035
0036 class RWebWindowsManager {
0037
0038 friend class RWebWindow;
0039
0040 private:
0041 std::unique_ptr<THttpServer> fServer;
0042 std::string fAddr;
0043 std::string fSessionKey;
0044 bool fUseSessionKey{false};
0045 std::recursive_mutex fMutex;
0046 unsigned fIdCnt{0};
0047 bool fUseHttpThrd{false};
0048 bool fUseSenderThreads{false};
0049 float fLaunchTmout{30.};
0050 bool fExternalProcessEvents{false};
0051 std::unique_ptr<TExec> fAssgnExec;
0052 WebWindowShowCallback_t fShowCallback;
0053
0054
0055 bool IsUseHttpThread() const { return fUseHttpThrd; }
0056
0057
0058 bool IsUseSenderThreads() const { return fUseSenderThreads; }
0059
0060
0061 float GetLaunchTmout() const { return fLaunchTmout; }
0062
0063 void Unregister(RWebWindow &win);
0064
0065
0066 unsigned ShowWindow(RWebWindow &win, const RWebDisplayArgs &args);
0067
0068 int WaitFor(RWebWindow &win, WebWindowWaitFunc_t check, bool timed = false, double tm = -1);
0069
0070 std::string GetUrl(RWebWindow &win, bool remote = false, std::string *produced_key = nullptr);
0071
0072 bool CreateServer(bool with_http = false);
0073
0074 bool InformListener(const std::string &msg);
0075
0076 static std::string GenerateKey(int keylen = 32);
0077
0078 public:
0079 RWebWindowsManager();
0080
0081 ~RWebWindowsManager();
0082
0083
0084 THttpServer *GetServer() const { return fServer.get(); }
0085
0086
0087 std::string GetServerAddr() const { return fAddr; }
0088
0089
0090 void SetShowCallback(WebWindowShowCallback_t func) { fShowCallback = func; }
0091
0092 static std::shared_ptr<RWebWindowsManager> &Instance();
0093
0094 std::shared_ptr<RWebWindow> CreateWindow();
0095
0096 void Terminate();
0097
0098 static bool IsMainThrd();
0099 static void AssignMainThrd();
0100
0101 static void SetLoopbackMode(bool on = true);
0102 static bool IsLoopbackMode();
0103
0104 static void SetUseSessionKey(bool on = true);
0105 static void SetUseConnectionKey(bool on = true);
0106 };
0107
0108 }
0109
0110 #endif