Logo ROOT   6.18/05
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::condition_variable fCond; ///<! condition used to sync with sending thread
37
38 std::mutex fDataMutex; ///<! protects data submitted for send operation
39 enum { kNone, kData, kHeader, kText } fKind{kNone}; ///<! kind of operation
40 bool fDoingSend{false}; ///<! doing send operation in other thread
41 std::string fData; ///<! data (binary or text)
42 std::string fHdr; ///<! header
43
44protected:
45 THttpWSEngine() = default;
46
47 /// Indicate if engine require extra thread to complete postponed thread operation
48 virtual Bool_t SupportSendThrd() const { return kFALSE; }
49
50 /// One always can send data to websocket - as long as previous send operation completed
51 virtual Bool_t CanSendDirectly() { return kTRUE; }
52
53public:
54 virtual ~THttpWSEngine() = default;
55
56 virtual UInt_t GetId() const = 0;
57
58 virtual void ClearHandle(Bool_t) = 0;
59
60 virtual void Send(const void *buf, int len) = 0;
61
62 virtual void SendHeader(const char *hdr, const void *buf, int len) = 0;
63
64 virtual void SendCharStar(const char *str);
65
66 virtual Bool_t PreProcess(std::shared_ptr<THttpCallArg> &arg);
67
68 virtual void PostProcess(std::shared_ptr<THttpCallArg> &arg);
69};
70
71#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:36
bool fDoingSend
! doing send operation in other thread
Definition: THttpWSEngine.h:40
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:42
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
bool fDisabled
! true shortly before cleanup, set under locked fMutex from WSHandler
Definition: THttpWSEngine.h:32
enum THttpWSEngine::@151 kNone
! kind of operation
virtual void SendHeader(const char *hdr, const void *buf, int len)=0
virtual Bool_t CanSendDirectly()
One always can send data to websocket - as long as previous send operation completed.
Definition: THttpWSEngine.h:51
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:48
std::mutex fDataMutex
! protects data submitted for send operation
Definition: THttpWSEngine.h:38
virtual void Send(const void *buf, int len)=0
std::string fData
! data (binary or text)
Definition: THttpWSEngine.h:41
virtual ~THttpWSEngine()=default
virtual void ClearHandle(Bool_t)=0