5 #include "stg/servconf.h"
6 #include "stg/servconf_types.h"
7 #include "stg/service_conf.h"
8 #include "stg/common.h"
15 std::string Indent(size_t level, bool dash = false)
19 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
22 void PrintService(const STG::GET_SERVICE::INFO & info, size_t level = 0)
24 std::cout << Indent(level, true) << "name: " << info.name << "\n"
25 << Indent(level) << "cost: " << info.cost << "\n"
26 << Indent(level) << "payment day: " << info.payDay << "\n"
27 << Indent(level) << "comment: " << info.comment << "\n";
30 void SimpleCallback(bool result,
31 const std::string & reason,
36 std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
39 std::cout << "Success.\n";
42 void GetServicesCallback(bool result,
43 const std::string & reason,
44 const std::vector<STG::GET_SERVICE::INFO> & info,
49 std::cerr << "Failed to get service list. Reason: '" << reason << "'." << std::endl;
52 std::cout << "Services:\n";
53 for (size_t i = 0; i < info.size(); ++i)
54 PrintService(info[i], 1);
57 void GetServiceCallback(bool result,
58 const std::string & reason,
59 const STG::GET_SERVICE::INFO & info,
64 std::cerr << "Failed to get service. Reason: '" << reason << "'." << std::endl;
70 } // namespace anonymous
72 bool SGCONF::GetServicesFunction(const SGCONF::CONFIG & config,
73 const std::string & /*arg*/,
74 const std::map<std::string, std::string> & /*options*/)
76 STG::SERVCONF proto(config.server.data(),
78 config.userName.data(),
79 config.userPass.data());
80 return proto.GetServices(GetServicesCallback, NULL) == STG::st_ok;
83 bool SGCONF::GetServiceFunction(const SGCONF::CONFIG & config,
84 const std::string & arg,
85 const std::map<std::string, std::string> & /*options*/)
87 STG::SERVCONF proto(config.server.data(),
89 config.userName.data(),
90 config.userPass.data());
91 return proto.GetService(arg, GetServiceCallback, NULL) == STG::st_ok;
94 bool SGCONF::DelServiceFunction(const SGCONF::CONFIG & config,
95 const std::string & arg,
96 const std::map<std::string, std::string> & /*options*/)
98 STG::SERVCONF proto(config.server.data(),
100 config.userName.data(),
101 config.userPass.data());
102 return proto.DelService(arg, SimpleCallback, NULL) == STG::st_ok;
105 bool SGCONF::AddServiceFunction(const SGCONF::CONFIG & config,
106 const std::string & arg,
107 const std::map<std::string, std::string> & /*options*/)
110 std::cerr << "Unimplemented.\n";
114 bool SGCONF::ChgServiceFunction(const SGCONF::CONFIG & config,
115 const std::string & arg,
116 const std::map<std::string, std::string> & options)
119 std::cerr << "Unimplemented.\n";