X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/479b8853c2ab18c98926a9369a03888021e9b986..1cd2b12bd4e4d86f6cd099240795f3ebeb3852b3:/projects/stargazer/plugins/other/ping/ping.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index 53f7b2f0..71752de6 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -50,7 +50,7 @@ if (pvi == s.moduleParams.end() || pvi->value.empty()) printfd(__FILE__, "Parameter 'PingDelay' not found\n"); return -1; } -if (ParseIntInRange(pvi->value[0], 5, 3600, &pingDelay)) +if (ParseIntInRange(pvi->value[0], 5, 3600, &pingDelay) != 0) { errorStr = "Cannot parse parameter \'PingDelay\': " + errorStr; printfd(__FILE__, "Canot parse parameter 'PingDelay'\n"); @@ -61,22 +61,16 @@ return 0; } //----------------------------------------------------------------------------- PING::PING() - : users(NULL), + : users(nullptr), isRunning(false), - onAddUserNotifier(*this), - onDelUserNotifier(*this), logger(STG::PluginLogger::get("ping")) { } //----------------------------------------------------------------------------- -PING::~PING() -{ -} -//----------------------------------------------------------------------------- int PING::ParseSettings() { -int ret = pingSettings.ParseSettings(settings); -if (ret) +auto ret = pingSettings.ParseSettings(settings); +if (ret != 0) errorStr = pingSettings.GetStrError(); return ret; } @@ -85,13 +79,13 @@ int PING::Start() { GetUsers(); -users->AddNotifierUserAdd(&onAddUserNotifier); -users->AddNotifierUserDel(&onDelUserNotifier); +m_onAddUserConn = users->onAdd([this](auto user){ AddUser(user); }); +m_onDelUserConn = users->onDel([this](auto user){ DelUser(user); }); pinger.SetDelayTime(pingSettings.GetPingDelay()); pinger.Start(); -m_thread = std::jthread([this](auto token){ Run(token); }); +m_thread = std::jthread([this](auto token){ Run(std::move(token)); }); return 0; } @@ -112,11 +106,11 @@ for (int i = 0; i < 25; i++) if (!isRunning) break; - nanosleep(&ts, NULL); + nanosleep(&ts, nullptr); } -users->DelNotifierUserAdd(&onAddUserNotifier); -users->DelNotifierUserDel(&onDelUserNotifier); +m_onAddUserConn.disconnect(); +m_onDelUserConn.disconnect(); std::list::iterator users_iter; users_iter = usersList.begin(); @@ -143,7 +137,7 @@ void PING::Run(std::stop_token token) { sigset_t signalSet; sigfillset(&signalSet); -pthread_sigmask(SIG_BLOCK, &signalSet, NULL); +pthread_sigmask(SIG_BLOCK, &signalSet, nullptr); isRunning = true; @@ -151,7 +145,7 @@ long delay = (10000000 * pingSettings.GetPingDelay()) / 3 + 50000000; while (!token.stop_requested()) { - std::list::iterator iter = usersList.begin(); + auto iter = usersList.begin(); { std::lock_guard lock(m_mutex); while (iter != usersList.end()) @@ -162,19 +156,19 @@ while (!token.stop_requested()) time_t t; if (pinger.GetIPTime(ip, &t) == 0) { - if (t) + if (t != 0) (*iter)->UpdatePingTime(t); } } else { uint32_t ip = (*iter)->GetCurrIP(); - if (ip) + if (ip != 0) { time_t t; if (pinger.GetIPTime(ip, &t) == 0) { - if (t) + if (t != 0) (*iter)->UpdatePingTime(t); } } @@ -187,7 +181,7 @@ while (!token.stop_requested()) { if (!token.stop_requested()) { - nanosleep(&ts, NULL); + nanosleep(&ts, nullptr); } } } @@ -259,7 +253,7 @@ while (users->SearchNext(h, &u) == 0) else { uint32_t ip = u->GetCurrIP(); - if (ip) + if (ip != 0) pinger.AddIP(ip); } } @@ -295,14 +289,14 @@ while (users_iter != usersList.end()) } } //----------------------------------------------------------------------------- -void CHG_CURRIP_NOTIFIER_PING::Notify(const uint32_t & oldIP, const uint32_t & newIP) +void CHG_CURRIP_NOTIFIER_PING::notify(const uint32_t & oldIP, const uint32_t & newIP) { ping.pinger.DelIP(oldIP); -if (newIP) +if (newIP != 0) ping.pinger.AddIP(newIP); } //----------------------------------------------------------------------------- -void CHG_IPS_NOTIFIER_PING::Notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS) +void CHG_IPS_NOTIFIER_PING::notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS) { if (oldIPS.onlyOneIP()) ping.pinger.DelIP(oldIPS[0].ip); @@ -310,14 +304,3 @@ if (oldIPS.onlyOneIP()) if (newIPS.onlyOneIP()) ping.pinger.AddIP(newIPS[0].ip); } -//----------------------------------------------------------------------------- -void ADD_USER_NONIFIER_PING::Notify(const UserPtr & user) -{ -ping.AddUser(user); -} -//----------------------------------------------------------------------------- -void DEL_USER_NONIFIER_PING::Notify(const UserPtr & user) -{ -ping.DelUser(user); -} -//-----------------------------------------------------------------------------