From: Maxim Mamontov Date: Mon, 8 Aug 2011 18:25:03 +0000 (+0300) Subject: Table builders added for the SMUX plugin X-Git-Tag: 2.408-alpha~48 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/c016156ebb870d9d81219b8c4165aa75703f1e85 Table builders added for the SMUX plugin --- 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; + } +} diff --git a/projects/stargazer/plugins/other/smux/tables.h b/projects/stargazer/plugins/other/smux/tables.h new file mode 100644 index 00000000..ad3b55a3 --- /dev/null +++ b/projects/stargazer/plugins/other/smux/tables.h @@ -0,0 +1,38 @@ +#ifndef __TABLES_H__ +#define __TABLES_H__ + +#include +#include + +#include "sensors.h" + +class TableSensor { + public: + TableSensor(const std::string & p) : prefix(p) {} + virtual ~TableSensor() {} + + const std::string & GetPrefix() const { return prefix; } + virtual void UpdateSensors(Sensors & sensors) const = 0; + + protected: + std::string prefix; +}; + +class TariffUsersTable : public TableSensor { + public: + TariffUsersTable(const std::string & p, + USERS & u) + : TableSensor(p), + users(u) + {} + virtual ~TariffUsersTable() {} + + void UpdateSensors(Sensors & sensors) const; + + private: + USERS & users; +}; + +typedef std::map Tables; + +#endif