X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/7c744ef82350aa401c61aa6f0424866a16c2ed1a..30a838da28667633e16040250680b793dee271c7:/projects/stargazer/tariffs_impl.cpp?ds=sidebyside diff --git a/projects/stargazer/tariffs_impl.cpp b/projects/stargazer/tariffs_impl.cpp index ea3632cb..d47ecf8f 100644 --- a/projects/stargazer/tariffs_impl.cpp +++ b/projects/stargazer/tariffs_impl.cpp @@ -38,14 +38,13 @@ #include "stg/admin.h" #include "tariffs_impl.h" -using namespace std; - //----------------------------------------------------------------------------- TARIFFS_IMPL::TARIFFS_IMPL(STORE * st) : TARIFFS(), tariffs(), store(st), WriteServLog(GetStgLogger()), + mutex(), strError(), noTariff(NO_TARIFF_NAME), onAddNotifiers(), @@ -62,18 +61,18 @@ pthread_mutex_destroy(&mutex); //----------------------------------------------------------------------------- int TARIFFS_IMPL::ReadTariffs() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); -vector tariffsList; +std::vector tariffsList; if (store->GetTariffsList(&tariffsList)) { WriteServLog("Cannot get tariffs list."); WriteServLog("%s", store->GetStrError().c_str()); } -int tariffsNum = tariffsList.size(); +Tariffs::size_type tariffsNum = tariffsList.size(); -for (int i = 0; i < tariffsNum; i++) +for (Tariffs::size_type i = 0; i < tariffsNum; i++) { TARIFF_DATA td; if (store->RestoreTariff(&td, tariffsList[i])) @@ -90,17 +89,17 @@ return 0; //----------------------------------------------------------------------------- size_t TARIFFS_IMPL::Count() const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); return tariffs.size(); } //----------------------------------------------------------------------------- -const TARIFF * TARIFFS_IMPL::FindByName(const string & name) const +const TARIFF * TARIFFS_IMPL::FindByName(const std::string & name) const { if (name == NO_TARIFF_NAME) return &noTariff; -STG_LOCKER lock(&mutex, __FILE__, __LINE__); -list::const_iterator ti; +STG_LOCKER lock(&mutex); +std::list::const_iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) @@ -115,16 +114,16 @@ const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Change tariff \'" + std::string s = admin->GetLogStr() + " Change tariff \'" + td.tariffConf.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; } -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); -list::iterator ti; +std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name)); if (ti == tariffs.end()) @@ -138,7 +137,7 @@ if (ti == tariffs.end()) if (store->SaveTariff(td, td.tariffConf.name)) { - string error = "Tariff " + td.tariffConf.name + " writing error. " + store->GetStrError(); + std::string error = "Tariff " + td.tariffConf.name + " writing error. " + store->GetStrError(); WriteServLog(error.c_str()); return -1; } @@ -149,13 +148,13 @@ WriteServLog("%s Tariff \'%s\' changed.", return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Del(const string & name, const ADMIN * admin) +int TARIFFS_IMPL::Del(const std::string & name, const ADMIN * admin) { const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Delete tariff \'" + std::string s = admin->GetLogStr() + " Delete tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -165,9 +164,9 @@ if (!priv->tariffChg) TARIFF_DATA td; { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); - list::iterator ti; + std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti == tariffs.end()) @@ -183,7 +182,7 @@ TARIFF_DATA td; WriteServLog("%s", store->GetStrError().c_str()); return -1; } - + td = ti->GetTariffData(); tariffs.erase(ti); @@ -202,13 +201,13 @@ WriteServLog("%s Tariff \'%s\' deleted.", return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Add(const string & name, const ADMIN * admin) +int TARIFFS_IMPL::Add(const std::string & name, const ADMIN * admin) { const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Add tariff \'" + std::string s = admin->GetLogStr() + " Add tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -216,9 +215,9 @@ if (!priv->tariffChg) } { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); + STG_LOCKER lock(&mutex); - list::iterator ti; + std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) @@ -252,12 +251,12 @@ WriteServLog("%s Tariff \'%s\' added.", return 0; } //----------------------------------------------------------------------------- -void TARIFFS_IMPL::GetTariffsData(std::list * tdl) +void TARIFFS_IMPL::GetTariffsData(std::list * tdl) const { assert(tdl != NULL && "Tariffs data list is not null"); -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); -std::list::const_iterator it = tariffs.begin(); +Tariffs::const_iterator it = tariffs.begin(); for (; it != tariffs.end(); ++it) { tdl->push_back(it->GetTariffData()); @@ -266,25 +265,25 @@ for (; it != tariffs.end(); ++it) //----------------------------------------------------------------------------- void TARIFFS_IMPL::AddNotifierAdd(NOTIFIER_BASE * n) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); onAddNotifiers.insert(n); } //----------------------------------------------------------------------------- void TARIFFS_IMPL::DelNotifierAdd(NOTIFIER_BASE * n) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); onAddNotifiers.erase(n); } //----------------------------------------------------------------------------- void TARIFFS_IMPL::AddNotifierDel(NOTIFIER_BASE * n) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); onDelNotifiers.insert(n); } //----------------------------------------------------------------------------- void TARIFFS_IMPL::DelNotifierDel(NOTIFIER_BASE * n) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); onDelNotifiers.erase(n); } //-----------------------------------------------------------------------------