SNode.C
Loading...
Searching...
No Matches
web::http::client::tools::EventSource Class Referenceabstract

#include <EventSource.h>

Inheritance diagram for web::http::client::tools::EventSource:
Collaboration diagram for web::http::client::tools::EventSource:

Classes

struct  MessageEvent
 
struct  SharedState
 

Public Types

enum class  ReadyState : int { CONNECTING = 0 , OPEN = 1 , CLOSED = 2 }
 

Public Member Functions

virtual ~EventSource ()
 
EventSourceonMessage (std::function< void(const MessageEvent &)> messageCallback)
 
EventSourceaddEventListener (const std::string &key, std::function< void(const MessageEvent &)> eventListener)
 
EventSourceremoveEventListeners (const std::string &type)
 
EventSourceonOpen (std::function< void()> onOpen)
 
EventSourceonError (std::function< void()> onError)
 
EventSource::ReadyState readyState () const
 
const std::string & lastEventId () const
 
uint32_t retry () const
 
EventSourceretry (uint32_t retry)
 
virtual void close ()=0
 

Protected Member Functions

 EventSource ()
 

Protected Attributes

std::shared_ptr< SharedStatesharedState
 

Detailed Description

Definition at line 68 of file EventSource.h.

Member Enumeration Documentation

◆ ReadyState

Constructor & Destructor Documentation

◆ EventSource()

web::http::client::tools::EventSource::EventSource ( )
protected

Definition at line 50 of file EventSource.cpp.

51 : sharedState(std::make_shared<SharedState>()) {
52 }
std::shared_ptr< SharedState > sharedState

References sharedState.

◆ ~EventSource()

Member Function Documentation

◆ addEventListener()

EventSource * web::http::client::tools::EventSource::addEventListener ( const std::string &  key,
std::function< void(const MessageEvent &)>  eventListener 
)

Definition at line 63 of file EventSource.cpp.

63 {
64 sharedState->onEventListener[key].push_back(std::move(eventListener));
65
66 return this;
67 }

References web::http::client::tools::EventSource::SharedState::onEventListener, and sharedState.

◆ close()

◆ lastEventId()

const std::string & web::http::client::tools::EventSource::lastEventId ( ) const

Definition at line 91 of file EventSource.cpp.

91 {
92 return sharedState->lastId;
93 }

References web::http::client::tools::EventSource::SharedState::lastId, and sharedState.

◆ onError()

EventSource * web::http::client::tools::EventSource::onError ( std::function< void()>  onError)

Definition at line 81 of file EventSource.cpp.

81 {
82 sharedState->onErrorListener.push_back(std::move(onError));
83
84 return this;
85 }
EventSource * onError(std::function< void()> onError)

References web::http::client::tools::EventSource::SharedState::onErrorListener, and sharedState.

◆ onMessage()

EventSource * web::http::client::tools::EventSource::onMessage ( std::function< void(const MessageEvent &)>  messageCallback)

Definition at line 57 of file EventSource.cpp.

57 {
58 sharedState->onMessageListener.push_back(std::move(messageCallback));
59
60 return this;
61 }

References web::http::client::tools::EventSource::SharedState::onMessageListener, and sharedState.

◆ onOpen()

EventSource * web::http::client::tools::EventSource::onOpen ( std::function< void()>  onOpen)

Definition at line 75 of file EventSource.cpp.

75 {
76 sharedState->onOpenListener.push_back(std::move(onOpen));
77
78 return this;
79 }
EventSource * onOpen(std::function< void()> onOpen)

References web::http::client::tools::EventSource::SharedState::onOpenListener, and sharedState.

◆ readyState()

EventSource::ReadyState web::http::client::tools::EventSource::readyState ( ) const

Definition at line 87 of file EventSource.cpp.

87 {
88 return sharedState->ready;
89 }

References web::http::client::tools::EventSource::SharedState::ready, and sharedState.

◆ removeEventListeners()

EventSource * web::http::client::tools::EventSource::removeEventListeners ( const std::string &  type)

Definition at line 69 of file EventSource.cpp.

69 {
70 sharedState->onEventListener.erase(type);
71
72 return this;
73 }

References web::http::client::tools::EventSource::SharedState::onEventListener, and sharedState.

◆ retry() [1/2]

uint32_t web::http::client::tools::EventSource::retry ( ) const

Definition at line 95 of file EventSource.cpp.

95 {
96 return sharedState->retry;
97 }

References web::http::client::tools::EventSource::SharedState::retry, and sharedState.

◆ retry() [2/2]

EventSource * web::http::client::tools::EventSource::retry ( uint32_t  retry)

Definition at line 99 of file EventSource.cpp.

99 {
100 sharedState->retry = retry;
101
102 return this;
103 }

References web::http::client::tools::EventSource::SharedState::retry, and sharedState.

Member Data Documentation

◆ sharedState

std::shared_ptr<SharedState> web::http::client::tools::EventSource::sharedState
protected

The documentation for this class was generated from the following files: