]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Moved common initialization code to a separate class method.
[stg.git] / projects / stargazer / user_impl.cpp
index 2b60c9adaab9e2c89c988b6bb53a1a3b5b26e28f..44fac908582ed1d3ed786b3657cdf7ed6b5eb1c7 100644 (file)
@@ -59,8 +59,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s,
            const TARIFFS * t,
            const ADMIN * a,
            const USERS * u)
-    : USER(),
-      users(u),
+    : users(u),
       property(s->GetScriptsDir()),
       WriteServLog(GetStgLogger()),
       lastScanMessages(0),
@@ -115,26 +114,12 @@ USER_IMPL::USER_IMPL(const SETTINGS * s,
       userdata8(property.userdata8),
       userdata9(property.userdata9),
       passiveNotifier(this),
+      disabledNotifier(this),
       tariffNotifier(this),
       cashNotifier(this),
       ipNotifier(this)
 {
-password = "*_EMPTY_PASSWORD_*";
-tariffName = NO_TARIFF_NAME;
-ips = StrToIPS("*");
-lastWriteStat = stgTime + random() % settings->GetStatWritePeriod();
-lastWriteDetailedStat = stgTime;
-
-property.tariffName.AddBeforeNotifier(&tariffNotifier);
-property.passive.AddBeforeNotifier(&passiveNotifier);
-property.disabled.AddAfterNotifier(&disabledNotifier);
-property.cash.AddBeforeNotifier(&cashNotifier);
-ips.AddAfterNotifier(&ipNotifier);
-
-pthread_mutexattr_t attr;
-pthread_mutexattr_init(&attr);
-pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&mutex, &attr);
+Init();
 }
 #else
 USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
@@ -142,8 +127,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
                      const TARIFFS * t,
                      const ADMIN * a,
                      const USERS * u)
-    : USER(),
-      users(u),
+    : users(u),
       property(s->GetScriptsDir()),
       WriteServLog(GetStgLogger()),
       lastScanMessages(0),
@@ -203,6 +187,12 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
       cashNotifier(this),
       ipNotifier(this)
 {
+Init();
+}
+#endif
+//-----------------------------------------------------------------------------
+void USER_IMPL::Init()
+{
 password = "*_EMPTY_PASSWORD_*";
 tariffName = NO_TARIFF_NAME;
 ips = StrToIPS("*");
@@ -220,7 +210,6 @@ pthread_mutexattr_init(&attr);
 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 pthread_mutex_init(&mutex, &attr);
 }
-#endif
 //-----------------------------------------------------------------------------
 USER_IMPL::USER_IMPL(const USER_IMPL & u)
     : USER(),
@@ -853,10 +842,10 @@ int64_t threshold = tariff->GetThreshold(dir) * 1024 * 1024;
 dt[dir] += len;
 
 int tt = tariff->GetTraffType();
-if (tt == TRAFF_UP ||
-    tt == TRAFF_UP_DOWN ||
+if (tt == TARIFF::TRAFF_UP ||
+    tt == TARIFF::TRAFF_UP_DOWN ||
     // Check NEW traff data
-    (tt == TRAFF_MAX && dt[dir] > down.ConstData()[dir]))
+    (tt == TARIFF::TRAFF_MAX && dt[dir] > down.ConstData()[dir]))
     {
     double dc = 0;
     if (traff < threshold &&
@@ -946,10 +935,10 @@ int64_t threshold = tariff->GetThreshold(dir) * 1024 * 1024;
 dt[dir] += len;
 
 int tt = tariff->GetTraffType();
-if (tt == TRAFF_DOWN ||
-    tt == TRAFF_UP_DOWN ||
+if (tt == TARIFF::TRAFF_DOWN ||
+    tt == TARIFF::TRAFF_UP_DOWN ||
     // Check NEW traff data
-    (tt == TRAFF_MAX && up.ConstData()[dir] <= dt[dir]))
+    (tt == TARIFF::TRAFF_MAX && up.ConstData()[dir] <= dt[dir]))
     {
     double dc = 0;
     if (traff < threshold &&