]> git.stg.codes - stg.git/blobdiff - projects/stargazer/tariffs_impl.cpp
Exclude legacy hostallow.lib from compilation
[stg.git] / projects / stargazer / tariffs_impl.cpp
index 1f8a4230bc3f2391ec30332274df773e0866e6e4..e0ef68e1ba49be0be3db4e17b5e7a950ceeb89ee 100644 (file)
 #include <algorithm>
 #include <vector>
 
-#include "tariffs.h"
+#include "tariffs_impl.h"
 #include "stg_locker.h"
 #include "stg_logger.h"
-#include "base_store.h"
+#include "store.h"
 #include "admin.h"
 
 using namespace std;
 
 //-----------------------------------------------------------------------------
-TARIFFS::TARIFFS(BASE_STORE * st)
+TARIFFS_IMPL::TARIFFS_IMPL(STORE * st)
     : tariffs(),
       store(st),
       WriteServLog(GetStgLogger()),
@@ -52,12 +52,12 @@ pthread_mutex_init(&mutex, NULL);
 ReadTariffs();
 }
 //-----------------------------------------------------------------------------
-TARIFFS::~TARIFFS()
+TARIFFS_IMPL::~TARIFFS_IMPL()
 {
 pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
-int TARIFFS::ReadTariffs()
+int TARIFFS_IMPL::ReadTariffs()
 {
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
@@ -79,26 +79,26 @@ for (int i = 0; i < tariffsNum; i++)
         WriteServLog("%s", store->GetStrError().c_str());
         return -1;
         }
-    tariffs.push_back(TARIFF(td));
+    tariffs.push_back(TARIFF_IMPL(td));
     }
 
 return 0;
 }
 //-----------------------------------------------------------------------------
-int TARIFFS::GetTariffsNum() const
+int TARIFFS_IMPL::GetTariffsNum() const
 {
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 return tariffs.size();
 }
 //-----------------------------------------------------------------------------
-const TARIFF * TARIFFS::FindByName(const string & name) const
+const TARIFF * TARIFFS_IMPL::FindByName(const string & name) const
 {
 if (name == NO_TARIFF_NAME)
     return &noTariff;
 
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-list<TARIFF>::const_iterator ti;
-ti = find(tariffs.begin(), tariffs.end(), TARIFF(name));
+list<TARIFF_IMPL>::const_iterator ti;
+ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name));
 
 if (ti != tariffs.end())
     return &(*ti);
@@ -106,13 +106,13 @@ if (ti != tariffs.end())
 return NULL;
 }
 //-----------------------------------------------------------------------------
-int TARIFFS::Chg(const TARIFF_DATA & td, const ADMIN & admin)
+int TARIFFS_IMPL::Chg(const TARIFF_DATA & td, const ADMIN * admin)
 {
-const PRIV * priv = admin.GetPriv();
+const PRIV * priv = admin->GetPriv();
 
 if (!priv->tariffChg)
     {
-    string s = admin.GetLogStr() + " Change tariff \'"
+    string s = admin->GetLogStr() + " Change tariff \'"
                + td.tariffConf.name + "\'. Access denied.";
     strError = "Access denied.";
     WriteServLog(s.c_str());
@@ -121,13 +121,13 @@ if (!priv->tariffChg)
 
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
-list<TARIFF>::iterator ti;
-ti = find(tariffs.begin(), tariffs.end(), TARIFF(td.tariffConf.name));
+list<TARIFF_IMPL>::iterator ti;
+ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name));
 
 if (ti == tariffs.end())
     {
     strError = "Tariff \'" + td.tariffConf.name + "\' cannot be changed. Tariff does not exist.";
-    WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str());
+    WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str());
     return -1;
     }
 
@@ -141,18 +141,18 @@ if (store->SaveTariff(td, td.tariffConf.name))
     }
 
 WriteServLog("%s Tariff \'%s\' changed.",
-             admin.GetLogStr().c_str(), td.tariffConf.name.c_str());
+             admin->GetLogStr().c_str(), td.tariffConf.name.c_str());
 
 return 0;
 }
 //-----------------------------------------------------------------------------
-int TARIFFS::Del(const string & name, const ADMIN & admin)
+int TARIFFS_IMPL::Del(const string & name, const ADMIN * admin)
 {
-const PRIV * priv = admin.GetPriv();
+const PRIV * priv = admin->GetPriv();
 
 if (!priv->tariffChg)
     {
-    string s = admin.GetLogStr() + " Delete tariff \'"
+    string s = admin->GetLogStr() + " Delete tariff \'"
                + name + "\'. Access denied.";
     strError = "Access denied.";
     WriteServLog(s.c_str());
@@ -161,13 +161,13 @@ if (!priv->tariffChg)
 
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
-list<TARIFF>::iterator ti;
-ti = find(tariffs.begin(), tariffs.end(), TARIFF(name));
+list<TARIFF_IMPL>::iterator ti;
+ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name));
 
 if (ti == tariffs.end())
     {
     strError = "Tariff \'" + name + "\' cannot be deleted. Tariff does not exist.";
-    WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str());
+    WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str());
     return -1;
     }
 
@@ -181,18 +181,18 @@ if (store->DelTariff(name))
 tariffs.erase(ti);
 
 WriteServLog("%s Tariff \'%s\' deleted.",
-             admin.GetLogStr().c_str(),
+             admin->GetLogStr().c_str(),
              name.c_str());
 return 0;
 }
 //-----------------------------------------------------------------------------
-int TARIFFS::Add(const string & name, const ADMIN & admin)
+int TARIFFS_IMPL::Add(const string & name, const ADMIN * admin)
 {
-const PRIV * priv = admin.GetPriv();
+const PRIV * priv = admin->GetPriv();
 
 if (!priv->tariffChg)
     {
-    string s = admin.GetLogStr() + " Add tariff \'"
+    string s = admin->GetLogStr() + " Add tariff \'"
                + name + "\'. Access denied.";
     strError = "Access denied.";
     WriteServLog(s.c_str());
@@ -201,17 +201,17 @@ if (!priv->tariffChg)
 
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
-list<TARIFF>::iterator ti;
-ti = find(tariffs.begin(), tariffs.end(), TARIFF(name));
+list<TARIFF_IMPL>::iterator ti;
+ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name));
 
 if (ti != tariffs.end())
     {
     strError = "Tariff \'" + name + "\' cannot be added. Tariff alredy exist.";
-    WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str());
+    WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str());
     return -1;
     }
 
-tariffs.push_back(TARIFF(name));
+tariffs.push_back(TARIFF_IMPL(name));
 
 if (store->AddTariff(name) < 0)
     {
@@ -221,22 +221,20 @@ if (store->AddTariff(name) < 0)
     }
 
 WriteServLog("%s Tariff \'%s\' added.",
-                 admin.GetLogStr().c_str(), name.c_str());
+                 admin->GetLogStr().c_str(), name.c_str());
 
 return 0;
 }
 //-----------------------------------------------------------------------------
-void TARIFFS::GetTariffsData(std::list<TARIFF_DATA> * tdl)
+void TARIFFS_IMPL::GetTariffsData(std::list<TARIFF_DATA> * tdl)
 {
 assert(tdl != NULL && "Tariffs data list is not null");
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
-std::list<TARIFF>::const_iterator it = tariffs.begin();
-TARIFF_DATA td;
+std::list<TARIFF_IMPL>::const_iterator it = tariffs.begin();
 for (; it != tariffs.end(); ++it)
     {
-    it->GetTariffData(&td);
-    tdl->push_back(td);
+    tdl->push_back(it->GetTariffData());
     }
 }
 //-----------------------------------------------------------------------------