AdcDeviceNetServerASIO classes now have template parameter 'IdentT' (type of identificator)
253 lines
7.2 KiB
C++
253 lines
7.2 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 <interfaces::adc_generic_netserver_c ServerT>
|
|
requires traits::formattable<typename ServerT::server_ident_t>
|
|
class AdcGenericNetServerSpdlog : public AdcSpdlogGenericMarkDecorator<ServerT>
|
|
{
|
|
protected:
|
|
using base_t = AdcSpdlogGenericMarkDecorator<ServerT>;
|
|
|
|
std::string _serverID;
|
|
|
|
public:
|
|
using typename ServerT::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), "{}", ServerT::_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 server_ident_t ident() const
|
|
{
|
|
this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
return ServerT::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));
|
|
}
|
|
|
|
ServerT::start(std::move(id), std::move(sess_ctx), std::forward<AcceptorCtorArgTs>(ctor_args)...);
|
|
}
|
|
|
|
virtual void stop()
|
|
{
|
|
this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
logInfo("Stopping network server ...");
|
|
|
|
ServerT::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__);
|
|
|
|
ServerT::_isListening(id);
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
};
|
|
|
|
// template <traits::adc_netserver_session_c SessionT>
|
|
// class AdcNetServerSessionSpdlogDecorator : public AdcSpdlogGenericMarkDecorator<SessionT>
|
|
// {
|
|
// protected:
|
|
// using base_t = AdcSpdlogGenericMarkDecorator<SessionT>;
|
|
|
|
// std::string _sessionID;
|
|
|
|
// public:
|
|
// using base_t::logDebug;
|
|
// using base_t::logInfo;
|
|
// using base_t::logMethodCalling;
|
|
|
|
// // using SessionT::sessionIdent;
|
|
// using typename SessionT::session_ident_t;
|
|
|
|
// static_assert(traits::formattable<session_ident_t>, "NETWORK SESSION IDENT TYPE MUST BE A FORMATTABLE ONE!!!");
|
|
|
|
// template <typename... ImplCtorArgTs>
|
|
// AdcNetServerSessionSpdlogDecorator(std::shared_ptr<spdlog::logger> logger, ImplCtorArgTs&&... ctor_args)
|
|
// : base_t("ADC NETSERVER SESSION", logger, std::forward<ImplCtorArgTs>(ctor_args)...)
|
|
// {
|
|
// logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// fmt::format_to(std::back_inserter(_sessionID), "{}", SessionT::sessionIdent());
|
|
|
|
// this->setPattern(base_t::constructPattern(_sessionID));
|
|
|
|
// logDebug("Creating network server session with ID = [{}] (ADDR = {})", _sessionID, this->_thisAddress);
|
|
// logDebug("Use logger with ", this->loggerInfo());
|
|
// }
|
|
|
|
// virtual ~AdcNetServerSessionSpdlogDecorator()
|
|
// {
|
|
// logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logDebug("Deleting network server session with ID = [{}] (ADDR = {})", _sessionID, this->_thisAddress);
|
|
// };
|
|
|
|
// virtual session_ident_t sessionIdent() const override
|
|
// {
|
|
// logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// return SessionT::sessionIdent();
|
|
// };
|
|
|
|
// virtual void start() override
|
|
// {
|
|
// logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logInfo("Starting network server session with ID = [{}]", _sessionID);
|
|
|
|
// SessionT::start();
|
|
|
|
// logInfo("Network server session [{}] is started", _sessionID);
|
|
// };
|
|
|
|
// virtual void stop() override
|
|
// {
|
|
// logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logInfo("Stopping network server session with ID = [{}]", _sessionID);
|
|
|
|
// SessionT::stop();
|
|
|
|
// logInfo("Network server session [{}] is stopped", _sessionID);
|
|
// };
|
|
// };
|
|
|
|
|
|
|
|
// template <traits::adc_netserver_c ServerT>
|
|
// class AdcNetServerSpdlogDecorator : public AdcSpdlogGenericMarkDecorator<ServerT>
|
|
// {
|
|
// protected:
|
|
// using base_t = AdcSpdlogGenericMarkDecorator<ServerT>;
|
|
|
|
// std::string _serverID;
|
|
|
|
// public:
|
|
// using base_t::logCritical;
|
|
// using base_t::logDebug;
|
|
// using base_t::logError;
|
|
// using base_t::logInfo;
|
|
// using base_t::logMsg;
|
|
// using base_t::logWarn;
|
|
|
|
// using typename ServerT::server_ident_t;
|
|
|
|
// static_assert(traits::formattable<server_ident_t>, "NETWORK SERVER IDENT TYPE MUST BE A FORMATTABLE ONE!!!");
|
|
|
|
// template <typename... ImplCtorArgTs>
|
|
// AdcNetServerSpdlogDecorator(std::shared_ptr<spdlog::logger> logger, ImplCtorArgTs&&... ctor_args)
|
|
// : base_t("ADC NETSERVER", logger, std::forward<ImplCtorArgTs>(ctor_args)...)
|
|
// {
|
|
// this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// fmt::format_to(std::back_inserter(_serverID), "{}", ServerT::serverIdent());
|
|
|
|
// this->setPattern(base_t::constructPattern(_serverID));
|
|
|
|
// logDebug("Creating network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress);
|
|
// logDebug("Use logger with ", this->loggerInfo());
|
|
// }
|
|
|
|
|
|
// virtual ~AdcNetServerSpdlogDecorator()
|
|
// {
|
|
// this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logDebug("Deleting network server with ID = [{}] (ADDR = {})", _serverID, this->_thisAddress);
|
|
// }
|
|
|
|
|
|
// virtual server_ident_t serverIdent() const
|
|
// {
|
|
// this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// return ServerT::serverIdent();
|
|
// }
|
|
|
|
// virtual void start()
|
|
// {
|
|
// this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logInfo("Starting network server");
|
|
|
|
// ServerT::start();
|
|
|
|
// logInfo("Network server is started");
|
|
// };
|
|
|
|
// virtual void stop()
|
|
// {
|
|
// this->logMethodCalling(__PRETTY_FUNCTION__);
|
|
|
|
// logInfo("Stopping network server ...");
|
|
|
|
// ServerT::stop();
|
|
|
|
// logInfo("Network server is stopped");
|
|
// };
|
|
// };
|
|
|
|
} // namespace adc::spdlog
|
|
|
|
#endif
|