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: module probation (DONT MERGE) #22

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
.idea

/build
/build-ex
/cmake-build-*

/.build
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API ON)

project(cpp-jam
VERSION 0.0.1
@@ -40,6 +41,12 @@ find_package(Boost.DI CONFIG REQUIRED)
find_package(qtils CONFIG REQUIRED)
find_package(prometheus-cpp CONFIG REQUIRED)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fmodules-ts)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
add_compile_options(-fmodules)
endif()

add_library(headers INTERFACE)
target_include_directories(headers INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src_>
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,3 +24,8 @@ add_subdirectory(metrics)
# Clocks and time subsystem
add_subdirectory(clock)

# Subscription Engine subsystem
add_subdirectory(se)

# Modules subsystem
add_subdirectory(modules)
4 changes: 3 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@ add_library(build_version

add_library(app_configuration SHARED configuration.cpp)
target_link_libraries(app_configuration
Boost::boost)
Boost::boost
fmt::fmt
)

add_library(app_configurator SHARED configurator.cpp)
target_link_libraries(app_configurator
28 changes: 13 additions & 15 deletions src/app/impl/application_impl.cpp
Original file line number Diff line number Diff line change
@@ -20,12 +20,12 @@
namespace jam::app {

ApplicationImpl::ApplicationImpl(
std::shared_ptr<log::LoggingSystem> logsys,
std::shared_ptr<Configuration> config,
std::shared_ptr<StateManager> state_manager,
std::shared_ptr<Watchdog> watchdog,
std::shared_ptr<metrics::Exposer> metrics_exposer,
std::shared_ptr<clock::SystemClock> system_clock)
qtils::StrictSharedPtr<log::LoggingSystem> logsys,
qtils::StrictSharedPtr<Configuration> config,
qtils::StrictSharedPtr<StateManager> state_manager,
qtils::StrictSharedPtr<Watchdog> watchdog,
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
qtils::StrictSharedPtr<clock::SystemClock> system_clock)
: logger_(logsys->getLogger("Application", "application")),
app_config_(std::move(config)),
state_manager_(std::move(state_manager)),
@@ -34,15 +34,13 @@ namespace jam::app {
system_clock_(std::move(system_clock)),
metrics_registry_(metrics::createRegistry()) {
// Metric for exposing name and version of node
constexpr auto buildInfoMetricName = "jam_build_info";
metrics_registry_->registerGaugeFamily(
buildInfoMetricName,
"A metric with a constant '1' value labeled by name, version");
auto metric_build_info = metrics_registry_->registerGaugeMetric(
buildInfoMetricName,
{{"name", app_config_->nodeName()},
{"version", app_config_->nodeVersion()}});
metric_build_info->set(1);
metrics::GaugeHelper(
"jam_build_info",
"A metric with a constant '1' value labeled by name, version",
std::map<std::string, std::string>{
{"name", app_config_->nodeName()},
{"version", app_config_->nodeVersion()}})
->set(1);
}

void ApplicationImpl::run() {
26 changes: 14 additions & 12 deletions src/app/impl/application_impl.hpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@

#include <memory>

#include <qtils/strict_sptr.hpp>

#include <metrics/registry.hpp>

namespace jam {
@@ -43,22 +45,22 @@ namespace jam::app {

class ApplicationImpl final : public Application {
public:
ApplicationImpl(std::shared_ptr<log::LoggingSystem> logsys,
std::shared_ptr<Configuration> config,
std::shared_ptr<StateManager> state_manager,
std::shared_ptr<Watchdog> watchdog,
std::shared_ptr<metrics::Exposer> metrics_exposer,
std::shared_ptr<clock::SystemClock> system_clock);
ApplicationImpl(qtils::StrictSharedPtr<log::LoggingSystem> logsys,
qtils::StrictSharedPtr<Configuration> config,
qtils::StrictSharedPtr<StateManager> state_manager,
qtils::StrictSharedPtr<Watchdog> watchdog,
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
qtils::StrictSharedPtr<clock::SystemClock> system_clock);

void run() override;

private:
std::shared_ptr<soralog::Logger> logger_;
std::shared_ptr<Configuration> app_config_;
std::shared_ptr<StateManager> state_manager_;
std::shared_ptr<Watchdog> watchdog_;
std::shared_ptr<metrics::Exposer> metrics_exposer_;
std::shared_ptr<clock::SystemClock> system_clock_;
qtils::StrictSharedPtr<soralog::Logger> logger_;
qtils::StrictSharedPtr<Configuration> app_config_;
qtils::StrictSharedPtr<StateManager> state_manager_;
qtils::StrictSharedPtr<Watchdog> watchdog_;
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer_;
qtils::StrictSharedPtr<clock::SystemClock> system_clock_;

// Metrics
std::unique_ptr<metrics::Registry> metrics_registry_;
2 changes: 1 addition & 1 deletion src/app/impl/state_manager_impl.cpp
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ namespace jam::app {
}

StateManagerImpl::StateManagerImpl(
std::shared_ptr<log::LoggingSystem> logging_system)
qtils::StrictSharedPtr<log::LoggingSystem> logging_system)
: logger_(logging_system->getLogger("StateManager", "application")),
logging_system_(std::move(logging_system)) {
shuttingDownSignalsEnable();
9 changes: 5 additions & 4 deletions src/app/impl/state_manager_impl.hpp
Original file line number Diff line number Diff line change
@@ -9,10 +9,11 @@
#include "app/state_manager.hpp"

#include <condition_variable>
#include <csignal>
#include <mutex>
#include <queue>

#include <qtils/strict_sptr.hpp>

#include "utils/ctor_limiters.hpp"

namespace soralog {
@@ -29,7 +30,7 @@ namespace jam::app {
public StateManager,
public std::enable_shared_from_this<StateManagerImpl> {
public:
StateManagerImpl(std::shared_ptr<log::LoggingSystem> logging_system);
StateManagerImpl(qtils::StrictSharedPtr<log::LoggingSystem> logging_system);

~StateManagerImpl() override;

@@ -66,8 +67,8 @@ namespace jam::app {

void shutdownRequestWaiting();

std::shared_ptr<soralog::Logger> logger_;
std::shared_ptr<log::LoggingSystem> logging_system_;
qtils::StrictSharedPtr<soralog::Logger> logger_;
qtils::StrictSharedPtr<log::LoggingSystem> logging_system_;

std::atomic<State> state_ = State::Init;

4 changes: 2 additions & 2 deletions src/injector/node_injector.cpp
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ namespace {

template <typename C>
auto useConfig(C c) {
return boost::di::bind<std::decay_t<C> >().to(
return boost::di::bind<std::decay_t<C>>().to(
std::move(c))[boost::di::override];
}

@@ -96,6 +96,6 @@ namespace jam::injector {

std::shared_ptr<app::Application> NodeInjector::injectApplication() {
return pimpl_->injector_
.template create<std::shared_ptr<app::Application> >();
.template create<std::shared_ptr<app::Application>>();
}
} // namespace jam::injector
1 change: 1 addition & 0 deletions src/loaders/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# loaders are locating here
34 changes: 34 additions & 0 deletions src/loaders/loader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "injector/node_injector.hpp"
#include "modules/module.hpp"

namespace jam::loaders {

class Loader {
public:
Loader(const Loader &) = delete;
Loader &operator=(const Loader &) = delete;

virtual ~Loader() = default;
virtual void start() = 0;

std::optional<std::string> module_info() {
auto result = module_.getFunctionFromLibrary<const char*()>("module_info");
if (result) {
return std::string((*result)());
}
return std::nullopt;
}

protected:
injector::NodeInjector injector_;
modules::Module module_;
};
} // namespace jam::loaders
22 changes: 12 additions & 10 deletions src/log/logger.hpp
Original file line number Diff line number Diff line change
@@ -9,19 +9,22 @@
#include <memory>
#include <sstream>

#include <qtils/outcome.hpp>
#include <qtils/enum_error_code.hpp>
#include <qtils/outcome.hpp>
#include <qtils/strict_sptr.hpp>
#include <soralog/level.hpp>
#include <soralog/logger.hpp>
#include <soralog/logging_system.hpp>
#include <soralog/macro.hpp>

#include "utils/ctor_limiters.hpp"
#include "injector/dont_inject.hpp"
#include "utils/ctor_limiters.hpp"

namespace jam::log {
using soralog::Level;

using Logger = qtils::StrictSharedPtr<soralog::Logger>;

enum class Error : uint8_t { WRONG_LEVEL = 1, WRONG_GROUP, WRONG_LOGGER };

outcome::result<Level> str2lvl(std::string_view str);
@@ -58,23 +61,22 @@ namespace jam::log {
return logging_system_->getLogger(logger_name, group_name, level);
}

[[nodiscard]]
bool setLevelOfGroup(const std::string &group_name, Level level) const {
[[nodiscard]] bool setLevelOfGroup(const std::string &group_name,
Level level) const {
return logging_system_->setLevelOfGroup(group_name, level);
}

[[nodiscard]]
bool resetLevelOfGroup(const std::string &group_name) const {
[[nodiscard]] bool resetLevelOfGroup(const std::string &group_name) const {
return logging_system_->resetLevelOfGroup(group_name);
}

[[nodiscard]]
bool setLevelOfLogger(const std::string &logger_name, Level level) const {
[[nodiscard]] bool setLevelOfLogger(const std::string &logger_name,
Level level) const {
return logging_system_->setLevelOfLogger(logger_name, level);
}

[[nodiscard]]
bool resetLevelOfLogger(const std::string &logger_name) const {
[[nodiscard]] bool resetLevelOfLogger(
const std::string &logger_name) const {
return logging_system_->resetLevelOfLogger(logger_name);
}

6 changes: 6 additions & 0 deletions src/metrics/histogram_timer.hpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,12 @@ namespace jam::metrics {
registry_->registerGaugeFamily(name, help);
metric_ = registry_->registerGaugeMetric(name);
}
GaugeHelper(const std::string &name,
const std::string &help,
const std::map<std::string, std::string> &labels) {
registry_->registerGaugeFamily(name, help);
metric_ = registry_->registerGaugeMetric(name, labels);
}

auto *operator->() const {
return metric_;
87 changes: 87 additions & 0 deletions src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# Copyright Quadrivium LLC
# All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#

function(add_jam_module NAME)
set(MODULE_NAME ${NAME})

set(MODULE "${MODULE_NAME}_module")

# Parse named arguments
cmake_parse_arguments(
# Prefix for parsed argument variables
MODULE
# List of flags (boolean arguments without values)
""
# List of named arguments with a single value
""
# List of named arguments with multiple values
"SOURCE;INCLUDE_DIRS;LIBRARIES;DEFINITIONS"
# Input arguments
${ARGN}
)

if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/module.cpp)
message(FATAL_ERROR "Not found `module.cpp` file (main file of module)")
endif ()
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}.hpp" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}.cpp")
message(FATAL_ERROR "Not found `${MODULE_NAME}.hpp` nor `${MODULE_NAME}.cpp` file (class of module)")
endif ()

# Create a shared module library
add_library(${MODULE} MODULE # or SHARED
module.cpp
${MODULE_NAME}.cpp
${MODULE_SOURCE}
)

# Set exported symbols visibility
set_target_properties(${MODULE} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)

# Set include directories
if (MODULE_INCLUDE_DIRS)
target_include_directories(${MODULE} PRIVATE
${MODULE_INCLUDE_DIRS}
)
endif ()

# Set definitions specified for module
if (MODULE_DEFINITIONS)
target_compile_definitions(${MODULE} PRIVATE
${MODULE_DEFINITIONS}
)
endif ()

# Link with libs
if (MODULE_LIBRARIES)
target_link_libraries(${MODULE}
${MODULE_LIBRARIES}
)
endif ()

# Set C++ standard
target_compile_features(${MODULE} PRIVATE
cxx_std_20
)

endfunction()

# -------------- Core-part of module subsystem --------------

add_library(modules
module_loader.cpp
)

target_link_libraries(modules
qtils::qtils
)

# -------------- Modules --------------

# Example module
add_subdirectory(example)
1 change: 1 addition & 0 deletions src/modules/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# modules are locating here
Loading