]> git.stg.codes - stg.git/blobdiff - projects/sgconf/tariffs.cpp
Ticket. The MaybeSet() function call for the 'change-policy' parameter added in
[stg.git] / projects / sgconf / tariffs.cpp
index cf9f49c9752d4d6a288a28563496fb9eea3e714b..a604a670a39c36659936044837bd10a90c5b25b3 100644 (file)
@@ -28,6 +28,18 @@ if (level == 0)
 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
 }
 
 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
 }
 
+std::string ChangePolicyToString(TARIFF::CHANGE_POLICY changePolicy)
+{
+switch (changePolicy)
+    {
+    case ALLOW: return "allow";
+    case TO_CHEAP: return "to_cheap";
+    case TO_EXPENSIVE: return "to_expensive";
+    case DENY: return "deny";
+    }
+return "unknown";
+}
+
 std::string PeriodToString(TARIFF::PERIOD period)
 {
 switch (period)
 std::string PeriodToString(TARIFF::PERIOD period)
 {
 switch (period)
@@ -40,17 +52,17 @@ switch (period)
 return "unknown";
 }
 
 return "unknown";
 }
 
-std::string TraffTypeToString(int traffType)
+std::string TraffTypeToString(TARIFF::TRAFF_TYPE traffType)
 {
 switch (traffType)
     {
 {
 switch (traffType)
     {
-    case TRAFF_UP:
+    case TARIFF::TRAFF_UP:
         return "upload";
         return "upload";
-    case TRAFF_DOWN:
+    case TARIFF::TRAFF_DOWN:
         return "download";
         return "download";
-    case TRAFF_UP_DOWN:
+    case TARIFF::TRAFF_UP_DOWN:
         return "upload + download";
         return "upload + download";
-    case TRAFF_MAX:
+    case TARIFF::TRAFF_MAX:
         return "max(upload, download)";
     }
 return "unknown";
         return "max(upload, download)";
     }
 return "unknown";
@@ -67,18 +79,18 @@ else
     throw SGCONF::ACTION::ERROR("Period should be 'daily' or 'monthly'. Got: '" + value + "'");
 }
 
     throw SGCONF::ACTION::ERROR("Period should be 'daily' or 'monthly'. Got: '" + value + "'");
 }
 
-void ConvTraffType(const std::string & value, RESETABLE<int> & res)
+void ConvTraffType(const std::string & value, RESETABLE<TARIFF::TRAFF_TYPE> & res)
 {
 std::string lowered = ToLower(value);
 lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end());
 if (lowered == "upload")
 {
 std::string lowered = ToLower(value);
 lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end());
 if (lowered == "upload")
-    res = TRAFF_UP;
+    res = TARIFF::TRAFF_UP;
 else if (lowered == "download")
 else if (lowered == "download")
-    res = TRAFF_DOWN;
+    res = TARIFF::TRAFF_DOWN;
 else if (lowered == "upload+download")
 else if (lowered == "upload+download")
-    res = TRAFF_UP_DOWN;
+    res = TARIFF::TRAFF_UP_DOWN;
 else if (lowered.substr(0, 3) == "max")
 else if (lowered.substr(0, 3) == "max")
-    res = TRAFF_MAX;
+    res = TARIFF::TRAFF_MAX;
 else
     throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'");
 }
 else
     throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'");
 }
@@ -112,7 +124,7 @@ return res;
 
 void Splice(std::vector<DIRPRICE_DATA_RES> & lhs, const std::vector<DIRPRICE_DATA_RES> & rhs)
 {
 
 void Splice(std::vector<DIRPRICE_DATA_RES> & lhs, const std::vector<DIRPRICE_DATA_RES> & rhs)
 {
-for (size_t i = 0; i < lhs.size(); ++i)
+for (size_t i = 0; i < lhs.size() && i < rhs.size(); ++i)
     lhs[i].Splice(rhs[i]);
 }
 
     lhs[i].Splice(rhs[i]);
 }
 
@@ -214,7 +226,8 @@ std::cout << Indent(level, true) << "name: " << conf.name << "\n"
           << Indent(level)       << "free mb: " << conf.free << "\n"
           << Indent(level)       << "passive cost: " << conf.passiveCost << "\n"
           << Indent(level)       << "traff type: " << TraffTypeToString(conf.traffType) << "\n"
           << Indent(level)       << "free mb: " << conf.free << "\n"
           << Indent(level)       << "passive cost: " << conf.passiveCost << "\n"
           << Indent(level)       << "traff type: " << TraffTypeToString(conf.traffType) << "\n"
-          << Indent(level)       << "period: " << PeriodToString(conf.period) << "\n";
+          << Indent(level)       << "period: " << PeriodToString(conf.period) << "\n"
+          << Indent(level)       << "change policy: " << CyangePolicyToString(conf.changePolicy) << "\n";
 }
 
 void PrintTariff(const STG::GET_TARIFF::INFO & info, size_t level = 0)
 }
 
 void PrintTariff(const STG::GET_TARIFF::INFO & info, size_t level = 0)
@@ -229,13 +242,14 @@ std::vector<SGCONF::API_ACTION::PARAM> GetTariffParams()
 {
 std::vector<SGCONF::API_ACTION::PARAM> params;
 params.push_back(SGCONF::API_ACTION::PARAM("fee", "<fee>", "\t\ttariff fee"));
 {
 std::vector<SGCONF::API_ACTION::PARAM> params;
 params.push_back(SGCONF::API_ACTION::PARAM("fee", "<fee>", "\t\ttariff fee"));
-params.push_back(SGCONF::API_ACTION::PARAM("free", "<free mb>", "\tprepaid traff"));
+params.push_back(SGCONF::API_ACTION::PARAM("free", "<free mb>", "\tprepaid traffic"));
 params.push_back(SGCONF::API_ACTION::PARAM("passive-cost", "<cost>", "\tpassive cost"));
 params.push_back(SGCONF::API_ACTION::PARAM("passive-cost", "<cost>", "\tpassive cost"));
-params.push_back(SGCONF::API_ACTION::PARAM("traff-type", "<type>", "\ttraff type (up, dow, up+down, max)"));
+params.push_back(SGCONF::API_ACTION::PARAM("traff-type", "<type>", "\ttraffic type (up, down, up+down, max)"));
 params.push_back(SGCONF::API_ACTION::PARAM("period", "<period>", "\ttarification period (daily, monthly)"));
 params.push_back(SGCONF::API_ACTION::PARAM("period", "<period>", "\ttarification period (daily, monthly)"));
+params.push_back(SGCONF::API_ACTION::PARAM("change-policy", "<change-policy>", "\ttarification change-policy (allow, to_cheap, to_expensive, deny)"));
 params.push_back(SGCONF::API_ACTION::PARAM("times", "<hh:mm-hh:mm, ...>", "coma-separated day time-spans for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("day-prices", "<price/price, ...>", "coma-separated day prices for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("times", "<hh:mm-hh:mm, ...>", "coma-separated day time-spans for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("day-prices", "<price/price, ...>", "coma-separated day prices for each direction"));
-params.push_back(SGCONF::API_ACTION::PARAM("night-prices", "<price/price, ...>", "coma-separated day prices for each direction"));
+params.push_back(SGCONF::API_ACTION::PARAM("night-prices", "<price/price, ...>", "coma-separated night prices for each direction"));
 params.push_back(SGCONF::API_ACTION::PARAM("thresholds", "<threshold, ...>", "coma-separated thresholds for each direction"));
 return params;
 }
 params.push_back(SGCONF::API_ACTION::PARAM("thresholds", "<threshold, ...>", "coma-separated thresholds for each direction"));
 return params;
 }
@@ -290,6 +304,8 @@ bool GetTariffsFunction(const SGCONF::CONFIG & config,
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
+                    config.localAddress.data(),
+                    config.localPort.data(),
                     config.userName.data(),
                     config.userPass.data());
 return proto.GetTariffs(GetTariffsCallback, NULL) == STG::st_ok;
                     config.userName.data(),
                     config.userPass.data());
 return proto.GetTariffs(GetTariffsCallback, NULL) == STG::st_ok;
@@ -301,6 +317,8 @@ bool GetTariffFunction(const SGCONF::CONFIG & config,
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
+                    config.localAddress.data(),
+                    config.localPort.data(),
                     config.userName.data(),
                     config.userPass.data());
 // STG currently doesn't support <GetTariff name="..."/>.
                     config.userName.data(),
                     config.userPass.data());
 // STG currently doesn't support <GetTariff name="..."/>.
@@ -315,6 +333,8 @@ bool DelTariffFunction(const SGCONF::CONFIG & config,
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
 {
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
+                    config.localAddress.data(),
+                    config.localPort.data(),
                     config.userName.data(),
                     config.userPass.data());
 return proto.DelTariff(arg, SimpleCallback, NULL) == STG::st_ok;
                     config.userName.data(),
                     config.userPass.data());
 return proto.DelTariff(arg, SimpleCallback, NULL) == STG::st_ok;
@@ -331,6 +351,7 @@ SGCONF::MaybeSet(options, "free", conf.tariffConf.free);
 SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost);
 SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
 SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
 SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost);
 SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType);
 SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod);
+SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy);
 SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
 SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
 SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
 SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes);
 SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices);
 SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);
@@ -346,6 +367,8 @@ for (size_t i = 0; i < conf.dirPrice.size(); ++i)
     }
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
     }
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
+                    config.localAddress.data(),
+                    config.localPort.data(),
                     config.userName.data(),
                     config.userPass.data());
 return proto.AddTariff(arg, conf, SimpleCallback, NULL) == STG::st_ok;
                     config.userName.data(),
                     config.userPass.data());
 return proto.AddTariff(arg, conf, SimpleCallback, NULL) == STG::st_ok;
@@ -377,6 +400,8 @@ for (size_t i = 0; i < conf.dirPrice.size(); ++i)
     }
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
     }
 STG::SERVCONF proto(config.server.data(),
                     config.port.data(),
+                    config.localAddress.data(),
+                    config.localPort.data(),
                     config.userName.data(),
                     config.userPass.data());
 return proto.ChgTariff(conf, SimpleCallback, NULL) == STG::st_ok;
                     config.userName.data(),
                     config.userPass.data());
 return proto.ChgTariff(conf, SimpleCallback, NULL) == STG::st_ok;
@@ -391,6 +416,6 @@ blocks.Add("Tariff management options")
       .Add("get-tariffs", SGCONF::MakeAPIAction(commands, GetTariffsFunction), "\tget tariff list")
       .Add("get-tariff", SGCONF::MakeAPIAction(commands, "<name>", GetTariffFunction), "get tariff")
       .Add("add-tariff", SGCONF::MakeAPIAction(commands, "<name>", params, AddTariffFunction), "add tariff")
       .Add("get-tariffs", SGCONF::MakeAPIAction(commands, GetTariffsFunction), "\tget tariff list")
       .Add("get-tariff", SGCONF::MakeAPIAction(commands, "<name>", GetTariffFunction), "get tariff")
       .Add("add-tariff", SGCONF::MakeAPIAction(commands, "<name>", params, AddTariffFunction), "add tariff")
-      .Add("del-tariff", SGCONF::MakeAPIAction(commands, "<name>", DelTariffFunction), "del tariff")
+      .Add("del-tariff", SGCONF::MakeAPIAction(commands, "<name>", DelTariffFunction), "delete tariff")
       .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", params, ChgTariffFunction), "change tariff");
 }
       .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", params, ChgTariffFunction), "change tariff");
 }