#include "stg/plugin_creator.h"
#include "ping.h"
-PLUGIN_CREATOR<PING> pc;
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
+namespace
{
-return pc.GetPlugin();
-}
+PLUGIN_CREATOR<PING> pc;
+
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
template <typename varType>
-class IS_CONTAINS_USER: public binary_function<varType, USER_PTR, bool>
+class IS_CONTAINS_USER: public std::binary_function<varType, USER_PTR, bool>
{
public:
IS_CONTAINS_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);
ChgCurrIPNotifierList(),
ChgIPNotifierList(),
onAddUserNotifier(*this),
- onDelUserNotifier(*this)
+ onDelUserNotifier(*this),
+ logger(GetPluginLogger(GetStgLogger(), "ping"))
{
pthread_mutex_init(&mutex, NULL);
}
if (pthread_create(&thread, NULL, Run, this))
{
errorStr = "Cannot start thread.";
+ logger("Cannot create thread.");
printfd(__FILE__, "Cannot start thread\n");
return -1;
}
//-----------------------------------------------------------------------------
int PING::Stop()
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (!isRunning)
return 0;
nanosleep(&ts, NULL);
}
-//after 5 seconds waiting thread still running. now kill it
-if (isRunning)
- {
- printfd(__FILE__, "kill PING thread.\n");
- if (pthread_kill(thread, SIGINT))
- {
- errorStr = "Cannot kill PING thread.";
- printfd(__FILE__, "Cannot kill PING thread.\n");
- return -1;
- }
- printfd(__FILE__, "PING killed\n");
- }
-
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())
{
++users_iter;
}
+if (isRunning)
+ return -1;
+
return 0;
}
//-----------------------------------------------------------------------------
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())
IS_CONTAINS_USER<CHG_CURRIP_NOTIFIER_PING> IsContainsUserCurrIP(u);
IS_CONTAINS_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(),
//-----------------------------------------------------------------------------
void PING::GetUsers()
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
USER_PTR u;
int h = users->OpenSearch();
//-----------------------------------------------------------------------------
void PING::AddUser(USER_PTR u)
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
SetUserNotifiers(u);
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())