]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/tables.cpp
Added license header.
[stg.git] / projects / stargazer / plugins / other / smux / tables.cpp
1 #include <cassert>
2 #include <utility>
3 #include <iterator>
4 #include <algorithm>
5
6 #include "stg/user_property.h"
7 #include "stg/tariffs.h"
8 #include "stg/users.h"
9
10 #include "tables.h"
11
12 std::pair<std::string, size_t> TD2Info(const TARIFF_DATA & td);
13
14 void TariffUsersTable::UpdateSensors(Sensors & sensors) const
15 {
16 std::map<std::string, size_t> data;
17
18 std::list<TARIFF_DATA> tdl;
19 tariffs.GetTariffsData(&tdl);
20 std::transform(tdl.begin(),
21                tdl.end(),
22                std::inserter(data, data.begin()),
23                TD2Info);
24
25 int handle = users.OpenSearch();
26 assert(handle && "USERS::OpenSearch is always correct");
27
28 USER_PTR user;
29 while (!users.SearchNext(handle, &user))
30     {
31     if (user->GetDeleted())
32         continue;
33     std::string tariffName(user->GetProperty().tariffName.ConstData());
34     std::map<std::string, size_t>::iterator it(data.lower_bound(tariffName));
35     if (it == data.end() ||
36         it->first != tariffName)
37         {
38         data.insert(it, std::make_pair(tariffName, 1));
39         }
40     else
41         {
42         ++it->second;
43         }
44     }
45
46 users.CloseSearch(handle);
47
48 size_t idx = 1;
49 OID prefixOid(prefix);
50
51 std::map<std::string, size_t>::const_iterator it(data.begin());
52 while (it != data.end())
53     {
54     sensors[prefixOid.copyWithSuffix(2, static_cast<unsigned int>(idx))] = new ConstSensor<std::string>(it->first);
55     sensors[prefixOid.copyWithSuffix(3, static_cast<unsigned int>(idx))] = new ConstSensor<unsigned long>(it->second);
56     ++idx;
57     ++it;
58     }
59 }
60
61 std::pair<std::string, size_t> TD2Info(const TARIFF_DATA & td)
62 {
63 return std::make_pair(td.tariffConf.name, 0);
64 }