ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ocpp::WebsocketBase Class Referenceabstract

contains a websocket abstraction More...

#include <websocket_base.hpp>

Inheritance diagram for ocpp::WebsocketBase:
ocpp::WebsocketLibwebsockets

Public Member Functions

 WebsocketBase ()
 Creates a new WebsocketBase object. The connection_options must be initialised with set_connection_options()
 
virtual bool start_connecting ()=0
 Starts the connection attempts. It will init the websocket processing thread. More...
 
virtual void set_connection_options (const WebsocketConnectionOptions &connection_options)=0
 sets this connection_options to the given connection_options and resets the connection_attempts More...
 
void set_connection_options_base (const WebsocketConnectionOptions &connection_options)
 
virtual void reconnect (long delay)=0
 reconnect the websocket after the delay More...
 
void disconnect (const WebsocketCloseReason code)
 disconnect the websocket
 
bool is_connected ()
 indicates if the websocket is connected
 
virtual void close (const WebsocketCloseReason code, const std::string &reason)=0
 closes the websocket More...
 
void register_connected_callback (const std::function< void(OcppProtocolVersion protocol)> &callback)
 register a callback that is called when the websocket is connected successfully
 
void register_disconnected_callback (const std::function< void()> &callback)
 register a callback that is called when the websocket connection is disconnected
 
void register_stopped_connecting_callback (const std::function< void(const WebsocketCloseReason reason)> &callback)
 register a callback that is called when the websocket connection has been closed and will not attempt to reconnect
 
void register_message_callback (const std::function< void(const std::string &message)> &callback)
 register a callback that is called when the websocket receives a message
 
void register_connection_failed_callback (const std::function< void(ConnectionFailedReason)> &callback)
 register a callback that is called when the websocket could not connect with a specific reason
 
virtual bool send (const std::string &message)=0
 send a message over the websocket More...
 
void set_websocket_ping_interval (int32_t interval_s)
 starts a timer that sends a websocket ping at the given interval_s
 
void set_authorization_key (const std::string &authorization_key)
 set the authorization_key of the connection_options
 

Protected Member Functions

bool initialized ()
 Indicates if the required callbacks are registered. More...
 
std::optional< std::string > getAuthorizationHeader ()
 getter for authorization header for connection with basic authentication
 
void log_on_fail (const std::error_code &ec, const boost::system::error_code &transport_ec, const int http_status)
 Logs websocket connection error.
 
long get_reconnect_interval ()
 Calculates and returns the reconnect interval based on int retry_backoff_random_range_s, retry_backoff_repeat_times, int retry_backoff_wait_minimum_s of the WebsocketConnectionOptions.
 
void cancel_reconnect_timer ()
 
virtual void ping ()=0
 send a websocket ping More...
 
void on_pong_timeout (std::string msg)
 Called when a websocket pong timeout is received.
 

Protected Attributes

std::atomic_bool m_is_connected
 
WebsocketConnectionOptions connection_options
 
std::function< void(OcppProtocolVersion protocol)> connected_callback
 
std::function< void()> disconnected_callback
 
std::function< void(const WebsocketCloseReason reason)> stopped_connecting_callback
 
std::function< void(const std::string &message)> message_callback
 
std::function< void(ConnectionFailedReason)> connection_failed_callback
 
std::shared_ptr< boost::asio::steady_timer > reconnect_timer
 
std::unique_ptr< Everest::SteadyTimer > ping_timer
 
std::mutex reconnect_mutex
 
std::mutex connection_mutex
 
std::atomic_int reconnect_backoff_ms
 
std::atomic_int connection_attempts
 
std::atomic_bool shutting_down
 
std::atomic_bool reconnecting
 

Detailed Description

contains a websocket abstraction

Member Function Documentation

◆ close()

virtual void ocpp::WebsocketBase::close ( const WebsocketCloseReason  code,
const std::string &  reason 
)
pure virtual

closes the websocket

Implemented in ocpp::WebsocketLibwebsockets.

◆ initialized()

bool ocpp::WebsocketBase::initialized ( )
protected

Indicates if the required callbacks are registered.

Returns
true if the websocket is properly initialized

◆ ping()

virtual void ocpp::WebsocketBase::ping ( )
protectedpure virtual

send a websocket ping

Implemented in ocpp::WebsocketLibwebsockets.

◆ reconnect()

virtual void ocpp::WebsocketBase::reconnect ( long  delay)
pure virtual

reconnect the websocket after the delay

Implemented in ocpp::WebsocketLibwebsockets.

◆ send()

virtual bool ocpp::WebsocketBase::send ( const std::string &  message)
pure virtual

send a message over the websocket

Returns
true if the message was sent successfully

Implemented in ocpp::WebsocketLibwebsockets.

◆ set_connection_options()

virtual void ocpp::WebsocketBase::set_connection_options ( const WebsocketConnectionOptions connection_options)
pure virtual

sets this connection_options to the given connection_options and resets the connection_attempts

Implemented in ocpp::WebsocketLibwebsockets.

◆ start_connecting()

virtual bool ocpp::WebsocketBase::start_connecting ( )
pure virtual

Starts the connection attempts. It will init the websocket processing thread.

Returns
true if the websocket is successfully initialized, false otherwise. Does not wait for a successful connection

Implemented in ocpp::WebsocketLibwebsockets.


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