]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/ping/ping.cpp
Remove redundand ctors.
[stg.git] / projects / stargazer / plugins / other / ping / ping.cpp
index 7f47b7cf8464906ee754cc9c3977ca054ca100a8..040e3faa12ac8172aad5fa3e0f1eeba00d728bc0 100644 (file)
@@ -1,50 +1,56 @@
-#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"
 
-PLUGIN_CREATOR<PING> pc;
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
+#include <cstdio>
+#include <cassert>
+#include <csignal>
+#include <ctime>
+#include <algorithm>
+
+namespace
 {
-return pc.GetPlugin();
-}
+PLUGIN_CREATOR<PING> pc;
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
 template <typename varType>
-class IS_CONTAINS_USER: public 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;
-        };
+        }
 private:
     const USER_PTR & user;
 };
+}
+
+extern "C" PLUGIN * GetPlugin();
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+PLUGIN * GetPlugin()
+{
+return pc.GetPlugin();
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 int PING_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
 {
 PARAM_VALUE pv;
-vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<PARAM_VALUE>::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");
@@ -61,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"))
@@ -118,7 +115,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int PING::Stop()
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 
 if (!isRunning)
     return 0;
@@ -138,7 +135,7 @@ for (int i = 0; i < 25; i++)
 users->DelNotifierUserAdd(&onAddUserNotifier);
 users->DelNotifierUserDel(&onDelUserNotifier);
 
-list<USER_PTR>::iterator users_iter;
+std::list<USER_PTR>::iterator users_iter;
 users_iter = usersList.begin();
 while (users_iter != usersList.end())
     {
@@ -167,12 +164,12 @@ PING * ping = static_cast<PING *>(d);
 ping->isRunning = true;
 
 long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000;
+
 while (ping->nonstop)
     {
-    list<USER_PTR>::iterator iter = ping->usersList.begin();
+    std::list<USER_PTR>::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())
@@ -230,11 +227,11 @@ u->GetProperty().ips.AddAfterNotifier(&(*ChgIPNotifierList.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);
 
-list<CHG_CURRIP_NOTIFIER_PING>::iterator currIPter;
-list<CHG_IPS_NOTIFIER_PING>::iterator IPIter;
+std::list<CHG_CURRIP_NOTIFIER_PING>::iterator currIPter;
+std::list<CHG_IPS_NOTIFIER_PING>::iterator IPIter;
 
 currIPter = find_if(ChgCurrIPNotifierList.begin(),
                     ChgCurrIPNotifierList.end(),
@@ -262,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();
@@ -280,9 +277,7 @@ while (users->SearchNext(h, &u) == 0)
         {
         uint32_t ip = u->GetCurrIP();
         if (ip)
-            {
             pinger.AddIP(ip);
-            }
         }
     }
 
@@ -291,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);
@@ -299,11 +294,11 @@ usersList.push_back(u);
 //-----------------------------------------------------------------------------
 void PING::DelUser(USER_PTR u)
 {
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 
 UnSetUserNotifiers(u);
 
-list<USER_PTR>::iterator users_iter;
+std::list<USER_PTR>::iterator users_iter;
 users_iter = usersList.begin();
 
 while (users_iter != usersList.end())
@@ -321,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)