#pragma once /* ABSTRACT DEVICE COMPONENTS LIBRARY spdlog-library extensions */ #ifdef USE_SPDLOG_LIBRARY #include #include "../common/adc_spdlog.h" #include "../common/adc_traits.h" #include "adc_netserver.h" namespace adc::spdlog { template class AdcGenericNetServerSpdlog : public AdcSpdlogGenericMarkDecorator> { protected: using base_t = AdcSpdlogGenericMarkDecorator>; std::string _serverID; virtual void errorMessage(const std::string& err_msg) { logError(err_msg); } public: using typename base_t::server_ident_t; using base_t::logCritical; using base_t::logDebug; using base_t::logError; using base_t::logInfo; using base_t::logMsg; using base_t::logWarn; template AdcGenericNetServerSpdlog(const server_ident_t& id, const R& mark = std::string_view("ADC GENERIC NETSERVER"), std::shared_ptr<::spdlog::logger> logger = ::spdlog::null_logger_mt("NULL_LOGGER")) : base_t(mark, logger, id) { this->logMethodCalling(__PRETTY_FUNCTION__); fmt::format_to(std::back_inserter(_serverID), "{}", base_t::_serverIdent); this->setPattern(base_t::constructPattern(_serverID)); logDebug("Creating ADC-library generic network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress); logDebug("Use logger with ", this->loggerInfo()); } virtual ~AdcGenericNetServerSpdlog() { this->logMethodCalling(__PRETTY_FUNCTION__); logDebug("Deleting ADC-library generic network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress); } virtual server_ident_t ident() const { this->logMethodCalling(__PRETTY_FUNCTION__); return base_t::ident(); } template void start(SessionT::netsession_ident_t id, SessionT::netsession_ctx_t sess_ctx, AcceptorCtorArgTs&&... ctor_args) { this->logMethodCalling(__PRETTY_FUNCTION__); if constexpr (traits::formattable) { logInfo("Start accepting client connections for server session ID: {} ...", id); } else { // here session ID has hashable type (see AdcGenericNetServer) logInfo("Start accepting client connections for server session ID hash: {} ...", std::hash(id)); } base_t::start(std::move(id), std::move(sess_ctx), std::forward(ctor_args)...); } virtual void stop() { this->logMethodCalling(__PRETTY_FUNCTION__); logInfo("Stopping network server ..."); base_t::stop(); logInfo("Network server is stopped"); } template bool isListening(const typename SessionT::netsession_ident_t& id) const { this->logMethodCalling(__PRETTY_FUNCTION__); base_t::_isListening(id); } void daemonize() { this->logMethodCalling(__PRETTY_FUNCTION__); logInfo("Daemonizing server ..."); base_t::daemonize(); logInfo("The server was daemonized"); } }; } // namespace adc::spdlog #endif