X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/01cdd74060b063287784d3aff7f9f861a404b789..c00e81f9f50c4fe50ee32b02a689d68c9bc595b6:/projects/sgconf/tariffs.cpp?ds=sidebyside diff --git a/projects/sgconf/tariffs.cpp b/projects/sgconf/tariffs.cpp index 046a6121..3da1001a 100644 --- a/projects/sgconf/tariffs.cpp +++ b/projects/sgconf/tariffs.cpp @@ -1,5 +1,7 @@ #include "tariffs.h" +#include "api_action.h" +#include "options.h" #include "config.h" #include "stg/servconf.h" @@ -9,6 +11,8 @@ #include #include +#include +#include #include namespace @@ -87,6 +91,21 @@ for (size_t i = 0; i < info.dirPrice.size(); ++i) PrintDirPriceData(i, info.dirPrice[i], level + 1); } +std::vector GetTariffParams() +{ +std::vector params; +params.push_back(SGCONF::API_ACTION::PARAM("fee", "", "\t\ttariff fee")); +params.push_back(SGCONF::API_ACTION::PARAM("free", "", "\tprepaid traff")); +params.push_back(SGCONF::API_ACTION::PARAM("passive-cost", "", "\tpassive cost")); +params.push_back(SGCONF::API_ACTION::PARAM("traff-type", "", "\ttraff type (up, dow, up+down, max)")); +params.push_back(SGCONF::API_ACTION::PARAM("period", "", "\ttarification period (daily, monthly)")); +params.push_back(SGCONF::API_ACTION::PARAM("times", "", "coma-separated day time-spans for each direction")); +params.push_back(SGCONF::API_ACTION::PARAM("day-prices", "", "coma-separated day prices for each direction")); +params.push_back(SGCONF::API_ACTION::PARAM("night-prices", "", "coma-separated day prices for each direction")); +params.push_back(SGCONF::API_ACTION::PARAM("thresholds", "", "coma-separated thresholds for each direction")); +return params; +} + void SimpleCallback(bool result, const std::string & reason, void * /*data*/) @@ -131,12 +150,9 @@ for (size_t i = 0; i < info.size(); ++i) PrintTariff(info[i]); } -} - - -bool SGCONF::GetTariffsFunction(const SGCONF::CONFIG & config, - const std::string & /*arg*/, - const std::map & /*options*/) +bool GetTariffsFunction(const SGCONF::CONFIG & config, + const std::string & /*arg*/, + const std::map & /*options*/) { STG::SERVCONF proto(config.server.data(), config.port.data(), @@ -145,9 +161,9 @@ STG::SERVCONF proto(config.server.data(), return proto.GetTariffs(GetTariffsCallback, NULL) == STG::st_ok; } -bool SGCONF::GetTariffFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & /*options*/) +bool GetTariffFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) { STG::SERVCONF proto(config.server.data(), config.port.data(), @@ -159,9 +175,9 @@ std::string name(arg); return proto.GetTariffs(GetTariffCallback, &name) == STG::st_ok; } -bool SGCONF::DelTariffFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & /*options*/) +bool DelTariffFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) { STG::SERVCONF proto(config.server.data(), config.port.data(), @@ -170,20 +186,33 @@ STG::SERVCONF proto(config.server.data(), return proto.DelTariff(arg, SimpleCallback, NULL) == STG::st_ok; } -bool SGCONF::AddTariffFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & /*options*/) +bool AddTariffFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) { // TODO std::cerr << "Unimplemented.\n"; return false; } -bool SGCONF::ChgTariffFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & options) +bool ChgTariffFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & options) { // TODO std::cerr << "Unimplemented.\n"; return false; } + +} // namespace anonymous + +void SGCONF::AppendTariffsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks) +{ +std::vector params(GetTariffParams()); +blocks.Add("Tariff management options") + .Add("get-tariffs", SGCONF::MakeAPIAction(commands, GetTariffsFunction), "\tget tariff list") + .Add("get-tariff", SGCONF::MakeAPIAction(commands, "", GetTariffFunction), "get tariff") + .Add("add-tariff", SGCONF::MakeAPIAction(commands, "", params, AddTariffFunction), "add tariff") + .Add("del-tariff", SGCONF::MakeAPIAction(commands, "", DelTariffFunction), "del tariff") + .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "", params, ChgTariffFunction), "change tariff"); +}