Skip to content

Commit

Permalink
Add error-handling functionality to example modules and build up a de…
Browse files Browse the repository at this point in the history
…monstration

Signed-off-by: Andreas Heinrich <andreas.heinrich@rwth-aachen.de>
  • Loading branch information
andistorm committed Oct 18, 2023
1 parent 8e114a0 commit acd4a82
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ generate_config_run_script(CONFIG hil)
generate_config_run_script(CONFIG sil-gen-pm)
generate_config_run_script(CONFIG sil-ocpp)
generate_config_run_script(CONFIG sil-ocpp-custom-extension)
generate_config_run_script(CONFIG example)

# install configs
install(
Expand Down
23 changes: 23 additions & 0 deletions config/config-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
settings:
telemetry_enabled: true
logging_config_file: /home/andreas/everest-logging-config.conf
active_modules:
store:
module: Store
example:
config_implementation:
example:
current: 42
enum_test: one
enum_test2: 2
connections:
kvs:
- module_id: store
implementation_id: main
module: Example
example_user:
connections:
example:
- module_id: example
implementation_id: example
module: ExampleUser
10 changes: 10 additions & 0 deletions errors/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
description: Example group of errors used by example modules to demonstrate error handling
errors:
- name: ExampleErrorA
description: Example error A
- name: ExampleErrorB
description: Example error B
- name: ExampleErrorC
description: Example error C
- name: ExampleErrorD
description: Example error D
2 changes: 2 additions & 0 deletions interfaces/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ vars:
max_current:
description: Provides maximum current of this supply in ampere
type: number
errors:
- $ref: '../errors/example.yaml#/errors'
2 changes: 2 additions & 0 deletions interfaces/example_user.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
description: >-
This interface defines an example_user interface that uses the example
interface
errors:
- $ref: '../errors/example.yaml#/errors'
10 changes: 10 additions & 0 deletions modules/examples/Example/example/exampleImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ void exampleImpl::init() {

void exampleImpl::ready() {
publish_max_current(config.current);
std::this_thread::sleep_for(std::chrono::seconds(2));
Everest::error::ErrorHandle my_error_uuid = raise_example_ExampleErrorA("This error is raised to test the error handling");
std::this_thread::sleep_for(std::chrono::seconds(2));
mod->r_kvs->call_store("test", "test");
std::this_thread::sleep_for(std::chrono::seconds(2));
request_clear_error(Everest::error::ErrorHandle());
std::this_thread::sleep_for(std::chrono::seconds(10));
request_clear_error(my_error_uuid);
raise_example_ExampleErrorB("This error is raised to test the error handling", Everest::error::Severity::High);
request_clear_all_errors();
}

bool exampleImpl::handle_uses_something(std::string& key) {
Expand Down
17 changes: 17 additions & 0 deletions modules/examples/ExampleUser/example_user/example_userImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@ namespace module {
namespace example_user {

void example_userImpl::init() {
Everest::error::ErrorCallback error_callback = [this](const Everest::error::Error& error) {
EVLOG_error << "received error from error manager: " << error.type;
this->received_error = error.uuid;
};
Everest::error::ErrorCallback error_cleared_callback = [](const Everest::error::Error& error) {
EVLOG_info << "received error cleared from error manager: " << error.type;
};
mod->r_example->subscribe_error_example_ExampleErrorA(
error_callback,
error_cleared_callback
);
mod->r_example->subscribe_all_errors(
error_callback,
error_cleared_callback
);
}

void example_userImpl::ready() {
mod->r_example->call_uses_something("hello_there");
std::this_thread::sleep_for(std::chrono::seconds(6));
request_clear_error(this->received_error);
}

} // namespace example_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class example_userImpl : public example_userImplBase {

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
Everest::error::ErrorHandle received_error;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down

0 comments on commit acd4a82

Please sign in to comment.