#include "traffcounter_impl.h"
#include "stg_timer.h"
#include "users_impl.h"
+#include "async_pool.h"
#define FLUSH_TIME (10)
#define REMOVE_TIME (31)
using STG::TraffCounterImpl;
+using STG::TRF_IP_BEFORE;
+using STG::TRF_IP_AFTER;
+
+namespace AsyncPoolST = STG::AsyncPoolST;
const char protoName[PROTOMAX][8] =
{"TCP", "UDP", "ICMP", "TCP_UDP", "ALL"};
monitoring(false),
touchTimeP(stgTime - MONITOR_TIME_DELAY_SEC),
users(u),
- stopped(true),
- addUserNotifier(*this),
- delUserNotifier(*this)
+ stopped(true)
{
for (int i = 0; i < DIR_NUM; i++)
strprintf(&dirName[i], "DIR%d", i);
dirName[DIR_NUM] = "NULL";
-users->AddNotifierUserAdd(&addUserNotifier);
-users->AddNotifierUserDel(&delUserNotifier);
+m_onAddUserConn = users->onImplAdd([this](auto user){
+ AsyncPoolST::enqueue([this, user](){ SetUserNotifiers(user); });
+});
+m_onDelUserConn = users->onImplDel([this](auto user){
+ AsyncPoolST::enqueue([this, user](){ UnSetUserNotifiers(user); });
+ AsyncPoolST::enqueue([this, user](){ DelUser(user->GetCurrIP()); });
+});
}
//-----------------------------------------------------------------------------
TraffCounterImpl::~TraffCounterImpl()
monitoring = !monitorDir.empty();
}
//-----------------------------------------------------------------------------
+void TRF_IP_BEFORE::notify(const uint32_t & oldValue, const uint32_t &)
+{
+// User changes his address. Remove old IP
+if (!oldValue)
+ return;
+
+AsyncPoolST::enqueue([this, oldValue](){ traffCnt.DelUser(oldValue); });
+}
+//-----------------------------------------------------------------------------
+void TRF_IP_AFTER::notify(const uint32_t &, const uint32_t & newValue)
+{
+// User changes his address. Add new IP
+if (!newValue)
+ return;
+
+AsyncPoolST::enqueue([this](){ traffCnt.AddUser(user); });
+}
+//-----------------------------------------------------------------------------