Skip to content

Commit d9b7f90

Browse files
authored
Merge pull request #152 from c-jimenez/dev/rpc_server_optim
[websocket/rpc] Add server callback when connection fails + disable queues on disconnect to speed-up disconnection management
2 parents 777b9d4 + c2c9af2 commit d9b7f90

17 files changed

+129
-5
lines changed

examples/common/DefaultCentralSystemEventsHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ bool DefaultCentralSystemEventsHandler::acceptConnection(const char* ip_address)
6666
return true;
6767
}
6868

69+
/** @copydoc void ICentralSystemEventsHandler::clientFailedToConnect(const char*) */
70+
void DefaultCentralSystemEventsHandler::clientFailedToConnect(const char* ip_address)
71+
{
72+
cout << "Client [" << ip_address << "] failed to connect" << endl;
73+
}
74+
6975
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
7076
bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& chargepoint_id, const std::string& password)
7177
{

examples/common/DefaultCentralSystemEventsHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSy
4848
/** @copydoc bool ICentralSystemEventsHandler::acceptConnection(const char*) */
4949
bool acceptConnection(const char* ip_address) override;
5050

51+
/** @copydoc void ICentralSystemEventsHandler::clientFailedToConnect(const char*) */
52+
void clientFailedToConnect(const char* ip_address) override;
53+
5154
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
5255
bool checkCredentials(const std::string& chargepoint_id, const std::string& password) override;
5356

examples/common/DefaultLocalControllerEventsHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ bool DefaultLocalControllerEventsHandler::acceptConnection(const char* ip_addres
4848
return true;
4949
}
5050

51+
/** @copydoc void ILocalControllerEventsHandler::clientFailedToConnect(const char*) */
52+
void DefaultLocalControllerEventsHandler::clientFailedToConnect(const char* ip_address)
53+
{
54+
cout << "Client [" << ip_address << "] failed to connect" << endl;
55+
}
56+
5157
/** @copydoc bool ILocalControllerEventsHandler::checkCredentials(const std::string&, const std::string&) */
5258
bool DefaultLocalControllerEventsHandler::checkCredentials(const std::string& chargepoint_id, const std::string& password)
5359
{

examples/common/DefaultLocalControllerEventsHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class DefaultLocalControllerEventsHandler : public ocpp::localcontroller::ILocal
4646
/** @copydoc bool ILocalControllerEventsHandler::acceptConnection(const char*) */
4747
bool acceptConnection(const char* ip_address) override;
4848

49+
/** @copydoc void ILocalControllerEventsHandler::clientFailedToConnect(const char*) */
50+
void clientFailedToConnect(const char* ip_address) override;
51+
4952
/** @copydoc bool ILocalControllerEventsHandler::checkCredentials(const std::string&, const std::string&) */
5053
bool checkCredentials(const std::string& chargepoint_id, const std::string& password) override;
5154

src/centralsystem/CentralSystem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ void CentralSystem::rpcClientConnected(const std::string& chargepoint_id, std::s
300300
m_events_handler.chargePointConnected(chargepoint);
301301
}
302302

303+
/** @copydoc void RpcServer::IListener::rpcClientFailedToConnect(const char*) */
304+
void CentralSystem::rpcClientFailedToConnect(const char* ip_address)
305+
{
306+
// Notify failure => no additional processing is done here
307+
// to keep this callback has fast as possible
308+
return m_events_handler.clientFailedToConnect(ip_address);
309+
}
310+
303311
/** @copydoc void RpcServer::IListener::rpcServerError() */
304312
void CentralSystem::rpcServerError()
305313
{

src/centralsystem/CentralSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class CentralSystem : public ICentralSystem, public ocpp::rpc::RpcServer::IListe
7878
/** @copydoc void RpcServer::IListener::rpcClientConnected(const std::string&, std::shared_ptr<Client>) */
7979
void rpcClientConnected(const std::string& chargepoint_id, std::shared_ptr<ocpp::rpc::RpcServer::Client> client) override;
8080

81+
/** @copydoc void RpcServer::IListener::rpcClientFailedToConnect(const char*) */
82+
void rpcClientFailedToConnect(const char* ip_address) override;
83+
8184
/** @copydoc void RpcServer::IListener::rpcServerError() */
8285
void rpcServerError() override;
8386

src/centralsystem/interface/ICentralSystemEventsHandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class ICentralSystemEventsHandler
4040
*/
4141
virtual bool acceptConnection(const char* ip_address) = 0;
4242

43+
/**
44+
* @brief Called when connection fails to established
45+
* @param ip_address IP address of the client
46+
*/
47+
virtual void clientFailedToConnect(const char* ip_address) = 0;
48+
4349
/**
4450
* @brief Called to check the charge point credentials for HTTP basic authentication
4551
* @param chargepoint_id Charge Point identifier

src/localcontroller/LocalController.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ void LocalController::rpcClientConnected(const std::string& chargepoint_id, std:
313313
m_events_handler.chargePointConnected(chargepoint);
314314
}
315315

316+
/** @copydoc void RpcServer::IListener::rpcClientFailedToConnect(const char*) */
317+
void LocalController::rpcClientFailedToConnect(const char* ip_address)
318+
{
319+
// Notify failure => no additional processing is done here
320+
// to keep this callback has fast as possible
321+
return m_events_handler.clientFailedToConnect(ip_address);
322+
}
323+
316324
/** @copydoc void RpcServer::IListener::rpcServerError() */
317325
void LocalController::rpcServerError()
318326
{

src/localcontroller/LocalController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class LocalController : public ILocalController, public ocpp::rpc::RpcServer::IL
7878
/** @copydoc void RpcServer::IListener::rpcClientConnected(const std::string&, std::shared_ptr<Client>) */
7979
void rpcClientConnected(const std::string& chargepoint_id, std::shared_ptr<ocpp::rpc::RpcServer::Client> client) override;
8080

81+
/** @copydoc void RpcServer::IListener::rpcClientFailedToConnect(const char*) */
82+
void rpcClientFailedToConnect(const char* ip_address) override;
83+
8184
/** @copydoc void RpcServer::IListener::rpcServerError() */
8285
void rpcServerError() override;
8386

src/localcontroller/interface/ILocalControllerEventsHandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class ILocalControllerEventsHandler
4040
*/
4141
virtual bool acceptConnection(const char* ip_address) = 0;
4242

43+
/**
44+
* @brief Called when connection fails to established
45+
* @param ip_address IP address of the client
46+
*/
47+
virtual void clientFailedToConnect(const char* ip_address) = 0;
48+
4349
/**
4450
* @brief Called to check the charge point credentials for HTTP basic authentication
4551
* @param chargepoint_id Charge Point identifier

0 commit comments

Comments
 (0)