Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add visidentifier handler #3

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
include(AosCoreLib)

# Poco lib
find_package(Poco REQUIRED Util DataSQLite JSON)
find_package(
Poco
REQUIRED
Crypto
mlohvynenko marked this conversation as resolved.
Show resolved Hide resolved
DataSQLite
Foundation
JSON
Net
NetSSL
Util
)

# Systemd lib
find_package(PkgConfig REQUIRED)
Expand Down
3 changes: 2 additions & 1 deletion CMakeModules/AosCoreLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ExternalProject_Add(
aoscore
PREFIX ${aoscore_build_dir}
GIT_REPOSITORY https://github.com/aoscloud/aos_core_lib_cpp.git
GIT_TAG main
GIT_TAG develop
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${aoscore_build_dir}
Expand All @@ -23,6 +23,7 @@ ExternalProject_Add(
file(MAKE_DIRECTORY ${aoscore_build_dir}/include)

add_library(aoscommon STATIC IMPORTED GLOBAL)
add_dependencies(aoscommon aoscore)
set_target_properties(aoscommon PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${aoscore_build_dir}/include)
set_target_properties(aoscommon PROPERTIES IMPORTED_LOCATION ${aoscore_build_dir}/lib/libaoscommoncpp.a)

Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# ######################################################################################################################

add_subdirectory(app)
add_subdirectory(config)
add_subdirectory(database)
add_subdirectory(logger)
add_subdirectory(config)
add_subdirectory(utils)
add_subdirectory(visidentifier)
mlohvynenko marked this conversation as resolved.
Show resolved Hide resolved

# ######################################################################################################################
# Sources
Expand Down
6 changes: 4 additions & 2 deletions src/logger/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ class LogModuleType {
public:
enum class Enum {
eApp,
eDatabase,
eConfig,
eDatabase,
eVISIdentifier,
eNumModules,
};

static const aos::Array<const char* const> GetStrings()
{
static const char* const sLogModuleTypeStrings[] = {
"app",
"database",
"config",
"database",
"visidentifier",
};

return aos::Array<const char* const>(sLogModuleTypeStrings, aos::ArraySize(sLogModuleTypeStrings));
Expand Down
12 changes: 10 additions & 2 deletions src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ set(TARGET utils)
# Sources
# ######################################################################################################################

set(SOURCES time.cpp)
set(SOURCES json.cpp time.cpp)

# ######################################################################################################################
# Includes
# ######################################################################################################################

# ######################################################################################################################
# Target
Expand All @@ -23,4 +27,8 @@ add_library(${TARGET} STATIC ${SOURCES})
# Labraries
# ######################################################################################################################

target_link_libraries(${TARGET} PUBLIC aoscommon)
target_link_libraries(
${TARGET}
PUBLIC aoscommon Poco::Foundation
PRIVATE Poco::JSON
)
66 changes: 66 additions & 0 deletions src/utils/json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2024 Renesas Electronics Corporation.
* Copyright (C) 2024 EPAM Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <Poco/JSON/JSONException.h>
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h>

#include "utils/json.hpp"

namespace UtilsJson {

aos::RetWithError<Poco::Dynamic::Var> ParseJson(const std::string& json) noexcept
{
try {
auto parser = Poco::JSON::Parser();

return parser.parse(json);
} catch (const Poco::JSON::JSONException& e) {
return {{}, aos::ErrorEnum::eInvalidArgument};
} catch (...) {
return {{}, aos::ErrorEnum::eFailed};
}
}

aos::RetWithError<Poco::Dynamic::Var> ParseJson(std::istream& in) noexcept
{
try {
auto parser = Poco::JSON::Parser();

return parser.parse(in);
} catch (const Poco::JSON::JSONException& e) {
return {{}, aos::ErrorEnum::eInvalidArgument};
} catch (...) {
return {{}, aos::ErrorEnum::eFailed};
}
}

Poco::Dynamic::Var FindByPath(const Poco::Dynamic::Var object, const std::vector<std::string>& keys)
{
if (keys.empty()) {
return object;
}

Poco::Dynamic::Var result = object;

for (const auto& key : keys) {

if (result.type() == typeid(Poco::JSON::Object)) {
result = result.extract<Poco::JSON::Object>().get(key);
} else if (result.type() == typeid(Poco::JSON::Object::Ptr)) {
result = result.extract<Poco::JSON::Object::Ptr>()->get(key);
} else {
result.clear();

break;
}
}

return result;
}

} // namespace UtilsJson
46 changes: 46 additions & 0 deletions src/utils/json.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2024 Renesas Electronics Corporation.
* Copyright (C) 2024 EPAM Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef UTILS_JSON_HPP_
#define UTILS_JSON_HPP_

#include <string>
#include <vector>

#include <Poco/Dynamic/Var.h>

#include <aos/common/tools/error.hpp>

namespace UtilsJson {
/**
* Parses json string.
*
* @param json json string.
* @return aos::RetWithError<Poco::Dynamic::Var> .
*/
aos::RetWithError<Poco::Dynamic::Var> ParseJson(const std::string& json) noexcept;

/**
* Parses input stream.
*
* @param in input stream.
* @return aos::RetWithError<Poco::Dynamic::Var> .
*/
aos::RetWithError<Poco::Dynamic::Var> ParseJson(std::istream& in) noexcept;

/**
* Finds value of the json by path
*
* @param object json object.
* @param path json path.
* @return Poco::Dynamic::Var.
*/
Poco::Dynamic::Var FindByPath(const Poco::Dynamic::Var object, const std::vector<std::string>& path);

} // namespace UtilsJson

#endif
34 changes: 34 additions & 0 deletions src/visidentifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (C) 2024 Renesas Electronics Corporation.
# Copyright (C) 2024 EPAM Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

set(TARGET visidentifier)

# ######################################################################################################################
# Sources
# ######################################################################################################################

set(SOURCES pocowsclient.cpp visconfig.cpp visidentifier.cpp vismessage.cpp wsclientevent.cpp wspendingrequests.cpp)

# ######################################################################################################################
# Includes
# ######################################################################################################################

# ######################################################################################################################
# Target
# ######################################################################################################################

add_library(${TARGET} STATIC ${SOURCES})

# ######################################################################################################################
# Labraries
# ######################################################################################################################

target_link_libraries(
mlohvynenko marked this conversation as resolved.
Show resolved Hide resolved
${TARGET}
PUBLIC aoscommon aosiam Poco::Foundation
PRIVATE Poco::Crypto Poco::Net Poco::NetSSL
)
18 changes: 18 additions & 0 deletions src/visidentifier/log.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
mlohvynenko marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (C) 2024 Renesas Electronics Corporation.
* Copyright (C) 2024 EPAM Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef LOG_HPP_
#define LOG_HPP_

#include "logger/logger.hpp"

#define LOG_DBG() LOG_MODULE_DBG(AosLogModule(LogModuleEnum::eVISIdentifier))
#define LOG_INF() LOG_MODULE_INF(AosLogModule(LogModuleEnum::eVISIdentifier))
#define LOG_WRN() LOG_MODULE_WRN(AosLogModule(LogModuleEnum::eVISIdentifier))
#define LOG_ERR() LOG_MODULE_ERR(AosLogModule(LogModuleEnum::eVISIdentifier))

#endif
Loading
Loading