]> git.stg.codes - stg.git/blob - projects/sgconf/info.cpp
Add missing library link.
[stg.git] / projects / sgconf / info.cpp
1 #include "info.h"
2
3 #include "api_action.h"
4 #include "options.h"
5 #include "makeproto.h"
6 #include "config.h"
7
8 #include "stg/servconf.h"
9
10 #include <iostream>
11 #include <string>
12 #include <map>
13
14 #include <expat.h>
15
16 namespace
17 {
18
19 void PrintInfo(const STG::ServerInfo::Info& info)
20 {
21     std::cout << "Server version: '" << info.version << "'\n"
22               << "Number of tariffs: " << info.tariffNum << "\n"
23               << "Tariff subsystem version: " << info.tariffType << "\n"
24               << "Number of users: " << info.usersNum << "\n"
25               << "UName: '" << info.uname << "\n"
26               << "Number of directions: " << info.dirNum << "\n"
27               << "Dirs:\n";
28     for (size_t i = 0; i < info.dirName.size(); ++i)
29         std::cout << "\t - '" << info.dirName[i] << "'\n";
30 }
31
32 void InfoCallback(bool result, const std::string & reason, const STG::ServerInfo::Info & info, void * /*data*/)
33 {
34 if (!result)
35     {
36     std::cerr << "Failed to get server info. Reason: '" << reason << "'." << std::endl;
37     return;
38     }
39 PrintInfo(info);
40 }
41
42 bool InfoFunction(const SGCONF::CONFIG & config,
43                   const std::string& /*arg*/,
44                   const std::map<std::string, std::string> & /*options*/)
45 {
46 return makeProto(config).ServerInfo(InfoCallback, NULL) == STG::st_ok;
47 }
48
49 }
50
51 void SGCONF::AppendServerInfoBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
52 {
53 blocks.Add("Server info")
54       .Add("server-info", SGCONF::MakeAPIAction(commands, InfoFunction), "\tget server info");
55 }