Skip to content

Commit

Permalink
Rename DeviceModelStorage to DeviceModelInterface
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez committed Sep 3, 2024
1 parent 7fc94d2 commit d588926
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 84 deletions.
8 changes: 4 additions & 4 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <ocpp/v201/ctrlr_component_variables.hpp>
#include <ocpp/v201/database_handler.hpp>
#include <ocpp/v201/device_model.hpp>
#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/device_model_interface.hpp>
#include <ocpp/v201/evse_manager.hpp>
#include <ocpp/v201/monitoring_updater.hpp>
#include <ocpp/v201/ocpp_enums.hpp>
Expand Down Expand Up @@ -838,14 +838,14 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The
/// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of
/// the EVSEs have to increment starting with 1.
/// \param device_model_storage device model storage instance
/// \param device_model_interface device model interface instance
/// \param ocpp_main_path Path where utility files for OCPP are read and written to
/// \param core_database_path Path to directory where core database is located
/// \param message_log_path Path to where logfiles are written to
/// \param evse_security Pointer to evse_security that manages security related operations
/// \param callbacks Callbacks that will be registered for ChargePoint
ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
std::unique_ptr<DeviceModelStorage> device_model_storage, const std::string& ocpp_main_path,
std::unique_ptr<DeviceModelInterface> device_model_interface, const std::string& ocpp_main_path,
const std::string& core_database_path, const std::string& sql_init_path,
const std::string& message_log_path, const std::shared_ptr<EvseSecurity> evse_security,
const Callbacks& callbacks);
Expand All @@ -854,7 +854,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The
/// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of
/// the EVSEs have to increment starting with 1.
/// \param device_model_storage device model storage instance
/// \param device_model device model instance
/// \param database_handler database handler instance
/// \param message_queue message queue instance
/// \param message_log_path Path to where logfiles are written to
Expand Down
20 changes: 10 additions & 10 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <everest/logging.hpp>

#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/device_model_interface.hpp>

namespace ocpp {
namespace v201 {
Expand Down Expand Up @@ -91,13 +91,13 @@ typedef std::function<void(const VariableMonitoringMeta& updated_monitor, const
const VariableAttribute& attribute, const std::string& current_value)>
on_monitor_updated;

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

private:
DeviceModelMap device_model;
std::unique_ptr<DeviceModelStorage> storage;
std::unique_ptr<DeviceModelInterface> interface;

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

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

public:
/// \brief Constructor for the device model
/// \param device_model_storage pointer to a device model storage class
explicit DeviceModel(std::unique_ptr<DeviceModelStorage> device_model_storage);
/// \param device_model_interface pointer to a device model interface class
explicit DeviceModel(std::unique_ptr<DeviceModelInterface> device_model_interface);

/// \brief Direct access to value of a VariableAttribute for the given component, variable and attribute_enum. This
/// should only be called for variables that have a role standardized in the OCPP2.0.1 specification.
/// \tparam T datatype of the value that is requested
/// \param component_variable Combination of Component and Variable that identifies the Variable
/// \param attribute_enum defaults to AttributeEnum::Actual
/// \return the requested value from the device model storage
/// \return the requested value from the device model interface
template <typename T>
T get_value(const RequiredComponentVariable& component_variable,
const AttributeEnum& attribute_enum = AttributeEnum::Actual) {
Expand All @@ -160,10 +160,10 @@ class DeviceModel {
return to_specific_type<T>(value);
} else {
EVLOG_critical
<< "Directly requested value for ComponentVariable that doesn't exist in the device model storage: "
<< "Directly requested value for ComponentVariable that doesn't exist in the device model: "
<< component_variable;
EVLOG_AND_THROW(std::runtime_error(
"Directly requested value for ComponentVariable that doesn't exist in the device model storage."));
"Directly requested value for ComponentVariable that doesn't exist in the device model."));
}
}

Expand All @@ -190,7 +190,7 @@ class DeviceModel {
}

/// \brief Requests a value of a VariableAttribute specified by combination of \p component_id and \p variable_id
/// from the device model storage
/// from the device model
/// \tparam T datatype of the value that is requested
/// \param component_id
/// \param variable_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest

#ifndef OCPP_V201_DEVICE_MODEL_STORAGE_HPP
#define OCPP_V201_DEVICE_MODEL_STORAGE_HPP
#pragma once

#include <map>
#include <memory>
Expand Down Expand Up @@ -39,31 +38,31 @@ struct VariableMetaData {
using VariableMap = std::map<Variable, VariableMetaData>;
using DeviceModelMap = std::map<Component, VariableMap>;

class DeviceModelStorageError : public std::exception {
class DeviceModelError : public std::exception {
public:
[[nodiscard]] const char* what() const noexcept override {
return this->reason.c_str();
}
explicit DeviceModelStorageError(std::string msg) {
explicit DeviceModelError(std::string msg) {
this->reason = std::move(msg);
}
explicit DeviceModelStorageError(const char* msg) {
explicit DeviceModelError(const char* msg) {
this->reason = std::string(msg);
}

private:
std::string reason;
};

/// \brief Abstract base class for device model storage. This class provides an interface for accessing and modifying
/// \brief Abstract base class for device model interface. This class provides an interface for accessing and modifying
/// device model data. Implementations of this class should provide concrete implementations for the virtual methods
/// declared here.
class DeviceModelStorage {
class DeviceModelInterface {

public:
virtual ~DeviceModelStorage() = default;
virtual ~DeviceModelInterface() = default;

/// \brief Gets the device model from the device model storage
/// \brief Gets the device model from the device model interface
/// \return std::map<Component, std::map<Variable, VariableMetaData>> that will contain a full representation of the
/// device model except for the VariableAttribute(s) of each Variable.
virtual DeviceModelMap get_device_model() = 0;
Expand Down Expand Up @@ -141,4 +140,3 @@ class DeviceModelStorage {
} // namespace v201
} // namespace ocpp

#endif // OCPP_V201_DEVICE_MODEL_STORAGE_HPP
4 changes: 2 additions & 2 deletions include/ocpp/v201/device_model_storage_sqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

#include <everest/logging.hpp>
#include <ocpp/common/database/database_connection.hpp>
#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/device_model_interface.hpp>

namespace ocpp {
namespace v201 {

class DeviceModelStorageSqlite : public DeviceModelStorage {
class DeviceModelStorageSqlite : public DeviceModelInterface {

private:
std::unique_ptr<ocpp::common::DatabaseConnectionInterface> db;
Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/v201/init_device_model_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// database is not set by an external source, like the CSMS.
///
/// The data from the schema json files or database are read into some structs. Some structs could be reused from
/// the DeviceModelStorage class, but some members are missing there and and to prevent too many database reads, some
/// the DeviceModelInterface class, but some members are missing there and and to prevent too many database reads, some
/// structs are 'redefined' in this class with the proper members.
///
/// Since the DeviceModel class creates a map based on the device model database in the constructor, this class should
Expand All @@ -36,7 +36,7 @@
#include <filesystem>

#include <ocpp/common/database/database_handler_common.hpp>
#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/device_model_interface.hpp>

namespace ocpp::v201 {
///
Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/v201/monitoring_updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <ocpp/v201/ocpp_enums.hpp>
#include <ocpp/v201/ocpp_types.hpp>

#include <ocpp/v201/device_model_storage.hpp>
#include <ocpp/v201/device_model_interface.hpp>

namespace ocpp::v201 {

Expand Down Expand Up @@ -187,4 +187,4 @@ class MonitoringUpdater {
std::unordered_map<std::int32_t, UpdaterMonitorMeta> updater_monitors_meta;
};

} // namespace ocpp::v201
} // namespace ocpp::v201
23 changes: 11 additions & 12 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
}

ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
std::unique_ptr<DeviceModelStorage> device_model_storage, const std::string& ocpp_main_path,
const std::string& core_database_path, const std::string& sql_init_path,
const std::string& message_log_path, const std::shared_ptr<EvseSecurity> evse_security,
const Callbacks& callbacks) :
std::unique_ptr<DeviceModelInterface> device_model_interface,
const std::string& ocpp_main_path, const std::string& core_database_path,
const std::string& sql_init_path, const std::string& message_log_path,
const std::shared_ptr<EvseSecurity> evse_security, const Callbacks& callbacks) :
ocpp::ChargingStationBase(evse_security),
registration_status(RegistrationStatusEnum::Rejected),
skip_invalid_csms_certificate_notifications(false),
Expand All @@ -139,7 +139,7 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
bootreason(BootReasonEnum::PowerUp),
ocsp_updater(this->evse_security, this->send_callback<GetCertificateStatusRequest, GetCertificateStatusResponse>(
MessageType::GetCertificateStatusResponse)),
device_model(std::make_shared<DeviceModel>(std::move(device_model_storage))),
device_model(std::make_shared<DeviceModel>(std::move(device_model_interface))),
monitoring_updater(
device_model, [this](const std::vector<EventData>& events) { this->notify_event_req(events); },
[this]() { return this->is_offline(); }),
Expand Down Expand Up @@ -2434,8 +2434,7 @@ void ChargePoint::handle_set_network_profile_req(Call<SetNetworkProfileRequest>
ControllerComponentVariables::NetworkConnectionProfiles.variable.value(),
AttributeEnum::Actual, network_connection_profiles.dump(),
VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL) != SetVariableStatusEnum::Accepted) {
EVLOG_warning
<< "CSMS attempted to set a network profile that could not be written to the device model storage";
EVLOG_warning << "CSMS attempted to set a network profile that could not be written to the device model";
response.status = SetNetworkProfileStatusEnum::Rejected;
ocpp::CallResult<SetNetworkProfileResponse> call_result(response, call.uniqueId);
this->send<SetNetworkProfileResponse>(call_result);
Expand Down Expand Up @@ -3339,7 +3338,7 @@ void ChargePoint::handle_set_monitoring_base_req(Call<SetMonitoringBaseRequest>
msg.monitoringBase == MonitoringBaseEnum::FactoryDefault) {
try {
this->device_model->clear_custom_monitors();
} catch (const DeviceModelStorageError& e) {
} catch (const DeviceModelError& e) {
EVLOG_warning << "Could not clear custom monitors from DB: " << e.what();
response.status = GenericDeviceModelStatusEnum::Rejected;
}
Expand Down Expand Up @@ -3399,7 +3398,7 @@ void ChargePoint::handle_set_variable_monitoring_req(const EnhancedMessage<v201:

try {
response.setMonitoringResult = this->device_model->set_monitors(msg.setMonitoringData);
} catch (const DeviceModelStorageError& e) {
} catch (const DeviceModelError& e) {
EVLOG_error << "Set monitors failed:" << e.what();
}

Expand Down Expand Up @@ -3479,7 +3478,7 @@ void ChargePoint::handle_get_monitoring_report_req(Call<GetMonitoringReportReque
} else {
response.status = GenericDeviceModelStatusEnum::EmptyResultSet;
}
} catch (const DeviceModelStorageError& e) {
} catch (const DeviceModelError& e) {
EVLOG_error << "Get variable monitoring failed:" << e.what();
response.status = GenericDeviceModelStatusEnum::Rejected;
}
Expand All @@ -3499,7 +3498,7 @@ void ChargePoint::handle_clear_variable_monitoring_req(Call<ClearVariableMonitor

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

Expand Down Expand Up @@ -3633,7 +3632,7 @@ void ChargePoint::handle_send_local_authorization_list_req(Call<SendLocalListReq
this->device_model->set_read_only_value(local_entries.component, local_entries.variable.value(),
AttributeEnum::Actual, std::to_string(entries),
VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL);
} catch (const DeviceModelStorageError& e) {
} catch (const DeviceModelError& e) {
EVLOG_warning << "Could not get local list count from database:" << e.what();
} catch (const DatabaseException& e) {
EVLOG_warning << "Could not get local list count from database: " << e.what();
Expand Down
Loading

0 comments on commit d588926

Please sign in to comment.