Skip to content

Commit 83c4712

Browse files
authored
Merge pull request #100 from c-jimenez/dev/improve_websockets
Improve websockets management
2 parents 7bb74ed + cced923 commit 83c4712

21 files changed

+334
-30
lines changed

CMakeLists_Options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ if(NOT DEFINED LOG_LEVEL)
88
endif()
99
add_compile_definitions(LOG_LEVEL=${LOG_LEVEL})
1010

11+
# Logger
12+
option(EXTERNAL_LOGGER "Use an external logger" OFF)
13+
if(EXTERNAL_LOGGER)
14+
add_compile_definitions(EXTERNAL_LOGGER=1)
15+
endif()
16+
1117
# Static library
1218
option(BUILD_STATIC_LIBRARY "Build Open OCPP as a static library" ON)
1319

examples/common/DefaultCentralSystemEventsHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ DefaultCentralSystemEventsHandler::~DefaultCentralSystemEventsHandler() { }
5454

5555
// ICentralSystemEventsHandler interface
5656

57+
/** @copydoc bool ICentralSystemEventsHandler::acceptConnection(const char*) */
58+
bool DefaultCentralSystemEventsHandler::acceptConnection(const char* ip_address)
59+
{
60+
cout << "Accept connection from [" << ip_address << "]" << endl;
61+
return true;
62+
}
63+
5764
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
5865
bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& chargepoint_id, const std::string& password)
5966
{

examples/common/DefaultCentralSystemEventsHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSy
4545

4646
// ICentralSystemEventsHandler interface
4747

48+
/** @copydoc bool ICentralSystemEventsHandler::acceptConnection(const char*) */
49+
bool acceptConnection(const char* ip_address) override;
50+
4851
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
4952
bool checkCredentials(const std::string& chargepoint_id, const std::string& password) override;
5053

examples/common/DefaultLocalControllerEventsHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ DefaultLocalControllerEventsHandler::~DefaultLocalControllerEventsHandler() { }
4141

4242
// ILocalControllerEventsHandler interface
4343

44+
/** @copydoc bool ILocalControllerEventsHandler::acceptConnection(const char*) */
45+
bool DefaultLocalControllerEventsHandler::acceptConnection(const char* ip_address)
46+
{
47+
cout << "Accept connection from [" << ip_address << "]" << endl;
48+
return true;
49+
}
50+
4451
/** @copydoc bool ILocalControllerEventsHandler::checkCredentials(const std::string&, const std::string&) */
4552
bool DefaultLocalControllerEventsHandler::checkCredentials(const std::string& chargepoint_id, const std::string& password)
4653
{

examples/common/DefaultLocalControllerEventsHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class DefaultLocalControllerEventsHandler : public ocpp::localcontroller::ILocal
4343

4444
// ILocalControllerEventsHandler interface
4545

46+
/** @copydoc bool ILocalControllerEventsHandler::acceptConnection(const char*) */
47+
bool acceptConnection(const char* ip_address) override;
48+
4649
/** @copydoc bool ILocalControllerEventsHandler::checkCredentials(const std::string&, const std::string&) */
4750
bool checkCredentials(const std::string& chargepoint_id, const std::string& password) override;
4851

src/centralsystem/CentralSystem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ bool CentralSystem::stop()
240240
return ret;
241241
}
242242

243+
/** @copydoc bool RpcServer::IListener::rpcAcceptConnection(const char*) */
244+
bool CentralSystem::rpcAcceptConnection(const char* ip_address)
245+
{
246+
// Notify connection => no additional processing is done here
247+
// to keep this callback has fast as possible
248+
return m_events_handler.acceptConnection(ip_address);
249+
}
250+
243251
/** @copydoc bool RpcServer::IListener::rpcCheckCredentials(const std::string&, const std::string&, const std::string&) */
244252
bool CentralSystem::rpcCheckCredentials(const std::string& chargepoint_id, const std::string& user, const std::string& password)
245253
{

src/centralsystem/CentralSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class CentralSystem : public ICentralSystem, public ocpp::rpc::RpcServer::IListe
6969

7070
// RpcServer::IListener interface
7171

72+
/** @copydoc bool RpcServer::IListener::rpcAcceptConnection(const char*) */
73+
bool rpcAcceptConnection(const char* ip_address) override;
74+
7275
/** @copydoc bool RpcServer::IListener::rpcCheckCredentials(const std::string&, const std::string&, const std::string&) */
7376
bool rpcCheckCredentials(const std::string& chargepoint_id, const std::string& user, const std::string& password) override;
7477

src/centralsystem/interface/ICentralSystemEventsHandler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class ICentralSystemEventsHandler
3333
/** @brief Destructor */
3434
virtual ~ICentralSystemEventsHandler() { }
3535

36+
/**
37+
* @brief Called to accept an incoming connection
38+
* @param ip_address IP address of the client
39+
* @return true if the incoming connection must be accepted, false otherwise
40+
*/
41+
virtual bool acceptConnection(const char* ip_address) = 0;
42+
3643
/**
3744
* @brief Called to check the charge point credentials for HTTP basic authentication
3845
* @param chargepoint_id Charge Point identifier

src/localcontroller/LocalController.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ bool LocalController::stop()
242242
return ret;
243243
}
244244

245+
/** @copydoc bool RpcServer::IListener::rpcAcceptConnection(const char*) */
246+
bool LocalController::rpcAcceptConnection(const char* ip_address)
247+
{
248+
// Notify connection => no additional processing is done here
249+
// to keep this callback has fast as possible
250+
return m_events_handler.acceptConnection(ip_address);
251+
}
252+
245253
/** @copydoc bool RpcServer::IListener::rpcCheckCredentials(const std::string&, const std::string&, const std::string&) */
246254
bool LocalController::rpcCheckCredentials(const std::string& chargepoint_id, const std::string& user, const std::string& password)
247255
{

src/localcontroller/LocalController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class LocalController : public ILocalController, public ocpp::rpc::RpcServer::IL
6969

7070
// RpcServer::IListener interface
7171

72+
/** @copydoc bool RpcServer::IListener::rpcAcceptConnection(const char*) */
73+
bool rpcAcceptConnection(const char* ip_address) override;
74+
7275
/** @copydoc bool RpcServer::IListener::rpcCheckCredentials(const std::string&, const std::string&, const std::string&) */
7376
bool rpcCheckCredentials(const std::string& chargepoint_id, const std::string& user, const std::string& password) override;
7477

0 commit comments

Comments
 (0)