ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
Public Member Functions | List of all members
ocpp::WebsocketLibwebsockets Class Referencefinal

Experimental libwebsockets TLS connection. More...

#include <websocket_libwebsockets.hpp>

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

Public Member Functions

 WebsocketLibwebsockets (const WebsocketConnectionOptions &connection_options, std::shared_ptr< EvseSecurity > evse_security)
 Creates a new Websocket object with the providede connection_options.
 
void set_connection_options (const WebsocketConnectionOptions &connection_options) override
 sets this connection_options to the given connection_options and resets the connection_attempts More...
 
bool start_connecting () override
 Starts the connection attempts. It will init the websocket processing thread. More...
 
void reconnect (long delay) override
 reconnect the websocket after the delay More...
 
void close (const WebsocketCloseReason code, const std::string &reason) override
 closes the websocket More...
 
bool send (const std::string &message) override
 send a message over the websocket More...
 
void ping () override
 send a websocket ping More...
 
bool is_trying_to_connect ()
 Indicates if the websocket has a valid connection data and is trying to connect/reconnect internally even if for the moment it might not be connected. More...
 
int process_callback (void *wsi_ptr, int callback_reason, void *user, void *in, size_t len)
 
- Public Member Functions inherited from ocpp::WebsocketBase
 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
 

Additional Inherited Members

- Protected Member Functions inherited from ocpp::WebsocketBase
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 inherited from ocpp::WebsocketBase
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

Experimental libwebsockets TLS connection.

Member Function Documentation

◆ close()

void ocpp::WebsocketLibwebsockets::close ( const WebsocketCloseReason  code,
const std::string &  reason 
)
overridevirtual

closes the websocket

Implements ocpp::WebsocketBase.

◆ is_trying_to_connect()

bool ocpp::WebsocketLibwebsockets::is_trying_to_connect ( )

Indicates if the websocket has a valid connection data and is trying to connect/reconnect internally even if for the moment it might not be connected.

Returns
True if the websocket is connected or trying to connect, false otherwise

◆ ping()

void ocpp::WebsocketLibwebsockets::ping ( )
overridevirtual

send a websocket ping

Implements ocpp::WebsocketBase.

◆ reconnect()

void ocpp::WebsocketLibwebsockets::reconnect ( long  delay)
overridevirtual

reconnect the websocket after the delay

Implements ocpp::WebsocketBase.

◆ send()

bool ocpp::WebsocketLibwebsockets::send ( const std::string &  message)
overridevirtual

send a message over the websocket

Returns
true if the message was sent successfully

Implements ocpp::WebsocketBase.

◆ set_connection_options()

void ocpp::WebsocketLibwebsockets::set_connection_options ( const WebsocketConnectionOptions connection_options)
overridevirtual

sets this connection_options to the given connection_options and resets the connection_attempts

Implements ocpp::WebsocketBase.

◆ start_connecting()

bool ocpp::WebsocketLibwebsockets::start_connecting ( )
overridevirtual

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

Implements ocpp::WebsocketBase.


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