Skip to content

Commit

Permalink
Add clang-format linter workflow (#140)
Browse files Browse the repository at this point in the history
* Add clang-format linter workflow
* Fix clang-format errors

---------

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass authored Aug 17, 2023
1 parent 4660464 commit 315842e
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 97 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint
on: [workflow_dispatch, pull_request]

jobs:
lint:
name: Lint
strategy:
matrix:
os: [large-ubuntu-22.04-s]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout libocpp
uses: actions/checkout@v3
with:
path: source
- name: Run clang-format
uses: everest/everest-ci/github-actions/run-clang-format@v1.0.0
with:
source-dir: source
extensions: hpp,cpp
exclude: cache
2 changes: 1 addition & 1 deletion include/ocpp/common/charging_station_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ChargingStationBase {
/// meter value should be sent, else std::nullopt
std::optional<DateTime> get_next_clock_aligned_meter_value_timestamp(const int32_t interval);

/// \brief Generates a uuid
/// \brief Generates a uuid
/// \return uuid
std::string uuid();

Expand Down
2 changes: 1 addition & 1 deletion include/ocpp/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <chrono>
#include <cstddef>
#include <iostream>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <optional>

#include <nlohmann/json_fwd.hpp>

Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/common/websocket/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Websocket {
/// \brief connect to a websocket (TLS or non-TLS depending on the central system uri in the configuration).
bool connect();

void set_connection_options(const WebsocketConnectionOptions &connection_options);
void set_connection_options(const WebsocketConnectionOptions& connection_options);

/// \brief disconnect the websocket
void disconnect(websocketpp::close::status::value code);
Expand Down Expand Up @@ -58,7 +58,7 @@ class Websocket {
void set_websocket_ping_interval(int32_t interval_s);

/// \brief set the \p authorization_key of the connection_options
void set_authorization_key(const std::string &authorization_key);
void set_authorization_key(const std::string& authorization_key);
};

} // namespace ocpp
Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/common/websocket/websocket_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class WebsocketBase {
virtual bool connect() = 0;

/// \brief sets this connection_options to the given \p connection_options and resets the connection_attempts
void set_connection_options(const WebsocketConnectionOptions &connection_options);
void set_connection_options(const WebsocketConnectionOptions& connection_options);

/// \brief reconnect the websocket after the delay
virtual void reconnect(std::error_code reason, long delay) = 0;
Expand Down Expand Up @@ -118,7 +118,7 @@ class WebsocketBase {
void set_websocket_ping_interval(int32_t interval_s);

/// \brief set the \p authorization_key of the connection_options
void set_authorization_key(const std::string &authorization_key);
void set_authorization_key(const std::string& authorization_key);
};

} // namespace ocpp
Expand Down
2 changes: 1 addition & 1 deletion include/ocpp/common/websocket/websocket_tls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WebsocketTLS : public WebsocketBase {
tls_client wss_client;
std::shared_ptr<PkiHandler> pki_handler;
websocketpp::lib::shared_ptr<websocketpp::lib::thread> websocket_thread;

/// \brief Extracts the hostname from the provided \p uri
/// FIXME(kai): this only works with a very limited subset of hostnames and should be extended to work spec conform
/// \returns the extracted hostname
Expand Down
2 changes: 1 addition & 1 deletion include/ocpp/v16/charge_point_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ChargePointConfiguration {
KeyValue getSupportedCiphers13KeyValue();
bool getUseSslDefaultVerifyPaths();
KeyValue getUseSslDefaultVerifyPathsKeyValue();

int32_t getRetryBackoffRandomRange();
void setRetryBackoffRandomRange(int32_t retry_backoff_random_range);
KeyValue getRetryBackoffRandomRangeKeyValue();
Expand Down
14 changes: 6 additions & 8 deletions include/ocpp/v16/charge_point_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ class ChargePointImpl : ocpp::ChargingStationBase {
std::function<GetLogResponse(GetLogRequest msg)> upload_logs_callback;
std::function<void(int32_t connection_timeout)> set_connection_timeout_callback;

std::function<void(const int32_t connector, const int32_t transaction_id)>
transaction_started_callback;
std::function<void(const int32_t connector, const int32_t transaction_id)> transaction_started_callback;

// iso15118 callback
std::function<void(const int32_t connector, const ocpp::v201::Get15118EVCertificateResponse& certificate_response,
Expand All @@ -190,8 +189,8 @@ class ChargePointImpl : ocpp::ChargingStationBase {
void update_meter_values_sample_interval();
void update_clock_aligned_meter_values_interval();
std::optional<MeterValue> get_latest_meter_value(int32_t connector,
std::vector<MeasurandWithPhase> values_of_interest,
ReadingContext context);
std::vector<MeasurandWithPhase> values_of_interest,
ReadingContext context);
MeterValue get_signed_meter_value(const std::string& signed_value, const ReadingContext& context,
const ocpp::DateTime& datetime);
void send_meter_value(int32_t connector, MeterValue meter_value);
Expand Down Expand Up @@ -448,8 +447,7 @@ class ChargePointImpl : ocpp::ChargingStationBase {
/// \param signed_meter_value e.g. in OCMF format
void on_transaction_stopped(const int32_t connector, const std::string& session_id, const Reason& reason,
ocpp::DateTime timestamp, float energy_wh_import,
std::optional<CiString<20>> id_tag_end,
std::optional<std::string> signed_meter_value);
std::optional<CiString<20>> id_tag_end, std::optional<std::string> signed_meter_value);

/// \brief This function should be called when EV indicates that it suspends charging on the given \p connector
/// \param connector
Expand Down Expand Up @@ -649,8 +647,8 @@ class ChargePointImpl : ocpp::ChargingStationBase {
const ocpp::v201::Get15118EVCertificateResponse& certificate_response,
const ocpp::v201::CertificateActionEnum& certificate_action)>& callback);

// \brief registers a \p callback function that can be used to publish the response when transaction starts respone is received
// \param callback
// \brief registers a \p callback function that can be used to publish the response when transaction starts respone
// is received \param callback
void register_transaction_started_callback(
const std::function<void(int32_t connector, int32_t transaction_id)>& callback);
};
Expand Down
10 changes: 5 additions & 5 deletions include/ocpp/v16/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ std::ostream& operator<<(std::ostream& os, const SupportedFeatureProfiles& suppo
/// \brief Contains the different connection states of the charge point
enum ChargePointConnectionState {
Disconnected, // state when disconnected
Connected, // state when ws is connected
Booted, // state when ws is connected and BootNotifcation had been Accepted
Pending, // state when ws is connected and state when BootNotifcation is Pending
Rejected, // state when ws is connected and state when BootNotifcation had been Rejected
Connected, // state when ws is connected
Booted, // state when ws is connected and BootNotifcation had been Accepted
Pending, // state when ws is connected and state when BootNotifcation is Pending
Rejected, // state when ws is connected and state when BootNotifcation had been Rejected
};
namespace conversions {
/// \brief Converts the given ChargePointConnectionState \p e to std::string
Expand All @@ -165,7 +165,7 @@ std::ostream& operator<<(std::ostream& os, const ChargePointConnectionState& cha

/// \brief Combines a Measurand with an optional Phase
struct MeasurandWithPhase {
Measurand measurand; ///< A OCPP Measurand
Measurand measurand; ///< A OCPP Measurand
std::optional<Phase> phase; ///< If applicable and available a Phase

/// \brief Comparison operator== between this MeasurandWithPhase and the given \p measurand_with_phase
Expand Down
10 changes: 5 additions & 5 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ struct Callbacks {
std::optional<std::function<SetNetworkProfileStatusEnum(
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
validate_network_profile_callback;
std::optional<std::function<bool(const NetworkConnectionProfile &network_connection_profile)>> configure_network_connection_profile_callback;
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile)>>
configure_network_connection_profile_callback;
};

/// \brief Class implements OCPP2.0.1 Charging Station
Expand Down Expand Up @@ -122,15 +123,15 @@ class ChargePoint : ocpp::ChargingStationBase {
/// central system uri ofthe connection options will not contain ws:// or wss:// because this method removes it if
/// present \param network_configuration_priority \return
std::optional<NetworkConnectionProfile> get_network_connection_profile(const int32_t configuration_slot);
/// \brief Moves websocket network_configuration_priority to next profile
/// \brief Moves websocket network_configuration_priority to next profile
void next_network_configuration_priority();
void handle_message(const json& json_message, const MessageType& message_type);
void message_callback(const std::string& message);
void update_aligned_data_interval();
bool is_change_availability_possible(const ChangeAvailabilityRequest& req);
void handle_scheduled_change_availability_requests(const int32_t evse_id);
void handle_variable_changed(const SetVariableData& set_variable_data);
bool validate_set_variable(const SetVariableData &set_variable_data);
bool validate_set_variable(const SetVariableData& set_variable_data);

///
/// \brief Get evseid for the given transaction id.
Expand Down Expand Up @@ -287,8 +288,7 @@ class ChargePoint : ocpp::ChargingStationBase {
const MeterValue& meter_start, const IdToken& id_token,
const std::optional<IdToken>& group_id_token,
const std::optional<int32_t>& reservation_id,
const std::optional<int32_t>& remote_start_id,
const ChargingStateEnum charging_state);
const std::optional<int32_t>& remote_start_id, const ChargingStateEnum charging_state);

/// \brief Event handler that should be called when a transaction has finished
/// \param evse_id
Expand Down
6 changes: 3 additions & 3 deletions include/ocpp/v201/ctrlr_component_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern const Component& SecurityCtrlr;
extern const Component& SmartChargingCtrlr;
extern const Component& TariffCostCtrlr;
extern const Component& TxCtrlr;
} // ControllerComponents
} // namespace ControllerComponents

// Provides access to standardized variables of OCPP2.0.1 spec
namespace ControllerComponentVariables {
Expand Down Expand Up @@ -192,8 +192,8 @@ extern const ComponentVariable& TxBeforeAcceptedEnabled;
extern const ComponentVariable& TxStartPoint;
extern const ComponentVariable& TxStopPoint;

} // namespace ComponentVariables
} // namespace ocpp
} // namespace ControllerComponentVariables
} // namespace v201
} // namespace ocpp

#endif // OCPP_V201_CTRLR_COMPONENT_VARIABLES
6 changes: 3 additions & 3 deletions include/ocpp/v201/device_model_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ inline bool operator<(const Variable& lhs, const Variable& rhs) {
return lhs.instance < rhs.instance;
};

inline bool operator==(const ComponentVariable& lhs, const ComponentVariable &rhs) {
inline bool operator==(const ComponentVariable& lhs, const ComponentVariable& rhs) {
return lhs.component == rhs.component and lhs.variable == rhs.variable;
}

inline bool operator<(const ComponentVariable& lhs, const ComponentVariable &rhs) {
inline bool operator<(const ComponentVariable& lhs, const ComponentVariable& rhs) {
if (lhs.component == rhs.component) {
return lhs.variable < rhs.variable;
}
return lhs.component < rhs.component;
return lhs.component < rhs.component;
}

using VariableMap = std::map<Variable, VariableMetaData>;
Expand Down
6 changes: 3 additions & 3 deletions include/ocpp/v201/evse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Evse {
EVSE get_evse_info();

/// \brief Returns the number of connectors of this EVSE
/// \return
/// \return
int32_t get_number_of_connectors();

/// \brief Returns a reference to the sampled meter values timer
Expand All @@ -64,8 +64,8 @@ class Evse {
/// \param sampled_data_tx_updated_interval Interval between sampling of metering (or other) data, intended to be
/// transmitted via TransactionEventRequest (eventType = Updated) messages
void open_transaction(const std::string& transaction_id, const int32_t connector_id, const DateTime& timestamp,
const MeterValue& meter_start, const IdToken& id_token, const std::optional<IdToken> &group_id_token,
const std::optional<int32_t> reservation_id,
const MeterValue& meter_start, const IdToken& id_token,
const std::optional<IdToken>& group_id_token, const std::optional<int32_t> reservation_id,
const int32_t sampled_data_tx_updated_interval);

/// \brief Closes the transaction on this evse by adding the given \p timestamp \p meter_stop and \p reason .
Expand Down
11 changes: 5 additions & 6 deletions lib/ocpp/common/charging_station_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ std::optional<DateTime> ChargingStationBase::get_next_clock_aligned_meter_value_
const auto now = date::utc_clock::now();
const auto midnight = date::floor<date::days>(now) + std::chrono::seconds(date::get_tzdb().leap_seconds.size());
const auto diff = now - midnight;
const auto start = std::chrono::duration_cast<std::chrono::seconds>(diff / interval) *
interval +
std::chrono::seconds(interval);
const auto start =
std::chrono::duration_cast<std::chrono::seconds>(diff / interval) * interval + std::chrono::seconds(interval);
const auto clock_aligned_meter_values_time_point = DateTime(midnight + start);
EVLOG_debug << "Sending clock aligned meter values every " << interval
<< " seconds, starting at " << ocpp::DateTime(clock_aligned_meter_values_time_point)
<< ". This amounts to " << seconds_in_a_day / interval << " samples per day.";
EVLOG_debug << "Sending clock aligned meter values every " << interval << " seconds, starting at "
<< ocpp::DateTime(clock_aligned_meter_values_time_point) << ". This amounts to "
<< seconds_in_a_day / interval << " samples per day.";
return clock_aligned_meter_values_time_point;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/ocpp/common/pki_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ InstallCertificateResult PkiHandler::installRootCertificate(const std::string& r
<< ocpp::conversions::certificate_type_to_string(certificateType);
InstallCertificateResult installCertificateResult = InstallCertificateResult::Valid;

if (certificateStoreMaxLength &&
this->getCaCertificates().size() >= size_t(certificateStoreMaxLength.value())) {
if (certificateStoreMaxLength && this->getCaCertificates().size() >= size_t(certificateStoreMaxLength.value())) {
return InstallCertificateResult::CertificateStoreMaxLengthExceeded;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/ocpp/common/websocket/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool Websocket::connect() {
return this->websocket->connect();
}

void Websocket::set_connection_options(const WebsocketConnectionOptions &connection_options) {
void Websocket::set_connection_options(const WebsocketConnectionOptions& connection_options) {
this->websocket->set_connection_options(connection_options);
}

Expand All @@ -58,7 +58,8 @@ void Websocket::register_connected_callback(const std::function<void(const int s
});
}

void Websocket::register_closed_callback(const std::function<void(const websocketpp::close::status::value reason)>& callback) {
void Websocket::register_closed_callback(
const std::function<void(const websocketpp::close::status::value reason)>& callback) {
this->closed_callback = callback;
this->websocket->register_closed_callback([this](const websocketpp::close::status::value reason) {
this->logging->sys("Disconnected");
Expand All @@ -82,7 +83,7 @@ void Websocket::set_websocket_ping_interval(int32_t interval_s) {
this->websocket->set_websocket_ping_interval(interval_s);
}

void Websocket::set_authorization_key(const std::string &authorization_key) {
void Websocket::set_authorization_key(const std::string& authorization_key) {
this->websocket->set_authorization_key(authorization_key);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/ocpp/common/websocket/websocket_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WebsocketBase::WebsocketBase(const WebsocketConnectionOptions& connection_option
WebsocketBase::~WebsocketBase() {
}

void WebsocketBase::set_connection_options(const WebsocketConnectionOptions &connection_options) {
void WebsocketBase::set_connection_options(const WebsocketConnectionOptions& connection_options) {
this->connection_attempts = 0;
this->connection_options = connection_options;
}
Expand All @@ -36,7 +36,8 @@ void WebsocketBase::register_connected_callback(const std::function<void(const i
this->connected_callback = callback;
}

void WebsocketBase::register_closed_callback(const std::function<void(const websocketpp::close::status::value reason)>& callback) {
void WebsocketBase::register_closed_callback(
const std::function<void(const websocketpp::close::status::value reason)>& callback) {
this->closed_callback = callback;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/common/websocket/websocket_tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void WebsocketTLS::reconnect(std::error_code reason, long delay) {
EVLOG_info << "Not reconnecting because the websocket is being shutdown.";
return;
}

// TODO(kai): notify message queue that connection is down and a reconnect is imminent?
{
std::lock_guard<std::mutex> lk(this->reconnect_mutex);
Expand Down
3 changes: 1 addition & 2 deletions lib/ocpp/v16/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ void TransactionHandler::change_meter_values_sample_intervals(int32_t interval)
}
}

std::optional<CiString<20>>
TransactionHandler::get_authorized_id_tag(const std::string& stop_transaction_message_id) {
std::optional<CiString<20>> TransactionHandler::get_authorized_id_tag(const std::string& stop_transaction_message_id) {
for (const auto& transaction : this->stopped_transactions) {
if (transaction->get_stop_transaction_message_id() == stop_transaction_message_id) {
transaction->get_id_tag();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/types.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
#include <optional>
#include <chrono>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
Expand Down
Loading

0 comments on commit 315842e

Please sign in to comment.