131 lines
3.4 KiB
C++
131 lines
3.4 KiB
C++
#pragma once
|
|
|
|
/*
|
|
|
|
ABSTRACT DEVICE COMPONENTS LIBRARY
|
|
|
|
spdlog-library extensions
|
|
|
|
*/
|
|
|
|
|
|
#ifdef USE_SPDLOG_LIBRARY
|
|
|
|
#include <spdlog/sinks/null_sink.h>
|
|
|
|
#include "../common/adc_spdlog.h"
|
|
#include "../common/adc_traits.h"
|
|
|
|
#include "adc_netserver.h"
|
|
|
|
namespace adc::spdlog
|
|
{
|
|
|
|
template <traits::formattable IdentT = std::string>
|
|
class AdcGenericNetServerSpdlog : public AdcSpdlogGenericMarkDecorator<AdcGenericNetServer<IdentT>>
|
|
{
|
|
protected:
|
|
using base_t = AdcSpdlogGenericMarkDecorator<AdcGenericNetServer<IdentT>>;
|
|
|
|
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 <traits::adc_input_char_range R>
|
|
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 <interfaces::adc_netsession_c SessionT, typename... AcceptorCtorArgTs>
|
|
void start(SessionT::netsession_ident_t id, SessionT::netsession_ctx_t sess_ctx, AcceptorCtorArgTs&&... ctor_args)
|
|
{
|
|
this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
if constexpr (traits::formattable<typename SessionT::netsession_ident_t>) {
|
|
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<SessionT>(id));
|
|
}
|
|
|
|
base_t::start(std::move(id), std::move(sess_ctx), std::forward<AcceptorCtorArgTs>(ctor_args)...);
|
|
}
|
|
|
|
virtual void stop()
|
|
{
|
|
this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
logInfo("Stopping network server ...");
|
|
|
|
base_t::stop();
|
|
|
|
logInfo("Network server is stopped");
|
|
}
|
|
|
|
|
|
template <interfaces::adc_netsession_c SessionT>
|
|
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
|