Skip to content

Commit ec5e913

Browse files
authored
Merge pull request #78 from c-jimenez/dev/json_validator
Dev/json validator
2 parents 55b12cd + 9738357 commit ec5e913

25 files changed

+549
-221
lines changed

schemas/SignedFirmwareStatusNotificationResponse.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
"type": "object",
77
"properties": {},
88
"additionalProperties": false
9-
}
109
}

src/centralsystem/CentralSystem.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ CentralSystem::CentralSystem(const ocpp::config::ICentralSystemConfig& st
6969
m_database(),
7070
m_internal_config(m_database),
7171
m_messages_converter(),
72+
m_messages_validator(),
7273
m_ws_server(),
7374
m_rpc_server(),
7475
m_uptime_timer(*m_timer_pool.get(), "Uptime timer"),
@@ -164,31 +165,40 @@ bool CentralSystem::start()
164165
{
165166
LOG_INFO << "Starting OCPP stack v" << OPEN_OCPP_VERSION << " - Listen URL : " << m_stack_config.listenUrl();
166167

167-
// Start uptime counter
168-
m_uptime = 0;
169-
m_internal_config.setKey(START_DATE_KEY, DateTime::now().str());
170-
m_uptime_timer.start(std::chrono::seconds(1u));
171-
172-
// Allocate resources
173-
m_ws_server = std::unique_ptr<ocpp::websockets::IWebsocketServer>(ocpp::websockets::WebsocketFactory::newServer());
174-
m_rpc_server = std::make_unique<ocpp::rpc::RpcServer>(*m_ws_server, "ocpp1.6");
175-
m_rpc_server->registerServerListener(*this);
176-
177-
// Configure websocket link
178-
ocpp::websockets::IWebsocketServer::Credentials credentials;
179-
credentials.http_basic_authent = m_stack_config.httpBasicAuthent();
180-
credentials.tls12_cipher_list = m_stack_config.tlsv12CipherList();
181-
credentials.tls13_cipher_list = m_stack_config.tlsv13CipherList();
182-
credentials.ecdh_curve = m_stack_config.tlsEcdhCurve();
183-
credentials.server_certificate = m_stack_config.tlsServerCertificate();
184-
credentials.server_certificate_private_key = m_stack_config.tlsServerCertificatePrivateKey();
185-
credentials.server_certificate_private_key_passphrase = m_stack_config.tlsServerCertificatePrivateKeyPassphrase();
186-
credentials.server_certificate_ca = m_stack_config.tlsServerCertificateCa();
187-
credentials.client_certificate_authent = m_stack_config.tlsClientCertificateAuthent();
188-
credentials.encoded_pem_certificates = false;
189-
190-
// Start listening
191-
ret = m_rpc_server->start(m_stack_config.listenUrl(), credentials, m_stack_config.webSocketPingInterval());
168+
// Load validator
169+
ret = m_messages_validator.load(m_stack_config.jsonSchemasPath());
170+
if (ret)
171+
{
172+
// Start uptime counter
173+
m_uptime = 0;
174+
m_internal_config.setKey(START_DATE_KEY, DateTime::now().str());
175+
m_uptime_timer.start(std::chrono::seconds(1u));
176+
177+
// Allocate resources
178+
m_ws_server = std::unique_ptr<ocpp::websockets::IWebsocketServer>(ocpp::websockets::WebsocketFactory::newServer());
179+
m_rpc_server = std::make_unique<ocpp::rpc::RpcServer>(*m_ws_server, "ocpp1.6");
180+
m_rpc_server->registerServerListener(*this);
181+
182+
// Configure websocket link
183+
ocpp::websockets::IWebsocketServer::Credentials credentials;
184+
credentials.http_basic_authent = m_stack_config.httpBasicAuthent();
185+
credentials.tls12_cipher_list = m_stack_config.tlsv12CipherList();
186+
credentials.tls13_cipher_list = m_stack_config.tlsv13CipherList();
187+
credentials.ecdh_curve = m_stack_config.tlsEcdhCurve();
188+
credentials.server_certificate = m_stack_config.tlsServerCertificate();
189+
credentials.server_certificate_private_key = m_stack_config.tlsServerCertificatePrivateKey();
190+
credentials.server_certificate_private_key_passphrase = m_stack_config.tlsServerCertificatePrivateKeyPassphrase();
191+
credentials.server_certificate_ca = m_stack_config.tlsServerCertificateCa();
192+
credentials.client_certificate_authent = m_stack_config.tlsClientCertificateAuthent();
193+
credentials.encoded_pem_certificates = false;
194+
195+
// Start listening
196+
ret = m_rpc_server->start(m_stack_config.listenUrl(), credentials, m_stack_config.webSocketPingInterval());
197+
}
198+
else
199+
{
200+
LOG_ERROR << "Unable to load all the messages validators";
201+
}
192202
}
193203
else
194204
{
@@ -252,7 +262,7 @@ void CentralSystem::rpcClientConnected(const std::string& chargepoint_id, std::s
252262

253263
// Instanciate proxy
254264
std::shared_ptr<ICentralSystem::IChargePoint> chargepoint(
255-
new ChargePointProxy(*this, chargepoint_id, client, m_stack_config.jsonSchemasPath(), m_messages_converter, m_stack_config));
265+
new ChargePointProxy(*this, chargepoint_id, client, m_messages_validator, m_messages_converter, m_stack_config));
256266

257267
// Notify connection
258268
m_events_handler.chargePointConnected(chargepoint);

src/centralsystem/CentralSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2323
#include "ICentralSystem.h"
2424
#include "InternalConfigManager.h"
2525
#include "MessagesConverter.h"
26+
#include "MessagesValidator.h"
2627
#include "RpcServer.h"
2728
#include "Timer.h"
2829

@@ -95,6 +96,8 @@ class CentralSystem : public ICentralSystem, public ocpp::rpc::RpcServer::IListe
9596

9697
/** @brief Messages converter */
9798
ocpp::messages::MessagesConverter m_messages_converter;
99+
/** @brief Messages validator */
100+
ocpp::messages::MessagesValidator m_messages_validator;
98101

99102
/** @brief Websocket server */
100103
std::unique_ptr<ocpp::websockets::IWebsocketServer> m_ws_server;

src/centralsystem/chargepoint/ChargePointProxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ namespace centralsystem
5858
ChargePointProxy::ChargePointProxy(ICentralSystem& central_system,
5959
const std::string& identifier,
6060
std::shared_ptr<ocpp::rpc::RpcServer::Client> rpc,
61-
const std::string& schemas_path,
61+
const ocpp::messages::MessagesValidator& messages_validator,
6262
ocpp::messages::MessagesConverter& messages_converter,
6363
const ocpp::config::ICentralSystemConfig& stack_config)
6464
: m_central_system(central_system),
6565
m_identifier(identifier),
6666
m_rpc(rpc),
67-
m_msg_dispatcher(schemas_path),
68-
m_msg_sender(*m_rpc, messages_converter, stack_config.callRequestTimeout()),
67+
m_msg_dispatcher(messages_validator),
68+
m_msg_sender(*m_rpc, messages_converter, messages_validator, stack_config.callRequestTimeout()),
6969
m_handler(m_identifier, messages_converter, m_msg_dispatcher, stack_config)
7070
{
7171
m_rpc->registerSpy(*this);

src/centralsystem/chargepoint/ChargePointProxy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2323
#include "GenericMessageSender.h"
2424
#include "ICentralSystem.h"
2525
#include "MessageDispatcher.h"
26+
#include "MessagesValidator.h"
2627
#include "RpcServer.h"
2728

2829
#include <memory>
@@ -41,14 +42,14 @@ class ChargePointProxy : public ICentralSystem::IChargePoint, public ocpp::rpc::
4142
* @param central_system Central System instance associated to the charge point
4243
* @param identifier Charge point's identifier
4344
* @param rpc RPC connection with the charge point
44-
* @param schemas_path Path to the JSON schemas needed to validate payloads
45+
* @param messages_validator JSON schemas needed to validate payloads
4546
* @param messages_converter Converter from/to OCPP to/from JSON messages
4647
* @param stack_config Stack configuration
4748
*/
4849
ChargePointProxy(ICentralSystem& central_system,
4950
const std::string& identifier,
5051
std::shared_ptr<ocpp::rpc::RpcServer::Client> rpc,
51-
const std::string& schemas_path,
52+
const ocpp::messages::MessagesValidator& messages_validator,
5253
ocpp::messages::MessagesConverter& messages_converter,
5354
const ocpp::config::ICentralSystemConfig& stack_config);
5455
/** @brief Destructor */

0 commit comments

Comments
 (0)