Skip to content

Commit

Permalink
Engine Base module refactor
Browse files Browse the repository at this point in the history
- Base module is now a static library
- Moved json module to base module
- Fixed includes across the engine modules
- Deleted unused tracy code and macros definitions
  • Loading branch information
JavierBejMen committed Jul 30, 2024
1 parent 0e22fa6 commit 8473423
Show file tree
Hide file tree
Showing 197 changed files with 284 additions and 571 deletions.
1 change: 0 additions & 1 deletion src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ add_subdirectory(${ENGINE_SOURCE_DIR}/logpar)
add_subdirectory(${ENGINE_SOURCE_DIR}/kvdb)
add_subdirectory(${ENGINE_SOURCE_DIR}/logicexpr)
add_subdirectory(${ENGINE_SOURCE_DIR}/server)
add_subdirectory(${ENGINE_SOURCE_DIR}/json)
add_subdirectory(${ENGINE_SOURCE_DIR}/yml)
add_subdirectory(${ENGINE_SOURCE_DIR}/wdb)
add_subdirectory(${ENGINE_SOURCE_DIR}/cmds)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/benchmark/base/parseEvent_bench.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "parseEvent.hpp"
#include <base/parseEvent.hpp>

#include <list>

Expand Down
2 changes: 1 addition & 1 deletion src/engine/benchmark/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(jsonSearch_benchmark
${CMAKE_CURRENT_LIST_DIR}/jsonSearch_benchmark.cpp
)
target_link_libraries(jsonSearch_benchmark json benchmark::benchmark_main)
target_link_libraries(jsonSearch_benchmark base benchmark::benchmark_main)
2 changes: 1 addition & 1 deletion src/engine/benchmark/wazuhBenchMain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <benchmark/benchmark.h>
#include <logging/logging.hpp>
#include <base/logging.hpp>

int main(int argc, char **argv)
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(IFACE_DIR ${CMAKE_CURRENT_LIST_DIR}/interface)
# ###################################################################################################
add_library(api_iapi INTERFACE)
target_include_directories(api_iapi INTERFACE ${IFACE_DIR})
target_link_libraries(api_iapi INTERFACE fmt base json store::istore)
target_link_libraries(api_iapi INTERFACE fmt base store::istore)
add_library(api::iapi ALIAS api_iapi)

add_library(api STATIC
Expand Down Expand Up @@ -45,7 +45,6 @@ target_link_libraries(api
base
eMessages
fmt
json
kvdb::ikvdb
metrics
router::irouter
Expand Down Expand Up @@ -94,6 +93,7 @@ if(ENGINE_BUILD_TEST)
target_link_libraries(api_utest
gtest_main
base
base::test
api
schemf::mocks
store::mocks
Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/include/api/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <eMessages/eMessage.h>
#include <eMessages/engine.pb.h>
#include <utils/wazuhProtocol/wazuhRequest.hpp>
#include <utils/wazuhProtocol/wazuhResponse.hpp>
#include <base/utils/wazuhProtocol/wazuhRequest.hpp>
#include <base/utils/wazuhProtocol/wazuhResponse.hpp>

namespace api::adapter
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/include/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "registry.hpp"

#include <json/json.hpp>
#include <base/json.hpp>
#include <rbac/irbac.hpp>

namespace api
Expand Down Expand Up @@ -70,7 +70,7 @@ class Api

/**
* @brief Processes a raw string request and invokes a callback function with the response.
*
*
* @param message Raw string request
* @param callbackFn Callback function that will be invoked with the generated response
*/
Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/include/api/catalog/catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include <api/catalog/resource.hpp>
#include <builder/ivalidator.hpp>
#include <error.hpp>
#include <name.hpp>
#include <base/error.hpp>
#include <base/name.hpp>
#include <store/istore.hpp>

namespace api::catalog
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/include/api/catalog/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <fmt/format.h>

#include <eMessages/catalog.pb.h>
#include <name.hpp>
#include <base/name.hpp>

namespace api::catalog
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/include/api/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <exception>

#include <conf/iconf.hpp>
#include <json/json.hpp>
#include <base/json.hpp>
#include <eMessages/config.pb.h>

#include <api/api.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/include/api/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <shared_mutex>
#include <string>

#include <utils/wazuhProtocol/wazuhProtocol.hpp>
#include <base/utils/wazuhProtocol/wazuhProtocol.hpp>

namespace api
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/interface/api/policy/ipolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <list>

#include <error.hpp>
#include <name.hpp>
#include <base/error.hpp>
#include <base/name.hpp>
#include <store/namespaceId.hpp>

namespace api::policy
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "api/catalog/catalog.hpp"

#include <fmt/format.h>
#include <logging/logging.hpp>
#include <base/logging.hpp>

#include <store/utils.hpp>
#include <yml/yml.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/catalog/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <eMessages/catalog.pb.h>
#include <eMessages/eMessage.h>
#include <json/json.hpp>
#include <base/json.hpp>

#include <api/adapter.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/geo/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <eMessages/eMessage.h>
#include <eMessages/geo.pb.h>
#include <json/json.hpp>
#include <base/json.hpp>

#include <api/adapter.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/src/kvdb/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <api/adapter.hpp>
#include <eMessages/eMessage.h>
#include <eMessages/kvdb.pb.h>
#include <json/json.hpp>
#include <utils/stringUtils.hpp>
#include <base/json.hpp>
#include <base/utils/stringUtils.hpp>

namespace api::kvdb::handlers
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/metrics/handlers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "api/metrics/handlers.hpp"

#include <json/json.hpp>
#include <base/json.hpp>
#include <eMessages/eMessage.h>
#include <eMessages/metrics.pb.h>

Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/policy/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>

#include <eMessages/policy.pb.h>
#include <logging/logging.hpp>
#include <base/logging.hpp>

#include <api/adapter.hpp>
#include <api/policy/handlers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/src/registry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "api/registry.hpp"

#include <logging/logging.hpp>
#include <base/logging.hpp>

namespace api
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/test/src/unit/api_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>

#include <api/api.hpp>
#include <logging/logging.hpp>
#include <base/logging.hpp>

using namespace api;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>

#include <logging/logging.hpp>
#include <base/logging.hpp>

#include "catalogTestShared.hpp"

Expand Down
4 changes: 2 additions & 2 deletions src/engine/source/api/test/src/unit/geo/handlers_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <gtest/gtest.h>

#include <api/geo/handlers.hpp>
#include <base/test/behaviour.hpp>
#include <base/behaviour.hpp>
#include <eMessages/geo.pb.h>
#include <geo/mockManager.hpp>
#include <logging/logging.hpp>
#include <base/logging.hpp>

using namespace ::geo::mocks;
using namespace base::test;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/source/api/test/src/unit/registry_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <api/api.hpp>
#include <api/registry.hpp>
#include <utils/wazuhProtocol/wazuhProtocol.hpp>
#include <base/utils/wazuhProtocol/wazuhProtocol.hpp>

using namespace base::utils::wazuhProtocol;

Expand Down
78 changes: 38 additions & 40 deletions src/engine/source/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# FIXME: Base should be refactored to be an OBJECT library so other modules can simply include what they need.
####################################################################################################
# logging
####################################################################################################
Expand Down Expand Up @@ -32,57 +31,51 @@ CPMAddPackage(
DOWNLOAD_ONLY YES
)

add_library(base STATIC
logging/logging.hpp
utils/wazuhProtocol/wazuhResponse.hpp
utils/wazuhProtocol/wazuhRequest.hpp
utils/wazuhProtocol/wazuhRequest.cpp
utils/baseMacros.hpp
utils/baseMacros.cpp
utils/ipUtils.cpp
utils/ipUtils.hpp
utils/stringUtils.cpp
utils/stringUtils.hpp
result.hpp
baseTypes.hpp
expression.cpp
error.hpp
parseEvent.cpp
parseEvent.hpp
name.hpp
)
####################################################################################################
# BASE
####################################################################################################
# Defs
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
set(INC_DIR ${CMAKE_CURRENT_LIST_DIR}/include)

if(PROFILE_BUILD)
target_link_libraries(base
PUBLIC
profile
)
endif()
add_library(base STATIC
${SRC_DIR}/utils/wazuhProtocol/wazuhRequest.cpp
${SRC_DIR}/utils/ipUtils.cpp
${SRC_DIR}/utils/stringUtils.cpp
${SRC_DIR}/expression.cpp
${SRC_DIR}/parseEvent.cpp
${SRC_DIR}/json.cpp
)
target_include_directories(base
PUBLIC
${INC_DIR}
${spdlog_SOURCE_DIR}/include
${rapidjson_SOURCE_DIR}/include

PRIVATE
${INC_DIR}/base
${SRC_DIR}
)
target_link_libraries(base
PUBLIC
dl
fmt
spdlog
json
)

target_include_directories(base
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${spdlog_SOURCE_DIR}/include
${rapidjson_SOURCE_DIR}/include
${ENGINE_SOURCE_DIR}/json
${ENGINE_SOURCE_DIR}/base
${ENGINE_SOURCE_DIR} # TODO remove when BUILDER is updated (#include <builder/builder.hpp)
PRIVATE
spdlog
)

# Tests

if(ENGINE_BUILD_TEST)

set(TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test)
set(TEST_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/test/src)
set(UNIT_SRC_DIR ${TEST_SRC_DIR}/unit)

add_library(base_test INTERFACE)
target_include_directories(base_test INTERFACE ${TEST_DIR}/include)
add_library(base::test ALIAS base_test)

add_executable(base_utest
${UNIT_SRC_DIR}/stringUtils_test.cpp
${UNIT_SRC_DIR}/ipUtils_test.cpp
Expand All @@ -93,13 +86,18 @@ add_executable(base_utest
${UNIT_SRC_DIR}/utils/wazuhProtocol/wazuhResponse_test.cpp
${UNIT_SRC_DIR}/parseEvent_test.cpp
${UNIT_SRC_DIR}/dotPath_test.cpp
${UNIT_SRC_DIR}/json_test.cpp
)
target_include_directories(base_utest
PRIVATE
${TEST_SRC_DIR}
${CMAKE_CURRENT_LIST_DIR}
${SRC_DIR}
${INC_DIR}/base
)
target_link_libraries(base_utest
PUBLIC
base::test

PRIVATE
base
gtest_main
Expand All @@ -113,7 +111,7 @@ add_executable(base_logger_utest
target_include_directories(base_logger_utest
PRIVATE
${TEST_SRC_DIR}
${CMAKE_CURRENT_LIST_DIR}
${INC_DIR}/base
)
target_link_libraries(base_logger_utest
PRIVATE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _H_BASE_TYPES
#define _H_BASE_TYPES

#include <json/json.hpp>
#include <base/json.hpp>
#include "result.hpp"
#include <functional>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <fmt/core.h>
#include <fmt/format.h>

#include <utils/stringUtils.hpp>
#include <base/utils/stringUtils.hpp>

/**
* @brief A dot-separated path, used to navigate nested field structures.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

#include <error.hpp>
#include <base/error.hpp>

namespace json
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <string>

#include "baseTypes.hpp"
#include <base/baseTypes.hpp>

namespace base::parseEvent
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _BASE_UTILS_WAZUH_REQUEST_HPP
#define _BASE_UTILS_WAZUH_REQUEST_HPP

#include <json/json.hpp>
#include <base/json.hpp>

namespace base::utils::wazuhProtocol
{
Expand Down
Loading

0 comments on commit 8473423

Please sign in to comment.