Kurlyk
Loading...
Searching...
No Matches
kurlyk::IWebSocketClient Class Referenceabstract

Interface for a WebSocket client, providing methods for connection management, configuration, and event handling. More...

#include <IWebSocketClient.hpp>

Inheritance diagram for kurlyk::IWebSocketClient:
kurlyk::IWebSocketSender kurlyk::BaseWebSocketClient kurlyk::SimpleWebSocketClientAdapter

Public Member Functions

 IWebSocketClient ()=default
 Default constructor.
 
virtual ~IWebSocketClient ()=default
 Virtual destructor for safe cleanup in derived classes.
 
virtual std::function< void(std::unique_ptr< WebSocketEventData >)> & event_handler ()=0
 Accessor for the event handler function.
 
virtual std::function< void()> & notify_handler ()=0
 Accesses the notification handler for WebSocket events.
 
virtual void set_config (std::unique_ptr< WebSocketConfig > config, std::function< void(bool)> callback)=0
 Sets the configuration for the WebSocket client.
 
virtual void connect (std::function< void(bool)> callback)=0
 Initiates a connection to the WebSocket server.
 
virtual void disconnect (std::function< void(bool)> callback)=0
 Closes the connection to the WebSocket server.
 
virtual bool is_running () const =0
 Checks if the WebSocket client is actively running.
 
virtual std::list< std::unique_ptr< WebSocketEventData > > receive_events () const =0
 Retrieves all pending WebSocket events in a batch.
 
virtual std::unique_ptr< WebSocketEventDatareceive_event () const =0
 Retrieves the next available WebSocket event, if any.
 
virtual void process ()=0
 Processes internal operations such as event handling and state updates.
 
virtual void shutdown ()=0
 Shuts down the WebSocket client, disconnecting and clearing all pending events.
 
- Public Member Functions inherited from kurlyk::IWebSocketSender
 IWebSocketSender ()=default
 Default constructor for IWebSocketSender.
 
virtual ~IWebSocketSender ()=default
 Virtual destructor for IWebSocketSender.
 
virtual std::string get_http_version ()=0
 Retrieves the HTTP version used in the WebSocket connection.
 
virtual Headers get_headers ()=0
 Retrieves the headers associated with the WebSocket connection.
 
virtual std::string get_remote_endpoint ()=0
 Retrieves the remote endpoint information.
 
virtual bool send_message (const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)=0
 Sends a WebSocket message.
 
virtual bool send_close (int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)=0
 Sends a close request to the WebSocket server.
 
virtual bool is_connected () const =0
 Checks if the WebSocket connection is currently active.
 

Detailed Description

Interface for a WebSocket client, providing methods for connection management, configuration, and event handling.

Definition at line 12 of file IWebSocketClient.hpp.

Constructor & Destructor Documentation

◆ IWebSocketClient()

kurlyk::IWebSocketClient::IWebSocketClient ( )
default

Default constructor.

◆ ~IWebSocketClient()

virtual kurlyk::IWebSocketClient::~IWebSocketClient ( )
virtualdefault

Virtual destructor for safe cleanup in derived classes.

Member Function Documentation

◆ connect()

virtual void kurlyk::IWebSocketClient::connect ( std::function< void(bool)> callback)
pure virtual

Initiates a connection to the WebSocket server.

Parameters
callbackCallback function to be executed upon connection completion, receiving a success status.

Implemented in kurlyk::BaseWebSocketClient.

◆ disconnect()

virtual void kurlyk::IWebSocketClient::disconnect ( std::function< void(bool)> callback)
pure virtual

Closes the connection to the WebSocket server.

Parameters
callbackCallback function to be executed upon disconnection completion, receiving a success status.

Implemented in kurlyk::BaseWebSocketClient.

◆ event_handler()

virtual std::function< void(std::unique_ptr< WebSocketEventData >)> & kurlyk::IWebSocketClient::event_handler ( )
pure virtual

Accessor for the event handler function.

This method provides access to the event handler function used for handling WebSocket events. The returned reference allows getting or setting the function that will be called when a WebSocket event occurs.

Returns
A reference to a std::function<void(std::unique_ptr<WebSocketEventData>)> representing the event handler function.

Implemented in kurlyk::BaseWebSocketClient.

◆ is_running()

virtual bool kurlyk::IWebSocketClient::is_running ( ) const
pure virtual

Checks if the WebSocket client is actively running.

Returns
True if the client is running, otherwise false.

Implemented in kurlyk::BaseWebSocketClient.

◆ notify_handler()

virtual std::function< void()> & kurlyk::IWebSocketClient::notify_handler ( )
pure virtual

Accesses the notification handler for WebSocket events.

The notification handler triggers the network worker to process WebSocket events by notifying it that an event has occurred, typically through NetworkWorker::get_instance().notify().

Returns
A reference to the notification handler callback function.

Implemented in kurlyk::BaseWebSocketClient.

◆ process()

virtual void kurlyk::IWebSocketClient::process ( )
pure virtual

Processes internal operations such as event handling and state updates.

This function should be called periodically to ensure timely processing of internal state changes, events, and messages.

Implemented in kurlyk::BaseWebSocketClient.

◆ receive_event()

virtual std::unique_ptr< WebSocketEventData > kurlyk::IWebSocketClient::receive_event ( ) const
pure virtual

Retrieves the next available WebSocket event, if any.

This method supports event-by-event processing by returning the next event in the queue.

Returns
A unique pointer to a WebSocketEventData object representing an event, or nullptr if no events are available.

Implemented in kurlyk::BaseWebSocketClient.

◆ receive_events()

virtual std::list< std::unique_ptr< WebSocketEventData > > kurlyk::IWebSocketClient::receive_events ( ) const
pure virtual

Retrieves all pending WebSocket events in a batch.

This method enables efficient processing of multiple accumulated events at once.

Returns
A list of unique pointers to WebSocketEventData objects representing the events.

Implemented in kurlyk::BaseWebSocketClient.

◆ set_config()

virtual void kurlyk::IWebSocketClient::set_config ( std::unique_ptr< WebSocketConfig > config,
std::function< void(bool)> callback )
pure virtual

Sets the configuration for the WebSocket client.

Parameters
configA unique pointer to the WebSocket configuration object.
callbackCallback function to be executed upon configuration completion.

Implemented in kurlyk::BaseWebSocketClient.

◆ shutdown()

virtual void kurlyk::IWebSocketClient::shutdown ( )
pure virtual

Shuts down the WebSocket client, disconnecting and clearing all pending events.

Initiates a disconnect event and processes any remaining events until the client stops running.

Implemented in kurlyk::BaseWebSocketClient.


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