1 #include "tariff_helper.h"
3 void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
5 std::map<std::string, xmlrpc_c::value> structVal;
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);
14 std::vector<xmlrpc_c::value> prices(DIR_NUM);
16 for (unsigned i = 0; i < DIR_NUM; ++i)
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);
33 structVal["dirprices"] = xmlrpc_c::value_array(prices);
35 *info = xmlrpc_c::value_struct(structVal);
38 bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info)
40 std::map<std::string, xmlrpc_c::value> structVal(
41 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
44 std::map<std::string, xmlrpc_c::value>::iterator it;
46 if ((it = structVal.find("fee")) != structVal.end())
48 data.tariffConf.fee = xmlrpc_c::value_double(it->second);
51 if ((it = structVal.find("freemb")) != structVal.end())
53 data.tariffConf.free = xmlrpc_c::value_double(it->second);
56 if ((it = structVal.find("passivecost")) != structVal.end())
58 data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second);
61 if ((it = structVal.find("traffType")) != structVal.end())
63 data.tariffConf.traffType = xmlrpc_c::value_int(it->second);
66 if ((it = structVal.find("dirprices")) != structVal.end())
68 std::vector<xmlrpc_c::value> prices(
69 xmlrpc_c::value_array(it->second).vectorValueValue()
72 for (unsigned i = 0; i < DIR_NUM; ++i)
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]))
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"]);