1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "tariff_helper.h"
5 void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
7 std::map<std::string, xmlrpc_c::value> structVal;
9 structVal["result"] = xmlrpc_c::value_boolean(true);
10 structVal["name"] = xmlrpc_c::value_string(data.tariffConf.name);
11 structVal["fee"] = xmlrpc_c::value_double(data.tariffConf.fee);
12 structVal["freemb"] = xmlrpc_c::value_double(data.tariffConf.free);
13 structVal["passivecost"] = xmlrpc_c::value_double(data.tariffConf.passiveCost);
14 structVal["traffType"] = xmlrpc_c::value_int(data.tariffConf.traffType);
15 structVal["period"] = xmlrpc_c::value_string(TARIFF::PeriodToString(data.tariffConf.period));
16 structVal["changePolicy"] = xmlrpc_c::value_string(TARIFF::ChangePolicyToString(data.tariffConf.changePolicy));
18 std::vector<xmlrpc_c::value> prices(DIR_NUM);
20 for (unsigned i = 0; i < DIR_NUM; ++i)
22 std::map<std::string, xmlrpc_c::value> dirPrice;
23 dirPrice["hday"] = xmlrpc_c::value_int(data.dirPrice[i].hDay);
24 dirPrice["mday"] = xmlrpc_c::value_int(data.dirPrice[i].mDay);
25 dirPrice["hnight"] = xmlrpc_c::value_int(data.dirPrice[i].hNight);
26 dirPrice["mnight"] = xmlrpc_c::value_int(data.dirPrice[i].mNight);
27 dirPrice["pricedaya"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayA * 1024 * 1024);
28 dirPrice["pricedayb"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayB * 1024 * 1024);
29 dirPrice["pricenighta"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightA * 1024 * 1024);
30 dirPrice["pricenightb"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightB * 1024 * 1024);
31 dirPrice["threshold"] = xmlrpc_c::value_int(data.dirPrice[i].threshold);
32 dirPrice["singleprice"] = xmlrpc_c::value_boolean(data.dirPrice[i].singlePrice);
33 dirPrice["nodiscount"] = xmlrpc_c::value_boolean(data.dirPrice[i].noDiscount);
34 prices[i] = xmlrpc_c::value_struct(dirPrice);
37 structVal["dirprices"] = xmlrpc_c::value_array(prices);
39 *info = xmlrpc_c::value_struct(structVal);
42 bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info)
44 std::map<std::string, xmlrpc_c::value> structVal(
45 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
48 std::map<std::string, xmlrpc_c::value>::iterator it;
50 if ((it = structVal.find("fee")) != structVal.end())
52 data.tariffConf.fee = xmlrpc_c::value_double(it->second);
55 if ((it = structVal.find("freemb")) != structVal.end())
57 data.tariffConf.free = xmlrpc_c::value_double(it->second);
60 if ((it = structVal.find("passivecost")) != structVal.end())
62 data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second);
65 if ((it = structVal.find("traffType")) != structVal.end())
67 data.tariffConf.traffType = static_cast<TARIFF::TRAFF_TYPE>(xmlrpc_c::value_int(it->second).cvalue());
70 if ((it = structVal.find("period")) != structVal.end())
72 data.tariffConf.period = TARIFF::StringToPeriod(xmlrpc_c::value_string(it->second));
75 if ((it = structVal.find("changePolicy")) != structVal.end())
77 data.tariffConf.changePolicy = TARIFF::StringToChangePolicy(xmlrpc_c::value_string(it->second));
80 if ((it = structVal.find("dirprices")) != structVal.end())
82 std::vector<xmlrpc_c::value> prices(
83 xmlrpc_c::value_array(it->second).vectorValueValue()
86 for (unsigned i = 0; i < DIR_NUM; ++i)
88 std::map<std::string, xmlrpc_c::value> dirPrice(
89 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(prices[i]))
91 data.dirPrice[i].mDay = xmlrpc_c::value_int(dirPrice["mday"]);
92 data.dirPrice[i].hDay = xmlrpc_c::value_int(dirPrice["hday"]);
93 data.dirPrice[i].mNight = xmlrpc_c::value_int(dirPrice["mnight"]);
94 data.dirPrice[i].hNight = xmlrpc_c::value_int(dirPrice["hnight"]);
95 data.dirPrice[i].priceDayA = xmlrpc_c::value_double(dirPrice["pricedaya"]) / 1024 / 1024;
96 data.dirPrice[i].priceDayB = xmlrpc_c::value_double(dirPrice["pricedayb"]) / 1024 / 1024;
97 data.dirPrice[i].priceNightA = xmlrpc_c::value_double(dirPrice["pricenighta"]) / 1024 / 1024;
98 data.dirPrice[i].priceNightB = xmlrpc_c::value_double(dirPrice["pricenightb"]) / 1024 / 1024;
99 data.dirPrice[i].threshold = xmlrpc_c::value_int(dirPrice["threshold"]);
100 data.dirPrice[i].singlePrice = xmlrpc_c::value_boolean(dirPrice["singleprice"]);
101 data.dirPrice[i].noDiscount = xmlrpc_c::value_boolean(dirPrice["nodiscount"]);