Logo ROOT   6.16/01
Reference Guide
THttpWSEngine.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_THttpWSEngine
13#define ROOT_THttpWSEngine
14
15#include "Rtypes.h"
16
17#include "THttpCallArg.h"
18
19#include <mutex>
20#include <thread>
21#include <string>
22#include <condition_variable>
23
24class THttpWSHandler;
25
27
28private:
29 friend class THttpWSHandler;
30
31 bool fMTSend{false}; ///<! true when send operation runs, set under locked fMutex from WSHandler
32 bool fDisabled{false}; ///<! true shortly before cleanup, set under locked fMutex from WSHandler
33
34 std::thread fSendThrd; ///<! dedicated thread for all send operations
35 bool fHasSendThrd{false}; ///<! if thread was started one have to call join method for it
36 std::mutex fCondMutex; ///<! mutex used to access condition
37 std::condition_variable fCond; ///<! condition used to sync with sending thread
38
39 std::mutex fDataMutex; ///<! protects data submitted for send operation
40 enum { kNone, kData, kHeader, kText } fKind{kNone}; ///<! kind of operation
41 bool fDoingSend{false}; ///<! doing send operation in other thread
42 std::string fData; ///<! data (binary or text)
43 std::string fHdr; ///<! header
44
45protected:
46 THttpWSEngine() = default;
47
48 /// Indicate if engine require extra thread to complete postponed thread operation
49 virtual Bool_t SupportSendThrd() const { return kFALSE; }
50
51 /// One always can send data to websocket - as long as previous send operation completed
52 virtual Bool_t CanSendDirectly() { return kTRUE; }
53
54public:
55 virtual ~THttpWSEngine() = default;
56
57 virtual UInt_t GetId() const = 0;
58
59 virtual void ClearHandle(Bool_t) = 0;
60
61 virtual void Send(const void *buf, int len) = 0;
62
63 virtual void SendHeader(const char *hdr, const void *buf, int len) = 0;
64
65 virtual void SendCharStar(const char *str);
66
67 virtual Bool_t PreProcess(std::shared_ptr<THttpCallArg> &arg);
68
69 virtual void PostProcess(std::shared_ptr<THttpCallArg> &arg);
70};
71
72#endif
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
bool fMTSend
! true when send operation runs, set under locked fMutex from WSHandler
Definition: THttpWSEngine.h:31
virtual Bool_t PreProcess(std::shared_ptr< THttpCallArg > &arg)
Method should be invoked before processing data coming from websocket If method returns kTRUE,...
std::condition_variable fCond
! condition used to sync with sending thread
Definition: THttpWSEngine.h:37
bool fDoingSend
! doing send operation in other thread
Definition: THttpWSEngine.h:41
virtual void SendCharStar(const char *str)
Envelope for sending string via the websocket.
virtual UInt_t GetId() const =0
std::string fHdr
! header
Definition: THttpWSEngine.h:43
THttpWSEngine()=default
std::thread fSendThrd
! dedicated thread for all send operations
Definition: THttpWSEngine.h:34
bool fHasSendThrd
! if thread was started one have to call join method for it
Definition: THttpWSEngine.h:35
std::mutex fCondMutex
! mutex used to access condition
Definition: THttpWSEngine.h:36
bool fDisabled
! true shortly before cleanup, set under locked fMutex from WSHandler
Definition: THttpWSEngine.h:32
virtual void SendHeader(const char *hdr, const void *buf, int len)=0
enum THttpWSEngine::@144 kNone
! kind of operation
virtual Bool_t CanSendDirectly()
One always can send data to websocket - as long as previous send operation completed.
Definition: THttpWSEngine.h:52
virtual void PostProcess(std::shared_ptr< THttpCallArg > &arg)
Method invoked after user process data received via websocket.
virtual Bool_t SupportSendThrd() const
Indicate if engine require extra thread to complete postponed thread operation.
Definition: THttpWSEngine.h:49
std::mutex fDataMutex
! protects data submitted for send operation
Definition: THttpWSEngine.h:39
virtual void Send(const void *buf, int len)=0
std::string fData
! data (binary or text)
Definition: THttpWSEngine.h:42
virtual ~THttpWSEngine()=default
virtual void ClearHandle(Bool_t)=0