From 9769c24005ad8fa8a4d6dfc70954cb1248a6037d Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Tue, 12 Nov 2024 01:00:22 +0300 Subject: [PATCH] ... --- common/adc_spdlog.h | 6 ++++-- net/adc_device_netmsg.h | 6 ++++++ net/adc_device_netserver.h | 11 +++++++++++ net/adc_net_concepts.h | 14 ++++++++++++++ net/adc_netserver.h | 4 +++- net/adc_netserver_spdlog.h | 22 ++++++++++------------ 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/common/adc_spdlog.h b/common/adc_spdlog.h index e76ce9f..e76b9a3 100644 --- a/common/adc_spdlog.h +++ b/common/adc_spdlog.h @@ -23,7 +23,7 @@ protected: std::string _currentPattern; public: - constexpr static std::string_view LOGGER_DEFAULT_FORMAT = "[%Y-%m-%d %T.%e] [%l]: [%v]"; + constexpr static std::string_view LOGGER_DEFAULT_FORMAT = "[%Y-%m-%d %T.%e] [%l]: %v"; template AdcSpdlogGenericDecorator(const R& pattern, std::shared_ptr logger, BaseCtorArgTs&&... ctor_args) @@ -161,7 +161,7 @@ protected: using base_t = AdcSpdlogGenericDecorator; public: - constexpr static std::array LOGGER_DEFAULT_FORMAT{"[%Y-%m-%d %T.%e] [%l]: ", "[%v]"}; + constexpr static std::array LOGGER_DEFAULT_FORMAT{"[%Y-%m-%d %T.%e] [%l] ", "%v"}; template static std::string constructPattern(const R& mark, size_t after_idx = 0, const IR& format = LOGGER_DEFAULT_FORMAT) @@ -169,7 +169,9 @@ public: std::string pattern; std::ranges::copy(format | std::views::take(after_idx + 1) | std::views::join, std::back_inserter(pattern)); + std::ranges::copy(std::string_view("["), std::back_inserter(pattern)); std::ranges::copy(mark, std::back_inserter(pattern)); + std::ranges::copy(std::string_view("]: "), std::back_inserter(pattern)); std::ranges::copy(format | std::views::drop(after_idx + 1) | std::views::join, std::back_inserter(pattern)); return pattern; diff --git a/net/adc_device_netmsg.h b/net/adc_device_netmsg.h index 4c96808..982c7a5 100644 --- a/net/adc_device_netmsg.h +++ b/net/adc_device_netmsg.h @@ -49,6 +49,12 @@ public: return std::ranges::size(_byteSequence) == 0; } + + size_t size() const + { + return std::ranges::size(_byteSequence); + } + template requires(traits::adc_char_view && std::ranges::contiguous_range) || traits::adc_output_char_range diff --git a/net/adc_device_netserver.h b/net/adc_device_netserver.h index 099ce7c..6788cf8 100644 --- a/net/adc_device_netserver.h +++ b/net/adc_device_netserver.h @@ -232,6 +232,13 @@ public: _recvTimeout(ctx.recvTimeout), _sendTimeout(ctx.sendTimeout) { + _serverPtr->logInfo("Create client session with ID = {} (addr = {})", _ident, (void*)this); + } + + + virtual ~Session() + { + _serverPtr->logInfo("Delete client session with ID = {} (addr = {})", _ident, (void*)this); } netsession_ident_t ident() const @@ -241,6 +248,8 @@ public: void start() { + _serverPtr->logInfo("Start client session with ID = {} (addr = {})", _ident, (void*)this); + auto self(this->shared_from_this()); _netService.asyncReceive( @@ -281,6 +290,8 @@ public: void stop() { + _serverPtr->logInfo("Stop client session with ID = {} (addr = {})", _ident, (void*)this); + _netService.close(); } diff --git a/net/adc_net_concepts.h b/net/adc_net_concepts.h index bed4cb4..b35e570 100644 --- a/net/adc_net_concepts.h +++ b/net/adc_net_concepts.h @@ -223,4 +223,18 @@ concept adc_netsession_proto_c = }; + +/* LOGGER */ + +template +concept adc_logger_c = requires(LOGGERT log) { + // logging method must accept at least the single argument - formating string + log.logInfo(std::declval()); + log.logInfo(std::declval(), std::declval()); + + log.logWarn(std::declval(), std::declval()); + log.logError(std::declval(), std::declval()); +}; + + } // namespace adc::interfaces diff --git a/net/adc_netserver.h b/net/adc_netserver.h index 1a725f3..4f9884d 100644 --- a/net/adc_netserver.h +++ b/net/adc_netserver.h @@ -36,7 +36,7 @@ class AdcTrivialLogger public: virtual ~AdcTrivialLogger() = default; -protected: + // protected: static constexpr std::string_view errorLevelMark{"error"}; static constexpr std::string_view warnLevelMark{"warning"}; static constexpr std::string_view infoLevelMark{"info"}; @@ -109,6 +109,8 @@ protected: }; +static_assert(interfaces::adc_logger_c, "!!!!!!!!!!!"); + // A generic implementation of POSIX OS daemon class AdcPosixGenericDaemon { diff --git a/net/adc_netserver_spdlog.h b/net/adc_netserver_spdlog.h index 9c09403..ad2ac74 100644 --- a/net/adc_netserver_spdlog.h +++ b/net/adc_netserver_spdlog.h @@ -21,12 +21,11 @@ ABSTRACT DEVICE COMPONENTS LIBRARY namespace adc::spdlog { -template - requires traits::formattable -class AdcGenericNetServerSpdlog : public AdcSpdlogGenericMarkDecorator +template +class AdcGenericNetServerSpdlog : public AdcSpdlogGenericMarkDecorator> { protected: - using base_t = AdcSpdlogGenericMarkDecorator; + using base_t = AdcSpdlogGenericMarkDecorator>; std::string _serverID; @@ -36,7 +35,7 @@ protected: } public: - using typename ServerT::server_ident_t; + using typename base_t::server_ident_t; using base_t::logCritical; using base_t::logDebug; @@ -53,7 +52,7 @@ public: { this->logMethodCalling(__PRETTY_FUNCTION__); - fmt::format_to(std::back_inserter(_serverID), "{}", ServerT::_serverIdent); + fmt::format_to(std::back_inserter(_serverID), "{}", base_t::_serverIdent); this->setPattern(base_t::constructPattern(_serverID)); @@ -75,7 +74,7 @@ public: { this->logMethodCalling(__PRETTY_FUNCTION__); - return ServerT::ident(); + return base_t::ident(); } template @@ -89,7 +88,7 @@ public: logInfo("Start accepting client connections for server session ID hash: {} ...", std::hash(id)); } - ServerT::start(std::move(id), std::move(sess_ctx), std::forward(ctor_args)...); + base_t::start(std::move(id), std::move(sess_ctx), std::forward(ctor_args)...); } virtual void stop() @@ -98,7 +97,7 @@ public: logInfo("Stopping network server ..."); - ServerT::stop(); + base_t::stop(); logInfo("Network server is stopped"); } @@ -109,18 +108,17 @@ public: { this->logMethodCalling(__PRETTY_FUNCTION__); - ServerT::_isListening(id); + base_t::_isListening(id); } void daemonize() - requires std::derived_from { this->logMethodCalling(__PRETTY_FUNCTION__); logInfo("Daemonizing server ..."); - ServerT::daemonize(); + base_t::daemonize(); logInfo("The server was daemonized"); }