Skip to content

Commit dcf68c2

Browse files
committed
refactor: use strict shared ptr
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent bbfe084 commit dcf68c2

8 files changed

+46
-38
lines changed

src/app/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ add_library(build_version
2828

2929
add_library(app_configuration SHARED configuration.cpp)
3030
target_link_libraries(app_configuration
31-
Boost::boost)
31+
Boost::boost
32+
fmt::fmt
33+
)
3234

3335
add_library(app_configurator SHARED configurator.cpp)
3436
target_link_libraries(app_configurator

src/app/impl/application_impl.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
namespace jam::app {
2121

2222
ApplicationImpl::ApplicationImpl(
23-
std::shared_ptr<log::LoggingSystem> logsys,
24-
std::shared_ptr<Configuration> config,
25-
std::shared_ptr<StateManager> state_manager,
26-
std::shared_ptr<Watchdog> watchdog,
27-
std::shared_ptr<metrics::Exposer> metrics_exposer,
28-
std::shared_ptr<clock::SystemClock> system_clock)
23+
qtils::StrictSharedPtr<log::LoggingSystem> logsys,
24+
qtils::StrictSharedPtr<Configuration> config,
25+
qtils::StrictSharedPtr<StateManager> state_manager,
26+
qtils::StrictSharedPtr<Watchdog> watchdog,
27+
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
28+
qtils::StrictSharedPtr<clock::SystemClock> system_clock)
2929
: logger_(logsys->getLogger("Application", "application")),
3030
app_config_(std::move(config)),
3131
state_manager_(std::move(state_manager)),

src/app/impl/application_impl.hpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <memory>
1212

13+
#include <qtils/strict_sptr.hpp>
14+
1315
#include <metrics/registry.hpp>
1416

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

4446
class ApplicationImpl final : public Application {
4547
public:
46-
ApplicationImpl(std::shared_ptr<log::LoggingSystem> logsys,
47-
std::shared_ptr<Configuration> config,
48-
std::shared_ptr<StateManager> state_manager,
49-
std::shared_ptr<Watchdog> watchdog,
50-
std::shared_ptr<metrics::Exposer> metrics_exposer,
51-
std::shared_ptr<clock::SystemClock> system_clock);
48+
ApplicationImpl(qtils::StrictSharedPtr<log::LoggingSystem> logsys,
49+
qtils::StrictSharedPtr<Configuration> config,
50+
qtils::StrictSharedPtr<StateManager> state_manager,
51+
qtils::StrictSharedPtr<Watchdog> watchdog,
52+
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
53+
qtils::StrictSharedPtr<clock::SystemClock> system_clock);
5254

5355
void run() override;
5456

5557
private:
56-
std::shared_ptr<soralog::Logger> logger_;
57-
std::shared_ptr<Configuration> app_config_;
58-
std::shared_ptr<StateManager> state_manager_;
59-
std::shared_ptr<Watchdog> watchdog_;
60-
std::shared_ptr<metrics::Exposer> metrics_exposer_;
61-
std::shared_ptr<clock::SystemClock> system_clock_;
58+
qtils::StrictSharedPtr<soralog::Logger> logger_;
59+
qtils::StrictSharedPtr<Configuration> app_config_;
60+
qtils::StrictSharedPtr<StateManager> state_manager_;
61+
qtils::StrictSharedPtr<Watchdog> watchdog_;
62+
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer_;
63+
qtils::StrictSharedPtr<clock::SystemClock> system_clock_;
6264

6365
// Metrics
6466
std::unique_ptr<metrics::Registry> metrics_registry_;

src/app/impl/state_manager_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace jam::app {
9292
}
9393

9494
StateManagerImpl::StateManagerImpl(
95-
std::shared_ptr<log::LoggingSystem> logging_system)
95+
qtils::StrictSharedPtr<log::LoggingSystem> logging_system)
9696
: logger_(logging_system->getLogger("StateManager", "application")),
9797
logging_system_(std::move(logging_system)) {
9898
shuttingDownSignalsEnable();

src/app/impl/state_manager_impl.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include "app/state_manager.hpp"
1010

1111
#include <condition_variable>
12-
#include <csignal>
1312
#include <mutex>
1413
#include <queue>
1514

15+
#include <qtils/strict_sptr.hpp>
16+
1617
#include "utils/ctor_limiters.hpp"
1718

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

3435
~StateManagerImpl() override;
3536

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

6768
void shutdownRequestWaiting();
6869

69-
std::shared_ptr<soralog::Logger> logger_;
70-
std::shared_ptr<log::LoggingSystem> logging_system_;
70+
qtils::StrictSharedPtr<soralog::Logger> logger_;
71+
qtils::StrictSharedPtr<log::LoggingSystem> logging_system_;
7172

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

src/injector/node_injector.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace {
2929

3030
template <typename C>
3131
auto useConfig(C c) {
32-
return boost::di::bind<std::decay_t<C> >().to(
32+
return boost::di::bind<std::decay_t<C>>().to(
3333
std::move(c))[boost::di::override];
3434
}
3535

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

9797
std::shared_ptr<app::Application> NodeInjector::injectApplication() {
9898
return pimpl_->injector_
99-
.template create<std::shared_ptr<app::Application> >();
99+
.template create<std::shared_ptr<app::Application>>();
100100
}
101101
} // namespace jam::injector

src/log/logger.hpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
#include <memory>
1010
#include <sstream>
1111

12-
#include <qtils/outcome.hpp>
1312
#include <qtils/enum_error_code.hpp>
13+
#include <qtils/outcome.hpp>
14+
#include <qtils/strict_sptr.hpp>
1415
#include <soralog/level.hpp>
1516
#include <soralog/logger.hpp>
1617
#include <soralog/logging_system.hpp>
1718
#include <soralog/macro.hpp>
1819

19-
#include "utils/ctor_limiters.hpp"
2020
#include "injector/dont_inject.hpp"
21+
#include "utils/ctor_limiters.hpp"
2122

2223
namespace jam::log {
2324
using soralog::Level;
2425

26+
using Logger = qtils::StrictSharedPtr<soralog::Logger>;
27+
2528
enum class Error : uint8_t { WRONG_LEVEL = 1, WRONG_GROUP, WRONG_LOGGER };
2629

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

61-
[[nodiscard]]
62-
bool setLevelOfGroup(const std::string &group_name, Level level) const {
64+
[[nodiscard]] bool setLevelOfGroup(const std::string &group_name,
65+
Level level) const {
6366
return logging_system_->setLevelOfGroup(group_name, level);
6467
}
6568

66-
[[nodiscard]]
67-
bool resetLevelOfGroup(const std::string &group_name) const {
69+
[[nodiscard]] bool resetLevelOfGroup(const std::string &group_name) const {
6870
return logging_system_->resetLevelOfGroup(group_name);
6971
}
7072

71-
[[nodiscard]]
72-
bool setLevelOfLogger(const std::string &logger_name, Level level) const {
73+
[[nodiscard]] bool setLevelOfLogger(const std::string &logger_name,
74+
Level level) const {
7375
return logging_system_->setLevelOfLogger(logger_name, level);
7476
}
7577

76-
[[nodiscard]]
77-
bool resetLevelOfLogger(const std::string &logger_name) const {
78+
[[nodiscard]] bool resetLevelOfLogger(
79+
const std::string &logger_name) const {
7880
return logging_system_->resetLevelOfLogger(logger_name);
7981
}
8082

vcpkg-overlay/qtils/portfile.cmake

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
22
vcpkg_from_github(
33
OUT_SOURCE_PATH SOURCE_PATH
44
REPO qdrvm/qtils
5-
REF refs/tags/v0.1.0
6-
SHA512 301987eefc98b66c42dcf731d73c11c3e9835098fc3d9a1b8e3adef9b73dad6b0198019d416e1809956620377b48e575157d56b278dcdcf65a24ecdfc134605e
5+
# REF refs/tags/v0.1.0
6+
REF 7fa095bed51f9c1b7d4a2c99552229df380373ea
7+
SHA512 b03d6d324c28b57f20d23ae17be1e61fddf6d394c2b6fd5fff886d36018a12bd83593e25718e9d7f1ed88f8fb3b6ab71b5fb7c7b3f2f208493c8d16b22a0af2a
78
)
89
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}")
910
vcpkg_cmake_install()

0 commit comments

Comments
 (0)