Skip to content

Commit

Permalink
Merge branch 'main' into feat/add_clippy_allow_too_many_arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dorezyuk authored Jul 1, 2024
2 parents 1034dee + 06a22c2 commit 209c0a6
Show file tree
Hide file tree
Showing 47 changed files with 2,218 additions and 989 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cmake_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
- 'ubuntu-22.04'
- 'large-ubuntu-22.04-xxl'

env:
BUILD_KIT_IMAGE: ghcr.io/everest/build-kit-alpine:v1.2.0

jobs:
build:
name: Build and Test
Expand Down Expand Up @@ -39,8 +42,8 @@ jobs:
rsync -a source/.ci/build-kit/ scripts
- name: Pull build-kit docker image
run: |
docker pull --quiet ghcr.io/everest/build-kit-alpine:latest
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
docker pull --quiet ${{ env.BUILD_KIT_IMAGE }}
docker image tag ${{ env.BUILD_KIT_IMAGE }} build-kit
- name: Compile
run: |
docker run \
Expand Down
14 changes: 13 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ genrule(
""",
)

genrule(
name = "version_information",
outs = ["include/generated/version_information.hpp"],
cmd = """
echo "#pragma once" > $@
echo "#define PROJECT_NAME \\"everest-framework\\"" >> $@
echo "#define PROJECT_DESCRIPTION \\"\\"" >> $@
echo "#define PROJECT_VERSION \\"\\"" >> $@
echo "#define GIT_VERSION \\"\\"" >> $@
""",
)

cc_library(
name = "framework",
srcs = glob(["lib/**/*.cpp"]),
hdrs = glob(["include/**/*.hpp"]) + [":compile_time_settings"],
hdrs = glob(["include/**/*.hpp"]) + [":compile_time_settings", ":version_information"],
copts = ["-std=c++17"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.14)

project(everest-framework
VERSION 0.13.0
VERSION 0.15.2
DESCRIPTION "The open operating system for e-mobility charging stations"
LANGUAGES CXX C
)

find_package(everest-cmake 0.1 REQUIRED
find_package(everest-cmake 0.4 REQUIRED
PATHS ../everest-cmake
)

Expand All @@ -20,6 +20,13 @@ option(EVEREST_ENABLE_PY_SUPPORT "Enable everestpy for Python modules" ON)
option(EVEREST_ENABLE_RS_SUPPORT "Enable everestrs for Rust modules" OFF)
option(EVEREST_ENABLE_ADMIN_PANEL_BACKEND "Enable everest admin panel backend" ON)
option(EVEREST_INSTALL_ADMIN_PANEL "Download and install everest admin panel" ON)
ev_setup_cmake_variables_python_wheel()
option(${PROJECT_NAME}_USE_PYTHON_VENV "Use python venv for pip install targets" OFF)
set(${PROJECT_NAME}_PYTHON_VENV_PATH "${CMAKE_BINARY_DIR}/venv" CACHE PATH "Path to python venv")
ev_setup_python_executable(
USE_PYTHON_VENV ${${PROJECT_NAME}_USE_PYTHON_VENV}
PYTHON_VENV_PATH ${${PROJECT_NAME}_PYTHON_VENV_PATH}
)

# make own cmake modules available
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down
102 changes: 102 additions & 0 deletions everestjs/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <everest/exceptions.hpp>
#include <everest/logging.hpp>

#include <utils/error/error_json.hpp>

namespace EverestJs {

Everest::json convertToJson(const Napi::Value& value) {
Expand Down Expand Up @@ -108,4 +110,104 @@ Napi::Value convertToNapiValue(const Napi::Env& env, const json& value) {
EVTHROW(EVEXCEPTION(Everest::EverestApiError, "Javascript type can not be converted to Napi::Value: ", value));
}

Everest::error::Error convertToError(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

Everest::json j = convertToJson(value);
return j.get<Everest::error::Error>();
}

Everest::error::ErrorType convertToErrorType(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsString()) {
return Everest::error::ErrorType(std::string(value.As<Napi::String>()));
}
EVTHROW(EVEXCEPTION(Everest::EverestApiError, "Javascript type can not be converted to Everest::error::ErrorType: ",
napi_valuetype_strings[value.Type()]));
}

Everest::error::ErrorSubType convertToErrorSubType(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsString()) {
return Everest::error::ErrorSubType(std::string(value.As<Napi::String>()));
}
EVTHROW(EVEXCEPTION(Everest::EverestApiError,
"Javascript type can not be converted to Everest::error::ErrorSubType: ",
napi_valuetype_strings[value.Type()]));
}

Everest::error::Severity convertToErrorSeverity(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsString()) {
return Everest::error::string_to_severity(std::string(value.As<Napi::String>()));
}
EVTHROW(EVEXCEPTION(Everest::EverestApiError, "Javascript type can not be converted to Everest::error::Severity: ",
napi_valuetype_strings[value.Type()]));
}

Everest::error::State convertToErrorState(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsString()) {
return Everest::error::string_to_state(std::string(value.As<Napi::String>()));
}
EVTHROW(EVEXCEPTION(Everest::EverestApiError, "Javascript type can not be converted to Everest::error::State: ",
napi_valuetype_strings[value.Type()]));
}

Napi::Value convertToNapiValue(const Napi::Env& env, const Everest::error::Error& error) {
BOOST_LOG_FUNCTION();

json j(error);
Napi::Value res = convertToNapiValue(env, j);
return res;
}

bool isSingleErrorStateCondition(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsArray()) {
return false;
}
return true;
}

Everest::error::ErrorStateMonitor::StateCondition convertToErrorStateCondition(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsObject()) {
Napi::Object obj = value.As<Napi::Object>();
Napi::Value type = obj.Get("type");
Napi::Value sub_type = obj.Get("sub_type");
Napi::Value active = obj.Get("active");
return Everest::error::ErrorStateMonitor::StateCondition(
convertToErrorType(type), convertToErrorSubType(sub_type), bool(active.As<Napi::Boolean>()));
}
EVTHROW(EVEXCEPTION(Everest::EverestApiError,
"Javascript type can not be converted to Everest::error::ErrorStateMonitor::StateCondition: ",
napi_valuetype_strings[value.Type()]));
}

std::list<Everest::error::ErrorStateMonitor::StateCondition>
convertToErrorStateConditionList(const Napi::Value& value) {
BOOST_LOG_FUNCTION();

if (value.IsArray()) {
std::list<Everest::error::ErrorStateMonitor::StateCondition> conditions;
Napi::Array array = value.As<Napi::Array>();
for (uint64_t i = 0; i < array.Length(); i++) {
Napi::Value entry = Napi::Value(array[i]);
conditions.push_back(convertToErrorStateCondition(entry));
}
return conditions;
}
EVTHROW(EVEXCEPTION(
Everest::EverestApiError,
"Javascript type can not be converted to std::list<Everest::error::ErrorStateMonitor::StateCondition>: ",
napi_valuetype_strings[value.Type()]));
}

} // namespace EverestJs
15 changes: 15 additions & 0 deletions everestjs/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <utils/conversions.hpp>
#include <utils/types.hpp>

#include <utils/error.hpp>
#include <utils/error/error_state_monitor.hpp>

namespace EverestJs {

static const char* const napi_valuetype_strings[] = {
Expand All @@ -29,6 +32,18 @@ Everest::json convertToJson(const Napi::Value& value);
Everest::TelemetryMap convertToTelemetryMap(const Napi::Object& obj);
Napi::Value convertToNapiValue(const Napi::Env& env, const Everest::json& value);

// Error related
Everest::error::Error convertToError(const Napi::Value& value);
Everest::error::ErrorType convertToErrorType(const Napi::Value& value);
Everest::error::ErrorSubType convertToErrorSubType(const Napi::Value& value);
Everest::error::Severity convertToErrorSeverity(const Napi::Value& value);
Everest::error::State convertToErrorState(const Napi::Value& value);
Napi::Value convertToNapiValue(const Napi::Env& env, const Everest::error::Error& error);
// ErrorStateCondition related
bool isSingleErrorStateCondition(const Napi::Value& value);
Everest::error::ErrorStateMonitor::StateCondition convertToErrorStateCondition(const Napi::Value& value);
std::list<Everest::error::ErrorStateMonitor::StateCondition> convertToErrorStateConditionList(const Napi::Value& value);

} // namespace EverestJs

#endif // CONVERSIONS_HPP
Loading

0 comments on commit 209c0a6

Please sign in to comment.