Skip to content

Commit

Permalink
Binding json default construct to use initializer list based constructor
Browse files Browse the repository at this point in the history
GCC 7.3 generates a null string for json({}), and not {}.
With this workaround, the right constructor is selected providing {}.

This is based on #178 but fixes the code generator to extend the fix to all messages of OCPP 1.6 and 2.0.1

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored and Pietfried committed Oct 2, 2023
1 parent dedfa94 commit f04fc57
Show file tree
Hide file tree
Showing 45 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions lib/ocpp/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ std::ostream& operator<<(std::ostream& os, const SessionStartedReason& session_s

void to_json(json& j, const Current& k) {
// the required parts of the type
j = json({});
j = json({}, true);
// the optional parts of the type
if (k.DC) {
j["DC"] = k.DC.value();
Expand Down Expand Up @@ -204,7 +204,7 @@ std::ostream& operator<<(std::ostream& os, const Current& k) {

void to_json(json& j, const Voltage& k) {
// the required parts of the type
j = json({});
j = json({}, true);
// the optional parts of the type
if (k.DC) {
j["DC"] = k.DC.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ json ChargePointConfiguration::get_user_config() {
return json::parse(user_config_file);
}

return json({});
return json({}, true);
}

void ChargePointConfiguration::setInUserConfig(std::string profile, std::string key, const json value) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ void ChargePointImpl::message_callback(const std::string& message) {
EVLOG_warning << "Received an unsupported message: " << enhanced_message.messageType;
// FIXME(kai): however, only send a CALLERROR when it is a CALL message we just received
if (enhanced_message.messageTypeId == MessageTypeId::CALL) {
auto call_error = CallError(enhanced_message.uniqueId, "NotSupported", "", json({}));
auto call_error = CallError(enhanced_message.uniqueId, "NotSupported", "", json({}, true));
this->send(call_error);
} else if (enhanced_message.messageTypeId == MessageTypeId::CALLERROR) {
auto call_messagetype =
Expand Down Expand Up @@ -953,7 +953,7 @@ void ChargePointImpl::message_callback(const std::string& message) {
EVLOG_error << "JSON exception during handling of message: " << e.what();
if (json_message.is_array() && json_message.size() > MESSAGE_ID) {
auto call_error = CallError(MessageId(json_message.at(MESSAGE_ID).get<std::string>()), "FormationViolation",
e.what(), json({}));
e.what(), json({}, true));
this->send(call_error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/ClearCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std::string ClearCacheRequest::get_type() const {

void to_json(json& j, const ClearCacheRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/ClearChargingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string ClearChargingProfileRequest::get_type() const {

void to_json(json& j, const ClearChargingProfileRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.id) {
j["id"] = k.id.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/DiagnosticsStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string DiagnosticsStatusNotificationResponse::get_type() const {

void to_json(json& j, const DiagnosticsStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/FirmwareStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::string FirmwareStatusNotificationResponse::get_type() const {

void to_json(json& j, const FirmwareStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ocpp/v16/messages/GetConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string GetConfigurationRequest::get_type() const {

void to_json(json& j, const GetConfigurationRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.key) {
if (j.size() == 0) {
Expand Down Expand Up @@ -60,7 +60,7 @@ std::string GetConfigurationResponse::get_type() const {

void to_json(json& j, const GetConfigurationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.configurationKey) {
if (j.size() == 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/GetDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::string GetDiagnosticsResponse::get_type() const {

void to_json(json& j, const GetDiagnosticsResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.fileName) {
j["fileName"] = k.fileName.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/GetLocalListVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std::string GetLocalListVersionRequest::get_type() const {

void to_json(json& j, const GetLocalListVersionRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/Heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std::string HeartbeatRequest::get_type() const {

void to_json(json& j, const HeartbeatRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/LogStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string LogStatusNotificationResponse::get_type() const {

void to_json(json& j, const LogStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/MeterValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::string MeterValuesResponse::get_type() const {

void to_json(json& j, const MeterValuesResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/SecurityEventNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string SecurityEventNotificationResponse::get_type() const {

void to_json(json& j, const SecurityEventNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/SignedFirmwareStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string SignedFirmwareStatusNotificationResponse::get_type() const {

void to_json(json& j, const SignedFirmwareStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/StatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::string StatusNotificationResponse::get_type() const {

void to_json(json& j, const StatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/StopTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::string StopTransactionResponse::get_type() const {

void to_json(json& j, const StopTransactionResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.idTagInfo) {
j["idTagInfo"] = k.idTagInfo.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/messages/UpdateFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string UpdateFirmwareResponse::get_type() const {

void to_json(json& j, const UpdateFirmwareResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
(void)k; // no elements to unpack, silence unused parameter warning
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void ChargePoint::message_callback(const std::string& message) {
const auto error_message = "Received other message than BootNotificationResponse before "
"having received an accepted BootNotificationResponse";
EVLOG_warning << error_message;
const auto call_error = CallError(enhanced_message.uniqueId, "SecurityError", "", json({}));
const auto call_error = CallError(enhanced_message.uniqueId, "SecurityError", "", json({}, true));
this->send(call_error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/ClearCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string ClearCacheRequest::get_type() const {

void to_json(json& j, const ClearCacheRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/ClearChargingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string ClearChargingProfileRequest::get_type() const {

void to_json(json& j, const ClearChargingProfileRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/ClearedChargingLimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string ClearedChargingLimitResponse::get_type() const {

void to_json(json& j, const ClearedChargingLimitResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/CostUpdated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string CostUpdatedResponse::get_type() const {

void to_json(json& j, const CostUpdatedResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/FirmwareStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string FirmwareStatusNotificationResponse::get_type() const {

void to_json(json& j, const FirmwareStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/GetInstalledCertificateIds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string GetInstalledCertificateIdsRequest::get_type() const {

void to_json(json& j, const GetInstalledCertificateIdsRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/GetLocalListVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string GetLocalListVersionRequest::get_type() const {

void to_json(json& j, const GetLocalListVersionRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/GetTransactionStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string GetTransactionStatusRequest::get_type() const {

void to_json(json& j, const GetTransactionStatusRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/Heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string HeartbeatRequest::get_type() const {

void to_json(json& j, const HeartbeatRequest& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/LogStatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string LogStatusNotificationResponse::get_type() const {

void to_json(json& j, const LogStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/MeterValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::string MeterValuesResponse::get_type() const {

void to_json(json& j, const MeterValuesResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyChargingLimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::string NotifyChargingLimitResponse::get_type() const {

void to_json(json& j, const NotifyChargingLimitResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyCustomerInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string NotifyCustomerInformationResponse::get_type() const {

void to_json(json& j, const NotifyCustomerInformationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyDisplayMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::string NotifyDisplayMessagesResponse::get_type() const {

void to_json(json& j, const NotifyDisplayMessagesResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string NotifyEventResponse::get_type() const {

void to_json(json& j, const NotifyEventResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyMonitoringReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::string NotifyMonitoringReportResponse::get_type() const {

void to_json(json& j, const NotifyMonitoringReportResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/NotifyReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::string NotifyReportResponse::get_type() const {

void to_json(json& j, const NotifyReportResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::string PublishFirmwareStatusNotificationResponse::get_type() const {

void to_json(json& j, const PublishFirmwareStatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/ReportChargingProfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::string ReportChargingProfilesResponse::get_type() const {

void to_json(json& j, const ReportChargingProfilesResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/ReservationStatusUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string ReservationStatusUpdateResponse::get_type() const {

void to_json(json& j, const ReservationStatusUpdateResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/SecurityEventNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string SecurityEventNotificationResponse::get_type() const {

void to_json(json& j, const SecurityEventNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/messages/StatusNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string StatusNotificationResponse::get_type() const {

void to_json(json& j, const StatusNotificationResponse& k) {
// the required parts of the message
j = json({});
j = json({}, true);
// the optional parts of the message
if (k.customData) {
j["customData"] = k.customData.value();
Expand Down
Loading

0 comments on commit f04fc57

Please sign in to comment.