X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d7a542f962802ad207d823b7e805c9135c1693e3..c016156ebb870d9d81219b8c4165aa75703f1e85:/projects/stargazer/plugins/other/smux/tables.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/other/smux/tables.cpp b/projects/stargazer/plugins/other/smux/tables.cpp new file mode 100644 index 00000000..023b90b2 --- /dev/null +++ b/projects/stargazer/plugins/other/smux/tables.cpp @@ -0,0 +1,45 @@ +#include + +#include "stg/user_property.h" + +#include "tables.h" + +void TariffUsersTable::UpdateSensors(Sensors & sensors) const +{ +std::map data; + +int handle = users.OpenSearch(); +if (!handle) + return; + +USER_PTR user; +while (!users.SearchNext(handle, &user)) + { + std::string tariffName(user->GetProperty().tariffName.ConstData()); + std::map::iterator it; + it = data.lower_bound(tariffName); + if (it == data.end() || + it->first != tariffName) + { + data.insert(it, std::make_pair(tariffName, 1)); + } + else + { + ++it->second; + } + } + +users.CloseSearch(handle); + +size_t idx = 1; +OID prefixOid(prefix); + +std::map::const_iterator it(data.begin()); +while (it != data.end()) + { + sensors[prefixOid.copyWithSuffix(2, idx)] = new ConstSensor(it->first); + sensors[prefixOid.copyWithSuffix(3, idx)] = new ConstSensor(it->second); + ++idx; + ++it; + } +}