Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DeviceModelStorage to DeviceModelInterface #768

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"properties": {
"AlignedDataCtrlrEnabled": {
"variable_name": "Enabled",
"source": "OCPP",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we only have that im some of the files? To have an example?

Copy link
Contributor Author

@maaikez maaikez Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure anymore (it's a long time ago already), but I think so indeed.
I also don't know exactly which values should be for ocpp and which internal, from some I know but for the others we have to walk through them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, all should be OCPP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id suggest to remove the "source" here. It will be useful later when we add externally managed variables.

"characteristics": {
"supportsMonitoring": true,
"dataType": "boolean"
Expand All @@ -22,6 +23,7 @@
},
"AlignedDataCtrlrAvailable": {
"variable_name": "Available",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "boolean"
Expand All @@ -38,6 +40,7 @@
},
"AlignedDataInterval": {
"variable_name": "Interval",
"source": "OCPP",
"characteristics": {
"unit": "s",
"supportsMonitoring": true,
Expand Down
1 change: 1 addition & 0 deletions config/v201/component_config/standardized/ClockCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"properties": {
"ClockCtrlrEnabled": {
"variable_name": "Enabled",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "boolean"
Expand Down
8 changes: 8 additions & 0 deletions config/v201/component_config/standardized/SecurityCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"AdditionalRootCertificateCheck": {
"variable_name": "AdditionalRootCertificateCheck",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "boolean"
Expand All @@ -38,6 +39,7 @@
},
"BasicAuthPassword": {
"variable_name": "BasicAuthPassword",
"source": "OCPP",
"characteristics": {
"minLimit": 16,
"maxLimit": 40,
Expand Down Expand Up @@ -75,6 +77,7 @@
},
"CertSigningRepeatTimes": {
"variable_name": "CertSigningRepeatTimes",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "integer"
Expand All @@ -92,6 +95,7 @@
},
"CertSigningWaitMinimum": {
"variable_name": "CertSigningWaitMinimum",
"source": "OCPP",
"characteristics": {
"unit": "s",
"supportsMonitoring": true,
Expand All @@ -110,6 +114,7 @@
},
"SecurityCtrlrIdentity": {
"variable_name": "Identity",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "string"
Expand All @@ -127,6 +132,7 @@
},
"MaxCertificateChainSize": {
"variable_name": "MaxCertificateChainSize",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "integer"
Expand All @@ -142,6 +148,7 @@
},
"OrganizationName": {
"variable_name": "OrganizationName",
"source": "OCPP",
"characteristics": {
"supportsMonitoring": true,
"dataType": "string"
Expand All @@ -159,6 +166,7 @@
},
"SecurityProfile": {
"variable_name": "SecurityProfile",
"source": "OCPP",
"characteristics": {
"minLimit": 1,
"maxLimit": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE VARIABLE

Check failure on line 1 in config/v201/device_model_migrations/2_down-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_down-variable_source.sql#L1

Expected SET ANSI_NULLS ON near top of file

Check failure on line 1 in config/v201/device_model_migrations/2_down-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_down-variable_source.sql#L1

Expected SET QUOTED_IDENTIFIER ON near top of file

Check failure on line 1 in config/v201/device_model_migrations/2_down-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_down-variable_source.sql#L1

Expected SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED near top of file
DROP COLUMN SOURCE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE VARIABLE

Check failure on line 1 in config/v201/device_model_migrations/2_up-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_up-variable_source.sql#L1

Expected SET ANSI_NULLS ON near top of file

Check failure on line 1 in config/v201/device_model_migrations/2_up-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_up-variable_source.sql#L1

Expected SET NOCOUNT ON near top of file

Check failure on line 1 in config/v201/device_model_migrations/2_up-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_up-variable_source.sql#L1

Expected SET QUOTED_IDENTIFIER ON near top of file

Check failure on line 1 in config/v201/device_model_migrations/2_up-variable_source.sql

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

config/v201/device_model_migrations/2_up-variable_source.sql#L1

Expected SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED near top of file
ADD COLUMN SOURCE TEXT;
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
25 changes: 12 additions & 13 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;
DeviceModelMap device_model_map;
std::unique_ptr<DeviceModelInterface> device_model;

/// \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 @@ -159,11 +159,10 @@ class DeviceModel {
if (response == GetVariableStatusEnum::Accepted) {
return to_specific_type<T>(value);
} else {
EVLOG_critical
<< "Directly requested value for ComponentVariable that doesn't exist in the device model storage: "
<< component_variable;
EVLOG_critical << "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 +189,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 @@ -34,36 +33,37 @@ struct VariableMonitoringPeriodic {
struct VariableMetaData {
VariableCharacteristics characteristics;
std::unordered_map<int64_t, VariableMonitoringMeta> monitors;
std::optional<std::string> source;
};

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 @@ -140,5 +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
2 changes: 2 additions & 0 deletions include/ocpp/v201/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef OCPP_V201_ENUMS_HPP
#define OCPP_V201_ENUMS_HPP

#include <string>

namespace ocpp {
namespace v201 {

Expand Down
6 changes: 4 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 Expand Up @@ -93,6 +93,8 @@ struct DeviceModelVariable {
std::optional<std::string> default_actual_value;
/// \brief Config monitors, if any
std::vector<VariableMonitoringMeta> monitors;
/// \brief Source of the variable.
std::optional<std::string> source;
};

/// \brief Convert from json to a ComponentKey struct.
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
Loading
Loading