X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ee1709cd231588fe672d0bd2546ef69ee87ff88c..0c097ef3435d2a45c1ee4ac80f8bd3f254fb8df5:/projects/stargazer/plugins/other/smux/smux.cpp?ds=inline diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 8d5079bd..a6ab8359 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -1,12 +1,7 @@ -#include -#include -#include +#include "smux.h" +#include "utils.h" -#include -#include -#include -#include -#include +#include "stg/common.h" #include #include @@ -14,10 +9,18 @@ #include #include -#include "stg/common.h" +#include +#include +#include +#include +#include -#include "smux.h" -#include "utils.h" +#include +#include +#include + +using STG::SMUX; +using STG::SMUX_SETTINGS; namespace { @@ -41,9 +44,9 @@ SMUX_SETTINGS::SMUX_SETTINGS() port(0) {} -int SMUX_SETTINGS::ParseSettings(const STG::ModuleSettings & s) +int SMUX_SETTINGS::ParseSettings(const ModuleSettings & s) { -STG::ParamValue pv; +ParamValue pv; int p; pv.param = "Port"; @@ -100,8 +103,7 @@ SMUX::SMUX() lastReconnectTry(0), reconnectTimeout(1), sock(-1), - addDelTariffNotifier(*this), - logger(STG::PluginLogger::get("smux")) + logger(PluginLogger::get("smux")) { smuxHandlers[SMUX_PDUs_PR_close] = &SMUX::CloseHandler; smuxHandlers[SMUX_PDUs_PR_registerResponse] = &SMUX::RegisterResponseHandler; @@ -227,7 +229,7 @@ printfd(__FILE__, "SMUX::Stop() - After\n"); return 0; } -int SMUX::Reload(const STG::ModuleSettings & /*ms*/) +int SMUX::Reload(const ModuleSettings & /*ms*/) { if (Stop() != 0) return -1; @@ -412,23 +414,17 @@ return true; void SMUX::SetNotifier(UserPtr userPtr) { -notifiers.emplace_back(*this, userPtr); -userPtr->GetProperties().tariffName.AddAfterNotifier(¬ifiers.back()); + m_conns.emplace_back( + userPtr->GetID(), + userPtr->GetProperties().tariffName.afterChange([this](const auto&, const auto&){ UpdateTables(); }) + ); } void SMUX::UnsetNotifier(UserPtr userPtr) { -auto it = notifiers.begin(); -while (it != notifiers.end()) - { - if (it->GetUserPtr() == userPtr) - { - userPtr->GetProperties().tariffName.DelAfterNotifier(&(*it)); - notifiers.erase(it); - break; - } - ++it; - } + m_conns.erase(std::remove_if(m_conns.begin(), m_conns.end(), + [userPtr](const auto& c){ return std::get<0>(c) == userPtr->GetID(); }), + m_conns.end()); } void SMUX::SetNotifiers() @@ -442,32 +438,27 @@ while (users->SearchNext(h, &u) == 0) users->CloseSearch(h); -m_onAddUserConn = users->onUserAdd([this](auto user){ +m_onAddUserConn = users->onAdd([this](auto user){ SetNotifier(user); UpdateTables(); }); -m_onDelUserConn = users->onUserDel([this](auto user){ +m_onDelUserConn = users->onDel([this](auto user){ UnsetNotifier(user); UpdateTables(); }); -tariffs->AddNotifierAdd(&addDelTariffNotifier); -tariffs->AddNotifierDel(&addDelTariffNotifier); +auto updateTables = [this](const TariffData&){ UpdateTables(); }; +m_onAddTariffConn = tariffs->onAdd(updateTables); +m_onDelTariffConn = tariffs->onDel(updateTables); } void SMUX::ResetNotifiers() { -tariffs->DelNotifierDel(&addDelTariffNotifier); -tariffs->DelNotifierAdd(&addDelTariffNotifier); +m_onAddTariffConn.disconnect(); +m_onDelTariffConn.disconnect(); m_onAddUserConn.disconnect(); m_onDelUserConn.disconnect(); -auto it = notifiers.begin(); -while (it != notifiers.end()) - { - it->GetUserPtr()->GetProperties().tariffName.DelAfterNotifier(&(*it)); - ++it; - } -notifiers.clear(); +m_conns.clear(); }