X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/c1b9be104712ea200385bd4f7d76f185a2d76eb7..8d4e3b241054c1977a36e33121a2f7540f320f44:/projects/sgconf/services.cpp diff --git a/projects/sgconf/services.cpp b/projects/sgconf/services.cpp index 7989de20..b6ce1a33 100644 --- a/projects/sgconf/services.cpp +++ b/projects/sgconf/services.cpp @@ -3,6 +3,7 @@ #include "api_action.h" #include "options.h" #include "config.h" +#include "utils.h" #include "stg/servconf.h" #include "stg/servconf_types.h" @@ -34,9 +35,9 @@ std::cout << Indent(level, true) << "name: " << info.name << "\n" std::vector GetServiceParams() { std::vector params; -params.push_back({"cost", "", "\tcost of the service"}); -params.push_back({"pay-day", "", "payment day"}); -params.push_back({"comment", "", "comment"}); +params.push_back(SGCONF::API_ACTION::PARAM("cost", "", "\tcost of the service")); +params.push_back(SGCONF::API_ACTION::PARAM("pay-day", "", "payment day")); +params.push_back(SGCONF::API_ACTION::PARAM("comment", "", "comment")); return params; } @@ -115,20 +116,34 @@ return proto.DelService(arg, SimpleCallback, NULL) == STG::st_ok; bool AddServiceFunction(const SGCONF::CONFIG & config, const std::string & arg, - const std::map & /*options*/) + const std::map & options) { -// TODO -std::cerr << "Unimplemented.\n"; -return false; +SERVICE_CONF_RES conf; +conf.name = arg; +SGCONF::MaybeSet(options, "cost", conf.cost); +SGCONF::MaybeSet(options, "pay-day", conf.payDay); +SGCONF::MaybeSet(options, "comment", conf.comment); +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.userName.data(), + config.userPass.data()); +return proto.AddService(arg, conf, SimpleCallback, NULL) == STG::st_ok; } bool ChgServiceFunction(const SGCONF::CONFIG & config, const std::string & arg, const std::map & options) { -// TODO -std::cerr << "Unimplemented.\n"; -return false; +SERVICE_CONF_RES conf; +conf.name = arg; +SGCONF::MaybeSet(options, "cost", conf.cost); +SGCONF::MaybeSet(options, "pay-day", conf.payDay); +SGCONF::MaybeSet(options, "comment", conf.comment); +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.userName.data(), + config.userPass.data()); +return proto.ChgService(conf, SimpleCallback, NULL) == STG::st_ok; } } // namespace anonymous