Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RWebWindowWSHandler.hxx
Go to the documentation of this file.
1 /// \file RWebWindowWSHandler.hxx
2 /// \ingroup WebGui ROOT7
3 /// \author Sergey Linev <s.linev@gsi.de>
4 /// \date 2018-08-20
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RWebWindowWSHandler
17 #define ROOT7_RWebWindowWSHandler
18 
19 #include "THttpWSHandler.h"
20 #include "TEnv.h"
21 
22 #include <ROOT/RWebWindow.hxx>
23 
24 #include <string>
25 
26 using namespace std::string_literals;
27 
28 namespace ROOT {
29 namespace Experimental {
30 
31 /// just wrapper to deliver websockets call-backs to the RWebWindow class
32 
33 class RWebWindowWSHandler : public THttpWSHandler {
34 
35 protected:
36  Bool_t ProcessBatchHolder(std::shared_ptr<THttpCallArg> &arg) override
37  {
38  return IsDisabled() ? kFALSE : fWindow.ProcessBatchHolder(arg);
39  }
40 
41  void VerifyDefaultPageContent(std::shared_ptr<THttpCallArg> &arg) override
42  {
43  auto version = fWindow.GetClientVersion();
44  if (!version.empty()) {
45  std::string search = "jsrootsys/scripts/JSRootCore."s;
46  std::string replace = version + "/jsrootsys/scripts/JSRootCore."s;
47  // replace link to JSROOT main script to emulate new version
48  arg->ReplaceAllinContent(search, replace, true);
49  arg->AddNoCacheHeader();
50  }
51 
52  std::string more_args;
53  const char *ui5source = gEnv->GetValue("WebGui.openui5src","");
54  if (ui5source && *ui5source)
55  more_args.append("openui5src: \""s + ui5source + "\","s);
56  const char *ui5libs = gEnv->GetValue("WebGui.openui5libs","");
57  if (ui5libs && *ui5libs)
58  more_args.append("openui5libs: \""s + ui5libs + "\","s);
59  const char *ui5theme = gEnv->GetValue("WebGui.openui5theme","");
60  if (ui5theme && *ui5theme)
61  more_args.append("openui5theme: \""s + ui5theme + "\","s);
62  auto user_args = fWindow.GetUserArgs();
63  if (!user_args.empty())
64  more_args = "user_args: "s + user_args + ","s;
65 
66  if (!more_args.empty()) {
67  std::string search = "JSROOT.ConnectWebWindow({"s;
68  std::string replace = search + more_args;
69  arg->ReplaceAllinContent(search, replace, true);
70  arg->AddNoCacheHeader();
71  }
72  }
73 
74 public:
75  RWebWindow &fWindow; ///<! window reference
76 
77  /// constructor
78  RWebWindowWSHandler(RWebWindow &wind, const char *name)
79  : THttpWSHandler(name, "RWebWindow websockets handler", kFALSE), fWindow(wind)
80  {
81  }
82 
83  virtual ~RWebWindowWSHandler() = default;
84 
85  /// returns content of default web-page
86  /// THttpWSHandler interface
87  TString GetDefaultPageContent() override { return IsDisabled() ? "" : fWindow.fDefaultPage.c_str(); }
88 
89  /// returns true when window allowed to serve files relative to default page
90  Bool_t CanServeFiles() const override { return !IsDisabled(); }
91 
92  /// Process websocket request - called from THttpServer thread
93  /// THttpWSHandler interface
94  Bool_t ProcessWS(THttpCallArg *arg) override { return arg && !IsDisabled() ? fWindow.ProcessWS(*arg) : kFALSE; }
95 
96  /// Allow processing of WS actions in arbitrary thread
97  Bool_t AllowMTProcess() const override { return fWindow.fProcessMT; }
98 
99  /// Allows usage of special threads for send operations
100  Bool_t AllowMTSend() const override { return fWindow.fSendMT; }
101 
102  /// React on completion of multi-threaded send operation
103  void CompleteWSSend(UInt_t wsid) override { if (!IsDisabled()) fWindow.CompleteWSSend(wsid); }
104 };
105 
106 } // namespace Experimental
107 } // namespace ROOT
108 
109 #endif