]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/tables.cpp
023b90b2b1df4f6f5db8d5b818368ca03d30b072
[stg.git] / projects / stargazer / plugins / other / smux / tables.cpp
1 #include <utility>
2
3 #include "stg/user_property.h"
4
5 #include "tables.h"
6
7 void TariffUsersTable::UpdateSensors(Sensors & sensors) const
8 {
9 std::map<std::string, size_t> data;
10
11 int handle = users.OpenSearch();
12 if (!handle)
13     return;
14
15 USER_PTR user;
16 while (!users.SearchNext(handle, &user))
17     {
18     std::string tariffName(user->GetProperty().tariffName.ConstData());
19     std::map<std::string, size_t>::iterator it;
20     it = data.lower_bound(tariffName);
21     if (it == data.end() ||
22         it->first != tariffName)
23         {
24         data.insert(it, std::make_pair(tariffName, 1));
25         }
26     else
27         {
28         ++it->second;
29         }
30     }
31
32 users.CloseSearch(handle);
33
34 size_t idx = 1;
35 OID prefixOid(prefix);
36
37 std::map<std::string, size_t>::const_iterator it(data.begin());
38 while (it != data.end())
39     {
40     sensors[prefixOid.copyWithSuffix(2, idx)] = new ConstSensor<std::string>(it->first);
41     sensors[prefixOid.copyWithSuffix(3, idx)] = new ConstSensor<int>(it->second);
42     ++idx;
43     ++it;
44     }
45 }