Logo ROOT   6.14/05
Reference Guide
THttpWSHandler.h
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 20/10/2017
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_THttpWSHandler
13 #define ROOT_THttpWSHandler
14 
15 #include "TNamed.h"
16 #include "THttpCallArg.h"
17 
18 #include <vector>
19 #include <memory>
20 
21 class THttpWSEngine;
22 class THttpServer;
23 
24 class THttpWSHandler : public TNamed {
25 
26 friend class THttpServer;
27 
28 private:
29 
30  std::vector<std::shared_ptr<THttpWSEngine>> fEngines; ///<! list of active WS engines (connections)
31 
32  THttpWSEngine *FindEngine(UInt_t id) const;
33 
34  Bool_t HandleWS(std::shared_ptr<THttpCallArg> &arg);
35 
36  void RemoveEngine(THttpWSEngine *engine);
37 
38 protected:
39 
40  THttpWSHandler(const char *name, const char *title);
41 
42 public:
43  virtual ~THttpWSHandler();
44 
45  /// Provides content of default web page for registered web-socket handler
46  /// Can be content of HTML page or file name, where content should be taken
47  /// For instance, file:/home/user/test.htm or file:$jsrootsys/files/canvas.htm
48  /// If not specified, default index.htm page will be shown
49  /// Used by the webcanvas
50  virtual TString GetDefaultPageContent() { return ""; }
51 
52  /// Return kTRUE if websocket with given ID exists
53  Bool_t HasWS(UInt_t wsid) const { return FindEngine(wsid) != 0; }
54 
55  /// Returns current number of websocket connections
56  Int_t GetNumWS() const { return fEngines.size(); }
57 
58  UInt_t GetWS(Int_t num = 0) const;
59 
60  void CloseWS(UInt_t wsid);
61 
62  void SendWS(UInt_t wsid, const void *buf, int len);
63 
64  void SendHeaderWS(UInt_t wsid, const char *hdr, const void *buf, int len);
65 
66  void SendCharStarWS(UInt_t wsid, const char *str);
67 
68  virtual Bool_t ProcessWS(THttpCallArg *arg) = 0;
69 
70  ClassDef(THttpWSHandler, 0) // abstract class for handling websocket requests
71 };
72 
73 #endif
void SendWS(UInt_t wsid, const void *buf, int len)
Send binary data via given websocket id.
Bool_t HasWS(UInt_t wsid) const
Return kTRUE if websocket with given ID exists.
Bool_t HandleWS(std::shared_ptr< THttpCallArg > &arg)
Process request to websocket Different kind of requests coded into THttpCallArg::Method "WS_CONNECT" ...
virtual ~THttpWSHandler()
destructor Delete all websockets handles
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
THttpWSEngine * FindEngine(UInt_t id) const
Find websocket connection handle with given id.
#define ClassDef(name, id)
Definition: Rtypes.h:320
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Int_t GetNumWS() const
Returns current number of websocket connections.
void CloseWS(UInt_t wsid)
Close connection with given websocket id.
void SendCharStarWS(UInt_t wsid, const char *str)
Send string via given websocket id.
void SendHeaderWS(UInt_t wsid, const char *hdr, const void *buf, int len)
Send binary data with binary data via given websocket id.
UInt_t GetWS(Int_t num=0) const
Return websocket id with given sequential number Number of websockets return with GetNumWS() method...
virtual TString GetDefaultPageContent()
Provides content of default web page for registered web-socket handler Can be content of HTML page or...
unsigned int UInt_t
Definition: RtypesCore.h:42
std::vector< std::shared_ptr< THttpWSEngine > > fEngines
! list of active WS engines (connections)
void RemoveEngine(THttpWSEngine *engine)
Remove and destroy WS connection.
virtual Bool_t ProcessWS(THttpCallArg *arg)=0
THttpWSHandler(const char *name, const char *title)
THttpWSHandler.
char name[80]
Definition: TGX11.cxx:109