From 961528b745c39b201a24d8401e51d279d028a9a4 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 31 Jan 2015 20:28:14 +0200 Subject: [PATCH] Backported some changes from 2.5. --- projects/stargazer/services_impl.cpp | 37 ++++++++++++++++++++++------ projects/stargazer/services_impl.h | 9 ++++--- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/projects/stargazer/services_impl.cpp b/projects/stargazer/services_impl.cpp index aebb98fb..90c23f81 100644 --- a/projects/stargazer/services_impl.cpp +++ b/projects/stargazer/services_impl.cpp @@ -54,7 +54,7 @@ if (!priv->serviceChg) return -1; } -srv_iter si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si != data.end()) { @@ -92,7 +92,7 @@ if (!priv->serviceChg) return -1; } -srv_iter si(find(data.begin(), data.end(), SERVICE_CONF(name))); +iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si == data.end()) { @@ -101,7 +101,7 @@ if (si == data.end()) return -1; } -std::map::iterator csi; +std::map::iterator csi; csi = searchDescriptors.begin(); while (csi != searchDescriptors.end()) { @@ -136,7 +136,7 @@ if (!priv->serviceChg) return -1; } -srv_iter si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si == data.end()) { @@ -145,7 +145,9 @@ if (si == data.end()) return -1; } +printfd(__FILE__, "Old cost = %f, old pay day = %d\n", si->cost, (unsigned)si->payDay); *si = service; +printfd(__FILE__, "New cost = %f, New pay day = %d\n", si->cost, (unsigned)si->payDay); if (store->SaveService(service)) { WriteServLog("Cannot write service %s.", service.name.c_str()); @@ -184,15 +186,34 @@ for (size_t i = 0; i < servicesList.size(); i++) return false; } //----------------------------------------------------------------------------- -bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF * service) +bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF * service) const { assert(service != NULL && "Pointer to service is not null"); STG_LOCKER lock(&mutex); if (data.empty()) + return true; + +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); + +if (si != data.end()) + { + *service = *si; return false; + } + +return true; +} +//----------------------------------------------------------------------------- +bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF_RES * service) const +{ +assert(service != NULL && "Pointer to service is not null"); + +STG_LOCKER lock(&mutex); +if (data.empty()) + return true; -srv_iter si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) { @@ -208,11 +229,11 @@ bool SERVICES_IMPL::Exists(const std::string & name) const STG_LOCKER lock(&mutex); if (data.empty()) { - printfd(__FILE__, "no admin in system!\n"); + printfd(__FILE__, "No services in the system!\n"); return true; } -const_srv_iter si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) return true; diff --git a/projects/stargazer/services_impl.h b/projects/stargazer/services_impl.h index 31aa72b2..56202c7a 100644 --- a/projects/stargazer/services_impl.h +++ b/projects/stargazer/services_impl.h @@ -44,7 +44,8 @@ public: int Add(const SERVICE_CONF & service, const ADMIN * admin); int Del(const std::string & name, const ADMIN * admin); int Change(const SERVICE_CONF & service, const ADMIN * admin); - bool Find(const std::string & name, SERVICE_CONF * service); + bool Find(const std::string & name, SERVICE_CONF * service) const; + bool Find(const std::string & name, SERVICE_CONF_RES * service) const; bool Exists(const std::string & name) const; const std::string & GetStrError() const { return strError; } @@ -58,15 +59,15 @@ private: SERVICES_IMPL(const SERVICES_IMPL & rvalue); SERVICES_IMPL & operator=(const SERVICES_IMPL & rvalue); - typedef std::list::iterator srv_iter; - typedef std::list::const_iterator const_srv_iter; + typedef std::list::iterator iterator; + typedef std::list::const_iterator const_iterator; bool Read(); std::list data; STORE * store; STG_LOGGER & WriteServLog; - mutable std::map searchDescriptors; + mutable std::map searchDescriptors; mutable unsigned int handle; mutable pthread_mutex_t mutex; std::string strError; -- 2.44.2