From efc31e581ff0c9ca27959ff3b2b694d401d7349c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 17 Oct 2014 13:05:56 +0300 Subject: [PATCH 1/1] Moved common initialization code to a separate class method. --- include/stg/user_conf.h | 35 ++------------------------------ projects/stargazer/user_impl.cpp | 30 ++++++++------------------- projects/stargazer/user_impl.h | 2 ++ 3 files changed, 13 insertions(+), 54 deletions(-) diff --git a/include/stg/user_conf.h b/include/stg/user_conf.h index fe458211..d0415c42 100644 --- a/include/stg/user_conf.h +++ b/include/stg/user_conf.h @@ -18,25 +18,13 @@ struct USER_CONF { USER_CONF() - : password(), - passive(0), + : passive(0), disabled(0), disabledDetailStat(0), alwaysOnline(0), - tariffName(), - address(), - phone(), - email(), - note(), - realName(), - corp(), - services(), - group(), credit(0), - nextTariff(), userdata(USERDATA_NUM), - creditExpire(0), - ips() + creditExpire(0) {} std::string password; @@ -63,25 +51,6 @@ struct USER_CONF struct USER_CONF_RES { USER_CONF_RES() - : password(), - passive(), - disabled(), - disabledDetailStat(), - alwaysOnline(), - tariffName(), - address(), - phone(), - email(), - note(), - realName(), - corp(), - group(), - credit(), - nextTariff(), - userdata(USERDATA_NUM), - services(), - creditExpire(), - ips() { } diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 79321987..44fac908 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -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), @@ -120,22 +119,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, 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, @@ -143,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), @@ -204,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("*"); @@ -221,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(), diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 29cc63c4..dbb0d892 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -230,6 +230,8 @@ public: private: USER_IMPL & operator=(const USER_IMPL & rvalue); + void Init(); + const USERS * users; USER_PROPERTIES property; STG_LOGGER & WriteServLog; -- 2.44.2