-#include <cstdio>
-#include <cassert>
-#include <csignal>
-#include <ctime>
-#include <algorithm>
+#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 <cstdio>
+#include <cassert>
+#include <csignal>
+#include <ctime>
+#include <algorithm>
namespace
{
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
template <typename varType>
-class IS_CONTAINS_USER: public std::binary_function<varType, USER_PTR, bool>
+class HAS_USER: public std::binary_function<varType, USER_PTR, bool>
{
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;
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");
}
//-----------------------------------------------------------------------------
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"))
ping->isRunning = true;
long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000;
-
+
while (ping->nonstop)
{
std::list<USER_PTR>::iterator iter = ping->usersList.begin();
void PING::UnSetUserNotifiers(USER_PTR u)
{
// --- CurrIP ---
-IS_CONTAINS_USER<CHG_CURRIP_NOTIFIER_PING> IsContainsUserCurrIP(u);
-IS_CONTAINS_USER<CHG_IPS_NOTIFIER_PING> IsContainsUserIP(u);
+HAS_USER<CHG_CURRIP_NOTIFIER_PING> IsContainsUserCurrIP(u);
+HAS_USER<CHG_IPS_NOTIFIER_PING> IsContainsUserIP(u);
std::list<CHG_CURRIP_NOTIFIER_PING>::iterator currIPter;
std::list<CHG_IPS_NOTIFIER_PING>::iterator IPIter;
{
uint32_t ip = u->GetCurrIP();
if (ip)
- {
pinger.AddIP(ip);
- }
}
}
{
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)