]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/tariff_helper.cpp
Косметические изменения в конфигурационных файлах
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / tariff_helper.cpp
1 #include "tariff_helper.h"
2
3 void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
4 {
5 std::map<std::string, xmlrpc_c::value> structVal;
6
7 structVal["result"] = xmlrpc_c::value_boolean(true);
8 structVal["name"] = xmlrpc_c::value_string(data.tariffConf.name);
9 structVal["fee"] = xmlrpc_c::value_double(data.tariffConf.fee);
10 structVal["freemb"] = xmlrpc_c::value_double(data.tariffConf.free);
11 structVal["passivecost"] = xmlrpc_c::value_double(data.tariffConf.passiveCost);
12 structVal["traffType"] = xmlrpc_c::value_int(data.tariffConf.traffType);
13
14 std::vector<xmlrpc_c::value> prices(DIR_NUM);
15
16 for (unsigned i = 0; i < DIR_NUM; ++i)
17     {
18     std::map<std::string, xmlrpc_c::value> dirPrice;
19     dirPrice["hday"] = xmlrpc_c::value_int(data.dirPrice[i].hDay);
20     dirPrice["mday"] = xmlrpc_c::value_int(data.dirPrice[i].mDay);
21     dirPrice["hnight"] = xmlrpc_c::value_int(data.dirPrice[i].hNight);
22     dirPrice["mnight"] = xmlrpc_c::value_int(data.dirPrice[i].mNight);
23     dirPrice["pricedaya"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayA * 1024 * 1024);
24     dirPrice["pricedayb"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayB * 1024 * 1024);
25     dirPrice["pricenighta"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightA * 1024 * 1024);
26     dirPrice["pricenightb"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightB * 1024 * 1024);
27     dirPrice["threshold"] = xmlrpc_c::value_int(data.dirPrice[i].threshold);
28     dirPrice["singleprice"] = xmlrpc_c::value_boolean(data.dirPrice[i].singlePrice);
29     dirPrice["nodiscount"] = xmlrpc_c::value_boolean(data.dirPrice[i].noDiscount);
30     prices[i] = xmlrpc_c::value_struct(dirPrice);
31     }
32
33 structVal["dirprices"] = xmlrpc_c::value_array(prices);
34
35 *info = xmlrpc_c::value_struct(structVal);
36 }
37
38 bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info)
39 {
40 std::map<std::string, xmlrpc_c::value> structVal(
41     static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
42     );
43
44 std::map<std::string, xmlrpc_c::value>::iterator it;
45
46 if ((it = structVal.find("fee")) != structVal.end())
47     {
48     data.tariffConf.fee = xmlrpc_c::value_double(it->second);
49     }
50
51 if ((it = structVal.find("freemb")) != structVal.end())
52     {
53     data.tariffConf.free = xmlrpc_c::value_double(it->second);
54     }
55
56 if ((it = structVal.find("passivecost")) != structVal.end())
57     {
58     data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second);
59     }
60
61 if ((it = structVal.find("traffType")) != structVal.end())
62     {
63     data.tariffConf.traffType = xmlrpc_c::value_int(it->second);
64     }
65
66 if ((it = structVal.find("dirprices")) != structVal.end())
67     {
68     std::vector<xmlrpc_c::value> prices(
69             xmlrpc_c::value_array(it->second).vectorValueValue()
70             );
71
72     for (unsigned i = 0; i < DIR_NUM; ++i)
73         {
74         std::map<std::string, xmlrpc_c::value> dirPrice(
75             static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(prices[i]))
76             );
77         data.dirPrice[i].mDay = xmlrpc_c::value_int(dirPrice["mday"]);
78         data.dirPrice[i].hDay = xmlrpc_c::value_int(dirPrice["hday"]);
79         data.dirPrice[i].mNight = xmlrpc_c::value_int(dirPrice["mnight"]);
80         data.dirPrice[i].hNight = xmlrpc_c::value_int(dirPrice["hnight"]);
81         data.dirPrice[i].priceDayA = xmlrpc_c::value_double(dirPrice["pricedaya"]) / 1024 / 1024;
82         data.dirPrice[i].priceDayB = xmlrpc_c::value_double(dirPrice["pricedayb"]) / 1024 / 1024;
83         data.dirPrice[i].priceNightA = xmlrpc_c::value_double(dirPrice["pricenighta"]) / 1024 / 1024;
84         data.dirPrice[i].priceNightB = xmlrpc_c::value_double(dirPrice["pricenightb"]) / 1024 / 1024;
85         data.dirPrice[i].threshold = xmlrpc_c::value_int(dirPrice["threshold"]);
86         data.dirPrice[i].singlePrice = xmlrpc_c::value_boolean(dirPrice["singleprice"]);
87         data.dirPrice[i].noDiscount = xmlrpc_c::value_boolean(dirPrice["nodiscount"]);
88         }
89     }
90
91 return false;
92 }