1 #include "tariff_helper.h"
3 #include "stg/tariff_conf.h"
4 #include "stg/common.h"
7 #include <ostream> // xmlrpc-c devs have missed something :)
9 void TARIFF_HELPER::GetTariffInfo(xmlrpc_c::value * info) const
11 std::map<std::string, xmlrpc_c::value> structVal;
13 structVal["result"] = xmlrpc_c::value_boolean(true);
14 structVal["name"] = xmlrpc_c::value_string(data.tariffConf.name);
15 structVal["fee"] = xmlrpc_c::value_double(data.tariffConf.fee);
16 structVal["freemb"] = xmlrpc_c::value_double(data.tariffConf.free);
17 structVal["passivecost"] = xmlrpc_c::value_double(data.tariffConf.passiveCost);
18 structVal["traffType"] = xmlrpc_c::value_int(data.tariffConf.traffType);
19 structVal["period"] = xmlrpc_c::value_string(STG::Tariff::toString(data.tariffConf.period));
20 structVal["changePolicy"] = xmlrpc_c::value_string(STG::Tariff::toString(data.tariffConf.changePolicy));
21 structVal["changePolicyTimeout"] = xmlrpc_c::value_string(formatTime(data.tariffConf.changePolicyTimeout));
23 std::vector<xmlrpc_c::value> prices(DIR_NUM);
25 for (unsigned i = 0; i < DIR_NUM; ++i)
27 std::map<std::string, xmlrpc_c::value> dirPrice;
28 dirPrice["hday"] = xmlrpc_c::value_int(data.dirPrice[i].hDay);
29 dirPrice["mday"] = xmlrpc_c::value_int(data.dirPrice[i].mDay);
30 dirPrice["hnight"] = xmlrpc_c::value_int(data.dirPrice[i].hNight);
31 dirPrice["mnight"] = xmlrpc_c::value_int(data.dirPrice[i].mNight);
32 dirPrice["pricedaya"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayA * 1024 * 1024);
33 dirPrice["pricedayb"] = xmlrpc_c::value_double(data.dirPrice[i].priceDayB * 1024 * 1024);
34 dirPrice["pricenighta"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightA * 1024 * 1024);
35 dirPrice["pricenightb"] = xmlrpc_c::value_double(data.dirPrice[i].priceNightB * 1024 * 1024);
36 dirPrice["threshold"] = xmlrpc_c::value_int(data.dirPrice[i].threshold);
37 dirPrice["singleprice"] = xmlrpc_c::value_boolean(data.dirPrice[i].singlePrice);
38 dirPrice["nodiscount"] = xmlrpc_c::value_boolean(data.dirPrice[i].noDiscount);
39 prices[i] = xmlrpc_c::value_struct(dirPrice);
42 structVal["dirprices"] = xmlrpc_c::value_array(prices);
44 *info = xmlrpc_c::value_struct(structVal);
47 bool TARIFF_HELPER::SetTariffInfo(const xmlrpc_c::value & info)
49 std::map<std::string, xmlrpc_c::value> structVal(
50 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(info))
53 std::map<std::string, xmlrpc_c::value>::iterator it;
55 if ((it = structVal.find("fee")) != structVal.end())
57 data.tariffConf.fee = xmlrpc_c::value_double(it->second);
60 if ((it = structVal.find("freemb")) != structVal.end())
62 data.tariffConf.free = xmlrpc_c::value_double(it->second);
65 if ((it = structVal.find("passivecost")) != structVal.end())
67 data.tariffConf.passiveCost = xmlrpc_c::value_double(it->second);
70 if ((it = structVal.find("traffType")) != structVal.end())
72 data.tariffConf.traffType = static_cast<STG::Tariff::TraffType>(xmlrpc_c::value_int(it->second).cvalue());
75 if ((it = structVal.find("period")) != structVal.end())
77 data.tariffConf.period = STG::Tariff::parsePeriod(xmlrpc_c::value_string(it->second));
80 if ((it = structVal.find("changePolicy")) != structVal.end())
82 data.tariffConf.changePolicy = STG::Tariff::parseChangePolicy(xmlrpc_c::value_string(it->second));
85 if ((it = structVal.find("changePolicyTimeout")) != structVal.end())
87 data.tariffConf.changePolicyTimeout = readTime(xmlrpc_c::value_string(it->second));
90 if ((it = structVal.find("dirprices")) != structVal.end())
92 std::vector<xmlrpc_c::value> prices(
93 xmlrpc_c::value_array(it->second).vectorValueValue()
96 for (unsigned i = 0; i < DIR_NUM; ++i)
98 std::map<std::string, xmlrpc_c::value> dirPrice(
99 static_cast<std::map<std::string, xmlrpc_c::value> >(xmlrpc_c::value_struct(prices[i]))
101 data.dirPrice[i].mDay = xmlrpc_c::value_int(dirPrice["mday"]);
102 data.dirPrice[i].hDay = xmlrpc_c::value_int(dirPrice["hday"]);
103 data.dirPrice[i].mNight = xmlrpc_c::value_int(dirPrice["mnight"]);
104 data.dirPrice[i].hNight = xmlrpc_c::value_int(dirPrice["hnight"]);
105 data.dirPrice[i].priceDayA = xmlrpc_c::value_double(dirPrice["pricedaya"]) / 1024 / 1024;
106 data.dirPrice[i].priceDayB = xmlrpc_c::value_double(dirPrice["pricedayb"]) / 1024 / 1024;
107 data.dirPrice[i].priceNightA = xmlrpc_c::value_double(dirPrice["pricenighta"]) / 1024 / 1024;
108 data.dirPrice[i].priceNightB = xmlrpc_c::value_double(dirPrice["pricenightb"]) / 1024 / 1024;
109 data.dirPrice[i].threshold = xmlrpc_c::value_int(dirPrice["threshold"]);
110 data.dirPrice[i].singlePrice = xmlrpc_c::value_boolean(dirPrice["singleprice"]);
111 data.dirPrice[i].noDiscount = xmlrpc_c::value_boolean(dirPrice["nodiscount"]);