X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/1347f3d1e04bedd1508589173f577673ee2c5554..da585bb94c437f06762a2042ef4c52166b8aafce:/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 7c4050ab..040e3faa 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -1,14 +1,15 @@ -#include -#include -#include -#include -#include +#include "ping.h" #include "stg/user.h" #include "stg/locker.h" #include "stg/user_property.h" #include "stg/plugin_creator.h" -#include "ping.h" + +#include +#include +#include +#include +#include namespace { @@ -17,12 +18,11 @@ PLUGIN_CREATOR pc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ× template -class IS_CONTAINS_USER: public std::binary_function +class HAS_USER: public std::binary_function { public: - IS_CONTAINS_USER(const USER_PTR & u) : user(u) {} + explicit HAS_USER(const USER_PTR & u) : user(u) {} bool operator()(varType notifier) const { return notifier.GetUser() == user; @@ -50,7 +50,7 @@ std::vector::const_iterator pvi; pv.param = "PingDelay"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); -if (pvi == s.moduleParams.end()) +if (pvi == s.moduleParams.end() || pvi->value.empty()) { errorStr = "Parameter \'PingDelay\' not found."; printfd(__FILE__, "Parameter 'PingDelay' not found\n"); @@ -67,18 +67,9 @@ return 0; } //----------------------------------------------------------------------------- PING::PING() - : errorStr(), - pingSettings(), - settings(), - users(NULL), - usersList(), - thread(), - mutex(), + : users(NULL), nonstop(false), isRunning(false), - pinger(), - ChgCurrIPNotifierList(), - ChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this), logger(GetPluginLogger(GetStgLogger(), "ping")) @@ -124,7 +115,7 @@ return 0; //----------------------------------------------------------------------------- int PING::Stop() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (!isRunning) return 0; @@ -173,12 +164,12 @@ PING * ping = static_cast(d); ping->isRunning = true; long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000; - + while (ping->nonstop) { std::list::iterator iter = ping->usersList.begin(); { - STG_LOCKER lock(&ping->mutex, __FILE__, __LINE__); + STG_LOCKER lock(&ping->mutex); while (iter != ping->usersList.end()) { if ((*iter)->GetProperty().ips.ConstData().OnlyOneIP()) @@ -236,8 +227,8 @@ u->GetProperty().ips.AddAfterNotifier(&(*ChgIPNotifierList.begin())); void PING::UnSetUserNotifiers(USER_PTR u) { // --- CurrIP --- -IS_CONTAINS_USER IsContainsUserCurrIP(u); -IS_CONTAINS_USER IsContainsUserIP(u); +HAS_USER IsContainsUserCurrIP(u); +HAS_USER IsContainsUserIP(u); std::list::iterator currIPter; std::list::iterator IPIter; @@ -268,7 +259,7 @@ if (IPIter != ChgIPNotifierList.end()) //----------------------------------------------------------------------------- void PING::GetUsers() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); USER_PTR u; int h = users->OpenSearch(); @@ -286,9 +277,7 @@ while (users->SearchNext(h, &u) == 0) { uint32_t ip = u->GetCurrIP(); if (ip) - { pinger.AddIP(ip); - } } } @@ -297,7 +286,7 @@ users->CloseSearch(h); //----------------------------------------------------------------------------- void PING::AddUser(USER_PTR u) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); SetUserNotifiers(u); usersList.push_back(u); @@ -305,7 +294,7 @@ usersList.push_back(u); //----------------------------------------------------------------------------- void PING::DelUser(USER_PTR u) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); UnSetUserNotifiers(u); @@ -327,22 +316,16 @@ void CHG_CURRIP_NOTIFIER_PING::Notify(const uint32_t & oldIP, const uint32_t & n { ping.pinger.DelIP(oldIP); if (newIP) - { ping.pinger.AddIP(newIP); - } } //----------------------------------------------------------------------------- void CHG_IPS_NOTIFIER_PING::Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS) { if (oldIPS.OnlyOneIP()) - { ping.pinger.DelIP(oldIPS[0].ip); - } if (newIPS.OnlyOneIP()) - { ping.pinger.AddIP(newIPS[0].ip); - } } //----------------------------------------------------------------------------- void ADD_USER_NONIFIER_PING::Notify(const USER_PTR & user)