Skip to content

Commit

Permalink
add error attribute vendor_id
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Heinrich <[email protected]>

add global_error_state_monitor

Signed-off-by: Andreas Heinrich <[email protected]>

use build kit branch

Signed-off-by: Andreas Heinrich <[email protected]>

add example module ExampleErrorGlobalSubscriber

Signed-off-by: Andreas Heinrich <[email protected]>

run clang-format

Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm committed Jun 17, 2024
1 parent 461cde5 commit 07d35ac
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 28 deletions.
18 changes: 12 additions & 6 deletions modules/ErrorHistory/ErrorDatabaseSqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void ErrorDatabaseSqlite::reset_database() {
"timestamp TEXT NOT NULL,"
"severity TEXT NOT NULL,"
"state TEXT NOT NULL,"
"sub_type TEXT NOT NULL);";
"sub_type TEXT NOT NULL,"
"vendor_id TEXT NOT NULL);";
db.exec(sql);
} catch (std::exception& e) {
EVLOG_error << "Error creating database: " << e.what();
Expand All @@ -102,8 +103,8 @@ void ErrorDatabaseSqlite::add_error_without_mutex(Everest::error::ErrorPtr error
try {
SQLite::Database db(this->db_path.string(), SQLite::OPEN_READWRITE);
std::string sql = "INSERT INTO errors(uuid, type, description, message, origin_module, origin_implementation, "
"timestamp, severity, state, sub_type) VALUES(";
sql += "?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10);";
"timestamp, severity, state, sub_type, vendor_id) VALUES(";
sql += "?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11);";
SQLite::Statement stmt(db, sql);
stmt.bind(1, error->uuid.to_string());
stmt.bind(2, error->type);
Expand All @@ -115,6 +116,7 @@ void ErrorDatabaseSqlite::add_error_without_mutex(Everest::error::ErrorPtr error
stmt.bind(8, Everest::error::severity_to_string(error->severity));
stmt.bind(9, Everest::error::state_to_string(error->state));
stmt.bind(10, error->sub_type);
stmt.bind(11, error->vendor_id);
stmt.exec();
} catch (std::exception& e) {
EVLOG_error << "Error adding error to database: " << e.what();
Expand Down Expand Up @@ -161,6 +163,9 @@ std::string ErrorDatabaseSqlite::filter_to_sql_condition(const Everest::error::E
case Everest::error::FilterType::SubType: {
condition = "(sub_type = '" + filter.get_sub_type_filter().value + "')";
} break;
case Everest::error::FilterType::VendorId: {
condition = "(vendor_id = '" + filter.get_vendor_id_filter().value + "')";
} break;
}
return condition;
}
Expand Down Expand Up @@ -211,9 +216,10 @@ std::list<Everest::error::ErrorPtr> ErrorDatabaseSqlite::get_errors(const std::o
const Everest::error::State err_state = Everest::error::string_to_state(stmt.getColumn("state").getText());
const Everest::error::ErrorHandle err_handle(Everest::error::ErrorHandle(stmt.getColumn("uuid").getText()));
const Everest::error::ErrorSubType err_sub_type(stmt.getColumn("sub_type").getText());
Everest::error::ErrorPtr error =
std::make_shared<Everest::error::Error>(err_type, err_sub_type, err_msg, err_description, err_origin,
err_severity, err_timestamp, err_handle, err_state);
const std::string err_vendor_id = stmt.getColumn("vendor_id").getText();
Everest::error::ErrorPtr error = std::make_shared<Everest::error::Error>(
err_type, err_sub_type, err_msg, err_description, err_origin, err_vendor_id, err_severity,
err_timestamp, err_handle, err_state);
result.push_back(error);
}
} catch (std::exception& e) {
Expand Down
6 changes: 3 additions & 3 deletions modules/ErrorHistory/tests/error_database_sqlite_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
WHEN("Adding an error") {
std::vector<Everest::error::ErrorPtr> test_errors = {std::make_shared<Everest::error::Error>(
"test_type", "test_sub_type", "test_message", "test_description",
ImplementationIdentifier("test_origin_module", "test_origin_implementation"),
ImplementationIdentifier("test_origin_module", "test_origin_implementation"), "everest-test",
Everest::error::Severity::Low, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::Active)};
db.add_error(test_errors.at(0));
Expand All @@ -32,12 +32,12 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
std::vector<Everest::error::ErrorPtr> test_errors = {
std::make_shared<Everest::error::Error>(
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::High, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::ClearedByModule),
std::make_shared<Everest::error::Error>(
"test_type_b", "test_sub_type_b", "test_message_b", "test_description_b",
ImplementationIdentifier("test_origin_module_b", "test_origin_implementation_b"),
ImplementationIdentifier("test_origin_module_b", "test_origin_implementation_b"), "everest-test",
Everest::error::Severity::Medium, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::ClearedByReboot)};
for (Everest::error::ErrorPtr error : test_errors) {
Expand Down
24 changes: 12 additions & 12 deletions modules/ErrorHistory/tests/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,73 @@ std::vector<Everest::error::ErrorPtr> get_test_errors() {
return {// index 0
std::make_shared<Everest::error::Error>(
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::Low, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::ClearedByModule),
// index 1
std::make_shared<Everest::error::Error>(
"test_type_b", "test_sub_type_b", "test_message_b", "test_description_b",
ImplementationIdentifier("test_origin_module_b", "test_origin_implementation_b"),
ImplementationIdentifier("test_origin_module_b", "test_origin_implementation_b"), "everest-test",
Everest::error::Severity::Low, date::utc_clock::now() + std::chrono::hours(1), Everest::error::UUID(),
Everest::error::State::ClearedByModule),
// index 2
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_c", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::Low, date::utc_clock::now() + std::chrono::hours(2), Everest::error::UUID(),
Everest::error::State::ClearedByModule),
// index 3
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_c", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"),
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"), "everest-test",
Everest::error::Severity::Low, date::utc_clock::now() + std::chrono::hours(3), Everest::error::UUID(),
Everest::error::State::Active),
// index 4
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_a", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::Medium, date::utc_clock::now() + std::chrono::hours(4),
Everest::error::UUID(), Everest::error::State::Active),
// index 5
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_a", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"),
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"), "everest-test",
Everest::error::Severity::Medium, date::utc_clock::now() + std::chrono::hours(5),
Everest::error::UUID(), Everest::error::State::Active),
// index 6
std::make_shared<Everest::error::Error>(
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::Medium, date::utc_clock::now() + std::chrono::hours(6),
Everest::error::UUID(), Everest::error::State::ClearedByReboot),
// index 7
std::make_shared<Everest::error::Error>(
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"),
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"), "everest-test",
Everest::error::Severity::Medium, date::utc_clock::now() + std::chrono::hours(7),
Everest::error::UUID(), Everest::error::State::ClearedByReboot),
// index 8
std::make_shared<Everest::error::Error>(
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::High, date::utc_clock::now() + std::chrono::hours(8), Everest::error::UUID(),
Everest::error::State::ClearedByReboot),
// index 9
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_c", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"),
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"), "everest-test",
Everest::error::Severity::High, date::utc_clock::now() + std::chrono::hours(9), Everest::error::UUID(),
Everest::error::State::ClearedByReboot),
// index 10
std::make_shared<Everest::error::Error>(
"test_type_c", "test_sub_type_c", "test_message_c", "test_description_c",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"), "everest-test",
Everest::error::Severity::High, date::utc_clock::now() + std::chrono::hours(10), Everest::error::UUID(),
Everest::error::State::ClearedByReboot),
// index 11
std::make_shared<Everest::error::Error>(
"test_type_b", "test_sub_type_b", "test_message_b", "test_description_b",
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"),
ImplementationIdentifier("test_origin_module_c", "test_origin_implementation_c"), "everest-test",
Everest::error::Severity::High, date::utc_clock::now() + std::chrono::hours(11), Everest::error::UUID(),
Everest::error::State::ClearedByReboot)};
}
Expand Down
22 changes: 15 additions & 7 deletions modules/EvseManager/tests/ModuleAdapterStub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utils/error/error_factory.hpp>
#include <utils/error/error_manager_impl.hpp>
#include <utils/error/error_manager_req.hpp>
#include <utils/error/error_manager_req_global.hpp>
#include <utils/error/error_state_monitor.hpp>
#include <utils/error/error_type_map.hpp>

Expand All @@ -35,10 +36,8 @@ struct ModuleAdapterStub : public Everest::ModuleAdapter {
get_error_state_monitor_req = [this](const Requirement& req) {
return this->get_error_state_monitor_req_fn(req);
};
subscribe_global_all_errors = [this](const Everest::error::ErrorCallback& cb1,
const Everest::error::ErrorCallback& cb2) {
this->subscribe_global_all_errors_fn(cb1, cb2);
};
get_global_error_manager = [this]() { return this->get_global_error_manager_fn(); };
get_global_error_state_monitor = [this]() { return this->get_global_error_state_monitor_fn(); };

ext_mqtt_publish = [this](const std::string& s1, const std::string& s2) { this->ext_mqtt_publish_fn(s1, s2); };
ext_mqtt_subscribe = [this](const std::string& str, StringHandler sh) {
Expand Down Expand Up @@ -88,9 +87,18 @@ struct ModuleAdapterStub : public Everest::ModuleAdapter {
return std::make_shared<Everest::error::ErrorStateMonitor>(
Everest::error::ErrorStateMonitor(std::make_shared<Everest::error::ErrorDatabaseMap>()));
}
virtual void subscribe_global_all_errors_fn(const Everest::error::ErrorCallback&,
const Everest::error::ErrorCallback&) {
std::printf("subscribe_global_all_errors_fn\n");
virtual std::shared_ptr<Everest::error::ErrorManagerReqGlobal> get_global_error_manager_fn() {
std::printf("get_global_error_manager_fn\n");
return std::make_shared<Everest::error::ErrorManagerReqGlobal>(
std::make_shared<Everest::error::ErrorTypeMap>(), std::make_shared<Everest::error::ErrorDatabaseMap>(),
[](const Everest::error::ErrorCallback&, const Everest::error::ErrorCallback&) {
std::printf("global_subscribe_all_errors\n");
});
}
virtual std::shared_ptr<Everest::error::ErrorStateMonitor> get_global_error_state_monitor_fn() {
std::printf("get_global_error_state_monitor\n");
return std::make_shared<Everest::error::ErrorStateMonitor>(
std::make_shared<Everest::error::ErrorDatabaseMap>());
}
virtual void ext_mqtt_publish_fn(const std::string&, const std::string&) {
std::printf("ext_mqtt_publish_fn\n");
Expand Down
1 change: 1 addition & 0 deletions modules/examples/error-framework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ev_add_module(ExampleErrorRaiser)
ev_add_module(ExampleErrorSubscriber)
ev_add_module(ExampleErrorGlobalSubscriber)
ev_add_module(PyExampleErrorRaiser)
ev_add_module(PyExampleErrorSubscriber)
ev_add_module(JsExampleErrorRaiser)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#

# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()

# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
PRIVATE
"example_global_subscriber/example_error_frameworkImpl.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "ExampleErrorGlobalSubscriber.hpp"

namespace module {

void ExampleErrorGlobalSubscriber::init() {
invoke_init(*p_example_global_subscriber);
}

void ExampleErrorGlobalSubscriber::ready() {
invoke_ready(*p_example_global_subscriber);
}

} // namespace module
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP
#define EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP

//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//

#include "ld-ev.hpp"

// headers for provided interface implementations
#include <generated/interfaces/example_error_framework/Implementation.hpp>

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1

namespace module {

struct Conf {};

class ExampleErrorGlobalSubscriber : public Everest::ModuleBase {
public:
ExampleErrorGlobalSubscriber() = delete;
ExampleErrorGlobalSubscriber(const ModuleInfo& info,
std::unique_ptr<example_error_frameworkImplBase> p_example_global_subscriber,
Conf& config) :
ModuleBase(info), p_example_global_subscriber(std::move(p_example_global_subscriber)), config(config){};

const std::unique_ptr<example_error_frameworkImplBase> p_example_global_subscriber;
const Conf& config;

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1

protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1

private:
friend class LdEverest;
void init();
void ready();

// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};

// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1

} // namespace module

#endif // EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _everest_modules_handwritten_ExampleErrorGlobalSubscriber:

.. This file is a placeholder for an optional single file
handwritten documentation for the ExampleErrorGlobalSubscriber module.
Please decide whether you want to use this single file,
or a set of files in the doc/ directory.
In the latter case, you can delete this file.
In the former case, you can delete the doc/ directory.
.. This handwritten documentation is optional. In case
you do not want to write it, you can delete this file
and the doc/ directory.
.. The documentation can be written in reStructuredText,
and will be converted to HTML and PDF by Sphinx.
*******************************************
ExampleErrorGlobalSubscriber
*******************************************

:ref:`Link <everest_modules_ExampleErrorGlobalSubscriber>` to the module's reference.
Simple example module written in C++ to demonstrate error framework on global subscriber side
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#include "example_error_frameworkImpl.hpp"

namespace module {
namespace example_global_subscriber {

void example_error_frameworkImpl::init() {
Everest::error::ErrorCallback error_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error: " << error.type;
this->test_state_monitor();
};
Everest::error::ErrorCallback error_cleared_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error cleared: " << error.type;
this->test_state_monitor();
};
subscribe_global_all_errors(error_callback, error_cleared_callback);
}

void example_error_frameworkImpl::test_state_monitor() {
EVLOG_info << "Currently there are " << get_global_error_state_monitor()->get_ative_error_count()
<< " errors active.";
}

void example_error_frameworkImpl::ready() {
}

} // namespace example_global_subscriber
} // namespace module
Loading

0 comments on commit 07d35ac

Please sign in to comment.