1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "tariff_helper.h"
4 #include "stg/common.h"
6 void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
8 std::map<std::string, xmlrpc_c::value> structVal;
10 structVal["result"] = xmlrpc_c::value_boolean(true);
11 structVal["name"] = xmlrpc_c::value_string(data.tariffConf.name);
12 structVal["fee"] = xmlrpc_c::value_double(data.tariffConf.fee);
13 structVal["freemb"] = xmlrpc_c::value_double(data.tariffConf.free);
14 structVal["passivecost"] = xmlrpc_c::value_double(data.tariffConf.passiveCost);
15 structVal["traffType"] = xmlrpc_c::value_int(data.tariffConf.traffType);
16 structVal["period"] = xmlrpc_c::value_string(TARIFF::PeriodToString(data.tariffConf.period));
17 structVal["changePolicy"] = xmlrpc_c::value_string(TARIFF::ChangePolicyToString(data.tariffConf.changePolicy));
18 structVal["changePolicyTimeout"] = xmlrpc_c::value_string(formatTime(data.tariffConf.changePolicyTimeout));
20 std::vector<xmlrpc_c::value> prices(DIR_NUM);
22 for (unsigned i = 0; i < DIR_NUM; ++i)
24 std::map<std::string, xmlrpc_c::value> dirPrice;
25 dirPrice["hday"] = xmlrpc_c::value_int(data.dirPrice[i].hDay);
26 dirPrice["mday"] = xmlrpc_c::value_int(data.dirPrice[i].mDay);
27 dirPrice["hnight"] = xmlrpc_c::value_int(data.dirPrice[i].hNight);
28 dirPrice["mnight"] = xmlrpc_c::value_int(data.dirPrice[i].mNight);
29 dirPrice["pricedaya"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayA * 1024 * 1024);
30 dirPrice["pricedayb"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayB * 1024 * 1024);
31 dirPrice["pricenighta"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightA * 1024 * 1024);
32 dirPrice["pricenightb"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightB * 1024 * 1024);
33 dirPrice["threshold"] = xmlrpc_c::value_int(data.dirPrice[i].threshold);
34 dirPrice["singleprice"] = xmlrpc_c::value_boolean(data.dirPrice[i].singlePrice);
35 dirPrice["nodiscount"] = xmlrpc_c::value_boolean(data.dirPrice[i].noDiscount);
36 prices[i] = xmlrpc_c::value_struct(dirPrice);
39 structVal["dirprices"] = xmlrpc_c::value_array(prices);
41 *info = xmlrpc_c::value_struct(structVal);
44 bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info)
46 std::map<std::string, xmlrpc_c::value> structVal(
47 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
50 std::map<std::string, xmlrpc_c::value>::iterator it;
52 if ((it = structVal.find("fee")) != structVal.end())
54 data.tariffConf.fee = xmlrpc_c::value_double(it->second);
57 if ((it = structVal.find("freemb")) != structVal.end())
59 data.tariffConf.free = xmlrpc_c::value_double(it->second);
62 if ((it = structVal.find("passivecost")) != structVal.end())
64 data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second);
67 if ((it = structVal.find("traffType")) != structVal.end())
69 data.tariffConf.traffType = static_cast<TARIFF::TRAFF_TYPE>(xmlrpc_c::value_int(it->second).cvalue());
72 if ((it = structVal.find("period")) != structVal.end())
74 data.tariffConf.period = TARIFF::StringToPeriod(xmlrpc_c::value_string(it->second));
77 if ((it = structVal.find("changePolicy")) != structVal.end())
79 data.tariffConf.changePolicy = TARIFF::StringToChangePolicy(xmlrpc_c::value_string(it->second));
82 if ((it = structVal.find("changePolicyTimeout")) != structVal.end())
84 data.tariffConf.changePolicyTimeout = readTime(xmlrpc_c::value_string(it->second));
87 if ((it = structVal.find("dirprices")) != structVal.end())
89 std::vector<xmlrpc_c::value> prices(
90 xmlrpc_c::value_array(it->second).vectorValueValue()
93 for (unsigned i = 0; i < DIR_NUM; ++i)
95 std::map<std::string, xmlrpc_c::value> dirPrice(
96 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(prices[i]))
98 data.dirPrice[i].mDay = xmlrpc_c::value_int(dirPrice["mday"]);
99 data.dirPrice[i].hDay = xmlrpc_c::value_int(dirPrice["hday"]);
100 data.dirPrice[i].mNight = xmlrpc_c::value_int(dirPrice["mnight"]);
101 data.dirPrice[i].hNight = xmlrpc_c::value_int(dirPrice["hnight"]);
102 data.dirPrice[i].priceDayA = xmlrpc_c::value_double(dirPrice["pricedaya"]) / 1024 / 1024;
103 data.dirPrice[i].priceDayB = xmlrpc_c::value_double(dirPrice["pricedayb"]) / 1024 / 1024;
104 data.dirPrice[i].priceNightA = xmlrpc_c::value_double(dirPrice["pricenighta"]) / 1024 / 1024;
105 data.dirPrice[i].priceNightB = xmlrpc_c::value_double(dirPrice["pricenightb"]) / 1024 / 1024;
106 data.dirPrice[i].threshold = xmlrpc_c::value_int(dirPrice["threshold"]);
107 data.dirPrice[i].singlePrice = xmlrpc_c::value_boolean(dirPrice["singleprice"]);
108 data.dirPrice[i].noDiscount = xmlrpc_c::value_boolean(dirPrice["nodiscount"]);