Skip to content

Commit b00d278

Browse files
authored
Rename DeviceModelStorage to DeviceModelInterface (#768)
* Rename `DeviceModelStorage` to `DeviceModelInterface` * Changes to the database and distinguish between external and ocpp values. Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent 5416829 commit b00d278

25 files changed

+171
-125
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
project(ocpp
4-
VERSION 0.19.0
4+
VERSION 0.20.0
55
DESCRIPTION "A C++ implementation of the Open Charge Point Protocol"
66
LANGUAGES CXX
77
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE VARIABLE
2+
DROP COLUMN SOURCE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE VARIABLE
2+
ADD COLUMN SOURCE TEXT;

include/ocpp/v201/charge_point.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <ocpp/v201/ctrlr_component_variables.hpp>
1515
#include <ocpp/v201/database_handler.hpp>
1616
#include <ocpp/v201/device_model.hpp>
17-
#include <ocpp/v201/device_model_storage.hpp>
17+
#include <ocpp/v201/device_model_storage_interface.hpp>
1818
#include <ocpp/v201/evse_manager.hpp>
1919
#include <ocpp/v201/monitoring_updater.hpp>
2020
#include <ocpp/v201/ocpp_enums.hpp>
@@ -808,17 +808,17 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
808808
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The
809809
/// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of
810810
/// the EVSEs have to increment starting with 1.
811-
/// \param device_model_storage device model storage instance
811+
/// \param device_model_storage_interface device model interface instance
812812
/// \param ocpp_main_path Path where utility files for OCPP are read and written to
813813
/// \param core_database_path Path to directory where core database is located
814814
/// \param message_log_path Path to where logfiles are written to
815815
/// \param evse_security Pointer to evse_security that manages security related operations
816816
/// \param callbacks Callbacks that will be registered for ChargePoint
817817
ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
818-
std::unique_ptr<DeviceModelStorage> device_model_storage, const std::string& ocpp_main_path,
819-
const std::string& core_database_path, const std::string& sql_init_path,
820-
const std::string& message_log_path, const std::shared_ptr<EvseSecurity> evse_security,
821-
const Callbacks& callbacks);
818+
std::unique_ptr<DeviceModelStorageInterface> device_model_storage_interface,
819+
const std::string& ocpp_main_path, const std::string& core_database_path,
820+
const std::string& sql_init_path, const std::string& message_log_path,
821+
const std::shared_ptr<EvseSecurity> evse_security, const Callbacks& callbacks);
822822

823823
/// \brief Construct a new ChargePoint object
824824
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The

include/ocpp/v201/device_model.hpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <everest/logging.hpp>
1010

11-
#include <ocpp/v201/device_model_storage.hpp>
11+
#include <ocpp/v201/device_model_storage_interface.hpp>
1212

1313
namespace ocpp {
1414
namespace v201 {
@@ -91,13 +91,13 @@ typedef std::function<void(const VariableMonitoringMeta& updated_monitor, const
9191
const VariableAttribute& attribute, const std::string& current_value)>
9292
on_monitor_updated;
9393

94-
/// \brief This class manages access to the device model representation and to the device model storage and provides
94+
/// \brief This class manages access to the device model representation and to the device model interface and provides
9595
/// functionality to support the use cases defined in the functional block Provisioning
9696
class DeviceModel {
9797

9898
private:
99-
DeviceModelMap device_model;
100-
std::unique_ptr<DeviceModelStorage> storage;
99+
DeviceModelMap device_model_map;
100+
std::unique_ptr<DeviceModelStorageInterface> device_model;
101101

102102
/// \brief Listener for the internal change of a variable
103103
on_variable_changed variable_listener;
@@ -106,7 +106,7 @@ class DeviceModel {
106106

107107
/// \brief Private helper method that does some checks with the device model representation in memory to evaluate if
108108
/// a value for the given parameters can be requested. If it can be requested it will be retrieved from the device
109-
/// model storage and the given \p value will be set to the value that was retrieved
109+
/// model interface and the given \p value will be set to the value that was retrieved
110110
/// \param component_id
111111
/// \param variable_id
112112
/// \param attribute_enum
@@ -138,15 +138,15 @@ class DeviceModel {
138138

139139
public:
140140
/// \brief Constructor for the device model
141-
/// \param device_model_storage pointer to a device model storage class
142-
explicit DeviceModel(std::unique_ptr<DeviceModelStorage> device_model_storage);
141+
/// \param device_model_storage_interface pointer to a device model interface class
142+
explicit DeviceModel(std::unique_ptr<DeviceModelStorageInterface> device_model_storage_interface);
143143

144144
/// \brief Direct access to value of a VariableAttribute for the given component, variable and attribute_enum. This
145145
/// should only be called for variables that have a role standardized in the OCPP2.0.1 specification.
146146
/// \tparam T datatype of the value that is requested
147147
/// \param component_variable Combination of Component and Variable that identifies the Variable
148148
/// \param attribute_enum defaults to AttributeEnum::Actual
149-
/// \return the requested value from the device model storage
149+
/// \return the requested value from the device model interface
150150
template <typename T>
151151
T get_value(const RequiredComponentVariable& component_variable,
152152
const AttributeEnum& attribute_enum = AttributeEnum::Actual) const {
@@ -159,11 +159,10 @@ class DeviceModel {
159159
if (response == GetVariableStatusEnum::Accepted) {
160160
return to_specific_type<T>(value);
161161
} else {
162-
EVLOG_critical
163-
<< "Directly requested value for ComponentVariable that doesn't exist in the device model storage: "
164-
<< component_variable;
162+
EVLOG_critical << "Directly requested value for ComponentVariable that doesn't exist in the device model: "
163+
<< component_variable;
165164
EVLOG_AND_THROW(std::runtime_error(
166-
"Directly requested value for ComponentVariable that doesn't exist in the device model storage."));
165+
"Directly requested value for ComponentVariable that doesn't exist in the device model."));
167166
}
168167
}
169168

@@ -190,7 +189,7 @@ class DeviceModel {
190189
}
191190

192191
/// \brief Requests a value of a VariableAttribute specified by combination of \p component_id and \p variable_id
193-
/// from the device model storage
192+
/// from the device model
194193
/// \tparam T datatype of the value that is requested
195194
/// \param component_id
196195
/// \param variable_id

include/ocpp/v201/device_model_storage.hpp include/ocpp/v201/device_model_storage_interface.hpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
33

4-
#ifndef OCPP_V201_DEVICE_MODEL_STORAGE_HPP
5-
#define OCPP_V201_DEVICE_MODEL_STORAGE_HPP
4+
#pragma once
65

76
#include <map>
87
#include <memory>
@@ -34,36 +33,37 @@ struct VariableMonitoringPeriodic {
3433
struct VariableMetaData {
3534
VariableCharacteristics characteristics;
3635
std::unordered_map<int64_t, VariableMonitoringMeta> monitors;
36+
std::optional<std::string> source;
3737
};
3838

3939
using VariableMap = std::map<Variable, VariableMetaData>;
4040
using DeviceModelMap = std::map<Component, VariableMap>;
4141

42-
class DeviceModelStorageError : public std::exception {
42+
class DeviceModelError : public std::exception {
4343
public:
4444
[[nodiscard]] const char* what() const noexcept override {
4545
return this->reason.c_str();
4646
}
47-
explicit DeviceModelStorageError(std::string msg) {
47+
explicit DeviceModelError(std::string msg) {
4848
this->reason = std::move(msg);
4949
}
50-
explicit DeviceModelStorageError(const char* msg) {
50+
explicit DeviceModelError(const char* msg) {
5151
this->reason = std::string(msg);
5252
}
5353

5454
private:
5555
std::string reason;
5656
};
5757

58-
/// \brief Abstract base class for device model storage. This class provides an interface for accessing and modifying
58+
/// \brief Abstract base class for device model interface. This class provides an interface for accessing and modifying
5959
/// device model data. Implementations of this class should provide concrete implementations for the virtual methods
6060
/// declared here.
61-
class DeviceModelStorage {
61+
class DeviceModelStorageInterface {
6262

6363
public:
64-
virtual ~DeviceModelStorage() = default;
64+
virtual ~DeviceModelStorageInterface() = default;
6565

66-
/// \brief Gets the device model from the device model storage
66+
/// \brief Gets the device model from the device model interface
6767
/// \return std::map<Component, std::map<Variable, VariableMetaData>> that will contain a full representation of the
6868
/// device model except for the VariableAttribute(s) of each Variable.
6969
virtual DeviceModelMap get_device_model() = 0;
@@ -140,5 +140,3 @@ class DeviceModelStorage {
140140

141141
} // namespace v201
142142
} // namespace ocpp
143-
144-
#endif // OCPP_V201_DEVICE_MODEL_STORAGE_HPP

include/ocpp/v201/device_model_storage_sqlite.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
#include <everest/logging.hpp>
1111
#include <ocpp/common/database/database_connection.hpp>
12-
#include <ocpp/v201/device_model_storage.hpp>
12+
#include <ocpp/v201/device_model_storage_interface.hpp>
1313

1414
namespace ocpp {
1515
namespace v201 {
1616

17-
class DeviceModelStorageSqlite : public DeviceModelStorage {
17+
class DeviceModelStorageSqlite : public DeviceModelStorageInterface {
1818

1919
private:
2020
std::unique_ptr<ocpp::common::DatabaseConnectionInterface> db;

include/ocpp/v201/enums.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef OCPP_V201_ENUMS_HPP
66
#define OCPP_V201_ENUMS_HPP
77

8+
#include <string>
9+
810
namespace ocpp {
911
namespace v201 {
1012

include/ocpp/v201/init_device_model_db.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <filesystem>
3737

3838
#include <ocpp/common/database/database_handler_common.hpp>
39-
#include <ocpp/v201/device_model_storage.hpp>
39+
#include <ocpp/v201/device_model_storage_interface.hpp>
4040

4141
namespace ocpp::v201 {
4242
///
@@ -93,6 +93,8 @@ struct DeviceModelVariable {
9393
std::optional<std::string> default_actual_value;
9494
/// \brief Config monitors, if any
9595
std::vector<VariableMonitoringMeta> monitors;
96+
/// \brief Source of the variable.
97+
std::optional<std::string> source;
9698
};
9799

98100
/// \brief Convert from json to a ComponentKey struct.

include/ocpp/v201/monitoring_updater.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <ocpp/v201/ocpp_enums.hpp>
1212
#include <ocpp/v201/ocpp_types.hpp>
1313

14-
#include <ocpp/v201/device_model_storage.hpp>
14+
#include <ocpp/v201/device_model_storage_interface.hpp>
1515

1616
namespace ocpp::v201 {
1717

@@ -187,4 +187,4 @@ class MonitoringUpdater {
187187
std::unordered_map<std::int32_t, UpdaterMonitorMeta> updater_monitors_meta;
188188
};
189189

190-
} // namespace ocpp::v201
190+
} // namespace ocpp::v201

lib/ocpp/v201/charge_point.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
7878
}
7979

8080
ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
81-
std::unique_ptr<DeviceModelStorage> device_model_storage, const std::string& ocpp_main_path,
82-
const std::string& core_database_path, const std::string& sql_init_path,
83-
const std::string& message_log_path, const std::shared_ptr<EvseSecurity> evse_security,
84-
const Callbacks& callbacks) :
81+
std::unique_ptr<DeviceModelStorageInterface> device_model_storage_interface,
82+
const std::string& ocpp_main_path, const std::string& core_database_path,
83+
const std::string& sql_init_path, const std::string& message_log_path,
84+
const std::shared_ptr<EvseSecurity> evse_security, const Callbacks& callbacks) :
8585
ChargePoint(
86-
evse_connector_structure, std::make_shared<DeviceModel>(std::move(device_model_storage)),
86+
evse_connector_structure, std::make_shared<DeviceModel>(std::move(device_model_storage_interface)),
8787
std::make_shared<DatabaseHandler>(
8888
std::make_unique<common::DatabaseConnection>(fs::path(core_database_path) / "cp.db"), sql_init_path),
8989
nullptr /* message_queue initialized in this constructor */, message_log_path, evse_security, callbacks) {
@@ -2661,8 +2661,7 @@ void ChargePoint::handle_set_network_profile_req(Call<SetNetworkProfileRequest>
26612661
ControllerComponentVariables::NetworkConnectionProfiles.variable.value(),
26622662
AttributeEnum::Actual, network_connection_profiles.dump(),
26632663
VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL) != SetVariableStatusEnum::Accepted) {
2664-
EVLOG_warning
2665-
<< "CSMS attempted to set a network profile that could not be written to the device model storage";
2664+
EVLOG_warning << "CSMS attempted to set a network profile that could not be written to the device model";
26662665
response.status = SetNetworkProfileStatusEnum::Rejected;
26672666
ocpp::CallResult<SetNetworkProfileResponse> call_result(response, call.uniqueId);
26682667
this->send<SetNetworkProfileResponse>(call_result);
@@ -3712,7 +3711,7 @@ void ChargePoint::handle_set_monitoring_base_req(Call<SetMonitoringBaseRequest>
37123711
msg.monitoringBase == MonitoringBaseEnum::FactoryDefault) {
37133712
try {
37143713
this->device_model->clear_custom_monitors();
3715-
} catch (const DeviceModelStorageError& e) {
3714+
} catch (const DeviceModelError& e) {
37163715
EVLOG_warning << "Could not clear custom monitors from DB: " << e.what();
37173716
response.status = GenericDeviceModelStatusEnum::Rejected;
37183717
}
@@ -3772,7 +3771,7 @@ void ChargePoint::handle_set_variable_monitoring_req(const EnhancedMessage<v201:
37723771

37733772
try {
37743773
response.setMonitoringResult = this->device_model->set_monitors(msg.setMonitoringData);
3775-
} catch (const DeviceModelStorageError& e) {
3774+
} catch (const DeviceModelError& e) {
37763775
EVLOG_error << "Set monitors failed:" << e.what();
37773776
}
37783777

@@ -3852,7 +3851,7 @@ void ChargePoint::handle_get_monitoring_report_req(Call<GetMonitoringReportReque
38523851
} else {
38533852
response.status = GenericDeviceModelStatusEnum::EmptyResultSet;
38543853
}
3855-
} catch (const DeviceModelStorageError& e) {
3854+
} catch (const DeviceModelError& e) {
38563855
EVLOG_error << "Get variable monitoring failed:" << e.what();
38573856
response.status = GenericDeviceModelStatusEnum::Rejected;
38583857
}
@@ -3872,7 +3871,7 @@ void ChargePoint::handle_clear_variable_monitoring_req(Call<ClearVariableMonitor
38723871

38733872
try {
38743873
response.clearMonitoringResult = this->device_model->clear_monitors(msg.id);
3875-
} catch (const DeviceModelStorageError& e) {
3874+
} catch (const DeviceModelError& e) {
38763875
EVLOG_error << "Clear variable monitoring failed:" << e.what();
38773876
}
38783877

@@ -4143,7 +4142,7 @@ void ChargePoint::handle_send_local_authorization_list_req(Call<SendLocalListReq
41434142
this->device_model->set_read_only_value(local_entries.component, local_entries.variable.value(),
41444143
AttributeEnum::Actual, std::to_string(entries),
41454144
VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL);
4146-
} catch (const DeviceModelStorageError& e) {
4145+
} catch (const DeviceModelError& e) {
41474146
EVLOG_warning << "Could not get local list count from database:" << e.what();
41484147
} catch (const DatabaseException& e) {
41494148
EVLOG_warning << "Could not get local list count from database: " << e.what();

0 commit comments

Comments
 (0)