From 915864c6ba58fa8c7e655bbcee5bdddfb6d2f197 Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Thu, 21 Nov 2024 14:59:27 +0100 Subject: [PATCH] Improve const awareness Signed-off-by: Marc Emmers --- include/ocpp/v201/charge_point.hpp | 8 ++++---- include/ocpp/v201/connectivity_manager.hpp | 6 +++--- lib/ocpp/v201/charge_point.cpp | 4 ++-- lib/ocpp/v201/connectivity_manager.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/ocpp/v201/charge_point.hpp b/include/ocpp/v201/charge_point.hpp index 1c9de4017..e247b6dde 100644 --- a/include/ocpp/v201/charge_point.hpp +++ b/include/ocpp/v201/charge_point.hpp @@ -352,13 +352,13 @@ class ChargePointInterface { /// present. This returns the value from the cached network connection profiles. \param /// network_configuration_priority \return virtual std::optional - get_network_connection_profile(const int32_t configuration_slot) = 0; + get_network_connection_profile(const int32_t configuration_slot) const = 0; /// \brief Get the priority of the given configuration slot. /// \param configuration_slot The configuration slot to get the priority from. /// \return The priority if the configuration slot exists. /// - virtual std::optional get_priority_from_configuration_slot(const int configuration_slot) = 0; + virtual std::optional get_priority_from_configuration_slot(const int configuration_slot) const = 0; /// @brief Get the network connection slots sorted by priority. /// Each item in the vector contains the configured configuration slots, where the slot with index 0 has the highest @@ -940,9 +940,9 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa std::vector get_all_composite_schedules(const int32_t duration, const ChargingRateUnitEnum& unit) override; - std::optional get_network_connection_profile(const int32_t configuration_slot) override; + std::optional get_network_connection_profile(const int32_t configuration_slot) const override; - std::optional get_priority_from_configuration_slot(const int configuration_slot) override; + std::optional get_priority_from_configuration_slot(const int configuration_slot) const override; const std::vector& get_network_connection_slots() const override; diff --git a/include/ocpp/v201/connectivity_manager.hpp b/include/ocpp/v201/connectivity_manager.hpp index 7ecc736a9..80c055a10 100644 --- a/include/ocpp/v201/connectivity_manager.hpp +++ b/include/ocpp/v201/connectivity_manager.hpp @@ -88,13 +88,13 @@ class ConnectivityManager { /// \brief Gets the cached NetworkConnectionProfile based on the given \p configuration_slot. /// This returns the value from the cached network connection profiles. /// \return Returns a profile if the slot is found - std::optional get_network_connection_profile(const int32_t configuration_slot); + std::optional get_network_connection_profile(const int32_t configuration_slot) const; /// \brief Get the priority of the given configuration slot. /// \param configuration_slot The configuration slot to get the priority from. /// \return The priority if the configuration slot exists. /// - std::optional get_priority_from_configuration_slot(const int configuration_slot); + std::optional get_priority_from_configuration_slot(const int configuration_slot) const; /// @brief Get the network connection slots sorted by priority. /// Each item in the vector contains the configured configuration slots, where the slot with index 0 has the highest @@ -174,7 +174,7 @@ class ConnectivityManager { /// \brief Get the active network configuration slot in use. /// \return The active slot the network is connected to or the pending slot. /// - int get_active_network_configuration_slot(); + int get_active_network_configuration_slot() const; /// /// \brief Get the network configuration slot of the given priority. diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 5eaaf6e6b..3afa446f3 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -4453,11 +4453,11 @@ std::vector ChargePoint::get_all_composite_schedules(const in return composite_schedules; } -std::optional ChargePoint::get_network_connection_profile(const int32_t configuration_slot) { +std::optional ChargePoint::get_network_connection_profile(const int32_t configuration_slot) const { return this->connectivity_manager->get_network_connection_profile(configuration_slot); } -std::optional ChargePoint::get_priority_from_configuration_slot(const int configuration_slot) { +std::optional ChargePoint::get_priority_from_configuration_slot(const int configuration_slot) const { return this->connectivity_manager->get_priority_from_configuration_slot(configuration_slot); } diff --git a/lib/ocpp/v201/connectivity_manager.cpp b/lib/ocpp/v201/connectivity_manager.cpp index 7abd4ebc7..82e39a227 100644 --- a/lib/ocpp/v201/connectivity_manager.cpp +++ b/lib/ocpp/v201/connectivity_manager.cpp @@ -71,7 +71,7 @@ void ConnectivityManager::set_configure_network_connection_profile_callback( } std::optional -ConnectivityManager::get_network_connection_profile(const int32_t configuration_slot) { +ConnectivityManager::get_network_connection_profile(const int32_t configuration_slot) const { for (const auto& network_profile : this->cached_network_connection_profiles) { if (network_profile.configurationSlot == configuration_slot) { @@ -88,7 +88,7 @@ ConnectivityManager::get_network_connection_profile(const int32_t configuration_ return std::nullopt; } -std::optional ConnectivityManager::get_priority_from_configuration_slot(const int configuration_slot) { +std::optional ConnectivityManager::get_priority_from_configuration_slot(const int configuration_slot) const { auto it = std::find(this->network_connection_slots.begin(), this->network_connection_slots.end(), configuration_slot); if (it != this->network_connection_slots.end()) { @@ -98,7 +98,7 @@ std::optional ConnectivityManager::get_priority_from_configuration_slot return std::nullopt; } -int ConnectivityManager::get_active_network_configuration_slot() { +int ConnectivityManager::get_active_network_configuration_slot() const { return this->network_connection_slots.at(this->active_network_configuration_priority); }