8 #include "stg/tariffs.h"
9 #include "stg/admins.h"
10 #include "stg/services.h"
11 #include "stg/corporations.h"
12 #include "stg/traffcounter.h"
13 #include "stg/user_property.h"
15 #include "stg/ObjectSyntax.h"
22 virtual ~Sensor() = default;
23 virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
25 virtual std::string ToString() const = 0;
29 typedef std::map<OID, Sensor *> Sensors;
31 class TotalUsersSensor : public Sensor {
33 explicit TotalUsersSensor(const STG::Users & u) : users(u) {}
35 bool GetValue(ObjectSyntax_t * objectSyntax) const override
37 ValueToOS(users.Count(), objectSyntax);
42 std::string ToString() const override
43 { std::string res; std::to_string(users.Count(), res); return res; }
47 const STG::Users & users;
50 class UsersSensor : public Sensor {
52 explicit UsersSensor(STG::Users & u) : users(u) {}
54 bool GetValue(ObjectSyntax_t * objectSyntax) const override;
56 std::string ToString() const override;
62 virtual bool UserPredicate(STG::User* userPtr) const = 0;
65 class ConnectedUsersSensor : public UsersSensor {
67 explicit ConnectedUsersSensor(STG::Users & u) : UsersSensor(u) {}
70 bool UserPredicate(STG::User* userPtr) const override
71 { return userPtr->GetConnected(); }
74 class AuthorizedUsersSensor : public UsersSensor {
76 explicit AuthorizedUsersSensor(STG::Users & u) : UsersSensor(u) {}
79 bool UserPredicate(STG::User* userPtr) const override
80 { return userPtr->GetAuthorized(); }
83 class AlwaysOnlineUsersSensor : public UsersSensor {
85 explicit AlwaysOnlineUsersSensor(STG::Users & u) : UsersSensor(u) {}
88 bool UserPredicate(STG::User* userPtr) const override
89 { return userPtr->GetProperties().alwaysOnline; }
92 class NoCashUsersSensor : public UsersSensor {
94 explicit NoCashUsersSensor(STG::Users & u) : UsersSensor(u) {}
97 bool UserPredicate(STG::User* userPtr) const override
98 { return userPtr->GetProperties().cash < 0; }
101 class DisabledDetailStatsUsersSensor : public UsersSensor {
103 explicit DisabledDetailStatsUsersSensor(STG::Users & u) : UsersSensor(u) {}
106 bool UserPredicate(STG::User* userPtr) const override
107 { return userPtr->GetProperties().disabledDetailStat; }
110 class DisabledUsersSensor : public UsersSensor {
112 explicit DisabledUsersSensor(STG::Users & u) : UsersSensor(u) {}
115 bool UserPredicate(STG::User* userPtr) const override
116 { return userPtr->GetProperties().disabled; }
119 class PassiveUsersSensor : public UsersSensor {
121 explicit PassiveUsersSensor(STG::Users & u) : UsersSensor(u) {}
124 bool UserPredicate(STG::User* userPtr) const override
125 { return userPtr->GetProperties().passive; }
128 class CreditUsersSensor : public UsersSensor {
130 explicit CreditUsersSensor(STG::Users & u) : UsersSensor(u) {}
133 bool UserPredicate(STG::User* userPtr) const override
134 { return userPtr->GetProperties().credit > 0; }
137 class FreeMbUsersSensor : public UsersSensor {
139 explicit FreeMbUsersSensor(STG::Users & u) : UsersSensor(u) {}
142 bool UserPredicate(STG::User* userPtr) const override
143 { return userPtr->GetProperties().freeMb > 0; }
146 class TariffChangeUsersSensor : public UsersSensor {
148 explicit TariffChangeUsersSensor(STG::Users & u) : UsersSensor(u) {}
151 bool UserPredicate(STG::User* userPtr) const override
152 { return !userPtr->GetProperties().nextTariff.ConstData().empty(); }
155 class ActiveUsersSensor : public UsersSensor {
157 explicit ActiveUsersSensor(STG::Users & u) : UsersSensor(u) {}
160 bool UserPredicate(STG::User* userPtr) const override;
163 class TotalTariffsSensor : public Sensor {
165 explicit TotalTariffsSensor(const STG::Tariffs & t) : tariffs(t) {}
167 bool GetValue(ObjectSyntax_t * objectSyntax) const override
169 ValueToOS(tariffs.Count(), objectSyntax);
174 std::string ToString() const override
175 { std::string res; std::to_string(tariffs.Count(), res); return res; }
179 const STG::Tariffs & tariffs;
182 class TotalAdminsSensor : public Sensor {
184 explicit TotalAdminsSensor(const STG::Admins & a) : admins(a) {}
186 bool GetValue(ObjectSyntax_t * objectSyntax) const override
188 ValueToOS(admins.count(), objectSyntax);
193 std::string ToString() const override
194 { std::string res; std::to_string(admins.Count(), res); return res; }
198 const STG::Admins & admins;
201 class TotalServicesSensor : public Sensor {
203 explicit TotalServicesSensor(const STG::Services & s) : services(s) {}
205 bool GetValue(ObjectSyntax_t * objectSyntax) const override
207 ValueToOS(services.Count(), objectSyntax);
212 std::string ToString() const override
213 { std::string res; std::to_string(services.Count(), res); return res; }
217 const STG::Services & services;
220 class TotalCorporationsSensor : public Sensor {
222 explicit TotalCorporationsSensor(const STG::Corporations & c) : corporations(c) {}
224 bool GetValue(ObjectSyntax_t * objectSyntax) const override
226 ValueToOS(corporations.Count(), objectSyntax);
231 std::string ToString() const override
232 { std::string res; std::to_string(corporations.Count(), res); return res; }
236 const STG::Corporations & corporations;
239 class TotalRulesSensor : public Sensor {
241 explicit TotalRulesSensor(const STG::TraffCounter & t) : traffcounter(t) {}
243 bool GetValue(ObjectSyntax_t * objectSyntax) const override
245 ValueToOS(traffcounter.rulesCount(), objectSyntax);
250 std::string ToString() const override
251 { std::string res; std::to_string(traffcounter.rulesCount(), res); return res; }
255 const STG::TraffCounter & traffcounter;
258 template <typename T>
259 class ConstSensor : public Sensor {
261 explicit ConstSensor(const T & v) : value(v) {}
263 bool GetValue(ObjectSyntax * objectSyntax) const override
264 { return ValueToOS(value, objectSyntax); }
267 std::string ToString() const override
268 { std::string res; std::to_string(value, res); return res; }
278 std::string ConstSensor<std::string>::ToString() const